diff options
author | Sean McDirmid <sean.mcdirmid@gmail.com> | 2007-05-22 10:23:00 +0000 |
---|---|---|
committer | Sean McDirmid <sean.mcdirmid@gmail.com> | 2007-05-22 10:23:00 +0000 |
commit | d13cbc73c321c7f677015920a378eabf825505f2 (patch) | |
tree | 5f1574bb79d65c0666ace4506eea8d2b01d05a08 /src/compiler | |
parent | 01e1d5902bfbe9b1f2398f07a34cd0cca0469429 (diff) | |
download | scala-d13cbc73c321c7f677015920a378eabf825505f2.tar.gz scala-d13cbc73c321c7f677015920a378eabf825505f2.tar.bz2 scala-d13cbc73c321c7f677015920a378eabf825505f2.zip |
Massaging compiler to integrate with IDE, no su...
Massaging compiler to integrate with IDE, no supercial changes. Just
don't want to get out of synch with Martin's changes. Also, changed
compiler to use RichInt.until instead of Iterator.range
Diffstat (limited to 'src/compiler')
17 files changed, 204 insertions, 165 deletions
diff --git a/src/compiler/scala/tools/nsc/MainTokenMetric.scala b/src/compiler/scala/tools/nsc/MainTokenMetric.scala index 9a48f1d4b1..37dfd4a39d 100644 --- a/src/compiler/scala/tools/nsc/MainTokenMetric.scala +++ b/src/compiler/scala/tools/nsc/MainTokenMetric.scala @@ -17,16 +17,17 @@ object MainTokenMetric { private def tokenMetric(compiler: Global, fnames: List[String]) { import compiler.CompilationUnit - import compiler.syntaxAnalyzer.UnitScanner import ast.parser.Tokens.EOF var totale = 0 for (source <- fnames) { - val s = new UnitScanner(new CompilationUnit(compiler.getSourceFile(source))) var i = 0 + /* + import compiler.syntaxAnalyzer.UnitScanner + val s = new UnitScanner(new CompilationUnit(compiler.getSourceFile(source))) while (s.token != EOF) { i += 1 s.nextToken - } + }*/ var j = 0 ; while(j + Math.log(i) / Math.log(10) < 7) { j += 1 Console.print(' ') diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala index a8c537cb8a..4ffb2ef07a 100644 --- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala @@ -79,7 +79,7 @@ abstract class TreePrinters { } def symName(tree: Tree, name: Name): String = - if (tree.symbol != NoSymbol) { + if (tree.symbol != null && tree.symbol != NoSymbol) { ((if (tree.symbol.isMixinConstructor) "/*"+tree.symbol.owner.name+"*/" else "") + tree.symbol.nameString) } else name.toString(); diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 57a4f10bd2..90009ac9cd 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -113,10 +113,10 @@ trait Trees { } def equalsStructure(that: Tree): Boolean = { - val this0 = this.asInstanceOf[Product] - val that0 = that.asInstanceOf[Product] if (this == that) return true if (this.getClass != that.getClass) return false + val this0 = this.asInstanceOf[Product] + val that0 = that.asInstanceOf[Product] assert(this0.productArity == that0.productArity) def equals0(thiz: Any, that: Any): Boolean = thiz match { case thiz: Tree => @@ -205,7 +205,8 @@ trait Trees { def mods: Modifiers def keyword: String = this match { case AliasTypeDef(_, _, _, _) => "type" - case ClassDef(_, _, _, _) => "class" + case AbsTypeDef(_, _, _, _, _) => "type" + case _ : ClassDef => "class" case DefDef(_, _, _, _, _, _) => "def" case ModuleDef(_, _, _) => "object" case PackageDef(_, _) => "package" @@ -362,7 +363,7 @@ trait Trees { * @param hi */ case class AbsTypeDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], lo: Tree, hi: Tree) - extends DefTree { + extends MemberDef { def namePos = pos.offset.map(n => n - name.length).get(-1) } @@ -1513,7 +1514,7 @@ trait Trees { } object posAssigner extends Traverser { - private var pos: Position = _ + var pos: Position = _ override def traverse(t: Tree): unit = if (t != EmptyTree && t.pos == NoPosition) { t.setPos(pos) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 63d9115063..c938abb4bf 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -107,7 +107,7 @@ trait Parsers { object treeBuilder extends TreeBuilder { val global: Parsers.this.global.type = Parsers.this.global - def freshName(prefix: String): Name = Parser.this.freshName(prefix) + def freshName(prefix: String, pos : Position): Name = Parser.this.freshName(prefix) } import treeBuilder._ diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 36188676c8..045d60c005 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -497,7 +497,7 @@ trait Scanners { if (in.ch == '\"') { in.next; token = MULTI_QUOTE } else { - token = EMPTY_STRING + token = throw new Error } return } else { diff --git a/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala b/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala index 2d157e350a..4803fbfcce 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala @@ -22,10 +22,14 @@ object Tokens { final val DOUBLELIT = 5 final val STRINGLIT = 6 final val SYMBOLLIT = 7 + def isLiteral(code : Int) = + code >= CHARLIT && code <= SYMBOLLIT /** identifiers */ final val IDENTIFIER = 10 final val BACKQUOTED_IDENT = 11 + def isIdentifier(code : Int) = + code >= IDENTIFIER && code <= BACKQUOTED_IDENT /** keywords */ final val IF = 20 @@ -70,6 +74,10 @@ object Tokens { final val MATCH = 58 final val REQUIRES = 59 + def isKeyword(code : Int) = + code >= IF && code <= REQUIRES + + /** special symbols */ final val COMMA = 61 final val SEMI = 62 @@ -87,6 +95,10 @@ object Tokens { final val AT = 74 final val VIEWBOUND = 75 + def isSymbol(code : Int) = + code >= COMMA && code <= VIEWBOUND + + /** parenthesis */ final val LPAREN = 90 final val RPAREN = 91 @@ -95,6 +107,9 @@ object Tokens { final val LBRACE = 94 final val RBRACE = 95 + def isParen(code : Int) = + code >= LPAREN && code <= RBRACE + /** XML mode */ final val XMLSTART = 96 @@ -106,9 +121,10 @@ object Tokens { final val DOUBLE_QUOTE = 101 final val BACK_QUOTE = 102 final val MULTI_QUOTE = 103 - final val EMPTY_STRING = 104 + //final val EMPTY_STRING = 104 final val WHITESPACE = 105 final val IGNORE = 106 final val XML_SINGLEEND = 107 final val XML_STARTEND = 108 + final val ESCAPE = 109 } diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index e53dd1c66b..333005fc54 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -15,9 +15,9 @@ abstract class TreeBuilder { val global: Global import global._ import posAssigner.atPos; - def freshName(prefix: String): Name + def freshName(prefix: String, pos : Position): Name - def freshName(): Name = freshName("x$") + def freshName(pos : Position): Name = freshName("x$", pos) def scalaDot(name: Name): Tree = Select(Ident(nme.scala_) setSymbol definitions.ScalaPackage, name) @@ -128,7 +128,7 @@ abstract class TreeBuilder { if (treeInfo.isLeftAssoc(op)) { Apply(Select(stripParens(left), op.encode), arguments) } else { - val x = freshName(); + val x = freshName(posAssigner.pos); Block( List(ValDef(Modifiers(SYNTHETIC), x, TypeTree(), stripParens(left))), Apply(Select(stripParens(right), op.encode), List(Ident(x)))) @@ -279,7 +279,7 @@ abstract class TreeBuilder { def makeBind(pat: Tree): Tree = pat match { case Bind(_, _) => pat - case _ => Bind(freshName(), pat) + case _ => Bind(freshName(pat.pos), pat) } def makeValue(pat: Tree): Tree = pat match { @@ -373,7 +373,7 @@ abstract class TreeBuilder { /** Create visitor <x => x match cases> */ def makeVisitor(cases: List[CaseDef], checkExhaustive: boolean, prefix: String): Tree = { - val x = freshName(prefix) + val x = freshName(prefix, posAssigner.pos) val sel = if (checkExhaustive) Ident(x) else makeUnchecked(Ident(x)) Function(List(makeSyntheticParam(x)), Match(sel, cases)) } @@ -416,7 +416,7 @@ abstract class TreeBuilder { case List((vname, tpt)) => List(ValDef(mods, vname, tpt, matchExpr)) case _ => - val tmp = freshName() + val tmp = freshName(pat1.pos) val firstDef = ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC), tmp, TypeTree(), matchExpr) var cnt = 0 val restDefs = for (val (vname, tpt) <- vars) yield { @@ -438,7 +438,7 @@ abstract class TreeBuilder { /** Append implicit view section if for `implicitViews' if nonempty */ def addImplicitViews(owner: Name, vparamss: List[List[ValDef]], implicitViews: List[Tree]): List[List[ValDef]] = { val mods = Modifiers(if (owner.isTypeName) PARAMACCESSOR | LOCAL | PRIVATE else PARAM) - def makeViewParam(tpt: Tree) = ValDef(mods | IMPLICIT, freshName("view$"), tpt, EmptyTree) + def makeViewParam(tpt: Tree) = ValDef(mods | IMPLICIT, freshName("view$", tpt.pos), tpt, EmptyTree) if (implicitViews.isEmpty) vparamss else vparamss ::: List(implicitViews map makeViewParam) } diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 5ddf6b052d..69c9008e38 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -757,7 +757,7 @@ abstract class GenICode extends SubComponent { ctx1.bb.emit(MONITOR_EXIT(), tree.pos) ctx1 }, List( - // tree.tpe / fun.tpe is object, which is no longer true after this transformation + // tree.tpe / fun.tpe is object, which is no longer true after this transformation (NoSymbol, expectedType, exhCtx => { exhCtx.bb.emit(LOAD_LOCAL(monitor)) exhCtx.bb.emit(MONITOR_EXIT(), tree.pos) @@ -1538,7 +1538,7 @@ abstract class GenICode extends SubComponent { else if (block == fail) CJUMP(succ, cont, cond, kind) else - abort("Could not find block in preds")) + abort("Could not find block in preds: " + method + " " + block + " " + pred + " " + p)) case CZJUMP(succ, fail, cond, kind) => if (settings.debug.value) @@ -1834,7 +1834,7 @@ abstract class GenICode extends SubComponent { def newHandler(cls: Symbol, resultKind: TypeKind): ExceptionHandler = { handlerCount += 1 val exh = new ExceptionHandler(method, "" + handlerCount, cls) - exh.resultKind = resultKind + exh.resultKind = resultKind method.addHandler(exh) handlers = exh :: handlers if (settings.debug.value) diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 9ee4404cc9..2a54f0eb6b 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -216,8 +216,8 @@ abstract class GenJVM extends SubComponent { for (val AnnotationInfo(ThrowsAttr, List(exc), _) <- excs.removeDuplicates) { buf.putShort( - cpool.addClass( - javaName(exc.constant.get.typeValue.symbol)).shortValue) + cpool.addClass( + javaName(exc.constant.get.typeValue.symbol)).shortValue) nattr = nattr + 1 } @@ -522,7 +522,7 @@ abstract class GenJVM extends SubComponent { { val paramJavaTypes = m.tpe.paramTypes map (t => toTypeKind(t)); val paramNames: Array[String] = new Array[String](paramJavaTypes.length); - for (val i <- Iterator.range(0, paramJavaTypes.length)) + for (val i <- 0.until(paramJavaTypes.length)) paramNames(i) = "x_" + i val mirrorMethod = mirrorClass .addNewMethod(ACC_PUBLIC | ACC_FINAL | ACC_STATIC, @@ -984,8 +984,8 @@ abstract class GenJVM extends SubComponent { if (b.lastInstruction == instr) endPC(b) = jcode.getPC(); - //System.err.println("CRTLINE: " + instr.pos + " " + - // /* (if (instr.pos < clasz.cunit.source.content.length) clasz.cunit.source.content(instr.pos) else '*') + */ " " + crtLine); + //System.err.println("CRTLINE: " + instr.pos + " " + + // /* (if (instr.pos < clasz.cunit.source.content.length) clasz.cunit.source.content(instr.pos) else '*') + */ " " + crtLine); if (crtPC > lastMappedPC) { jcode.completeLineNumber(lastMappedPC, crtPC, crtLine) diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala index 4eb8f987da..b73ac3329b 100644 --- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala +++ b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala @@ -1988,7 +1988,7 @@ abstract class GenMSIL extends SubComponent { if (parents.length > 1) { if (settings.debug.value){ log("interfaces:") - for (i <- Iterator.range(0, interfaces.length)){ + for (i <- 0.until(interfaces.length)){ log(" type: " + parents(i + 1).symbol + ", msil type: " + interfaces(i)) } } @@ -2039,7 +2039,7 @@ abstract class GenMSIL extends SubComponent { if (m.symbol.isClassConstructor) { val constr = ownerType.DefineConstructor(attr, CallingConventions.Standard, paramTypes) - for (i <- Iterator.range(0, paramTypes.length)) { + for (i <- 0.until(paramTypes.length)) { constr.DefineParameter(i, ParameterAttributes.None, msilName(m.params(i).sym)) } mapConstructor(sym, constr) @@ -2048,7 +2048,7 @@ abstract class GenMSIL extends SubComponent { var resType = msilType(m.returnType) val method = ownerType.DefineMethod(getMethodName(sym), attr, resType, paramTypes) - for (i <- Iterator.range(0, paramTypes.length)){ + for (i <- 0.until(paramTypes.length)){ method.DefineParameter(i, ParameterAttributes.None, msilName(m.params(i).sym)) } if (!methods.contains(sym)) @@ -2182,7 +2182,7 @@ abstract class GenMSIL extends SubComponent { val mirrorCode = mirrorMethod.GetILGenerator() mirrorCode.Emit(OpCodes.Ldsfld, getModuleInstanceField(sym)) - Iterator.range(0, paramTypes.length) foreach loadArg(mirrorCode) + 0.until(paramTypes.length) foreach loadArg(mirrorCode) mirrorCode.Emit(OpCodes.Call, getMethod(m)) mirrorCode.Emit(OpCodes.Ret) diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 8e73c62a19..b418ac22be 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -37,7 +37,7 @@ trait ParallelMatching { class SwitchRule(val scrutinee:Symbol, val column:List[Tree], val rest:Rep) extends MixtureRule(scrutinee,column,rest) { def getTransition() = { //here, we generate a switch tree, bodies of the switch is the corresponding [[row in rest]] - //if a default case has to be handled, body is [[that row + the default row]] + //if a default case has to be handled, body is [[that row + the default row]] } } */ @@ -92,10 +92,10 @@ trait ParallelMatching { However, if you uncomment them you will get a bug in genLoad: ^ [locker] java.lang.AssertionError: assertion failed: Trying to access the this of another class: tree.symbol = class TreeBrowsers, ctx.clazz.symbol = object TreeBrowsers$TreeInfo compilation unit:TreeBrowsers.scala - [locker] at scala.Predef$.assert(Predef.scala:90) - [locker] at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:809) - [locker] at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:996) - [locker] at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:785) + [locker] at scala.Predef$.assert(Predef.scala:90) + [locker] at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:809) + [locker] at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:996) + [locker] at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:785) (pat.symbol != NoSymbol) && pat.symbol.tpe.prefix.isStable && */ //{Console.println(pat.symbol+" "+definitions.isValueType(patternType.symbol)); !definitions.isValueType(patternType.symbol)}&& @@ -399,7 +399,7 @@ object Rep { for (open <- allcomb if !(row exists { r => covers(r._1, open)})) { sb.append("missing combination ") val NPAD = 15 - def pad(s:String) = { Iterator.range(1,NPAD - s.length).foreach { x => sb.append(" ") }; sb.append(s) } + def pad(s:String) = { 1.until(NPAD - s.length).foreach { x => sb.append(" ") }; sb.append(s) } List.range(0, temp.length) foreach { i => open.find { case (j,sym) => j==i } match { case None => pad("*") @@ -447,7 +447,7 @@ object Rep { override def toString = { val sb = new StringBuilder val NPAD = 15 - def pad(s:String) = { Iterator.range(1,NPAD - s.length).foreach { x => sb.append(" ") }; sb.append(s) } + def pad(s:String) = { 1.until(NPAD - s.length).foreach { x => sb.append(" ") }; sb.append(s) } for (tmp <- temp) pad(tmp.name.toString) sb.append('\n') for ((r,i) <- row.zipWithIndex) { diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index d991a2e601..63a6f1151a 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -62,7 +62,10 @@ abstract class ClassfileParser { def parse(file: AbstractFile, root: Symbol): unit = { def handleError(e: Exception) = { if (settings.debug.value) e.printStackTrace();//debug - throw new IOException("class file '" + in.file + "' is broken\n(" + e.getMessage() + ")") + throw new IOException("class file '" + in.file + "' is broken\n(" + { + if (e.getMessage() != null) e.getMessage() + else e.getClass.toString + } + ")") } assert(!busy) busy = true diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 4e4e95e25b..9f5b1e2b35 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -227,7 +227,7 @@ trait Contexts requires Analyzer { //todo: find out why we need next line while (baseContext.tree.isInstanceOf[Template]) baseContext = baseContext.outer - val argContext = baseContext.makeNewScope(tree, owner) + val argContext = Contexts.this.makeNewScope(baseContext, tree, owner) argContext.reportGeneralErrors = this.reportGeneralErrors argContext.reportAmbiguousErrors = this.reportAmbiguousErrors def enterElems(c: Context) { diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 10b390f041..7fcb5bd9ae 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -80,22 +80,23 @@ trait Namers requires Analyzer { private var innerNamerCache: Namer = null - def namerOf(sym: Symbol): Namer = { + protected def newNamer(context : Context) : Namer = new Namer(context) + def namerOf(sym: Symbol): Namer = { def innerNamer: Namer = { if (innerNamerCache eq null) innerNamerCache = if (!isTemplateContext(context)) this - else new Namer(context.make(context.tree, context.owner, newScope)) + else newNamer(context.make(context.tree, context.owner, newScope)) innerNamerCache } def primaryConstructorParamNamer: Namer = { //todo: can we merge this with SCCmode? val classContext = context.enclClass val outerContext = classContext.outer.outer - val paramContext = outerContext.makeNewScope(outerContext.tree, outerContext.owner) + val paramContext = makeNewScope(outerContext, outerContext.tree, outerContext.owner) classContext.owner.unsafeTypeParams foreach paramContext.scope.enter - new Namer(paramContext) + newNamer(paramContext) } if (sym.isTerm && @@ -110,10 +111,11 @@ trait Namers requires Analyzer { sym.name.toString() + " is already defined as " + (if (sym.hasFlag(CASE)) "case class " + sym.name else sym.toString())) - def enterInScope(sym: Symbol): Symbol = { + def enterInScope[Sym <: Symbol](sym: Sym): Sym = { // allow for overloaded methods if (!(sym.isSourceMethod && sym.owner.isClass && !sym.owner.isPackageClass)) { val prev = context.scope.lookupEntry(sym.name); + if ((prev ne null) && (prev.sym eq sym)) return sym if ((prev ne null) && prev.owner == context.scope && (!prev.sym.isSourceMethod || nme.isSetterName(sym.name) || @@ -126,6 +128,7 @@ trait Namers requires Analyzer { sym } + def enterPackageSymbol(pos: Position, name: Name): Symbol = { val cscope = if (context.owner == EmptyPackageClass) RootClass.info.decls else context.scope @@ -134,10 +137,10 @@ trait Namers requires Analyzer { p } else { val cowner = if (context.owner == EmptyPackageClass) RootClass else context.owner - val pkg = cowner.newPackage(pos, name) + val pkg = newPackage(cowner, pos, name) pkg.moduleClass.setInfo(new PackageClassInfoType(newScope, pkg.moduleClass)) - pkg.setInfo(pkg.moduleClass.tpe) - enterInScope(pkg) + //pkg.setInfo(pkg.moduleClass.tpe) + enterInScope(pkg) setInfo (pkg.moduleClass.tpe) } } @@ -145,12 +148,14 @@ trait Namers requires Analyzer { if (context.owner.isConstructor && !context.inConstructorSuffix || context.owner.isEarly) INCONSTRUCTOR else 0l - private def enterClassSymbol(pos: Position, flags: long, name: Name): Symbol = { + + private def enterClassSymbol(tree : ClassDef, 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) + updatePosFlags(setPrivateWithin(tree, c, tree.mods), tree.pos, flags) } else { - c = enterInScope(context.owner.newClass(pos, name)).setFlag(flags | inConstructorFlag) + c = enterAndSet(tree) + {newClass(tree.pos, name, flags | inConstructorFlag)} } if (c.owner.isPackageClass) { val file = context.unit.source.getFile() @@ -167,18 +172,17 @@ trait Namers requires Analyzer { c } - private def enterModuleSymbol(pos: Position, flags: long, name: Name): Symbol = { + private def enterModuleSymbol(tree: ModuleDef, 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)) { - updatePosFlags(m, pos, flags) + updatePosFlags(setPrivateWithin(tree, m, tree.mods), tree.pos, flags) } else { if (m.isTerm && !m.isPackage && !currentRun.compiles(m) && (context.scope == m.owner.info.decls)) context.scope.unlink(m) - m = context.owner.newModule(pos, name) - m.setFlag(flags) + m = enterAndSet(tree) + {newModule(tree.pos, name, flags)} m.moduleClass.setFlag(flags | inConstructorFlag) - enterInScope(m) } if (m.owner.isPackageClass) { m.moduleClass.sourceFile = context.unit.source.getFile() @@ -186,13 +190,31 @@ trait Namers requires Analyzer { } m } - - private def enterCaseFactorySymbol(pos: Position, flags: long, name: Name): Symbol = { + def newMethod(pos : Position, name : Name, flags : Long) : TermSymbol = context.owner.newMethod(pos, name).setFlag(flags) + def newValue(pos : Position, name : Name, flags : Long) : TermSymbol = context.owner.newValue(pos, name).setFlag(flags) + def newConstructor(pos : Position, flags : Long) : TermSymbol = context.owner.newConstructor(pos).setFlag(flags) + def newModule(pos : Position, name : Name, flags : Long) : TermSymbol = context.owner.newModule(pos, name).setFlag(flags) + def newClass(pos : Position, name : Name, flags : Long) : ClassSymbol = context.owner.newClass(pos, name).setFlag(flags) + def newPackage(owner : Symbol, pos : Position, name : Name) : TermSymbol = owner.newPackage(pos, name) + def newImport(pos : Position) : TermSymbol = NoSymbol.newImport(pos) + + def newAbstractType(pos : Position, name : Name, flags : Long) : TypeSymbol = context.owner.newAbstractType(pos, name).setFlag(flags) + def newAliasType(pos : Position, name : Name, flags : Long) : TypeSymbol = context.owner.newAliasType(pos, name).setFlag(flags) + def newValueParameter(owner : Symbol, pos : Position, name : Name, flags : Long) : TermSymbol = owner.newValueParameter(pos, name).setFlag(flags) + def newThisSym(owner : Symbol, pos : Position) : TermSymbol = owner.newThisSym(pos) + def newTypeSkolem(sym : Symbol) = sym.newTypeSkolem + def newLabel(owner : Symbol, pos : Position, name : Name) = owner.newLabel(pos, name) + + protected def setInfo(t : LazyType)(sym : Symbol) : Symbol = + sym setInfo t + + private def enterCaseFactorySymbol(tree : ClassDef, 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) + updatePosFlags(setPrivateWithin(tree, m, tree.mods), tree.pos, flags) } else { - m = enterInScope(context.owner.newMethod(pos, name)).setFlag(flags) + m = enterAndSet(tree) + {newMethod(tree.pos, name, flags)} } if (m.owner.isPackageClass) currentRun.symSource(m) = context.unit.source.getFile() @@ -203,18 +225,18 @@ trait Namers requires Analyzer { var namer : Namer = this for (tree <- trees) { val txt = namer.enterSym(tree) - if (!(txt eq namer.context)) namer = new Namer(txt) + if (!(txt eq namer.context)) namer = newNamer(txt) } namer } def newTypeSkolems(tparams: List[Symbol]): List[Symbol] = { - val tskolems = tparams map (.newTypeSkolem) + val tskolems = tparams map (newTypeSkolem) val ltp = new LazyType { override def complete(sym: Symbol): unit = sym setInfo sym.deSkolemize.info.substSym(tparams, tskolems) //@M the info of a skolem is the skolemized info of the actual type parameter of the skolem } - tskolems foreach (.setInfo(ltp)) + tskolems foreach (setInfo(ltp)) tskolems } @@ -238,13 +260,15 @@ trait Namers requires Analyzer { override val typeParams: List[Symbol]= tparams map (.symbol) //@M override def complete(sym: Symbol): unit = { if(ownerSym.isAbstractType) //@M an abstract type's type parameters are entered - new Namer(ctx.makeNewScope(owner, ownerSym)).enterSyms(tparams) //@M + newNamer(makeNewScope(ctx, owner, ownerSym)).enterSyms(tparams) //@M restp.complete(sym) } } - def enterSym(tree: Tree): Context = { + protected def enterAndSet(tree : MemberDef)(sym : Symbol) : Symbol = + enterInScope(setPrivateWithin(tree, sym, tree.mods)) + def enterSym(tree: Tree): Context = { def finishWith(tparams: List[AbsTypeDef]): unit = { val sym = tree.symbol if (settings.debug.value) log("entered " + sym + " in " + context.owner + ", scope-id = " + context.scope.hashCode()); @@ -254,93 +278,83 @@ trait Namers requires Analyzer { //@M e.g., in [A[x <: B], B], A and B are entered first as both are in scope in the definition of x //@M x is only in scope in `A[x <: B]' if(!sym.isAbstractType) //@M - new Namer(context.makeNewScope(tree, sym)).enterSyms(tparams) + new Namer(makeNewScope(context, tree, sym)).enterSyms(tparams) ltype = new LazyPolyType(tparams, ltype, tree, sym, context) //@M if (sym.isTerm) skolemize(tparams) } - sym.setInfo(ltype) + setInfo(ltype)(sym) } def finish = finishWith(List()) - if (tree.symbol == NoSymbol) { - val owner = context.owner + //val owner = context.owner tree match { case PackageDef(name, stats) => tree.symbol = enterPackageSymbol(tree.pos, name) - val namer = new Namer( - context.make(tree, tree.symbol.moduleClass, tree.symbol.info.decls)) + val namer = newNamer{ + context.make(tree, tree.symbol.moduleClass, tree.symbol.info.decls) + } namer.enterSyms(stats) - case ClassDef(mods, name, tparams, impl) => + case tree @ ClassDef(mods, name, tparams, impl) => if ((mods.flags & CASE) != 0) { // enter case factory method. tree.symbol = enterCaseFactorySymbol( - tree.pos, mods.flags & AccessFlags | METHOD | CASE, name.toTermName) - tree.symbol.setInfo(namerOf(tree.symbol).caseFactoryCompleter(tree)) - setPrivateWithin(tree, tree.symbol, mods) + tree, mods.flags & AccessFlags | METHOD | CASE, name.toTermName) + setInfo(namerOf(tree.symbol).caseFactoryCompleter(tree))(tree.symbol) } - tree.symbol = enterClassSymbol(tree.pos, mods.flags, name) - setPrivateWithin(tree, tree.symbol, mods) + tree.symbol = enterClassSymbol(tree, mods.flags, name) finishWith(tparams) - case ModuleDef(mods, name, _) => - tree.symbol = enterModuleSymbol(tree.pos, mods.flags | MODULE | FINAL, name) - setPrivateWithin(tree, tree.symbol, mods) + case tree @ ModuleDef(mods, name, _) => + tree.symbol = enterModuleSymbol(tree, mods.flags | MODULE | FINAL, name) + // additional stuff with moduleClass, note that module class doesn't go into the symbol table, so we don't care about it setPrivateWithin(tree, tree.symbol.moduleClass, mods) - tree.symbol.moduleClass.setInfo(namerOf(tree.symbol).moduleClassTypeCompleter(tree)) + setInfo(namerOf(tree.symbol).moduleClassTypeCompleter(tree))(tree.symbol.moduleClass) finish - case ValDef(mods, name, tp, rhs) => + case tree @ ValDef(mods, name, tp, rhs) => if (context.owner.isClass && (mods.flags & (PRIVATE | LOCAL)) != (PRIVATE | LOCAL)) { val accflags = ACCESSOR | (if ((mods.flags & MUTABLE) != 0) mods.flags & ~MUTABLE & ~PRESUPER else mods.flags & ~PRESUPER | STABLE) - val getter = owner.newMethod(tree.pos, name).setFlag(accflags) - getter.setInfo(namerOf(getter).getterTypeCompleter(tree)) - setPrivateWithin(tree, getter, mods) - enterInScope(getter) + val getter = enterAndSet(tree) + {newMethod(tree.pos, name, accflags)} + setInfo(namerOf(getter).getterTypeCompleter(tree))(getter) if ((mods.flags & MUTABLE) != 0) { - val setter = owner.newMethod(tree.pos, nme.getterToSetter(name)) - .setFlag(accflags & ~STABLE & ~CASEACCESSOR) - setter.setInfo(namerOf(setter).setterTypeCompleter(tree)) - setPrivateWithin(tree, setter, mods) - enterInScope(setter) + val setter = enterAndSet(tree) + {newMethod(tree.pos, nme.getterToSetter(name), + accflags & ~STABLE & ~CASEACCESSOR)} + setInfo(namerOf(setter).setterTypeCompleter(tree))(setter) } tree.symbol = if ((mods.flags & DEFERRED) == 0) { val value = - enterInScope(owner.newValue(tree.pos, nme.getterToLocal(name))) - .setFlag(mods.flags & FieldFlags | PRIVATE | LOCAL) - value.setInfo(namerOf(value).typeCompleter(tree)) + enterInScope(newValue(tree.pos, nme.getterToLocal(name), mods.flags & FieldFlags | PRIVATE | LOCAL)) + setInfo(namerOf(value).typeCompleter(tree))(value) value } else getter; } else { - tree.symbol = enterInScope(owner.newValue(tree.pos, name)) - .setFlag(mods.flags) + tree.symbol = enterInScope(newValue(tree.pos, name, mods.flags)) finish } - case DefDef(mods, nme.CONSTRUCTOR, tparams, _, _, _) => - tree.symbol = enterInScope(owner.newConstructor(tree.pos)) - .setFlag(mods.flags | owner.getFlag(ConstrFlags)) - setPrivateWithin(tree, tree.symbol, mods) + case tree @ DefDef(mods, nme.CONSTRUCTOR, tparams, _, _, _) => + tree.symbol = enterAndSet(tree) + {newConstructor(tree.pos, mods.flags | context.owner.getFlag(ConstrFlags))} finishWith(tparams) - case DefDef(mods, name, tparams, _, _, _) => - tree.symbol = enterInScope(owner.newMethod(tree.pos, name)) - .setFlag(mods.flags) - setPrivateWithin(tree, tree.symbol, mods) + case tree @ DefDef(mods, name, tparams, _, _, _) => + tree.symbol = enterAndSet(tree) + {newMethod(tree.pos, name, mods.flags)} finishWith(tparams) - case AbsTypeDef(mods, name, tparams, _, _) => - tree.symbol = enterInScope(owner.newAbstractType(tree.pos, name)) - .setFlag(mods.flags) - setPrivateWithin(tree, tree.symbol, mods) + case tree @ AbsTypeDef(mods, name, tparams, _, _) => + tree.symbol = enterAndSet(tree) + {newAbstractType(tree.pos, name, mods.flags)} finishWith(tparams) - case AliasTypeDef(mods, name, tparams, _) => - tree.symbol = enterInScope(owner.newAliasType(tree.pos, name)) - .setFlag(mods.flags) - setPrivateWithin(tree, tree.symbol, mods) + case tree @ AliasTypeDef(mods, name, tparams, _) => + tree.symbol = enterAndSet(tree) + {newAliasType(tree.pos, name, mods.flags)} finishWith(tparams) case DocDef(_, defn) => enterSym(defn) case imp @ Import(_, _) => - tree.symbol = NoSymbol.newImport(tree.pos) - tree.symbol.setInfo(namerOf(tree.symbol).typeCompleter(tree)) + tree.symbol = newImport(tree.pos) + setInfo(namerOf(tree.symbol).typeCompleter(tree))(tree.symbol) return (context.makeNewImport(imp)) case _ => } @@ -388,7 +402,7 @@ trait Namers requires Analyzer { } } - def selfTypeCompleter(tree: Tree) = new TypeCompleter(tree) { + def selfTypeCompleter(tree: Tree) : Type = new TypeCompleter(tree) { override def complete(sym: Symbol): unit = { sym.setInfo(typer.typedType(tree).tpe) } @@ -413,11 +427,11 @@ trait Namers requires Analyzer { def enterValueParams(owner: Symbol, vparamss: List[List[ValDef]]): List[List[Symbol]] = { def enterValueParam(param: ValDef): Symbol = if (doEnterValueParams) { - param.symbol = owner.newValueParameter(param.pos, param.name) - .setInfo(typeCompleter(param)) - .setFlag(param.mods.flags & (BYNAMEPARAM | IMPLICIT)) - setPrivateWithin(param, param.symbol, param.mods) - enterInScope(param.symbol) + param.symbol = setInfo(typeCompleter(param))( + enterAndSet(param) + {newValueParameter(owner, param.pos, param.name, + param.mods.flags & (BYNAMEPARAM | IMPLICIT))}) + param.symbol } else param.symbol vparamss.map(.map(enterValueParam)) @@ -544,7 +558,6 @@ trait Namers requires Analyzer { case PolyType(tparams, rt) => rt.substSym(tparams, tparamSyms) case mt => mt } - for (vparams <- vparamss) { var pfs = resultPt.paramTypes for (vparam <- vparams) { @@ -678,9 +691,9 @@ trait Namers requires Analyzer { context.error(tpt.pos, "missing parameter type"); ErrorType } else { - tpt.tpe = deconstIfNotFinal(sym, + tpt.tpe = deconstIfNotFinal(sym, newTyper(typer1.context.make(vdef, sym)).computeType(rhs, WildcardType)) - tpt.tpe + tpt.tpe } } else typer1.typedType(tpt).tpe diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 411662c96e..7e210856e9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -59,6 +59,7 @@ trait Typers requires Analyzer { def newDecls(tree : Template, clazz : Symbol) = newScope def newTemplateScope(impl : Template, clazz : Symbol) = newScope + // Mode constants /** The three mode <code>NOmode</code>, <code>EXPRmode</code> @@ -133,6 +134,7 @@ trait Typers requires Analyzer { class Typer(context0: Context) { import context0.unit + def freshName(prefix : String, pos : Position, n : Int) = unit.fresh.newName(prefix) val infer = new Inferencer(context0) { override def isCoercible(tp: Type, pt: Type): boolean = ( @@ -176,9 +178,10 @@ trait Typers requires Analyzer { */ private def inferView(pos: Position, from: Type, name: Name, tp: Type, reportAmbiguous: boolean): Tree = { val to = refinedType(List(WildcardType), NoSymbol) + // Sean: how to reuse from IDE? bad bad bad... val psym = (if (name.isTypeName) to.symbol.newAbstractType(pos, name) else to.symbol.newValue(pos, name)) setInfo tp - to.decls.enter(psym) + to.decls enter psym inferView(pos, from, to, reportAmbiguous) } @@ -187,9 +190,10 @@ trait Typers requires Analyzer { private var namerCache: Namer = null def namer = { if ((namerCache eq null) || namerCache.context != context) - namerCache = new Namer(context) + namerCache = newNamer(context) namerCache } + protected def newNamer(context : Context) = new Namer(context) private[typechecker] var context = context0 def context1 = context @@ -1018,7 +1022,7 @@ trait Typers requires Analyzer { } protected def enterSym(txt : Context, tree : Tree) : Context = if (txt eq context) namer.enterSym(tree) - else new Namer(txt).enterSym(tree) + else newNamer(txt).enterSym(tree) /** * @param templ ... @@ -1199,7 +1203,7 @@ trait Typers requires Analyzer { case ldef @ LabelDef(_, _, _) => if (ldef.symbol == NoSymbol) ldef.symbol = namer.enterInScope( - context.owner.newLabel(ldef.pos, ldef.name) setInfo MethodType(List(), UnitClass.tpe)) + namer.newLabel(context.owner, ldef.pos, ldef.name) setInfo MethodType(List(), UnitClass.tpe)) case _ => } @@ -1240,7 +1244,7 @@ trait Typers requires Analyzer { def typedBlock(block: Block, mode: int, pt: Type): Block = { if (context.retyping) { for (val stat <- block.stats) { - if (stat.isDef) context.scope.enter(stat.symbol) + if (stat.isDef) context.scope enter (stat.symbol) } } if (!inIDE) @@ -1411,7 +1415,7 @@ trait Typers requires Analyzer { (e.sym.isType || inBlock || (e.sym.tpe matches e1.sym.tpe))) if (!e.sym.isErroneous && !e1.sym.isErroneous) error(e.sym.pos, e1.sym+" is defined twice"+ - {if(!settings.debug.value) "" else " in "+unit.toString}); + {if(!settings.debug.value) "" else " in "+unit.toString}); e1 = scope.lookupNextEntry(e1); } e = e.next @@ -1569,8 +1573,7 @@ trait Typers requires Analyzer { assert(unapp.exists, tree) val unappType = otpe.memberType(unapp) val argDummyType = pt // was unappArg - val argDummy = context.owner.newValue(fun.pos, nme.SELECTOR_DUMMY) - .setFlag(SYNTHETIC) + val argDummy = namer.newValue(fun.pos, nme.SELECTOR_DUMMY, SYNTHETIC) .setInfo(argDummyType) if (args.length > MaxTupleArity) error(fun.pos, "too many arguments for unapply pattern, maximum = "+MaxTupleArity) @@ -1645,15 +1648,15 @@ trait Typers requires Analyzer { else { val annType = tpt.tpe - val needsConstant = - (!settings.Xplugtypes.value || - annType <:< ClassfileAnnotationClass.tpe) + val needsConstant = + (!settings.Xplugtypes.value || + annType <:< ClassfileAnnotationClass.tpe) def annotArg(tree: Tree): AnnotationArgument = { val arg = new AnnotationArgument(liftcode.reify(tree)) if(needsConstant && !arg.isConstant) - needConst(tree) - arg + needConst(tree) + arg } val constrArgs = args map annotArg @@ -1743,16 +1746,16 @@ trait Typers requires Analyzer { if (vble == NoSymbol) vble = if (isFullyDefined(pt)) - context.owner.newAliasType(tree.pos, name) setInfo pt + namer.newAliasType(tree.pos, name, 0) setInfo pt else - context.owner.newAbstractType(tree.pos, name) setInfo + namer.newAbstractType(tree.pos, name, 0) setInfo mkTypeBounds(AllClass.tpe, AnyClass.tpe) if (vble.name == nme.WILDCARD.toTypeName) context.scope.enter(vble) else namer.enterInScope(vble) tree setSymbol vble setType vble.tpe } else { if (vble == NoSymbol) - vble = context.owner.newValue(tree.pos, name) + vble = namer.newValue(tree.pos, name, 0) if (vble.name.toTermName != nme.WILDCARD) { /* if (namesSomeIdent(vble.name)) @@ -2461,8 +2464,8 @@ trait Typers requires Analyzer { case tree @ Function(_, _) => if (tree.symbol == NoSymbol) - tree.symbol = context.owner.newValue(tree.pos, nme.ANON_FUN_NAME) - .setFlag(SYNTHETIC).setInfo(NoType) + tree.symbol = namer.newValue(tree.pos, nme.ANON_FUN_NAME, SYNTHETIC) + .setInfo(NoType) newTyper(makeNewScope(context, tree, tree.symbol)).typedFunction(tree, mode, pt) case Assign(lhs, rhs) => @@ -2471,11 +2474,11 @@ trait Typers requires Analyzer { case If(cond, thenp, elsep) => typedIf(cond, thenp, elsep) - case Match(selector, cases) => + case tree @ Match(selector, cases) => if (selector == EmptyTree) { val arity = if (isFunctionType(pt)) pt.normalize.typeArgs.length - 1 else 1 val params = for (i <- List.range(0, arity)) yield - ValDef(Modifiers(PARAM | SYNTHETIC), unit.fresh.newName("x$"), TypeTree(), EmptyTree) + ValDef(Modifiers(PARAM | SYNTHETIC), freshName("x$", tree.pos, i), TypeTree(), EmptyTree) val ids = for (p <- params) yield Ident(p.name) val selector1 = atPos(tree.pos) { if (arity == 1) ids.head else gen.mkTuple(ids) } val body = copy.Match(tree, selector1, cases) diff --git a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala index 101cf51121..3bf9eba923 100644 --- a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala +++ b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala @@ -9,7 +9,7 @@ package scala.tools.nsc.util import scala.tools.nsc.util.SourceFile.{LF, FF, CR, SU} class CharArrayReader(buf: Array[char], start: int, /* startline: int, startcol: int, */ - decodeUni: boolean, error: String => unit) { + decodeUni: boolean, error: String => unit) extends Iterator[Char] { def this(buf: Array[char], decodeUni: boolean, error: String => unit) = this(buf, 0, /* 1, 1, */ decodeUni, error) @@ -50,10 +50,11 @@ class CharArrayReader(buf: Array[char], start: int, /* startline: int, startcol: def last: char = if(bp > start + 2) buf(bp - 2) else ' ' // XML literals - def next: unit = { + def next: Char = { //cline = nextline //ccol = nextcol - if(!hasNext) return SU // there is an endless stream of SU's at the end + if(!hasNext) + return SU // there is an endless stream of SU's at the end oldBp = bp oldCh = ch; ch = buf(bp) @@ -95,6 +96,7 @@ class CharArrayReader(buf: Array[char], start: int, /* startline: int, startcol: if (ch > ' ') onlyBlankChars = false // nextcol = nextcol + 1 } + ch } def rewind = { if (oldBp == -1) throw new IllegalArgumentException diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala index 58994e9d32..144809ff6a 100644 --- a/src/compiler/scala/tools/nsc/util/Position.scala +++ b/src/compiler/scala/tools/nsc/util/Position.scala @@ -9,10 +9,26 @@ // $Id$ package scala.tools.nsc.util -abstract class Position { +trait Position { def offset : Option[Int] = None - def line : Option[Int] = None - def column : Option[Int] = None + private val tabInc = 8 + def line : Option[Int] = + if (source.isEmpty || offset.isEmpty) None else Some(source.get.offsetToLine(offset.get) + 1) + def column : Option[Int] = { + if (source.isEmpty || offset.isEmpty) return None + var column = 1 + // find beginning offset for line + val line = source.get.offsetToLine(offset.get) + var coffset = source.get.lineToOffset(line) + var continue = true + while (continue) { + if (coffset == offset.get(-1)) continue = false + else if (source.get.content(coffset) == '\t') column = ((column - 1) / tabInc * tabInc) + tabInc + 1 + else column = column + 1 + coffset = coffset + 1 + } + Some(column) + } def source : Option[SourceFile] = None def lineContent: String = if (!line.isEmpty && !source.isEmpty) source.get.lineToString(line.get - 1) @@ -51,22 +67,6 @@ case class LinePosition(line0 : Int, override val source : Option[SourceFile]) e override def line = Some(line0) } case class OffsetPosition(source0 : SourceFile, offset0 : Int) extends Position { - private val tabInc = 8 override def source = Some(source0) override def offset = Some(offset0) - override def line = Some(source0.offsetToLine(offset0) + 1) - override def column = { - var column = 1 - // find beginning offset for line - val line = source0.offsetToLine(offset0) - var coffset = source0.lineToOffset(line) - var continue = true - while (continue) { - if (coffset == offset.get(-1)) continue = false - else if (source0.content(coffset) == '\t') column = ((column - 1) / tabInc * tabInc) + tabInc + 1 - else column = column + 1 - coffset = coffset + 1 - } - Some(column) - } }
\ No newline at end of file |