summaryrefslogtreecommitdiff
path: root/sources/scalac/transformer/matching/Label.java
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-06-19 17:15:34 +0000
committerburaq <buraq@epfl.ch>2003-06-19 17:15:34 +0000
commit88cb90bf6d10e0766c08cfa277e32a52de6f96ab (patch)
tree7ce6cfd1b271387904fdb68b6a9928768ac26403 /sources/scalac/transformer/matching/Label.java
parente7609c9d0e314117ef1c6161827d0982076090e7 (diff)
downloadscala-88cb90bf6d10e0766c08cfa277e32a52de6f96ab.tar.gz
scala-88cb90bf6d10e0766c08cfa277e32a52de6f96ab.tar.bz2
scala-88cb90bf6d10e0766c08cfa277e32a52de6f96ab.zip
automata stuff for pattern matching
Diffstat (limited to 'sources/scalac/transformer/matching/Label.java')
-rw-r--r--sources/scalac/transformer/matching/Label.java120
1 files changed, 120 insertions, 0 deletions
diff --git a/sources/scalac/transformer/matching/Label.java b/sources/scalac/transformer/matching/Label.java
new file mode 100644
index 0000000000..389139da0a
--- /dev/null
+++ b/sources/scalac/transformer/matching/Label.java
@@ -0,0 +1,120 @@
+package scalac.transformer.matching ;
+
+import scalac.ast.Tree ;
+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 ):
+ 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):
+ 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
+
+
+}