Skip to content

Commit

Permalink
Rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed Jan 28, 2019
1 parent 4098c43 commit 85e9e6a
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 88 deletions.
70 changes: 0 additions & 70 deletions compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl {
def Contravariant: Flags = core.Flags.Contravariant
def Scala2X: Flags = core.Flags.Scala2x
def DefaultParameterized: Flags = core.Flags.DefaultParameterized
def Stable: Flags = core.Flags.StableRealizable
def StableRealizable: Flags = core.Flags.StableRealizable
def Param: Flags = core.Flags.Param
def ParamAccessor: Flags = core.Flags.ParamAccessor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
val sym = symbol.moduleClass
if (sym.exists) Some(sym.asClass) else None
}

def companionClass(implicit ctx: Context): Option[ClassSymbol] = {
val sym = symbol.companionClass
if (sym.exists) Some(sym.asClass) else None
}
}

object IsBindSymbol extends IsBindSymbolModule {
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/tasty/reflect/FlagsOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ trait FlagsOps extends Core {
/** Is this symbol a method with default parameters */
def DefaultParameterized: Flags

/** Is this symbol member that is assumed to be stable */
def Stable: Flags
/** Is this symbol member that is assumed to be stable and realizable */
def StableRealizable: Flags

/** Is this symbol a parameter */
def Param: Flags
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ trait Printers
if (flags.is(Flags.Contravariant)) flagList += "Flags.Contravariant"
if (flags.is(Flags.Scala2X)) flagList += "Flags.Scala2X"
if (flags.is(Flags.DefaultParameterized)) flagList += "Flags.DefaultParameterized"
if (flags.is(Flags.Stable)) flagList += "Flags.Stable"
if (flags.is(Flags.StableRealizable)) flagList += "Flags.StableRealizable"
if (flags.is(Flags.Param)) flagList += "Flags.Param"
if (flags.is(Flags.ParamAccessor)) flagList += "Flags.ParamAccessor"
flagList.result().mkString(" | ")
Expand Down Expand Up @@ -501,7 +501,7 @@ trait Printers
if (flags.is(Flags.Contravariant)) flagList += "contravariant"
if (flags.is(Flags.Scala2X)) flagList += "scala2x"
if (flags.is(Flags.DefaultParameterized)) flagList += "defaultParameterized"
if (flags.is(Flags.Stable)) flagList += "stable"
if (flags.is(Flags.StableRealizable)) flagList += "stableRealizable"
if (flags.is(Flags.Param)) flagList += "param"
if (flags.is(Flags.ParamAccessor)) flagList += "paramAccessor"
flagList.result().mkString("/*", " ", "*/")
Expand Down
2 changes: 2 additions & 0 deletions library/src/scala/tasty/reflect/SymbolOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ trait SymbolOps extends Core {

/** The class symbol of the companion module class */
def moduleClass(implicit ctx: Context): Option[ClassSymbol]

def companionClass(implicit ctx: Context): Option[ClassSymbol]
}
implicit def ValSymbolDeco(symbol: ValSymbol): ValSymbolAPI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
case ValDef(name, tpt, Some(rhs)) =>
def evalRhs = eval(rhs)(accEnv)
val evalRef: LocalValue =
if (stat.symbol.flags.isLazy) LocalValue.lazyValFrom(evalRhs)
else if (stat.symbol.flags.isMutable) LocalValue.varFrom(evalRhs)
if (stat.symbol.flags.is(Flags.Lazy)) LocalValue.lazyValFrom(evalRhs)
else if (stat.symbol.flags.is(Flags.Mutable)) LocalValue.varFrom(evalRhs)
else LocalValue.valFrom(evalRhs)

accEnv.updated(stat.symbol, evalRef)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Interpreter[R <: Reflection & Singleton](reflect0: R) extends TreeInterpre
// FIXME not necesarly static
jvmReflection.interpretStaticVal(fn.symbol.owner, fn.symbol)
case _ =>
if (fn.symbol.flags.isObject)
if (fn.symbol.flags.is(Flags.Object))
jvmReflection.loadModule(fn.symbol.asVal.moduleClass.get)
else
jvmReflection.interpretStaticVal(fn.symbol.owner, fn.symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ class JVMReflection[R <: Reflection & Singleton](val reflect: R) {
final val MODULE_INSTANCE_FIELD = "MODULE$"

def loadModule(sym: Symbol): Object = {
if (sym.owner.flags.isPackage) {
// is top level object
val moduleClass = getClassOf(sym)
moduleClass.getField(MODULE_INSTANCE_FIELD).get(null)
}
else {
// nested object in an object
// val clazz = loadClass(sym.fullNameSeparated(FlatName))
// clazz.getConstructor().newInstance().asInstanceOf[Object]
???

sym.owner match {
case IsPackageSymbol(_) =>
val moduleClass = getClassOf(sym)
moduleClass.getField(MODULE_INSTANCE_FIELD).get(null)
case _ =>
// nested object in an object
// val clazz = loadClass(sym.fullNameSeparated(FlatName))
// clazz.getConstructor().newInstance().asInstanceOf[Object]
???
}
}

Expand Down

0 comments on commit 85e9e6a

Please sign in to comment.