Adding changes to cvs...
[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 String name() {
18         String name=vd.toString()+".";
19         if (inverse)
20             name+="~";
21         name+=rd.toString();
22         return name;
23     }
24
25     public ImageSetExpr(boolean inverse, VarDescriptor vd, RelationDescriptor rd) {
26         this.vd = vd;
27         this.rd = rd;
28         this.inverse = inverse;
29     }
30
31     public boolean equals(Map remap, Expr e) {
32         if (e==null||!(e instanceof ImageSetExpr))
33             return false;
34         ImageSetExpr ise=(ImageSetExpr)e;
35         if (ise.inverse!=inverse)
36             return false;
37         if (ise.rd!=rd)
38             return false;
39         VarDescriptor nvde=vd;
40         if (remap.containsKey(nvde))
41             nvde=(VarDescriptor)remap.get(nvde);
42         if (nvde!=ise.vd)
43             return false;
44         return true;
45     }
46
47     public boolean inverted() {
48         return inverse;
49     }
50
51     public VarDescriptor getVar() {
52         return vd;
53     }
54
55     public RelationDescriptor getRelation() {
56         return rd;
57     }
58
59     public Descriptor getDescriptor() {
60         return rd;
61     }
62
63     public boolean usesDescriptor(Descriptor d) {
64         return (d==rd)||(d==vd);
65     }
66
67     public Set getInversedRelations() {
68         HashSet set = new HashSet();
69         if (inverse) {
70             set.add(rd);
71         }
72         return set;
73     }
74
75     public Set getRequiredDescriptors() {
76         HashSet v = new HashSet();
77         v.add(rd);
78         return v;
79     }
80
81     public void generate(CodeWriter writer, VarDescriptor dest) {
82         throw new IRException("not supported");
83     }
84
85     public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
86         String hash = inverse ? "_hashinv->contains(" : "_hash->contains(" ;
87         writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
88     }    
89
90     public void generate_size(CodeWriter writer, VarDescriptor dest) {
91         assert dest != null;
92         assert vd != null;
93         assert rd != null;
94         String hash = inverse ? "_hashinv->count(" : "_hash->count(" ;
95         writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
96     }
97
98     public void prettyPrint(PrettyPrinter pp) {
99         pp.output(vd.toString());
100         pp.output(".");
101         if (inverse) {
102             pp.output("~");
103         }
104         pp.output(rd.toString());
105     }
106
107     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
108         throw new IRException("not supported");
109     }
110
111 }