diff options
author | Martin Odersky <odersky@gmail.com> | 2005-12-16 14:10:52 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2005-12-16 14:10:52 +0000 |
commit | 2eba60d6412a6fc9fef83c70ed6263b076fb3940 (patch) | |
tree | b3a896c7e3889051920c7883119812076b17f882 /sources | |
parent | 8ef485ab1799a219407529851e6ac52d4392cec9 (diff) | |
download | scala-2eba60d6412a6fc9fef83c70ed6263b076fb3940.tar.gz scala-2eba60d6412a6fc9fef83c70ed6263b076fb3940.tar.bz2 scala-2eba60d6412a6fc9fef83c70ed6263b076fb3940.zip |
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/tools/nsc/ast/TreeInfo.scala | 6 | ||||
-rw-r--r-- | sources/scala/tools/nsc/ast/TreePrinters.scala | 42 | ||||
-rw-r--r-- | sources/scala/tools/nsc/ast/Trees.scala | 88 | ||||
-rw-r--r-- | sources/scala/tools/nsc/ast/parser/Parsers.scala | 72 | ||||
-rw-r--r-- | sources/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala | 6 | ||||
-rw-r--r-- | sources/scala/tools/nsc/ast/parser/TreeBuilder.scala | 14 | ||||
-rw-r--r-- | sources/scala/tools/nsc/symtab/Flags.scala | 17 | ||||
-rw-r--r-- | sources/scala/tools/nsc/symtab/Names.scala | 2 | ||||
-rw-r--r-- | sources/scala/tools/nsc/transform/UnCurry.scala | 2 | ||||
-rw-r--r-- | sources/scala/tools/nsc/typechecker/Codification.scala | 2 | ||||
-rw-r--r-- | sources/scala/tools/nsc/typechecker/EtaExpansion.scala | 4 | ||||
-rw-r--r-- | sources/scala/tools/nsc/typechecker/Namers.scala | 115 | ||||
-rw-r--r-- | sources/scala/tools/nsc/typechecker/Typers.scala | 15 |
13 files changed, 214 insertions, 171 deletions
diff --git a/sources/scala/tools/nsc/ast/TreeInfo.scala b/sources/scala/tools/nsc/ast/TreeInfo.scala index 8e082fec1e..dedfc6b03a 100644 --- a/sources/scala/tools/nsc/ast/TreeInfo.scala +++ b/sources/scala/tools/nsc/ast/TreeInfo.scala @@ -41,8 +41,8 @@ abstract class TreeInfo { case Import(_, _) => true case AbsTypeDef(_, _, _, _) => true case AliasTypeDef(_, _, _, _) => true - case DefDef(mods, _, _, _, _, __) => (mods & DEFERRED) != 0 - case ValDef(mods, _, _, _) => (mods & DEFERRED) != 0 + case DefDef(mods, _, _, _, _, __) => mods.hasFlag(DEFERRED) + case ValDef(mods, _, _, _) => mods.hasFlag(DEFERRED) case DocDef(_, definition) => isInterfaceMember(definition) case Attributed(_, definition) => isInterfaceMember(definition) case _ => false @@ -61,7 +61,7 @@ abstract class TreeInfo { | DefDef(_, _, _, _, _, _) => true case ValDef(mods, _, _, rhs) => - (mods & MUTABLE) == 0 && isPureExpr(rhs) + mods.hasFlag(MUTABLE) && isPureExpr(rhs) case DocDef(_, definition) => isPureDef(definition) case Attributed(_, definition) => diff --git a/sources/scala/tools/nsc/ast/TreePrinters.scala b/sources/scala/tools/nsc/ast/TreePrinters.scala index 2c6d8b2930..206fa58061 100644 --- a/sources/scala/tools/nsc/ast/TreePrinters.scala +++ b/sources/scala/tools/nsc/ast/TreePrinters.scala @@ -55,7 +55,7 @@ abstract class TreePrinters { def printValueParams(ts: List[ValDef]): unit = { print("("); - if (!ts.isEmpty) printModifiers(ts.head.mods & IMPLICIT); + if (!ts.isEmpty) printFlags(ts.head.mods.flags & IMPLICIT, nme.EMPTY.toTypeName); printSeq(ts){printParam}{print(", ")}; print(")") } @@ -79,12 +79,20 @@ abstract class TreePrinters { def printOpt(prefix: String, tree: Tree): unit = if (!tree.isEmpty) { print(prefix); print(tree) } - def printFlags(tree: Tree, flags: long): unit = - printModifiers(if (tree.symbol == NoSymbol) flags else tree.symbol.flags); + def printModifiers(tree: Tree, mods: Modifiers): unit = { + if (tree.symbol == NoSymbol) + printFlags(mods.flags, mods.privateWithin) + else if (tree.symbol.privateWithin == null) + printFlags(tree.symbol.flags, nme.EMPTY.toTypeName) + else + printFlags(tree.symbol.flags, tree.symbol.privateWithin.name) + } - def printModifiers(flags: long): unit = { + def printFlags(flags: long, privateWithin: Name): unit = { val mask = if (settings.debug.value) -1 else PrintableFlags; - val s = flagsToString(flags & mask); + val suffixes: List[Pair[long, String]] = + if (privateWithin.isEmpty) List() else List(Pair(PRIVATE, privateWithin.toString())); + val s = flagsToString(flags & mask, suffixes); if (s.length() != 0) print(s + " ") } @@ -97,8 +105,8 @@ abstract class TreePrinters { print("<empty>"); case ClassDef(mods, name, tparams, tp, impl) => - printFlags(tree, mods); - print((if ((mods & TRAIT) != 0) "trait " else "class ") + symName(tree, name)); + printModifiers(tree, mods); + print((if (mods.hasFlag(TRAIT)) "trait " else "class ") + symName(tree, name)); printTypeParams(tparams); printOpt(": ", tp); print(" extends "); print(impl); @@ -106,30 +114,30 @@ abstract class TreePrinters { print("package "); print(packaged); printColumn(stats, " {", ";", "}") case ModuleDef(mods, name, impl) => - printFlags(tree, mods); print("object " + symName(tree, name)); + printModifiers(tree, mods); print("object " + symName(tree, name)); print(" extends "); print(impl); case ValDef(mods, name, tp, rhs) => - printFlags(tree, mods); - print(if ((mods & MUTABLE) != 0) "var " else "val "); + printModifiers(tree, mods); + print(if (mods.hasFlag(MUTABLE)) "var " else "val "); print(symName(tree, name)); printOpt(": ", tp); - if ((mods & DEFERRED) == 0) { + if (!mods.hasFlag(DEFERRED)) { print(" = "); if (rhs.isEmpty) print("_") else print(rhs) } case DefDef(mods, name, tparams, vparamss, tp, rhs) => - printFlags(tree, mods); + printModifiers(tree, mods); print("def " + symName(tree, name)); printTypeParams(tparams); vparamss foreach printValueParams; printOpt(": ", tp); printOpt(" = ", rhs); case AbsTypeDef(mods, name, lo, hi) => - printFlags(tree, mods); print("type "); printParam(tree); + printModifiers(tree, mods); print("type "); printParam(tree); case AliasTypeDef(mods, name, tparams, rhs) => - printFlags(tree, mods); print("type " + symName(tree, name)); + printModifiers(tree, mods); print("type " + symName(tree, name)); printTypeParams(tparams); printOpt(" = ", rhs); case LabelDef(name, params, rhs) => @@ -214,13 +222,13 @@ abstract class TreePrinters { print(fun); printRow(vargs, "(", ", ", ")"); case Super(qual, mixin) => - if (qual != nme.EMPTY.toTypeName || tree.symbol != NoSymbol) print(symName(tree, qual) + "."); + if (!qual.isEmpty || tree.symbol != NoSymbol) print(symName(tree, qual) + "."); print("super"); - if (mixin != nme.EMPTY.toTypeName) + if (!mixin.isEmpty) print("[" + mixin + "]") case This(qual) => - if (qual != nme.EMPTY.toTypeName) print(symName(tree, qual) + "."); + if (!qual.isEmpty) print(symName(tree, qual) + "."); print("this"); case Select(qualifier, name) => diff --git a/sources/scala/tools/nsc/ast/Trees.scala b/sources/scala/tools/nsc/ast/Trees.scala index 7cc1486fd2..92b147c947 100644 --- a/sources/scala/tools/nsc/ast/Trees.scala +++ b/sources/scala/tools/nsc/ast/Trees.scala @@ -21,9 +21,18 @@ import symtab.Flags._; def isProtected = ((flags & PROTECTED) != 0); def isVariable = ((flags & MUTABLE) != 0); def isPublic = !isPrivate && !isProtected; - def this(flags: int) = this(flags, nme.EMPTY.toTypeName) + def hasFlag(flag: int) = (flags & flag) != 0; + def | (flag: int): Modifiers = { + val flags1 = flags | flag; + if (flags1 == flags) this else Modifiers(flags1, privateWithin) + } } + def Modifiers(flags: int): Modifiers = Modifiers(flags, nme.EMPTY.toTypeName); + def Modifiers(flags: long): Modifiers = Modifiers(flags.asInstanceOf[int]); + + val NoMods = Modifiers(0); + abstract class Tree { if (util.Statistics.enabled) nodeCount = nodeCount + 1; @@ -32,8 +41,6 @@ import symtab.Flags._; def pos = posx; - - var tpe: Type = _; def setPos(p: int): this.type = { posx = p; this } @@ -125,11 +132,10 @@ import symtab.Flags._; } abstract class MemberDef extends DefTree { - def mods: int; + def mods: Modifiers; def name: Name; def keyword : String; - final def flags = new Flags.Flag(mods); - final def hasFlag(mask: long): boolean = (mods & mask) != 0; + final def hasFlag(mask: long): boolean = (mods.flags & mask) != 0; def namePos(source : SourceFile) : Int = if (pos == Position.NOPOS) Position.NOPOS else { assert(keyword != null); @@ -146,7 +152,7 @@ import symtab.Flags._; /** Package clause */ case class PackageDef(name: Name, stats: List[Tree]) extends MemberDef { - def mods = 0; + def mods = NoMods; def keyword = "package"; } @@ -159,14 +165,14 @@ import symtab.Flags._; } /** Class definition */ - case class ClassDef(mods: int, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template) + case class ClassDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template) extends ImplDef { def keyword = "class"; } def ClassDef(sym: Symbol, impl: Template): ClassDef = posAssigner.atPos(sym.pos) { - ClassDef(flags2mods(sym.flags), + ClassDef(Modifiers(sym.flags), sym.name, sym.typeParams map AbsTypeDef, if (sym.thisSym == sym) EmptyTree else TypeTree(sym.typeOfThis), @@ -184,14 +190,14 @@ import symtab.Flags._; ClassDef(sym, Template(sym.info.parents map TypeTree, vparamss, argss, body)); /** Singleton object definition */ - case class ModuleDef(mods: int, name: Name, impl: Template) + case class ModuleDef(mods: Modifiers, name: Name, impl: Template) extends ImplDef { def keyword = "object"; } def ModuleDef(sym: Symbol, impl: Template): ModuleDef = posAssigner.atPos(sym.pos) { - ModuleDef(flags2mods(sym.flags), sym.name, impl) + ModuleDef(Modifiers(sym.flags), sym.name, impl) } @@ -201,11 +207,11 @@ import symtab.Flags._; } /** Value definition */ - case class ValDef(mods: int, name: Name, tpt: Tree, rhs: Tree) + case class ValDef(mods: Modifiers, name: Name, tpt: Tree, rhs: Tree) extends ValOrDefDef { assert(tpt.isType, tpt); assert(rhs.isTerm, rhs); - def keyword = if (flags.isVariable) "var" else "val"; + def keyword = if (mods.isVariable) "var" else "val"; override def namePos(source : SourceFile) = if (pos == Position.NOPOS) Position.NOPOS; else if (source.beginsWith(pos, "val ") || source.beginsWith(pos, "var ")) source.skipWhitespace(pos + ("val ").length()); @@ -216,14 +222,14 @@ import symtab.Flags._; def ValDef(sym: Symbol, rhs: Tree): ValDef = { posAssigner.atPos(sym.pos) { - ValDef(flags2mods(sym.flags), sym.name, TypeTree(sym.tpe), rhs) setSymbol sym + ValDef(Modifiers(sym.flags), sym.name, TypeTree(sym.tpe), rhs) setSymbol sym } } def ValDef(sym: Symbol): ValDef = ValDef(sym, EmptyTree); /** Method definition */ - case class DefDef(mods: int, name: Name, tparams: List[AbsTypeDef], + case class DefDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) extends ValOrDefDef { assert(tpt.isType); @@ -234,7 +240,7 @@ import symtab.Flags._; def DefDef(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef = posAssigner.atPos(sym.pos) { assert(sym != NoSymbol); - DefDef(flags2mods(sym.flags), + DefDef(Modifiers(sym.flags), sym.name, sym.typeParams map AbsTypeDef, vparamss, @@ -248,7 +254,7 @@ import symtab.Flags._; } /** Abstract type or type parameter */ - case class AbsTypeDef(mods: int, name: Name, lo: Tree, hi: Tree) + case class AbsTypeDef(mods: Modifiers, name: Name, lo: Tree, hi: Tree) extends DefTree { def keyword = ""; @@ -261,19 +267,19 @@ import symtab.Flags._; def AbsTypeDef(sym: Symbol): AbsTypeDef = posAssigner.atPos(sym.pos) { - AbsTypeDef(flags2mods(sym.flags), sym.name, + AbsTypeDef(Modifiers(sym.flags), sym.name, TypeTree(sym.info.bounds.lo), TypeTree(sym.info.bounds.hi)) } /** Type alias */ - case class AliasTypeDef(mods: int, name: Name, tparams: List[AbsTypeDef], rhs: Tree) + case class AliasTypeDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree) extends MemberDef { def keyword = "type"; } def AliasTypeDef(sym: Symbol, rhs: Tree): AliasTypeDef = posAssigner.atPos(sym.pos) { - AliasTypeDef(flags2mods(sym.flags), sym.name, sym.typeParams map AbsTypeDef, rhs) + AliasTypeDef(Modifiers(sym.flags), sym.name, sym.typeParams map AbsTypeDef, rhs) } /** Labelled expression - the symbols in the array (must be Idents!) @@ -326,13 +332,13 @@ import symtab.Flags._; /** Add constructor to template */ var vparamss1 = vparamss map (.map (vd => - ValDef(PARAM | (vd.mods & IMPLICIT), vd.name, vd.tpt.duplicate, EmptyTree))); + ValDef(Modifiers(vd.mods.flags & IMPLICIT | PARAM), vd.name, vd.tpt.duplicate, EmptyTree))); if (vparamss1.isEmpty || - !vparamss1.head.isEmpty && (vparamss1.head.head.mods & IMPLICIT) != 0) + !vparamss1.head.isEmpty && (vparamss1.head.head.mods.flags & IMPLICIT) != 0) vparamss1 = List() :: vparamss1; val superRef: Tree = Select(Super(nme.EMPTY.toTypeName, nme.EMPTY.toTypeName), nme.CONSTRUCTOR); val superCall = (superRef /: argss) (Apply); - val constr: Tree = DefDef(0, nme.CONSTRUCTOR, List(), vparamss1, TypeTree(), superCall); + val constr: Tree = DefDef(NoMods, nme.CONSTRUCTOR, List(), vparamss1, TypeTree(), superCall); Template(parents, List.flatten(vparamss) ::: constr :: body) } @@ -597,13 +603,13 @@ import symtab.Flags._; */ trait TreeCopier { - def ClassDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template): ClassDef; + def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template): ClassDef; def PackageDef(tree: Tree, name: Name, stats: List[Tree]): PackageDef; - def ModuleDef(tree: Tree, mods: int, name: Name, impl: Template): ModuleDef; - def ValDef(tree: Tree, mods: int, name: Name, tpt: Tree, rhs: Tree): ValDef; - def DefDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef; - def AbsTypeDef(tree: Tree, mods: int, name: Name, lo: Tree, hi: Tree): AbsTypeDef; - def AliasTypeDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], rhs: Tree): AliasTypeDef; + def ModuleDef(tree: Tree, mods: Modifiers, name: Name, impl: Template): ModuleDef; + def ValDef(tree: Tree, mods: Modifiers, name: Name, tpt: Tree, rhs: Tree): ValDef; + def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef; + def AbsTypeDef(tree: Tree, mods: Modifiers, name: Name, lo: Tree, hi: Tree): AbsTypeDef; + def AliasTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree): AliasTypeDef; def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree): LabelDef; def Import(tree: Tree, expr: Tree, selectors: List[Pair[Name, Name]]): Import; def Attributed(tree: Tree, attribute: Tree, definition: Tree): Attributed; @@ -640,19 +646,19 @@ import symtab.Flags._; } class StrictTreeCopier extends TreeCopier { - def ClassDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template) = + def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template) = new ClassDef(mods, name, tparams, tpt, impl).copyAttrs(tree); def PackageDef(tree: Tree, name: Name, stats: List[Tree]) = new PackageDef(name, stats).copyAttrs(tree); - def ModuleDef(tree: Tree, mods: int, name: Name, impl: Template) = + def ModuleDef(tree: Tree, mods: Modifiers, name: Name, impl: Template) = new ModuleDef(mods, name, impl).copyAttrs(tree); - def ValDef(tree: Tree, mods: int, name: Name, tpt: Tree, rhs: Tree) = + def ValDef(tree: Tree, mods: Modifiers, name: Name, tpt: Tree, rhs: Tree) = new ValDef(mods, name, tpt, rhs).copyAttrs(tree); - def DefDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) = + def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) = new DefDef(mods, name, tparams, vparamss, tpt, rhs).copyAttrs(tree); - def AbsTypeDef(tree: Tree, mods: int, name: Name, lo: Tree, hi: Tree) = + def AbsTypeDef(tree: Tree, mods: Modifiers, name: Name, lo: Tree, hi: Tree) = new AbsTypeDef(mods, name, lo, hi).copyAttrs(tree); - def AliasTypeDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], rhs: Tree) = + def AliasTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree) = new AliasTypeDef(mods, name, tparams, rhs).copyAttrs(tree); def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree) = new LabelDef(name, params, rhs).copyAttrs(tree); @@ -724,7 +730,7 @@ import symtab.Flags._; class LazyTreeCopier(copy: TreeCopier) extends TreeCopier { def this() = this(new StrictTreeCopier); - def ClassDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template) = tree match { + def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template) = tree match { case t @ ClassDef(mods0, name0, tparams0, tpt0, impl0) if (mods0 == mods && (name0 == name) && (tparams0 == tparams) && (tpt0 == tpt) && (impl0 == impl)) => t case _ => copy.ClassDef(tree, mods, name, tparams, tpt, impl) @@ -734,27 +740,27 @@ import symtab.Flags._; if ((name0 == name) && (stats0 == stats)) => t case _ => copy.PackageDef(tree, name, stats) } - def ModuleDef(tree: Tree, mods: int, name: Name, impl: Template) = tree match { + def ModuleDef(tree: Tree, mods: Modifiers, name: Name, impl: Template) = tree match { case t @ ModuleDef(mods0, name0, impl0) if (mods0 == mods && (name0 == name) && (impl0 == impl)) => t case _ => copy.ModuleDef(tree, mods, name, impl) } - def ValDef(tree: Tree, mods: int, name: Name, tpt: Tree, rhs: Tree) = tree match { + def ValDef(tree: Tree, mods: Modifiers, name: Name, tpt: Tree, rhs: Tree) = tree match { case t @ ValDef(mods0, name0, tpt0, rhs0) if (mods0 == mods && (name0 == name) && (tpt0 == tpt) && (rhs0 == rhs)) => t case _ => copy.ValDef(tree, mods, name, tpt, rhs) } - def DefDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) = tree match { + def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) = tree match { case t @ DefDef(mods0, name0, tparams0, vparamss0, tpt0, rhs0) if (mods0 == mods && (name0 == name) && (tparams0 == tparams) && (vparamss0 == vparamss) && (tpt0 == tpt) && (rhs == rhs0)) => t case _ => copy.DefDef(tree, mods, name, tparams, vparamss, tpt, rhs) } - def AbsTypeDef(tree: Tree, mods: int, name: Name, lo: Tree, hi: Tree) = tree match { + def AbsTypeDef(tree: Tree, mods: Modifiers, name: Name, lo: Tree, hi: Tree) = tree match { case t @ AbsTypeDef(mods0, name0, lo0, hi0) if (mods0 == mods && (name0 == name) && (lo0 == lo) && (hi0 == hi)) => t case _ => copy.AbsTypeDef(tree, mods, name, lo, hi) } - def AliasTypeDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], rhs: Tree) = tree match { + def AliasTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree) = tree match { case t @ AliasTypeDef(mods0, name0, tparams0, rhs0) if (mods0 == mods && (name0 == name) && (tparams0 == tparams) && (rhs0 == rhs)) => t case _ => copy.AliasTypeDef(tree, mods, name, tparams, rhs) diff --git a/sources/scala/tools/nsc/ast/parser/Parsers.scala b/sources/scala/tools/nsc/ast/parser/Parsers.scala index 2d1ee973a1..0fbfac53c1 100644 --- a/sources/scala/tools/nsc/ast/parser/Parsers.scala +++ b/sources/scala/tools/nsc/ast/parser/Parsers.scala @@ -204,12 +204,12 @@ import Tokens._; atPos(tree.pos) { tree match { case Ident(name) => - ValDef(Flags.PARAM, name, TypeTree(), EmptyTree) + ValDef(Modifiers(Flags.PARAM), name, TypeTree(), EmptyTree) case Typed(Ident(name), tpe) => - ValDef(Flags.PARAM, name, tpe, EmptyTree) + ValDef(Modifiers(Flags.PARAM), name, tpe, EmptyTree) case _ => syntaxError(tree.pos, "not a legal formal parameter", false); - ValDef(Flags.PARAM, nme.ERROR, errorTypeTree, EmptyTree) + ValDef(Modifiers(Flags.PARAM), nme.ERROR, errorTypeTree, EmptyTree) } } @@ -243,7 +243,7 @@ import Tokens._; errorTermTree } Function( - List(ValDef(Flags.PARAM, pname, TypeTree(), EmptyTree)), + List(ValDef(Modifiers(Flags.PARAM), pname, TypeTree(), EmptyTree)), insertParam(tree)) } @@ -1067,7 +1067,7 @@ import Tokens._; * | override * | abstract */ - def modifiers(): int = { + def modifiers(): Modifiers = { def loop(mods: int): int = in.token match { case ABSTRACT => loop(addMod(mods, Flags.ABSTRACT)) @@ -1089,14 +1089,14 @@ import Tokens._; var mods = loop(0); if ((mods & (Flags.ABSTRACT | Flags.OVERRIDE)) == (Flags.ABSTRACT | Flags.OVERRIDE)) mods = mods & ~(Flags.ABSTRACT | Flags.OVERRIDE) | Flags.ABSOVERRIDE; - mods + Modifiers(mods) } /** LocalClassModifiers ::= {LocalClassModifier} * LocalClassModifier ::= final * | private */ - def localClassModifiers(): int = { + def localClassModifiers(): Modifiers = { def loop(mods: int): int = in.token match { case ABSTRACT => loop(addMod(mods, Flags.ABSTRACT)) @@ -1107,7 +1107,7 @@ import Tokens._; case _ => mods } - loop(0) + Modifiers(loop(0)) } private def addMod(mods: int, mod: int): int = { @@ -1124,19 +1124,23 @@ import Tokens._; * Param ::= Id `:' ParamType * ClassParamClauses ::= {`(' [ClassParam {`' ClassParam}] ')'} * [`(' implicit ClassParam {`,' ClassParam} `)'] - * ClassParam ::= [[modifiers] val] Param + * ClassParam ::= [[modifiers] (val | var)] Param */ def paramClauses(owner: Name, implicitViews: List[Tree], ofCaseClass: boolean): List[List[ValDef]] = { var implicitmod = 0; var caseParam = ofCaseClass; def param(): ValDef = { atPos(in.currentPos) { - var mods = Flags.PARAM; + var mods = Modifiers(Flags.PARAM); if (owner.isTypeName) { mods = modifiers() | Flags.PARAMACCESSOR; - if (in.token == VAL) in.nextToken() - else { - if (mods != Flags.PARAMACCESSOR) accept(VAL); + if (in.token == VAL) { + in.nextToken() + } else if (in.token == VAR) { + mods = mods | Flags.MUTABLE; + in.nextToken() + } else { + if (mods.flags != Flags.PARAMACCESSOR) accept(VAL); if (!(caseParam)) mods = mods | Flags.PRIVATE | Flags.LOCAL; } if (caseParam) mods = mods | Flags.CASEACCESSOR; @@ -1173,8 +1177,8 @@ import Tokens._; } val result = vds.toList; if (owner == nme.CONSTRUCTOR && - (result.isEmpty || (!result.head.isEmpty && - (result.head.head.mods & Flags.IMPLICIT) != 0))) + (result.isEmpty || + (!result.head.isEmpty && result.head.head.mods.hasFlag(Flags.IMPLICIT)))) if (in.token == LBRACKET) syntaxError(pos, "no type parameters allowed here", false); else @@ -1208,7 +1212,7 @@ import Tokens._; */ def typeParamClauseOpt(owner: Name, implicitViews: ListBuffer[Tree]): List[AbsTypeDef] = { def typeParam(): AbsTypeDef = { - var mods = Flags.PARAM; + var mods = Modifiers(Flags.PARAM); if (owner.isTypeName && in.token == IDENTIFIER) { if (in.name == PLUS) { in.nextToken(); @@ -1241,7 +1245,7 @@ import Tokens._; /** TypeBounds ::= [`>:' Type] [`<:' Type] */ - def typeBounds(mods: int, name: Name): AbsTypeDef = { + def typeBounds(mods: Modifiers, name: Name): AbsTypeDef = { def bound(tok: int, default: Name): Tree = if (in.token == tok) { in.nextToken(); typ() } else scalaDot(default.toTypeName); @@ -1347,7 +1351,7 @@ import Tokens._; * | def FunDcl {`,' FunDcl} * | type TypeDcl {`,' TypeDcl} */ - def defOrDcl(mods: int): List[Tree] = { + def defOrDcl(mods: Modifiers): List[Tree] = { in.token match { case VAL => patDefOrDcl(mods); @@ -1366,7 +1370,7 @@ import Tokens._; /** PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr * ValDcl ::= Id {`,' Id} `:' Type */ - def patDefOrDcl(mods: int): List[Tree] = { + def patDefOrDcl(mods: Modifiers): List[Tree] = { var newmods = mods; var lhs = new ListBuffer[Tree]; do { @@ -1404,7 +1408,7 @@ import Tokens._; * | Id {`,' Id} `:' Type `=' `_' * VarDcl ::= Id {`,' Id} `:' Type */ - def varDefOrDcl(mods: int): List[Tree] = { + def varDefOrDcl(mods: Modifiers): List[Tree] = { var newmods = mods | Flags.MUTABLE; val lhs = new ListBuffer[Pair[Int, Name]]; do { @@ -1431,7 +1435,7 @@ import Tokens._; * FunDcl ::= FunSig `:' Type * FunSig ::= id [FunTypeParamClause] ParamClauses */ - def funDefOrDcl(mods: int): Tree = + def funDefOrDcl(mods: Modifiers): Tree = atPos(in.skipToken()) { if (in.token == THIS) { in.nextToken(); @@ -1480,7 +1484,7 @@ import Tokens._; /** TypeDef ::= Id `=' Type * TypeDcl ::= Id TypeBounds */ - def typeDefOrDcl(mods: int): Tree = + def typeDefOrDcl(mods: Modifiers): Tree = atPos(in.currentPos) { val name = ident().toTypeName; in.token match { @@ -1502,7 +1506,7 @@ import Tokens._; /** TmplDef ::= ([case] class | trait) ClassDef * | [case] object ObjectDef */ - def tmplDef(mods: int): Tree = in.token match { + def tmplDef(mods: Modifiers): Tree = in.token match { case TRAIT => classDef(mods | Flags.TRAIT | Flags.ABSTRACT); case CLASS => @@ -1521,24 +1525,24 @@ import Tokens._; /** ClassDef ::= ClassSig RequiresTypeOpt ClassTemplate * ClassSig ::= Id [TypeParamClause] {ClassParamClause} */ - def classDef(mods: int): Tree = + def classDef(mods: Modifiers): Tree = atPos(in.skipToken()) { val name = ident().toTypeName; val implicitViews = new ListBuffer[Tree]; val tparams = typeParamClauseOpt(name, implicitViews); - if ((mods & Flags.CASE) != 0 && in.token != LPAREN) accept(LPAREN); - val vparamss = paramClauses(name, implicitViews.toList, (mods & Flags.CASE) != 0); + if (mods.hasFlag(Flags.CASE) && in.token != LPAREN) accept(LPAREN); + val vparamss = paramClauses(name, implicitViews.toList, mods.hasFlag(Flags.CASE)); val thistpe = requiresTypeOpt(); val template = classTemplate(mods, name, vparamss); - val mods1 = if ((mods & TRAIT) != 0 && - (template.body forall treeInfo.isInterfaceMember)) mods | Flags.INTERFACE + val mods1 = if (mods.hasFlag(Flags.TRAIT) && (template.body forall treeInfo.isInterfaceMember)) + mods | Flags.INTERFACE else mods; ClassDef(mods1, name, tparams, thistpe, template) } /** ObjectDef ::= Id ClassTemplate */ - def objectDef(mods: int): Tree = + def objectDef(mods: Modifiers): Tree = atPos(in.skipToken()) { val name = ident(); val template = classTemplate(mods, name, List()); @@ -1548,7 +1552,7 @@ import Tokens._; /** ClassTemplate ::= [`extends' TemplateParents] [[NL] TemplateBody] * TemplateParents ::= SimpleType {`(' [Exprs] `)'} {`with' SimpleType} */ - def classTemplate(mods: int, name: Name, vparamss: List[List[ValDef]]): Template = { + def classTemplate(mods: Modifiers, name: Name, vparamss: List[List[ValDef]]): Template = { val ret = atPos(in.currentPos) { val parents = new ListBuffer[Tree]; val argss = new ListBuffer[List[Tree]]; @@ -1567,7 +1571,7 @@ import Tokens._; } else argss += List(); if (name != nme.ScalaObject.toTypeName) parents += scalaScalaObjectConstr; - if (/*name.isTypeName && */(mods & Flags.CASE) != 0) parents += caseClassConstr; + if (mods.hasFlag(Flags.CASE)) parents += caseClassConstr; val ps = parents.toList; if (in.token == NEWLINE && in.next.token == LBRACE) in.nextToken(); var body = @@ -1578,7 +1582,7 @@ import Tokens._; syntaxError("`extends' or `{' expected", true); List() } - if ((mods & Flags.TRAIT) == 0) Template(ps, vparamss, argss.toList, body) + if (!mods.hasFlag(Flags.TRAIT)) Template(ps, vparamss, argss.toList, body) else Template(ps, body) } ret; @@ -1728,7 +1732,7 @@ import Tokens._; val stats = new ListBuffer[Tree]; while (in.token != RBRACE && in.token != EOF) { if (isDclIntro) { - stats ++= joinComment(defOrDcl(0)) + stats ++= joinComment(defOrDcl(NoMods)) } else if (in.token != SEMI && in.token != NEWLINE) { syntaxError("illegal start of declaration", true); } @@ -1753,7 +1757,7 @@ import Tokens._; stats += expr(false, true); if (in.token != RBRACE && in.token != CASE) acceptStatSep(); } else if (isDefIntro) { - stats ++= defOrDcl(0); + stats ++= defOrDcl(NoMods); acceptStatSep(); if (in.token == RBRACE || in.token == CASE) { stats += Literal(()).setPos(in.currentPos) diff --git a/sources/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala b/sources/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala index dce7f1603c..4fc234bead 100644 --- a/sources/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala +++ b/sources/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala @@ -316,19 +316,19 @@ abstract class SymbolicXMLBuilder(make: TreeBuilder, p: Parsers # Parser, preser var ts2: List[Tree] = List(); if(moreAttributes) { - ts2 = atPos(pos) {ValDef(MUTABLE, + ts2 = atPos(pos) {ValDef(Modifiers(MUTABLE), _md, _scala_xml_MetaData, _scala_xml_Null)} :: tlist2; } if(moreNamespaces) { ts = atPos(pos) { - ValDef(MUTABLE, + ValDef(Modifiers(MUTABLE), _tmpscope, _scala_xml_NamespaceBinding, Ident(_scope))} :: ts; - ts2 = ValDef(0, _scope, _scala_xml_NamespaceBinding, Ident(_tmpscope)) :: ts2; + ts2 = ValDef(NoMods, _scope, _scala_xml_NamespaceBinding, Ident(_tmpscope)) :: ts2; } val makeSymbolicAttrs = { diff --git a/sources/scala/tools/nsc/ast/parser/TreeBuilder.scala b/sources/scala/tools/nsc/ast/parser/TreeBuilder.scala index 241dc45e45..70355350a7 100644 --- a/sources/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/sources/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -81,7 +81,7 @@ abstract class TreeBuilder { } else { val x = freshName(); Block( - List(ValDef(SYNTHETIC, x, TypeTree(), left)), + List(ValDef(Modifiers(SYNTHETIC), x, TypeTree(), left)), Apply(Select(right, op.encode), List(Ident(x)))) } } else { @@ -97,7 +97,7 @@ abstract class TreeBuilder { val x = nme.ANON_CLASS_NAME.toTypeName; Block( List(ClassDef( - FINAL | SYNTHETIC, x, List(), TypeTree(), + Modifiers(FINAL | SYNTHETIC), x, List(), TypeTree(), Template(parents, List(List()), argss, stats))), New(Ident(x), List(List()))) } @@ -159,7 +159,7 @@ abstract class TreeBuilder { def makeCont(pat: Tree, body: Tree): Tree = matchVarPattern(pat) match { case Some(Pair(name, tpt)) => - Function(List(ValDef(PARAM, name, tpt, EmptyTree)), body) + Function(List(ValDef(Modifiers(PARAM), name, tpt, EmptyTree)), body) case None => makeVisitor(List(CaseDef(pat, EmptyTree, body))) } @@ -218,7 +218,7 @@ abstract class TreeBuilder { /** Create visitor <x => x match cases> */ def makeVisitor(cases: List[CaseDef]): Tree = { val x = freshName(); - Function(List(ValDef(PARAM | SYNTHETIC, x, TypeTree(), EmptyTree)), Match(Ident(x), cases)) + Function(List(ValDef(Modifiers(PARAM | SYNTHETIC), x, TypeTree(), EmptyTree)), Match(Ident(x), cases)) } /** Create tree for case definition <case pat if guard => rhs> */ @@ -227,7 +227,7 @@ abstract class TreeBuilder { } /** Create tree for pattern definition <mods val pat0 = rhs> */ - def makePatDef(mods: int, pat: Tree, rhs: Tree): List[Tree] = matchVarPattern(pat) match { + def makePatDef(mods: Modifiers, pat: Tree, rhs: Tree): List[Tree] = matchVarPattern(pat) match { case Some(Pair(name, tpt)) => List(ValDef(mods, name, tpt, rhs)) @@ -255,7 +255,7 @@ abstract class TreeBuilder { List(ValDef(mods, vname, TypeTree(), matchExpr)) case _ => val tmp = freshName(); - val firstDef = ValDef(PRIVATE | LOCAL | SYNTHETIC, tmp, TypeTree(), matchExpr); + val firstDef = ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC), tmp, TypeTree(), matchExpr); var cnt = 0; val restDefs = for (val v <- vars) yield { cnt = cnt + 1; @@ -273,7 +273,7 @@ abstract class TreeBuilder { /** Append implicit view section if for `implicitViews' if nonempty */ def addImplicitViews(owner: Name, vparamss: List[List[ValDef]], implicitViews: List[Tree]): List[List[ValDef]] = { - val mods = if (owner.isTypeName) PARAMACCESSOR | LOCAL | PRIVATE else PARAM; + val mods = Modifiers(if (owner.isTypeName) PARAMACCESSOR | LOCAL | PRIVATE else PARAM); def makeViewParam(tpt: Tree) = ValDef(mods | IMPLICIT, freshName("view$"), tpt, EmptyTree); if (implicitViews.isEmpty) vparamss else vparamss ::: List(implicitViews map makeViewParam) diff --git a/sources/scala/tools/nsc/symtab/Flags.scala b/sources/scala/tools/nsc/symtab/Flags.scala index 36e4fe72f2..2627640d2e 100644 --- a/sources/scala/tools/nsc/symtab/Flags.scala +++ b/sources/scala/tools/nsc/symtab/Flags.scala @@ -116,12 +116,17 @@ object Flags { /** Module flags inherited by their module-class */ final val ModuleToClassFlags = AccessFlags | PACKAGE | CASE; - def flags2mods(flags: long): int = flags.asInstanceOf[int]; - - def flagsToString(flags: long): String = - List.range(0, 63) - .map(i => flagToString(flags & (1L << i))) - .filter("" !=).mkString("", " ", ""); + def flagsToString(flags: long, suffixes: List[Pair[long, String]]): String = + (for (val i <- List.range(0, 63)) yield { + var s = flagToString(flags & (1L << i)); + suffixes.find(._1.==(i)) match { + case Some(Pair(i, suffix)) => s = s + "[" + suffix + "]" + case None => + } + s + }).filter("" !=).mkString("", " ", ""); + + def flagsToString(flags: long): String = flagsToString(flags, List()); private def flagToString(flag: long): String = { if (flag == LABEL) "<label>" diff --git a/sources/scala/tools/nsc/symtab/Names.scala b/sources/scala/tools/nsc/symtab/Names.scala index 88d2d192cf..5fedb67ce4 100644 --- a/sources/scala/tools/nsc/symtab/Names.scala +++ b/sources/scala/tools/nsc/symtab/Names.scala @@ -132,6 +132,8 @@ class Names { */ final def length: int = len; + final def isEmpty = length == 0; + def isTermName: boolean; def isTypeName: boolean; def toTermName: Name; diff --git a/sources/scala/tools/nsc/transform/UnCurry.scala b/sources/scala/tools/nsc/transform/UnCurry.scala index dfa8252a73..a435b2a2b2 100644 --- a/sources/scala/tools/nsc/transform/UnCurry.scala +++ b/sources/scala/tools/nsc/transform/UnCurry.scala @@ -136,7 +136,7 @@ abstract class UnCurry extends InfoTransform { for (val vparam <- fun.vparams) vparam.symbol.owner = applyMethod; new ChangeOwnerTraverser(fun.symbol, applyMethod).traverse(fun.body); var members = List( - DefDef(FINAL, nme.apply, List(), List(fun.vparams), TypeTree(restpe), fun.body) + DefDef(Modifiers(FINAL), nme.apply, List(), List(fun.vparams), TypeTree(restpe), fun.body) setSymbol applyMethod); if (fun.tpe.symbol == PartialFunctionClass) { val isDefinedAtMethod = anonClass.newMethod(fun.pos, nme.isDefinedAt) diff --git a/sources/scala/tools/nsc/typechecker/Codification.scala b/sources/scala/tools/nsc/typechecker/Codification.scala index 169468b87b..1deda7bdfb 100644 --- a/sources/scala/tools/nsc/typechecker/Codification.scala +++ b/sources/scala/tools/nsc/typechecker/Codification.scala @@ -152,7 +152,7 @@ import scala.tools.nsc.util.{ListBuffer, FreshNameCreator}; val vdefs = for (val param <- params) yield { val lname = newTermName(fresh.newName()); env1 = env1.update(param, lname); - ValDef(0, lname, injectType("scala.reflect.LocalValue"), + ValDef(NoMods, lname, injectType("scala.reflect.LocalValue"), New(injectType("scala.reflect.LocalValue"), List(List(inject(param.owner), inject(param.name), inject(param.tpe))))) } diff --git a/sources/scala/tools/nsc/typechecker/EtaExpansion.scala b/sources/scala/tools/nsc/typechecker/EtaExpansion.scala index 3d1bc528ec..f6d481d58b 100644 --- a/sources/scala/tools/nsc/typechecker/EtaExpansion.scala +++ b/sources/scala/tools/nsc/typechecker/EtaExpansion.scala @@ -39,7 +39,7 @@ import symtab.Flags._; if (treeInfo.isPureExpr(tree)) tree else { val vname: Name = freshName(); - defs += atPos(tree.pos)(ValDef(SYNTHETIC, vname, TypeTree(), tree)); + defs += atPos(tree.pos)(ValDef(Modifiers(SYNTHETIC), vname, TypeTree(), tree)); Ident(vname) setPos tree.pos } tree match { @@ -60,7 +60,7 @@ import symtab.Flags._; tree case MethodType(formals, restpe) => val params = formals map (formal => - ValDef(SYNTHETIC | PARAM, freshName(), TypeTree().setType(formal), EmptyTree)); + ValDef(Modifiers(SYNTHETIC | PARAM), freshName(), TypeTree().setType(formal), EmptyTree)); val args = params map (param => Ident(param.name)); atPos(tree.pos)(Function(params, expand(Apply(tree, args), restpe))) case _ => diff --git a/sources/scala/tools/nsc/typechecker/Namers.scala b/sources/scala/tools/nsc/typechecker/Namers.scala index 20e65934e4..bb0aeed305 100644 --- a/sources/scala/tools/nsc/typechecker/Namers.scala +++ b/sources/scala/tools/nsc/typechecker/Namers.scala @@ -14,20 +14,6 @@ trait Namers: Analyzer { import global._; import definitions._; - def updatePosFlags(sym: Symbol, pos: int, mods: int): Symbol = { - if (settings.debug.value) log("overwriting " + sym); - val lockedFlag = sym.flags & LOCKED; - sym.reset(NoType); - sym setPos pos; - sym.flags = mods | lockedFlag; - if (sym.isModule && sym.moduleClass != NoSymbol) - updatePosFlags(sym.moduleClass, pos, (mods & ModuleToClassFlags) | MODULE | FINAL); - if (sym.owner.isPackageClass && sym.linkedSym.rawInfo.isInstanceOf[loaders.SymbolLoader]) - // pre-set linked symbol to NoType, in case it is not loaded together with this symbol. - sym.linkedSym.setInfo(NoType); - sym - } - /** Convert to corresponding type parameters all skolems which satisfy one of the * following two conditions: * 1. The skolem is a parameter of a class or alias type @@ -54,6 +40,22 @@ trait Namers: Analyzer { class Namer(val context: Context) { + def setPrivate(sym: Symbol, mods: Modifiers): Symbol = sym; + + def updatePosFlags(sym: Symbol, pos: int, flags: int): Symbol = { + if (settings.debug.value) log("overwriting " + sym); + val lockedFlag = sym.flags & LOCKED; + sym.reset(NoType); + sym setPos pos; + sym.flags = flags | lockedFlag; + if (sym.isModule && sym.moduleClass != NoSymbol) + updatePosFlags(sym.moduleClass, pos, (flags & ModuleToClassFlags) | MODULE | FINAL); + if (sym.owner.isPackageClass && sym.linkedSym.rawInfo.isInstanceOf[loaders.SymbolLoader]) + // pre-set linked symbol to NoType, in case it is not loaded together with this symbol. + sym.linkedSym.setInfo(NoType); + sym + } + private def isTemplateContext(context: Context): boolean = context.tree match { case Template(_, _) => true case Import(_, _) => isTemplateContext(context.outer) @@ -102,39 +104,39 @@ trait Namers: Analyzer { if (context.owner.isConstructor && !context.inConstructorSuffix) INCONSTRUCTOR else 0l; - private def enterClassSymbol(pos: int, mods: int, name: Name): Symbol = { + private def enterClassSymbol(pos: int, flags: int, name: Name): Symbol = { var c: Symbol = context.scope.lookup(name); if (c.isType && c.isExternal && context.scope == c.owner.info.decls) { - updatePosFlags(c, pos, mods); + updatePosFlags(c, pos, flags); } else { - c = enterInScope(context.owner.newClass(pos, name).setFlag(mods | inConstructorFlag)) + c = enterInScope(context.owner.newClass(pos, name)).setFlag(flags | inConstructorFlag); } if (c.owner.isPackageClass) currentRun.symSource(c) = context.unit.source.getFile(); c } - private def enterModuleSymbol(pos: int, mods: int, name: Name): Symbol = { + private def enterModuleSymbol(pos: int, flags: int, name: Name): Symbol = { var m: Symbol = context.scope.lookup(name); if (m.isModule && !m.isPackage && m.isExternal && (context.scope == m.owner.info.decls)) { - updatePosFlags(m, pos, mods) + updatePosFlags(m, pos, flags) } else { if (m.isTerm && !m.isPackage && m.isExternal && (context.scope == m.owner.info.decls)) context.scope.unlink(m); m = context.owner.newModule(pos, name); - m.setFlag(mods); - m.moduleClass.setFlag(mods | inConstructorFlag); + m.setFlag(flags); + m.moduleClass.setFlag(flags | inConstructorFlag); enterInScope(m) } if (m.owner.isPackageClass) currentRun.symSource(m) = context.unit.source.getFile(); m } - private def enterCaseFactorySymbol(pos: int, mods: int, name: Name): Symbol = { + private def enterCaseFactorySymbol(pos: int, flags: int, name: Name): Symbol = { var m: Symbol = context.scope.lookup(name); if (m.isTerm && !m.isPackage && m.isExternal && context.scope == m.owner.info.decls) { - updatePosFlags(m, pos, mods) + updatePosFlags(m, pos, flags) } else { - m = enterInScope(context.owner.newMethod(pos, name).setFlag(mods)) + m = enterInScope(context.owner.newMethod(pos, name)).setFlag(flags); } if (m.owner.isPackageClass) currentRun.symSource(m) = context.unit.source.getFile(); m @@ -178,6 +180,7 @@ trait Namers: Analyzer { } def finish = finishWith(List()); + if (tree.symbol == NoSymbol) { val owner = context.owner; tree match { @@ -187,54 +190,68 @@ trait Namers: Analyzer { context.make(tree, tree.symbol.moduleClass, tree.symbol.info.decls)); namer.enterSyms(stats); case ClassDef(mods, name, tparams, _, impl) => - if ((mods & (CASE | ABSTRACT)) == CASE) { // enter case factory method. + if ((mods.flags & (CASE | ABSTRACT)) == CASE) { // enter case factory method. tree.symbol = enterCaseFactorySymbol( - tree.pos, mods & AccessFlags | METHOD | CASE, name.toTermName) - .setInfo(innerNamer.caseFactoryCompleter(tree)) + tree.pos, mods.flags & AccessFlags | METHOD | CASE, name.toTermName) + .setInfo(innerNamer.caseFactoryCompleter(tree)); + setPrivate(tree.symbol, mods); } - tree.symbol = enterClassSymbol(tree.pos, mods, name); + tree.symbol = enterClassSymbol(tree.pos, mods.flags, name); + setPrivate(tree.symbol, mods); finishWith(tparams); case ModuleDef(mods, name, _) => - tree.symbol = enterModuleSymbol(tree.pos, mods | MODULE | FINAL, name); + tree.symbol = enterModuleSymbol(tree.pos, mods.flags | MODULE | FINAL, name); + setPrivate(tree.symbol, mods); + setPrivate(tree.symbol.moduleClass, mods); tree.symbol.moduleClass.setInfo(innerNamer.typeCompleter(tree)); finish case ValDef(mods, name, tp, rhs) => - if (context.owner.isClass & (mods & LOCAL) == 0) { - val accmods = - ((if ((mods & MUTABLE) != 0) mods & ~MUTABLE else mods | STABLE) | - (if ((mods & DEFERRED) == 0) ACCESSOR else 0)); + if (context.owner.isClass & (mods.flags & LOCAL) == 0) { + val accflags = + ((if ((mods.flags & MUTABLE) != 0) mods.flags & ~MUTABLE else mods.flags | STABLE) | + (if ((mods.flags & DEFERRED) == 0) ACCESSOR else 0)); val getter = owner.newMethod(tree.pos, name) - .setFlag(accmods).setInfo(innerNamer.getterTypeCompleter(tree)); + .setFlag(accflags) + .setInfo(innerNamer.getterTypeCompleter(tree)); + setPrivate(getter, mods); enterInScope(getter); - if ((mods & MUTABLE) != 0) { + if ((mods.flags & MUTABLE) != 0) { val setter = owner.newMethod(tree.pos, nme.getterToSetter(name)) - .setFlag(accmods & ~STABLE).setInfo(innerNamer.setterTypeCompleter(tree)); + .setFlag(accflags & ~STABLE & ~CASEACCESSOR) + .setInfo(innerNamer.setterTypeCompleter(tree)); + setPrivate(setter, mods); enterInScope(setter) } tree.symbol = - if ((mods & DEFERRED) == 0) - enterInScope( - owner.newValue(tree.pos, nme.getterToLocal(name)) - .setFlag(mods & FieldFlags | PRIVATE | LOCAL) - .setInfo(innerNamer.typeCompleter(tree))) + if ((mods.flags & DEFERRED) == 0) + enterInScope(owner.newValue(tree.pos, nme.getterToLocal(name))) + .setFlag(mods.flags & FieldFlags | PRIVATE | LOCAL) + .setInfo(innerNamer.typeCompleter(tree)) else getter; } else { - tree.symbol = - enterInScope(owner.newValue(tree.pos, name).setFlag(mods)); + tree.symbol = enterInScope(owner.newValue(tree.pos, name)) + .setFlag(mods.flags); finish } case DefDef(mods, nme.CONSTRUCTOR, tparams, vparams, tp, rhs) => tree.symbol = enterInScope(owner.newConstructor(tree.pos)) - .setFlag(mods | owner.getFlag(ConstrFlags)); + .setFlag(mods.flags | owner.getFlag(ConstrFlags)); + setPrivate(tree.symbol, mods); finishWith(tparams); case DefDef(mods, name, tparams, _, _, _) => - tree.symbol = enterInScope(owner.newMethod(tree.pos, name)).setFlag(mods); + tree.symbol = enterInScope(owner.newMethod(tree.pos, name)) + .setFlag(mods.flags); + setPrivate(tree.symbol, mods); finishWith(tparams); case AbsTypeDef(mods, name, _, _) => - tree.symbol = enterInScope(owner.newAbstractType(tree.pos, name)).setFlag(mods); + tree.symbol = enterInScope(owner.newAbstractType(tree.pos, name)) + .setFlag(mods.flags); + setPrivate(tree.symbol, mods); finish case AliasTypeDef(mods, name, tparams, _) => - tree.symbol = enterInScope(owner.newAliasType(tree.pos, name)).setFlag(mods); + tree.symbol = enterInScope(owner.newAliasType(tree.pos, name)) + .setFlag(mods.flags); + setPrivate(tree.symbol, mods); finishWith(tparams) case Attributed(attr, defn) => enterSym(defn); @@ -307,7 +324,9 @@ trait Namers: Analyzer { def enterValueParams(owner: Symbol, vparamss: List[List[ValDef]]): List[List[Symbol]] = { def enterValueParam(param: ValDef): Symbol = { param.symbol = owner.newValueParameter(param.pos, param.name) - .setInfo(typeCompleter(param)).setFlag(param.mods & (BYNAMEPARAM | IMPLICIT)); + .setInfo(typeCompleter(param)) + .setFlag(param.mods.flags & (BYNAMEPARAM | IMPLICIT)); + setPrivate(param.symbol, param.mods); context.scope enter param.symbol; param.symbol } diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala index 7cfa781624..f4098b615a 100644 --- a/sources/scala/tools/nsc/typechecker/Typers.scala +++ b/sources/scala/tools/nsc/typechecker/Typers.scala @@ -548,16 +548,15 @@ import collection.mutable.HashMap; } def addGetterSetter(stat: Tree): List[Tree] = stat match { - case ValDef(mods, name, tpe, rhs) if (mods & LOCAL) == 0 && !stat.symbol.isModuleVar => + case ValDef(mods, name, tpe, rhs) if !(mods hasFlag LOCAL) && !stat.symbol.isModuleVar => val vdef = copy.ValDef(stat, mods | PRIVATE | LOCAL, nme.getterToLocal(name), tpe, rhs); val value = vdef.symbol; - val getter = if ((mods & DEFERRED) != 0) value else value.getter(value.owner); - if (getter hasFlag OVERLOADED) System.out.println("overloaded getter: " + getter.alternatives + getter.alternatives.map(.tpe));//debug - assert(getter != NoSymbol, value);//debug + val getter = if (mods hasFlag DEFERRED) value else value.getter(value.owner); + assert(getter != NoSymbol, getter);//debug val getterDef: DefDef = { val result = atPos(vdef.pos)( DefDef(getter, vparamss => - if ((mods & DEFERRED) != 0) EmptyTree + if (mods hasFlag DEFERRED) EmptyTree else typed(atPos(vdef.pos)(Select(This(value.owner), value)), EXPRmode, value.tpe))); checkNoEscaping.privates(getter, result.tpt); result @@ -567,13 +566,13 @@ import collection.mutable.HashMap; assert(setter != NoSymbol, getter);//debug atPos(vdef.pos)( DefDef(setter, vparamss => - if ((mods & DEFERRED) != 0) EmptyTree + if (mods hasFlag DEFERRED) EmptyTree else typed(Assign(Select(This(value.owner), value), Ident(vparamss.head.head))))) } - val gs = if ((mods & MUTABLE) != 0) List(getterDef, setterDef) + val gs = if (mods hasFlag MUTABLE) List(getterDef, setterDef) else List(getterDef); - if ((mods & DEFERRED) != 0) gs else vdef :: gs + if (mods hasFlag DEFERRED) gs else vdef :: gs case DocDef(comment, defn) => addGetterSetter(defn) map (stat => DocDef(comment, stat)) case Attributed(attr, defn) => |