Added support to printout data structure update nodes (bindings/updates)
[repair.git] / Repair / RepairCompiler / MCC / IR / ImageSetExpr.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class ImageSetExpr extends SetExpr {
6     static final public boolean INVERSE=true;
7     VarDescriptor vd;
8     RelationDescriptor rd;
9     boolean inverse;
10
11     public ImageSetExpr(VarDescriptor vd, RelationDescriptor rd) {
12         this.vd = vd;
13         this.rd = rd;
14         this.inverse = false;
15     }
16
17     public Set freeVars() {
18         HashSet hs=new HashSet();
19         hs.add(vd);
20         return hs;
21     }
22
23     public String name() {
24         String name=vd.toString()+".";
25         if (inverse)
26             name+="~";
27         name+=rd.toString();
28         return name;
29     }
30
31     public ImageSetExpr(boolean inverse, VarDescriptor vd, RelationDescriptor rd) {
32         this.vd = vd;
33         this.rd = rd;
34         this.inverse = inverse;
35     }
36
37     public boolean equals(Map remap, Expr e) {
38         if (e==null||!(e instanceof ImageSetExpr))
39             return false;
40         ImageSetExpr ise=(ImageSetExpr)e;
41         if (ise.inverse!=inverse)
42             return false;
43         if (ise.rd!=rd)
44             return false;
45         VarDescriptor nvde=vd;
46         if (remap.containsKey(nvde))
47             nvde=(VarDescriptor)remap.get(nvde);
48         if (nvde!=ise.vd)
49             return false;
50         return true;
51     }
52
53     public boolean inverted() {
54         return inverse;
55     }
56
57     public VarDescriptor getVar() {
58         return vd;
59     }
60
61     public RelationDescriptor getRelation() {
62         return rd;
63     }
64
65     public Descriptor getDescriptor() {
66         return rd;
67     }
68
69     public boolean usesDescriptor(Descriptor d) {
70         return (d==rd)||(d==vd);
71     }
72
73     public Set getInversedRelations() {
74         HashSet set = new HashSet();
75         if (inverse) {
76             set.add(rd);
77         }
78         return set;
79     }
80
81     public Set getRequiredDescriptors() {
82         HashSet v = new HashSet();
83         v.add(rd);
84         return v;
85     }
86
87     public void generate(CodeWriter writer, VarDescriptor dest) {
88         throw new IRException("not supported");
89     }
90
91     public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
92         String hash = inverse ? "_hashinv->contains(" : "_hash->contains(" ;
93         writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
94     }    
95
96     public void generate_size(CodeWriter writer, VarDescriptor dest) {
97         assert dest != null;
98         assert vd != null;
99         assert rd != null;
100         String hash = inverse ? "_hashinv->count(" : "_hash->count(" ;
101         writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
102     }
103
104     public void prettyPrint(PrettyPrinter pp) {
105         pp.output(vd.toString());
106         pp.output(".");
107         if (inverse) {
108             pp.output("~");
109         }
110         pp.output(rd.toString());
111     }
112
113     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
114         throw new IRException("not supported");
115     }
116
117 }