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     
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 boolean inverted() {
26         return inverse;
27     }
28
29     public VarDescriptor getVar() {
30         return vd;
31     }
32
33     public RelationDescriptor getRelation() {
34         return rd;
35     }
36
37     public Descriptor getDescriptor() {
38         return rd;
39     }
40
41     public boolean usesDescriptor(RelationDescriptor rd) {
42         return (rd==this.rd);
43     }
44
45     public Set getInversedRelations() {
46         HashSet set = new HashSet();
47         if (inverse) {
48             set.add(rd);
49         }
50         return set;
51     }
52
53     public Set getRequiredDescriptors() {
54         HashSet v = new HashSet();
55         v.add(rd);
56         return v;
57     }
58
59     public void generate(CodeWriter writer, VarDescriptor dest) {
60         throw new IRException("not supported");
61     }
62
63     public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
64         String hash = inverse ? "_hashinv->contains(" : "_hash->contains(" ;
65         writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
66     }    
67
68     public void generate_size(CodeWriter writer, VarDescriptor dest) {
69         assert dest != null;
70         assert vd != null;
71         assert rd != null;
72         String hash = inverse ? "_hashinv->count(" : "_hash->count(" ;
73         writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
74     }
75
76     public void prettyPrint(PrettyPrinter pp) {
77         pp.output(vd.toString());
78         pp.output(".");
79         if (inverse) {
80             pp.output("~");
81         }
82         pp.output(rd.toString());
83     }
84
85     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
86         throw new IRException("not supported");
87     }
88
89 }