summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/TreeGen.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-05-02 03:28:58 +0000
committerPaul Phillips <paulp@improving.org>2011-05-02 03:28:58 +0000
commitcb74fc1c8a4919edacf1274aee7c9229d064a35e (patch)
tree16ea39660f83ae0978fe8adf09e390319ed4729d /src/compiler/scala/tools/nsc/ast/TreeGen.scala
parent70f18a67e5cc55e534a504b71ee26a93488b40f8 (diff)
downloadscala-cb74fc1c8a4919edacf1274aee7c9229d064a35e.tar.gz
scala-cb74fc1c8a4919edacf1274aee7c9229d064a35e.tar.bz2
scala-cb74fc1c8a4919edacf1274aee7c9229d064a35e.zip
Figuring it couldn't hurt if more people had a ...
Figuring it couldn't hurt if more people had a command of some of our binary compatibility impacting code, I went over the ModuleDef elimination with my clarify stick and made the machinery more transparent, to me anyway. Review by plocinic.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/TreeGen.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
index d232bee46d..b655507658 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -111,6 +111,11 @@ abstract class TreeGen {
if (sym.owner.isClass) mkAttributedRef(sym.owner.thisType, sym)
else mkAttributedIdent(sym)
+ /** Builds an untyped reference to given symbol. */
+ def mkUnattributedRef(sym: Symbol): Tree =
+ if (sym.owner.isClass) Select(This(sym.owner), sym)
+ else Ident(sym)
+
/** Replaces tree type with a stable type if possible */
def stabilize(tree: Tree): Tree = {
for(tp <- stableTypeFor(tree)) tree.tpe = tp
@@ -255,7 +260,7 @@ abstract class TreeGen {
def mkSoftRef(expr: Tree): Tree = New(TypeTree(SoftReferenceClass.tpe), List(List(expr)))
def mkCached(cvar: Symbol, expr: Tree): Tree = {
- val cvarRef = if (cvar.owner.isClass) Select(This(cvar.owner), cvar) else Ident(cvar)
+ val cvarRef = mkUnattributedRef(cvar)
Block(
List(
If(Apply(Select(cvarRef, nme.eq), List(Literal(Constant(null)))),
@@ -265,17 +270,24 @@ abstract class TreeGen {
)
}
+ // Builds a tree of the form "{ lhs = rhs ; lhs }"
+ def mkAssignAndReturn(lhs: Symbol, rhs: Tree): Tree = {
+ val lhsRef = mkAttributedRef(lhs)
+ Block(Assign(lhsRef, rhs) :: Nil, lhsRef)
+ }
+
def mkModuleVarDef(accessor: Symbol) = {
- val mval = accessor.owner.newVariable(accessor.pos.focus, nme.moduleVarName(accessor.name))
- .setInfo(accessor.tpe.finalResultType)
- .setFlag(LAZY)
- .setFlag(MODULEVAR)
- mval.setLazyAccessor(accessor)
+ val mval = (
+ accessor.owner.newVariable(accessor.pos.focus, nme.moduleVarName(accessor.name))
+ setInfo accessor.tpe.finalResultType
+ setFlag (LAZY | MODULEVAR)
+ setLazyAccessor accessor
+ )
if (mval.owner.isClass) {
mval setFlag (PRIVATE | LOCAL | SYNTHETIC)
mval.owner.info.decls.enter(mval)
}
- ValDef(mval, EmptyTree)
+ ValDef(mval)
}
// def m: T = { if (m$ eq null) m$ = new m$class(...) m$ }