diff options
author | Paul Phillips <paulp@improving.org> | 2012-11-13 00:14:40 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-11-19 11:55:06 -0800 |
commit | d5e3f85946af966111f88af90a666a709df0ba6f (patch) | |
tree | edb2d3cfae76679bc0311f3c22d01779a2f32ef3 /src/compiler/scala/tools/nsc/ast/TreeGen.scala | |
parent | 645c2676dd6699ac24a57dfe750386bbdb827ee8 (diff) | |
download | scala-d5e3f85946af966111f88af90a666a709df0ba6f.tar.gz scala-d5e3f85946af966111f88af90a666a709df0ba6f.tar.bz2 scala-d5e3f85946af966111f88af90a666a709df0ba6f.zip |
Revert "Commenting out unused members."
This reverts commit 951fc3a486.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/TreeGen.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeGen.scala | 170 |
1 files changed, 85 insertions, 85 deletions
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. */ |