From 85e9e6ab352cf3b379e82918138598aee0f100fe Mon Sep 17 00:00:00 2001 From: Aggelos Biboudis Date: Fri, 25 Jan 2019 17:20:07 +0100 Subject: [PATCH] Rebased --- .../tools/dotc/tastyreflect/FlagSet.scala | 70 ------------------- .../dotc/tastyreflect/FlagsOpsImpl.scala | 2 +- .../dotc/tastyreflect/SymbolOpsImpl.scala | 5 ++ .../src/scala/tasty/reflect/FlagsOps.scala | 4 +- .../src/scala/tasty/reflect/Printers.scala | 4 +- .../src/scala/tasty/reflect/SymbolOps.scala | 2 + .../interpreter/TreeInterpreter.scala | 4 +- .../interpreter/jvm/Interpreter.scala | 2 +- .../interpreter/jvm/JVMReflection.scala | 20 +++--- 9 files changed, 25 insertions(+), 88 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala b/compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala deleted file mode 100644 index 5aabdfc97b30..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala +++ /dev/null @@ -1,70 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.core.Flags -import dotty.tools.dotc.core.Flags._ - -class FlagSet(flags: Flags.FlagSet) extends scala.tasty.reflect.FlagSet { - - def isProtected: Boolean = flags.is(Protected) - def isAbstract: Boolean = flags.is(Abstract) - def isFinal: Boolean = flags.is(Final) - def isSealed: Boolean = flags.is(Sealed) - def isCase: Boolean = flags.is(Case) - def isImplicit: Boolean = flags.is(Implicit) - def isErased: Boolean = flags.is(Erased) - def isLazy: Boolean = flags.is(Lazy) - def isOverride: Boolean = flags.is(Override) - def isInline: Boolean = flags.is(Inline) - def isMacro: Boolean = flags.is(Macro) - def isStatic: Boolean = flags.is(JavaStatic) - def isObject: Boolean = flags.is(Module) - def isTrait: Boolean = flags.is(Trait) - def isLocal: Boolean = flags.is(Local) - def isSynthetic: Boolean = flags.is(Synthetic) - def isArtifact: Boolean = flags.is(Artifact) - def isMutable: Boolean = flags.is(Mutable) - def isFieldAccessor: Boolean = flags.is(Accessor) - def isCaseAcessor: Boolean = flags.is(CaseAccessor) - def isCovariant: Boolean = flags.is(Covariant) - def isContravariant: Boolean = flags.is(Contravariant) - def isScala2X: Boolean = flags.is(Scala2x) - def isDefaultParameterized: Boolean = flags.is(DefaultParameterized) - def isStable: Boolean = flags.is(Stable) - def isParam: Boolean = flags.is(Param) - def isParamAccessor: Boolean = flags.is(ParamAccessor) - def isPackage: Boolean = flags.is(Package) - - override def toString: String = { - val flags = List.newBuilder[String] - if (isProtected) flags += "protected " - if (isAbstract) flags += "abstract" - if (isFinal) flags += "final" - if (isSealed) flags += "sealed" - if (isCase) flags += "case" - if (isImplicit) flags += "implicit" - if (isErased) flags += "erased" - if (isLazy) flags += "lazy" - if (isOverride) flags += "override" - if (isInline) flags += "inline" - if (isMacro) flags += "macro" - if (isStatic) flags += "javaStatic" - if (isObject) flags += "object" - if (isTrait) flags += "trait" - if (isLocal) flags += "local" - if (isSynthetic) flags += "synthetic" - if (isArtifact) flags += "artifact" - if (isMutable) flags += "mutable" - if (isFieldAccessor) flags += "accessor" - if (isCaseAcessor) flags += "caseAccessor" - if (isCovariant) flags += "covariant" - if (isContravariant) flags += "contravariant" - if (isScala2X) flags += "scala2x" - if (isDefaultParameterized) flags += "defaultParameterized" - if (isStable) flags += "stable" - if (isParam) flags += "param" - if (isParamAccessor) flags += "paramAccessor" - if (isPackage) flags += "package" - flags.result().mkString("<", ",", ">") - } - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala index a65357d20b32..d71935e79a50 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala @@ -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 } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala index c4359beacb1e..824f003663c1 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala @@ -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 { diff --git a/library/src/scala/tasty/reflect/FlagsOps.scala b/library/src/scala/tasty/reflect/FlagsOps.scala index d75c72cf2db7..eafef4cf3d01 100644 --- a/library/src/scala/tasty/reflect/FlagsOps.scala +++ b/library/src/scala/tasty/reflect/FlagsOps.scala @@ -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 diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index 6486334ef52a..cc5b827d7f01 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -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(" | ") @@ -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("/*", " ", "*/") diff --git a/library/src/scala/tasty/reflect/SymbolOps.scala b/library/src/scala/tasty/reflect/SymbolOps.scala index b16307278b3e..cd69466efdf7 100644 --- a/library/src/scala/tasty/reflect/SymbolOps.scala +++ b/library/src/scala/tasty/reflect/SymbolOps.scala @@ -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 diff --git a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala index 48eaf9c59cb3..8df8d08d65b2 100644 --- a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala +++ b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala @@ -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) diff --git a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala index 7a43e1f1b5c3..e27e00d14c65 100644 --- a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala +++ b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala @@ -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) diff --git a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala index 92ed6188d1b5..3983dd298113 100644 --- a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala +++ b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala @@ -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] + ??? } }