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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
package scalac.transformer.matching ;
import scalac.ast.Tree ;
import scalac.ast.TreeInfo ;
import scalac.symtab.Type ;
import Tree.Literal ;
/** this class represents the label that a transition in an automaton may carry.
* these get translated to specific (boolean) tests
*/
public class Label {
public case DefaultLabel;
public case SimpleLabel( Literal lit );
public case TreeLabel( Tree pat ); // Apply, Sequence
public case TypeLabel( Type tpe ); // Apply, Sequence
public case Pair( Integer state, Label lab );
//public case RLabel( Object rstate, Label lab, Symbol vars[] );
public int hashCode() {
switch( this ) {
case DefaultLabel:
return 0;
case SimpleLabel( Literal lit ):
return lit.value.hashCode();
case TreeLabel( Tree pat ):
switch( pat ) {
case Apply( _, Tree[] args ):
return TreeInfo.methSymbol( pat ).hashCode() + args.hashCode(); // incorrect?
}
return pat.hashCode();
case TypeLabel( Type type ):
return type.hashCode();
default:
return super.hashCode();
}
}
public boolean equals( Object o ) {
if( !(o instanceof Label ))
return false;
Label oL = (Label) o;
//System.out.print(this + " equals " + oL);
switch( this ) {
case DefaultLabel:
switch( oL ) {
case DefaultLabel:
return true;
} //
break;
case SimpleLabel( Literal lit ):
switch( oL ) {
case SimpleLabel( Literal lit2 ):
return /*(lit.kind == lit2.kind)
&& */lit.value.equals( lit2.value );
}
break;
case TreeLabel( Tree pat ):
switch( oL ) {
case TreeLabel( Tree pat2 ):
switch( pat ) {
case Apply( _, _ ):
switch( pat2 ) {
case Apply( _, _ ):
return TreeInfo.methSymbol( pat ) == TreeInfo.methSymbol( pat2 );
}
}
return pat == pat2;
}
break ;
case TypeLabel( Type tpe ):
switch( oL ) {
case TypeLabel( Type tpe2):
return tpe.equals( tpe2 );
}
break ;
case Pair( Integer state, Label lab ):
switch( oL ) {
case Pair( Integer state2, Label lab2 ):
return state.equals( state2 )
&& lab.equals( lab2 ) ;
}
break;
}
return false;
}
public String toString2() {
String ext = System.getProperty("extendedMatching");
if(( ext != null )
&& ext.equals( "true" )) {
switch( this ) {
case DefaultLabel:
return "<>:p"+p;
case SimpleLabel( Literal lit ):
return lit.toString()+":p"+p;
case TreeLabel( Tree pat ):
return pat.type()+":p"+p;
}
}
throw new scalac.ApplicationError
("this never happens");
}
public String toString() {
switch( this ) {
case DefaultLabel:
return "<>";
case SimpleLabel( Literal lit):
return lit.toString();
case TreeLabel( Tree pat):
return pat.toString();
case TypeLabel( Type tpe ):
return tpe.toString();
case Pair( Integer state, Label lab ):
return "("+state.toString()+","+lab.toString()+")";
}
throw new scalac.ApplicationError("this never happens");
}
int p = -1; // tree state - only needed for extended matching
}
|