From cb74fc1c8a4919edacf1274aee7c9229d064a35e Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 2 May 2011 03:28:58 +0000 Subject: 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. --- src/compiler/scala/tools/nsc/ast/TreeGen.scala | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/compiler/scala/tools/nsc/ast/TreeGen.scala') 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$ } -- cgit v1.2.3