Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.

Add freezable macro support #365

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6821547
Added some frozen classes (not finished)
chipsenkbeil Jan 29, 2017
fcc65f2
Unfinished work on frozen api
chipsenkbeil Feb 1, 2017
9240dba
Added a couple more missing implementations to frozen
chipsenkbeil Aug 6, 2017
5ffa41a
More code towards freeze support
chipsenkbeil Aug 13, 2017
05bfd58
Trying to create test macro
chipsenkbeil Aug 13, 2017
94c22a2
Added notes for freeze macro wip
chipsenkbeil Aug 13, 2017
76e48ef
Added wip code generator (not working)
chipsenkbeil Aug 13, 2017
7d69007
Still not working
chipsenkbeil Aug 14, 2017
0ec09b2
Still not working, but supports companion object already existing
chipsenkbeil Aug 14, 2017
579a474
Updated error message
chipsenkbeil Aug 14, 2017
08f903a
Added implicit support for freeze
chipsenkbeil Aug 14, 2017
5ff9fe1
Moved macro implementation to individual 2.10/2.11/2.12 versions (nee…
chipsenkbeil Aug 14, 2017
880a2fc
Switched to using macro-compat to get compiling under all three Scala…
chipsenkbeil Aug 14, 2017
894bef5
Switched default Scala version to 2.11
chipsenkbeil Aug 14, 2017
58daedb
Fixed to compile against all three Scala versions (again)
chipsenkbeil Aug 14, 2017
4cd0bf0
Got rid of some more red in IntelliJ
chipsenkbeil Aug 14, 2017
c245198
Got rid of last red in macro file
chipsenkbeil Aug 14, 2017
03ac810
Added commented-out attempt at filling in abstract methods
chipsenkbeil Aug 14, 2017
d6c27d9
Added ability to look up inherited methods -- need to use it to add m…
chipsenkbeil Aug 15, 2017
e72a46e
Added freezable to all info classes (code generation still not working)
chipsenkbeil Aug 15, 2017
3f05d8d
Updated @CanFreeze to have metadata, updated method generation for di…
chipsenkbeil Aug 15, 2017
31cd7ec
Removed old reference to FreezeMetadata
chipsenkbeil Aug 15, 2017
3c05345
Minor refactoring
chipsenkbeil Aug 15, 2017
6b396b4
Updated to blocks
chipsenkbeil Aug 15, 2017
a7b2c1c
Added empty tests for @Freezable, fixed issue where filled in methods…
chipsenkbeil Aug 16, 2017
c2cd929
Migrated some code to util class
chipsenkbeil Aug 16, 2017
ac3d000
Removed mutable object buildup
chipsenkbeil Aug 16, 2017
ffcd7a9
More refactoring
chipsenkbeil Aug 16, 2017
7a69f3b
Temporary testing
chipsenkbeil Aug 16, 2017
fe8afe3
Still trying to get to work, using inheritance
chipsenkbeil Aug 17, 2017
a94654f
Updated back to full method generation approach
chipsenkbeil Aug 17, 2017
d91bb04
Still working on it
chipsenkbeil Aug 17, 2017
cedd062
Still working on it -- recursive type is still an issue
chipsenkbeil Aug 17, 2017
bdf4acd
Where am I?
chipsenkbeil Aug 20, 2017
2f1b59d
Stopping again
chipsenkbeil Aug 20, 2017
61a8f2d
Unfinished refactor
chipsenkbeil Aug 23, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions project/Acyclic.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sbt.Keys._
import sbt._

import scala.util.Try

object Acyclic {
def settings: Seq[Setting[_]] = Seq(
libraryDependencies += "com.lihaoyi" %% "acyclic" % "0.1.7" % "provided",
libraryDependencies ++= (
if (scalaVersion.value.startsWith("2.10")) Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
) else Nil
),
autoCompilerPlugins := true,
addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.7")
)
}

4 changes: 2 additions & 2 deletions project/Common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Common {
homepage := Some(url("https://scala-debugger.org")),

// Default version when not cross-compiling
scalaVersion := "2.10.6",
scalaVersion := "2.11.8",

crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.1"),

Expand Down Expand Up @@ -135,6 +135,6 @@ object Common {
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
) ++ Macros.pluginSettings
) ++ Macros.pluginSettings ++ Acyclic.settings
}

12 changes: 8 additions & 4 deletions project/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ object Macros {
)

