From 6d9e1774b9d543550473b3f32c4925d290c9edd1 Mon Sep 17 00:00:00 2001 From: Sean McDirmid Date: Fri, 25 Aug 2006 10:32:17 +0000 Subject: Modified scopes and positions so they can be co... Modified scopes and positions so they can be configured more flexibly. --- src/compiler/scala/tools/nsc/CompileServer.scala | 2 +- src/compiler/scala/tools/nsc/Global.scala | 6 +- src/compiler/scala/tools/nsc/Interpreter.scala | 2 +- src/compiler/scala/tools/nsc/Main.scala | 2 +- src/compiler/scala/tools/nsc/MainTokenMetric.scala | 2 +- src/compiler/scala/tools/nsc/ScriptRunner.scala | 2 +- src/compiler/scala/tools/nsc/StdGlobal.scala | 11 +++ src/compiler/scala/tools/nsc/ast/Trees.scala | 22 +++--- .../scala/tools/nsc/ast/parser/MarkupParsers.scala | 2 +- .../scala/tools/nsc/ast/parser/Parsers.scala | 3 +- .../tools/nsc/ast/parser/SymbolicXMLBuilder.scala | 5 +- .../tools/nsc/ast/parser/SyntaxAnalyzer.scala | 3 + .../scala/tools/nsc/ast/parser/TreeBuilder.scala | 4 +- .../scala/tools/nsc/backend/opt/Inliners.scala | 1 + .../scala/tools/nsc/matching/CodeFactory.scala | 2 +- .../scala/tools/nsc/matching/PatternMatchers.scala | 2 +- .../tools/nsc/matching/PatternNodeCreator.scala | 33 ++++----- .../scala/tools/nsc/matching/PatternNodes.scala | 2 +- src/compiler/scala/tools/nsc/models/Models.scala | 71 +++++++++--------- .../scala/tools/nsc/models/SemanticTokens.scala | 46 ++++++------ .../scala/tools/nsc/models/Signatures.scala | 85 ++++++++++------------ .../scala/tools/nsc/symtab/Definitions.scala | 22 +++--- src/compiler/scala/tools/nsc/symtab/Flags.scala | 1 - src/compiler/scala/tools/nsc/symtab/Scopes.scala | 17 ++++- .../scala/tools/nsc/symtab/SymbolLoaders.scala | 8 +- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 72 ++++++++++-------- src/compiler/scala/tools/nsc/symtab/Types.scala | 15 ++-- .../nsc/symtab/classfile/ClassfileParser.scala | 20 ++--- .../tools/nsc/symtab/classfile/ICodeReader.scala | 2 +- .../tools/nsc/symtab/classfile/MetaParser.scala | 6 +- .../tools/nsc/symtab/classfile/UnPickler.scala | 3 +- .../scala/tools/nsc/transform/AddInterfaces.scala | 2 +- .../scala/tools/nsc/transform/CleanUp.scala | 2 +- .../scala/tools/nsc/transform/Erasure.scala | 2 +- .../scala/tools/nsc/transform/ExplicitOuter.scala | 4 +- .../scala/tools/nsc/transform/Flatten.scala | 2 +- .../scala/tools/nsc/transform/LambdaLift.scala | 2 +- src/compiler/scala/tools/nsc/transform/Mixin.scala | 14 ++-- .../tools/nsc/transform/OverridingPairs.scala | 2 +- .../scala/tools/nsc/transform/UnCurry.scala | 4 +- .../scala/tools/nsc/typechecker/Contexts.scala | 8 +- .../scala/tools/nsc/typechecker/Infer.scala | 6 +- .../scala/tools/nsc/typechecker/Namers.scala | 20 ++--- .../scala/tools/nsc/typechecker/RefChecks.scala | 2 +- .../scala/tools/nsc/typechecker/TreeCheckers.scala | 2 +- .../scala/tools/nsc/typechecker/Typers.scala | 26 +++---- 46 files changed, 302 insertions(+), 270 deletions(-) create mode 100644 src/compiler/scala/tools/nsc/StdGlobal.scala (limited to 'src/compiler/scala/tools/nsc') diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index c88f412948..9136216426 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -123,7 +123,7 @@ object CompileServer extends SocketServer { } else { if (args contains "-verbose") out.println("[Starting new Scala compile server instance]") - compiler = new Global(command.settings, reporter) { + compiler = new StdGlobal(command.settings, reporter) { override def inform(msg: String) = out.println(msg) } } diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 2640ee4257..891e35d98a 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -29,13 +29,11 @@ import backend.jvm.GenJVM import backend.opt.{Inliners, ClosureElimination, DeadCodeElimination} import backend.icode.analysis._ -class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable +abstract class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable with Trees with CompilationUnits { - // sub-components -------------------------------------------------- - object treePrinters extends TreePrinters { val global: Global.this.type = Global.this } @@ -336,7 +334,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable object icodeChecker extends checkers.ICodeChecker() object typer extends analyzer.Typer( - analyzer.NoContext.make(EmptyTree, Global.this.definitions.RootClass, new Scope())) + analyzer.NoContext.make(EmptyTree, Global.this.definitions.RootClass, newScope)) def phaseDescriptors: List[SubComponent] = List( analyzer.namerFactory, diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 30d71d438f..1288da2ba5 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -81,7 +81,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) settings.outdir.value = classfilePath.getPath /** the compiler to compile expressions with */ - val compiler = new Global(settings, reporter) + val compiler = new StdGlobal(settings, reporter) /** class loader used to load compiled code */ /* A single class loader is used for all commands interpreted by this Interpreter. diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala index 169c90e306..560ade7ff6 100644 --- a/src/compiler/scala/tools/nsc/Main.scala +++ b/src/compiler/scala/tools/nsc/Main.scala @@ -62,7 +62,7 @@ object Main extends Object with EvalLoop { reporter.info(null, command.usageMsg, true) else { try { - object compiler extends Global(command.settings, reporter); + object compiler extends StdGlobal(command.settings, reporter); /* if (command.settings.Xgenerics.value) forever(compiler) diff --git a/src/compiler/scala/tools/nsc/MainTokenMetric.scala b/src/compiler/scala/tools/nsc/MainTokenMetric.scala index 0fe6e0a2cc..cfe1b9a7ec 100644 --- a/src/compiler/scala/tools/nsc/MainTokenMetric.scala +++ b/src/compiler/scala/tools/nsc/MainTokenMetric.scala @@ -44,7 +44,7 @@ object MainTokenMetric { val command = new CompilerCommand(List.fromArray(args), error, false) reporter = new ConsoleReporter() try { - val compiler = new Global(command.settings, reporter) + val compiler = new StdGlobal(command.settings, reporter) tokenMetric(compiler, command.files) } catch { case ex @ FatalError(msg) => diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala index 8b65a0e0a3..e73dc8a308 100644 --- a/src/compiler/scala/tools/nsc/ScriptRunner.scala +++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala @@ -220,7 +220,7 @@ object ScriptRunner { if (settings.nocompdaemon.value) { val reporter = new ConsoleReporter - val compiler = new Global(settings, reporter) + val compiler = new StdGlobal(settings, reporter) val cr = new compiler.Run cr.compileSources(List(wrappedScript(scriptFile))) Pair(compiledPath, reporter.errors == 0) diff --git a/src/compiler/scala/tools/nsc/StdGlobal.scala b/src/compiler/scala/tools/nsc/StdGlobal.scala new file mode 100644 index 0000000000..d755d2d167 --- /dev/null +++ b/src/compiler/scala/tools/nsc/StdGlobal.scala @@ -0,0 +1,11 @@ +package scala.tools.nsc; +import scala.tools.nsc.reporters._ +import scala.tools.nsc.util.Position; + +class StdGlobal(settings: Settings, reporter: Reporter) extends Global(settings, reporter) { + type PositionType = Int; + implicit def coercePosToInt(pos : PositionType) : Int = pos; + def coerceIntToPos(pos : Int) : PositionType = pos; + val NoPos = Position.NOPOS; + val FirstPos = Position.FIRSTPOS; +} diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index c385c78012..ba1d827f86 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -45,16 +45,18 @@ trait Trees requires Global { val NoMods = Modifiers(0) abstract class Tree { + { + import util.Statistics; + if (Statistics.enabled) nodeCount = nodeCount + 1 + } - if (util.Statistics.enabled) nodeCount = nodeCount + 1 - - private var posx: int = Position.NOPOS + private var rawpos: PositionType = NoPos - def pos = posx + def pos = rawpos var tpe: Type = _ - def setPos(p: int): this.type = { posx = p; this } + def setPos(pos: PositionType): this.type = { rawpos = pos; this } def setType(tp: Type): this.type = { tpe = tp; this } def symbol: Symbol = null @@ -87,7 +89,7 @@ trait Trees requires Global { def duplicate: this.type = (duplicator transform this).asInstanceOf[this.type] def copyAttrs(tree: Tree): this.type = { - posx = tree.posx + rawpos = tree.rawpos tpe = tree.tpe if (hasSymbol) symbol = tree.symbol this @@ -1241,13 +1243,13 @@ trait Trees requires Global { } object posAssigner extends Traverser { - private var pos: int = _ + private var pos: PositionType = _ override def traverse(t: Tree): unit = - if (t != EmptyTree && t.pos == Position.NOPOS) { + if (t != EmptyTree && t.pos == NoPos) { t.setPos(pos) super.traverse(t) } - def atPos[T <: Tree](pos: int)(tree: T): T = { + def atPos[T <: Tree](pos: PositionType)(tree: T): T = { this.pos = pos traverse(tree) tree @@ -1256,7 +1258,7 @@ trait Trees requires Global { object resetPos extends Traverser { override def traverse(t: Tree): unit = { - if (t != EmptyTree) t.setPos(Position.NOPOS) + if (t != EmptyTree) t.setPos(NoPos) super.traverse(t) } } diff --git a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala index 0e9d96b330..1d99e5c402 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala @@ -14,7 +14,7 @@ import scala.xml.{Text,TextBuffer}; trait MarkupParsers requires SyntaxAnalyzer { import global._ ; - import posAssigner.atPos; + //import posAssigner.atPos; class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean) /*with scala.xml.parsing.MarkupParser[Tree,Tree] */{ diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 47f8c7bc64..dac4832019 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -44,8 +44,9 @@ import Tokens._ trait Parsers requires SyntaxAnalyzer { import global._ + import RequiresIntsAsPositions._; private val glob: global.type = global - import posAssigner.atPos + import global.posAssigner.atPos; class Parser(unit: global.CompilationUnit) { diff --git a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala index b61ea79017..ae223c721c 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala @@ -13,13 +13,14 @@ import scala.xml.{Text,TextBuffer}; import symtab.Flags.MUTABLE; + /** this class builds instance of Tree that represent XML */ abstract class SymbolicXMLBuilder(make: TreeBuilder, p: Parsers # Parser, preserveWS: Boolean ) { val global: Global; import global._; - import posAssigner.atPos; - + import RequiresIntsAsPositions._; + import global.posAssigner.atPos; //import scala.tools.scalac.ast.{TreeList => myTreeList} var isPattern:Boolean = _; diff --git a/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala b/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala index 8db8f1adba..99eb0a50b6 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala @@ -8,6 +8,9 @@ package scala.tools.nsc.ast.parser; /** An nsc sub-component. */ abstract class SyntaxAnalyzer extends SubComponent with Parsers with MarkupParsers with Scanners { + + + val phaseName = "parser"; def newPhase(prev: Phase): StdPhase = new ParserPhase(prev); class ParserPhase(prev: scala.tools.nsc.Phase) extends StdPhase(prev) { diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 055f5325b0..d11c322bf7 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -13,8 +13,8 @@ abstract class TreeBuilder { val global: Global import global._ - import posAssigner.atPos - + import RequiresIntsAsPositions._; + import posAssigner.atPos; def freshName(prefix: String): Name def freshName(): Name = freshName("x$") diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala index b9f4295929..acf2627466 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala @@ -14,6 +14,7 @@ import scala.tools.nsc.symtab._; */ abstract class Inliners extends SubComponent { import global._; + import RequiresIntsAsPositions._; import icodes._; import icodes.opcodes._; diff --git a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala index 8486ff36a0..4e33b386d5 100644 --- a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala +++ b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala @@ -190,7 +190,7 @@ trait CodeFactory requires TransMatcher { def GreaterThanOrEquals(left: Tree , right: Tree ): Tree = Apply(Select(left, nme.GE), List(right)); - def ThrowMatchError(pos: Int, obj: Tree ) = + def ThrowMatchError(pos: PositionType, obj: Tree ) = atPos(pos) { Throw( New( diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala index 62b96782f0..0eee9f8552 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala @@ -370,7 +370,7 @@ trait PatternMatchers requires (TransMatcher with PatternNodes) extends AnyRef w } - private def newHeader(pos: Int, casted: Symbol, index: Int): Header = { + private def newHeader(pos: PositionType, casted: Symbol, index: Int): Header = { //Console.println("newHeader(pos,"+casted+","+index+")"); //Console.println(" casted.tpe"+casted.tpe); //Console.println(" casted.pos "+casted.pos+" equals firstpos?"+(casted.pos == Position.FIRSTPOS)); diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodeCreator.scala b/src/compiler/scala/tools/nsc/matching/PatternNodeCreator.scala index 092be313c6..577e785745 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternNodeCreator.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternNodeCreator.scala @@ -10,10 +10,9 @@ import scala.tools.nsc.symtab.Flags; trait PatternNodeCreator requires (TransMatcher with PatternNodes) { import global._; - - def pSequencePat(pos: Int , tpe:Type , len:int) = { + def pSequencePat(pos: PositionType , tpe:Type , len:int) = { //assert (tpe != null); - val sym = newVar(Position.FIRSTPOS, tpe); + val sym = newVar(FirstPos, tpe); //Console.println("pncrea::sequencePat sym.pos = "+sym.pos); val node = new SequencePat(sym, len); node.pos = pos; @@ -22,9 +21,9 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { node; } - def pRightIgnoringSequencePat(pos: Int, tpe:Type, castedRest1: Symbol, minlen:int) = { + def pRightIgnoringSequencePat(pos: PositionType, tpe:Type, castedRest1: Symbol, minlen:int) = { //assert (tpe != null); - val sym = newVar(Position.FIRSTPOS, tpe); + val sym = newVar(FirstPos, tpe); var castedRest = if(castedRest1 != null) castedRest1 else newVar(pos, tpe); val node = new RightIgnoringSequencePat(sym, castedRest, minlen); node.pos = pos; @@ -32,16 +31,16 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { node; } - def pSeqContainerPat(pos: int, tpe: Type, seqpat:Tree ) = { + def pSeqContainerPat(pos: PositionType, tpe: Type, seqpat:Tree ) = { //assert (tpe != null); - val sym = newVar(Position.NOPOS, tpe); + val sym = newVar(NoPos, tpe); val node = new SeqContainerPat(sym, seqpat); node.pos = pos; node.setType(tpe); node; } - def pDefaultPat(pos: int, tpe: Type) = { + def pDefaultPat(pos: PositionType, tpe: Type) = { //assert (tpe != null); val node = new DefaultPat(); node.pos = pos; @@ -49,7 +48,7 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { node; } - def pConstrPat(pos: int, tpe: Type) = { + def pConstrPat(pos: PositionType, tpe: Type) = { //assert (tpe != null); val node = new ConstrPat(newVar(pos, tpe)); node.pos = pos; @@ -57,7 +56,7 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { node; } - def pConstantPat(pos: int, tpe: Type, value: Any /*AConstant*/ ) = { + def pConstantPat(pos: PositionType, tpe: Type, value: Any /*AConstant*/ ) = { //assert (tpe != null); val node = new ConstantPat( value ); node.pos = pos; @@ -65,7 +64,7 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { node; } - def pVariablePat(pos: int, tree:Tree) = { + def pVariablePat(pos: PositionType, tree:Tree) = { //assert (tree.tpe != null); val node = new VariablePat( tree ); node.pos = pos; @@ -73,7 +72,7 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { node; } - def pAltPat(pos: int, header:Header ) = { + def pAltPat(pos: PositionType, header:Header ) = { val node = new AltPat(header); node.pos = pos; node.setType(header.getTpe()); @@ -82,7 +81,7 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { // factories - def pHeader(pos: int, tpe: Type, selector:Tree) = { + def pHeader(pos: PositionType, tpe: Type, selector:Tree) = { //assert (tpe != null); val node = new Header(selector, null); node.pos = pos; @@ -90,19 +89,19 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { node; } - def pBody(pos: int) = { + def pBody(pos: PositionType) = { val node = new Body(new Array[Array[ValDef]](0), new Array[Tree](0), new Array[Tree](0)); node.pos = pos; node; } - def pBody(pos: int, bound:Array[ValDef] , guard:Tree, body:Tree) = { + def pBody(pos: PositionType, bound:Array[ValDef] , guard:Tree, body:Tree) = { val node = new Body(Predef.Array[Array[ValDef]](bound), Predef.Array[Tree](guard), Predef.Array[Tree](body)); node.pos = pos; node; } - def newVar(pos: int, name: Name, tpe: Type): Symbol= { + def newVar(pos: PositionType, name: Name, tpe: Type): Symbol= { /** hack: pos has special meaning*/ val sym = currentOwner.newVariable(pos, name); //Console.println("patnodcre::newVar sym = "+sym+ "tpe = "+tpe); @@ -112,7 +111,7 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { sym; } - def newVar(pos: int, tpe: Type): Symbol = { + def newVar(pos: PositionType, tpe: Type): Symbol = { newVar(pos, cunit.fresh.newName("temp"), tpe).setFlag(Flags.SYNTHETIC); } } diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala index 9cd7399556..4a899010b9 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala @@ -17,7 +17,7 @@ trait PatternNodes requires TransMatcher { /** Intermediate data structure for algebraic + pattern matcher */ class PatternNode { - var pos = Position.FIRSTPOS; + var pos = FirstPos; var tpe: Type = _; var or: PatternNode = _; var and: PatternNode = _; diff --git a/src/compiler/scala/tools/nsc/models/Models.scala b/src/compiler/scala/tools/nsc/models/Models.scala index 8ab0cea160..97e241f09c 100644 --- a/src/compiler/scala/tools/nsc/models/Models.scala +++ b/src/compiler/scala/tools/nsc/models/Models.scala @@ -31,7 +31,7 @@ abstract class Models { object ARG extends Kind object TPARAM extends Kind - val KINDS = CONSTRUCTOR :: TPARAM :: CLASS :: TRAIT :: OBJECT :: VAL :: VAR :: DEF :: Nil + def KINDS = CLASS :: TRAIT :: OBJECT :: CONSTRUCTOR :: TPARAM :: VAL :: VAR :: DEF :: Nil def labelFor(kind: Kind): String = kind match { case OBJECT => "Object" @@ -85,11 +85,7 @@ abstract class Models { } } - abstract class Listener { - def add(from: Composite, model: HasTree): Unit - def remove(from: Composite, model: HasTree): Unit - } - abstract class Model extends Listener + abstract class Model; // def textFor(tp : AbsTypeDef) : String = tp.toString() def textFor(tree: Tree): String = { @@ -141,16 +137,26 @@ abstract class Models { override def toString(): String = tree.toString() - def compare (ht: HasTree): Int = { - val result = tree.symbol.nameString.compare(ht.tree.symbol.nameString) - if (result != 0) result - else toString().compare(ht.toString()) + def compare(that : HasTree): Int = { + val idx = KINDS.indexOf(kind); + val jdx = KINDS.indexOf(that.kind); + System.err.println("" + kind + " " + idx); + System.err.println("" + that.kind + " " + jdx); + if (idx != jdx) return idx - jdx; + val result = tree.symbol.nameString.compare(that.tree.symbol.nameString); + if (result != 0) result; + else toString().compare(that.toString()) + } + def compare [b >: HasTree <% Ordered[b]](that: b): Int = { + if (that.isInstanceOf[HasTree]) { + compare(that.asInstanceOf[HasTree]); + } else -1; } def kind = kindOf(tree.symbol) - override def add(from: Composite, model: HasTree): Unit = { parent.add(from, model) } - override def remove(from: Composite, model: HasTree): Unit = { parent.remove(from, model) } + //override def add(from: Composite, model: HasTree): Unit = { parent.add(from, model) } + //override def remove(from: Composite, model: HasTree): Unit = { parent.remove(from, model) } } class ImportMod(parent0: Composite) extends HasTree(parent0) { @@ -171,19 +177,10 @@ abstract class Models { trait Composite extends Model { import scala.collection.mutable._ - class Members extends HashSet[HasTree] with ObservableSet[HasTree, Members] + class Members extends HashSet[HasTree] // val members = new Members; object members extends Members - object subscriber extends Subscriber[Message[HasTree] with Undoable, Members] { - def notify(pub: Members, event: Message[HasTree] with Undoable): Unit = event match { - //case Include(elem) => add(Composite.this, i.elem) - //case Remove(elem) => remove(Composite.this, i.elem) - case i: Include[HasTree] with Undoable => add(Composite.this, i.elem) - case r: Remove [HasTree] with Undoable => remove(Composite.this, r.elem) - } - } - members.subscribe(subscriber) def isMember(tree: Tree): Boolean = tree.isInstanceOf[Import] // imports welcome anywhere. @@ -310,7 +307,7 @@ abstract class Models { } else super.member(tree, members) def sym = tree0.symbol - if (tree0 == null || sym.pos == Position.NOPOS) null + if (tree0 == null || sym.pos == NoPos) null else if (!acceptPrivate && tree0.isInstanceOf[ValOrDefDef] && tree0.asInstanceOf[ValOrDefDef].mods.isPrivate) null; else tree0; @@ -336,11 +333,9 @@ abstract class Models { override def replacedBy(tree0: Tree): Boolean = super.replacedBy(tree0) && tree0.isInstanceOf[ModuleDef] } - class AliasTypeMod(parent0: Composite) extends MemberMod(parent0) { - def treey = tree.asInstanceOf[AliasTypeDef] - override def replacedBy(tree0: Tree): Boolean = - super.replacedBy(tree0) && tree0.isInstanceOf[AliasTypeDef] + def treey = tree.asInstanceOf[AliasTypeDef]; + override def replacedBy(tree0 : Tree) : Boolean = (super.replacedBy(tree0) && tree0.isInstanceOf[AliasTypeDef]); } class AbsTypeMod(parent0: Composite) extends HasTree(parent0) { @@ -348,20 +343,20 @@ abstract class Models { override def replacedBy(tree0: Tree): Boolean = super.replacedBy(tree0) && tree0.isInstanceOf[AbsTypeDef] } - - class SourceMod(val original: CompilationUnit) extends Composite with HasClassObjects { - update(original) - var listener: Listener = null - def update(unit: CompilationUnit) = unit.body match { - case pdef: PackageDef => update0(pdef.stats) + def SourceMod(original : CompilationUnit) = new SourceMod(original); + + class SourceMod(val original : CompilationUnit) extends Composite with HasClassObjects { + update(original); + //var listener : Listener = null; + def update(unit : CompilationUnit) = unit.body match { + case pdef : PackageDef => try { + update0(pdef.stats); + } catch { + case e : Error => members.clear; update0(pdef.stats); + } case _ => } - override def add(from: Composite, model: HasTree): Unit = - if (listener != null) listener.add(from, model) - - override def remove(from: Composite, model: HasTree): Unit = - if (listener != null) listener.remove(from, model) override def isMember(tree: Tree): Boolean = super.isMember(tree) || tree.isInstanceOf[Import] diff --git a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala index 5f6c3a6ceb..794820ccab 100644 --- a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala +++ b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala @@ -36,7 +36,7 @@ class SemanticTokens(val compiler: Global) { if (keywords.isEmpty) pos else if (pos == source.content.length) - Position.NOPOS + NoPos else if (source.beginsWith(pos, " ")) eatKeywords(source, pos + 1) else if (source.beginsWith(pos, keywords.head + " ")) @@ -49,7 +49,7 @@ class SemanticTokens(val compiler: Global) { val keywords = "package" :: "val" :: "var" :: "def" :: "class" :: "trait" :: "override" :: "case" :: "object" :: "sealed" :: "private" :: "protected" :: Nil - if (pos != Position.NOPOS) eatKeyword(source, pos, keywords) + if (pos != NoPos) eatKeyword(source, pos, keywords) else pos } @@ -127,12 +127,14 @@ class SemanticTokens(val compiler: Global) { private var doLog = true def source = unit.source - def dbg(tree : Tree) = {( + def dbg(tree : Tree) = { + def treePos : Int = if (tree != null) tree.pos else -1; + ( "TREE=" + tree + (if (tree != null) (" CLASS=" + tree.getClass()) else "") + " SYM=" + tree.symbol + " POS=" + - (new Position(source, if (tree != null) tree.pos else -1)).dbgString + (new Position(source, treePos)).dbgString )} val symbols = new HashMap[Symbol,Info]; @@ -194,10 +196,10 @@ class SemanticTokens(val compiler: Global) { for (val tree : T <- trees) build(tree) def build(tree0: Tree) : Unit = try { - /* if (tree0.pos != Position.NOPOS) */ tree0 match { + /* if (tree0.pos != NoPos) */ tree0 match { case tree: ImplDef => val pos = eatKeywords(unit.source, tree.pos) - if (pos == Position.NOPOS) { + if (pos == NoPos) { // inner types. // System.err.println("NOPOS: " + tree.getClass() + " " + (new Position(unit.source, tree.pos)).dbgString); //Thread.dumpStack(); @@ -210,15 +212,15 @@ class SemanticTokens(val compiler: Global) { build(tree.impl.body) case tree: ValOrDefDef => if (!tree.symbol.hasFlag(Flags.ACCESSOR)) { - { - val pos = if (tree.name.toString().equals("")) Position.NOPOS else - eatKeywords(unit.source, tree.pos); + { + val pos : Int = if (tree.name.toString().equals("")) NoPos else + eatKeywords(unit.source, tree.pos); if (false) System.err.println("VALDEF: tree=" + tree + " sym=" + tree.symbol + " pos0=" + tree.symbol.pos + " alias=" + tree.symbol.alias + " pos1=" + pos + " pos2=" + tree.pos + " " + unit.source.dbg(tree.pos) + " " + tree.symbol.hasFlag(Flags.SYNTHETIC)); - if (pos != Position.NOPOS && !tree.hasFlag(Flags.SYNTHETIC)) - buildDef(tree.symbol, pos); + if (pos != NoPos && !tree.hasFlag(Flags.SYNTHETIC)) + buildDef(tree.symbol, pos); } if (tree.isInstanceOf[DefDef]) { @@ -226,7 +228,7 @@ class SemanticTokens(val compiler: Global) { build(ddef.tparams); for (val l0 <- ddef.vparamss; val arg <- l0) { - val pos0 = if (!unit.source.beginsWith(arg.pos, "val ")) arg.pos; + val pos0 : Int = if (!unit.source.beginsWith(arg.pos, "val ")) arg.pos; else unit.source.skipWhitespace(arg.pos + ("val ").length()); buildDef(arg.symbol, pos0); build(arg.tpt); @@ -252,18 +254,18 @@ class SemanticTokens(val compiler: Global) { //System.err.println("PACKAGE: " + tree.name); if (false) { val pos = eatKeywords(unit.source, tree.pos) - if (pos != Position.NOPOS) + if (pos != NoPos) buildDef(tree.symbol, pos) } build(tree.stats) case tree: Function => - for (val arg <- tree.vparams) if (arg.pos != Position.NOPOS) { + for (val arg <- tree.vparams) if (arg.pos != NoPos) { val name = arg.name.toString().trim() val pos: Int = if (unit.source.beginsWith(arg.pos, "val ")) unit.source.skipWhitespace(arg.pos + ("val ").length()) else if (unit.source.content(arg.pos) == ':') { - var posx = arg.pos + var posx : Int = arg.pos while (Character.isWhitespace(unit.source.content(posx - 1))) posx = posx - 1 posx - name.length() } else arg.pos @@ -281,7 +283,7 @@ class SemanticTokens(val compiler: Global) { if (false) System.err.println("NO_ORIGINAL: " + tree + " " + tree.tpe + " " + classes(tree.tpe.getClass())); } if (tree.tpe != null) buildT(tree1, tree.tpe); - def buildT( tree : Tree, tpe : Type) : Unit = if (tree.pos != Position.NOPOS) tpe match { + def buildT( tree : Tree, tpe : Type) : Unit = if (tree.pos != NoPos) tpe match { case tpe0 : TypeRef => tree match { case apt : AppliedTypeTree => buildUse(tpe.symbol, apt.tpt.pos, tpe0); @@ -461,7 +463,7 @@ class SemanticTokens(val compiler: Global) { if (tree.symbol != null) buildUse(tree.symbol, tree.pos, tree.tpe); //Thread.dumpStack(); case tree : AliasTypeDef => - System.err.println("ALIAS: " + tree); + //System.err.println("ALIAS: " + tree); build(tree.rhs); build(tree.tparams); buildDef(tree.symbol, tree.pos); case tree : DocDef => build(tree.definition); case tree: Import => build(tree.expr) @@ -484,9 +486,9 @@ class SemanticTokens(val compiler: Global) { def buildSym(term: Symbol, pos: Int, isDef: Boolean, tpe: Type): Unit = if (term.hasFlag(Flags.ACCESSOR)) buildSym(term.accessed, pos, isDef, tpe) - else if (pos == Position.NOPOS) { - System.err.println("NOPOS: " + term) - Thread.dumpStack() + else if (pos == NoPos) { + //System.err.println("NOPOS: " + term) + //Thread.dumpStack() } else if (term != NoSymbol) { val name = NameTransformer.decode(term.name.toString()).toString().trim() @@ -515,7 +517,7 @@ class SemanticTokens(val compiler: Global) { } } - def selectPos(tree : Select): Int = if (tree.pos == Position.NOPOS) Position.NOPOS else { + def selectPos(tree : Select): Int = if (tree.pos == NoPos) NoPos else { val buf = unit.source.content if (tree.pos >= buf.length) { if (false) { @@ -527,7 +529,7 @@ class SemanticTokens(val compiler: Global) { return 0 } - val pos = + val pos : Int = if (buf(tree.pos) != '.') tree.pos else { def f(x : Int) : Int = { diff --git a/src/compiler/scala/tools/nsc/models/Signatures.scala b/src/compiler/scala/tools/nsc/models/Signatures.scala index 6499352a7b..43f5d3e73e 100644 --- a/src/compiler/scala/tools/nsc/models/Signatures.scala +++ b/src/compiler/scala/tools/nsc/models/Signatures.scala @@ -12,63 +12,58 @@ import scala.tools.nsc.symtab.{Flags,Names} import scala.tools.nsc.util.{NameTransformer,Position,SourceFile} class Signatures(val compiler: Compiler) { - import compiler._ + import compiler._; - class Signature(val name: String, val children: List[Signature]) { - def asString : String = name + "[" + asString0(children) + "]" + class Signature(val name : String, val children : List[Signature]) { + def asString : String = name + "[" + asString0(children) + "]"; } def sort(sigs : List[Signature]) = sigs.sort((l0,l1) => l0.name.compareTo(l1.name) > 0); - def asString0(sigs : List[Signature]) : String = { - var ret = "" - for (val sig <- sort(sigs)) ret = ret + sig.asString - ret + var ret = ""; + for (val sig <- sort(sigs)) + ret = ret + sig.asString; + ret; } def signature(unit: CompilationUnit): String = asString0(signature(unit.body, Nil)) - def signature(trees: List[Tree]): List[Signature] = { - var ret: List[Signature] = Nil - for (val tree <- trees) ret = signature(tree, ret) - ret + def signature(trees : List[Tree]) : List[Signature] = { + var ret : List[Signature] = Nil; + for (val tree <- trees) ret = signature(tree, ret); + ret; } + def signature(tree0 : Tree, rest : List[Signature]) : List[Signature] = tree0 match { + case tree : MemberDef => if (!tree.mods.isPrivate) { + val name = "" + tree.name + "::" + tree.mods; + val children : List[Signature] = (tree match { + case impl : ImplDef => + val supers = new Signature("$$supers", signature(impl.impl.parents)); + val body = new Signature("$$body", signature(impl.impl.body)); + val ret = supers :: body :: Nil; + (impl match { + case cdef : ClassDef => new Signature("$$tparams", signature(cdef.tparams)) :: ret; + case _ => ret; + }); + case vdef : ValOrDefDef => + val ret = signature(vdef.tpt, Nil); + (vdef match { + case ddef : DefDef => + val tparams = new Signature("$$tparams", signature(ddef.tparams)); + var vparamss : List[Signature] = Nil; + for (val list <- ddef.vparamss) vparamss = signature(list) ::: vparamss; + new Signature("$$ret", ret) :: tparams :: vparamss; + case _ => ret; + }); + case pdef : PackageDef => signature(pdef.stats); + case _ => Nil; + }); + new Signature(name, children) :: rest; - def signature(tree0: Tree, rest: List[Signature]): List[Signature] = tree0 match { - case tree: MemberDef => if (!tree.mods.isPrivate) { - val name = "" + tree.name + "::" + tree.mods - val children : List[Signature] = (tree match { - case impl : ImplDef => - val supers = new Signature("$$supers", signature(impl.impl.parents)) - val body = new Signature("$$body", signature(impl.impl.body)) - val ret = supers :: body :: Nil - (impl match { - case cdef: ClassDef => new Signature("$$tparams", signature(cdef.tparams)) :: ret; - case _ => ret - }); - case vdef: ValOrDefDef => - val ret = signature(vdef.tpt, Nil) - (vdef match { - case ddef : DefDef => - val tparams = new Signature("$$tparams", signature(ddef.tparams)); - var vparamss : List[Signature] = Nil; - for (val list <- ddef.vparamss) vparamss = signature(list) ::: vparamss; - tparams :: vparamss; - case _ => ret; - }); - case pdef : PackageDef => signature(pdef.stats); - case _ => Nil; - }); - new Signature(name, children) :: rest; - - } else - rest - case tree: TypeTree => - new Signature("" + tree.tpe, Nil) :: rest - case _ => - rest + } else rest; + case tree : TypeTree => new Signature("" + tree.tpe, Nil) :: rest; + case _ => rest; } - } diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 6efa735301..707b5e3748 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -223,8 +223,8 @@ trait Definitions requires SymbolTable { } private def newClass(owner: Symbol, name: Name, parents: List[Type]): Symbol = { - val clazz = owner.newClass(Position.NOPOS, name.toTypeName); - clazz.setInfo(ClassInfoType(parents, new Scope(), clazz)); + val clazz = owner.newClass(NoPos, name.toTypeName); + clazz.setInfo(ClassInfoType(parents, newScope, clazz)); owner.info.decls.enter(clazz); clazz } @@ -235,18 +235,18 @@ trait Definitions requires SymbolTable { clazz.setInfo( PolyType( List(tparam), - ClassInfoType(List(parent(tparam)), new Scope(), clazz))) + ClassInfoType(List(parent(tparam)), newScope, clazz))) } private def newAlias(owner: Symbol, name: Name, alias: Type): Symbol = { - val tpsym = owner.newAliasType(Position.NOPOS, name.toTypeName); + val tpsym = owner.newAliasType(NoPos, name.toTypeName); tpsym.setInfo(alias); owner.info.decls.enter(tpsym); tpsym } private def newMethod(owner: Symbol, name: Name): Symbol = { - val msym = owner.newMethod(Position.NOPOS, name.encode); + val msym = owner.newMethod(NoPos, name.encode); owner.info.decls.enter(msym); msym } @@ -264,7 +264,7 @@ trait Definitions requires SymbolTable { newMethod(owner, name).setInfo(PolyType(List(),restpe)) private def newTypeParam(owner: Symbol, index: int): Symbol = - owner.newTypeParameter(Position.NOPOS, "T" + index) + owner.newTypeParameter(NoPos, "T" + index) .setInfo(TypeBounds(AllClass.typeConstructor, AnyClass.typeConstructor)); val boxedClass = new HashMap[Symbol, Symbol] @@ -435,16 +435,16 @@ trait Definitions requires SymbolTable { if (isInitialized) return isInitialized = true RootClass = - NoSymbol.newClass(Position.NOPOS, nme.ROOT.toTypeName) + NoSymbol.newClass(NoPos, nme.ROOT.toTypeName) .setFlag(FINAL | MODULE | PACKAGE | JAVA).setInfo(rootLoader); - RootPackage = NoSymbol.newValue(Position.NOPOS, nme.ROOTPKG) + RootPackage = NoSymbol.newValue(NoPos, nme.ROOTPKG) .setFlag(FINAL | MODULE | PACKAGE | JAVA) .setInfo(PolyType(List(), RootClass.tpe)); EmptyPackage = - RootClass.newPackage(Position.NOPOS, nme.EMPTY_PACKAGE_NAME).setFlag(FINAL); + RootClass.newPackage(NoPos, nme.EMPTY_PACKAGE_NAME).setFlag(FINAL); EmptyPackageClass = EmptyPackage.moduleClass; - EmptyPackageClass.setInfo(ClassInfoType(List(), new Scope(), EmptyPackageClass)); + EmptyPackageClass.setInfo(ClassInfoType(List(), newScope, EmptyPackageClass)); EmptyPackage.setInfo(EmptyPackageClass.tpe) RootClass.info.decls.enter(EmptyPackage) @@ -569,7 +569,7 @@ trait Definitions requires SymbolTable { String_+ = newMethod( StringClass, "+", anyparam, StringClass.typeConstructor) setFlag FINAL; - PatternWildcard = NoSymbol.newValue(Position.NOPOS, "_").setInfo(AllClass.typeConstructor); + PatternWildcard = NoSymbol.newValue(NoPos, "_").setInfo(AllClass.typeConstructor); BoxedArrayClass = getClass("scala.runtime.BoxedArray") BoxedAnyArrayClass = getClass("scala.runtime.BoxedAnyArray") diff --git a/src/compiler/scala/tools/nsc/symtab/Flags.scala b/src/compiler/scala/tools/nsc/symtab/Flags.scala index eb245709df..38dbef1016 100644 --- a/src/compiler/scala/tools/nsc/symtab/Flags.scala +++ b/src/compiler/scala/tools/nsc/symtab/Flags.scala @@ -6,7 +6,6 @@ package scala.tools.nsc.symtab; object Flags { - // modifiers final val IMPLICIT = 0x00000001; final val FINAL = 0x00000002; diff --git a/src/compiler/scala/tools/nsc/symtab/Scopes.scala b/src/compiler/scala/tools/nsc/symtab/Scopes.scala index 0f0ae7b877..094f541262 100644 --- a/src/compiler/scala/tools/nsc/symtab/Scopes.scala +++ b/src/compiler/scala/tools/nsc/symtab/Scopes.scala @@ -31,7 +31,18 @@ trait Scopes requires SymbolTable { object NoScopeEntry extends ScopeEntry(NoSymbol, null) - class Scope(initElems: ScopeEntry) { + def newScope(initElems : ScopeEntry) : Scope = new NormalScope(initElems); + final def newScope : Scope = newScope(null : ScopeEntry); + final def newScope(base : Scope) : Scope = newScope(base.elems); + final def newScope(decls: List[Symbol]) : Scope = { + val ret = newScope; + decls.foreach(d => ret.enter(d)); + ret + } + + private class NormalScope(initElems : ScopeEntry) extends Scope(initElems); + + abstract class Scope(initElems: ScopeEntry) { var elems: ScopeEntry = initElems @@ -79,7 +90,7 @@ trait Scopes requires SymbolTable { /** Returns a new scope with the same content as this one. */ def cloneScope: Scope = { - val clone = new Scope() + val clone = newScope this.toList foreach clone.enter clone } @@ -216,7 +227,7 @@ trait Scopes requires SymbolTable { def elements: Iterator[Symbol] = toList.elements def filter(p: Symbol => boolean): Scope = - if (!(toList forall p)) new Scope(toList filter p) else this + if (!(toList forall p)) newScope(toList filter p) else this def mkString(start: String, sep: String, end: String) = toList.map(.defString).mkString(start, sep, end) diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala index 0136ab82a8..244e1d168a 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -86,7 +86,7 @@ abstract class SymbolLoaders { protected def doComplete(root: Symbol): unit = { assert(root.isPackageClass, root); - val scope = new Scope() + val scope = newScope root.setInfo(new PackageClassInfoType(scope, root)); /** Is the given name a valid input file base name? */ @@ -94,7 +94,7 @@ abstract class SymbolLoaders { name.length() > 0 && !name.endsWith("$class") && name.indexOf("$anon") == -1; def enterPackage(str: String, completer: SymbolLoader): unit = { - val pkg = root.newPackage(Position.NOPOS, newTermName(str)); + val pkg = root.newPackage(NoPos, newTermName(str)); pkg.moduleClass.setInfo(completer); pkg.setInfo(pkg.moduleClass.tpe); root.info.decls.enter(pkg) @@ -103,8 +103,8 @@ abstract class SymbolLoaders { def enterClassAndModule(str: String, completer: SymbolLoader): unit = { val owner = if (root.isRoot) definitions.EmptyPackageClass else root; val name = newTermName(str); - val clazz = owner.newClass(Position.NOPOS, name.toTypeName); - val module = owner.newModule(Position.NOPOS, name); + val clazz = owner.newClass(NoPos, name.toTypeName); + val module = owner.newModule(NoPos, name); clazz.setInfo(completer); module.setInfo(completer); module.moduleClass.setInfo(moduleClassLoader); diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 03e4549711..1f5f901ec3 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -23,9 +23,18 @@ trait Symbols requires SymbolTable { type AttrInfo = Triple[Type, List[Constant], List[Pair[Name,Constant]]] val emptySymbolArray = new Array[Symbol](0) + type PositionType; + val NoPos : PositionType; + val FirstPos : PositionType; + implicit def coercePosToInt(pos : PositionType) : Int; + def coerceIntToPos(pos : Int) : PositionType; + object RequiresIntsAsPositions { + implicit def coerceIntToPos0(pos : Int) = + coerceIntToPos(pos); + } /** The class for all symbols */ - abstract class Symbol(initOwner: Symbol, initPos: int, initName: Name) { + abstract class Symbol(initOwner: Symbol, initPos: PositionType, initName: Name) { var rawowner = initOwner var rawname = initName @@ -36,9 +45,10 @@ trait Symbols requires SymbolTable { var validTo: Period = NoPeriod def pos = rawpos - def setPos(pos: int): this.type = { this.rawpos = pos; this } + def setPos(pos: PositionType): this.type = { this.rawpos = pos; this } def namePos(source: SourceFile) = { + val pos : Int = this.pos; val buf = source.content if (pos == Position.NOPOS) Position.NOPOS else if (isTypeParameter) pos - name.length @@ -74,39 +84,39 @@ trait Symbols requires SymbolTable { // Creators ------------------------------------------------------------------- - final def newValue(pos: int, name: Name) = + final def newValue(pos: PositionType, name: Name) = new TermSymbol(this, pos, name) - final def newVariable(pos: int, name: Name) = + final def newVariable(pos: PositionType, name: Name) = newValue(pos, name).setFlag(MUTABLE) - final def newValueParameter(pos: int, name: Name) = + final def newValueParameter(pos: PositionType, name: Name) = newValue(pos, name).setFlag(PARAM) - final def newLocalDummy(pos: int) = + final def newLocalDummy(pos: PositionType) = newValue(pos, nme.LOCAL(this)).setInfo(NoType) - final def newMethod(pos: int, name: Name) = + final def newMethod(pos: PositionType, name: Name) = newValue(pos, name).setFlag(METHOD) - final def newLabel(pos: int, name: Name) = + final def newLabel(pos: PositionType, name: Name) = newMethod(pos, name).setFlag(LABEL) - final def newConstructor(pos: int) = + final def newConstructor(pos: PositionType) = newMethod(pos, nme.CONSTRUCTOR) - final def newModule(pos: int, name: Name, clazz: ClassSymbol) = + final def newModule(pos: PositionType, name: Name, clazz: ClassSymbol) = new ModuleSymbol(this, pos, name).setFlag(MODULE | FINAL).setModuleClass(clazz) - final def newModule(pos: int, name: Name) = { + final def newModule(pos: PositionType, name: Name) = { val m = new ModuleSymbol(this, pos, name).setFlag(MODULE | FINAL) m.setModuleClass(new ModuleClassSymbol(m)) } - final def newPackage(pos: int, name: Name) = { + final def newPackage(pos: PositionType, name: Name) = { assert(name == nme.ROOT || isPackageClass) val m = newModule(pos, name).setFlag(JAVA | PACKAGE) m.moduleClass.setFlag(JAVA | PACKAGE) m } - final def newThisSym(pos: int) = { + final def newThisSym(pos: PositionType) = { newValue(pos, nme.this_).setFlag(SYNTHETIC) } final def newThisSkolem: Symbol = new ThisSkolem(owner, pos, name, this) .setFlag(SYNTHETIC | FINAL) - final def newImport(pos: int) = + final def newImport(pos: PositionType) = newValue(pos, nme.IMPORT).setFlag(SYNTHETIC) final def newOverloaded(pre: Type, alternatives: List[Symbol]): Symbol = newValue(alternatives.head.pos, alternatives.head.name) @@ -115,28 +125,28 @@ trait Symbols requires SymbolTable { final def newErrorValue(name: Name) = newValue(pos, name).setFlag(SYNTHETIC | IS_ERROR).setInfo(ErrorType) - final def newAliasType(pos: int, name: Name) = + final def newAliasType(pos: PositionType, name: Name) = new TypeSymbol(this, pos, name) - final def newAbstractType(pos: int, name: Name) = + final def newAbstractType(pos: PositionType, name: Name) = new TypeSymbol(this, pos, name).setFlag(DEFERRED) - final def newTypeParameter(pos: int, name: Name) = + final def newTypeParameter(pos: PositionType, name: Name) = newAbstractType(pos, name).setFlag(PARAM) final def newTypeSkolem: Symbol = new TypeSkolem(owner, pos, name, this) .setFlag(flags) - final def newClass(pos: int, name: Name) = + final def newClass(pos: PositionType, name: Name) = new ClassSymbol(this, pos, name) - final def newModuleClass(pos: int, name: Name) = + final def newModuleClass(pos: PositionType, name: Name) = new ModuleClassSymbol(this, pos, name) - final def newAnonymousClass(pos: int) = + final def newAnonymousClass(pos: PositionType) = newClass(pos, nme.ANON_CLASS_NAME.toTypeName) - final def newAnonymousFunctionClass(pos: int) = { + final def newAnonymousFunctionClass(pos: PositionType) = { val anonfun = newClass(pos, nme.ANON_FUN_NAME.toTypeName) anonfun.attributes = Triple(definitions.SerializableAttr.tpe, List(), List()) :: anonfun.attributes anonfun } - final def newRefinementClass(pos: int) = + final def newRefinementClass(pos: PositionType) = newClass(pos, nme.REFINE_CLASS_NAME.toTypeName) final def newErrorClass(name: Name) = { val clazz = newClass(pos, name).setFlag(SYNTHETIC | IS_ERROR) @@ -860,7 +870,7 @@ trait Symbols requires SymbolTable { } /** A class for term symbols */ - class TermSymbol(initOwner: Symbol, initPos: int, initName: Name) extends Symbol(initOwner, initPos, initName) { + class TermSymbol(initOwner: Symbol, initPos: PositionType, initName: Name) extends Symbol(initOwner, initPos, initName) { override def isTerm = true privateWithin = NoSymbol @@ -896,7 +906,7 @@ trait Symbols requires SymbolTable { } /** A class for module symbols */ - class ModuleSymbol(initOwner: Symbol, initPos: int, initName: Name) extends TermSymbol(initOwner, initPos, initName) { + class ModuleSymbol(initOwner: Symbol, initPos: PositionType, initName: Name) extends TermSymbol(initOwner, initPos, initName) { private var flatname = nme.EMPTY @@ -923,7 +933,7 @@ trait Symbols requires SymbolTable { } /** A class for type parameters viewed from inside their scopes */ - class ThisSkolem(initOwner: Symbol, initPos: int, initName: Name, clazz: Symbol) extends TermSymbol(initOwner, initPos, initName) { + class ThisSkolem(initOwner: Symbol, initPos: PositionType, initName: Name, clazz: Symbol) extends TermSymbol(initOwner, initPos, initName) { override def deSkolemize = clazz override def cloneSymbolImpl(owner: Symbol): Symbol = { throw new Error("should not clone a this skolem") @@ -934,7 +944,7 @@ trait Symbols requires SymbolTable { /** A class of type symbols. Alias and abstract types are direct instances * of this class. Classes are instances of a subclass. */ - class TypeSymbol(initOwner: Symbol, initPos: int, initName: Name) extends Symbol(initOwner, initPos, initName) { + class TypeSymbol(initOwner: Symbol, initPos: PositionType, initName: Name) extends Symbol(initOwner, initPos, initName) { override def isType = true privateWithin = NoSymbol private var tyconCache: Type = null @@ -994,7 +1004,7 @@ trait Symbols requires SymbolTable { } /** A class for type parameters viewed from inside their scopes */ - class TypeSkolem(initOwner: Symbol, initPos: int, initName: Name, typeParam: Symbol) extends TypeSymbol(initOwner, initPos, initName) { + class TypeSkolem(initOwner: Symbol, initPos: PositionType, initName: Name, typeParam: Symbol) extends TypeSymbol(initOwner, initPos, initName) { override def deSkolemize = typeParam override def cloneSymbolImpl(owner: Symbol): Symbol = { throw new Error("should not clone a type skolem") @@ -1005,7 +1015,7 @@ trait Symbols requires SymbolTable { } /** A class for class symbols */ - class ClassSymbol(initOwner: Symbol, initPos: int, initName: Name) extends TypeSymbol(initOwner, initPos, initName) { + class ClassSymbol(initOwner: Symbol, initPos: PositionType, initName: Name) extends TypeSymbol(initOwner, initPos, initName) { /** The classfile from which this class was loaded. Maybe null. */ var classFile: AbstractFile = _; @@ -1078,7 +1088,7 @@ trait Symbols requires SymbolTable { /** A class for module class symbols * Note: Not all module classes are of this type; when unpickled, we get plain class symbols! */ - class ModuleClassSymbol(owner: Symbol, pos: int, name: Name) extends ClassSymbol(owner, pos, name) { + class ModuleClassSymbol(owner: Symbol, pos: PositionType, name: Name) extends ClassSymbol(owner, pos, name) { private var module: Symbol = null def this(module: TermSymbol) = { this(module.owner, module.pos, module.name.toTypeName) @@ -1090,14 +1100,14 @@ trait Symbols requires SymbolTable { } /** An object repreesenting a missing symbol */ - object NoSymbol extends Symbol(null, Position.NOPOS, nme.NOSYMBOL) { + object NoSymbol extends Symbol(null, NoPos, nme.NOSYMBOL) { setInfo(NoType) privateWithin = this override def setInfo(info: Type): this.type = { assert(info eq NoType); super.setInfo(info) } override def enclClass: Symbol = this override def toplevelClass: Symbol = this override def enclMethod: Symbol = this - override def owner: Symbol = throw new Error() + override def owner: Symbol = throw new Error("no-symbol does not have owner") override def sourceFile: AbstractFile = null override def ownerChain: List[Symbol] = List() override def alternatives: List[Symbol] = List() diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 80760e7de8..144a8f8333 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -415,7 +415,7 @@ trait Types requires SymbolTable { (member.owner == sym.owner || { if (self == null) self = this.narrow; !self.memberType(member).matches(self.memberType(sym))})) - members = new Scope(List(member, sym)); + members = newScope(List(member, sym)); } else { var prevEntry = members lookupEntry sym.name; while (prevEntry != null && @@ -1070,7 +1070,7 @@ trait Types requires SymbolTable { if (phase.erasedTypes) if (parents.isEmpty) ObjectClass.tpe else parents.head else { - val clazz = owner.newRefinementClass(Position.NOPOS); + val clazz = owner.newRefinementClass(NoPos); val result = new RefinedType(parents, decls) { override def symbol: Symbol = clazz } clazz.setInfo(result); result @@ -1079,7 +1079,7 @@ trait Types requires SymbolTable { /** the canonical creator for a refined type with an initially empty scope */ def refinedType(parents: List[Type], owner: Symbol): Type = - refinedType(parents, owner, new Scope) + refinedType(parents, owner, newScope) /** the canonical creator for a constant type */ def ConstantType(value: Constant): ConstantType = @@ -1299,7 +1299,7 @@ trait Types requires SymbolTable { val elems = scope.toList val elems1 = mapOver(elems) if (elems1 eq elems) scope - else new Scope(elems1) + else newScope(elems1) } /** Map this function over given list of symbols */ @@ -1499,6 +1499,8 @@ trait Types requires SymbolTable { /** The two symbols have the same fully qualified name */ def corresponds(sym1: Symbol, sym2: Symbol): boolean = sym1.name == sym2.name && (sym1.isPackageClass || corresponds(sym1.owner, sym2.owner)) + assert(sym != NoSymbol); + assert(rebind0 != NoSymbol); if (!corresponds(sym.owner, rebind0.owner)) { if (settings.debug.value) Console.println("ADAPT1 pre = "+pre+", sym = "+sym+sym.locationString+", rebind = "+rebind0+rebind0.locationString) val bcs = pre.baseClasses.dropWhile(bc => !corresponds(bc, sym.owner)); @@ -1790,6 +1792,7 @@ trait Types requires SymbolTable { sym2.isAliasType && tp2.memberType(sym2).substThis(tp2.symbol, tp1) =:= tp1.memberType(sym1) } + /** A function implementing tp1 matches tp2 */ private def matchesType(tp1: Type, tp2: Type): boolean = Pair(tp1, tp2) match { case Pair(MethodType(pts1, res1), MethodType(pts2, res2)) => @@ -2224,8 +2227,8 @@ trait Types requires SymbolTable { // Errors and Diagnostics --------------------------------------------------------- /** An exception signalling a type error */ - class TypeError(val pos: int, val msg: String) extends java.lang.Error(msg) { - def this(msg: String) = this(Position.NOPOS, msg) + class TypeError(val pos: PositionType, val msg: String) extends java.lang.Error(msg) { + def this(msg: String) = this(NoPos, msg) } class NoCommonType(tps: List[Type]) extends java.lang.Error( diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 1c539f9400..2ead4c4f66 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -300,8 +300,8 @@ abstract class ClassfileParser { val parents = (superType :: (for (val i <- List.range(0, ifaceCount)) yield pool.getSuperClass(in.nextChar).tpe)) - instanceDefs = new Scope() - staticDefs = new Scope() + instanceDefs = newScope + staticDefs = newScope val classInfo = ClassInfoType(parents, instanceDefs, clazz) val staticInfo = ClassInfoType(List(), staticDefs, statics) @@ -329,7 +329,7 @@ abstract class ClassfileParser { { //System.out.println("adding constructor to " + clazz);//DEBUG instanceDefs.enter( - clazz.newConstructor(Position.NOPOS) + clazz.newConstructor(NoPos) .setFlag(clazz.flags & ConstrFlags) .setInfo(MethodType(List(), clazz.tpe))) @@ -339,7 +339,7 @@ abstract class ClassfileParser { val value = instanceDefs.lookup(nme.value) if (value != NoSymbol) { instanceDefs.enter( - clazz.newConstructor(Position.NOPOS) + clazz.newConstructor(NoPos) .setFlag(clazz.flags & ConstrFlags) .setInfo(MethodType(List(value.tpe.resultType), clazz.tpe))) } @@ -358,7 +358,7 @@ abstract class ClassfileParser { val name = pool.getName(in.nextChar) val info = pool.getType(in.nextChar) val sym = getOwner(jflags) - .newValue(Position.NOPOS, name).setFlag(sflags) + .newValue(NoPos, name).setFlag(sflags) sym.setInfo(if ((jflags & JAVA_ACC_ENUM) == 0) info else ConstantType(Constant(sym))) setPrivateWithin(sym, jflags) parseAttributes(sym, info) @@ -382,7 +382,7 @@ abstract class ClassfileParser { info = MethodType(formals, clazz.tpe) } val sym = getOwner(jflags) - .newMethod(Position.NOPOS, name).setFlag(sflags).setInfo(info) + .newMethod(NoPos, name).setFlag(sflags).setInfo(info) setPrivateWithin(sym, jflags) parseAttributes(sym, info) getScope(jflags).enter(sym) @@ -426,9 +426,9 @@ abstract class ClassfileParser { } val name = fresh.newName("T_" + sym.name) val newtparam = - if (covariant) clazz.newAbstractType(Position.NOPOS, name) + if (covariant) clazz.newAbstractType(NoPos, name) else { - val s = sym.newTypeParameter(Position.NOPOS, name) + val s = sym.newTypeParameter(NoPos, name) newTParams += s s } @@ -485,7 +485,7 @@ abstract class ClassfileParser { index = index + 1 while (sig(index) != '>') { val tpname = subName(':'.==).toTypeName - val s = sym.newTypeParameter(Position.NOPOS, tpname) + val s = sym.newTypeParameter(NoPos, tpname) tparams = tparams + tpname -> s val ts = new ListBuffer[Type] while (sig(index) == ':') { @@ -637,7 +637,7 @@ abstract class ClassfileParser { (jflags & (JAVA_ACC_PUBLIC | JAVA_ACC_PROTECTED)) != 0 && pool.getClassSymbol(outerIndex) == sym) { val innerAlias = getOwner(jflags) - .newAliasType(Position.NOPOS, pool.getName(nameIndex).toTypeName) + .newAliasType(NoPos, pool.getName(nameIndex).toTypeName) .setInfo(pool.getClassSymbol(innerIndex).tpe) getScope(jflags).enter(innerAlias) } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala index 8f7e13164b..302834bc40 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala @@ -537,7 +537,7 @@ abstract class ICodeReader extends ClassfileParser { * TODO: 'isArgument' is always false, should be modified accordingly. */ def freshLocal(idx: Int, kind: TypeKind) = { - val sym = method.symbol.newVariable(Position.NOPOS, "loc" + idx).setInfo(kind.toType); + val sym = method.symbol.newVariable(NoPos, "loc" + idx).setInfo(kind.toType); new Local(sym, kind, false) } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/MetaParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/MetaParser.scala index 21293bd194..b5fc245c62 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/MetaParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/MetaParser.scala @@ -66,7 +66,7 @@ abstract class MetaParser{ else if (token == "-") { nextToken(); Flags.CONTRAVARIANT } else 0; assert(token.startsWith("?")); - val sym = owner.newTypeParameter(Position.NOPOS, newTypeName(token)).setFlag(vflag) + val sym = owner.newTypeParameter(NoPos, newTypeName(token)).setFlag(vflag) nextToken() val lo = if (token == ">") { nextToken(); parseType() } @@ -106,7 +106,7 @@ abstract class MetaParser{ } protected def parseClass(): unit = { - locals = new Scope() + locals = newScope def parse(): Type = { nextToken(); if (token == "[") { @@ -128,7 +128,7 @@ abstract class MetaParser{ protected def parseMethod(): unit = { val globals = locals - locals = if (locals == null) new Scope() else new Scope(locals); + locals = if (locals == null) newScope else newScope(locals); def parse(): Type = { nextToken(); if (token == "[") PolyType(parseTypeParams(), parse()) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala index 0d295489e1..a0522396d1 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala @@ -23,6 +23,7 @@ import java.io.IOException abstract class UnPickler { val global: Global import global._ + import RequiresIntsAsPositions._; def unpickle(bytes: Array[byte], offset: int, classRoot: Symbol, moduleRoot: Symbol, filename: String): unit = try { new UnPickle(bytes, offset, classRoot, moduleRoot) @@ -59,7 +60,7 @@ abstract class UnPickler { /** The scope associated with given symbol */ private def symScope(sym: Symbol) = symScopes.get(sym) match { - case None => val s = new Scope(); symScopes(sym) = s; s + case None => val s = newScope; symScopes(sym) = s; s case Some(s) => s } diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala index a7df6449dd..d07c56cfcf 100644 --- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala +++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala @@ -66,7 +66,7 @@ abstract class AddInterfaces extends InfoTransform { private class LazyImplClassType(iface: Symbol) extends LazyType { def implDecls(implClass: Symbol, ifaceDecls: Scope): Scope = { - val decls = new Scope() + val decls = newScope for (val sym <- ifaceDecls.elements) { if (isInterfaceMember(sym)) { if (needsImplMethod(sym)) { diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 610d9caab5..afb97969e7 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -32,7 +32,7 @@ abstract class CleanUp extends Transform { private def freshClassConstantMethName() = unit.fresh.newName("class$Method") private def freshClassConstantVarName() = unit.fresh.newName("class$Cache") - private def classConstantMethod(pos: int, sig: String): Symbol = classConstantMeth.get(sig) match { + private def classConstantMethod(pos: PositionType, sig: String): Symbol = classConstantMeth.get(sig) match { case Some(meth) => meth case None => diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 96d2805ef2..3e18fc8907 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -482,7 +482,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { private def bridgeDefs(owner: Symbol): List[Tree] = { //System.out.println("computing bridges for " + owner)//DEBUG val site = owner.thisType - val bridgesScope = new Scope() + val bridgesScope = newScope val bridgeTarget = new HashMap[Symbol, Symbol] var bridges: List[Tree] = List() val opc = atPhase(phase.prev) { // to avoid DEFERRED flags for interfaces diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index bd2edaa47b..be67c4cd26 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -50,7 +50,7 @@ abstract class ExplicitOuter extends InfoTransform { var decls1 = decls if (!(clazz hasFlag INTERFACE)) { if (!isStatic(clazz)) { - decls1 = new Scope(decls1.toList) + decls1 = newScope(decls1.toList) val outerAcc = clazz.newMethod(clazz.pos, nme.OUTER) if (clazz.isTrait || (decls.toList exists (.isClass))) outerAcc.expandName(clazz); @@ -62,7 +62,7 @@ abstract class ExplicitOuter extends InfoTransform { setInfo outerClass(clazz).thisType); } if (clazz.isTrait) { - decls1 = new Scope(decls1.toList) + decls1 = newScope(decls1.toList) decls1 enter makeMixinConstructor(clazz) } } diff --git a/src/compiler/scala/tools/nsc/transform/Flatten.scala b/src/compiler/scala/tools/nsc/transform/Flatten.scala index 38fb1d0493..f64fceb6c3 100644 --- a/src/compiler/scala/tools/nsc/transform/Flatten.scala +++ b/src/compiler/scala/tools/nsc/transform/Flatten.scala @@ -38,7 +38,7 @@ abstract class Flatten extends InfoTransform { typeRef(sym.toplevelClass.owner.thisType, sym, args) case ClassInfoType(parents, decls, clazz) => var parents1 = parents - val decls1 = new Scope() + val decls1 = newScope if (clazz.isPackageClass) { atPhase(phase.next)(decls.toList foreach (decls1 enter)) } else { diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 7dff2b0079..cce643d926 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -303,7 +303,7 @@ abstract class LambdaLift extends InfoTransform { } } - private def addFreeArgs(pos: int, sym: Symbol, args: List[Tree]) = { + private def addFreeArgs(pos: PositionType, sym: Symbol, args: List[Tree]) = { def freeArg(fv: Symbol) = atPos(pos)(proxyRef(fv)) val fvs = freeVars(sym).toList if (fvs.isEmpty) args else args ::: (fvs map freeArg) diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 4fb0dbba37..74ebe4f00c 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -184,12 +184,12 @@ abstract class Mixin extends InfoTransform { sourceModule setInfo sym.tpe assert(clazz.sourceModule != NoSymbol)//debug parents1 = List() - decls1 = new Scope(decls.toList filter isForwarded) + decls1 = newScope(decls.toList filter isForwarded) } else if (!parents.isEmpty) { parents1 = parents.head :: (parents.tail map toInterface) } } - //decls1 = atPhase(phase.next)(new Scope(decls1.toList))//debug + //decls1 = atPhase(phase.next)(newScope(decls1.toList))//debug if ((parents1 eq parents) && (decls1 eq decls)) tp else ClassInfoType(parents1, decls1, clazz); @@ -206,7 +206,7 @@ abstract class Mixin extends InfoTransform { class MixinTransformer extends Transformer { private var self: Symbol = _ - private val rootContext = erasure.NoContext.make(EmptyTree, RootClass, new Scope()) + private val rootContext = erasure.NoContext.make(EmptyTree, RootClass, newScope) private var localTyper: erasure.Typer = _ private var enclInterface: Symbol = _ @@ -246,7 +246,7 @@ abstract class Mixin extends InfoTransform { } } - private def selfRef(pos: int) = gen.mkAttributedIdent(self) setPos pos; + private def selfRef(pos: PositionType) = gen.mkAttributedIdent(self) setPos pos; private def staticRef(sym: Symbol) = { sym.owner.info @@ -259,13 +259,13 @@ abstract class Mixin extends InfoTransform { private def addNewDefs(clazz: Symbol, stats: List[Tree]): List[Tree] = { val newDefs = new ListBuffer[Tree] - def attributedDef(pos: int, tree: Tree): Tree = { + def attributedDef(pos: PositionType, tree: Tree): Tree = { if (settings.debug.value) System.out.println("add new def to " + clazz + ": " + tree); localTyper.typed { atPos(pos) { tree } } } def position(sym: Symbol) = - if (sym.pos == Position.NOPOS) clazz.pos else sym.pos - def addDef(pos: int, tree: Tree): unit = + if (sym.pos == NoPos) clazz.pos else sym.pos + def addDef(pos: PositionType, tree: Tree): unit = newDefs += attributedDef(pos, tree) def addDefDef(sym: Symbol, rhs: List[Symbol] => Tree): unit = addDef(position(sym), DefDef(sym, vparamss => rhs(vparamss.head))) diff --git a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala index 00d0c2a469..63e27168e8 100644 --- a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala +++ b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala @@ -51,7 +51,7 @@ abstract class OverridingPairs { ((bs1(nshifted) & bs2(nshifted) & (nmask | nmask - 1)) != 0)) } - private val decls = new Scope; + private val decls = newScope; { def fillDecls(bcs: List[Symbol], deferredflag: int): unit = if (!bcs.isEmpty) { fillDecls(bcs.tail, deferredflag) diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index e34a52db53..15dda5b11a 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -205,7 +205,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers { val formals = fun.tpe.typeArgs.init val restpe = fun.tpe.typeArgs.last anonClass setInfo ClassInfoType( - List(ObjectClass.tpe, fun.tpe, ScalaObjectClass.tpe), new Scope(), anonClass); + List(ObjectClass.tpe, fun.tpe, ScalaObjectClass.tpe), newScope, anonClass); val applyMethod = anonClass.newMethod(fun.pos, nme.apply) .setFlag(FINAL).setInfo(MethodType(formals, restpe)); anonClass.info.decls enter applyMethod; @@ -245,7 +245,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers { } } - def transformArgs(pos: int, args: List[Tree], formals: List[Type]) = { + def transformArgs(pos: PositionType, args: List[Tree], formals: List[Type]) = { if (formals.isEmpty) { assert(args.isEmpty); List() } else { diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index cac726f51e..5891da326e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -32,7 +32,7 @@ trait Contexts requires Analyzer { val qual = gen.mkAttributedStableRef(pkg) sc = sc.makeNewImport( Import(qual, List(Pair(nme.WILDCARD, null))) - .setSymbol(NoSymbol.newImport(Position.NOPOS).setInfo(ImportType(qual))) + .setSymbol(NoSymbol.newImport(NoPos).setInfo(ImportType(qual))) .setType(NoType)) sc.depth = sc.depth + 1 } @@ -142,7 +142,7 @@ trait Contexts requires Analyzer { make(unit, tree, owner, scope, imports) def makeNewScope(tree: Tree, owner: Symbol): Context = - make(tree, owner, new Scope(scope)) + make(tree, owner, newScope(scope)) def make(tree: Tree, owner: Symbol): Context = make(tree, owner, scope) @@ -186,13 +186,13 @@ trait Contexts requires Analyzer { throw er; } - def error(pos: int, msg: String): unit = + def error(pos: PositionType, msg: String): unit = if (reportGeneralErrors) unit.error(pos, if (checking) "**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg) else throw new TypeError(pos, msg) - def ambiguousError(pos: int, pre: Type, sym1: Symbol, sym2: Symbol, rest: String): unit = { + def ambiguousError(pos: PositionType, pre: Type, sym1: Symbol, sym2: Symbol, rest: String): unit = { val msg = ("ambiguous reference to overloaded definition,\n" + "both " + sym1 + sym1.locationString + " of type " + pre.memberType(sym1) + diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 67a7c5e5ec..9de82ec080 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -203,7 +203,7 @@ trait Infer requires Analyzer { def foundReqMsg(found: Type, req: Type): String = ";\n found : " + found.toLongString + "\n required: " + req; - def error(pos: int, msg: String): unit = + def error(pos: PositionType, msg: String): unit = context.error(pos, msg); def errorTree(tree: Tree, msg: String): Tree = { @@ -211,7 +211,7 @@ trait Infer requires Analyzer { setError(tree) } - def typeError(pos: int, found: Type, req: Type): unit = + def typeError(pos: PositionType, found: Type, req: Type): unit = if (!found.isErroneous && !req.isErroneous) { error(pos, "type mismatch" + foundReqMsg(found, req) + @@ -441,7 +441,7 @@ trait Infer requires Analyzer { } /** error if arguments not within bounds. */ - def checkBounds(pos: int, tparams: List[Symbol], targs: List[Type], prefix: String): unit = + def checkBounds(pos: PositionType, tparams: List[Symbol], targs: List[Type], prefix: String): unit = if (!isWithinBounds(tparams, targs)) { if (!(targs exists (.isErroneous)) && !(tparams exists (.isErroneous))) error(pos, diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index f0f19d839d..8059aa641c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -48,7 +48,7 @@ trait Namers requires Analyzer { sym } - def updatePosFlags(sym: Symbol, pos: int, flags: int): Symbol = { + def updatePosFlags(sym: Symbol, pos: PositionType, flags: int): Symbol = { if (settings.debug.value) log("overwriting " + sym); val lockedFlag = sym.flags & LOCKED; sym.reset(NoType); @@ -74,11 +74,11 @@ trait Namers requires Analyzer { def innerNamer: Namer = { if (innerNamerCache == null) innerNamerCache = if (!isTemplateContext(context)) this - else new Namer(context.make(context.tree, context.owner, new Scope())); + else new Namer(context.make(context.tree, context.owner, newScope)); innerNamerCache } - private def doubleDefError(pos: int, sym: Symbol): unit = + private def doubleDefError(pos: PositionType, sym: Symbol): unit = context.error(pos, sym.name.toString() + " is already defined as " + (if (sym.hasFlag(CASE)) "case class " + sym.name else sym.toString())); @@ -98,7 +98,7 @@ trait Namers requires Analyzer { sym } - private def enterPackageSymbol(pos: int, name: Name): Symbol = { + private def enterPackageSymbol(pos: PositionType, name: Name): Symbol = { val cscope = if (context.owner == EmptyPackageClass) RootClass.info.decls else context.scope; val p: Symbol = cscope.lookup(name); @@ -107,7 +107,7 @@ trait Namers requires Analyzer { } else { val cowner = if (context.owner == EmptyPackageClass) RootClass else context.owner; val pkg = cowner.newPackage(pos, name); - pkg.moduleClass.setInfo(new PackageClassInfoType(new Scope(), pkg.moduleClass)); + pkg.moduleClass.setInfo(new PackageClassInfoType(newScope, pkg.moduleClass)); pkg.setInfo(pkg.moduleClass.tpe); enterInScope(pkg) } @@ -117,7 +117,7 @@ trait Namers requires Analyzer { if (context.owner.isConstructor && !context.inConstructorSuffix) INCONSTRUCTOR else 0l; - private def enterClassSymbol(pos: int, flags: int, name: Name): Symbol = { + private def enterClassSymbol(pos: PositionType, flags: int, 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); @@ -139,7 +139,7 @@ trait Namers requires Analyzer { c } - private def enterModuleSymbol(pos: int, flags: int, name: Name): Symbol = { + private def enterModuleSymbol(pos: PositionType, flags: int, name: Name): Symbol = { var m: Symbol = context.scope.lookup(name); if (m.isModule && !m.isPackage && !currentRun.compiles(m) && (context.scope == m.owner.info.decls)) { @@ -159,7 +159,7 @@ trait Namers requires Analyzer { m } - private def enterCaseFactorySymbol(pos: int, flags: int, name: Name): Symbol = { + private def enterCaseFactorySymbol(pos: PositionType, flags: int, 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) @@ -385,7 +385,7 @@ trait Namers requires Analyzer { } } val parents = typer.parentTypes(templ) map checkParent - val decls = new Scope(); + val decls = newScope; new Namer(context.make(templ, clazz, decls)).enterSyms(templ.body); ClassInfoType(parents, decls, clazz) @@ -509,7 +509,7 @@ trait Namers requires Analyzer { val expr1 = typer.typedQualifier(expr); val base = expr1.tpe; typer.checkStable(expr1); - def checkNotRedundant(pos: int, from: Name, to: Name): boolean = { + def checkNotRedundant(pos: PositionType, from: Name, to: Name): boolean = { if (!base.symbol.isPackage && base.member(from) != NoSymbol) { val e = context.scope.lookupEntry(to) def warnRedundant(sym: Symbol) = diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index e5c82085fb..478e3e206b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -376,7 +376,7 @@ abstract class RefChecks extends InfoTransform { // Forward reference checking --------------------------------------------------- class LevelInfo(val outer: LevelInfo) { - val scope: Scope = if (outer == null) new Scope() else new Scope(outer.scope); + val scope: Scope = if (outer == null) newScope else newScope(outer.scope); var maxindex: int = Integer.MIN_VALUE; var refpos: int = _; var refsym: Symbol = _; diff --git a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala index f48f6eaf96..2d00a9d5ea 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala @@ -97,7 +97,7 @@ abstract class TreeCheckers extends Analyzer { } case _ => } - if (tree.pos == Position.NOPOS && tree != EmptyTree) { + if (tree.pos == NoPos && tree != EmptyTree) { error(tree.pos, "tree without position: " + tree) } else if (tree.tpe == 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 29a83910f1..fd80250a63 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -53,11 +53,11 @@ 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(Position.NOPOS, tp, pt, false) != EmptyTree + inferView(NoPos, tp, pt, false) != EmptyTree ) } - private def inferView(pos: int, from: Type, to: Type, reportAmbiguous: boolean): Tree = { + private def inferView(pos: PositionType, 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 { @@ -68,7 +68,7 @@ trait Typers requires Analyzer { } } - private def inferView(pos: int, from: Type, name: Name, tp: Type, reportAmbiguous: boolean): Tree = { + private def inferView(pos: PositionType, 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 @@ -129,9 +129,9 @@ trait Typers requires Analyzer { /** Report a type error. * @param pos The position where to report the error * @param ex The exception that caused the error */ - def reportTypeError(pos0: int, ex: TypeError): unit = { + def reportTypeError(pos0: PositionType, ex: TypeError): unit = { if (settings.debug.value) ex.printStackTrace() - val pos = if (ex.pos == Position.NOPOS) pos0 else ex.pos + val pos = if (ex.pos == NoPos) pos0 else ex.pos ex match { case CyclicReference(sym, info: TypeCompleter) => context.unit.error( @@ -158,7 +158,7 @@ trait Typers requires Analyzer { /** Check that type `tp' is not a subtype of itself. */ - def checkNonCyclic(pos: int, tp: Type): boolean = { + def checkNonCyclic(pos: PositionType, tp: Type): boolean = { def checkNotLocked(sym: Symbol): boolean = { sym.initialize if (sym hasFlag LOCKED) { @@ -184,7 +184,7 @@ trait Typers requires Analyzer { } } - def checkNonCyclic(pos: int, tp: Type, lockedSym: Symbol): boolean = { + def checkNonCyclic(pos: PositionType, tp: Type, lockedSym: Symbol): boolean = { lockedSym.setFlag(LOCKED) val result = checkNonCyclic(pos, tp) lockedSym.resetFlag(LOCKED) @@ -201,7 +201,7 @@ trait Typers requires Analyzer { } } - def checkParamsConvertible(pos: int, tpe: Type): unit = tpe match { + def checkParamsConvertible(pos: PositionType, tpe: Type): unit = tpe match { case MethodType(formals, restpe) => if (formals exists (.symbol.==(ByNameParamClass))) error(pos, "methods with `=>'-parameters cannot be converted to function values"); @@ -635,7 +635,7 @@ trait Typers requires Analyzer { reenterTypeParams(cdef.tparams) val tparams1 = List.mapConserve(cdef.tparams)(typedAbsTypeDef) val tpt1 = checkNoEscaping.privates(clazz.thisSym, typedType(cdef.tpt)) - val impl1 = newTyper(context.make(cdef.impl, clazz, new Scope())) + val impl1 = newTyper(context.make(cdef.impl, clazz, newScope)) .typedTemplate(cdef.impl, parentTypes(cdef.impl)) val impl2 = addSyntheticMethods(impl1, clazz, context.unit) val ret = copy.ClassDef(cdef, cdef.mods, cdef.name, tparams1, tpt1, impl2) @@ -647,7 +647,7 @@ trait Typers requires Analyzer { //System.out.println("sourcefile of " + mdef.symbol + "=" + mdef.symbol.sourceFile); attributes(mdef) val clazz = mdef.symbol.moduleClass - val impl1 = newTyper(context.make(mdef.impl, clazz, new Scope())) + val impl1 = newTyper(context.make(mdef.impl, clazz, newScope)) .typedTemplate(mdef.impl, parentTypes(mdef.impl)) val impl2 = addSyntheticMethods(impl1, clazz, context.unit) @@ -1768,7 +1768,7 @@ trait Typers requires Analyzer { val parents1 = List.mapConserve(templ.parents)(typedType) if (parents1 exists (.tpe.isError)) ErrorType else { - val decls = new Scope() + val decls = newScope val self = refinedType(parents1 map (.tpe), context.enclClass.owner, decls) newTyper(context.make(templ, self.symbol, decls)).typedRefinement(templ.body) self @@ -1909,7 +1909,7 @@ trait Typers requires Analyzer { * @returns A typed tree if the implicit info can be made to conform to `pt', EmptyTree otherwise. * @pre info.tpe does not contain an error */ - private def typedImplicit(pos: int, info: ImplicitInfo, pt: Type, isLocal: boolean): Tree = { + private def typedImplicit(pos: PositionType, info: ImplicitInfo, pt: Type, isLocal: boolean): Tree = { if (isCompatible(depoly(info.tpe), pt)) { val tree = Ident(info.name) setPos pos def fail(reason: String, sym1: Symbol, sym2: Symbol): Tree = { @@ -1939,7 +1939,7 @@ trait Typers requires Analyzer { * @param reportAmbiguous should ambiguous errors be reported? False iff we search for a view * to find out whether one type is coercible to another (@see isCoercible) */ - private def inferImplicit(pos: int, pt: Type, isView: boolean, reportAmbiguous: boolean): Tree = { + private def inferImplicit(pos: PositionType, pt: Type, isView: boolean, reportAmbiguous: boolean): Tree = { if (util.Statistics.enabled) implcnt = implcnt + 1 val startTime = if (util.Statistics.enabled) System.currentTimeMillis() else 0l -- cgit v1.2.3