summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2010-12-02 06:36:00 +0000
committerMartin Odersky <odersky@gmail.com>2010-12-02 06:36:00 +0000
commit7e94841fb7daf0942286bf035785686fc9a91361 (patch)
treee649dfd56f38a7de5ef9ed6760813e4af1487868 /src
parentd7de71e9d31dae56b5afc62e3777fa03112ee1e1 (diff)
downloadscala-7e94841fb7daf0942286bf035785686fc9a91361.tar.gz
scala-7e94841fb7daf0942286bf035785686fc9a91361.tar.bz2
scala-7e94841fb7daf0942286bf035785686fc9a91361.zip
Reverted delayed init because of two failing tests
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala92
1 files changed, 5 insertions, 87 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index 091e10c170..e8874f281e 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -1,4 +1,4 @@
-/* NSC -- new Scala compiler
+g/* NSC -- new Scala compiler
* Copyright 2005-2010 LAMP/EPFL
* @author
*/
@@ -155,8 +155,7 @@ abstract class Constructors extends Transform with ast.TreeDSL {
// The list of statements that go into constructor after superclass constructor call
val constrStatBuf = new ListBuffer[Tree]
- // The list of statements that go into constructor before and including the
- // superclass constructor call
+ // The list of statements that go into constructor before superclass constructor call
val constrPrefixBuf = new ListBuffer[Tree]
// The early initialized field definitions of the class (these are the class members)
@@ -164,14 +163,14 @@ abstract class Constructors extends Transform with ast.TreeDSL {
// generate code to copy pre-initialized fields
for (stat <- constrBody.stats) {
- constrPrefixBuf += stat
+ constrStatBuf += stat
stat match {
case ValDef(mods, name, _, _) if (mods hasFlag PRESUPER) =>
// stat is the constructor-local definition of the field value
val fields = presupers filter (
vdef => nme.localToGetter(vdef.name) == name)
assert(fields.length == 1)
- constrPrefixBuf += mkAssign(fields.head.symbol, Ident(stat.symbol))
+ constrStatBuf += mkAssign(fields.head.symbol, Ident(stat.symbol))
case _ =>
}
}
@@ -405,87 +404,12 @@ abstract class Constructors extends Transform with ast.TreeDSL {
} else stats0
}
- def isInitDef(stat: Tree) = stat match {
- case dd: DefDef => dd.symbol == delayedInitMethod
- case _ => false
- }
-
- def delayedInitClosure(stats: List[Tree]) =
- localTyper.typed {
- atPos(impl.pos) {
- val closureClass = clazz.newClass(impl.pos, nme.delayedInitArg.toTypeName)
- .setFlag(SYNTHETIC | FINAL)
- val closureParents = List(AbstractFunctionClass(0).tpe, ScalaObjectClass.tpe)
- closureClass.setInfo(new ClassInfoType(closureParents, new Scope, closureClass))
-
- val outerField = clazz.newValue(impl.pos, nme.OUTER)
- .setFlag(PRIVATE | LOCAL)
- .setInfo(clazz.tpe)
-
- val applyMethod = closureClass.newMethod(impl.pos, nme.apply)
- .setFlag(FINAL)
- .setInfo(MethodType(List(), ObjectClass.tpe))
-
- closureClass.info.decls enter outerField
- closureClass.info.decls enter applyMethod
-
- val outerFieldDef = ValDef(outerField)
-
- val changeOwner = new ChangeOwnerTraverser(impl.symbol, applyMethod)
- val constrStatTransformer = new Transformer {
- override def transform(tree: Tree): Tree = tree match {
- case This(`clazz`) =>
- localTyper.typed {
- atPos(tree.pos) {
- Select(This(closureClass), outerField)
- }
- }
- case _ =>
- changeOwner traverse tree
- tree
- }
- }
-
- def applyMethodStats = constrStatTransformer.transformTrees(stats)
-
- val applyMethodDef = DefDef(
- sym = applyMethod,
- vparamss = List(List()),
- rhs = Block(applyMethodStats, gen.mkAttributedRef(BoxedUnit_UNIT)))
-
- util.trace("delayedInit: ") { ClassDef(
- sym = closureClass,
- constrMods = Modifiers(0),
- vparamss = List(List(outerFieldDef)),
- argss = List(List()),
- body = List(outerFieldDef, applyMethodDef),
- superPos = impl.pos)
- }}
- }
-
- def delayedInitCall(closure: Tree) =
- localTyper.typed {
- atPos(impl.pos) {
- Apply(
- Select(This(clazz), delayedInitMethod),
- List(New(TypeTree(closure.symbol.tpe), List(List(This(clazz))))))
- }
- }
-
- val needsDelayedInit =
- false && (clazz isSubClass DelayedInitClass) && !(defBuf exists isInitDef) && constrStatBuf.nonEmpty
-
- var constrStats = constrStatBuf.toList
- if (needsDelayedInit) {
- constrStats = List(delayedInitCall(delayedInitClosure(constrStats)))
- }
-
// Assemble final constructor
defBuf += treeCopy.DefDef(
constr, constr.mods, constr.name, constr.tparams, constr.vparamss, constr.tpt,
treeCopy.Block(
constrBody,
- paramInits ::: constrPrefixBuf.toList ::: guardSpecializedInitializer(constrStats),
+ paramInits ::: constrPrefixBuf.toList ::: guardSpecializedInitializer(constrStatBuf.toList),
constrBody.expr));
// Followed by any auxiliary constructors
@@ -500,12 +424,6 @@ abstract class Constructors extends Transform with ast.TreeDSL {
defBuf.toList filter (stat => mustbeKept(stat.symbol)))
} // transformClassTemplate
- def hasDelayedInit(clazz: Symbol) = false &&
- (clazz isSubClass DelayedInitClass) &&
- (clazz.info.decls lookup nme.delayedInit) == NoSymbol
-
- def delayedInitCall(stats: List[Tree]): Tree = null
-
override def transform(tree: Tree): Tree =
tree match {
case ClassDef(mods, name, tparams, impl) if !tree.symbol.isInterface =>