bug fixes
[IRC.git] / Robust / src / IR / Operation.java
1 package IR;
2
3 public class Operation {
4     public static final int LOGIC_OR=1;
5     public static final int LOGIC_AND=2;
6     public static final int BIT_OR=3;
7     public static final int BIT_XOR=4;
8     public static final int BIT_AND=5;
9     public static final int EQUAL=6;
10     public static final int NOTEQUAL=7;
11     public static final int LT=8;
12     public static final int GT=9;
13     public static final int LTE=10;
14     public static final int GTE=11;
15     public static final int LEFTSHIFT=12;
16     public static final int RIGHTSHIFT=13;
17     public static final int SUB=14;
18     public static final int ADD=15;
19     public static final int MULT=16;
20     public static final int DIV=17;
21     public static final int MOD=18;
22     public static final int UNARYPLUS=19;
23     public static final int UNARYMINUS=20;
24     public static final int POSTINC=21;
25     public static final int POSTDEC=22;
26     public static final int PREINC=23;
27     public static final int PREDEC=24;
28     public static final int LOGIC_NOT=25;
29     public static final int ISAVAILABLE=26;
30     public static final int URIGHTSHIFT=27;
31     public static final int COMP=28;
32     /* Flat Operations */
33     public static final int ASSIGN=100;
34
35     private int operation;
36     public Operation(int op) {
37         this.operation=op;
38     }
39
40     public Operation(String op) {
41         this.operation=parseOp(op);
42     }
43
44     public int getOp() {
45         return operation;
46     }
47     
48     public static int parseOp(String st) {
49         if (st.equals("logical_or"))
50             return LOGIC_OR;
51         else if (st.equals("logical_and"))
52             return LOGIC_AND;
53         else if (st.equals("bitwise_or"))
54             return BIT_OR;
55         else if (st.equals("bitwise_xor"))
56             return BIT_XOR;
57         else if (st.equals("bitwise_and"))
58             return BIT_AND;
59         else if (st.equals("equal"))
60             return EQUAL;
61         else if (st.equals("not_equal"))
62             return NOTEQUAL;
63         else if (st.equals("comp_lt"))
64             return LT;
65         else if (st.equals("comp_gt"))
66             return GT;
67         else if (st.equals("comp_lte"))
68             return LTE;
69         else if (st.equals("comp_gte"))
70             return GTE;
71         else if (st.equals("leftshift"))
72             return LEFTSHIFT;
73         else if (st.equals("rightshift"))
74             return RIGHTSHIFT;
75         else if (st.equals("urightshift"))
76             return URIGHTSHIFT;
77         else if (st.equals("sub"))
78             return SUB;
79         else if (st.equals("add"))
80             return ADD;
81         else if (st.equals("mult"))
82             return MULT;
83         else if (st.equals("div"))
84             return DIV;
85         else if (st.equals("mod"))
86             return MOD;
87         else if (st.equals("unaryplus"))
88             return UNARYPLUS;
89         else if (st.equals("unaryminus"))
90             return UNARYMINUS;
91         else if (st.equals("postinc"))
92             return POSTINC;
93         else if (st.equals("postdec"))
94             return POSTDEC;
95         else if (st.equals("preinc"))
96             return PREINC;
97         else if (st.equals("predec"))
98             return PREDEC;
99         else if (st.equals("not"))
100             return LOGIC_NOT;
101         else if (st.equals("comp"))
102             return COMP;
103         else
104             throw new Error();
105     }
106
107     public String toString() {
108         if (operation==LOGIC_OR)
109             return "||";
110         else if (operation==LOGIC_AND)
111             return "&&";
112         else if (operation==LOGIC_NOT)
113             return "not";
114         else if (operation==COMP)
115             return "~";
116         else if (operation==BIT_OR)
117             return "|";
118         else if (operation==BIT_XOR)
119             return "^";
120         else if (operation==BIT_AND)
121             return "&";
122         else if (operation==EQUAL)
123             return "==";
124         else if (operation==NOTEQUAL)
125             return "!=";
126         else if (operation==LT)
127             return "<";
128         else if (operation==GT)
129             return ">";
130         else if (operation==LTE)
131             return "<=";
132         else if (operation==GTE)
133             return ">=";
134         else if (operation==LEFTSHIFT)
135             return "<<";
136         else if (operation==RIGHTSHIFT)
137             return ">>";
138         else if (operation==RIGHTSHIFT)
139             return ">>>";
140         else if (operation==SUB)
141             return "-";
142         else if (operation==ADD)
143             return "+";
144         else if (operation==MULT)
145             return "*";
146         else if (operation==DIV)
147             return "/";
148         else if (operation==MOD)
149             return "%";
150         else if (operation==UNARYPLUS)
151             return "unaryplus";
152         else if (operation==UNARYMINUS)
153             return "unaryminus";
154         else if (operation==POSTINC)
155             return "postinc";
156         else if (operation==POSTDEC)
157             return "postdec";
158         else if (operation==PREINC)
159             return "preinc";
160         else if (operation==PREDEC)
161             return "predec";
162         else if (operation==ASSIGN)
163             return "assign";
164         else throw new Error();
165     }
166
167
168 }