From 4827da4894dbdc3b9c26c4a4d28897f2ba20f24b Mon Sep 17 00:00:00 2001 From: mihaylov Date: Thu, 26 Jun 2003 09:37:05 +0000 Subject: - moved the initialization of the class-paramet... - moved the initialization of the class-parameter fields before the call to the super constructor (fixes bug No 17) - changed the initialization of the ValDef fields to refer to their fully qualified name (Select), rather than just the identifier (Ident) --- sources/scalac/transformer/AddConstructors.java | 59 ++++++++++++++----------- 1 file changed, 34 insertions(+), 25 deletions(-) (limited to 'sources/scalac/transformer/AddConstructors.java') diff --git a/sources/scalac/transformer/AddConstructors.java b/sources/scalac/transformer/AddConstructors.java index cba2303715..6adcfd2018 100644 --- a/sources/scalac/transformer/AddConstructors.java +++ b/sources/scalac/transformer/AddConstructors.java @@ -118,6 +118,7 @@ public class AddConstructors extends Transformer { paramSyms[i] = vparams[0][i].symbol(); ArrayList constrBody = new ArrayList(); + ArrayList constrBody2 = new ArrayList(); ArrayList classBody = new ArrayList(); Symbol constrSym = getConstructor(treeSym.constructor(), paramSyms, treeSym); @@ -129,6 +130,35 @@ public class AddConstructors extends Transformer { Debug.show(constrSym.owner()) + "\n\texpected: " + Debug.show(treeSym); + // for every ValDef move the initialization code into the constructor + for (int i = 0; i < body.length; i++) { + Tree t = body[i]; + if (t.definesSymbol()) { + Symbol sym = t.symbol(); + switch (t) { + case ValDef(_, _, _, Tree rhs): + if (rhs != Tree.Empty) { + Tree lhs = + gen.Select(gen.This(t.pos, treeSym), sym); + Tree assign = + gen.Assign(t.pos, lhs, transform(rhs)); + t = gen.ValDef(sym, Tree.Empty); + if (rhs.hasSymbol() && rhs.symbol().isParameter()) { + constrBody.add(assign); + } else { + constrBody2.add(assign); + } + } + break; + } + classBody.add(transform(t)); + classScope.enterOrOverload(sym); + } else { + // move class-level expressions into the constructor + constrBody2.add(transform(body[i])); + } + } + // inline the call to the super constructor Type superType = treeSym.parents()[0]; if ( !forINT || !superType.symbol().isJava()) { @@ -141,7 +171,8 @@ public class AddConstructors extends Transformer { constrBody.add(gen.Apply(superConstr, transform(args))); break; default: - new scalac.ast.printer.TextTreePrinter().print(baseClasses[0]).println().end(); + new scalac.ast.printer.TextTreePrinter(). + print(baseClasses[0]).println().end(); assert false; } } @@ -170,30 +201,8 @@ public class AddConstructors extends Transformer { } } - // for every ValDef move the initialization code into the constructor - for (int i = 0; i < body.length; i++) { - Tree t = body[i]; - if (t.definesSymbol()) { - Symbol sym = t.symbol(); - switch (t) { - case ValDef(_, _, _, Tree rhs): - if (rhs != Tree.Empty) { - // !!!FIXME: revert to this.whatever when the bug is fixed - //Tree ident = gen.Select(gen.This(t.pos, treeSym), sym); - Tree ident = gen.Ident(sym); - - constrBody.add - (gen.Assign(t.pos, ident, transform(rhs))); - t = gen.ValDef(sym, Tree.Empty); - } - break; - } - classBody.add(transform(t)); - classScope.enterOrOverload(sym); - } else - // move every class-level expression into the constructor - constrBody.add(transform(t)); - } + // add valdefs and class-level expression to the constructorr body + constrBody.addAll(constrBody2); // add result expression consistent with the // result type of the constructor -- cgit v1.2.3