diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast')
-rwxr-xr-x | src/compiler/scala/tools/nsc/ast/DocComments.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Printers.scala | 82 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeDSL.scala | 76 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeGen.scala | 170 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeInfo.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 25 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 59 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Tokens.scala | 62 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala | 26 |
9 files changed, 293 insertions, 221 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/DocComments.scala b/src/compiler/scala/tools/nsc/ast/DocComments.scala index 40f97222a9..21407289db 100755 --- a/src/compiler/scala/tools/nsc/ast/DocComments.scala +++ b/src/compiler/scala/tools/nsc/ast/DocComments.scala @@ -22,9 +22,9 @@ trait DocComments { self: Global => val docComments = mutable.HashMap[Symbol, DocComment]() /** Associate comment with symbol `sym` at position `pos`. */ - // def docComment(sym: Symbol, docStr: String, pos: Position = NoPosition) = - // if ((sym ne null) && (sym ne NoSymbol)) - // docComments += (sym -> DocComment(docStr, pos)) + def docComment(sym: Symbol, docStr: String, pos: Position = NoPosition) = + if ((sym ne null) && (sym ne NoSymbol)) + docComments += (sym -> DocComment(docStr, pos)) /** The raw doc comment of symbol `sym`, as it appears in the source text, "" if missing. */ @@ -120,7 +120,7 @@ trait DocComments { self: Global => getDocComment(sym) map getUseCases getOrElse List() } - // def useCases(sym: Symbol): List[(Symbol, String, Position)] = useCases(sym, sym.enclClass) + def useCases(sym: Symbol): List[(Symbol, String, Position)] = useCases(sym, sym.enclClass) /** Returns the javadoc format of doc comment string `s`, including wiki expansion */ diff --git a/src/compiler/scala/tools/nsc/ast/Printers.scala b/src/compiler/scala/tools/nsc/ast/Printers.scala index d0aa004c9a..0414e0f123 100644 --- a/src/compiler/scala/tools/nsc/ast/Printers.scala +++ b/src/compiler/scala/tools/nsc/ast/Printers.scala @@ -200,17 +200,91 @@ trait Printers extends scala.reflect.internal.Printers { this: Global => override def printTree(tree: Tree) { print(safe(tree)) } } + class TreeMatchTemplate { + // non-trees defined in Trees + // + // case class ImportSelector(name: Name, namePos: Int, rename: Name, renamePos: Int) + // case class Modifiers(flags: Long, privateWithin: Name, annotations: List[Tree], positions: Map[Long, Position]) + // + def apply(t: Tree): Unit = t match { + // eliminated by typer + case Annotated(annot, arg) => + case AssignOrNamedArg(lhs, rhs) => + case DocDef(comment, definition) => + case Import(expr, selectors) => + + // eliminated by refchecks + case ModuleDef(mods, name, impl) => + case TypeTreeWithDeferredRefCheck() => + + // eliminated by erasure + case TypeDef(mods, name, tparams, rhs) => + case Typed(expr, tpt) => + + // eliminated by cleanup + case ApplyDynamic(qual, args) => + + // eliminated by explicitouter + case Alternative(trees) => + case Bind(name, body) => + case CaseDef(pat, guard, body) => + case Star(elem) => + case UnApply(fun, args) => + + // eliminated by lambdalift + case Function(vparams, body) => + + // eliminated by uncurry + case AppliedTypeTree(tpt, args) => + case CompoundTypeTree(templ) => + case ExistentialTypeTree(tpt, whereClauses) => + case SelectFromTypeTree(qual, selector) => + case SingletonTypeTree(ref) => + case TypeBoundsTree(lo, hi) => + + // survivors + case Apply(fun, args) => + case ArrayValue(elemtpt, trees) => + case Assign(lhs, rhs) => + case Block(stats, expr) => + case ClassDef(mods, name, tparams, impl) => + case DefDef(mods, name, tparams, vparamss, tpt, rhs) => + case EmptyTree => + case Ident(name) => + case If(cond, thenp, elsep) => + case LabelDef(name, params, rhs) => + case Literal(value) => + case Match(selector, cases) => + case New(tpt) => + case PackageDef(pid, stats) => + case Return(expr) => + case Select(qualifier, selector) => + case Super(qual, mix) => + case Template(parents, self, body) => + case This(qual) => + case Throw(expr) => + case Try(block, catches, finalizer) => + case TypeApply(fun, args) => + case TypeTree() => + case ValDef(mods, name, tpt, rhs) => + + // missing from the Trees comment + case Parens(args) => // only used during parsing + case SelectFromArray(qual, name, erasure) => // only used during erasure + } + } + def asString(t: Tree): String = render(t, newStandardTreePrinter, settings.printtypes.value, settings.uniqid.value, settings.Yshowsymkinds.value) def asCompactString(t: Tree): String = render(t, newCompactTreePrinter, settings.printtypes.value, settings.uniqid.value, settings.Yshowsymkinds.value) def asCompactDebugString(t: Tree): String = render(t, newCompactTreePrinter, true, true, true) def newStandardTreePrinter(writer: PrintWriter): TreePrinter = new TreePrinter(writer) - // def newStandardTreePrinter(stream: OutputStream): TreePrinter = newStandardTreePrinter(new PrintWriter(stream)) - // def newStandardTreePrinter(): TreePrinter = newStandardTreePrinter(new PrintWriter(ConsoleWriter)) + def newStandardTreePrinter(stream: OutputStream): TreePrinter = newStandardTreePrinter(new PrintWriter(stream)) + def newStandardTreePrinter(): TreePrinter = newStandardTreePrinter(new PrintWriter(ConsoleWriter)) def newCompactTreePrinter(writer: PrintWriter): CompactTreePrinter = new CompactTreePrinter(writer) - // def newCompactTreePrinter(stream: OutputStream): CompactTreePrinter = newCompactTreePrinter(new PrintWriter(stream)) - // def newCompactTreePrinter(): CompactTreePrinter = newCompactTreePrinter(new PrintWriter(ConsoleWriter)) + def newCompactTreePrinter(stream: OutputStream): CompactTreePrinter = newCompactTreePrinter(new PrintWriter(stream)) + def newCompactTreePrinter(): CompactTreePrinter = newCompactTreePrinter(new PrintWriter(ConsoleWriter)) override def newTreePrinter(writer: PrintWriter): TreePrinter = if (settings.Ycompacttrees.value) newCompactTreePrinter(writer) diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala index 0696b0e673..3acefe9441 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala @@ -84,16 +84,16 @@ trait TreeDSL { def ANY_EQ (other: Tree) = OBJ_EQ(other AS ObjectClass.tpe) def ANY_== (other: Tree) = fn(target, Any_==, other) def ANY_!= (other: Tree) = fn(target, Any_!=, other) - // def OBJ_== (other: Tree) = fn(target, Object_==, other) + def OBJ_== (other: Tree) = fn(target, Object_==, other) def OBJ_!= (other: Tree) = fn(target, Object_!=, other) def OBJ_EQ (other: Tree) = fn(target, Object_eq, other) def OBJ_NE (other: Tree) = fn(target, Object_ne, other) - // def INT_| (other: Tree) = fn(target, getMember(IntClass, nme.OR), other) - // def INT_& (other: Tree) = fn(target, getMember(IntClass, nme.AND), other) + def INT_| (other: Tree) = fn(target, getMember(IntClass, nme.OR), other) + def INT_& (other: Tree) = fn(target, getMember(IntClass, nme.AND), other) def INT_>= (other: Tree) = fn(target, getMember(IntClass, nme.GE), other) def INT_== (other: Tree) = fn(target, getMember(IntClass, nme.EQ), other) - // def INT_!= (other: Tree) = fn(target, getMember(IntClass, nme.NE), other) + def INT_!= (other: Tree) = fn(target, getMember(IntClass, nme.NE), other) // generic operations on ByteClass, IntClass, LongClass def GEN_| (other: Tree, kind: ClassSymbol) = fn(target, getMember(kind, nme.OR), other) @@ -101,8 +101,8 @@ trait TreeDSL { def GEN_== (other: Tree, kind: ClassSymbol) = fn(target, getMember(kind, nme.EQ), other) def GEN_!= (other: Tree, kind: ClassSymbol) = fn(target, getMember(kind, nme.NE), other) - // def BOOL_&& (other: Tree) = fn(target, Boolean_and, other) - // def BOOL_|| (other: Tree) = fn(target, Boolean_or, other) + def BOOL_&& (other: Tree) = fn(target, Boolean_and, other) + def BOOL_|| (other: Tree) = fn(target, Boolean_or, other) /** Apply, Select, Match **/ def APPLY(params: Tree*) = Apply(target, params.toList) @@ -158,7 +158,7 @@ trait TreeDSL { def mkTree(rhs: Tree): ResultTreeType def ===(rhs: Tree): ResultTreeType - // private var _mods: Modifiers = null + private var _mods: Modifiers = null private var _tpt: Tree = null private var _pos: Position = null @@ -166,19 +166,19 @@ trait TreeDSL { _tpt = TypeTree(tp) this } - // def withFlags(flags: Long*): this.type = { - // if (_mods == null) - // _mods = defaultMods + def withFlags(flags: Long*): this.type = { + if (_mods == null) + _mods = defaultMods - // _mods = flags.foldLeft(_mods)(_ | _) - // this - // } + _mods = flags.foldLeft(_mods)(_ | _) + this + } def withPos(pos: Position): this.type = { _pos = pos this } - final def mods = defaultMods // if (_mods == null) defaultMods else _mods + final def mods = if (_mods == null) defaultMods else _mods final def tpt = if (_tpt == null) defaultTpt else _tpt final def pos = if (_pos == null) defaultPos else _pos } @@ -243,7 +243,7 @@ trait TreeDSL { } class TryStart(body: Tree, catches: List[CaseDef], fin: Tree) { def CATCH(xs: CaseDef*) = new TryStart(body, xs.toList, fin) - // def FINALLY(x: Tree) = Try(body, catches, x) + def FINALLY(x: Tree) = Try(body, catches, x) def ENDTRY = Try(body, catches, fin) } @@ -251,16 +251,16 @@ trait TreeDSL { def DEFAULT: CaseStart = new CaseStart(WILD.empty, EmptyTree) class SymbolMethods(target: Symbol) { - // def BIND(body: Tree) = Bind(target, body) + def BIND(body: Tree) = Bind(target, body) def IS_NULL() = REF(target) OBJ_EQ NULL - // def NOT_NULL() = REF(target) OBJ_NE NULL + def NOT_NULL() = REF(target) OBJ_NE NULL def GET() = fn(REF(target), nme.get) // name of nth indexed argument to a method (first parameter list), defaults to 1st - // def ARG(idx: Int = 0) = Ident(target.paramss.head(idx)) + def ARG(idx: Int = 0) = Ident(target.paramss.head(idx)) def ARGS = target.paramss.head - // def ARGNAMES = ARGS map Ident + def ARGNAMES = ARGS map Ident } /** Top level accessible. */ @@ -268,31 +268,31 @@ trait TreeDSL { def THROW(sym: Symbol, msg: Tree): Throw = Throw(sym.tpe, msg.TOSTRING()) def NEW(tpt: Tree, args: Tree*): Tree = New(tpt, List(args.toList)) - // def NEW(sym: Symbol, args: Tree*): Tree = New(sym.tpe, args: _*) + def NEW(sym: Symbol, args: Tree*): Tree = New(sym.tpe, args: _*) - // def DEF(name: Name, tp: Type): DefTreeStart = DEF(name) withType tp - // def DEF(name: Name): DefTreeStart = new DefTreeStart(name) + def DEF(name: Name, tp: Type): DefTreeStart = DEF(name) withType tp + def DEF(name: Name): DefTreeStart = new DefTreeStart(name) def DEF(sym: Symbol): DefSymStart = new DefSymStart(sym) - // def VAL(name: Name, tp: Type): ValTreeStart = VAL(name) withType tp - // def VAL(name: Name): ValTreeStart = new ValTreeStart(name) + def VAL(name: Name, tp: Type): ValTreeStart = VAL(name) withType tp + def VAL(name: Name): ValTreeStart = new ValTreeStart(name) def VAL(sym: Symbol): ValSymStart = new ValSymStart(sym) - // def VAR(name: Name, tp: Type): ValTreeStart = VAL(name, tp) withFlags Flags.MUTABLE - // def VAR(name: Name): ValTreeStart = VAL(name) withFlags Flags.MUTABLE - // def VAR(sym: Symbol): ValSymStart = VAL(sym) withFlags Flags.MUTABLE + def VAR(name: Name, tp: Type): ValTreeStart = VAL(name, tp) withFlags Flags.MUTABLE + def VAR(name: Name): ValTreeStart = VAL(name) withFlags Flags.MUTABLE + def VAR(sym: Symbol): ValSymStart = VAL(sym) withFlags Flags.MUTABLE - // def LAZYVAL(name: Name, tp: Type): ValTreeStart = VAL(name, tp) withFlags Flags.LAZY - // def LAZYVAL(name: Name): ValTreeStart = VAL(name) withFlags Flags.LAZY - // def LAZYVAL(sym: Symbol): ValSymStart = VAL(sym) withFlags Flags.LAZY + def LAZYVAL(name: Name, tp: Type): ValTreeStart = VAL(name, tp) withFlags Flags.LAZY + def LAZYVAL(name: Name): ValTreeStart = VAL(name) withFlags Flags.LAZY + def LAZYVAL(sym: Symbol): ValSymStart = VAL(sym) withFlags Flags.LAZY def AND(guards: Tree*) = if (guards.isEmpty) EmptyTree else guards reduceLeft gen.mkAnd - // def OR(guards: Tree*) = - // if (guards.isEmpty) EmptyTree - // else guards reduceLeft gen.mkOr + def OR(guards: Tree*) = + if (guards.isEmpty) EmptyTree + else guards reduceLeft gen.mkOr def IF(tree: Tree) = new IfStart(tree, EmptyTree) def TRY(tree: Tree) = new TryStart(tree, Nil, EmptyTree) @@ -311,11 +311,11 @@ trait TreeDSL { case List(tree) if flattenUnary => tree case _ => Apply(TupleClass(trees.length).companionModule, trees: _*) } - // def makeTupleType(trees: List[Tree], flattenUnary: Boolean): Tree = trees match { - // case Nil => gen.scalaUnitConstr - // case List(tree) if flattenUnary => tree - // case _ => AppliedTypeTree(REF(TupleClass(trees.length)), trees) - // } + def makeTupleType(trees: List[Tree], flattenUnary: Boolean): Tree = trees match { + case Nil => gen.scalaUnitConstr + case List(tree) if flattenUnary => tree + case _ => AppliedTypeTree(REF(TupleClass(trees.length)), trees) + } /** Implicits - some of these should probably disappear **/ implicit def mkTreeMethods(target: Tree): TreeMethods = new TreeMethods(target) diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index ea7f674809..983f355c58 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -63,71 +63,71 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL { Annotated(New(scalaDot(UncheckedClass.name), ListOfNil), expr) } // if it's a Match, mark the selector unchecked; otherwise nothing. - // def mkUncheckedMatch(tree: Tree) = tree match { - // case Match(selector, cases) => atPos(tree.pos)(Match(mkUnchecked(selector), cases)) - // case _ => tree - // } + def mkUncheckedMatch(tree: Tree) = tree match { + case Match(selector, cases) => atPos(tree.pos)(Match(mkUnchecked(selector), cases)) + case _ => tree + } - // def mkSynthSwitchSelector(expr: Tree): Tree = atPos(expr.pos) { - // // This can't be "Annotated(New(SwitchClass), expr)" because annotations - // // are very picky about things and it crashes the compiler with "unexpected new". - // Annotated(Ident(nme.synthSwitch), expr) - // } + def mkSynthSwitchSelector(expr: Tree): Tree = atPos(expr.pos) { + // This can't be "Annotated(New(SwitchClass), expr)" because annotations + // are very picky about things and it crashes the compiler with "unexpected new". + Annotated(Ident(nme.synthSwitch), expr) + } // TODO: would be so much nicer if we would know during match-translation (i.e., type checking) // whether we should emit missingCase-style apply (and isDefinedAt), instead of transforming trees post-factum - // class MatchMatcher { - // def caseMatch(orig: Tree, selector: Tree, cases: List[CaseDef], wrap: Tree => Tree): Tree = unknownTree(orig) - // def caseVirtualizedMatch(orig: Tree, _match: Tree, targs: List[Tree], scrut: Tree, matcher: Tree): Tree = unknownTree(orig) - // def caseVirtualizedMatchOpt(orig: Tree, prologue: List[Tree], cases: List[Tree], matchEndDef: Tree, wrap: Tree => Tree): Tree = unknownTree(orig) - - // def genVirtualizedMatch(prologue: List[Tree], cases: List[Tree], matchEndDef: Tree): Tree = Block(prologue ++ cases, matchEndDef) - - // def apply(matchExpr: Tree): Tree = matchExpr match { - // // old-style match or virtpatmat switch - // case Match(selector, cases) => // println("simple match: "+ (selector, cases) + "for:\n"+ matchExpr ) - // caseMatch(matchExpr, selector, cases, identity) - // // old-style match or virtpatmat switch - // case Block((vd: ValDef) :: Nil, orig@Match(selector, cases)) => // println("block match: "+ (selector, cases, vd) + "for:\n"+ matchExpr ) - // caseMatch(matchExpr, selector, cases, m => copyBlock(matchExpr, List(vd), m)) - // // virtpatmat - // case Apply(Apply(TypeApply(Select(tgt, nme.runOrElse), targs), List(scrut)), List(matcher)) if !settings.XoldPatmat.value => // println("virt match: "+ (tgt, targs, scrut, matcher) + "for:\n"+ matchExpr ) - // caseVirtualizedMatch(matchExpr, tgt, targs, scrut, matcher) - // // optimized version of virtpatmat - // case Block(stats, matchEndDef) if !settings.XoldPatmat.value && (stats forall treeInfo.hasSynthCaseSymbol) => - // // the assumption is once we encounter a case, the remainder of the block will consist of cases - // // the prologue may be empty, usually it is the valdef that stores the scrut - // val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef]) - // caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, identity) - // // optimized version of virtpatmat - // case Block(outerStats, orig@Block(stats, matchEndDef)) if !settings.XoldPatmat.value && (stats forall treeInfo.hasSynthCaseSymbol) => - // val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef]) - // caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, m => copyBlock(matchExpr, outerStats, m)) - // case other => - // unknownTree(other) - // } - - // def unknownTree(t: Tree): Tree = throw new MatchError(t) - // def copyBlock(orig: Tree, stats: List[Tree], expr: Tree): Block = Block(stats, expr) - - // def dropSyntheticCatchAll(cases: List[CaseDef]): List[CaseDef] = - // if (settings.XoldPatmat.value) cases - // else cases filter { - // case CaseDef(pat, EmptyTree, Throw(Apply(Select(New(exTpt), nme.CONSTRUCTOR), _))) if (treeInfo.isWildcardArg(pat) && (exTpt.tpe.typeSymbol eq MatchErrorClass)) => false - // case CaseDef(pat, guard, body) => true - // } - // } - - // def mkCached(cvar: Symbol, expr: Tree): Tree = { - // val cvarRef = mkUnattributedRef(cvar) - // Block( - // List( - // If(Apply(Select(cvarRef, nme.eq), List(Literal(Constant(null)))), - // Assign(cvarRef, expr), - // EmptyTree)), - // cvarRef - // ) - // } + class MatchMatcher { + def caseMatch(orig: Tree, selector: Tree, cases: List[CaseDef], wrap: Tree => Tree): Tree = unknownTree(orig) + def caseVirtualizedMatch(orig: Tree, _match: Tree, targs: List[Tree], scrut: Tree, matcher: Tree): Tree = unknownTree(orig) + def caseVirtualizedMatchOpt(orig: Tree, prologue: List[Tree], cases: List[Tree], matchEndDef: Tree, wrap: Tree => Tree): Tree = unknownTree(orig) + + def genVirtualizedMatch(prologue: List[Tree], cases: List[Tree], matchEndDef: Tree): Tree = Block(prologue ++ cases, matchEndDef) + + def apply(matchExpr: Tree): Tree = matchExpr match { + // old-style match or virtpatmat switch + case Match(selector, cases) => // println("simple match: "+ (selector, cases) + "for:\n"+ matchExpr ) + caseMatch(matchExpr, selector, cases, identity) + // old-style match or virtpatmat switch + case Block((vd: ValDef) :: Nil, orig@Match(selector, cases)) => // println("block match: "+ (selector, cases, vd) + "for:\n"+ matchExpr ) + caseMatch(matchExpr, selector, cases, m => copyBlock(matchExpr, List(vd), m)) + // virtpatmat + case Apply(Apply(TypeApply(Select(tgt, nme.runOrElse), targs), List(scrut)), List(matcher)) if !settings.XoldPatmat.value => // println("virt match: "+ (tgt, targs, scrut, matcher) + "for:\n"+ matchExpr ) + caseVirtualizedMatch(matchExpr, tgt, targs, scrut, matcher) + // optimized version of virtpatmat + case Block(stats, matchEndDef) if !settings.XoldPatmat.value && (stats forall treeInfo.hasSynthCaseSymbol) => + // the assumption is once we encounter a case, the remainder of the block will consist of cases + // the prologue may be empty, usually it is the valdef that stores the scrut + val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef]) + caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, identity) + // optimized version of virtpatmat + case Block(outerStats, orig@Block(stats, matchEndDef)) if !settings.XoldPatmat.value && (stats forall treeInfo.hasSynthCaseSymbol) => + val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef]) + caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, m => copyBlock(matchExpr, outerStats, m)) + case other => + unknownTree(other) + } + + def unknownTree(t: Tree): Tree = throw new MatchError(t) + def copyBlock(orig: Tree, stats: List[Tree], expr: Tree): Block = Block(stats, expr) + + def dropSyntheticCatchAll(cases: List[CaseDef]): List[CaseDef] = + if (settings.XoldPatmat.value) cases + else cases filter { + case CaseDef(pat, EmptyTree, Throw(Apply(Select(New(exTpt), nme.CONSTRUCTOR), _))) if (treeInfo.isWildcardArg(pat) && (exTpt.tpe.typeSymbol eq MatchErrorClass)) => false + case CaseDef(pat, guard, body) => true + } + } + + def mkCached(cvar: Symbol, expr: Tree): Tree = { + val cvarRef = mkUnattributedRef(cvar) + Block( + List( + If(Apply(Select(cvarRef, nme.eq), List(Literal(Constant(null)))), + Assign(cvarRef, expr), + EmptyTree)), + cvarRef + ) + } // Builds a tree of the form "{ lhs = rhs ; lhs }" def mkAssignAndReturn(lhs: Symbol, rhs: Tree): Tree = { @@ -152,8 +152,8 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL { // def m: T = { if (m$ eq null) m$ = new m$class(...) m$ } // where (...) are eventual outer accessors - // def mkCachedModuleAccessDef(accessor: Symbol, mvar: Symbol) = - // DefDef(accessor, mkCached(mvar, newModule(accessor, mvar.tpe))) + def mkCachedModuleAccessDef(accessor: Symbol, mvar: Symbol) = + DefDef(accessor, mkCached(mvar, newModule(accessor, mvar.tpe))) def mkModuleAccessDef(accessor: Symbol, msym: Symbol) = DefDef(accessor, Select(This(msym.owner), msym)) @@ -165,8 +165,8 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL { } // def m: T; - // def mkModuleAccessDcl(accessor: Symbol) = - // DefDef(accessor setFlag lateDEFERRED, EmptyTree) + def mkModuleAccessDcl(accessor: Symbol) = + DefDef(accessor setFlag lateDEFERRED, EmptyTree) def mkRuntimeCall(meth: Name, args: List[Tree]): Tree = mkRuntimeCall(meth, Nil, args) @@ -223,8 +223,8 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL { if (isRepeatedParam) wildcardStar(arg) else arg /** Make forwarder to method `target`, passing all parameters in `params` */ - // def mkForwarder(target: Tree, vparamss: List[List[Symbol]]) = - // (target /: vparamss)((fn, vparams) => Apply(fn, vparams map paramToArg)) + def mkForwarder(target: Tree, vparamss: List[List[Symbol]]) = + (target /: vparamss)((fn, vparams) => Apply(fn, vparams map paramToArg)) /** Applies a wrapArray call to an array, making it a WrappedArray. * Don't let a reference type parameter be inferred, in case it's a singleton: @@ -264,24 +264,24 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL { else mkCast(tree, pt) - // def mkZeroContravariantAfterTyper(tp: Type): Tree = { - // // contravariant -- for replacing an argument in a method call - // // must use subtyping, as otherwise we miss types like `Any with Int` - // val tree = - // if (NullClass.tpe <:< tp) Literal(Constant(null)) - // else if (UnitClass.tpe <:< tp) Literal(Constant()) - // else if (BooleanClass.tpe <:< tp) Literal(Constant(false)) - // else if (FloatClass.tpe <:< tp) Literal(Constant(0.0f)) - // else if (DoubleClass.tpe <:< tp) Literal(Constant(0.0d)) - // else if (ByteClass.tpe <:< tp) Literal(Constant(0.toByte)) - // else if (ShortClass.tpe <:< tp) Literal(Constant(0.toShort)) - // else if (IntClass.tpe <:< tp) Literal(Constant(0)) - // else if (LongClass.tpe <:< tp) Literal(Constant(0L)) - // else if (CharClass.tpe <:< tp) Literal(Constant(0.toChar)) - // else mkCast(Literal(Constant(null)), tp) - - // tree - // } + def mkZeroContravariantAfterTyper(tp: Type): Tree = { + // contravariant -- for replacing an argument in a method call + // must use subtyping, as otherwise we miss types like `Any with Int` + val tree = + if (NullClass.tpe <:< tp) Literal(Constant(null)) + else if (UnitClass.tpe <:< tp) Literal(Constant()) + else if (BooleanClass.tpe <:< tp) Literal(Constant(false)) + else if (FloatClass.tpe <:< tp) Literal(Constant(0.0f)) + else if (DoubleClass.tpe <:< tp) Literal(Constant(0.0d)) + else if (ByteClass.tpe <:< tp) Literal(Constant(0.toByte)) + else if (ShortClass.tpe <:< tp) Literal(Constant(0.toShort)) + else if (IntClass.tpe <:< tp) Literal(Constant(0)) + else if (LongClass.tpe <:< tp) Literal(Constant(0L)) + else if (CharClass.tpe <:< tp) Literal(Constant(0.toChar)) + else mkCast(Literal(Constant(null)), tp) + + tree + } /** Translate names in Select/Ident nodes to type names. */ diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index 5c1ab29548..97227a5b6e 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -6,7 +6,7 @@ package scala.tools.nsc package ast -// import scala.reflect.internal.HasFlags +import scala.reflect.internal.HasFlags /** This class ... * @@ -39,6 +39,6 @@ abstract class TreeInfo extends scala.reflect.internal.TreeInfo { case _ => super.firstDefinesClassOrObject(trees, name) } - // def isInterface(mods: HasFlags, body: List[Tree]) = - // mods.isTrait && (body forall isInterfaceMember) + def isInterface(mods: HasFlags, body: List[Tree]) = + mods.isTrait && (body forall isInterfaceMember) } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 501127865b..efcde1f74f 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -9,8 +9,7 @@ package scala.tools.nsc package ast.parser -import scala.collection.{ mutable, immutable } -import mutable.{ ListBuffer, StringBuilder } +import scala.collection.mutable.{ListBuffer, StringBuilder} import scala.reflect.internal.{ ModifierFlags => Flags } import scala.reflect.internal.Chars.{ isScalaLetter } import scala.reflect.internal.util.{ SourceFile, OffsetPosition } @@ -168,7 +167,7 @@ self => object symbXMLBuilder extends SymbolicXMLBuilder(this, preserveWS = true) { // DEBUG choices val global: self.global.type = self.global - // def freshName(prefix: String): Name = SourceFileParser.this.freshName(prefix) + def freshName(prefix: String): Name = SourceFileParser.this.freshName(prefix) } def xmlLiteral : Tree = xmlp.xLiteral @@ -464,7 +463,7 @@ self => /* ------------- ERROR HANDLING ------------------------------------------- */ - val assumedClosingParens = mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0) + var assumedClosingParens = scala.collection.mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0) private var inFunReturnType = false @inline private def fromWithinReturnType[T](body: => T): T = { @@ -641,7 +640,7 @@ self => case _ => false } - // def isTypeIntro: Boolean = isTypeIntroToken(in.token) + def isTypeIntro: Boolean = isTypeIntroToken(in.token) def isStatSeqEnd = in.token == RBRACE || in.token == EOF @@ -766,9 +765,9 @@ self => } } - // def checkSize(kind: String, size: Int, max: Int) { - // if (size > max) syntaxError("too many "+kind+", maximum = "+max, false) - // } + def checkSize(kind: String, size: Int, max: Int) { + if (size > max) syntaxError("too many "+kind+", maximum = "+max, false) + } def checkAssoc(offset: Int, op: Name, leftAssoc: Boolean) = if (treeInfo.isLeftAssoc(op) != leftAssoc) @@ -1219,10 +1218,10 @@ self => * EqualsExpr ::= `=' Expr * }}} */ - // def equalsExpr(): Tree = { - // accept(EQUALS) - // expr() - // } + def equalsExpr(): Tree = { + accept(EQUALS) + expr() + } def condExpr(): Tree = { if (in.token == LPAREN) { @@ -1965,7 +1964,7 @@ self => /** Default entry points into some pattern contexts. */ def pattern(): Tree = noSeq.pattern() - // def patterns(): List[Tree] = noSeq.patterns() + def patterns(): List[Tree] = noSeq.patterns() def seqPatterns(): List[Tree] = seqOK.patterns() def xmlSeqPatterns(): List[Tree] = xmlSeqOK.patterns() // Called from xml parser def argumentPatterns(): List[Tree] = inParens { diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index b346ce0a14..1be5fb1782 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -10,8 +10,7 @@ import scala.reflect.internal.util._ import scala.reflect.internal.Chars._ import Tokens._ import scala.annotation.switch -import scala.collection.{ mutable, immutable } -import mutable.{ ListBuffer, ArrayBuffer } +import scala.collection.mutable.{ ListBuffer, ArrayBuffer } import scala.xml.Utility.{ isNameStart } /** See Parsers.scala / ParsersCommon for some explanation of ScannersCommon. @@ -27,7 +26,7 @@ trait ScannersCommon { trait ScannerCommon extends CommonTokenData { // things to fill in, in addition to buf, decodeUni which come from CharArrayReader - // def warning(off: Int, msg: String): Unit + def warning(off: Int, msg: String): Unit def error (off: Int, msg: String): Unit def incompleteInputError(off: Int, msg: String): Unit def deprecationWarning(off: Int, msg: String): Unit @@ -52,7 +51,7 @@ trait Scanners extends ScannersCommon { type Offset = Int /** An undefined offset */ - // val NoOffset: Offset = -1 + val NoOffset: Offset = -1 trait TokenData extends CommonTokenData { @@ -89,7 +88,7 @@ trait Scanners extends ScannersCommon { def isAtEnd = charOffset >= buf.length - // def flush = { charOffset = offset; nextChar(); this } + def flush = { charOffset = offset; nextChar(); this } def resume(lastCode: Int) = { token = lastCode @@ -101,7 +100,7 @@ trait Scanners extends ScannersCommon { /** the last error offset */ - // var errOffset: Offset = NoOffset + var errOffset: Offset = NoOffset /** A character buffer for literals */ @@ -1064,7 +1063,7 @@ trait Scanners extends ScannersCommon { def syntaxError(off: Offset, msg: String) { error(off, msg) token = ERROR - // errOffset = off + errOffset = off } /** generate an error at the current token offset @@ -1077,7 +1076,7 @@ trait Scanners extends ScannersCommon { def incompleteInputError(msg: String) { incompleteInputError(offset, msg) token = EOF - // errOffset = offset + errOffset = offset } override def toString() = token match { @@ -1242,7 +1241,7 @@ trait Scanners extends ScannersCommon { override val decodeUni: Boolean = !settings.nouescape.value // suppress warnings, throw exception on errors - // def warning(off: Offset, msg: String): Unit = () + def warning(off: Offset, msg: String): Unit = () def deprecationWarning(off: Offset, msg: String): Unit = () def error (off: Offset, msg: String): Unit = throw new MalformedInput(off, msg) def incompleteInputError(off: Offset, msg: String): Unit = throw new MalformedInput(off, msg) @@ -1253,7 +1252,7 @@ trait Scanners extends ScannersCommon { class UnitScanner(unit: CompilationUnit, patches: List[BracePatch]) extends SourceFileScanner(unit.source) { def this(unit: CompilationUnit) = this(unit, List()) - // override def warning(off: Offset, msg: String) = unit.warning(unit.position(off), msg) + override def warning(off: Offset, msg: String) = unit.warning(unit.position(off), msg) override def deprecationWarning(off: Offset, msg: String) = unit.deprecationWarning(unit.position(off), msg) override def error (off: Offset, msg: String) = unit.error(unit.position(off), msg) override def incompleteInputError(off: Offset, msg: String) = unit.incompleteInputError(unit.position(off), msg) @@ -1312,7 +1311,7 @@ trait Scanners extends ScannersCommon { } class ParensAnalyzer(unit: CompilationUnit, patches: List[BracePatch]) extends UnitScanner(unit, patches) { - val balance = mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0) + var balance = scala.collection.mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0) init() @@ -1434,17 +1433,17 @@ trait Scanners extends ScannersCommon { else bp :: insertPatch(bps, patch) } - // def leftColumn(offset: Int) = - // if (offset == -1) -1 else column(lineStart(line(offset))) + def leftColumn(offset: Int) = + if (offset == -1) -1 else column(lineStart(line(offset))) - // def rightColumn(offset: Int, default: Int) = - // if (offset == -1) -1 - // else { - // val rlin = line(offset) - // if (lineStart(rlin) == offset) column(offset) - // else if (rlin + 1 < lineStart.length) column(lineStart(rlin + 1)) - // else default - // } + def rightColumn(offset: Int, default: Int) = + if (offset == -1) -1 + else { + val rlin = line(offset) + if (lineStart(rlin) == offset) column(offset) + else if (rlin + 1 < lineStart.length) column(lineStart(rlin + 1)) + else default + } def insertRBrace(): List[BracePatch] = { def insert(bps: List[BracePair]): List[BracePatch] = bps match { @@ -1487,16 +1486,16 @@ trait Scanners extends ScannersCommon { delete(bracePairs) } - // def imbalanceMeasure: Int = { - // def measureList(bps: List[BracePair]): Int = - // (bps map measure).sum - // def measure(bp: BracePair): Int = - // (if (bp.lindent != bp.rindent) 1 else 0) + measureList(bp.nested) - // measureList(bracePairs) - // } + def imbalanceMeasure: Int = { + def measureList(bps: List[BracePair]): Int = + (bps map measure).sum + def measure(bp: BracePair): Int = + (if (bp.lindent != bp.rindent) 1 else 0) + measureList(bp.nested) + measureList(bracePairs) + } - // def improves(patches1: List[BracePatch]): Boolean = - // imbalanceMeasure > new ParensAnalyzer(unit, patches1).imbalanceMeasure + def improves(patches1: List[BracePatch]): Boolean = + imbalanceMeasure > new ParensAnalyzer(unit, patches1).imbalanceMeasure override def error(offset: Int, msg: String) {} } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala b/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala index be8e1bc8b4..c3fd414426 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala @@ -6,14 +6,14 @@ package scala.tools.nsc package ast.parser -// import scala.annotation.switch +import scala.annotation.switch /** Common code between JavaTokens and Tokens. Not as much (and not as concrete) * as one might like because JavaTokens for no clear reason chose new numbers for * identical token sets. */ abstract class Tokens { - // import scala.reflect.internal.Chars._ + import scala.reflect.internal.Chars._ /** special tokens */ final val EMPTY = -3 @@ -32,16 +32,16 @@ abstract class Tokens { def LPAREN: Int def RBRACE: Int - // def isIdentifier(code: Int): Boolean + def isIdentifier(code: Int): Boolean def isLiteral(code: Int): Boolean - // def isKeyword(code: Int): Boolean - // def isSymbol(code: Int): Boolean - - // final def isSpace(at: Char) = at == ' ' || at == '\t' - // final def isNewLine(at: Char) = at == CR || at == LF || at == FF - // final def isBrace(code: Int) = code >= LPAREN && code <= RBRACE - // final def isOpenBrace(code: Int) = isBrace(code) && (code % 2 == 0) - // final def isCloseBrace(code: Int) = isBrace(code) && (code % 2 == 1) + def isKeyword(code: Int): Boolean + def isSymbol(code: Int): Boolean + + final def isSpace(at: Char) = at == ' ' || at == '\t' + final def isNewLine(at: Char) = at == CR || at == LF || at == FF + final def isBrace(code: Int) = code >= LPAREN && code <= RBRACE + final def isOpenBrace(code: Int) = isBrace(code) && (code % 2 == 0) + final def isCloseBrace(code: Int) = isBrace(code) && (code % 2 == 1) } object Tokens extends Tokens { @@ -56,16 +56,16 @@ object Tokens extends Tokens { /** identifiers */ final val IDENTIFIER = 10 final val BACKQUOTED_IDENT = 11 - // def isIdentifier(code: Int) = - // code >= IDENTIFIER && code <= BACKQUOTED_IDENT + def isIdentifier(code: Int) = + code >= IDENTIFIER && code <= BACKQUOTED_IDENT - // @switch def canBeginExpression(code: Int) = code match { - // case IDENTIFIER|BACKQUOTED_IDENT|USCORE => true - // case LBRACE|LPAREN|LBRACKET|COMMENT => true - // case IF|DO|WHILE|FOR|NEW|TRY|THROW => true - // case NULL|THIS|TRUE|FALSE => true - // case code => isLiteral(code) - // } + @switch def canBeginExpression(code: Int) = code match { + case IDENTIFIER|BACKQUOTED_IDENT|USCORE => true + case LBRACE|LPAREN|LBRACKET|COMMENT => true + case IF|DO|WHILE|FOR|NEW|TRY|THROW => true + case NULL|THIS|TRUE|FALSE => true + case code => isLiteral(code) + } /** keywords */ final val IF = 20 @@ -113,16 +113,16 @@ object Tokens extends Tokens { final val MACRO = 62 // not yet used in 2.10 final val THEN = 63 // not yet used in 2.10 - // def isKeyword(code: Int) = - // code >= IF && code <= LAZY + def isKeyword(code: Int) = + code >= IF && code <= LAZY - // @switch def isDefinition(code: Int) = code match { - // case CLASS|TRAIT|OBJECT => true - // case CASECLASS|CASEOBJECT => true - // case DEF|VAL|VAR => true - // case TYPE => true - // case _ => false - // } + @switch def isDefinition(code: Int) = code match { + case CLASS|TRAIT|OBJECT => true + case CASECLASS|CASEOBJECT => true + case DEF|VAL|VAR => true + case TYPE => true + case _ => false + } /** special symbols */ final val COMMA = 70 @@ -141,8 +141,8 @@ object Tokens extends Tokens { final val AT = 83 final val VIEWBOUND = 84 - // def isSymbol(code: Int) = - // code >= COMMA && code <= VIEWBOUND + def isSymbol(code: Int) = + code >= COMMA && code <= VIEWBOUND /** parenthesis */ final val LPAREN = 90 diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 6dc2055121..49b772ed2c 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -26,15 +26,15 @@ abstract class TreeBuilder { def o2p(offset: Int): Position def r2p(start: Int, point: Int, end: Int): Position - // def rootId(name: Name) = gen.rootId(name) + def rootId(name: Name) = gen.rootId(name) def rootScalaDot(name: Name) = gen.rootScalaDot(name) def scalaDot(name: Name) = gen.scalaDot(name) def scalaAnyRefConstr = scalaDot(tpnme.AnyRef) - // def scalaAnyValConstr = scalaDot(tpnme.AnyVal) - // def scalaAnyConstr = scalaDot(tpnme.Any) + def scalaAnyValConstr = scalaDot(tpnme.AnyVal) + def scalaAnyConstr = scalaDot(tpnme.Any) def scalaUnitConstr = scalaDot(tpnme.Unit) def productConstr = scalaDot(tpnme.Product) - // def productConstrN(n: Int) = scalaDot(newTypeName("Product" + n)) + def productConstrN(n: Int) = scalaDot(newTypeName("Product" + n)) def serializableConstr = scalaDot(tpnme.Serializable) def convertToTypeName(t: Tree) = gen.convertToTypeName(t) @@ -446,15 +446,15 @@ abstract class TreeBuilder { /** Create tree for a lifted expression XX-LIFTING */ - // def makeLifted(gs: List[ValFrom], body: Tree): Tree = { - // def combine(gs: List[ValFrom]): ValFrom = (gs: @unchecked) match { - // case g :: Nil => g - // case ValFrom(pos1, pat1, rhs1) :: gs2 => - // val ValFrom(_, pat2, rhs2) = combine(gs2) - // ValFrom(pos1, makeTuple(List(pat1, pat2), false), Apply(Select(rhs1, nme.zip), List(rhs2))) - // } - // makeForYield(List(combine(gs)), body) - // } + def makeLifted(gs: List[ValFrom], body: Tree): Tree = { + def combine(gs: List[ValFrom]): ValFrom = (gs: @unchecked) match { + case g :: Nil => g + case ValFrom(pos1, pat1, rhs1) :: gs2 => + val ValFrom(_, pat2, rhs2) = combine(gs2) + ValFrom(pos1, makeTuple(List(pat1, pat2), false), Apply(Select(rhs1, nme.zip), List(rhs2))) + } + makeForYield(List(combine(gs)), body) + } /** Create tree for a pattern alternative */ def makeAlternative(ts: List[Tree]): Tree = { |