5 public class SetInclusion extends Inclusion {
10 public String generatedresult = null;
11 public String generatedaddeditem = null;
13 static boolean worklist = false;
14 public boolean dostore = true;
16 public SetInclusion(Expr elementexpr, SetDescriptor set) {
17 this.elementexpr = elementexpr;
21 public SetDescriptor getSet() {
25 public Set getTargetDescriptors() {
26 HashSet v = new HashSet();
31 public Set getRequiredDescriptors() {
32 return elementexpr.getRequiredDescriptors();
35 public void generate(CodeWriter writer) {
36 VarDescriptor vd = VarDescriptor.makeNew("element");
37 elementexpr.generate(writer, vd);
39 // allows access to the value of this set addition later
40 generatedresult = vd.getSafeSymbol();
42 String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
43 generatedaddeditem = addeditem; // allows access to the result of the set addition later.
45 // we set equal to one so that if dostore == false the guard in teh
46 // metainclusion generation for the subrules and sub quantifiers will go on
47 writer.outputline("int " + addeditem + " = 1;");
51 writer.outputline(addeditem + " = " + set.getSafeSymbol() + "_hash->add((int)" + vd.getSafeSymbol()
52 + ", (int)" + vd.getSafeSymbol() + ");");
54 if (SetInclusion.worklist) {
55 writer.outputline("if (" + addeditem + ")");
56 writer.startblock(); {
57 WorkList.generate_dispatch(writer, set, vd.getSafeSymbol());
66 public boolean typecheck(SemanticAnalyzer sa) {
67 TypeDescriptor td = elementexpr.typecheck(sa);
73 TypeDescriptor settype = set.getType();
75 if (!td.equals(settype)) {
76 sa.getErrorReporter().report(null, "Type mismatch: attempting to test for types '" + td.getSymbol() + "' in set of type '" + settype.getSymbol() + "'");