diff options
author | Sean McDirmid <sean.mcdirmid@gmail.com> | 2007-04-19 05:16:02 +0000 |
---|---|---|
committer | Sean McDirmid <sean.mcdirmid@gmail.com> | 2007-04-19 05:16:02 +0000 |
commit | 2ef5d4c6d81e5008fdb2ae1b4f2ecdd9d9901fd2 (patch) | |
tree | 1d1b222bd6a0caa29c0a02e465842bdf30cfae52 /src/compiler/scala/tools/nsc/typechecker | |
parent | e43c7bef06d64b98f00752bd06510768ba37910a (diff) | |
download | scala-2ef5d4c6d81e5008fdb2ae1b4f2ecdd9d9901fd2.tar.gz scala-2ef5d4c6d81e5008fdb2ae1b4f2ecdd9d9901fd2.tar.bz2 scala-2ef5d4c6d81e5008fdb2ae1b4f2ecdd9d9901fd2.zip |
Switching over to position objects from positio...
Switching over to position objects from position type parameters.
Positions are no longer ints.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker')
7 files changed, 51 insertions, 50 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 6943c78226..a4990fc865 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -7,7 +7,7 @@ package scala.tools.nsc.typechecker import symtab.Flags._ -import scala.tools.nsc.util.Position +import scala.tools.nsc.util.{Position,NoPosition} /** This trait ... * @@ -42,7 +42,7 @@ trait Contexts requires Analyzer { val qual = gen.mkAttributedStableRef(pkg) sc = sc.makeNewImport( Import(qual, List((nme.WILDCARD, null))) - .setSymbol(NoSymbol.newImport(NoPos).setFlag(SYNTHETIC).setInfo(ImportType(qual))) + .setSymbol(NoSymbol.newImport(NoPosition).setFlag(SYNTHETIC).setInfo(ImportType(qual))) .setType(NoType)) sc.depth = sc.depth + 1 } @@ -253,7 +253,7 @@ trait Contexts requires Analyzer { c } - def error(pos: Int, err: Error) { + def error(pos: Position, err: Error) { val msg = err.getMessage() if (reportGeneralErrors) unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg) @@ -261,14 +261,14 @@ trait Contexts requires Analyzer { throw err } - def error(pos: PositionType, msg: String) { + def error(pos: Position, msg: String) { if (reportGeneralErrors) unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg) else throw new TypeError(pos, msg) } - def warning(pos: PositionType, msg: String) { + def warning(pos: Position, msg: String) { if (reportGeneralErrors) unit.warning(pos, msg) } @@ -279,7 +279,7 @@ trait Contexts requires Analyzer { * @param sym2 ... * @param rest ... */ - def ambiguousError(pos: PositionType, pre: Type, sym1: Symbol, + def ambiguousError(pos: Position, pre: Type, sym1: Symbol, sym2: Symbol, rest: String): unit = { val msg = ("ambiguous reference to overloaded definition,\n" + diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index a0ee58feab..af34a088df 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -5,7 +5,7 @@ // $Id$ package scala.tools.nsc.typechecker - +import scala.tools.nsc.util.{Position, NoPosition} import scala.collection.mutable.ListBuffer import symtab.Flags._ @@ -55,7 +55,7 @@ trait Infer requires Analyzer { List(if (actuals.length == 0) UnitClass.tpe else tupleType(actuals)) else actuals - def actualArgs(pos: PositionType, actuals: List[Tree], nformals: int): List[Tree] = + def actualArgs(pos: Position, actuals: List[Tree], nformals: int): List[Tree] = if (nformals == 1 && actuals.length != 1) List(atPos(pos)(gen.mkTuple(actuals))) else actuals /** A fresh type varable with given type parameter as origin. @@ -257,7 +257,7 @@ trait Infer requires Analyzer { "\n possible cause: missing arguments for method or constructor" else "") - def error(pos: PositionType, msg: String): unit = + def error(pos: Position, msg: String): unit = context.error(pos, msg) def errorTree(tree: Tree, msg: String): Tree = { @@ -265,7 +265,7 @@ trait Infer requires Analyzer { setError(tree) } - def typeError(pos: PositionType, found: Type, req: Type) { + def typeError(pos: Position, found: Type, req: Type) { if (!found.isErroneous && !req.isErroneous) { error(pos, typeErrorMsg(found, req)) if (settings.explaintypes.value) explainTypes(found, req) @@ -594,7 +594,7 @@ trait Infer requires Analyzer { } /** error if arguments not within bounds. */ - def checkBounds(pos: PositionType, pre: Type, owner: Symbol, + def checkBounds(pos: Position, pre: Type, owner: Symbol, tparams: List[Symbol], targs: List[Type], prefix: String) = { //@M validate variances & bounds of targs wrt variances & bounds of tparams //@M TODO: better place to check this? @@ -897,7 +897,7 @@ trait Infer requires Analyzer { } } - def checkCheckable(pos: PositionType, tp: Type): unit = { + def checkCheckable(pos: Position, tp: Type): unit = { def patternWarning(tp: Type, prefix: String) = context.unit.uncheckedWarning(pos, prefix+tp+" in type pattern is unchecked since it is eliminated by erasure") def isLocalBinding(sym: Symbol) = @@ -954,7 +954,7 @@ trait Infer requires Analyzer { } } - def inferTypedPattern(pos: PositionType, pattp: Type, pt: Type): Type = { + def inferTypedPattern(pos: Position, pattp: Type, pt: Type): Type = { checkCheckable(pos, pattp) if (!(pattp <:< pt)) { val tpparams = freeTypeParamsOfTerms.collect(pattp) @@ -1049,7 +1049,7 @@ trait Infer requires Analyzer { /* -- Overload Resolution ---------------------------------------------- */ - def checkNotShadowed(pos: PositionType, pre: Type, best: Symbol, eligible: List[Symbol]) = + def checkNotShadowed(pos: Position, pre: Type, best: Symbol, eligible: List[Symbol]) = if (!phase.erasedTypes) for (val alt <- eligible) { if (alt.owner != best.owner && alt.owner.isSubClass(best.owner)) diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 969ab1cce2..9adfbe07fc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -65,7 +65,7 @@ trait Namers requires Analyzer { sym } - def updatePosFlags(sym: Symbol, pos: PositionType, flags: long): Symbol = { + def updatePosFlags(sym: Symbol, pos: Position, flags: long): Symbol = { if (settings.debug.value) log("overwriting " + sym) val lockedFlag = sym.flags & LOCKED sym.reset(NoType) @@ -114,7 +114,7 @@ trait Namers requires Analyzer { innerNamer } - private def doubleDefError(pos: PositionType, sym: Symbol): unit = + private def doubleDefError(pos: Position, sym: Symbol): unit = context.error(pos, sym.name.toString() + " is already defined as " + (if (sym.hasFlag(CASE)) "case class " + sym.name else sym.toString())) @@ -135,7 +135,7 @@ trait Namers requires Analyzer { sym } - def enterPackageSymbol(pos: PositionType, name: Name): Symbol = { + def enterPackageSymbol(pos: Position, name: Name): Symbol = { val cscope = if (context.owner == EmptyPackageClass) RootClass.info.decls else context.scope val p: Symbol = cscope.lookup(name) @@ -154,7 +154,7 @@ trait Namers requires Analyzer { if (context.owner.isConstructor && !context.inConstructorSuffix) INCONSTRUCTOR else 0l - private def enterClassSymbol(pos: PositionType, flags: long, name: Name): Symbol = { + private def enterClassSymbol(pos: Position, flags: long, name: Name): Symbol = { var c: Symbol = context.scope.lookup(name) if (c.isType && !currentRun.compiles(c) && context.scope == c.owner.info.decls) { updatePosFlags(c, pos, flags) @@ -176,7 +176,7 @@ trait Namers requires Analyzer { c } - private def enterModuleSymbol(pos: PositionType, flags: long, name: Name): Symbol = { + private def enterModuleSymbol(pos: Position, flags: long, name: Name): Symbol = { var m: Symbol = context.scope.lookup(name) if (m.isModule && !m.isPackage && !currentRun.compiles(m) && (context.scope == m.owner.info.decls)) { @@ -196,7 +196,7 @@ trait Namers requires Analyzer { m } - private def enterCaseFactorySymbol(pos: PositionType, flags: long, name: Name): Symbol = { + private def enterCaseFactorySymbol(pos: Position, flags: long, name: Name): Symbol = { var m: Symbol = context.scope.lookup(name) if (m.isTerm && !m.isPackage && !currentRun.compiles(m) && context.scope == m.owner.info.decls) { updatePosFlags(m, pos, flags) @@ -677,7 +677,7 @@ trait Namers requires Analyzer { val expr1 = typer.typedQualifier(expr) val base = expr1.tpe typer.checkStable(expr1) - def checkNotRedundant(pos: PositionType, from: Name, to: Name): boolean = { + def checkNotRedundant(pos: Position, from: Name, to: Name): boolean = { if (!tree.symbol.hasFlag(SYNTHETIC) && !((expr1.symbol ne null) && expr1.symbol.isInterpreterWrapper) && base.member(from) != NoSymbol) { diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index cfb4c3e270..3d8c664ae6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -9,7 +9,7 @@ package scala.tools.nsc.typechecker import symtab.Flags._ import collection.mutable.HashMap import transform.InfoTransform - +import scala.tools.nsc.util.{Position, NoPosition} import compat.Math.MIN_INT /** <p> @@ -422,7 +422,7 @@ abstract class RefChecks extends InfoTransform { class LevelInfo(val outer: LevelInfo) { val scope: Scope = if (outer eq null) newScope else newScope(outer.scope) var maxindex: int = MIN_INT - var refpos: int = _ + var refpos: Position = _ var refsym: Symbol = _ } @@ -451,7 +451,7 @@ abstract class RefChecks extends InfoTransform { } } - private def enterReference(pos: int, sym: Symbol): unit = + private def enterReference(pos: Position, sym: Symbol): unit = if (sym.isLocal) { val e = currentLevel.scope.lookupEntry(sym.name) if ((e ne null) && sym == e.sym) { @@ -471,7 +471,7 @@ abstract class RefChecks extends InfoTransform { def apply(tp: Type) = mapOver(tp).normalize } - def checkSensible(pos: int, fn: Tree, args: List[Tree]) = fn match { + def checkSensible(pos: Position, fn: Tree, args: List[Tree]) = fn match { case Select(qual, name) if (args.length == 1) => def isNew(tree: Tree) = tree match { case Function(_, _) @@ -519,7 +519,7 @@ abstract class RefChecks extends InfoTransform { // Transformation ------------------------------------------------------------ /* Convert a reference to a case factory of type `tpe' to a new of the class it produces. */ - def toConstructor(pos: PositionType, tpe: Type): Tree = { + def toConstructor(pos: Position, tpe: Type): Tree = { var rtpe = tpe.finalResultType assert(rtpe.symbol hasFlag CASE, tpe); localTyper.typedOperator { diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 61bd300472..0b88b7e340 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -8,6 +8,7 @@ package scala.tools.nsc.typechecker import scala.collection.mutable.ListBuffer import nsc.symtab.Flags._ +import scala.tools.nsc.util.{Position} /** This phase adds super accessors for all super calls that * either appear in a trait or have as a target a member of some outer class. @@ -289,7 +290,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT * inherit anything. Since we can't (yet) add accessors for 'required' * classes, this has to be signaled as error. */ - private def needsProtectedAccessor(sym: Symbol, pos: PositionType): Boolean = { + private def needsProtectedAccessor(sym: Symbol, pos: Position): Boolean = { val res = /* settings.debug.value && */ ((sym hasFlag PROTECTED) && (!validCurrentOwner || !(currentOwner.enclClass.thisSym isSubClass sym.owner)) diff --git a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala index 2cceae8059..88e630705a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala @@ -8,7 +8,7 @@ package scala.tools.nsc.typechecker import scala.tools.nsc.reporters.AbstractReporter import scala.tools.nsc.symtab.Flags._ -import scala.tools.nsc.util.Position +import scala.tools.nsc.util.{Position, NoPosition} abstract class TreeCheckers extends Analyzer { @@ -99,7 +99,7 @@ abstract class TreeCheckers extends Analyzer { } case _ => } - if (tree.pos == NoPos && tree != EmptyTree) { + if (tree.pos == NoPosition && tree != EmptyTree) { error(tree.pos, "tree without position: " + tree) } else if ((tree.tpe eq null) && phase.id >= currentRun.typerPhase.id) { error(tree.pos, "tree without type: " + tree) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 38a7bcea62..cec250063a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -12,7 +12,7 @@ package scala.tools.nsc.typechecker import scala.collection.mutable.{HashMap, ListBuffer} import scala.compat.Platform.currentTime -import scala.tools.nsc.util.{HashSet, Position, Set} +import scala.tools.nsc.util.{HashSet, Position, Set, NoPosition} import symtab.Flags._ import util.HashSet @@ -144,7 +144,7 @@ trait Typers requires Analyzer { override def isCoercible(tp: Type, pt: Type): boolean = ( tp.isError || pt.isError || context0.implicitsEnabled && // this condition prevents chains of views - inferView(NoPos, tp, pt, false) != EmptyTree + inferView(NoPosition, tp, pt, false) != EmptyTree ) } @@ -155,7 +155,7 @@ trait Typers requires Analyzer { * @param reportAmbiguous ... * @return ... */ - private def inferView(pos: PositionType, from: Type, to: Type, reportAmbiguous: boolean): Tree = { + private def inferView(pos: Position, from: Type, to: Type, reportAmbiguous: boolean): Tree = { if (settings.debug.value) log("infer view from "+from+" to "+to)//debug if (phase.id > currentRun.typerPhase.id) EmptyTree else from match { @@ -180,7 +180,7 @@ trait Typers requires Analyzer { * @param reportAmbiguous ... * @return ... */ - private def inferView(pos: PositionType, from: Type, name: Name, tp: Type, reportAmbiguous: boolean): Tree = { + private def inferView(pos: Position, from: Type, name: Name, tp: Type, reportAmbiguous: boolean): Tree = { val to = refinedType(List(WildcardType), NoSymbol) val psym = (if (name.isTypeName) to.symbol.newAbstractType(pos, name) else to.symbol.newValue(pos, name)) setInfo tp @@ -205,9 +205,9 @@ trait Typers requires Analyzer { * @param pos0 The position where to report the error * @param ex The exception that caused the error */ - def reportTypeError(pos0: PositionType, ex: TypeError): unit = { + def reportTypeError(pos0: Position, ex: TypeError): unit = { if (settings.debug.value) ex.printStackTrace() - val pos = if (ex.pos == NoPos) pos0 else ex.pos + val pos = if (ex.pos == NoPosition) pos0 else ex.pos ex match { case CyclicReference(sym, info: TypeCompleter) => val msg = @@ -244,7 +244,7 @@ trait Typers requires Analyzer { * @param tp ... * @return <code>true</code> if <code>tp</code> is not a subtype of itself. */ - def checkNonCyclic(pos: PositionType, tp: Type): boolean = { + def checkNonCyclic(pos: Position, tp: Type): boolean = { def checkNotLocked(sym: Symbol): boolean = { sym.initialize if (sym hasFlag LOCKED) { @@ -271,7 +271,7 @@ trait Typers requires Analyzer { } } - def checkNonCyclic(pos: PositionType, tp: Type, lockedSym: Symbol): boolean = { + def checkNonCyclic(pos: Position, tp: Type, lockedSym: Symbol): boolean = { lockedSym.setFlag(LOCKED) val result = checkNonCyclic(pos, tp) lockedSym.resetFlag(LOCKED) @@ -288,7 +288,7 @@ trait Typers requires Analyzer { } } - def checkParamsConvertible(pos: PositionType, tpe: Type): unit = tpe match { + def checkParamsConvertible(pos: Position, tpe: Type): unit = tpe match { case MethodType(formals, restpe) => if (formals.exists(.symbol.==(ByNameParamClass)) && formals.length != 1) error(pos, "methods with `=>'-parameter can be converted to function values only if they take no other parameters") @@ -298,7 +298,7 @@ trait Typers requires Analyzer { case _ => } - def checkRegPatOK(pos: PositionType, mode: int): unit = + def checkRegPatOK(pos: Position, mode: int): unit = if ((mode & REGPATmode) == 0) { error(pos, "no regular expression pattern allowed here\n"+ "(regular expression patterns are only allowed in arguments to *-parameters)") @@ -644,7 +644,7 @@ trait Typers requires Analyzer { } catch { case tpe : TypeError => throw tpe case t : Throwable => - logError("CONTEXT: " + context.unit.source.dbg(tree.pos), t) + logError("CONTEXT: " + (tree.pos).dbgString, t) throw t } tree1 @@ -1395,7 +1395,7 @@ trait Typers requires Analyzer { val result = checkDead(localTyper.typed(stat)) if (treeInfo.isSelfOrSuperConstrCall(result)) { context.inConstructorSuffix = true - if (treeInfo.isSelfConstrCall(result) && result.symbol.pos >= exprOwner.enclMethod.pos) + if (treeInfo.isSelfConstrCall(result) && result.symbol.pos.offset.get(0) >= exprOwner.enclMethod.pos.offset.get(0)) error(stat.pos, "called constructor's definition must precede calling constructor's definition") } result @@ -1645,7 +1645,7 @@ trait Typers requires Analyzer { def typedAnnotation[T](annot: Annotation, reify: Tree => T): AnnotationInfo[T] = { var attrError: Boolean = false; - def error(pos: PositionType, msg: String): Null = { + def error(pos: Position, msg: String): Null = { context.error(pos, msg) attrError = true null @@ -2160,8 +2160,8 @@ trait Typers requires Analyzer { qual.tpe.widen+" does not have a constructor" else decode(name)+" is not a member of "+qual.tpe.widen + - (if (!inIDE && (context.unit ne null) && Position.line(context.unit.source, qual.pos) < - Position.line(context.unit.source, tree.pos)) + (if (!inIDE && (context.unit ne null) && (qual.pos).line.get < + tree.pos.line.get) "\npossible cause: maybe a semicolon is missing before `"+decode(name)+"'?" else "")) } @@ -2232,9 +2232,9 @@ trait Typers requires Analyzer { defEntry = cx.scope.lookupEntry(name) if (inIDE && (defEntry ne null) && defEntry.sym.exists) { val sym = defEntry.sym - val namePos : Int = tree.pos - val symPos : Int = sym.pos - if (namePos < symPos) defEntry = null + val namePos : Position = tree.pos + val symPos : Position = sym.pos + if (namePos.offset.get < symPos.offset.get) defEntry = null } if ((defEntry ne null) && qualifies(defEntry.sym)) { defSym = defEntry.sym @@ -2629,7 +2629,7 @@ trait Typers requires Analyzer { // Console.println("exception when typing "+tree+", pt = "+pt) if ((context ne null) && (context.unit ne null) && (context.unit.source ne null) && (tree ne null)) - logError("AT: " + context.unit.source.dbg(tree.pos), ex); + logError("AT: " + (tree.pos).dbgString, ex); throw(ex) } @@ -2739,7 +2739,7 @@ trait Typers requires Analyzer { * to <code>pt</code>, EmptyTree otherwise. * @pre <code>info.tpe</code> does not contain an error */ - private def typedImplicit(pos: PositionType, info: ImplicitInfo, pt: Type, isLocal: boolean): Tree = { + private def typedImplicit(pos: Position, info: ImplicitInfo, pt: Type, isLocal: boolean): Tree = { def isStable(tp: Type): boolean = tp match { case TypeRef(pre, sym, _) => sym.isPackageClass || sym.isModuleClass && isStable(pre) case _ => tp.isStable @@ -2780,7 +2780,7 @@ trait Typers requires Analyzer { * @return ... * @see <code>isCoercible</code> */ - private def inferImplicit(pos: PositionType, pt: Type, isView: boolean, reportAmbiguous: boolean): Tree = { + private def inferImplicit(pos: Position, pt: Type, isView: boolean, reportAmbiguous: boolean): Tree = { if (util.Statistics.enabled) implcnt = implcnt + 1 val startTime = if (util.Statistics.enabled) currentTime else 0l |