Generalize definition of SumExpr a little...Lets sum all elements of
[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.addDeclaration("int", dest.getSafeSymbol());
61         writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskey(" +sd.getSafeSymbol()+ "_hash, "+element.getSafeSymbol() + ");");
62     }
63
64     public void generate_size(CodeWriter writer, VarDescriptor dest) {
65         writer.addDeclaration("int", dest.getSafeSymbol());
66         writer.outputline(dest.getSafeSymbol() + " = SimpleHashcountset("+sd.getSafeSymbol()+"_hash);");
67     }
68
69     public void prettyPrint(PrettyPrinter pp) {
70         pp.output(sd.getSafeSymbol());
71     }
72
73     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
74         this.td = sd.getType();
75         return this.td;
76     }
77
78 }