File tree 9 files changed +25
-88
lines changed
compiler/src/dotty/tools/dotc/tastyreflect
library/src/scala/tasty/reflect
tests/run-with-compiler-custom-args/tasty-interpreter/interpreter
9 files changed +25
-88
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl {
40
40
def Contravariant : Flags = core.Flags .Contravariant
41
41
def Scala2X : Flags = core.Flags .Scala2x
42
42
def DefaultParameterized : Flags = core.Flags .DefaultParameterized
43
- def Stable : Flags = core.Flags .StableRealizable
43
+ def StableRealizable : Flags = core.Flags .StableRealizable
44
44
def Param : Flags = core.Flags .Param
45
45
def ParamAccessor : Flags = core.Flags .ParamAccessor
46
46
}
Original file line number Diff line number Diff line change @@ -193,6 +193,11 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
193
193
val sym = symbol.moduleClass
194
194
if (sym.exists) Some (sym.asClass) else None
195
195
}
196
+
197
+ def companionClass (implicit ctx : Context ): Option [ClassSymbol ] = {
198
+ val sym = symbol.companionClass
199
+ if (sym.exists) Some (sym.asClass) else None
200
+ }
196
201
}
197
202
198
203
object IsBindSymbol extends IsBindSymbolModule {
Original file line number Diff line number Diff line change @@ -93,8 +93,8 @@ trait FlagsOps extends Core {
93
93
/** Is this symbol a method with default parameters */
94
94
def DefaultParameterized : Flags
95
95
96
- /** Is this symbol member that is assumed to be stable */
97
- def Stable : Flags
96
+ /** Is this symbol member that is assumed to be stable and realizable */
97
+ def StableRealizable : Flags
98
98
99
99
/** Is this symbol a parameter */
100
100
def Param : Flags
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ trait Printers
126
126
if (flags.is(Flags .Contravariant )) flagList += " Flags.Contravariant"
127
127
if (flags.is(Flags .Scala2X )) flagList += " Flags.Scala2X"
128
128
if (flags.is(Flags .DefaultParameterized )) flagList += " Flags.DefaultParameterized"
129
- if (flags.is(Flags .Stable )) flagList += " Flags.Stable "
129
+ if (flags.is(Flags .StableRealizable )) flagList += " Flags.StableRealizable "
130
130
if (flags.is(Flags .Param )) flagList += " Flags.Param"
131
131
if (flags.is(Flags .ParamAccessor )) flagList += " Flags.ParamAccessor"
132
132
flagList.result().mkString(" | " )
@@ -501,7 +501,7 @@ trait Printers
501
501
if (flags.is(Flags .Contravariant )) flagList += " contravariant"
502
502
if (flags.is(Flags .Scala2X )) flagList += " scala2x"
503
503
if (flags.is(Flags .DefaultParameterized )) flagList += " defaultParameterized"
504
- if (flags.is(Flags .Stable )) flagList += " stable "
504
+ if (flags.is(Flags .StableRealizable )) flagList += " stableRealizable "
505
505
if (flags.is(Flags .Param )) flagList += " param"
506
506
if (flags.is(Flags .ParamAccessor )) flagList += " paramAccessor"
507
507
flagList.result().mkString(" /*" , " " , " */" )
Original file line number Diff line number Diff line change @@ -155,6 +155,8 @@ trait SymbolOps extends Core {
155
155
156
156
/** The class symbol of the companion module class */
157
157
def moduleClass (implicit ctx : Context ): Option [ClassSymbol ]
158
+
159
+ def companionClass (implicit ctx : Context ): Option [ClassSymbol ]
158
160
}
159
161
implicit def ValSymbolDeco (symbol : ValSymbol ): ValSymbolAPI
160
162
Original file line number Diff line number Diff line change @@ -67,8 +67,8 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
67
67
case ValDef (name, tpt, Some (rhs)) =>
68
68
def evalRhs = eval(rhs)(accEnv)
69
69
val evalRef : LocalValue =
70
- if (stat.symbol.flags.isLazy ) LocalValue .lazyValFrom(evalRhs)
71
- else if (stat.symbol.flags.isMutable ) LocalValue .varFrom(evalRhs)
70
+ if (stat.symbol.flags.is( Flags . Lazy ) ) LocalValue .lazyValFrom(evalRhs)
71
+ else if (stat.symbol.flags.is( Flags . Mutable ) ) LocalValue .varFrom(evalRhs)
72
72
else LocalValue .valFrom(evalRhs)
73
73
74
74
accEnv.updated(stat.symbol, evalRef)
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ class Interpreter[R <: Reflection & Singleton](reflect0: R) extends TreeInterpre
77
77
// FIXME not necesarly static
78
78
jvmReflection.interpretStaticVal(fn.symbol.owner, fn.symbol)
79
79
case _ =>
80
- if (fn.symbol.flags.isObject )
80
+ if (fn.symbol.flags.is( Flags . Object ) )
81
81
jvmReflection.loadModule(fn.symbol.asVal.moduleClass.get)
82
82
else
83
83
jvmReflection.interpretStaticVal(fn.symbol.owner, fn.symbol)
Original file line number Diff line number Diff line change @@ -11,16 +11,16 @@ class JVMReflection[R <: Reflection & Singleton](val reflect: R) {
11
11
final val MODULE_INSTANCE_FIELD = " MODULE$"
12
12
13
13
def loadModule (sym : Symbol ): Object = {
14
- if (sym.owner.flags.isPackage) {
15
- // is top level object
16
- val moduleClass = getClassOf(sym)
17
- moduleClass.getField( MODULE_INSTANCE_FIELD ).get( null )
18
- }
19
- else {
20
- // nested object in an object
21
- // val clazz = loadClass(sym.fullNameSeparated(FlatName))
22
- // clazz.getConstructor().newInstance().asInstanceOf[Object]
23
- ???
14
+
15
+ sym.owner match {
16
+ case IsPackageSymbol (_) =>
17
+ val moduleClass = getClassOf(sym )
18
+ moduleClass.getField( MODULE_INSTANCE_FIELD ).get( null )
19
+ case _ =>
20
+ // nested object in an object
21
+ // val clazz = loadClass(sym.fullNameSeparated(FlatName))
22
+ // clazz.getConstructor().newInstance().asInstanceOf[Object]
23
+ ???
24
24
}
25
25
}
26
26
You can’t perform that action at this time.
0 commit comments