Skip to content

Commit 1628cf5

Browse files
committed
Position -> Span
1 parent d5058af commit 1628cf5

File tree

69 files changed

+316
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+316
-312
lines changed

compiler/src/dotty/tools/backend/sjs/JSPositions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package dotty.tools.backend.sjs
22

33
import dotty.tools.dotc.core._
44
import Contexts._
5-
import dotty.tools.dotc.util.Positions
6-
import Positions.Position
5+
import dotty.tools.dotc.util.Spans
6+
import Spans.Span
77

88
import org.scalajs.ir
99

1010
/** Conversion utilities from dotty Positions to IR Positions. */
1111
class JSPositions()(implicit ctx: Context) {
1212

1313
/** Implicit conversion from dotty Position to ir.Position. */
14-
implicit def pos2irPos(pos: Position): ir.Position = {
14+
implicit def pos2irPos(pos: Span): ir.Position = {
1515
if (!pos.exists) ir.Position.NoPosition
1616
else {
1717
val source = pos2irPosCache.toIRSource(ctx.compilationUnit.source)
@@ -23,7 +23,7 @@ class JSPositions()(implicit ctx: Context) {
2323

2424
/** Implicitly materializes an ir.Position from an implicit dotty Position. */
2525
implicit def implicitPos2irPos(
26-
implicit pos: Position): ir.Position = {
26+
implicit pos: Span): ir.Position = {
2727
pos2irPos(pos)
2828
}
2929

compiler/src/dotty/tools/dotc/ast/CheckTrees.scala.disabled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package ast
44

55
import core._
6-
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._
6+
import util.Spans._, Types._, Contexts._, Constants._, Names._, Flags._
77
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._
88

99
// TODO: revise, integrate in a checking phase.

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package ast
44

55
import core._
6-
import util.Positions._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
6+
import util.Spans._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
77
import Symbols._, StdNames._, Trees._
88
import Decorators._, transform.SymUtils._
99
import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName}
@@ -793,7 +793,7 @@ object desugar {
793793
pats map {
794794
case id: Ident =>
795795
expandSimpleEnumCase(id.name.asTermName, mods,
796-
Position(pdef.pos.start, id.pos.end, id.pos.start))
796+
Span(pdef.pos.start, id.pos.end, id.pos.start))
797797
}
798798
else {
799799
val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
@@ -894,7 +894,7 @@ object desugar {
894894
case Assign(Ident(name), rhs) => cpy.NamedArg(arg)(name, rhs)
895895
case _ => arg
896896
}
897-
def makeOp(fn: Tree, arg: Tree, selectPos: Position) = {
897+
def makeOp(fn: Tree, arg: Tree, selectPos: Span) = {
898898
val args: List[Tree] = arg match {
899899
case Parens(arg) => assignToNamedArg(arg) :: Nil
900900
case Tuple(args) => args.mapConserve(assignToNamedArg)
@@ -904,9 +904,9 @@ object desugar {
904904
}
905905

906906
if (isLeftAssoc(op.name))
907-
makeOp(left, right, Position(left.pos.start, op.pos.end, op.pos.start))
907+
makeOp(left, right, Span(left.pos.start, op.pos.end, op.pos.start))
908908
else
909-
makeOp(right, left, Position(op.pos.start, right.pos.end))
909+
makeOp(right, left, Span(op.pos.start, right.pos.end))
910910
}
911911

912912
/** Translate tuple expressions of arity <= 22

compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package ast
44

55
import core._
6-
import util.Positions._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
6+
import util.Spans._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
77
import Symbols._, StdNames._, Trees._
88
import Decorators._
99
import util.Property
@@ -44,7 +44,7 @@ object DesugarEnums {
4444
* It is an error if a type parameter is non-variant, or if its approximation
4545
* refers to pther type parameters.
4646
*/
47-
def interpolatedEnumParent(pos: Position)(implicit ctx: Context): Tree = {
47+
def interpolatedEnumParent(pos: Span)(implicit ctx: Context): Tree = {
4848
val tparams = enumClass.typeParams
4949
def isGround(tp: Type) = tp.subst(tparams, tparams.map(_ => NoType)) eq tp
5050
val targs = tparams map { tparam =>
@@ -195,7 +195,7 @@ object DesugarEnums {
195195
}
196196

197197
/** Expand a module definition representing a parameterless enum case */
198-
def expandEnumModule(name: TermName, impl: Template, mods: Modifiers, pos: Position)(implicit ctx: Context): Tree = {
198+
def expandEnumModule(name: TermName, impl: Template, mods: Modifiers, pos: Span)(implicit ctx: Context): Tree = {
199199
assert(impl.body.isEmpty)
200200
if (!enumClass.exists) EmptyTree
201201
else if (impl.parents.isEmpty)
@@ -212,7 +212,7 @@ object DesugarEnums {
212212
}
213213

214214
/** Expand a simple enum case */
215-
def expandSimpleEnumCase(name: TermName, mods: Modifiers, pos: Position)(implicit ctx: Context): Tree =
215+
def expandSimpleEnumCase(name: TermName, mods: Modifiers, pos: Span)(implicit ctx: Context): Tree =
216216
if (!enumClass.exists) EmptyTree
217217
else if (enumClass.typeParams.nonEmpty) {
218218
val parent = interpolatedEnumParent(pos)

compiler/src/dotty/tools/dotc/ast/NavigateAST.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package ast
33

44
import core.Contexts.Context
55
import core.Decorators._
6-
import util.Positions._
6+
import util.Spans._
77
import Trees.{MemberDef, DefTree, WithLazyField}
88

99
/** Utility functions to go from typed to untyped ASTs */
@@ -54,7 +54,7 @@ object NavigateAST {
5454
/** The reverse part of the untyped root of the compilation unit of `ctx` to
5555
* position `pos`.
5656
*/
57-
def untypedPath(pos: Position)(implicit ctx: Context): List[Positioned] =
57+
def untypedPath(pos: Span)(implicit ctx: Context): List[Positioned] =
5858
pathTo(pos, ctx.compilationUnit.untpdTree)
5959

6060

@@ -67,7 +67,7 @@ object NavigateAST {
6767
* end point are the same, so this is useful when trying to reconcile
6868
* nodes with source code.
6969
*/
70-
def pathTo(pos: Position, from: Positioned, skipZeroExtent: Boolean = false)(implicit ctx: Context): List[Positioned] = {
70+
def pathTo(pos: Span, from: Positioned, skipZeroExtent: Boolean = false)(implicit ctx: Context): List[Positioned] = {
7171
def childPath(it: Iterator[Any], path: List[Positioned]): List[Positioned] = {
7272
while (it.hasNext) {
7373
val path1 = it.next() match {

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33
package ast
44

5-
import util.Positions._
5+
import util.Spans._
66
import util.{SourceFile, SourcePosition}
77
import core.Contexts.{Context, SourceInfo}
88
import core.Decorators._
@@ -20,10 +20,10 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
2020
* component of the position.
2121
*/
2222
private var myUniqueId: Int = _
23-
private[this] var curPos: Position = _
23+
private[this] var curPos: Span = _
2424

2525
/** The item's position */
26-
def pos: Position = curPos
26+
def pos: Span = curPos
2727

2828
/** item's id */
2929
def uniqueId: Int = myUniqueId
@@ -43,7 +43,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
4343
/** Destructively update `curPos` to given position. Also, set any missing
4444
* positions in children.
4545
*/
46-
protected def setPos(pos: Position, file: AbstractFile): Unit = {
46+
protected def setPos(pos: Span, file: AbstractFile): Unit = {
4747
setPosUnchecked(pos, file)
4848
if (pos.exists) setChildPositions(pos.toSynthetic, file)
4949
}
@@ -53,7 +53,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
5353
* If the positioned item is synthetic, the position is updated
5454
* destructively and the item itself is returned.
5555
*/
56-
def withSpan(pos: Position): this.type = {
56+
def withSpan(pos: Span): this.type = {
5757
val ownPos = this.pos
5858
val newpd: this.type =
5959
if (pos == ownPos || ownPos.isSynthetic) this else cloneIn(srcfile)
@@ -83,7 +83,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
8383
* any checks of consistency with - or updates of - other positions.
8484
* Called from Unpickler when entering positions.
8585
*/
86-
private[dotc] def setPosUnchecked(pos: Position, file: AbstractFile = this.srcfile): Unit = {
86+
private[dotc] def setPosUnchecked(pos: Span, file: AbstractFile = this.srcfile): Unit = {
8787
if (file != this.srcfile) setId(TreeIds.nextIdFor(file))
8888
curPos = pos
8989
}
@@ -99,7 +99,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
9999
* But since mutual tail recursion is not supported in Scala, we express it instead
100100
* as a while loop with a termination by return in the middle.
101101
*/
102-
private def setChildPositions(pos: Position, file: AbstractFile): Unit = {
102+
private def setChildPositions(pos: Span, file: AbstractFile): Unit = {
103103
var n = productArity // subnodes are analyzed right to left
104104
var elems: List[Any] = Nil // children in lists still to be considered, from right to left
105105
var end = pos.end // the last defined offset, fill in positions up to this offset
@@ -111,10 +111,10 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
111111
// synthetic. We can preserve this invariant by always setting a
112112
// zero-extent position for these trees here.
113113
if (!p.pos.exists || p.pos.isZeroExtent) {
114-
p.setPos(Position(start, start), file)
114+
p.setPos(Span(start, start), file)
115115
fillIn(ps1, start, end)
116116
} else {
117-
p.setPos(Position(start, end), file)
117+
p.setPos(Span(start, end), file)
118118
fillIn(ps1, end, end)
119119
}
120120
case nil =>
@@ -186,22 +186,22 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
186186
* needed for pickling, since TypeTrees are pickled as types, so
187187
* their position is lost.
188188
*/
189-
def initialSpan(ignoreTypeTrees: Boolean = false): Position = {
189+
def initialSpan(ignoreTypeTrees: Boolean = false): Span = {
190190

191-
def include(p1: Position, p2: Positioned) = p2 match {
191+
def include(p1: Span, p2: Positioned) = p2 match {
192192
case _: Trees.TypeTree[_] if ignoreTypeTrees => p1
193193
case _ => p1.union(p2.pos)
194194
}
195195

196-
def includeAll(pos: Position, xs: List[_]): Position = xs match {
196+
def includeAll(pos: Span, xs: List[_]): Span = xs match {
197197
case (p: Positioned) :: xs1 if sameSource(p) => includeAll(include(pos, p), xs1)
198198
case (xs0: List[_]) :: xs1 => includeAll(includeAll(pos, xs0), xs1)
199199
case _ :: xs1 => includeAll(pos, xs1)
200200
case _ => pos
201201
}
202202

203203
var n = productArity
204-
var pos = NoPosition
204+
var pos = NoSpan
205205
while (n > 0) {
206206
n -= 1
207207
productElement(n) match {
@@ -246,7 +246,7 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
246246
def checkPos(nonOverlapping: Boolean)(implicit ctx: Context): Unit = try {
247247
import untpd._
248248
var lastPositioned: Positioned = null
249-
var lastPos = NoPosition
249+
var lastPos = NoSpan
250250
def check(p: Any): Unit = p match {
251251
case p: Positioned =>
252252
assert(pos contains p.pos,

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package ast
44

55
import core._
6-
import Types._, Names._, NameOps._, Flags._, util.Positions._, Contexts._, Constants._
6+
import Types._, Names._, NameOps._, Flags._, util.Spans._, Contexts._, Constants._
77
import SymDenotations._, Symbols._, Denotations._, StdNames._, Comments._
88
import language.higherKinds
99
import collection.mutable.ListBuffer
@@ -339,13 +339,13 @@ object Trees {
339339
* This is a point position if the definition is synthetic, or a range position
340340
* if the definition comes from source.
341341
* It might also be that the definition does not have a position (for instance when synthesized by
342-
* a calling chain from `viewExists`), in that case the return position is NoPosition.
342+
* a calling chain from `viewExists`), in that case the return position is NoSpan.
343343
*/
344-
def namePos: Position =
344+
def namePos: Span =
345345
if (pos.exists) {
346346
val point = pos.point
347-
if (rawMods.is(Synthetic) || name.toTermName == nme.ERROR) Position(point)
348-
else Position(point, point + name.stripModuleClassSuffix.lastPart.length, point)
347+
if (rawMods.is(Synthetic) || name.toTermName == nme.ERROR) Span(point)
348+
else Span(point, point + name.stripModuleClassSuffix.lastPart.length, point)
349349
}
350350
else pos
351351
}
@@ -598,7 +598,7 @@ object Trees {
598598
case class Inlined[-T >: Untyped] private[ast] (call: tpd.Tree, bindings: List[MemberDef[T]], expansion: Tree[T])(implicit @transientParam src: SourceInfo)
599599
extends Tree[T] {
600600
type ThisTree[-T >: Untyped] = Inlined[T]
601-
override def initialSpan(ignoreTypeTrees: Boolean): Position = call.pos
601+
override def initialSpan(ignoreTypeTrees: Boolean): Span = call.pos
602602
}
603603

604604
/** A type tree that represents an existing or inferred type */
@@ -771,8 +771,8 @@ object Trees {
771771

772772
trait WithoutTypeOrPos[-T >: Untyped] extends Tree[T] {
773773
override def withTypeUnchecked(tpe: Type): ThisTree[Type] = this.asInstanceOf[ThisTree[Type]]
774-
override def pos: Position = NoPosition
775-
override def setPos(pos: Position, file: AbstractFile): Unit = {}
774+
override def pos: Span = NoSpan
775+
override def setPos(pos: Span, file: AbstractFile): Unit = {}
776776
}
777777

778778
/** Temporary class that results from translation of ModuleDefs
@@ -799,9 +799,9 @@ object Trees {
799799
override def isEmpty: Boolean = trees.isEmpty
800800
override def toList: List[Tree[T]] = flatten(trees)
801801
override def toString: String = if (isEmpty) "EmptyTree" else "Thicket(" + trees.mkString(", ") + ")"
802-
override def pos: Position = (NoPosition /: trees) ((pos, t) => pos union t.pos)
802+
override def pos: Span = (NoSpan /: trees) ((pos, t) => pos union t.pos)
803803

804-
override def withSpan(pos: Position): this.type =
804+
override def withSpan(pos: Span): this.type =
805805
mapElems(_.withSpan(pos)).asInstanceOf[this.type]
806806
override def withPosOf(posd: Positioned): this.type =
807807
mapElems(_.withPosOf(posd)).asInstanceOf[this.type]

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tools.dotc.typer.ProtoTypes.FunProtoTyped
77
import transform.SymUtils._
88
import transform.TypeUtils._
99
import core._
10-
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._, NameOps._
10+
import util.Spans._, Types._, Contexts._, Constants._, Names._, Flags._, NameOps._
1111
import Symbols._, StdNames._, Annotations._, Trees._, Symbols._
1212
import Decorators._, DenotTransformers._
1313
import collection.mutable
@@ -401,7 +401,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
401401
* kind for the given element type in `elemTpe`. No type arguments or
402402
* `length` arguments are given.
403403
*/
404-
def newArray(elemTpe: Type, returnTpe: Type, pos: Position, dims: JavaSeqLiteral)(implicit ctx: Context): Tree = {
404+
def newArray(elemTpe: Type, returnTpe: Type, pos: Span, dims: JavaSeqLiteral)(implicit ctx: Context): Tree = {
405405
val elemClass = elemTpe.classSymbol
406406
def newArr =
407407
ref(defn.DottyArraysModule).select(defn.newArrayMethod).withSpan(pos)

compiler/src/dotty/tools/dotc/core/Comments.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package core
55
import ast.{ untpd, tpd }
66
import Decorators._, Symbols._, Contexts._
77
import util.SourceFile
8-
import util.Positions._
8+
import util.Spans._
99
import util.CommentParsing._
1010
import util.Property.Key
1111
import parsing.Parsers.Parser
@@ -45,7 +45,7 @@ object Comments {
4545
* @param expanded If this comment has been expanded, it's expansion, otherwise `None`.
4646
* @param usecases The usecases for this comment.
4747
*/
48-
final case class Comment(pos: Position, raw: String, expanded: Option[String], usecases: List[UseCase]) {
48+
final case class Comment(pos: Span, raw: String, expanded: Option[String], usecases: List[UseCase]) {
4949

5050
/** Has this comment been cooked or expanded? */
5151
def isExpanded: Boolean = expanded.isDefined
@@ -74,10 +74,10 @@ object Comments {
7474

7575
def isDocComment(comment: String): Boolean = comment.startsWith("/**")
7676

77-
def apply(pos: Position, raw: String): Comment =
77+
def apply(pos: Span, raw: String): Comment =
7878
Comment(pos, raw, None, Nil)
7979

80-
private def parseUsecases(expandedComment: String, pos: Position)(implicit ctx: Context): List[UseCase] =
80+
private def parseUsecases(expandedComment: String, pos: Span)(implicit ctx: Context): List[UseCase] =
8181
if (!isDocComment(expandedComment)) {
8282
Nil
8383
} else {
@@ -94,9 +94,9 @@ object Comments {
9494
* def foo: A = ???
9595
* }}}
9696
*/
97-
private[this] def decomposeUseCase(body: String, pos: Position, start: Int, end: Int)(implicit ctx: Context): UseCase = {
97+
private[this] def decomposeUseCase(body: String, pos: Span, start: Int, end: Int)(implicit ctx: Context): UseCase = {
9898
def subPos(start: Int, end: Int) =
99-
if (pos == NoPosition) NoPosition
99+
if (pos == NoSpan) NoSpan
100100
else {
101101
val start1 = pos.start + start
102102
val end1 = pos.end + end
@@ -112,12 +112,12 @@ object Comments {
112112
}
113113
}
114114

115-
final case class UseCase(code: String, codePos: Position, untpdCode: untpd.Tree, tpdCode: Option[tpd.DefDef]) {
115+
final case class UseCase(code: String, codePos: Span, untpdCode: untpd.Tree, tpdCode: Option[tpd.DefDef]) {
116116
def typed(tpdCode: tpd.DefDef): UseCase = copy(tpdCode = Some(tpdCode))
117117
}
118118

119119
object UseCase {
120-
def apply(code: String, codePos: Position)(implicit ctx: Context): UseCase = {
120+
def apply(code: String, codePos: Span)(implicit ctx: Context): UseCase = {
121121
val tree = {
122122
val tree = new Parser(new SourceFile("<usecase>", code)).localDef(codePos.start)
123123
tree match {
@@ -441,8 +441,8 @@ object Comments {
441441
* If a symbol does not have a doc comment but some overridden version of it does,
442442
* the position of the doc comment of the overridden version is returned instead.
443443
*/
444-
def docCommentPos(sym: Symbol)(implicit ctx: Context): Position =
445-
ctx.docCtx.flatMap(_.docstring(sym).map(_.pos)).getOrElse(NoPosition)
444+
def docCommentPos(sym: Symbol)(implicit ctx: Context): Span =
445+
ctx.docCtx.flatMap(_.docstring(sym).map(_.pos)).getOrElse(NoSpan)
446446

447447
/** A version which doesn't consider self types, as a temporary measure:
448448
* an infinite loop has broken out between superComment and cookedDocComment

0 commit comments

Comments
 (0)