diff options
author | Paul Phillips <paulp@improving.org> | 2013-10-01 15:02:45 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-10-01 15:02:45 -0700 |
commit | bef9e52d7337dafcc1f507ff1d93241f12f7c6d9 (patch) | |
tree | a7061f415a042fb65e3980d3f7a0bd21e717777d /src/compiler | |
parent | 2bba7797028a19b541b5bd88bd2b732e9a58681c (diff) | |
parent | 7d62df035cd4393c73e7530e1cad1130e79d90c6 (diff) | |
download | scala-bef9e52d7337dafcc1f507ff1d93241f12f7c6d9.tar.gz scala-bef9e52d7337dafcc1f507ff1d93241f12f7c6d9.tar.bz2 scala-bef9e52d7337dafcc1f507ff1d93241f12f7c6d9.zip |
Merge pull request #3003 from paulp/pr/position-catchup
Updating Position call sites.
Diffstat (limited to 'src/compiler')
9 files changed, 45 insertions, 46 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 0ba4719d37..d75e39ae00 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -13,7 +13,7 @@ import scala.collection.{ mutable, immutable } import mutable.{ ListBuffer, StringBuilder } import scala.reflect.internal.{ ModifierFlags => Flags } import scala.reflect.internal.Chars.{ isScalaLetter } -import scala.reflect.internal.util.{ SourceFile, OffsetPosition } +import scala.reflect.internal.util.{ SourceFile, Position } import Tokens._ import util.FreshNameCreator @@ -171,7 +171,7 @@ self => def freshTermName(prefix: String): TermName = newTermName(globalFresh.newName(prefix)) def freshTypeName(prefix: String): TypeName = newTypeName(globalFresh.newName(prefix)) - def o2p(offset: Int): Position = new OffsetPosition(source, offset) + def o2p(offset: Int): Position = Position.offset(source, offset) def r2p(start: Int, mid: Int, end: Int): Position = rangePos(source, start, mid, end) // suppress warnings; silent abort on errors @@ -725,13 +725,13 @@ self => tree match { case Ident(name) => removeAsPlaceholder(name) - makeParam(name.toTermName, TypeTree() setPos o2p(tree.pos.endOrPoint)) + makeParam(name.toTermName, TypeTree() setPos o2p(tree.pos.end)) case Typed(Ident(name), tpe) if tpe.isType => // get the ident! removeAsPlaceholder(name) makeParam(name.toTermName, tpe) case _ => syntaxError(tree.pos, "not a legal formal parameter", skipIt = false) - makeParam(nme.ERROR, errorTypeTree setPos o2p(tree.pos.endOrPoint)) + makeParam(nme.ERROR, errorTypeTree setPos o2p(tree.pos.end)) } } @@ -803,9 +803,9 @@ self => opstack = opstack.tail val opPos = r2p(opinfo.offset, opinfo.offset, opinfo.offset+opinfo.operator.length) val lPos = opinfo.operand.pos - val start = if (lPos.isDefined) lPos.startOrPoint else opPos.startOrPoint + val start = if (lPos.isDefined) lPos.start else opPos.start val rPos = top.pos - val end = if (rPos.isDefined) rPos.endOrPoint else opPos.endOrPoint + val end = if (rPos.isDefined) rPos.end else opPos.end top = atPos(start, opinfo.offset, end) { makeBinop(isExpr, opinfo.operand, opinfo.operator.toTermName, top, opPos) } @@ -917,11 +917,11 @@ self => val nameOffset = in.offset val name = identForType(skipIt = false) val point = if (name == tpnme.ERROR) hashOffset else nameOffset - atPos(t.pos.startOrPoint, point)(SelectFromTypeTree(t, name)) + atPos(t.pos.start, point)(SelectFromTypeTree(t, name)) } def simpleTypeRest(t: Tree): Tree = in.token match { case HASH => simpleTypeRest(typeProjection(t)) - case LBRACKET => simpleTypeRest(atPos(t.pos.startOrPoint, t.pos.point)(AppliedTypeTree(t, typeArgs()))) + case LBRACKET => simpleTypeRest(atPos(t.pos.start, t.pos.point)(AppliedTypeTree(t, typeArgs()))) case _ => t } @@ -958,7 +958,7 @@ self => // it still gets a CompoundTypeTree. ts.toList match { case tp :: Nil if !hasRefinement => tp // single type, no refinement, already positioned - case tps => atPos(t.pos.startOrPoint)(CompoundTypeTree(Template(tps, noSelfType, refinements))) + case tps => atPos(t.pos.start)(CompoundTypeTree(Template(tps, noSelfType, refinements))) } } @@ -970,7 +970,7 @@ self => val op = identForType() val tycon = atPos(opOffset) { Ident(op) } newLineOptWhenFollowing(isTypeIntroToken) - def mkOp(t1: Tree) = atPos(t.pos.startOrPoint, opOffset) { AppliedTypeTree(tycon, List(t, t1)) } + def mkOp(t1: Tree) = atPos(t.pos.start, opOffset) { AppliedTypeTree(tycon, List(t, t1)) } if (leftAssoc) infixTypeRest(mkOp(compoundType()), InfixMode.LeftOp) else @@ -1010,7 +1010,7 @@ self => val point = in.offset //assert(t.pos.isDefined, t) if (t != EmptyTree) - Select(t, ident(skipIt = false)) setPos r2p(t.pos.startOrPoint, point, in.lastOffset) + Select(t, ident(skipIt = false)) setPos r2p(t.pos.start, point, in.lastOffset) else errorTermTree // has already been reported } @@ -1067,7 +1067,7 @@ self => def selectors(t: Tree, typeOK: Boolean, dotOffset: Int): Tree = if (typeOK && in.token == TYPE) { in.nextToken() - atPos(t.pos.startOrPoint, dotOffset) { SingletonTypeTree(t) } + atPos(t.pos.start, dotOffset) { SingletonTypeTree(t) } } else { val t1 = selector(t) @@ -1403,7 +1403,7 @@ self => if (in.token == EQUALS) { t match { case Ident(_) | Select(_, _) | Apply(_, _) => - t = atPos(t.pos.startOrPoint, in.skipToken()) { gen.mkAssign(t, expr()) } + t = atPos(t.pos.start, in.skipToken()) { gen.mkAssign(t, expr()) } case _ => } } else if (in.token == COLON) { @@ -1414,7 +1414,7 @@ self => val uscorePos = in.skipToken() if (isIdent && in.name == nme.STAR) { in.nextToken() - t = atPos(t.pos.startOrPoint, colonPos) { + t = atPos(t.pos.start, colonPos) { Typed(t, atPos(uscorePos) { Ident(tpnme.WILDCARD_STAR) }) } } else { @@ -1423,7 +1423,7 @@ self => } else if (isAnnotation) { t = (t /: annotations(skipNewLines = false))(makeAnnotated) } else { - t = atPos(t.pos.startOrPoint, colonPos) { + t = atPos(t.pos.start, colonPos) { val tpt = typeOrInfixType(location) if (isWildcard(t)) (placeholderParams: @unchecked) match { @@ -1436,7 +1436,7 @@ self => } } } else if (in.token == MATCH) { - t = atPos(t.pos.startOrPoint, in.skipToken())(Match(stripParens(t), inBracesOrNil(caseClauses()))) + t = atPos(t.pos.start, in.skipToken())(Match(stripParens(t), inBracesOrNil(caseClauses()))) } // in order to allow anonymous functions as statements (as opposed to expressions) inside // templates, we have to disambiguate them from self type declarations - bug #1565 @@ -1447,7 +1447,7 @@ self => case _ => false } if (in.token == ARROW && (location != InTemplate || lhsIsTypedParamList)) { - t = atPos(t.pos.startOrPoint, in.skipToken()) { + t = atPos(t.pos.start, in.skipToken()) { Function(convertToParams(t), if (location != InBlock) expr() else block()) } } @@ -1586,14 +1586,14 @@ self => case Ident(_) | Select(_, _) | Apply(_, _) => var app: Tree = t1 while (in.token == LBRACKET) - app = atPos(app.pos.startOrPoint, in.offset)(TypeApply(app, exprTypeArgs())) + app = atPos(app.pos.start, in.offset)(TypeApply(app, exprTypeArgs())) simpleExprRest(app, canApply = true) case _ => t1 } case LPAREN | LBRACE if (canApply) => - val app = atPos(t.pos.startOrPoint, in.offset) { + val app = atPos(t.pos.start, in.offset) { // look for anonymous function application like (f _)(x) and // translate to (f _).apply(x), bug #460 val sel = t match { @@ -1606,7 +1606,7 @@ self => } simpleExprRest(app, canApply = true) case USCORE => - atPos(t.pos.startOrPoint, in.skipToken()) { + atPos(t.pos.start, in.skipToken()) { Typed(stripParens(t), Function(Nil, EmptyTree)) } case _ => @@ -1727,7 +1727,7 @@ self => while (in.token == IF) enums += makeFilter(in.offset, guard()) } - def makeFilter(start: Int, tree: Tree) = Filter(r2p(start, tree.pos.point, tree.pos.endOrPoint), tree) + def makeFilter(start: Int, tree: Tree) = Filter(r2p(start, tree.pos.point, tree.pos.end), tree) /* -------- PATTERNS ------------------------------------------- */ @@ -1793,7 +1793,7 @@ self => def pattern1(): Tree = pattern2() match { case p @ Ident(name) if in.token == COLON => if (treeInfo.isVarPattern(p)) - atPos(p.pos.startOrPoint, in.skipToken())(Typed(p, compoundType())) + atPos(p.pos.start, in.skipToken())(Typed(p, compoundType())) else { syntaxError(in.offset, "Pattern variables must start with a lower-case letter. (SLS 8.1.1.)") p @@ -1818,7 +1818,7 @@ self => pattern3() case Ident(name) if treeInfo.isVarPattern(p) => in.nextToken() - atPos(p.pos.startOrPoint) { Bind(name, pattern3()) } + atPos(p.pos.start) { Bind(name, pattern3()) } case _ => p } } @@ -1831,7 +1831,7 @@ self => def pattern3(): Tree = { var top = simplePattern(badPattern3) // after peekahead - def acceptWildStar() = atPos(top.pos.startOrPoint, in.prev.offset)(Star(stripParens(top))) + def acceptWildStar() = atPos(top.pos.start, in.prev.offset)(Star(stripParens(top))) def peekahead() = { in.prev copyFrom in in.nextToken() @@ -2220,7 +2220,7 @@ self => if (isRawStar) { in.nextToken() if (useStartAsPosition) atPos(start)(repeatedApplication(t)) - else atPos(t.pos.startOrPoint, t.pos.point)(repeatedApplication(t)) + else atPos(t.pos.start, t.pos.point)(repeatedApplication(t)) } else t } @@ -2689,7 +2689,7 @@ self => val contextBoundBuf = new ListBuffer[Tree] val tparams = typeParamClauseOpt(name, contextBoundBuf) classContextBounds = contextBoundBuf.toList - val tstart = (in.offset :: classContextBounds.map(_.pos.startOrPoint)).min + val tstart = (in.offset :: classContextBounds.map(_.pos.start)).min if (!classContextBounds.isEmpty && mods.isTrait) { val viewBoundsExist = if (settings.future) "" else " nor view bounds `<% ...'" syntaxError(s"traits cannot have type parameters with context bounds `: ...'$viewBoundsExist", skipIt = false) @@ -2746,7 +2746,7 @@ self => def packageObjectDef(start: Offset): PackageDef = { val defn = objectDef(in.offset, NoMods) val module = copyModuleDef(defn)(name = nme.PACKAGEkw) - val pid = atPos(o2p(defn.pos.startOrPoint))(Ident(defn.name)) + val pid = atPos(o2p(defn.pos.start))(Ident(defn.name)) makePackaging(start, pid, module :: Nil) } @@ -2763,7 +2763,7 @@ self => def makePackageObject(start: Int, objDef: ModuleDef): PackageDef = objDef match { case ModuleDef(mods, name, impl) => makePackaging( - start, atPos(o2p(objDef.pos.startOrPoint)){ Ident(name) }, List(ModuleDef(mods, nme.PACKAGEkw, impl))) + start, atPos(o2p(objDef.pos.start)){ Ident(name) }, List(ModuleDef(mods, nme.PACKAGEkw, impl))) } /** {{{ @@ -3147,7 +3147,7 @@ self => if (stats forall (_ == EmptyTree)) 0 else { val wpos = wrappingPos(stats) - if (wpos.isDefined) wpos.startOrPoint + if (wpos.isDefined) wpos.start else 0 } diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 0d93a1b427..2d38848f90 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -8,7 +8,7 @@ package ast.parser import symtab.Flags._ import scala.collection.mutable.ListBuffer -import scala.reflect.internal.util.OffsetPosition +import scala.reflect.internal.util.Position /** Methods for building trees, used in the parser. All the trees * returned by this class must be untyped. @@ -193,7 +193,7 @@ abstract class TreeBuilder { /** Tree for `od op`, start is start0 if od.pos is borked. */ def makePostfixSelect(start0: Int, end: Int, od: Tree, op: Name): Tree = { - val start = if (od.pos.isDefined) od.pos.startOrPoint else start0 + val start = if (od.pos.isDefined) od.pos.start else start0 atPos(r2p(start, end, end + op.length)) { new PostfixSelect(od, op.encode) } } @@ -201,7 +201,7 @@ abstract class TreeBuilder { def makeWhile(startPos: Int, cond: Tree, body: Tree): Tree = { val lname = freshTermName(nme.WHILE_PREFIX) def default = wrappingPos(List(cond, body)) match { - case p if p.isDefined => p.endOrPoint + case p if p.isDefined => p.end case _ => startPos } val continu = atPos(o2p(body.pos pointOrElse default)) { Apply(Ident(lname), Nil) } @@ -339,9 +339,9 @@ abstract class TreeBuilder { def closurePos(genpos: Position) = { val end = body.pos match { case NoPosition => genpos.point - case bodypos => bodypos.endOrPoint + case bodypos => bodypos.end } - r2p(genpos.startOrPoint, genpos.point, end) + r2p(genpos.start, genpos.point, end) } // val result = @@ -369,7 +369,7 @@ abstract class TreeBuilder { List(ValFrom(pos, defpat1, rhs)), Block(pdefs, atPos(wrappingPos(ids)) { makeTupleTerm(ids, flattenUnary = true) }) setPos wrappingPos(pdefs)) val allpats = (pat :: pats) map (_.duplicate) - val vfrom1 = ValFrom(r2p(pos.startOrPoint, pos.point, rhs1.pos.endOrPoint), atPos(wrappingPos(allpats)) { makeTuple(allpats, isType = false) } , rhs1) + val vfrom1 = ValFrom(r2p(pos.start, pos.point, rhs1.pos.end), atPos(wrappingPos(allpats)) { makeTuple(allpats, isType = false) } , rhs1) makeFor(mapName, flatMapName, vfrom1 :: rest1, body) case _ => EmptyTree //may happen for erroneous input @@ -529,6 +529,6 @@ abstract class UnitTreeBuilder extends TreeBuilder { def freshName(prefix: String): Name = freshTermName(prefix) def freshTermName(prefix: String): TermName = unit.freshTermName(prefix) def freshTypeName(prefix: String): TypeName = unit.freshTypeName(prefix) - def o2p(offset: Int): Position = new OffsetPosition(unit.source, offset) + def o2p(offset: Int): Position = Position.offset(unit.source, offset) def r2p(start: Int, mid: Int, end: Int): Position = rangePos(unit.source, start, mid, end) } diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index 8d025b5451..2f6f9620a8 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -2316,8 +2316,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM { lastLineNr = currentLineNr val lineLab = new asm.Label jmethod.visitLabel(lineLab) - val actual = iPos inUltimateSource iPos.source - lnEntries ::= LineNumberEntry(actual.line, lineLab) + lnEntries ::= LineNumberEntry(iPos.finalPosition.line, lineLab) } } diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index c34ff0ce97..7932dd3459 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -8,11 +8,11 @@ package scala.tools.nsc package javac -import scala.reflect.internal.util.OffsetPosition import scala.collection.mutable.ListBuffer import symtab.Flags import JavaTokens._ import scala.language.implicitConversions +import scala.reflect.internal.util.Position trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val global : Global @@ -27,7 +27,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def freshTermName(prefix: String): TermName = unit.freshTermName(prefix) def freshTypeName(prefix: String): TypeName = unit.freshTypeName(prefix) def deprecationWarning(off: Int, msg: String) = unit.deprecationWarning(off, msg) - implicit def i2p(offset : Int) : Position = new OffsetPosition(unit.source, offset) + implicit def i2p(offset : Int) : Position = Position.offset(unit.source, offset) def warning(pos : Int, msg : String) : Unit = unit.warning(pos, msg) def syntaxError(pos: Int, msg: String) : Unit = unit.error(pos, msg) } diff --git a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala index e987b6de2f..b7ea70e2c7 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala @@ -863,6 +863,6 @@ trait JavaScanners extends ast.parser.ScannersCommon { def error (pos: Int, msg: String) = unit. error(pos, msg) def incompleteInputError(pos: Int, msg: String) = unit.incompleteInputError(pos, msg) def deprecationWarning(pos: Int, msg: String) = unit.deprecationWarning(pos, msg) - implicit def g2p(pos: Int): Position = new OffsetPosition(unit.source, pos) + implicit def g2p(pos: Int): Position = Position.offset(unit.source, pos) } } diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index e68f55a09e..d97f62d5d6 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -337,7 +337,7 @@ abstract class UnCurry extends InfoTransform arg setType functionType(Nil, arg.tpe) } else { - log(s"Argument '$arg' at line ${arg.pos.safeLine} is $formal from ${fun.fullName}") + log(s"Argument '$arg' at line ${arg.pos.line} is $formal from ${fun.fullName}") def canUseDirectly(recv: Tree) = ( recv.tpe.typeSymbol.isSubClass(FunctionClass(0)) && treeInfo.isExprSafeToInline(recv) diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 315496e5f6..abc5363423 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -1269,7 +1269,7 @@ trait Contexts { self: Analyzer => def importedSymbol(name: Name): Symbol = importedSymbol(name, requireExplicit = false) private def recordUsage(sel: ImportSelector, result: Symbol) { - def posstr = pos.source.file.name + ":" + posOf(sel).safeLine + def posstr = pos.source.file.name + ":" + posOf(sel).line def resstr = if (tree.symbol.hasCompleteInfo) s"(qual=$qual, $result)" else s"(expr=${tree.expr}, ${result.fullLocationString})" debuglog(s"In $this at $posstr, selector '${selectorString(sel)}' resolved to $resstr") allUsedSelectors(this) += sel diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2a2fd889ad..d74fa50dcb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5127,7 +5127,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper // @M causes cyclic reference error devWarning(s"exception when typing $tree, pt=$ptPlugins") if (context != null && context.unit.exists && tree != null) - logError("AT: " + (tree.pos).dbgString, ex) + logError("AT: " + tree.pos, ex) throw ex } } diff --git a/src/compiler/scala/tools/reflect/MacroImplementations.scala b/src/compiler/scala/tools/reflect/MacroImplementations.scala index 4e3761454d..a9ed419b1e 100644 --- a/src/compiler/scala/tools/reflect/MacroImplementations.scala +++ b/src/compiler/scala/tools/reflect/MacroImplementations.scala @@ -3,7 +3,7 @@ package scala.tools.reflect import scala.reflect.macros.contexts.Context import scala.collection.mutable.ListBuffer import scala.collection.mutable.Stack -import scala.reflect.internal.util.OffsetPosition +import scala.reflect.internal.util.Position abstract class MacroImplementations { val c: Context @@ -91,7 +91,7 @@ abstract class MacroImplementations { def isConversion(idx: Int) = isPercent(idx) && !charAtIndexIs(idx + 1, 'n') && !charAtIndexIs(idx + 1, '%') var idx = 0 - def errorAtIndex(idx: Int, msg: String) = c.error(new OffsetPosition(strTree.pos.source, strTree.pos.point + idx), msg) + def errorAtIndex(idx: Int, msg: String) = c.error(Position.offset(strTree.pos.source, strTree.pos.point + idx), msg) def wrongConversionString(idx: Int) = errorAtIndex(idx, "wrong conversion string") def illegalConversionCharacter(idx: Int) = errorAtIndex(idx, "illegal conversion character") def nonEscapedPercent(idx: Int) = errorAtIndex(idx, |