summaryrefslogtreecommitdiff
path: root/sources/scalac/ast
diff options
context:
space:
mode:
authormihaylov <mihaylov@epfl.ch>2004-11-23 14:46:23 +0000
committermihaylov <mihaylov@epfl.ch>2004-11-23 14:46:23 +0000
commite35884ed02bc991d958509a1fa83823161e02f68 (patch)
tree8d9b7edb93ab415f94d07dc189106b9a8c581406 /sources/scalac/ast
parenta21098b9cb410f0e645ecf0b7c5df4808dabc377 (diff)
downloadscala-e35884ed02bc991d958509a1fa83823161e02f68.tar.gz
scala-e35884ed02bc991d958509a1fa83823161e02f68.tar.bz2
scala-e35884ed02bc991d958509a1fa83823161e02f68.zip
- Added mkTagMethod that generates tree for Sca...
- Added mkTagMethod that generates tree for ScalaObject.$tag - Added a flag to mkUnitFunction and mkFunction whether to generate the $tag method
Diffstat (limited to 'sources/scalac/ast')
-rw-r--r--sources/scalac/ast/TreeGen.java26
1 files changed, 21 insertions, 5 deletions
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java
index e077413b3b..1594be86ad 100644
--- a/sources/scalac/ast/TreeGen.java
+++ b/sources/scalac/ast/TreeGen.java
@@ -1186,8 +1186,11 @@ public class TreeGen implements Kinds, Modifiers, TypeTags {
/** Build the expansion of (() => expr)
*/
- public Tree mkUnitFunction(Tree expr, Type type, Symbol owner) {
- return mkFunction(expr.pos, Tree.ValDef_EMPTY_ARRAY, expr, type, owner);
+ public Tree mkUnitFunction(Tree expr, Type type, Symbol owner,
+ boolean tagMethod)
+ {
+ return mkFunction
+ (expr.pos, Tree.ValDef_EMPTY_ARRAY, expr, type, owner, tagMethod);
}
/** Build the expansion of ((vparams_1, ..., vparams_n) => body)
@@ -1206,7 +1209,8 @@ public class TreeGen implements Kinds, Modifiers, TypeTags {
* symbols in `body' from `owner' to the apply method.
*/
public Tree mkFunction(int pos, ValDef[] vparams, Tree body, Type restype,
- Symbol owner) {
+ Symbol owner, boolean tagMethod)
+ {
int n = vparams.length;
Symbol[] params = new Symbol[n];
Type[] argtypes = new Type[n];
@@ -1218,7 +1222,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags {
definitions.ANYREF_TYPE(),
definitions.FUNCTION_TYPE(argtypes, restype) };
Name name = Names.ANON_CLASS_NAME.toTypeName();
- Symbol clazz = owner.newAnonymousClass(pos, name);
+ ClassSymbol clazz = owner.newAnonymousClass(pos, name);
clazz.setInfo(Type.compoundType(parentTypes, new Scope(), clazz));
clazz.allConstructors().setInfo(
Type.MethodType(Symbol.EMPTY_ARRAY, clazz.typeConstructor()));
@@ -1231,12 +1235,24 @@ public class TreeGen implements Kinds, Modifiers, TypeTags {
params[i].setOwner(applyMeth);
}
changeOwner(body, owner, applyMeth);
- Tree[] memberTrees = { DefDef(applyMeth, body) };
+ Tree[] memberTrees = new Tree[tagMethod ? 2 : 1];
+ memberTrees[0] = DefDef(applyMeth, body);
+ if (tagMethod)
+ memberTrees[1] = mkTagMethod(clazz);
Tree classDef = ClassDef(clazz, memberTrees);
Tree alloc = New(mkApply__(mkPrimaryConstructorLocalRef(pos, clazz)));
return mkBlock(classDef, Typed(alloc, parentTypes[1])); // !!! Typed
}
+ public Tree mkTagMethod(ClassSymbol clazz) {
+ int flags =
+ clazz.isSubClass(definitions.SCALAOBJECT_CLASS) ? OVERRIDE : 0;
+ Symbol tagSym = clazz.newMethod(clazz.pos, flags, Names.tag)
+ .setInfo(Type.MethodType(Symbol.EMPTY_ARRAY, definitions.int_TYPE()));
+ clazz.info().members().enter(tagSym);
+ int tagValue = clazz.isCaseClass() ? clazz.tag() : 0;
+ return DefDef(tagSym, mkIntLit(clazz.pos, tagValue));
+ }
public Tree mkPartialFunction(int pos, Tree applyVisitor, Tree isDefinedAtVisitor,
Type pattype, Type restype, Symbol owner) {