File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ class Compiler {
91
91
new Flatten , // Lift all inner classes to package scope
92
92
new RestoreScopes ), // Repair scopes rendered invalid by moving definitions in prior phases of the group
93
93
List (new ExpandPrivate , // Widen private definitions accessed from nested classes
94
+ new SelectStatic , // get rid of selects that would be compiled into GetStatic
94
95
new CollectEntryPoints , // Find classes with main methods
95
96
new CollectSuperCalls , // Find classes that are called with super
96
97
new MoveStatics , // Move static methods to companion classes
Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc
2
+ package transform
3
+
4
+ import dotty .tools .dotc .ast .tpd
5
+ import dotty .tools .dotc .core .Contexts .Context
6
+ import dotty .tools .dotc .core .DenotTransformers .IdentityDenotTransformer
7
+ import dotty .tools .dotc .core .Flags ._
8
+ import dotty .tools .dotc .core .Symbols ._
9
+ import dotty .tools .dotc .core ._
10
+ import dotty .tools .dotc .transform .TreeTransforms ._
11
+
12
+ /** Removes selects that would be compiled into GetStatic
13
+ * otherwise backend needs to be aware that some qualifiers need to be dropped.
14
+ * Similar transformation seems to be performed by flatten in nsc
15
+ *
16
+ * @author Dmytro Petrashko
17
+ */
18
+ class SelectStatic extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform =>
19
+ import ast .tpd ._
20
+
21
+ override def phaseName : String = " selectStatic"
22
+ private val isPackage = FlagConjunction (PackageCreationFlags .bits)
23
+
24
+ override def transformSelect (tree : tpd.Select )(implicit ctx : Context , info : TransformerInfo ): tpd.Tree = {
25
+ val sym = tree.symbol
26
+ if (! sym.is(isPackage) && ! sym.owner.is(isPackage) &&
27
+ (
28
+ ((sym is Flags .Module ) && sym.owner.isStaticOwner) ||
29
+ (sym is Flags .JavaStatic ) ||
30
+ (sym.owner is Flags .ImplClass ) ||
31
+ sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot )
32
+ )
33
+ )
34
+ Block (List (tree.qualifier), ref(sym))
35
+ else tree
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments