@@ -3,12 +3,11 @@ package dotc
3
3
package ast
4
4
5
5
import util .Spans ._
6
- import util .{SourceFile , SourcePosition }
6
+ import util .{SourceFile , NoSource , SourcePosition }
7
7
import core .Contexts .{Context , SourceInfo }
8
8
import core .Decorators ._
9
9
import core .Flags .{JavaDefined , Extension }
10
10
import core .StdNames .nme
11
- import io .AbstractFile
12
11
import annotation .transientParam
13
12
import annotation .internal .sharable
14
13
@@ -28,12 +27,11 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
28
27
/** item's id */
29
28
def uniqueId : Int = myUniqueId
30
29
31
- protected def srcfile : AbstractFile = TreeIds .fileOfId(uniqueId)
32
- def source (implicit ctx : Context ): SourceFile = ctx.getSource(srcfile)
30
+ def source : SourceFile = SourceFile .fromId(uniqueId)
33
31
def sourcePos (implicit ctx : Context ): SourcePosition = source.atSpan(span)
34
32
35
- setId(TreeIds .nextIdFor(initialFile( src)) )
36
- setPos(initialSpan(), srcfile )
33
+ setId(initialSource( src).nextId )
34
+ setPos(initialSpan(), source )
37
35
38
36
protected def setId (id : Int ): Unit = {
39
37
myUniqueId = id
@@ -43,7 +41,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
43
41
/** Destructively update `mySpan` to given span and potentially update `id` so that
44
42
* it refers to `file`. Also, set any missing positions in children.
45
43
*/
46
- protected def setPos (span : Span , file : AbstractFile ): Unit = {
44
+ protected def setPos (span : Span , file : SourceFile ): Unit = {
47
45
setOnePos(span, file)
48
46
if (span.exists) setChildPositions(span.toSynthetic, file)
49
47
}
@@ -56,34 +54,34 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
56
54
def withSpan (span : Span ): this .type = {
57
55
val ownSpan = this .span
58
56
val newpd : this .type =
59
- if (span == ownSpan || ownSpan.isSynthetic) this else cloneIn(srcfile )
60
- newpd.setPos(span, srcfile )
57
+ if (span == ownSpan || ownSpan.isSynthetic) this else cloneIn(source )
58
+ newpd.setPos(span, source )
61
59
newpd
62
60
}
63
61
64
62
def withPosOf (posd : Positioned ): this .type = {
65
63
val ownSpan = this .span
66
64
val newpd : this .type =
67
- if (posd.srcfile == srcfile && posd.span == ownSpan || ownSpan.isSynthetic) this
68
- else cloneIn(posd.srcfile )
69
- newpd.setPos(posd.span, posd.srcfile )
65
+ if (( posd.source `eq` source) && posd.span == ownSpan || ownSpan.isSynthetic) this
66
+ else cloneIn(posd.source )
67
+ newpd.setPos(posd.span, posd.source )
70
68
newpd
71
69
}
72
70
73
71
def withSourcePos (sourcePos : SourcePosition ): this .type = {
74
72
val ownSpan = this .span
75
73
val newpd : this .type =
76
- if (sourcePos.source.file == srcfile && sourcePos.span == ownSpan || ownSpan.isSynthetic) this
77
- else cloneIn(sourcePos.source.file )
78
- newpd.setPos(sourcePos.span, sourcePos.source.file )
74
+ if (( sourcePos.source `eq` source) && sourcePos.span == ownSpan || ownSpan.isSynthetic) this
75
+ else cloneIn(sourcePos.source)
76
+ newpd.setPos(sourcePos.span, sourcePos.source)
79
77
newpd
80
78
}
81
79
82
80
/** Set span of this tree only, without updating children spans.
83
81
* Called from Unpickler when entering positions.
84
82
*/
85
- private [dotc] def setOnePos (span : Span , file : AbstractFile = this .srcfile ): Unit = {
86
- if (file != this .srcfile ) setId(TreeIds .nextIdFor( file) )
83
+ private [dotc] def setOnePos (span : Span , file : SourceFile = this .source ): Unit = {
84
+ if (file `ne` this .source ) setId(file.nextId )
87
85
mySpan = span
88
86
}
89
87
@@ -98,7 +96,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
98
96
* But since mutual tail recursion is not supported in Scala, we express it instead
99
97
* as a while loop with a termination by return in the middle.
100
98
*/
101
- private def setChildPositions (span : Span , file : AbstractFile ): Unit = {
99
+ private def setChildPositions (span : Span , file : SourceFile ): Unit = {
102
100
var n = productArity // subnodes are analyzed right to left
103
101
var elems : List [Any ] = Nil // children in lists still to be considered, from right to left
104
102
var end = span.end // the last defined offset, fill in spans up to this offset
@@ -150,39 +148,39 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
150
148
}
151
149
152
150
/** Clone this node but assign it a fresh id which marks it as a node in `file`. */
153
- protected def cloneIn (file : AbstractFile ): this .type = {
151
+ protected def cloneIn (file : SourceFile ): this .type = {
154
152
val newpd : this .type = clone.asInstanceOf [this .type ]
155
- newpd.setId(TreeIds .nextIdFor( file) )
153
+ newpd.setId(file.nextId )
156
154
newpd
157
155
}
158
156
159
157
/** The source of the first element of this node that has a position */
160
- def elemsFile : AbstractFile = {
161
- def firstFile (x : Any ): AbstractFile = x match {
158
+ def elemsSource : SourceFile = {
159
+ def firstSource (x : Any ): SourceFile = x match {
162
160
case x : Positioned if x.span.exists =>
163
- x.srcfile
161
+ x.source
164
162
case x1 :: xs1 =>
165
- val f = firstFile (x1)
166
- if (f != null ) f else firstFile (xs1)
163
+ val f = firstSource (x1)
164
+ if (f.exists ) f else firstSource (xs1)
167
165
case _ =>
168
- null
166
+ NoSource
169
167
}
170
- def firstElemFile (n : Int ): AbstractFile =
171
- if (n == productArity) null
168
+ def firstElemSource (n : Int ): SourceFile =
169
+ if (n == productArity) NoSource
172
170
else {
173
- val f = firstFile (productElement(n))
174
- if (f != null ) f else firstElemFile (n + 1 )
171
+ val f = firstSource (productElement(n))
172
+ if (f.exists ) f else firstElemSource (n + 1 )
175
173
}
176
- firstElemFile (0 )
174
+ firstElemSource (0 )
177
175
}
178
176
179
177
/** The source file to use for the `id` of this node. This is
180
- * `elemsFile ` if it exists, or the source file indicated by
178
+ * `elemsSource ` if it exists, or the source file indicated by
181
179
* `src` otherwise
182
180
*/
183
- private def initialFile (src : SourceInfo ): AbstractFile = {
184
- val f = elemsFile
185
- if (f != null ) f else src.srcfile
181
+ private def initialSource (src : SourceInfo ): SourceFile = {
182
+ val f = elemsSource
183
+ if (f.exists ) f else src.source
186
184
}
187
185
188
186
/** The initial, synthetic span. This is usually the union of all positioned children's spans.
@@ -219,7 +217,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
219
217
span.toSynthetic
220
218
}
221
219
222
- private def sameSource (that : Positioned ) = srcfile == that.srcfile
220
+ private def sameSource (that : Positioned ) = source `eq` that.source
223
221
224
222
def contains (that : Positioned ): Boolean = {
225
223
def isParent (x : Any ): Boolean = x match {
0 commit comments