From 938d635c43dd677f37a0d2cbd86f2e4c04f24187 Mon Sep 17 00:00:00 2001 From: paltherr Date: Sun, 4 Apr 2004 15:11:35 +0000 Subject: - Changed Tree.New(Template) to Tree.New(Tree) --- sources/scalac/ast/Transformer.java.tmpl | 5 +-- sources/scalac/ast/TreeGen.java | 63 ++++++++++++++++---------------- 2 files changed, 33 insertions(+), 35 deletions(-) (limited to 'sources/scalac/ast') diff --git a/sources/scalac/ast/Transformer.java.tmpl b/sources/scalac/ast/Transformer.java.tmpl index 1af073fc86..2c8d355587 100644 --- a/sources/scalac/ast/Transformer.java.tmpl +++ b/sources/scalac/ast/Transformer.java.tmpl @@ -236,9 +236,8 @@ public class GenTransformer { // case Throw(Tree expr): - case New(Template(Tree[] base, Tree[] body)): - assert base.length == 1 && body.length == 0: tree; - return gen.New(tree.pos, transform(base[0])); + case New(Tree init): + return gen.New(tree.pos, transform(init)); case Typed(Tree expr, Tree tpe): return gen.Typed(tree.pos, transform(expr), transform(tpe)); diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 20b3cab3c4..6cf6c6cb23 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -457,6 +457,33 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { return Apply(fn.pos, fn); } + //######################################################################## + // Public Methods - Building new instances + + /** Builds a New node corresponding to "new ". */ + public New New(int pos, Tree init) { + New tree = make.New(pos, init); + tree.setType(init.type); + // after AddConstructor use type of symbol + switch (init) { + case Apply(TypeApply(Tree fun, Tree[] targs), _): + Symbol sym = fun.symbol(); + if (sym == null || sym.isConstructor()) break; + Type[] args = Tree.typeOf(targs); + tree.setType(Type.appliedType(sym.owner().nextType(), args)); + break; + case Apply(Tree fun, _): + Symbol sym = fun.symbol(); + if (sym == null || sym.isConstructor()) break; + tree.setType(sym.owner().nextType()); + break; + } + return tree; + } + public New New(Tree init) { + return New(init.pos, init); + } + //######################################################################## // Public Methods - Building expressions - Simple nodes @@ -690,32 +717,6 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { return Return(value.pos, method, value); } - /** Builds a New node corresponding to "new ". */ - public Tree New(int pos, Tree constr) { - Tree[] constrs = { constr }; - Template templ = Template(pos, Symbol.NONE, constrs, Tree.EMPTY_ARRAY); - New tree = make.New(pos, templ); - tree.setType(constr.type); - // after AddConstructor use type of symbol - switch (constr) { - case Apply(TypeApply(Tree fun, Tree[] targs), _): - Symbol sym = fun.symbol(); - if (sym == null || sym.isConstructor()) break; - Type[] args = Tree.typeOf(targs); - tree.setType(Type.appliedType(sym.owner().nextType(), args)); - break; - case Apply(Tree fun, _): - Symbol sym = fun.symbol(); - if (sym == null || sym.isConstructor()) break; - tree.setType(sym.owner().nextType()); - break; - } - return tree; - } - public Tree New(Tree constr) { - return New(constr.pos, constr); - } - /** Builds a Typed nodes with given value and type. */ public Typed Typed(int pos, Tree value, Tree type) { Typed tree = make.Typed(pos, value, type); @@ -1130,9 +1131,8 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { changeOwner(body, owner, applyMeth); Tree[] memberTrees = { DefDef(applyMeth, body) }; Tree classDef = ClassDef(clazz, memberTrees); - Tree alloc = New(mkApply__(mkPrimaryConstructorLocalRef(pos, clazz))) - .setType(parentTypes[1]); // !!! - return mkBlock(classDef, alloc); + Tree alloc = New(mkApply__(mkPrimaryConstructorLocalRef(pos, clazz))); + return mkBlock(classDef, Typed(alloc, parentTypes[1])); // !!! Typed } @@ -1151,9 +1151,8 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { makeVisitorMethod(pos, Names.isDefinedAt, isDefinedAtVisitor, pattype, definitions.BOOLEAN_TYPE(), clazz, owner)}; Tree classDef = ClassDef(clazz, memberTrees); - Tree alloc = New(mkApply__(mkPrimaryConstructorLocalRef(pos, clazz))) - .setType(parentTypes[1]); // !!! - return mkBlock(classDef, alloc); + Tree alloc = New(mkApply__(mkPrimaryConstructorLocalRef(pos, clazz))); + return mkBlock(classDef, Typed(alloc, parentTypes[1])); // !!! Typed } //where private Tree makeVisitorMethod(int pos, Name name, Tree visitor, -- cgit v1.2.3