Skip to content

Commit 4534fd3

Browse files
committed
Rename SourcePos#pos -> SourcePos#span
Also: Better toText for source positions - only print file name instead of full path - enclose in <...> when printing in trees
1 parent d4a0a4a commit 4534fd3

File tree

10 files changed

+34
-32
lines changed

10 files changed

+34
-32
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
800800

801801

802802
def freshLocal(cunit: CompilationUnit, name: String, tpe: Type, pos: Position, flags: Flags): Symbol = {
803-
ctx.newSymbol(sym, name.toTermName, termFlagSet(flags), tpe, NoSymbol, pos.pos)
803+
ctx.newSymbol(sym, name.toTermName, termFlagSet(flags), tpe, NoSymbol, pos.span)
804804
}
805805

806806
def getter(clz: Symbol): Symbol = decorateSymbol(sym).getter

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ abstract class Positioned(implicit @transientParam src: SourceInfo) extends Prod
7373
def withSourcePos(sourcePos: SourcePosition): this.type = {
7474
val ownPos = this.pos
7575
val newpd: this.type =
76-
if (sourcePos.source.file == srcfile && sourcePos.pos == ownPos || ownPos.isSynthetic) this
76+
if (sourcePos.source.file == srcfile && sourcePos.span == ownPos || ownPos.isSynthetic) this
7777
else cloneIn(sourcePos.source.file)
78-
newpd.setPos(sourcePos.pos, sourcePos.source.file)
78+
newpd.setPos(sourcePos.span, sourcePos.source.file)
7979
newpd
8080
}
8181

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object Completion {
4040
* @return offset and list of symbols for possible completions
4141
*/
4242
def completions(pos: SourcePosition)(implicit ctx: Context): (Int, List[Completion]) = {
43-
val path = Interactive.pathTo(ctx.compilationUnit.tpdTree, pos.pos)
43+
val path = Interactive.pathTo(ctx.compilationUnit.tpdTree, pos.span)
4444
computeCompletions(pos, path)(Interactive.contextOfPath(path))
4545
}
4646

@@ -62,7 +62,7 @@ object Completion {
6262
else Mode.None
6363

6464
case Thicket(name :: _ :: Nil) :: (_: Import) :: _ =>
65-
if (name.pos.contains(pos.pos)) Mode.Import
65+
if (name.pos.contains(pos.span)) Mode.Import
6666
else Mode.None // Can't help completing the renaming
6767

6868
case Import(_, _) :: _ =>
@@ -83,13 +83,13 @@ object Completion {
8383
completionPrefix(name :: Nil, pos)
8484

8585
case Import(expr, selectors) :: _ =>
86-
selectors.find(_.pos.contains(pos.pos)).map { selector =>
86+
selectors.find(_.pos.contains(pos.span)).map { selector =>
8787
completionPrefix(selector.asInstanceOf[Tree] :: Nil, pos)
8888
}.getOrElse("")
8989

9090
case (ref: RefTree) :: _ =>
9191
if (ref.name == nme.ERROR) ""
92-
else ref.name.toString.take(pos.pos.point - ref.pos.point)
92+
else ref.name.toString.take(pos.span.point - ref.pos.point)
9393

9494
case _ =>
9595
""
@@ -309,7 +309,7 @@ object Completion {
309309
*/
310310
private def implicitConversionTargets(qual: Tree)(implicit ctx: Context): Set[Type] = {
311311
val typer = ctx.typer
312-
val conversions = new typer.ImplicitSearch(defn.AnyType, qual, pos.pos).allImplicits
312+
val conversions = new typer.ImplicitSearch(defn.AnyType, qual, pos.span).allImplicits
313313
val targets = conversions.map(_.widen.finalResultType)
314314
interactiv.println(i"implicit conversion targets considered: ${targets.toList}%, %")
315315
targets

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ object Interactive {
121121
List(select.symbol)
122122

123123
case (_: Thicket) :: (imp: Import) :: _ =>
124-
importedSymbols(imp, _.pos.contains(pos.pos))
124+
importedSymbols(imp, _.pos.contains(pos.span))
125125

126126
case (imp: Import) :: _ =>
127-
importedSymbols(imp, _.pos.contains(pos.pos))
127+
importedSymbols(imp, _.pos.contains(pos.span))
128128

129129
case _ =>
130130
List(enclosingTree(path).symbol)
@@ -252,7 +252,7 @@ object Interactive {
252252
*/
253253
def pathTo(trees: List[SourceTree], pos: SourcePosition)(implicit ctx: Context): List[Tree] =
254254
trees.find(_.pos.contains(pos)) match {
255-
case Some(tree) => pathTo(tree.tree, pos.pos)
255+
case Some(tree) => pathTo(tree.tree, pos.span)
256256
case None => Nil
257257
}
258258

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,11 @@ class PlainPrinter(_ctx: Context) extends Printer {
505505
nodeName ~ "(" ~ elems ~ tpSuffix ~ ")" ~ (Str(tree.sourcePos.toString) provided ctx.settings.YprintPos.value)
506506
}.close // todo: override in refined printer
507507

508-
def toText(pos: SourcePosition): Text =
508+
def toText(pos: SourcePosition): Text = {
509509
if (!pos.exists) "<no position>"
510-
else if (pos.source.exists) s"${pos.source.file}:${pos.line + 1}"
511-
else s"(no source file, offset = ${pos.pos.point})"
510+
else if (pos.source.exists) s"${pos.source.file.name}:${pos.line + 1}"
511+
else s"(no source file, offset = ${pos.span.point})"
512+
}
512513

513514
def toText(result: SearchResult): Text = result match {
514515
case result: SearchSuccess =>

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
600600
if (printPos) {
601601
val posStr =
602602
if (homogenizedView)
603-
if (tree.isInstanceOf[MemberDef]) s"${tree.source}${tree.pos}"
604-
else s"${tree.source}${tree.pos.toSynthetic}"
605-
else tree.sourcePos.toString
603+
if (tree.isInstanceOf[MemberDef]) Str(s"${tree.source}${tree.pos}")
604+
else Str(s"${tree.source}${tree.pos.toSynthetic}")
605+
else
606+
"<" ~ toText(tree.sourcePos) ~ ">"
606607
val clsStr = ""//if (tree.isType) tree.getClass.toString else ""
607608
txt = (txt ~ "@" ~ posStr ~ clsStr).close
608609
}

compiler/src/dotty/tools/dotc/transform/Bridges.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
8686
owner = root,
8787
flags = (member.flags | Method | Bridge | Artifact) &~
8888
(Accessor | ParamAccessor | CaseAccessor | Deferred | Lazy | Module),
89-
coord = bridgePosFor(member).pos).enteredAfter(thisPhase).asTerm
89+
coord = bridgePosFor(member).span).enteredAfter(thisPhase).asTerm
9090

9191
ctx.debuglog(
9292
i"""generating bridge from ${other.showLocated}: ${other.info}

compiler/src/dotty/tools/dotc/transform/Staging.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class Staging extends MacroTransformWithImplicits {
265265
None
266266
} else {
267267
val reqType = defn.QuotedTypeType.appliedTo(tp)
268-
val tag = ctx.typer.inferImplicitArg(reqType, pos.pos)
268+
val tag = ctx.typer.inferImplicitArg(reqType, pos.span)
269269
tag.tpe match {
270270
case fail: SearchFailureType =>
271271
Some(i"""

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
7777
* For regular source files, simply return the argument.
7878
*/
7979
def positionInUltimateSource(position: SourcePosition): SourcePosition =
80-
SourcePosition(underlying, position.pos shift start)
80+
SourcePosition(underlying, position.span shift start)
8181

8282
private def isLineBreak(idx: Int) =
8383
if (idx >= length) false else {

compiler/src/dotty/tools/dotc/util/SourcePosition.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import Spans.{Span, NoSpan}
88
import scala.annotation.internal.sharable
99

1010
/** A source position is comprised of a position in a source file */
11-
case class SourcePosition(source: SourceFile, pos: Span, outer: SourcePosition = NoSourcePosition)
11+
case class SourcePosition(source: SourceFile, span: Span, outer: SourcePosition = NoSourcePosition)
1212
extends interfaces.SourcePosition with Showable {
1313
/** Is `that` a source position contained in this source position ?
1414
* `outer` is not taken into account. */
1515
def contains(that: SourcePosition): Boolean =
16-
this.source == that.source && this.pos.contains(that.pos)
16+
this.source == that.source && this.span.contains(that.span)
1717

18-
def exists: Boolean = pos.exists
18+
def exists: Boolean = span.exists
1919

2020
def lineContent: String = source.lineContent(point)
2121

22-
def point: Int = pos.point
22+
def point: Int = span.point
2323

2424
/** The line of the position, starting at 0 */
2525
def line: Int = source.offsetToLine(point)
@@ -45,25 +45,25 @@ extends interfaces.SourcePosition with Showable {
4545
/** The column of the position, starting at 0 */
4646
def column: Int = source.column(point)
4747

48-
def start: Int = pos.start
48+
def start: Int = span.start
4949
def startLine: Int = source.offsetToLine(start)
5050
def startColumn: Int = source.column(start)
5151
def startColumnPadding: String = source.startColumnPadding(start)
5252

53-
def end: Int = pos.end
53+
def end: Int = span.end
5454
def endLine: Int = source.offsetToLine(end)
5555
def endColumn: Int = source.column(end)
5656

57-
def withOuter(outer: SourcePosition): SourcePosition = SourcePosition(source, pos, outer)
57+
def withOuter(outer: SourcePosition): SourcePosition = SourcePosition(source, span, outer)
5858
def withSpan(range: Span) = SourcePosition(source, range, outer)
5959

60-
def startPos: SourcePosition = withSpan(pos.startPos)
61-
def endPos : SourcePosition = withSpan(pos.endPos)
62-
def focus : SourcePosition = withSpan(pos.focus)
63-
def toSynthetic: SourcePosition = withSpan(pos.toSynthetic)
60+
def startPos: SourcePosition = withSpan(span.startPos)
61+
def endPos : SourcePosition = withSpan(span.endPos)
62+
def focus : SourcePosition = withSpan(span.focus)
63+
def toSynthetic: SourcePosition = withSpan(span.toSynthetic)
6464

6565
override def toString: String =
66-
s"${if (source.exists) source.file.toString else "(no source)"}:$pos"
66+
s"${if (source.exists) source.file.toString else "(no source)"}:$span"
6767

6868
def toText(printer: Printer): Text = printer.toText(this)
6969
}

0 commit comments

Comments
 (0)