Skip to content

Commit c7dc93d

Browse files
committed
Rename other uses of pos to span
1 parent eb5be39 commit c7dc93d

File tree

15 files changed

+82
-82
lines changed

15 files changed

+82
-82
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ class TreeUnpickler(reader: TastyReader,
13271327
def coordAt(addr: Addr)(implicit ctx: Context): Coord = {
13281328
val pos = posAt(addr)
13291329
if (pos.exists)
1330-
positionCoord(pos)
1330+
spanCoord(pos)
13311331
else
13321332
indexCoord(addr.index)
13331333
}

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
984984
symbol = readSymbolRef()
985985
}
986986

987-
implicit val pos: Span = NoSpan
987+
implicit val span: Span = NoSpan
988988

989989
tag match {
990990
case EMPTYtree =>

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ object Scanners {
245245
val isScala2Mode: Boolean = ctx.scala2Setting
246246

247247
/** Cannot use ctx.featureEnabled because accessing the context would force too much */
248-
def testScala2Mode(msg: String, pos: Span = Span(offset)): Boolean = {
249-
if (isScala2Mode) ctx.migrationWarning(msg, source atSpan pos)
248+
def testScala2Mode(msg: String, span: Span = Span(offset)): Boolean = {
249+
if (isScala2Mode) ctx.migrationWarning(msg, source.atSpan(span))
250250
isScala2Mode
251251
}
252252

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ object MarkupParsers {
179179
xTakeUntil(handle.comment, () => Span(start, curOffset, start), "-->")
180180
}
181181

182-
def appendText(pos: Span, ts: Buffer[Tree], txt: String): Unit = {
183-
def append(t: String) = ts append handle.text(pos, t)
182+
def appendText(span: Span, ts: Buffer[Tree], txt: String): Unit = {
183+
def append(t: String) = ts append handle.text(span, t)
184184

185185
if (preserveWS) append(txt)
186186
else {
@@ -286,10 +286,10 @@ object MarkupParsers {
286286
val ts = content
287287
xEndTag(qname)
288288
debugLastStartElement = debugLastStartElement.tail
289-
val pos = Span(start, curOffset, start)
289+
val span = Span(start, curOffset, start)
290290
qname match {
291-
case "xml:group" => handle.group(pos, ts)
292-
case _ => handle.element(pos, qname, attrMap, false, ts)
291+
case "xml:group" => handle.group(span, ts)
292+
case _ => handle.element(span, qname, attrMap, false, ts)
293293
}
294294
}
295295
}
@@ -411,7 +411,7 @@ object MarkupParsers {
411411
*/
412412
def xScalaPatterns: List[Tree] = escapeToScala(parser.patterns(), "pattern")
413413

414-
def reportSyntaxError(pos: Int, str: String): Unit = parser.syntaxError(str, pos)
414+
def reportSyntaxError(offset: Int, str: String): Unit = parser.syntaxError(str, offset)
415415
def reportSyntaxError(str: String): Unit = {
416416
reportSyntaxError(curOffset, "in XML literal: " + str)
417417
nextch()

compiler/src/dotty/tools/dotc/parsing/xml/SymbolicXMLBuilder.scala

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
8989

9090
/** Wildly wrong documentation deleted in favor of "self-documenting code." */
9191
protected def mkXML(
92-
pos: Span,
92+
span: Span,
9393
isPattern: Boolean,
9494
pre: Tree,
9595
label: Tree,
@@ -100,41 +100,41 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
100100
{
101101
def starArgs =
102102
if (children.isEmpty) Nil
103-
else List(Typed(makeXMLseq(pos, children), wildStar))
103+
else List(Typed(makeXMLseq(span, children), wildStar))
104104

105105
def pat = Apply(_scala_xml__Elem, List(pre, label, wild, wild) ::: convertToTextPat(children))
106106
def nonpat = New(_scala_xml_Elem, List(List(pre, label, attrs, scope, if (empty) Literal(Constant(true)) else Literal(Constant(false))) ::: starArgs))
107107

108-
atPos(pos) { if (isPattern) pat else nonpat }
108+
atPos(span) { if (isPattern) pat else nonpat }
109109
}
110110

111-
final def entityRef(pos: Span, n: String): Tree =
112-
atPos(pos)( New(_scala_xml_EntityRef, LL(const(n))) )
111+
final def entityRef(span: Span, n: String): Tree =
112+
atPos(span)( New(_scala_xml_EntityRef, LL(const(n))) )
113113

114114
// create scala.xml.Text here <: scala.xml.Node
115-
final def text(pos: Span, txt: String): Tree = atPos(pos) {
115+
final def text(span: Span, txt: String): Tree = atPos(span) {
116116
if (isPattern) makeTextPat(const(txt))
117117
else makeText1(const(txt))
118118
}
119119

120120
def makeTextPat(txt: Tree): Apply = Apply(_scala_xml__Text, List(txt))
121121
def makeText1(txt: Tree): Tree = New(_scala_xml_Text, LL(txt))
122-
def comment(pos: Span, text: String): Tree = atPos(pos)( Comment(const(text)) )
123-
def charData(pos: Span, txt: String): Tree = atPos(pos)( makeText1(const(txt)) )
122+
def comment(span: Span, text: String): Tree = atPos(span)( Comment(const(text)) )
123+
def charData(span: Span, txt: String): Tree = atPos(span)( makeText1(const(txt)) )
124124

125-
def procInstr(pos: Span, target: String, txt: String): Tree =
126-
atPos(pos)( ProcInstr(const(target), const(txt)) )
125+
def procInstr(span: Span, target: String, txt: String): Tree =
126+
atPos(span)( ProcInstr(const(target), const(txt)) )
127127

128128
protected def Comment(txt: Tree): Tree = New(_scala_xml_Comment, LL(txt))
129129
protected def ProcInstr(target: Tree, txt: Tree): Tree = New(_scala_xml_ProcInstr, LL(target, txt))
130130

131131
/** @todo: attributes */
132-
def makeXMLpat(pos: Span, n: String, args: Seq[Tree]): Tree = {
132+
def makeXMLpat(span: Span, n: String, args: Seq[Tree]): Tree = {
133133
val (prepat, labpat) = splitPrefix(n) match {
134134
case (Some(pre), rest) => (const(pre), const(rest))
135135
case _ => (wild, const(n))
136136
}
137-
mkXML(pos, true, prepat, labpat, null, null, false, args)
137+
mkXML(span, true, prepat, labpat, null, null, false, args)
138138
}
139139

140140
protected def convertToTextPat(t: Tree): Tree = t match {
@@ -144,12 +144,12 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
144144
protected def convertToTextPat(buf: Seq[Tree]): List[Tree] =
145145
(buf map convertToTextPat).toList
146146

147-
def parseAttribute(pos: Span, s: String): Tree = {
148-
val ts = Utility.parseAttributeValue(s, text(pos, _), entityRef(pos, _))
147+
def parseAttribute(span: Span, s: String): Tree = {
148+
val ts = Utility.parseAttributeValue(s, text(span, _), entityRef(span, _))
149149
ts match {
150-
case Nil => TypedSplice(tpd.ref(defn.NilModule).withSpan(pos))
150+
case Nil => TypedSplice(tpd.ref(defn.NilModule).withSpan(span))
151151
case t :: Nil => t
152-
case _ => makeXMLseq(pos, ts)
152+
case _ => makeXMLseq(span, ts)
153153
}
154154
}
155155

@@ -159,11 +159,11 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
159159
}
160160

161161
/** could optimize if args.length == 0, args.length == 1 AND args(0) is <: Node. */
162-
def makeXMLseq(pos: Span, args: Seq[Tree]): Block = {
162+
def makeXMLseq(span: Span, args: Seq[Tree]): Block = {
163163
val buffer = ValDef(_buf, TypeTree(), New(_scala_xml_NodeBuffer, ListOfNil))
164164
val applies = args filterNot isEmptyText map (t => Apply(Select(Ident(_buf), _plus), List(t)))
165165

166-
atPos(pos)( Block(buffer :: applies.toList, Ident(_buf)) )
166+
atPos(span)( Block(buffer :: applies.toList, Ident(_buf)) )
167167
}
168168

169169
/** Returns (Some(prefix) | None, rest) based on position of ':' */
@@ -173,13 +173,13 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
173173
}
174174

175175
/** Various node constructions. */
176-
def group(pos: Span, args: Seq[Tree]): Tree =
177-
atPos(pos)( New(_scala_xml_Group, LL(makeXMLseq(pos, args))) )
176+
def group(span: Span, args: Seq[Tree]): Tree =
177+
atPos(span)( New(_scala_xml_Group, LL(makeXMLseq(span, args))) )
178178

179-
def unparsed(pos: Span, str: String): Tree =
180-
atPos(pos)( New(_scala_xml_Unparsed, LL(const(str))) )
179+
def unparsed(span: Span, str: String): Tree =
180+
atPos(span)( New(_scala_xml_Unparsed, LL(const(str))) )
181181

182-
def element(pos: Span, qname: String, attrMap: mutable.Map[String, Tree], empty: Boolean, args: Seq[Tree]): Tree = {
182+
def element(span: Span, qname: String, attrMap: mutable.Map[String, Tree], empty: Boolean, args: Seq[Tree]): Tree = {
183183
def handleNamespaceBinding(pre: String, z: String): Tree = {
184184
def mkAssign(t: Tree): Tree = Assign(
185185
Ident(_tmpscope),
@@ -210,7 +210,7 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
210210
case (None, x) => (null, x)
211211
}
212212

213-
def mkAttributeTree(pre: String, key: String, value: Tree) = atPos(pos.toSynthetic) {
213+
def mkAttributeTree(pre: String, key: String, value: Tree) = atPos(span.toSynthetic) {
214214
// XXX this is where we'd like to put Select(value, nme.toString_) for #1787
215215
// after we resolve the Some(foo) situation.
216216
val baseArgs = List(const(key), value, Ident(_md))
@@ -244,7 +244,7 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
244244
}
245245

246246
val body = mkXML(
247-
pos.toSynthetic,
247+
span.toSynthetic,
248248
false,
249249
const(pre),
250250
const(newlabel),
@@ -254,6 +254,6 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
254254
args
255255
)
256256

257-
atPos(pos.toSynthetic)(new XMLBlock(nsResult, new XMLBlock(attrResult, body)))
257+
atPos(span.toSynthetic)(new XMLBlock(nsResult, new XMLBlock(attrResult, body)))
258258
}
259259
}

compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ import scala.annotation.tailrec
1111
object Rewrites {
1212
private class PatchedFiles extends mutable.HashMap[SourceFile, Patches]
1313

14-
private case class Patch(pos: Span, replacement: String) {
15-
def delta = replacement.length - (pos.end - pos.start)
14+
private case class Patch(span: Span, replacement: String) {
15+
def delta = replacement.length - (span.end - span.start)
1616
}
1717

1818
private class Patches(source: SourceFile) {
1919
private val pbuf = new mutable.ListBuffer[Patch]()
2020

21-
def addPatch(pos: Span, replacement: String): Unit =
22-
pbuf += Patch(pos, replacement)
21+
def addPatch(span: Span, replacement: String): Unit =
22+
pbuf += Patch(span, replacement)
2323

2424
def apply(cs: Array[Char]): Array[Char] = {
2525
val delta = pbuf.map(_.delta).sum
26-
val patches = pbuf.toList.sortBy(_.pos.start)
26+
val patches = pbuf.toList.sortBy(_.span.start)
2727
if (patches.nonEmpty)
2828
patches reduceLeft {(p1, p2) =>
29-
assert(p1.pos.end <= p2.pos.start, s"overlapping patches: $p1 and $p2")
29+
assert(p1.span.end <= p2.span.start, s"overlapping patches: $p1 and $p2")
3030
p2
3131
}
3232
val ds = new Array[Char](cs.length + delta)
@@ -37,10 +37,10 @@ object Rewrites {
3737
outIdx + untouched
3838
}
3939
ps match {
40-
case patch @ Patch(pos, replacement) :: ps1 =>
41-
val outNew = copy(pos.start)
40+
case patch @ Patch(span, replacement) :: ps1 =>
41+
val outNew = copy(span.start)
4242
replacement.copyToArray(ds, outNew)
43-
loop(ps1, pos.end, outNew + replacement.length)
43+
loop(ps1, span.end, outNew + replacement.length)
4444
case Nil =>
4545
val outNew = copy(cs.length)
4646
assert(outNew == ds.length, s"$outNew != ${ds.length}")
@@ -60,17 +60,17 @@ object Rewrites {
6060
}
6161

6262
/** If -rewrite is set, record a patch that replaces the range
63-
* given by `pos` in `source` by `replacement`
63+
* given by `span` in `source` by `replacement`
6464
*/
65-
def patch(source: SourceFile, pos: Span, replacement: String)(implicit ctx: Context): Unit =
65+
def patch(source: SourceFile, span: Span, replacement: String)(implicit ctx: Context): Unit =
6666
for (rewrites <- ctx.settings.rewrite.value)
6767
rewrites.patched
6868
.getOrElseUpdate(source, new Patches(source))
69-
.addPatch(pos, replacement)
69+
.addPatch(span, replacement)
7070

7171
/** Patch position in `ctx.compilationUnit.source`. */
72-
def patch(pos: Span, replacement: String)(implicit ctx: Context): Unit =
73-
patch(ctx.compilationUnit.source, pos, replacement)
72+
def patch(span: Span, replacement: String)(implicit ctx: Context): Unit =
73+
patch(ctx.compilationUnit.source, span, replacement)
7474

7575
/** If -rewrite is set, apply all patches and overwrite patched source files.
7676
*/

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class Lifter {
4646
// don't instantiate here, as the type params could be further constrained, see tests/pos/pickleinf.scala
4747
var liftedType = expr.tpe.widen
4848
if (liftedFlags.is(Method)) liftedType = ExprType(liftedType)
49-
val lifted = ctx.newSymbol(ctx.owner, name, liftedFlags | Synthetic, liftedType, coord = positionCoord(expr.span))
49+
val lifted = ctx.newSymbol(ctx.owner, name, liftedFlags | Synthetic, liftedType, coord = spanCoord(expr.span))
5050
defs += liftedDef(lifted, expr).withPosOf(expr)
5151
ref(lifted.termRef).withSpan(expr.span.focus)
5252
}

compiler/src/dotty/tools/dotc/typer/ReTyper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ReTyper extends Typer with ReChecking {
120120
override def checkVariance(tree: Tree)(implicit ctx: Context): Unit = ()
121121
override def inferView(from: Tree, to: Type)(implicit ctx: Context): Implicits.SearchResult =
122122
Implicits.NoMatchingImplicitsFailure
123-
override def checkCanEqual(ltp: Type, rtp: Type, pos: Span)(implicit ctx: Context): Unit = ()
123+
override def checkCanEqual(ltp: Type, rtp: Type, span: Span)(implicit ctx: Context): Unit = ()
124124
override protected def addAccessorDefs(cls: Symbol, body: List[Tree])(implicit ctx: Context): List[Tree] = body
125125
override protected def checkEqualityEvidence(tree: tpd.Tree, pt: Type)(implicit ctx: Context): Unit = ()
126126
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
6767
/** The start of this file in the underlying source file */
6868
def start: Int = 0
6969

70-
def atSpan(pos: Span): SourcePosition =
71-
if (pos.exists) SourcePosition(underlying, pos)
70+
def atSpan(span: Span): SourcePosition =
71+
if (span.exists) SourcePosition(underlying, span)
7272
else NoSourcePosition
7373

7474
def isSelfContained: Boolean = underlying eq this
@@ -155,6 +155,6 @@ object SourceFile {
155155

156156
@sharable object NoSource extends SourceFile(NoAbstractFile, Array[Char]()) {
157157
override def exists: Boolean = false
158-
override def atSpan(pos: Span): SourcePosition = NoSourcePosition
158+
override def atSpan(span: Span): SourcePosition = NoSourcePosition
159159
}
160160

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ object Spans {
171171

172172
/** An index coordinate */
173173
implicit def indexCoord(n: Int): Coord = new Coord(n + 1)
174-
implicit def positionCoord(pos: Span): Coord =
175-
if (pos.exists) new Coord(-(pos.point + 1))
174+
implicit def spanCoord(span: Span): Coord =
175+
if (span.exists) new Coord(-(span.point + 1))
176176
else NoCoord
177177

178178
/** A sentinel for a missing coordinate */

doc-tool/src/dotty/tools/dottydoc/model/comment/Comment.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private[comment] case class ParsedComment (
5959

6060
trait MarkupConversion[T] extends MemberLookup {
6161
def ent: Entity
62-
def pos: Span
62+
def span: Span
6363
def parsed: ParsedComment
6464

6565
protected def linkedExceptions(m: Map[String, String])(implicit ctx: Context): Map[String, String]
@@ -74,7 +74,7 @@ trait MarkupConversion[T] extends MemberLookup {
7474
case x :: xs =>
7575
if (xs.nonEmpty) ctx.docbase.warn(
7676
s"Only allowed to have a single annotation for $annot",
77-
ent.symbol.sourcePosition(pos)
77+
ent.symbol.sourcePosition(span)
7878
)
7979
Some(x)
8080
case _ => None
@@ -104,7 +104,7 @@ trait MarkupConversion[T] extends MemberLookup {
104104
)
105105
}
106106

107-
case class MarkdownComment(ent: Entity, parsed: ParsedComment, pos: Span)
107+
case class MarkdownComment(ent: Entity, parsed: ParsedComment, span: Span)
108108
extends MarkupConversion[MarkdownNode] {
109109

110110
def stringToMarkup(str: String)(implicit ctx: Context) =
@@ -135,29 +135,29 @@ extends MarkupConversion[MarkdownNode] {
135135
.mapValues(stringToMarkup)
136136
}
137137

138-
case class WikiComment(ent: Entity, parsed: ParsedComment, pos: Span)
138+
case class WikiComment(ent: Entity, parsed: ParsedComment, span: Span)
139139
extends MarkupConversion[Body] {
140140

141141
def filterEmpty(xs: Map[String,String])(implicit ctx: Context) =
142-
xs.mapValues(_.toWiki(ent, ctx.docbase.packages, pos))
142+
xs.mapValues(_.toWiki(ent, ctx.docbase.packages, span))
143143
.filterNot { case (_, v) => v.blocks.isEmpty }
144144

145145
def filterEmpty(xs: List[String])(implicit ctx: Context) =
146-
xs.map(_.toWiki(ent, ctx.docbase.packages, pos))
146+
xs.map(_.toWiki(ent, ctx.docbase.packages, span))
147147

148148
def markupToHtml(t: Body)(implicit ctx: Context) =
149149
t.show(ent)
150150

151151
def stringToMarkup(str: String)(implicit ctx: Context) =
152-
str.toWiki(ent, ctx.docbase.packages, pos)
152+
str.toWiki(ent, ctx.docbase.packages, span)
153153

154154
def stringToShortHtml(str: String)(implicit ctx: Context) = {
155155
val parsed = stringToMarkup(str)
156156
parsed.summary.getOrElse(parsed).show(ent)
157157
}
158158

159159
def linkedExceptions(m: Map[String, String])(implicit ctx: Context) = {
160-
m.mapValues(_.toWiki(ent, ctx.docbase.packages, pos)).map { case (targetStr, body) =>
160+
m.mapValues(_.toWiki(ent, ctx.docbase.packages, span)).map { case (targetStr, body) =>
161161
val link = lookup(Some(ent), ctx.docbase.packages, targetStr)
162162
val newBody = body match {
163163
case Body(List(Paragraph(Chain(content)))) =>

0 commit comments

Comments
 (0)