diff options
author | Sean McDirmid <sean.mcdirmid@gmail.com> | 2006-11-02 15:12:06 +0000 |
---|---|---|
committer | Sean McDirmid <sean.mcdirmid@gmail.com> | 2006-11-02 15:12:06 +0000 |
commit | d433eb14c8a069f349979282b0acb71cedb43b49 (patch) | |
tree | 91221f505760c5cd53c4f6978288617661c892e6 | |
parent | 2b3c8f9449bfd44375aa266035800c7b616aefbe (diff) | |
download | scala-d433eb14c8a069f349979282b0acb71cedb43b49.tar.gz scala-d433eb14c8a069f349979282b0acb71cedb43b49.tar.bz2 scala-d433eb14c8a069f349979282b0acb71cedb43b49.zip |
Some of these haven't changed, but SVN is too s...
Some of these haven't changed, but SVN is too stupid to care. Adding IDE
hooks to Global.
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 18 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreePrinters.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 28 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Scopes.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Analyzer.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 50 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 20 |
7 files changed, 101 insertions, 28 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 3a0e38c5c0..baeae2cc93 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -622,15 +622,21 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable def forCLDC: Boolean = settings.target.value == "cldc" def onlyPresentation = settings.doc.value // position stuff - protected val positionConfiguration: PositionConfiguration = new PositionConfiguration { + final val positionConfiguration: PositionConfiguration = initConfig; + protected def initConfig : PositionConfiguration = posConfig; + + private object posConfig extends PositionConfiguration { type PositionType = Int - def coercePosToInt(pos: PositionType): Int = pos - def coerceIntToPos(pos: Int): PositionType = pos - val NoPos: PositionType = Position.NOPOS - val FirstPos: PositionType = Position.FIRSTPOS + def coercePosToInt(pos: Int): Int = pos + def coerceIntToPos(pos: Int): Int = pos + val NoPos: Int = Position.NOPOS + val FirstPos: Int = Position.FIRSTPOS } final type PositionType = positionConfiguration.PositionType - final val FirstPos = positionConfiguration.FirstPos + final val FirstPos = { + val posConfig : PositionConfiguration = positionConfiguration; + posConfig.FirstPos.asInstanceOf[PositionType]; + } final val NoPos = positionConfiguration.NoPos final def coerceIntToPos(pos: Int): PositionType = positionConfiguration.coerceIntToPos(pos) diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala index e5bc54cfcf..237dbf8b46 100644 --- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala @@ -318,6 +318,7 @@ abstract class TreePrinters { case WildcardTypeTree(lo, hi) => print("_ "); printOpt(" >: ", lo); printOpt(" <: ", hi) + case tree if (tree != null) => print(tree.toString()) } if (global.settings.printtypes.value && tree.isTerm && !tree.isEmpty) { print("{"); print(if (tree.tpe == null) "<null>" else tree.tpe.toString()); print("}") diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 286f297b30..e9522577c7 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -91,6 +91,32 @@ trait Trees requires Global { case t: Tree => this eq t case _ => false } + def equalsStructure(that : Tree) : Boolean = if (this == that) true else (this:Any) match { + case thiz : CaseClass if (that != null && thiz.getClass == that.getClass) => + val that0 = that.asInstanceOf[CaseClass] + val result : Iterator[Boolean] = for (val i <- 0.until(thiz.caseArity)) yield thiz.caseElement(i) match { + case tree : Tree => + val b = tree.equalsStructure(that0.caseElement(i).asInstanceOf[Tree]) + b + case list : List[Any] if (that0.caseElement(i).isInstanceOf[List[Any]]) => + val listThat = that0.caseElement(i).asInstanceOf[List[Any]]; + if (list.length == listThat.length) (for (val x <- list.zip(listThat)) yield { + if (x._1 != null && x._1.isInstanceOf[Tree] && x._2.isInstanceOf[Tree]) { + val b = x._1.asInstanceOf[Tree] equalsStructure x._2.asInstanceOf[Tree] + b + } else x._1 == x._2 + }).foldLeft(true)((x,y) => x && y) else false; + case elem => + val b = elem == that0.caseElement(i) + b + } + val b = result.foldLeft(true)((x,y) => x && y) + if (b) { + tpe == that.tpe + } else false; + case _ => false; + } + def duplicate: this.type = (duplicator transform this).asInstanceOf[this.type] @@ -1087,7 +1113,7 @@ trait Trees requires Global { } def transformTrees(trees: List[Tree]): List[Tree] = - List.mapConserve(trees)(transform) + List.mapConserve(trees)(transform) def transformTemplate(tree: Template): Template = transform(tree: Tree).asInstanceOf[Template] def transformAbsTypeDefs(trees: List[AbsTypeDef]): List[AbsTypeDef] = diff --git a/src/compiler/scala/tools/nsc/symtab/Scopes.scala b/src/compiler/scala/tools/nsc/symtab/Scopes.scala index b7b4a827f9..3c2a1e8724 100644 --- a/src/compiler/scala/tools/nsc/symtab/Scopes.scala +++ b/src/compiler/scala/tools/nsc/symtab/Scopes.scala @@ -9,6 +9,9 @@ package scala.tools.nsc.symtab trait Scopes requires SymbolTable { class ScopeEntry(val sym: Symbol, val owner: Scope) { + /** hook to notify IDE that new symbol has been added to this scope */ + owner.enter00(sym); + /** the next entry in the hash bucket */ @@ -55,6 +58,11 @@ trait Scopes requires SymbolTable { var elems: ScopeEntry = initElems + /** hook for IDE + */ + protected def enter0(sym : Symbol) : Unit = {} + private[Scopes] def enter00(sym : Symbol) = enter0(sym); + /** The number of times this scope is neted in another */ private var nestinglevel = 0 diff --git a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala index abe5a0d0ef..91fcd64d5c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala @@ -17,8 +17,8 @@ trait Analyzer extends AnyRef with EtaExpansion with SyntheticMethods { - val global: Global - import global._ + val global : Global; + import global._; object namerFactory extends SubComponent { val global: Analyzer.this.global.type = Analyzer.this.global diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 8357a4cb80..156b9932cb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -24,10 +24,12 @@ trait Contexts requires Analyzer { NoContext.enclClass = NoContext NoContext.enclMethod = NoContext - private val startContext = NoContext.make( - Template(List(), List()) setSymbol NoSymbol setType NoType, - definitions.RootClass, - definitions.RootClass.info.decls) + private val startContext = { + NoContext.make( + global.Template(List(), List()) setSymbol global.NoSymbol setType global.NoType, + global.definitions.RootClass, + global.definitions.RootClass.info.decls) + } def rootContext(unit: CompilationUnit): Context = rootContext(unit, EmptyTree, false) @@ -72,7 +74,7 @@ trait Contexts requires Analyzer { class Context { var unit: CompilationUnit = _ var tree: Tree = _ // Tree associated with this context - var owner: Symbol = NoSymbol // The current owner + var owner: Symbol = NoSymbol// The current owner var scope: Scope = _ // The current scope var outer: Context = _ // The next outer context var enclClass: Context = _ // The next outer context whose tree is a @@ -97,14 +99,36 @@ trait Contexts requires Analyzer { override def equals(that : Any) = that match { case that if (super.equals(that)) => true - case txt : Context => - tree == txt.tree && owner == txt.owner && scope == txt.scope && - outer == txt.outer && enclClass == txt.enclClass && enclMethod == txt.enclMethod && - variance == txt.variance && _undetparams == txt._undetparams && - depth == txt.depth && imports == txt.imports && prefix == txt.prefix && - inConstructorSuffix == txt.inConstructorSuffix && implicitsEnabled == txt.implicitsEnabled && - checking == txt.checking && retyping == txt.retyping && - savedTypeBounds == txt.savedTypeBounds + case that : Context => + val a0 = if (tree == null) tree == that.tree else tree equalsStructure that.tree; + val a1 = owner == that.owner; + val a2 = scope == that.scope; + val a3 = outer == that.outer; + val a4 = { + if (enclClass eq this) { + that.enclClass eq that; + } else enclClass == that.enclClass; + } + val a5 = { + if (enclMethod eq this) + that.enclMethod eq that; + else enclMethod == that.enclMethod; + } + val a6 = variance == that.variance; + val a7 = _undetparams == that._undetparams; + val a8 = depth == that.depth; + val a9 = if (imports.length != that.imports.length) false else + (for (val x <- imports.zip(that.imports)) yield + (x._1.tree equalsStructure x._2.tree) && x._1.depth == x._2.depth). + foldLeft(true)((x,y) => x && y); + + val a10 = prefix == that.prefix; + val a11 = inConstructorSuffix == that.inConstructorSuffix; + val a12 = implicitsEnabled == that.implicitsEnabled; + val a13 = checking == that.checking; + val a14 = retyping == that.retyping; + val a15 = savedTypeBounds == that.savedTypeBounds; + a0 && a1 && a2 && a3 && a4 && a5 && a6 && a7 && a8 && a9 && a10 && a11 && a12 && a13 && a14 && a15 case _ => false; } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 581b1f9637..b01227da01 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -42,7 +42,9 @@ trait Namers requires Analyzer { mapOver(tp) } } - protected def doEnterValueParams = true; + /** overridden by IDE to not manually enter value parameters */ + protected final def doEnterValueParams = !inIDE; + protected def inIDE = false; class Namer(val context: Context) { @@ -196,8 +198,14 @@ trait Namers requires Analyzer { m } - def enterSyms(trees: List[Tree]): Namer = - (this /: trees) ((namer, tree) => namer.enterSym(tree)) + def enterSyms(trees: List[Tree]): Namer = { + var namer : Namer = this + for (val tree <- trees) { + val txt = namer.enterSym(tree) + if (!(txt eq namer.context)) namer = new Namer(txt) + } + namer + } def newTypeSkolems(tparams: List[Symbol]): List[Symbol] = { val tskolems = tparams map (.newTypeSkolem) @@ -220,7 +228,7 @@ trait Namers requires Analyzer { def deSkolemize: TypeMap = new DeSkolemizeMap(applicableTypeParams(context.owner)) - def enterSym(tree: Tree): Namer = { + def enterSym(tree: Tree): Context = { def finishWith(tparams: List[AbsTypeDef]): unit = { val sym = tree.symbol @@ -313,11 +321,11 @@ trait Namers requires Analyzer { case imp @ Import(_, _) => tree.symbol = NoSymbol.newImport(tree.pos) tree.symbol.setInfo(namerOf(tree.symbol).typeCompleter(tree)) - return new Namer(context.makeNewImport(imp)) + return (context.makeNewImport(imp)) case _ => } } - this + this.context } // --- Lazy Type Assignment -------------------------------------------------- |