summaryrefslogtreecommitdiff
path: root/sources/scalac/transformer/AddConstructors.java
diff options
context:
space:
mode:
authormihaylov <mihaylov@epfl.ch>2003-06-26 09:37:05 +0000
committermihaylov <mihaylov@epfl.ch>2003-06-26 09:37:05 +0000
commit4827da4894dbdc3b9c26c4a4d28897f2ba20f24b (patch)
tree4ccf676693b117932e1d3d0c6aa8032462b246eb /sources/scalac/transformer/AddConstructors.java
parent1066a7cf015f6eb3d930b06c5fe6b43d51235f18 (diff)
downloadscala-4827da4894dbdc3b9c26c4a4d28897f2ba20f24b.tar.gz
scala-4827da4894dbdc3b9c26c4a4d28897f2ba20f24b.tar.bz2
scala-4827da4894dbdc3b9c26c4a4d28897f2ba20f24b.zip
- 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)
Diffstat (limited to 'sources/scalac/transformer/AddConstructors.java')
-rw-r--r--sources/scalac/transformer/AddConstructors.java59
1 files changed, 34 insertions, 25 deletions
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