blob: 27c1f0a03480a01a4da6c37b4186994e35935eb0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
** **
** $Id$
\* */
package scalac.transformer.matching;
import scalac.Global;
import scalac.ast.*;
import scalac.util.*;
import scalac.symtab.*;
import java.util.*;
public class TestRegTraverser extends Traverser {
boolean result = false;
Set variables = new HashSet();
static Set nilVariables = new HashSet();
public void traverse(Tree tree) {
//System.out.println("traverse:"+tree);
if (!result)
switch (tree) {
case Alternative(_):
result = true;
break;
case Bind(Name n, Tree pat):
if( TreeInfo.isNameOfStarPattern( n ) ) {
result = true;
}
if( TreeInfo.isEmptySequence( pat ) ) {
// annoying special case: b@() [or b@(()|()) after normalization]
//System.err.println("bindin empty "+tree.symbol());
nilVariables.add(tree.symbol());
result = true;
} else {
variables.add(tree.symbol());
}
traverse(pat);
break;
case Ident(_):
Symbol symbol = tree.symbol();
if ((symbol != Global.instance.definitions.PATTERN_WILDCARD) &&
variables.contains(symbol))
result = true;
break;
case CaseDef(Tree pat, _, _):
traverse(pat);
break;
case Sequence( Tree[] trees):
if( trees.length == 0 ) {
result = true;
break;
} else traverse( trees );
//result = true;
break;
// Matthias PatternMatcher cannot handle this case
case Apply( Tree fn, Tree[] trees ):
if( trees.length == 1 )
switch (trees[ 0 ]) {
case Sequence( Tree[] trees2 ):
if( trees2.length == 1 ) {
switch (trees2[ 0 ]) {
case Sequence( Tree[] trees3 ):
result = true;
break;
}
//System.out.println( fn );
//System.out.println( tree.type() );
}
}
if( !result ) super.traverse( tree );
break;
default:
super.traverse( tree );
}
}
public static boolean apply(Tree t) {
TestRegTraverser trt = new TestRegTraverser();
nilVariables.clear();
trt.traverse(t);
//System.out.println("TestRegTraverser says "+t+" -> "+trt.result);
return trt.result;
}
public static Set getNilVariables() {
return nilVariables;
}
}
|