From 2eba60d6412a6fc9fef83c70ed6263b076fb3940 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 Dec 2005 14:10:52 +0000 Subject: --- sources/scala/tools/nsc/ast/TreeInfo.scala | 6 +- sources/scala/tools/nsc/ast/TreePrinters.scala | 42 +++++--- sources/scala/tools/nsc/ast/Trees.scala | 88 ++++++++-------- sources/scala/tools/nsc/ast/parser/Parsers.scala | 72 +++++++------ .../tools/nsc/ast/parser/SymbolicXMLBuilder.scala | 6 +- .../scala/tools/nsc/ast/parser/TreeBuilder.scala | 14 +-- sources/scala/tools/nsc/symtab/Flags.scala | 17 +-- sources/scala/tools/nsc/symtab/Names.scala | 2 + sources/scala/tools/nsc/transform/UnCurry.scala | 2 +- .../scala/tools/nsc/typechecker/Codification.scala | 2 +- .../scala/tools/nsc/typechecker/EtaExpansion.scala | 4 +- sources/scala/tools/nsc/typechecker/Namers.scala | 115 ++++++++++++--------- 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(""); 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 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 rhs> */ @@ -227,7 +227,7 @@ abstract class TreeBuilder { } /** Create tree for pattern definition */ - 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) "