summaryrefslogtreecommitdiff
path: root/sources/scalac/ast/TreeInfo.java
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-07-13 11:42:36 +0000
committerburaq <buraq@epfl.ch>2003-07-13 11:42:36 +0000
commite96d1be7b64a67733cc589f258af1baecaeaf6dd (patch)
treee162b2e1ffbbf29b527eeda461a6e158890e5fbe /sources/scalac/ast/TreeInfo.java
parent1935d7178d9fde62ef32be8f61040eca79810178 (diff)
downloadscala-e96d1be7b64a67733cc589f258af1baecaeaf6dd.tar.gz
scala-e96d1be7b64a67733cc589f258af1baecaeaf6dd.tar.bz2
scala-e96d1be7b64a67733cc589f258af1baecaeaf6dd.zip
isSequenceValued
Diffstat (limited to 'sources/scalac/ast/TreeInfo.java')
-rw-r--r--sources/scalac/ast/TreeInfo.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/sources/scalac/ast/TreeInfo.java b/sources/scalac/ast/TreeInfo.java
index 052b6bd326..337f6c7de2 100644
--- a/sources/scalac/ast/TreeInfo.java
+++ b/sources/scalac/ast/TreeInfo.java
@@ -14,6 +14,8 @@ import scalac.symtab.Type;
import scalac.symtab.Symbol;
import scalac.symtab.Modifiers;
+import java.util.LinkedList;
+
public class TreeInfo {
public static boolean isTerm(Tree tree) {
@@ -157,4 +159,41 @@ public class TreeInfo {
else return Symbol.NONE;
}
}
+
+ /** returns true if the tree is a sequence-valued pattern.
+ * precondition: tree is a pattern.
+ * calls isSequenceValued( Tree, List ) because needs to remember bound
+ * values.
+ */
+ public static boolean isSequenceValued( Tree tree ) {
+ return isSequenceValued( tree, new LinkedList() );
+ }
+
+ /** returns true if the tree is a sequence-valued pattern.
+ * precondition: tree is a pattern
+ */
+ public static boolean isSequenceValued( Tree tree, LinkedList recVars ) {
+ switch( tree ) {
+ case Bind(_, Tree t):
+ recVars.addFirst( tree.symbol() );
+ boolean res = isSequenceValued( t );
+ recVars.removeFirst();
+ return res;
+ case Sequence(_):
+ return true;
+ case Alternative(Tree[] ts):
+ for( int i = 0; i < ts.length; i++ ) {
+ if( isSequenceValued( ts[ i ] ) )
+ return true;
+ }
+ return false;
+ case Apply( _, _ ):
+ case Literal( _ ):
+ return false;
+ case Ident(Name n): // if Ident is a recursive var, then true
+ return recVars.contains( tree.symbol() );
+ default:
+ throw new scalac.ApplicationError("Unexpected pattern "+tree);
+ }
+ }
}