implemented PCLOC annotation.
[IRC.git] / Robust / src / IR / AssignOperation.java
1 package IR;
2
3 public class AssignOperation {
4   public static final int EQ=1;
5   public static final int MULTEQ=2;
6   public static final int DIVEQ=3;
7   public static final int MODEQ=4;
8   public static final int PLUSEQ=5;
9   public static final int MINUSEQ=6;
10   public static final int LSHIFTEQ=7;
11   public static final int RSHIFTEQ=8;
12   public static final int URSHIFTEQ=9;
13   public static final int ANDEQ=10;
14   public static final int XOREQ=11;
15   public static final int OREQ=12;
16   public static final int POSTINC=13;
17   public static final int POSTDEC=14;
18
19   private int operation;
20   public AssignOperation(int op) {
21     this.operation=op;
22   }
23
24   public AssignOperation(String op) {
25     this.operation=parseOp(op);
26   }
27
28   public int getOp() {
29     return operation;
30   }
31
32   public Operation getBaseOp() {
33     switch(operation) {
34     case EQ:
35       return null;
36
37     case MULTEQ:
38       return new Operation(Operation.MULT);
39
40     case DIVEQ:
41       return new Operation(Operation.DIV);
42
43     case MODEQ:
44       return new Operation(Operation.MOD);
45
46     case PLUSEQ:
47       return new Operation(Operation.ADD);
48
49     case MINUSEQ:
50       return new Operation(Operation.SUB);
51
52     case LSHIFTEQ:
53       return new Operation(Operation.LEFTSHIFT);
54
55     case RSHIFTEQ:
56       return new Operation(Operation.RIGHTSHIFT);
57
58     case URSHIFTEQ:
59       return new Operation(Operation.URIGHTSHIFT);
60
61     case ANDEQ:
62       return new Operation(Operation.BIT_AND);
63
64     case XOREQ:
65       return new Operation(Operation.BIT_XOR);
66
67     case OREQ:
68       return new Operation(Operation.BIT_OR);
69
70     case POSTINC:
71       return new Operation(Operation.POSTINC);
72
73     case POSTDEC:
74       return new Operation(Operation.POSTDEC);
75     }
76     throw new Error();
77   }
78
79   public static int parseOp(String st) {
80     if (st.equals("eq"))
81       return EQ;
82     else if (st.equals("multeq"))
83       return MULTEQ;
84     else if (st.equals("diveq"))
85       return DIVEQ;
86     else if (st.equals("modeq"))
87       return MODEQ;
88     else if (st.equals("pluseq"))
89       return PLUSEQ;
90     else if (st.equals("minuseq"))
91       return MINUSEQ;
92     else if (st.equals("lshifteq"))
93       return LSHIFTEQ;
94     else if (st.equals("urshifteq"))
95       return URSHIFTEQ;
96     else if (st.equals("rshifteq"))
97       return RSHIFTEQ;
98     else if (st.equals("andeq"))
99       return ANDEQ;
100     else if (st.equals("xoreq"))
101       return XOREQ;
102     else if (st.equals("oreq"))
103       return OREQ;
104     else if (st.equals("postinc"))
105       return POSTINC;
106     else if (st.equals("postdec"))
107       return POSTDEC;
108     else throw new Error();
109   }
110
111   public String toString() {
112     if (operation==EQ)
113       return "=";
114     else if (operation==MULTEQ)
115       return "*=";
116     else if (operation==DIVEQ)
117       return "/=";
118     else if (operation==MODEQ)
119       return "%=";
120     else if (operation==PLUSEQ)
121       return "+=";
122     else if (operation==MINUSEQ)
123       return "-=";
124     else if (operation==LSHIFTEQ)
125       return "<=";
126     else if (operation==RSHIFTEQ)
127       return ">=";
128     else if (operation==RSHIFTEQ)
129       return ">>=";
130     else if (operation==ANDEQ)
131       return "&=";
132     else if (operation==XOREQ)
133       return "^=";
134     else if (operation==OREQ)
135       return "|=";
136     else if (operation==POSTINC)
137       return "postinc";
138     else if (operation==POSTDEC)
139       return "postdec";
140     else if ( operation==URSHIFTEQ)
141       return ">>>=";
142     else 
143       throw new Error();    
144   }
145
146
147 }