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 boolean usesDescriptor(Descriptor d) {
25 return elementexpr.usesDescriptor(d);
28 public SetDescriptor getSet() {
32 public Set getTargetDescriptors() {
33 HashSet v = new HashSet();
38 public Set getRequiredDescriptors() {
39 return elementexpr.getRequiredDescriptors();
42 public void generate(CodeWriter writer) {
43 VarDescriptor vd = VarDescriptor.makeNew("element");
44 elementexpr.generate(writer, vd);
46 // allows access to the value of this set addition later
47 generatedresult = vd.getSafeSymbol();
49 String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
50 generatedaddeditem = addeditem; // allows access to the result of the set addition later.
52 // we set equal to one so that if dostore == false the guard in teh
53 // metainclusion generation for the subrules and sub quantifiers will go on
54 writer.outputline("int " + addeditem + " = 1;");
58 writer.outputline(addeditem + " = " + set.getSafeSymbol() + "_hash->add((int)" + vd.getSafeSymbol()
59 + ", (int)" + vd.getSafeSymbol() + ");");
61 if (SetInclusion.worklist) {
62 writer.outputline("if (" + addeditem + ")");
63 writer.startblock(); {
64 WorkList.generate_dispatch(writer, set, vd.getSafeSymbol());
73 public boolean typecheck(SemanticAnalyzer sa) {
74 TypeDescriptor td = elementexpr.typecheck(sa);
80 TypeDescriptor settype = set.getType();
82 if (!td.equals(settype)) {
83 sa.getErrorReporter().report(null, "Type mismatch: attempting to test for types '" + td.getSymbol() + "' in set of type '" + settype.getSymbol() + "'");