File tree 7 files changed +59
-19
lines changed
7 files changed +59
-19
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ class Compiler {
55
55
List (new Erasure ),
56
56
List (new CapturedVars ,
57
57
new Constructors ),
58
- List (new LambdaLift )
58
+ List (new LambdaLift ,
59
+ new Flatten )
59
60
)
60
61
61
62
var runId = 1
Load Diff This file was deleted.
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc
2
+ package transform
3
+
4
+ import core ._
5
+ import DenotTransformers .SymTransformer
6
+ import Phases .Phase
7
+ import Contexts .Context
8
+ import Flags ._
9
+ import SymUtils ._
10
+ import SymDenotations .SymDenotation
11
+ import collection .mutable
12
+ import TreeTransforms .MiniPhaseTransform
13
+ import dotty .tools .dotc .transform .TreeTransforms .TransformerInfo
14
+
15
+ class Flatten extends MiniPhaseTransform with SymTransformer { thisTransform =>
16
+ import ast .tpd ._
17
+ override def phaseName = " flatten"
18
+
19
+ def transformSym (ref : SymDenotation )(implicit ctx : Context ) = {
20
+ if (ref.isClass && ! ref.is(Package ) && ! ref.owner.is(Package )) {
21
+ ref.copySymDenotation(
22
+ name = ref.flatName,
23
+ owner = ref.enclosingPackageClass)
24
+ }
25
+ else ref
26
+ }
27
+
28
+ override def treeTransformPhase = thisTransform.next
29
+
30
+ private val liftedDefs = new mutable.ListBuffer [Tree ]
31
+
32
+ private def liftIfNested (tree : Tree )(implicit ctx : Context , info : TransformerInfo ) =
33
+ if (ctx.owner is Package ) tree
34
+ else {
35
+ liftedDefs += transformFollowing(tree)
36
+ EmptyTree
37
+ }
38
+
39
+ override def transformStats (stats : List [Tree ])(implicit ctx : Context , info : TransformerInfo ) =
40
+ if (ctx.owner is Package ) {
41
+ val liftedStats = stats ++ liftedDefs
42
+ liftedDefs.clear
43
+ liftedStats
44
+ }
45
+ else stats
46
+
47
+ override def transformTypeDef (tree : TypeDef )(implicit ctx : Context , info : TransformerInfo ) =
48
+ liftIfNested(tree)
49
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import core._
5
5
import Types ._
6
6
import Contexts ._
7
7
import Symbols ._
8
+ import SymDenotations ._
8
9
import Decorators ._
9
10
import Names ._
10
11
import StdNames ._
@@ -13,7 +14,8 @@ import Flags._
13
14
import language .implicitConversions
14
15
15
16
object SymUtils {
16
- implicit def decorateSymUtils (sym : Symbol ): SymUtils = new SymUtils (sym)
17
+ implicit def decorateSymbol (sym : Symbol ): SymUtils = new SymUtils (sym)
18
+ implicit def decorateSymDenot (d : SymDenotation ): SymUtils = new SymUtils (d.symbol)
17
19
}
18
20
19
21
/** A decorator that provides methods on symbols
@@ -64,4 +66,7 @@ class SymUtils(val self: Symbol) extends AnyVal {
64
66
65
67
def field (implicit ctx : Context ): Symbol =
66
68
self.owner.info.decl(self.asTerm.name.fieldName).suchThat(! _.is(Method )).symbol
69
+
70
+ /** `fullName` where `$' is the separator character */
71
+ def flatName (implicit ctx : Context ): Name = self.fullNameSeparated('$' )
67
72
}
Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ class TreeChecker {
180
180
override def typedStats (trees : List [untpd.Tree ], exprOwner : Symbol )(implicit ctx : Context ): List [Tree ] = {
181
181
for (tree <- trees) tree match {
182
182
case tree : untpd.DefTree => checkOwner(tree)
183
- case _ : untpd.Thicket => assert(false , " unexpanded thicket in statement sequence" )
183
+ case _ : untpd.Thicket => assert(false , i " unexpanded thicket $tree in statement sequence $trees % \n % " )
184
184
case _ =>
185
185
}
186
186
super .typedStats(trees, exprOwner)
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class tests extends CompilerTest {
15
15
16
16
implicit val defaultOptions = noCheckOptions ++ List (
17
17
" -Yno-deep-subtypes" ,
18
- " -Ycheck:patternMatcher,gettersSetters,lambdaLift "
18
+ " -Ycheck:patternMatcher,gettersSetters,flatten "
19
19
)
20
20
21
21
val twice = List (" #runs" , " 2" , " -YnoDoubleBindings" )
You can’t perform that action at this time.
0 commit comments