deb6ea54fd542c4803ef790d7f11ca78ae1ba3c0
[repair.git] / Repair / RepairCompiler / MCC / IR / SetInclusion.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class SetInclusion extends Inclusion {
6     
7     Expr elementexpr;
8     SetDescriptor set;
9
10     public SetInclusion(Expr elementexpr, SetDescriptor set) {
11         this.elementexpr = elementexpr;
12         this.set = set;
13     }
14
15     public Set getTargetDescriptors() {
16         HashSet v = new HashSet();
17         v.add(set);
18         return v;
19     }
20
21     public Set getRequiredDescriptors() {
22         return elementexpr.getRequiredDescriptors();
23     }
24
25     public void generate(CodeWriter writer) {
26         VarDescriptor vd = VarDescriptor.makeNew("element");
27         elementexpr.generate(writer, vd);
28         writer.outputline(set.getSafeSymbol() + "_hash->add((int)" + vd.getSafeSymbol() +  ", (int)" + vd.getSafeSymbol() + ");");
29         //writer.outputline("printf(\"" + set.getSafeSymbol() + " (add): %d\\n\", " + vd.getSafeSymbol() + ");");
30     }
31
32     public boolean typecheck(SemanticAnalyzer sa) {
33         TypeDescriptor td = elementexpr.typecheck(sa);
34         
35         if (td == null) {
36             return false;
37         }
38
39         TypeDescriptor settype = set.getType();
40
41         if (!td.equals(settype)) {
42             sa.getErrorReporter().report(null, "Type mismatch: attempting to test for types '" + td.getSymbol() + "' in set of type '" + settype.getSymbol() + "'");
43             return false;
44         }
45         
46         return true;
47     }
48
49 }