Still adding code to construct termination graph, abstract repair actions, concrete...
[repair.git] / Repair / RepairCompiler / MCC / IR / Updates.java
1 package MCC.IR;
2
3 class Updates {
4     static public final int EXPR=0;
5     static public final int POSITION=1;
6     static public final int ABSTRACT=2;
7     int type=-1;
8     int rightposition;
9     Expr rightexpr;
10     Expr leftexpr;
11     Opcode opcode;
12     boolean negate;
13
14     public Updates(Expr lexpr, Expr rexpr, Opcode op) {
15         leftexpr=lexpr;
16         type=Updates.EXPR;
17         opcode=Opcode.EQ;
18         /* Get rid of everything but NE */
19         if (op==Opcode.GT) {
20             rightexpr=new OpExpr(Opcode.ADD,rexpr,new IntegerLiteralExpr(1));
21         } else if (op==Opcode.GE) {
22             rightexpr=rexpr;
23         } else if (op==Opcode.LT) {
24             rightexpr=new OpExpr(Opcode.SUB,rexpr,new IntegerLiteralExpr(1));
25         } else if (op==Opcode.LE) {
26             rightexpr=rexpr;
27         } else if (op==Opcode.EQ) {
28             rightexpr=rexpr;
29         } else if (op==Opcode.NE) {
30             opcode=Opcode.NE;
31         }
32     }
33
34     boolean isGlobal() {
35         if (leftexpr instanceof VarExpr)
36             return true;
37         else return false;
38     }
39
40     Descriptor getDescriptor() {
41         if (isGlobal()) {
42             return ((VarExpr)leftexpr).getVar();
43         } else if (isField()) {
44             return ((DotExpr)leftexpr).getField();
45         } else throw New Error("Unrecognized Update");
46     }
47
48     boolean isField() {
49         if (leftexpr instanceof DotExpr) {
50             assert ((DotExpr)leftexpr).getIndex()==null;
51             return true;
52         } else
53             return false;
54     }
55     
56     
57     Opcode getOpcode() {
58         return opcode;
59     }
60
61     public Updates(Expr lexpr, Expr rexpr) {
62         leftexpr=lexpr;
63         rightexpr=rexpr;
64         type=Updates.EXPR;
65         opcode=Opcode.EQ;
66     }
67
68     public Updates(Expr lexpr, int rpos) {
69         leftexpr=lexpr;
70         rightposition=rpos;
71         type=Updates.POSITION;
72         opcode=null;
73     }
74     public Updates(Expr lexpr,boolean negates) {
75         leftexpr=lexpr;
76         type=Updates.ABSTRACT;
77         negate=negates;
78         opcode=null;
79     }
80
81     public int getType() {
82         return type;
83     }
84     public Expr getLeftExpr() {
85         return leftexpr;
86     }
87     public int getRightPos() {
88         assert type==Updates.POSITION;
89         return rightposition;
90     }
91     public Expr getRightExpr() {
92         assert type==Updates.EXPR;
93         return rightexpr;
94     }
95 }