c7f507965e822624f2a97430e90ce28c3d10b787
[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     
7     public static final boolean INVERSE = true;
8
9     VarDescriptor vd;
10     RelationDescriptor rd;
11     boolean inverse;
12
13     public ImageSetExpr(VarDescriptor vd, RelationDescriptor rd) {
14         this.vd = vd;
15         this.rd = rd;
16         this.inverse = false;
17     }
18
19     public ImageSetExpr(boolean inverse, VarDescriptor vd, RelationDescriptor rd) {
20         this.vd = vd;
21         this.rd = rd;
22         this.inverse = inverse;
23     }
24
25     public VarDescriptor getVar() {
26         return vd;
27     }
28
29     public RelationDescriptor getRelation() {
30         return rd;
31     }
32
33     public Set getInversedRelations() {
34         HashSet set = new HashSet();
35         if (inverse) {
36             set.add(rd);
37         }
38         return set;
39     }
40
41     public Set getRequiredDescriptors() {
42         HashSet v = new HashSet();
43         v.add(rd);
44         return v;
45     }
46
47     public void generate(CodeWriter writer, VarDescriptor dest) {
48         throw new IRException("not supported");
49     }
50
51     public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
52         String hash = inverse ? "_hashinv->contains(" : "_hash->contains(" ;
53         writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
54     }    
55
56     public void generate_size(CodeWriter writer, VarDescriptor dest) {
57         assert dest != null;
58         assert vd != null;
59         assert rd != null;
60         String hash = inverse ? "_hashinv->count(" : "_hash->count(" ;
61         writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
62     }
63
64     public void prettyPrint(PrettyPrinter pp) {
65         pp.output(vd.toString());
66         pp.output(".");
67         if (inverse) {
68             pp.output("~");
69         }
70         pp.output(rd.toString());
71     }
72
73     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
74         throw new IRException("not supported");
75     }
76
77 }