@@ -28,135 +28,6 @@ object Trees {
28
28
/** The total number of created tree nodes, maintained if Stats.enabled */
29
29
var ntrees = 0
30
30
31
- /** A base class for things that have positions (currently: modifiers and trees)
32
- */
33
- abstract class Positioned extends DotClass with Product {
34
-
35
- private [this ] var curPos : Position = _
36
-
37
- setPos(initialPos)
38
-
39
- /** The item's position.
40
- */
41
- def pos : Position = curPos
42
-
43
- /** Destructively update `curPos` to given position. Also, set any missing
44
- * positions in children.
45
- */
46
- protected def setPos (pos : Position ): Unit = {
47
- curPos = pos
48
- if (pos.exists) setChildPositions(pos.toSynthetic)
49
- }
50
-
51
- /** The envelope containing the item in its entirety. Envelope is different from
52
- * `pos` for definitions (instances of MemberDef).
53
- */
54
- def envelope : Position = pos.toSynthetic
55
-
56
- /** A positioned item like this one with the position set to `pos`.
57
- * if the positioned item is source-derived, a clone is returned.
58
- * If the positioned item is synthetic, the position is updated
59
- * destructively and the item itself is returned.
60
- */
61
- def withPos (pos : Position ): this .type = {
62
- val newpd = (if (pos == curPos || curPos.isSynthetic) this else clone).asInstanceOf [Positioned ]
63
- newpd.setPos(pos)
64
- newpd.asInstanceOf [this .type ]
65
- }
66
-
67
- def withPos (posd : Positioned ): this .type =
68
- if (posd == null ) this else withPos(posd.pos)
69
-
70
- /** This item with a position that's the union of the given `pos` and the
71
- * current position.
72
- */
73
- def addPos (pos : Position ): this .type = withPos(pos union this .pos)
74
-
75
- /** If any children of this node do not have positions, set them to the given position,
76
- * and transitively visit their children.
77
- */
78
- private def setChildPositions (pos : Position ): Unit = {
79
- def deepSetPos (x : Any ): Unit = x match {
80
- case p : Positioned =>
81
- if (! p.pos.exists) p.setPos(pos)
82
- case xs : List [_] =>
83
- xs foreach deepSetPos
84
- case _ =>
85
- }
86
- var n = productArity
87
- while (n > 0 ) {
88
- n -= 1
89
- deepSetPos(productElement(n))
90
- }
91
- }
92
-
93
- /** The initial, synthetic position. This is usually the union of all positioned children's
94
- * envelopes.
95
- */
96
- protected def initialPos : Position = {
97
- var n = productArity
98
- var pos = NoPosition
99
- while (n > 0 ) {
100
- n -= 1
101
- productElement(n) match {
102
- case p : Positioned => pos = pos union p.envelope
103
- case xs : List [_] => pos = unionPos(pos, xs)
104
- case _ =>
105
- }
106
- }
107
- pos.toSynthetic
108
- }
109
-
110
- private def unionPos (pos : Position , xs : List [_]): Position = xs match {
111
- case (t : Tree [_]) :: xs1 => unionPos(pos union t.envelope, xs1)
112
- case _ => pos
113
- }
114
-
115
- def contains (that : Positioned ): Boolean = {
116
- def isParent (x : Any ): Boolean = x match {
117
- case x : Positioned =>
118
- x contains that
119
- case xs : List [_] =>
120
- xs exists isParent
121
- case _ =>
122
- false
123
- }
124
- (this eq that) ||
125
- (this .envelope contains that.pos) && {
126
- var n = productArity
127
- var found = false
128
- while (n > 0 && ! found) {
129
- n -= 1
130
- found = isParent(productElement(n))
131
- }
132
- found
133
- }
134
- }
135
-
136
- /** The path from this node to `that` node, represented
137
- * as a list starting with `this`, ending with`that` where
138
- * every node is a child of its predecessor.
139
- * Nil if no such path exists.
140
- */
141
- def pathTo (that : Positioned ): List [Positioned ] = {
142
- def childPath (it : Iterator [Any ]): List [Positioned ] =
143
- if (it.hasNext) {
144
- val cpath = it.next match {
145
- case x : Positioned => x.pathTo(that)
146
- case xs : List [_] => childPath(xs.iterator)
147
- case _ => Nil
148
- }
149
- if (cpath.nonEmpty) cpath else childPath(it)
150
- } else Nil
151
- if (this eq that) this :: Nil
152
- else if (this .envelope contains that.pos) {
153
- val cpath = childPath(productIterator)
154
- if (cpath.nonEmpty) this :: cpath else Nil
155
- }
156
- else Nil
157
- }
158
- }
159
-
160
31
/** Modifiers and annotations for definitions
161
32
* @param flags The set flags
162
33
* @param privateWithin If a private or protected has is followed by a
@@ -204,7 +75,7 @@ object Trees {
204
75
def tokenPos : Seq [(Token , Position )] = ???
205
76
}
206
77
207
- private var nextId = 0
78
+ private var nextId = 0 // for debugging
208
79
209
80
/** Trees take a parameter indicating what the type of their `tpe` field
210
81
* is. Two choices: `Type` or `Untyped`.
0 commit comments