diff options
author | schinz <schinz@epfl.ch> | 2003-08-27 14:59:51 +0000 |
---|---|---|
committer | schinz <schinz@epfl.ch> | 2003-08-27 14:59:51 +0000 |
commit | bbbecb8a613f7302541ba303ee248ef7dac089d1 (patch) | |
tree | 2d0112ad2b00b7df222309d2979c5a7d3b1411ff /sources/scalac | |
parent | a2bc132e04a9590519ce0fc22b9cf4c39db4d255 (diff) | |
download | scala-bbbecb8a613f7302541ba303ee248ef7dac089d1.tar.gz scala-bbbecb8a613f7302541ba303ee248ef7dac089d1.tar.bz2 scala-bbbecb8a613f7302541ba303ee248ef7dac089d1.zip |
- don't use accessors for constructor arguments...
- don't use accessors for constructor arguments when they are used
during class construction (this both makes the program faster, and
avoids unnecessary accessors in some interesting cases)
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/transformer/AddAccessors.java | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/sources/scalac/transformer/AddAccessors.java b/sources/scalac/transformer/AddAccessors.java index aaed700b89..e2dc69b7f1 100644 --- a/sources/scalac/transformer/AddAccessors.java +++ b/sources/scalac/transformer/AddAccessors.java @@ -36,7 +36,7 @@ public class AddAccessors extends Transformer { } protected final HashMap/*<Symbol,Symbol>*/ accessorMap = new HashMap(); - protected boolean inClassContext = true; + protected boolean inClassContext; protected Symbol accessor(Symbol sym) { Symbol accessor = (Symbol)accessorMap.get(sym); @@ -62,14 +62,22 @@ public class AddAccessors extends Transformer { Tree tpe, Tree.Template impl): { Symbol clsSym = tree.symbol(); + assert vparams.length == 1; + Tree.ValDef[] params = vparams[0]; - LinkedList/*<Tree>*/ newBody = - new LinkedList(Arrays.asList(transform(impl.body))); + // Recursively transform body + Tree[] body = impl.body; + LinkedList/*<Tree>*/ newBody = new LinkedList(); + for (int i = 0; i < body.length; ++i) { + Tree mem = body[i]; + Symbol sym = mem.symbol(); + inClassContext = + mem.definesSymbol() && (sym.isClass() || sym.isMethod()); + newBody.add(transform(mem)); + } // Add value definitions and accessors for all constructor // arguments which were found in the body of the class. - assert vparams.length == 1; - Tree.ValDef[] params = vparams[0]; Scope newMembers = new Scope(clsSym.members()); for (int i = 0; i < params.length; ++i) { Symbol paramSym = params[i].symbol(); @@ -95,10 +103,8 @@ public class AddAccessors extends Transformer { newMembers, clsSym)); - assert inClassContext; inClassContext = false; Tree[] newParents = transform(impl.parents); - inClassContext = true; Tree[] newBodyA = (Tree[])newBody.toArray(new Tree[newBody.size()]); @@ -110,16 +116,6 @@ public class AddAccessors extends Transformer { copy.Template(impl, newParents, newBodyA)); } - case ValDef(_, _, _, _): { - // Do not go into RHS of value definitions which reference - // case class constructor arguments, to avoid creating - // another accessor. - if (Modifiers.Helper.isCaseAccessor(tree.symbol().flags)) { - return tree; - } else - return super.transform(tree); - } - case Select(Tree qualifier, _): { Symbol sym = tree.symbol(); assert sym.kind != Kinds.NONE : tree; |