Checking in updates
[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=21;
27     public static final int PREDEC=22;
28
29     private int operation;
30     public Operation(int op) {
31         this.operation=op;
32     }
33
34     public Operation(String op) {
35         this.operation=parseOp(op);
36     }
37
38     public static int parseOp(String st) {
39         if (st.equals("logical_or"))
40             return LOGIC_OR;
41         else if (st.equals("logical_and"))
42             return LOGIC_AND;
43         else if (st.equals("bitwise_or"))
44             return BIT_OR;
45         else if (st.equals("bitwise_xor"))
46             return BIT_XOR;
47         else if (st.equals("bitwise_and"))
48             return BIT_AND;
49         else if (st.equals("equal"))
50             return EQUAL;
51         else if (st.equals("not_equal"))
52             return NOTEQUAL;
53         else if (st.equals("comp_lt"))
54             return LT;
55         else if (st.equals("comp_gt"))
56             return GT;
57         else if (st.equals("comp_lte"))
58             return LTE;
59         else if (st.equals("comp_gte"))
60             return GTE;
61         else if (st.equals("leftshift"))
62             return LEFTSHIFT;
63         else if (st.equals("rightshift"))
64             return RIGHTSHIFT;
65         else if (st.equals("sub"))
66             return SUB;
67         else if (st.equals("add"))
68             return ADD;
69         else if (st.equals("mult"))
70             return MULT;
71         else if (st.equals("div"))
72             return DIV;
73         else if (st.equals("mod"))
74             return MOD;
75         else if (st.equals("unaryplus"))
76             return UNARYPLUS;
77         else if (st.equals("unaryminus"))
78             return UNARYMINUS;
79         else if (st.equals("postinc"))
80             return POSTINC;
81         else if (st.equals("postdec"))
82             return POSTDEC;
83         else if (st.equals("preinc"))
84             return PREINC;
85         else if (st.equals("predec"))
86             return PREDEC;
87         else
88             throw new Error();
89     }
90
91     public String toString() {
92         if (operation==LOGIC_OR)
93             return "||";
94         else if (operation==LOGIC_AND)
95             return "&&";
96         else if (operation==BIT_OR)
97             return "|";
98         else if (operation==BIT_XOR)
99             return "^";
100         else if (operation==BIT_AND)
101             return "&";
102         else if (operation==EQUAL)
103             return "==";
104         else if (operation==NOTEQUAL)
105             return "!=";
106         else if (operation==LT)
107             return "<";
108         else if (operation==GT)
109             return ">";
110         else if (operation==LTE)
111             return "<=";
112         else if (operation==GTE)
113             return ">=";
114         else if (operation==LEFTSHIFT)
115             return "<<";
116         else if (operation==RIGHTSHIFT)
117             return ">>";
118         else if (operation==SUB)
119             return "-";
120         else if (operation==ADD)
121             return "+";
122         else if (operation==MULT)
123             return "*";
124         else if (operation==DIV)
125             return "/";
126         else if (operation==MOD)
127             return "%";
128         else if (operation==UNARYPLUS)
129             return "unaryplus";
130         else if (operation==UNARYMINUS)
131             return "unaryminus";
132         else if (operation==POSTINC)
133             return "postinc";
134         else if (operation==POSTDEC)
135             return "postdec";
136         else if (operation==PREINC)
137             return "preinc";
138         else if (operation==PREDEC)
139             return "predec";
140         else throw new Error();
141     }
142
143
144 }