diff options
Diffstat (limited to 'sources/scalac/ast/TreeGen.java')
-rw-r--r-- | sources/scalac/ast/TreeGen.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index e3c2315005..751e78044d 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -21,7 +21,7 @@ import Tree.*; * @author Martin Odersky, Christine Roeckl * @version 1.0 */ -public class TreeGen implements Kinds, Modifiers { +public class TreeGen implements Kinds, Modifiers, TypeTags { /********************************************************************************/ /********************************************************************************/ @@ -185,6 +185,34 @@ public class TreeGen implements Kinds, Modifiers { return make.Literal(pos, new Integer(value)).setType(definitions.INT_TYPE); } + /** Build a default zero value according to type + */ + public Tree mkDefaultValue(int pos, Type tp) { + if (tp.isSubType(definitions.ANYREF_TYPE)) { + return Ident(pos, definitions.NULL); + } else { + switch (tp.unbox()) { + case UnboxedType(BOOLEAN): + return mkBooleanLit(pos, false); + case UnboxedType(BYTE): + case UnboxedType(SHORT): + case UnboxedType(CHAR): + case UnboxedType(INT): + return mkIntLit(pos, 0); + case UnboxedType(LONG): + return make.Literal(pos, new Long(0)).setType(definitions.LONG_TYPE); + case UnboxedType(FLOAT): + return make.Literal(pos, new Float(0)).setType(definitions.FLOAT_TYPE); + case UnboxedType(DOUBLE): + return make.Literal(pos, new Double(0)).setType(definitions.DOUBLE_TYPE); + case UnboxedType(UNIT): + return Block(pos, Tree.EMPTY_ARRAY); + default: + return Ident(pos, definitions.ZERO); + } + } + } + /** Build a tree to be used as a base class constructor for a template. */ public Tree mkParentConstr(int pos, Type parentType, Tree[] parentArgs) { |