summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-10-10 09:28:57 +0000
committerpaltherr <paltherr@epfl.ch>2003-10-10 09:28:57 +0000
commitda160bfd73256ca2a0a82752f82f17824a93fde0 (patch)
tree4e84f064d2814c5883ec671a5ba70516bfd15d0e /sources
parentcbf2cf2dca9022ce7967215d2aff6596d24ba603 (diff)
downloadscala-da160bfd73256ca2a0a82752f82f17824a93fde0.tar.gz
scala-da160bfd73256ca2a0a82752f82f17824a93fde0.tar.bz2
scala-da160bfd73256ca2a0a82752f82f17824a93fde0.zip
- Added methods Switch
- Added method assertTreeSubTypeOf
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/ast/TreeGen.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java
index fae66b5102..0b3a747004 100644
--- a/sources/scalac/ast/TreeGen.java
+++ b/sources/scalac/ast/TreeGen.java
@@ -590,6 +590,23 @@ public class TreeGen implements Kinds, Modifiers, TypeTags {
return If(cond.pos, cond, thenpart, elsepart);
}
+ /** Builds a Switch node with given components and type. */
+ public Switch Switch(int pos, Tree test, int[] tags, Tree[] bodies,
+ Tree defavlt, Type type)
+ {
+ for (int i = 0; i < bodies.length; i++)
+ assert assertTreeSubTypeOf(bodies[i], type);
+ assert assertTreeSubTypeOf(defavlt, type);
+ Switch tree = make.Switch(pos, test, tags, bodies, defavlt);
+ tree.setType(type);
+ return tree;
+ }
+ public Switch Switch(Tree test, int[] tags, Tree[] bodies, Tree defavlt,
+ Type type)
+ {
+ return Switch(test.pos, test, tags, bodies, defavlt, type);
+ }
+
/** Builds a New node corresponding to "new <constr>". */
public Tree New(int pos, Tree constr) {
Tree[] constrs = { constr };
@@ -743,6 +760,20 @@ public class TreeGen implements Kinds, Modifiers, TypeTags {
}
//########################################################################
+ // Private Methods
+
+ /** Asserts type of given tree is a subtype of given type. */
+ private boolean assertTreeSubTypeOf(Tree tree, Type expected) {
+ global.nextPhase();
+ assert tree.type().isSubType(expected):
+ "\ntree : " + tree +
+ "\ntype : " + tree.type() +
+ "\nexpected: " + expected;
+ global.prevPhase();
+ return true;
+ }
+
+ //########################################################################
//########################################################################
//########################################################################