From bc1714113b80807451689b1f3e244640e3874612 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 15 Dec 2005 17:22:34 +0000 Subject: --- sources/scala/tools/nsc/ast/Trees.scala | 52 +++++++++++++--------- sources/scala/tools/nsc/ast/parser/Parsers.scala | 2 +- .../scala/tools/nsc/models/SemanticTokens.scala | 20 ++++----- sources/scala/tools/nsc/symtab/Symbols.scala | 24 +++++----- 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/sources/scala/tools/nsc/ast/Trees.scala b/sources/scala/tools/nsc/ast/Trees.scala index fba4e84db5..7cc1486fd2 100644 --- a/sources/scala/tools/nsc/ast/Trees.scala +++ b/sources/scala/tools/nsc/ast/Trees.scala @@ -16,6 +16,14 @@ import symtab.Flags._; //statistics var nodeCount = 0; + case class Modifiers(flags: int, privateWithin: Name) { + def isPrivate = ((flags & PRIVATE ) != 0); + def isProtected = ((flags & PROTECTED) != 0); + def isVariable = ((flags & MUTABLE) != 0); + def isPublic = !isPrivate && !isProtected; + def this(flags: int) = this(flags, nme.EMPTY.toTypeName) + } + abstract class Tree { if (util.Statistics.enabled) nodeCount = nodeCount + 1; @@ -71,7 +79,8 @@ import symtab.Flags._; override var symbol: Symbol = NoSymbol; } - abstract class DefTree(val name0 : Name) extends SymTree { + abstract class DefTree extends SymTree { + def name: Name; override def isDef = true; } @@ -115,10 +124,12 @@ import symtab.Flags._; override def isEmpty = true; } - abstract class MemberDef(val mods0: int, name: Name) extends DefTree(name) { + abstract class MemberDef extends DefTree { + def mods: int; + def name: Name; def keyword : String; - def flags = new Flags.Flag(mods0); - final def hasFlag(mask: long): boolean = (mods0 & mask) != 0; + final def flags = new Flags.Flag(mods); + final def hasFlag(mask: long): boolean = (mods & mask) != 0; def namePos(source : SourceFile) : Int = if (pos == Position.NOPOS) Position.NOPOS else { assert(keyword != null); @@ -134,7 +145,8 @@ import symtab.Flags._; /** Package clause */ case class PackageDef(name: Name, stats: List[Tree]) - extends MemberDef(0, name) { + extends MemberDef { + def mods = 0; def keyword = "package"; } @@ -142,14 +154,13 @@ import symtab.Flags._; PackageDef(sym.name, stats) setSymbol sym; - - - abstract class ImplDef(mods : int, name: Name, val impl0: Template) extends MemberDef(mods, name); - + abstract class ImplDef extends MemberDef { + def impl: Template + } /** Class definition */ case class ClassDef(mods: int, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template) - extends ImplDef(mods, name, impl) { + extends ImplDef { def keyword = "class"; } @@ -174,7 +185,7 @@ import symtab.Flags._; /** Singleton object definition */ case class ModuleDef(mods: int, name: Name, impl: Template) - extends ImplDef(mods, name, impl) { + extends ImplDef { def keyword = "object"; } @@ -184,13 +195,14 @@ import symtab.Flags._; } - abstract class ValOrDefDef(mods: int, name: Name, val tpt0: Tree, val rhs0 : Tree) extends MemberDef(mods, name); - - + abstract class ValOrDefDef extends MemberDef { + def tpt: Tree; + def rhs: Tree; + } /** Value definition */ case class ValDef(mods: int, name: Name, tpt: Tree, rhs: Tree) - extends ValOrDefDef(mods, name, tpt, rhs) { + extends ValOrDefDef { assert(tpt.isType, tpt); assert(rhs.isTerm, rhs); def keyword = if (flags.isVariable) "var" else "val"; @@ -213,7 +225,7 @@ import symtab.Flags._; /** Method definition */ case class DefDef(mods: int, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) - extends ValOrDefDef(mods, name, tpt, rhs) { + extends ValOrDefDef { assert(tpt.isType); assert(rhs.isTerm); def keyword = "def"; @@ -237,7 +249,7 @@ import symtab.Flags._; /** Abstract type or type parameter */ case class AbsTypeDef(mods: int, name: Name, lo: Tree, hi: Tree) - extends DefTree(name) { + extends DefTree { def keyword = ""; override def setPos(pos : Int) : this.type = { @@ -255,7 +267,7 @@ import symtab.Flags._; /** Type alias */ case class AliasTypeDef(mods: int, name: Name, tparams: List[AbsTypeDef], rhs: Tree) - extends MemberDef(mods, name) { + extends MemberDef { def keyword = "type"; } @@ -277,7 +289,7 @@ import symtab.Flags._; * jumps within a Block. */ case class LabelDef(name: Name, params: List[Ident], rhs: Tree) - extends DefTree(name) with TermTree { + extends DefTree with TermTree { assert(rhs.isTerm); } @@ -353,7 +365,7 @@ import symtab.Flags._; /** Bind of a variable to a rhs pattern, eliminated by TransMatch */ case class Bind(name: Name, body: Tree) - extends DefTree(name); + extends DefTree; def Bind(sym: Symbol, body: Tree): Bind = Bind(sym.name, body) setSymbol sym; diff --git a/sources/scala/tools/nsc/ast/parser/Parsers.scala b/sources/scala/tools/nsc/ast/parser/Parsers.scala index f1f8e26760..2d1ee973a1 100755 --- a/sources/scala/tools/nsc/ast/parser/Parsers.scala +++ b/sources/scala/tools/nsc/ast/parser/Parsers.scala @@ -1062,7 +1062,7 @@ import Tokens._; /** Modifiers ::= {Modifier} * Modifier ::= final - * | private + * | private [ "[" Id "]" ] * | protected * | override * | abstract diff --git a/sources/scala/tools/nsc/models/SemanticTokens.scala b/sources/scala/tools/nsc/models/SemanticTokens.scala index d92fb33ac5..b9aa64de38 100644 --- a/sources/scala/tools/nsc/models/SemanticTokens.scala +++ b/sources/scala/tools/nsc/models/SemanticTokens.scala @@ -161,15 +161,15 @@ class SemanticTokens(val compiler: Compiler) { case cdef : ClassDef => build(cdef.tparams); case _ => ; } - build(tree.impl0.parents); - build(tree.impl0.body); + build(tree.impl.parents); + build(tree.impl.body); case tree : ValOrDefDef => if (tree.symbol.hasFlag(Flags.ACCESSOR)) { // ignore ; } else { { - val pos = if (tree.name0.toString().equals("")) Position.NOPOS else tree.namePos(unit.source); + val pos = if (tree.name.toString().equals("")) Position.NOPOS else tree.namePos(unit.source); if (pos != Position.NOPOS) { if (!tree.hasFlag(Flags.SYNTHETIC)) buildDef(tree.symbol, pos); @@ -185,20 +185,20 @@ class SemanticTokens(val compiler: Compiler) { val pos0 = if (!unit.source.beginsWith(arg.pos, "val ")) arg.pos; else unit.source.skipWhitespace(arg.pos + ("val ").length()); buildDef(arg.symbol, pos0); - build(arg.tpt0); + build(arg.tpt); } } try { - build(tree.tpt0); + build(tree.tpt); } catch { case e: Error => - System.err.println("VALDEF: " + tree + " " + tree.tpt0 + " " + tree.pos + " " + tree.tpt0.pos); + System.err.println("VALDEF: " + tree + " " + tree.tpt + " " + tree.pos + " " + tree.tpt.pos); throw e; } - build(tree.rhs0); + build(tree.rhs); } case tree : PackageDef => - //System.err.println("PACKAGE: " + tree.name0); + //System.err.println("PACKAGE: " + tree.name); if (false) { val pos = tree.namePos(unit.source); if (pos != Position.NOPOS) @@ -207,7 +207,7 @@ class SemanticTokens(val compiler: Compiler) { build(tree.stats); case tree : Function => for (val arg <- tree.vparams) if (arg.pos != Position.NOPOS) { - val name = arg.name0.toString().trim(); + 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) == ':') { @@ -216,7 +216,7 @@ class SemanticTokens(val compiler: Compiler) { posx - name.length(); } else arg.pos; buildDef(arg.symbol, pos); - build(arg.tpt0); + build(arg.tpt); } build(tree.body); case tree : TypeTree => diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala index 7dc213164f..6bdf29c54e 100755 --- a/sources/scala/tools/nsc/symtab/Symbols.scala +++ b/sources/scala/tools/nsc/symtab/Symbols.scala @@ -57,6 +57,8 @@ import Flags._; var attributes: List[AttrInfo] = List(); + var privateWithin: Symbol = null; + // Creators ------------------------------------------------------------------- final def newValue(pos: int, name: Name) = @@ -367,19 +369,19 @@ import Flags._; if (limit < phase.id) { if (validForRun == currentRun) { val current = phase; - var itr = infoTransformers.nextFrom(limit); - infoTransformers = itr; // caching optimization - while (itr.pid != NoPhase.id && itr.pid < current.id) { - phase = phaseWithId(itr.pid); - val info1 = itr.transform(this, infos.info); - limit = phase.id + 1; + var itr = infoTransformers.nextFrom(limit); + infoTransformers = itr; // caching optimization + while (itr.pid != NoPhase.id && itr.pid < current.id) { + phase = phaseWithId(itr.pid); + val info1 = itr.transform(this, infos.info); + limit = phase.id + 1; if (info1 ne infos.info) { infos = new TypeHistory(limit, info1, infos); - } - itr = itr.nextFrom(limit) - } - phase = current; - limit = current.id; + } + itr = itr.nextFrom(limit) + } + phase = current; + limit = current.id; } assert(infos != null, name); infos.info -- cgit v1.2.3