/** Macro-specific project settings. */
val settings = pluginSettings ++ Seq(
libraryDependencies += {
scalaVersion("org.scala-lang" % "scala-reflect" % _).value
},
val settings: Seq[Setting[_]] = pluginSettings ++ Seq(
libraryDependencies ++= Seq(
"org.typelevel" %% "macro-compat" % "1.1.1",
"com.lihaoyi" %% "scalaparse" % "0.4.4",
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided",
scalaVersion("org.scala-lang" % "scala-reflect" % _).value,
"org.scalatest" %% "scalatest" % "3.0.0" % "test,it"
),

libraryDependencies ++= (
if (scalaVersion.value.startsWith("2.10")) Seq(
Expand Down
1 change: 1 addition & 0 deletions scala-debugger-api/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.16
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class JavaInfoProducer extends InfoProducer {
* @return The profile instance providing an implementation corresponding
* to Java
*/
override def toJavaInfo: InfoProducer = new JavaInfoProducer
override def toJavaInfo: InfoProducer = this

/**
* Retrieves the event info producer tied to this info producer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class JavaThreadInfo(
*/
override def totalFrames: Int = _threadReference.frameCount()

protected def newValueConverter(value: Value): ValueConverter =
JavaValueConverter.from()

protected def newFrameProfile(
stackFrame: StackFrame,
index: Int
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package org.scaladebugger.api.profiles.java.info

import com.sun.jdi._
import org.scaladebugger.api.profiles.traits.info._
import JavaTypeConverter._

object JavaTypeConverter {
val DefaultNewReferenceTypeProfile: JavaTypeInfo => ReferenceType => ReferenceTypeInfo =
`type` => `type`.infoProducer.newReferenceTypeInfo(
`type`.scalaVirtualMachine,
_: ReferenceType
)
val DefaultNewArrayTypeProfile: JavaTypeInfo => ArrayType => ArrayTypeInfo =
`type` => `type`.infoProducer.newArrayTypeInfo(
`type`.scalaVirtualMachine,
_: ArrayType
)
val DefaultNewClassTypeProfile: JavaTypeInfo => ClassType => ClassTypeInfo =
`type` => `type`.infoProducer.newClassTypeInfo(
`type`.scalaVirtualMachine,
_: ClassType
)
val DefaultNewInterfaceTypeProfile: JavaTypeInfo => InterfaceType => InterfaceTypeInfo =
`type` => `type`.infoProducer.newInterfaceTypeInfo(
`type`.scalaVirtualMachine,
_: InterfaceType
)
val DefaultNewPrimitiveTypeProfile: JavaTypeInfo => PrimitiveType => PrimitiveTypeInfo =
`type` => `type`.infoProducer.newPrimitiveTypeInfo(
`type`.scalaVirtualMachine,
_: PrimitiveType
)
val DefaultNewVoidTypeProfile: JavaTypeInfo => VoidType => PrimitiveTypeInfo =
`type` => `type`.infoProducer.newPrimitiveTypeInfo(
`type`.scalaVirtualMachine,
_: VoidType
)

/**
* Creates a new converter from the provided type.
* @param `type` The type to convert
* @return The converter capable of converting the provided type
*/
def from(`type`: JavaTypeInfo): JavaTypeConverter =
new JavaTypeConverter(`type`)()
}

class JavaTypeConverter private(private val `type`: JavaTypeInfo)(
private val newReferenceTypeProfile: ReferenceType => ReferenceTypeInfo =
DefaultNewReferenceTypeProfile(`type`),
private val newArrayTypeProfile: ArrayType => ArrayTypeInfo =
DefaultNewArrayTypeProfile(`type`),
private val newClassTypeProfile: ClassType => ClassTypeInfo =
DefaultNewClassTypeProfile(`type`),
private val newInterfaceTypeProfile: InterfaceType => InterfaceTypeInfo =
DefaultNewInterfaceTypeProfile(`type`),
private val newPrimitiveTypeProfile: PrimitiveType => PrimitiveTypeInfo =
DefaultNewPrimitiveTypeProfile(`type`),
private val newVoidTypeProfile: VoidType => PrimitiveTypeInfo =
DefaultNewVoidTypeProfile(`type`)
) extends TypeConverter {
/**
* Creates a copy of the converter that will use the specified converter
* functions over the current instances.
* @param newReferenceTypeProfile
* @param newArrayTypeProfile
* @param newClassTypeProfile
* @param newInterfaceTypeProfile
* @param newPrimitiveTypeProfile
* @param newVoidTypeProfile
* @return The new converter instance
*/
def using(
newReferenceTypeProfile: ReferenceType => ReferenceTypeInfo = newReferenceTypeProfile,
newArrayTypeProfile: ArrayType => ArrayTypeInfo = newArrayTypeProfile,
newClassTypeProfile: ClassType => ClassTypeInfo = newClassTypeProfile,
newInterfaceTypeProfile: InterfaceType => InterfaceTypeInfo = newInterfaceTypeProfile,
newPrimitiveTypeProfile: PrimitiveType => PrimitiveTypeInfo = newPrimitiveTypeProfile,
newVoidTypeProfile: VoidType => PrimitiveTypeInfo = newVoidTypeProfile
): JavaTypeConverter = new JavaTypeConverter(`type`)(
newReferenceTypeProfile = newReferenceTypeProfile,
newArrayTypeProfile = newArrayTypeProfile,
newClassTypeProfile = newClassTypeProfile,
newInterfaceTypeProfile = newInterfaceTypeProfile,
newPrimitiveTypeProfile = newPrimitiveTypeProfile,
newVoidTypeProfile = newVoidTypeProfile
)

/**
* Returns the type as an array type (profile).
*
* @return The array type profile wrapping this type
*/
@throws[AssertionError]
override def toArrayType: ArrayTypeInfo = {
assert(`type`.isArrayType, "Type must be an array type!")
newArrayTypeProfile(`type`._type.asInstanceOf[ArrayType])
}

/**
* Returns the type as an class type (profile).
*
* @return The class type profile wrapping this type
*/
@throws[AssertionError]
override def toClassType: ClassTypeInfo = {
assert(`type`.isClassType, "Type must be a class type!")
newClassTypeProfile(`type`._type.asInstanceOf[ClassType])
}

/**
* Returns the type as an interface type (profile).
*
* @return The interface type profile wrapping this type
*/
@throws[AssertionError]
override def toInterfaceType: InterfaceTypeInfo = {
assert(`type`.isInterfaceType, "Type must be an interface type!")
newInterfaceTypeProfile(`type`._type.asInstanceOf[InterfaceType])
}

/**
* Returns the type as an reference type (profile).
*
* @return The reference type profile wrapping this type
*/
@throws[AssertionError]
override def toReferenceType: ReferenceTypeInfo = {
assert(`type`.isReferenceType, "Type must be a reference type!")
newReferenceTypeProfile(`type`._type.asInstanceOf[ReferenceType])
}

/**
* Returns the type as an primitive type (profile).
*
* @return The primitive type profile wrapping this type
*/
@throws[AssertionError]
override def toPrimitiveType: PrimitiveTypeInfo = {
assert(`type`.isPrimitiveType, "Type must be a primitive type!")
`type`._type match {
case p: PrimitiveType => newPrimitiveTypeProfile(p)
case v: VoidType => newPrimitiveTypeProfile(v)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ object JavaTypeInfo {
*/
class JavaTypeInfo(
val scalaVirtualMachine: ScalaVirtualMachine,
protected val infoProducer: InfoProducer,
private val _type: Type
protected[info] val infoProducer: InfoProducer,
private[info] val _type: Type
) extends TypeInfo {
/**
* Returns whether or not this info profile represents the low-level Java
Expand Down Expand Up @@ -121,106 +121,6 @@ class JavaTypeInfo(
*/
override def isNullType: Boolean = _type == null

/**
* Returns the type as an array type (profile).
*
* @return The array type profile wrapping this type
*/
@throws[AssertionError]
override def toArrayType: ArrayTypeInfo = {
assert(isArrayType, "Type must be an array type!")
newArrayTypeProfile(_type.asInstanceOf[ArrayType])
}

/**
* Returns the type as an class type (profile).
*
* @return The class type profile wrapping this type
*/
@throws[AssertionError]
override def toClassType: ClassTypeInfo = {
assert(isClassType, "Type must be a class type!")
newClassTypeProfile(_type.asInstanceOf[ClassType])
}

/**
* Returns the type as an interface type (profile).
*
* @return The interface type profile wrapping this type
*/
@throws[AssertionError]
override def toInterfaceType: InterfaceTypeInfo = {
assert(isInterfaceType, "Type must be an interface type!")
newInterfaceTypeProfile(_type.asInstanceOf[InterfaceType])
}

/**
* Returns the type as an reference type (profile).
*
* @return The reference type profile wrapping this type
*/
@throws[AssertionError]
override def toReferenceType: ReferenceTypeInfo = {
assert(isReferenceType, "Type must be a reference type!")
newReferenceTypeProfile(_type.asInstanceOf[ReferenceType])
}

/**
* Returns the type as an primitive type (profile).
*
* @return The primitive type profile wrapping this type
*/
@throws[AssertionError]
override def toPrimitiveType: PrimitiveTypeInfo = {
assert(isPrimitiveType, "Type must be a primitive type!")
_type match {
case p: PrimitiveType => newPrimitiveTypeProfile(p)
case v: VoidType => newPrimitiveTypeProfile(v)
}
}

protected def newTypeProfile(_type: Type): TypeInfo =
infoProducer.newTypeInfo(scalaVirtualMachine, _type)

protected def newReferenceTypeProfile(
referenceType: ReferenceType
): ReferenceTypeInfo = infoProducer.newReferenceTypeInfo(
scalaVirtualMachine,
referenceType
)

protected def newArrayTypeProfile(
arrayType: ArrayType
): ArrayTypeInfo = infoProducer.newArrayTypeInfo(
scalaVirtualMachine,
arrayType
)

protected def newClassTypeProfile(
classType: ClassType
): ClassTypeInfo = infoProducer.newClassTypeInfo(
scalaVirtualMachine,
classType
)

protected def newInterfaceTypeProfile(
interfaceType: InterfaceType
): InterfaceTypeInfo = infoProducer.newInterfaceTypeInfo(
scalaVirtualMachine,
interfaceType
)

protected def newPrimitiveTypeProfile(
primitiveType: PrimitiveType
): PrimitiveTypeInfo = infoProducer.newPrimitiveTypeInfo(
scalaVirtualMachine,
primitiveType
)

protected def newPrimitiveTypeProfile(
voidType: VoidType
): PrimitiveTypeInfo = infoProducer.newPrimitiveTypeInfo(
scalaVirtualMachine,
voidType
)
}
Loading