...
[repair.git] / Repair / RepairCompiler / MCC / IR / SetExpr.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class SetExpr extends Expr {
6
7     SetDescriptor sd;
8
9     public SetExpr(SetDescriptor sd) {
10         this.sd = sd;
11     }
12
13     public String name() {
14         return sd.toString();
15     }
16
17     public boolean equals(Map remap, Expr e) {
18         if (e==null||!(e instanceof SetExpr))
19             return false;
20         SetExpr se=(SetExpr)e;
21         if (sd!=se.sd)
22             return false;
23         return true;
24     }
25
26     public boolean usesDescriptor(Descriptor s) {
27         return (s==sd);
28     }
29
30     public Set useDescriptor(Descriptor s) {
31         HashSet newset=new HashSet();
32         if (s==sd)
33             newset.add(this);
34         return newset;
35     }
36
37     public SetExpr() {
38         this.sd = null;
39     }
40
41     public Set getInversedRelations() {
42         return new HashSet();
43     }
44
45     public Descriptor getDescriptor() {
46         return sd;
47     }
48
49     public Set getRequiredDescriptors() {
50         HashSet v = new HashSet();
51         v.add(sd);
52         return v;
53     }
54
55     public void generate(CodeWriter writer, VarDescriptor dest) {
56         throw new IRException("unsupported");
57     }
58
59     public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
60         writer.outputline("int " + dest.getSafeSymbol() + " = " + sd.getSafeSymbol() + "_hash->contains(" + element.getSafeSymbol() + ");");
61     }    
62
63     public void generate_size(CodeWriter writer, VarDescriptor dest) {
64         writer.outputline("int " + dest.getSafeSymbol() + " = " + sd.getSafeSymbol() + "_hash->count();");
65     }
66
67     public void prettyPrint(PrettyPrinter pp) {
68         pp.output(sd.getSafeSymbol());
69     }
70
71     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
72         this.td = sd.getType();
73         return this.td;
74     }
75
76 }
77
78