@@ -17,7 +17,55 @@ import dotty.tools.dotc.report
1717import dotty .tools .dotc .util .SrcPos
1818import scala .annotation .nowarn
1919
20- private class ExtractExpression (config : ExpressionCompilerConfig , expressionStore : ExpressionStore ) extends MacroTransform with DenotTransformer :
20+ /**
21+ * This phase extracts the typed expression from the source tree, transfoms it and places it
22+ * in the evaluate method of the Expression class.
23+ *
24+ * Before:
25+ * package example:
26+ * class A:
27+ * def m: T =
28+ * val expression =
29+ * println("")
30+ * typed_expr
31+ * body
32+ *
33+ * class Expression(thisObject: Any, names: Array[String], values: Array[Any]):
34+ * def evaluate(): Any = ()
35+ *
36+ * After:
37+ * package example:
38+ * class A:
39+ * def m: T = body
40+ *
41+ * class Expression(thisObject: Any, names: Array[String], values: Array[Any]):
42+ * def evaluate(): Any =
43+ {
44+ * transformed_expr
45+ * }
46+ *
47+ * Every access to a local variable, or an inaccessible member is transformed into a temporary reflectEval call.
48+ * A ReflectEvalStrategy is attached to each reflectEval call to describe what should be evaluated and how.
49+ * When printing trees for debugging, the ReflectEvalStrategy appears as a String literal argument.
50+ *
51+ * Examples:
52+ *
53+ * 1. Get local variable `a`:
54+ * reflectEval(null, "ReflectEvalStrategy.LocalValue(a)", [])
55+ *
56+ * 2. Call private method `a.m(x1, x2)`:
57+ * reflectEval(a, "ReflectEvalStrategy.MethodCall(m)", [x1, x2])
58+ *
59+ * 3. Set private field `a.b = c`:
60+ * reflectEval(a, "ReflectEvalStrategy.FieldAssign(b)", [c])
61+ *
62+ * etc
63+ *
64+ */
65+ private class ExtractExpression (
66+ config : ExpressionCompilerConfig ,
67+ expressionStore : ExpressionStore
68+ ) extends MacroTransform with DenotTransformer :
2169 override def phaseName : String = ExtractExpression .name
2270
2371 /** Update the owner of the symbols inserted into `evaluate`. */
0 commit comments