summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-06-28 21:52:49 +0000
committerPaul Phillips <paulp@improving.org>2009-06-28 21:52:49 +0000
commit31baa0e552e0df0592ece4c181231887cd8709b5 (patch)
treec757ff647ba84eaab53a3725a9973019f9bed2e1
parente3bb9bfa5cdaa4ef293713a7bebb189f73732e6d (diff)
downloadscala-31baa0e552e0df0592ece4c181231887cd8709b5.tar.gz
scala-31baa0e552e0df0592ece4c181231887cd8709b5.tar.bz2
scala-31baa0e552e0df0592ece4c181231887cd8709b5.zip
More of the DSL.
the various ad hoc helpers into one place. Opportunistically recoding AST generation in spots where it looks like it'll help me flesh out the syntax.
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeDSL.scala31
-rw-r--r--src/compiler/scala/tools/nsc/matching/CodeFactory.scala53
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala53
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternNodes.scala13
-rw-r--r--src/compiler/scala/tools/nsc/matching/TransMatcher.scala7
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala63
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala5
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala3
-rw-r--r--src/compiler/scala/tools/nsc/transform/Mixin.scala37
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala4
10 files changed, 123 insertions, 146 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
index 7e5e133345..5f28b1753f 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
@@ -18,15 +18,25 @@ trait TreeDSL {
import definitions._
object CODE {
- def LIT(x: Any) = Literal(Constant(x))
+ object LIT extends (Any => Literal) {
+ def apply(x: Any) = Literal(Constant(x))
+ def unapply(x: Any) = x match {
+ case Literal(Constant(value)) => Some(value)
+ case _ => None
+ }
+ }
+
def ID(sym: Symbol) = Ident(sym) setType sym.tpe
- def TRUE = LIT(true)
- def FALSE = LIT(false)
- def NULL = LIT(null)
- def UNIT = LIT(())
- def ZERO = LIT(0)
- def WILD = Ident(nme.WILDCARD)
+ val TRUE = LIT(true)
+ val FALSE = LIT(false)
+ val NULL = LIT(null)
+ val UNIT = LIT(())
+ val ZERO = LIT(0)
+
+ def WILD(tpe: Type = null) =
+ if (tpe == null) Ident(nme.WILDCARD)
+ else Ident(nme.WILDCARD) setType tpe
def fn(lhs: Tree, op: Name, args: Tree*) = Apply(Select(lhs, op), args.toList)
def fn(lhs: Tree, op: Symbol, args: Tree*) = Apply(Select(lhs, op), args.toList)
@@ -45,9 +55,7 @@ trait TreeDSL {
else if (other == EmptyTree) target
else gen.mkAnd(target, other)
- def NE_REF(other: Tree) = fn(target, nme.ne, other)
- def EQEQ(other: Tree) = fn(target, nme.EQ, other)
-
+ def ANY_NE (other: Tree) = fn(target, nme.ne, toAnyRef(other))
def ANY_EQ (other: Tree) = fn(target, nme.eq, toAnyRef(other))
def ANY_== (other: Tree) = fn(target, Any_==, other)
def OBJ_!= (other: Tree) = fn(target, Object_ne, other)
@@ -114,7 +122,7 @@ trait TreeDSL {
}
def CASE(pat: Tree): CaseStart = new CaseStart(pat, EmptyTree)
- def DEFAULT: CaseStart = new CaseStart(WILD, EmptyTree)
+ def DEFAULT: CaseStart = new CaseStart(WILD(), EmptyTree)
class NameMethods(target: Name) {
def BIND(body: Tree) = Bind(target, body)
@@ -153,6 +161,7 @@ trait TreeDSL {
def IF(tree: Tree) = new IfStart(tree, EmptyTree)
def TRY(tree: Tree) = new TryStart(tree, Nil, EmptyTree)
def REF(sym: Symbol) = gen.mkAttributedRef(sym)
+ def REF(pre: Type, sym: Symbol) = gen.mkAttributedRef(pre, sym)
def BLOCK(xs: Tree*) = Block(xs.init.toList, xs.last)
def NOT(tree: Tree) = Select(tree, getMember(BooleanClass, nme.UNARY_!))
diff --git a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
index f62c5a0c7a..021adfe3aa 100644
--- a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
+++ b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
@@ -18,66 +18,43 @@ trait CodeFactory extends ast.TreeDSL
import global.{typer => _, _}
import analyzer.Typer
-
import definitions._
- import Code._
import CODE._
- /** Methods to simplify code generation
- */
- object Code {
- // val SOME = definitions.SomeClass
-
- object Const {
- def apply(x: Any) = Literal(Constant(x))
- def unapply(x: Any) = x match {
- case Literal(Constant(value)) => Some(value)
- case _ => None
- }
+ final def typedValDef(x: Symbol, rhs: Tree)(implicit typer: Typer) = {
+ val finalRhs = x.tpe match {
+ case WildcardType =>
+ rhs setType null
+ x setInfo typer.typed(rhs).tpe
+ rhs
+ case _ =>
+ typer.typed(rhs, x.tpe)
}
+ typer typed (VAL(x) === finalRhs)
}
- final def typedValDef(x: Symbol, rhs: Tree)(implicit typer: Typer) = x.tpe match {
- case WildcardType =>
- rhs setType null
- x setInfo typer.typed(rhs).tpe
- typer.typed(ValDef(x, rhs))
- case _ =>
- typer.typed(ValDef(x, typer.typed(rhs, x.tpe)))
- }
-
- final def mkIdent(sym: Symbol) = Ident(sym) setType sym.tpe
- final def mk_(tpe: Type) = Ident(nme.WILDCARD) setType tpe
-
/** for tree of sequence type, returns tree that drops first i elements */
final def seqDrop(sel:Tree, ix: Int)(implicit typer : Typer) =
if (ix == 0) sel else
- typer.typed(Select(fn(sel, nme.drop, Const(ix)), nme.toSeq))
+ typer typed (fn(sel, nme.drop, LIT(ix)) DOT nme.toSeq)
/** for tree of sequence type, returns tree that represents element at index i */
final def seqElement(sel:Tree, ix: Int)(implicit typer : Typer) =
- typer.typed(fn(sel, sel.tpe.member(nme.apply), Const(ix)))
+ typer typed (fn(sel, sel.tpe.member(nme.apply), LIT(ix)))
/** for tree of sequence type, returns boolean tree testing that the sequence has length i */
final def seqHasLength(sel: Tree, ntpe: Type, i: Int)(implicit typer : Typer) =
- typer.typed( Equals(fn(sel, ntpe.member(nme.lengthCompare), Const(i)), Const(0)) ) // defs.Seq_length ?
+ typer typed (fn(sel, ntpe.member(nme.lengthCompare), LIT(i)) ANY_== ZERO) // defs.Seq_length ?
/** for tree of sequence type sel, returns boolean tree testing that length >= i
*/
final def seqLongerThan(sel:Tree, tpe:Type, i:Int)(implicit typer : Typer) = {
- val cmp = fn(sel, tpe.member(nme.lengthCompare), Const(i))
- GTE(typer.typed(cmp), typer.typed(Const(0))) // defs.Seq_length instead of tpe.member?
+ val cmp = fn(sel, tpe.member(nme.lengthCompare), LIT(i))
+ GTE(typer.typed(cmp), typer.typed(ZERO)) // defs.Seq_length instead of tpe.member?
}
- final def Equals (left: Tree, right: Tree): Tree = fn(left, nme.EQ, right)
- final def Eq (left: Tree, right: Tree): Tree = fn(left, nme.eq, right)
final def GTE (left: Tree, right: Tree): Tree = fn(left, nme.GE, right) // >=
-
- final def ThrowMatchError(pos: Position, obj: Tree) = atPos(pos) {
- Throw( New(TypeTree(MatchErrorClass.tpe), List(List(obj))) )
- }
-
- final def NotNull(tree: Tree)(implicit typer : Typer) = typer.typed(fn(tree, nme.ne, NULL))
+ final def ThrowMatchError(pos: Position, obj: Tree) = atPos(pos)(THROW(MatchErrorClass, obj))
final def Get(tree: Tree) = fn(tree, nme.get)
final def squeezedBlock(vds: List[Tree], exp: Tree)(implicit theOwner: Symbol): Tree =
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index b497dcf185..9e18d94d97 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -37,7 +37,6 @@ trait ParallelMatching extends ast.TreeDSL {
import analyzer.Typer;
import symtab.Flags
import Types._
- import Code.Const
import CODE._
/**
@@ -274,8 +273,8 @@ trait ParallelMatching extends ast.TreeDSL {
val varMap: List[(Int, List[Symbol])] =
(for ((x, i) <- pats.zip) yield strip2(x) match {
- case p @ Const(c: Int) => insertTagIndexPair(c, i) ; Some(c, definedVars(x))
- case p @ Const(c: Char) => insertTagIndexPair(c.toInt, i) ; Some(c.toInt, definedVars(x))
+ case p @ LIT(c: Int) => insertTagIndexPair(c, i) ; Some(c, definedVars(x))
+ case p @ LIT(c: Char) => insertTagIndexPair(c.toInt, i) ; Some(c.toInt, definedVars(x))
case p if isDefaultPattern(p) => insertDefault(i, strip1(x)) ; None
}) . flatMap(x => x) . reverse
@@ -297,10 +296,10 @@ trait ParallelMatching extends ast.TreeDSL {
CASE(Literal(tag)) ==> r2.toTree
}
lazy val ndefault = defaultRep.map(_.toTree) getOrElse failTree
- lazy val casesWithDefault = cases ::: List(CASE(mk_(definitions.IntClass.tpe)) ==> ndefault)
+ lazy val casesWithDefault = cases ::: List(CASE(WILD(definitions.IntClass.tpe)) ==> ndefault)
cases match {
- case CaseDef(lit,_,body) :: Nil => If(Equals(scrut.id, lit), body, ndefault)
+ case CaseDef(lit,_,body) :: Nil => IF (scrut.id ANY_== lit) THEN body ELSE ndefault
case _ if scrut.isChar => Match(Select(scrut.id, nme.toInt), casesWithDefault) // chars to ints
case _ => Match(scrut.id, casesWithDefault)
}
@@ -384,7 +383,10 @@ trait ParallelMatching extends ast.TreeDSL {
if (uacall.symbol.tpe.isBoolean) typer.typed(ID(uacall.symbol))
else uacall.symbol IS_DEFINED
- typer.typed( squeezedBlock(List(rep.handleOuter(uacall)), If(cond,squeezedBlock(vdefs,succ),fail)) )
+ typer typed (squeezedBlock(
+ List(rep.handleOuter(uacall)),
+ IF(cond) THEN squeezedBlock(vdefs, succ) ELSE fail
+ ))
}
}
@@ -394,7 +396,7 @@ trait ParallelMatching extends ast.TreeDSL {
val Patterns(scrut, patterns) = pats
final def removeStar(xs: List[Tree]): List[Tree] =
- xs.init ::: makeBind(strip1(xs.last).toList, mk_(scrut.sequenceType)) :: Nil
+ xs.init ::: makeBind(strip1(xs.last).toList, WILD(scrut.sequenceType)) :: Nil
protected def getSubPatterns(len:Int, x:Tree):Option[List[Tree]] = x match {
case av @ ArrayValue(_,xs) if (!isRightIgnoring(av) && xs.length == len) => Some(xs ::: List(EmptyTree))
@@ -451,11 +453,8 @@ trait ParallelMatching extends ast.TreeDSL {
// lengthArg is exact length
protected def getCond(tree:Tree, lengthArg:Int) = seqHasLength(tree.duplicate, pats.head.tpe, lengthArg)
- final def tree(implicit theOwner: Symbol, failTree: Tree) = {
- val (cx,srep,frep) = this.getTransition
- val succ = srep.toTree
- val fail = frep.toTree
- cx(succ)(fail)
+ final def tree(implicit theOwner: Symbol, failTree: Tree) = this.getTransition match {
+ case (cx, succRep, failRep) => cx(succRep.toTree)(failRep.toTree)
}
}
@@ -493,7 +492,7 @@ trait ParallelMatching extends ast.TreeDSL {
/** condition (to be used in IF), success and failure Rep */
final def getTransition(implicit theOwner: Symbol): (Tree, Rep, Symbol, Rep) = {
val vlue = (head.tpe: @unchecked) match {
- case TypeRef(_,_,List(SingleType(pre,sym))) => gen.mkAttributedRef(pre,sym)
+ case TypeRef(_,_,List(SingleType(pre,sym))) => REF(pre, sym)
case TypeRef(_,_,List(PseudoType(o))) => o.duplicate
}
assert(vlue.tpe ne null, "value tpe is null")
@@ -507,16 +506,16 @@ trait ParallelMatching extends ast.TreeDSL {
val nsucc = rep.make(scrut.mkList(rest.temp), nsuccRow)
val nfail = repWithoutHead(pats, rest)
- (typer.typed(Equals(scrut.id, vlue)), nsucc, fLabel, nfail)
+ (typer.typed(scrut.id ANY_== vlue), nsucc, fLabel, nfail)
}
final def tree(implicit theOwner: Symbol, failTree: Tree) = {
val (cond, srep, fLabel, frep) = this.getTransition
- val cond2 = typer.typed( rep.handleOuter(cond) )
- val fail = typer.typed( frep.toTree)
+ val cond2 = typer typed (rep handleOuter cond)
+ val fail = typer typed frep.toTree
fLabel setInfo MethodType(Nil, fail.tpe)
- typer.typed( If(cond2, srep.toTree, LabelDef(fLabel, Nil, fail)) )
+ typer typed { IF (cond2) THEN srep.toTree ELSE LabelDef(fLabel, Nil, fail) }
}
}
@@ -553,7 +552,7 @@ trait ParallelMatching extends ast.TreeDSL {
// which will be flattened down to the values
implicit def mkOpt[T](x: T): Option[T] = Some(x) // limits noise from Some(value)
(spat match {
- case Const(null) if !eqHead(spat.tpe) => (None, None, pass) // special case for constant null
+ case LIT(null) if !eqHead(spat.tpe) => (None, None, pass) // special case for constant null
case _ if pats.isObjectTest(pat) => (EmptyTree, dummy, None) // matching an object
case Typed(p @ Strip2(_: UnApply), _) if xIsaY => (p, dummy, None) // <:< is never <equals>
case q @ Typed(pp, _) if xIsaY => (alts(pp, q), dummy, None) // never =:= for <equals>
@@ -700,7 +699,7 @@ trait ParallelMatching extends ast.TreeDSL {
if (bx >= 0 && !isReachedTwice(bx)) squeezedBlock(vdefs,body)
else blck
- case If(cond, Const(true), Const(false)) =>
+ case If(cond, TRUE, FALSE) =>
super.transform(cond)
case If(cond1, If(cond2, thenp, elsep1), elsep2) if (elsep1 equalsStructure elsep2) =>
super.transform( IF (cond1 AND cond2) THEN thenp ELSE elsep1 )
@@ -837,7 +836,7 @@ trait ParallelMatching extends ast.TreeDSL {
makeBind(vs, npat) setType argtpe
case o @ Apply_Function(fn) => val stpe = applyType(o, fn)
val ttst = mkEqualsRef(List(stpe))
- makeBind(vs, Typed(mk_(ttst), TypeTree(stpe)) setType ttst)
+ makeBind(vs, Typed(WILD(ttst), TypeTree(stpe)) setType ttst)
case Apply_Value(pre, sym) => mkEmptyTreeBind(vs, mkEqualsRef(List(singleType(pre, sym))))
case Apply_CaseClass_NoArgs(tpe) => mkEmptyTreeBind(vs, tpe)
case Apply_CaseClass_WithArgs() => opat
@@ -989,8 +988,8 @@ trait ParallelMatching extends ast.TreeDSL {
final def condition(tpe: Type, scrutTree: Tree)(implicit typer : Typer): Tree = {
assert((tpe ne NoType) && (scrutTree.tpe ne NoType))
- def equalsRef = Equals(gen.mkAttributedRef(tpe.termSymbol), scrutTree)
- def isInst = gen.mkIsInstanceOf(scrutTree, tpe)
+ def equalsRef = REF(tpe.termSymbol) ANY_== scrutTree
+ def isInst = scrutTree IS tpe
tpe match {
case _: SingletonType if !tpe.isInstanceOf[ConstantType] =>
@@ -998,11 +997,11 @@ trait ParallelMatching extends ast.TreeDSL {
else if (tpe.prefix ne NoPrefix) typer.typed(isInst)
else typer.typed(equalsRef)
case ct: ConstantType => ct.value match { // constant
- case v @ Constant(null) if scrutTree.tpe.isAnyRef => Eq(scrutTree, Literal(v))
- case v => Equals(scrutTree, Literal(v))
+ case v @ Constant(null) if scrutTree.tpe.isAnyRef => scrutTree ANY_EQ Literal(v)
+ case v => scrutTree ANY_== Literal(v)
}
- case _ if scrutTree.tpe <:< tpe && tpe.isAnyRef => NotNull(scrutTree)
- case _ => gen.mkIsInstanceOf(scrutTree, tpe)
+ case _ if scrutTree.tpe <:< tpe && tpe.isAnyRef => typer.typed(scrutTree OBJ_!= NULL)
+ case _ => isInst
}
}
@@ -1011,7 +1010,7 @@ trait ParallelMatching extends ast.TreeDSL {
val theRef = handleOuter(tpe2test match {
case TypeRef(NoPrefix, _, _) => abort("assertion failed: NoPrefix")
case TypeRef(ThisType(clazz), _, _) => gen.mkAttributedThis(clazz)
- case TypeRef(prefix, _, _) => gen.mkAttributedRef(prefix.prefix, prefix.termSymbol)
+ case TypeRef(prefix, _, _) => REF(prefix.prefix, prefix.termSymbol)
})
outerAccessor(tpe2test.typeSymbol) match {
diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
index 3b142affbc..befb8b8926 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
@@ -11,13 +11,15 @@ import scala.tools.nsc.util.{Position, NoPosition}
/**
* @author Burak Emir
*/
-trait PatternNodes {
+trait PatternNodes extends ast.TreeDSL
+{
self: transform.ExplicitOuter =>
import global.{ typer => _, _ }
import analyzer.Typer
import symtab.Flags
import Types._
+ import CODE._
case class TypeComparison(x: Type, y: Type) {
def xIsaY = x <:< y
@@ -111,7 +113,7 @@ trait PatternNodes {
if (vs eq Nil) pat else Bind(vs.head, makeBind(vs.tail, pat)) setType pat.tpe
def mkTypedBind(vs: List[Symbol], tpe: Type) =
- makeBind(vs, Typed(mk_(tpe), TypeTree(tpe)) setType tpe)
+ makeBind(vs, Typed(WILD(tpe), TypeTree(tpe)) setType tpe)
def mkEmptyTreeBind(vs: List[Symbol], tpe: Type) =
makeBind(vs, Typed(EmptyTree, TypeTree(tpe)) setType tpe)
@@ -120,7 +122,7 @@ trait PatternNodes {
def normalizedListPattern(pats:List[Tree], tptArg:Type): Tree = pats match {
case Nil => gen.mkNil
- case (sp @ Strip(_, _: Star)) :: xs => makeBind(definedVars(sp), mk_(sp.tpe))
+ case (sp @ Strip(_, _: Star)) :: xs => makeBind(definedVars(sp), WILD(sp.tpe))
case x::xs =>
var resType: Type = null;
val consType: Type = definitions.ConsClass.primaryConstructor.tpe match {
@@ -240,9 +242,8 @@ trait PatternNodes {
* The corresponding list of value definitions.
*/
final def targetParams(implicit typer: Typer): List[ValDef] =
- bindings.toList.map{ case Binding(v, t) => ValDef(v,
- typer.typed{if(t.tpe <:< v.tpe) mkIdent(t)
- else gen.mkAsInstanceOf(mkIdent(t), v.tpe)})}
+ for (Binding(v, t) <- bindings.toList) yield
+ VAL(v) === (typer typed (if (t.tpe <:< v.tpe) ID(t) else (ID(t) AS_ANY v.tpe)))
}
val NoBinding: Bindings = Bindings()
diff --git a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
index 97aa3fbada..7525cedbe3 100644
--- a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
+++ b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
@@ -11,13 +11,14 @@ package scala.tools.nsc.matching
*
* @author Burak Emir
*/
-trait TransMatcher {
+trait TransMatcher extends ast.TreeDSL {
self: transform.ExplicitOuter with PatternNodes with ParallelMatching with CodeFactory =>
import global.{ typer => _, _ }
import analyzer.Typer;
import definitions._
import symtab.Flags
+ import CODE._
var cunit: CompilationUnit = _ // memory leak?
var resultType: Type = _
@@ -68,7 +69,7 @@ trait TransMatcher {
(v, typedValDef(v, ti))
}
)
- (tmps, vds, ThrowMatchError(selector.pos, treeCopy.Apply(app, fn, tmps map mkIdent)))
+ (tmps, vds, ThrowMatchError(selector.pos, treeCopy.Apply(app, fn, tmps map ID)))
}
// sets temporaries, variable declarations, and the fail tree
@@ -78,7 +79,7 @@ trait TransMatcher {
case _ =>
val root: Symbol = newVar(selector.pos, selector.tpe, flags)
val vdef: Tree = typer.typed(ValDef(root, selector))
- val failTree: Tree = ThrowMatchError(selector.pos, mkIdent(root))
+ val failTree: Tree = ThrowMatchError(selector.pos, ID(root))
(List(root), List(vdef), failTree)
}
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index 4313ec5f8e..e05bed9682 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -224,7 +224,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
addStaticMethodToClass("reflMethod$Method", List(ClassClass.tpe), MethodClass.tpe) {
case Pair(reflMethodSym, List(forReceiverSym)) =>
BLOCK(
- IF (REF(reflClassCacheSym) NE_REF REF(forReceiverSym)) THEN BLOCK(
+ IF (REF(reflClassCacheSym) ANY_NE REF(forReceiverSym)) THEN BLOCK(
REF(reflMethodCacheSym) === ((REF(forReceiverSym) DOT getMethodSym)(LIT(method), REF(reflParamsCacheSym))) ,
REF(reflClassCacheSym) === REF(forReceiverSym),
UNIT
@@ -260,29 +260,25 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
val reflPolyCacheSym: Symbol =
addStaticVariableToClass("reflPoly$Cache", MethodCacheClass.tpe, NEW(TypeTree(EmptyMethodCacheClass.tpe)))
- val reflMethodSym: Symbol =
- addStaticMethodToClass("reflMethod$Method", List(ClassClass.tpe), MethodClass.tpe)
- { case Pair(reflMethodSym, List(forReceiverSym)) =>
- val methodSym = reflMethodSym.newVariable(ad.pos, mkTerm("method")) setInfo MethodClass.tpe
-
- BLOCK(
- VAL(methodSym) === ((REF(reflPolyCacheSym) DOT methodCache_find)(REF(forReceiverSym))) ,
- IF (REF(methodSym) OBJ_!= NULL) .
- THEN (Return(REF(methodSym)))
- ELSE {
- def methodSymRHS = ((REF(forReceiverSym) DOT Class_getMethod)(LIT(method), REF(reflParamsCacheSym)))
- def cacheRHS = ((REF(reflPolyCacheSym) DOT methodCache_add)(REF(forReceiverSym), REF(methodSym)))
- BLOCK(
- REF(methodSym) === methodSymRHS,
- REF(reflPolyCacheSym) === cacheRHS,
- Return(REF(methodSym))
- )
- }
- )
- }
-
- reflMethodSym
+ addStaticMethodToClass("reflMethod$Method", List(ClassClass.tpe), MethodClass.tpe)
+ { case Pair(reflMethodSym, List(forReceiverSym)) =>
+ val methodSym = reflMethodSym.newVariable(ad.pos, mkTerm("method")) setInfo MethodClass.tpe
+ BLOCK(
+ VAL(methodSym) === ((REF(reflPolyCacheSym) DOT methodCache_find)(REF(forReceiverSym))) ,
+ IF (REF(methodSym) OBJ_!= NULL) .
+ THEN (Return(REF(methodSym)))
+ ELSE {
+ def methodSymRHS = ((REF(forReceiverSym) DOT Class_getMethod)(LIT(method), REF(reflParamsCacheSym)))
+ def cacheRHS = ((REF(reflPolyCacheSym) DOT methodCache_add)(REF(forReceiverSym), REF(methodSym)))
+ BLOCK(
+ REF(methodSym) === methodSymRHS,
+ REF(reflPolyCacheSym) === cacheRHS,
+ Return(REF(methodSym))
+ )
+ }
+ )
+ }
}
/* ### HANDLING METHODS NORMALLY COMPILED TO OPERATORS ### */
@@ -575,18 +571,14 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
val tpe = theTry.tpe.widen
val tempVar = currentOwner.newValue(theTry.pos, unit.fresh.newName(theTry.pos, "exceptionResult"))
.setInfo(tpe).setFlag(Flags.MUTABLE)
+ def assignBlock(rhs: Tree) = super.transform(BLOCK(Ident(tempVar) === transform(rhs)))
- val newBlock = super.transform(Block(Nil, Assign(Ident(tempVar), transform(block))))
- val newCatches = for (CaseDef(pattern, guard, body) <- catches) yield {
- CaseDef(
- super.transform(pattern),
- super.transform(guard),
- Block(Nil, Assign(Ident(tempVar), super.transform(body)))
- )
- }
- val newTry = Try(newBlock, newCatches, super.transform(finalizer))
- val res = Block(List(ValDef(tempVar, EmptyTree), newTry), Ident(tempVar))
- localTyper.typed(res)
+ val newBlock = assignBlock(block)
+ val newCatches = for (CaseDef(pattern, guard, body) <- catches) yield
+ (CASE(super.transform(pattern)) IF (super.transform(guard))) ==> assignBlock(body)
+ val newTry = Try(newBlock, newCatches, super.transform(finalizer))
+
+ localTyper typed { BLOCK(VAL(tempVar) === EmptyTree, newTry, Ident(tempVar)) }
/* Adds @serializable annotation to anonymous function classes */
case cdef @ ClassDef(mods, name, tparams, impl) =>
@@ -594,8 +586,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
val sym = cdef.symbol
// is this an anonymous function class?
if (sym.isAnonymousFunction && !sym.hasAnnotation(SerializableAttr))
- sym.addAnnotation(
- AnnotationInfo(definitions.SerializableAttr.tpe, List(), List()))
+ sym addAnnotation AnnotationInfo(SerializableAttr.tpe, Nil, Nil)
}
super.transform(tree)
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 8ed3aaef88..ec720e90a8 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -975,9 +975,8 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast.
gen.evalOnce(qual, currentOwner, unit) { q =>
gen.mkOr(
mkIsInstanceOf(q)(targ.tpe),
- atPos(tree.pos) {
- Apply(gen.mkAttributedRef(isArrayMethod), List(q()))
- })
+ atPos(tree.pos) { REF(isArrayMethod) APPLY (q()) }
+ )
}
}
} else tree
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index 1a8c52c118..6720425c79 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -441,7 +441,8 @@ abstract class ExplicitOuter extends InfoTransform
localTyper.typed(Apply(Ident(guardDef.symbol), vs map Ident))
}
- CaseDef(transform(p), gdcall, transform(b))
+
+ (CODE.CASE(transform(p)) IF gdcall) ==> transform(b)
}
def isUncheckedAnnotation(tpe: Type) = tpe hasAnnotation UncheckedClass
diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala
index bcab93b461..040edb9a60 100644
--- a/src/compiler/scala/tools/nsc/transform/Mixin.scala
+++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala
@@ -271,11 +271,10 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
}
if (!member.isSetter)
member.tpe match {
- case MethodType(List(), ConstantType(_)) =>
+ case MethodType(Nil, ConstantType(_)) =>
// member is a constant; only getter is needed
;
- case MethodType(List(), TypeRef(_, tpeSym, _))
- if tpeSym == definitions.UnitClass =>
+ case MethodType(Nil, TypeRef(_, UnitClass, _)) =>
// member is a value of type unit. No field needed
;
case _ =>
@@ -562,22 +561,22 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
assert(!sym.hasFlag(OVERLOADED))
if (sym == NoSymbol) {
sym = clazz.newVariable(clazz.pos, nme.bitmapName(offset / FLAGS_PER_WORD))
- .setInfo(definitions.IntClass.tpe)
+ .setInfo(IntClass.tpe)
.setFlag(PROTECTED)
atPhase(currentRun.typerPhase) {
- sym.addAnnotation(AnnotationInfo(definitions.VolatileAttr.tpe, List(), List()))
+ sym.addAnnotation(AnnotationInfo(VolatileAttr.tpe, List(), List()))
}
clazz.info.decls.enter(sym)
- addDef(clazz.pos, ValDef(sym, Literal(Constant(0))))
+ addDef(clazz.pos, ValDef(sym, ZERO))
}
sym
}
/** Return an (untyped) tree of the form 'Clazz.this.bmp = Clazz.this.bmp | mask'. */
def mkSetFlag(clazz: Symbol, offset: Int): Tree = {
- val bmp = bitmapFor(clazz, offset)
- val mask = LIT(1 << (offset % FLAGS_PER_WORD))
- def x = This(clazz) DOT bmp
+ val bmp = bitmapFor(clazz, offset)
+ val mask = LIT(1 << (offset % FLAGS_PER_WORD))
+ def x = This(clazz) DOT bmp
x === (x INT_| mask)
}
@@ -654,8 +653,8 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
case DefDef(mods, name, tp, vp, tpt, rhs)
if sym.hasFlag(LAZY) && rhs != EmptyTree && !clazz.isImplClass =>
assert(fieldOffset.isDefinedAt(sym))
- val rhs1 = if (sym.tpe.resultType.typeSymbol == definitions.UnitClass)
- mkLazyDef(clazz, List(rhs), Literal(()), fieldOffset(sym))
+ val rhs1 = if (sym.tpe.resultType.typeSymbol == UnitClass)
+ mkLazyDef(clazz, List(rhs), UNIT, fieldOffset(sym))
else {
val Block(stats, res) = rhs
mkLazyDef(clazz, stats, Select(This(clazz), res.symbol), fieldOffset(sym))
@@ -666,8 +665,8 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
if needsInitFlag(sym) && rhs != EmptyTree && !clazz.isImplClass && !clazz.isTrait =>
assert(fieldOffset.isDefinedAt(sym))
- val rhs1 = if (sym.tpe.resultType.typeSymbol == definitions.UnitClass)
- mkCheckedAccessor(clazz, Literal(()), fieldOffset(sym), stat.pos)
+ val rhs1 = if (sym.tpe.resultType.typeSymbol == UnitClass)
+ mkCheckedAccessor(clazz, UNIT, fieldOffset(sym), stat.pos)
else {
mkCheckedAccessor(clazz, rhs, fieldOffset(sym), stat.pos)
}
@@ -793,8 +792,8 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
// if it is a mixed-in lazy value, complete the accessor
if (sym.hasFlag(LAZY) && sym.isGetter) {
val rhs1 =
- if (sym.tpe.resultType.typeSymbol == definitions.UnitClass)
- mkLazyDef(clazz, List(Apply(staticRef(initializer(sym)), List(gen.mkAttributedThis(clazz)))), Literal(()), fieldOffset(sym))
+ if (sym.tpe.resultType.typeSymbol == UnitClass)
+ mkLazyDef(clazz, List(Apply(staticRef(initializer(sym)), List(gen.mkAttributedThis(clazz)))), UNIT, fieldOffset(sym))
else {
val assign = atPos(sym.pos) {
Assign(Select(This(sym.accessed.owner), sym.accessed) /*gen.mkAttributedRef(sym.accessed)*/ ,
@@ -803,8 +802,8 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
mkLazyDef(clazz, List(assign), Select(This(clazz), sym.accessed), fieldOffset(sym))
}
rhs1
- } else if (sym.getter(sym.owner).tpe.resultType.typeSymbol == definitions.UnitClass) {
- Literal(())
+ } else if (sym.getter(sym.owner).tpe.resultType.typeSymbol == UnitClass) {
+ UNIT
} else {
Select(This(clazz), sym.accessed)
}
@@ -819,13 +818,13 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
false
}
}
- if (isOverriddenSetter) Literal(())
+ if (isOverriddenSetter) UNIT
else accessedRef match {
case Literal(_) => accessedRef
case _ =>
val init = Assign(accessedRef, Ident(vparams.head))
if (settings.checkInit.value && needsInitFlag(sym.getter(clazz))) {
- Block(List(init, mkSetFlag(clazz, fieldOffset(sym.getter(clazz)))), Literal(()))
+ Block(List(init, mkSetFlag(clazz, fieldOffset(sym.getter(clazz)))), UNIT)
} else
init
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
index 010171effe..202c9bc7ca 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
@@ -161,8 +161,8 @@ trait SyntheticMethods extends ast.TreeDSL {
def makeTrees(acc: Symbol, cpt: Type): (Tree, Bind) = {
val varName = context.unit.fresh.newName(clazz.pos, acc.name + "$")
val (eqMethod, binding) =
- if (cpt.isVarargs) (nme.sameElements, Star(WILD))
- else (nme.EQ , WILD )
+ if (cpt.isVarargs) (nme.sameElements, Star(WILD()))
+ else (nme.EQ , WILD() )
((varName DOT eqMethod)(Ident(acc)), varName BIND binding)
}