5 public class MetaInclusion extends Inclusion {
11 public MetaInclusion() {
14 constraints = new Vector();
17 public Set getTargetDescriptors() {
18 throw new IRException("unsupported");
21 public Set getRequiredDescriptors() {
22 return inclusion.getRequiredDescriptors();
25 public boolean typecheck(SemanticAnalyzer sa) {
26 throw new IRException("unsupported");
29 public void setInclusion(Inclusion in) {
30 assert (in instanceof SetInclusion); // we only support setinclusion meta inclusions
34 public Inclusion getInclusion() {
38 public void addRules(Collection newrules) {
39 rules.addAll(newrules);
42 public void addConstraint(Constraint c) {
46 public void generate(CodeWriter cr) {
48 this.inclusion.generate(cr);
50 // for each of the rules, since they are guaranteed to be single quantifiers, and in fact,
51 // even stricter, there only quantifier is the same quantifier just generated by
52 // the inclusion constraint, we only need to bind each of there vardescriptors in there
53 // own blocks (to avoid name space clashes) to the newly quantified variable.
55 // we know that the inclusion is a setinlusion
56 SetInclusion setinclusion = (SetInclusion) inclusion;
58 String addeditem = setinclusion.generatedaddeditem; // boolean : new item or not
59 String result = setinclusion.generatedresult; // item added to set... what we must bind
61 cr.outputline("if (" + addeditem + ")");
64 ListIterator allrules = rules.listIterator();
65 while (allrules.hasNext()) {
66 Rule rule = (Rule) allrules.next();
68 // we need to grab the vardescriptor of the first quantifeir (which is a setquantifier)
69 // and we need to instantiate it inside a new block scope and set it equal to the value
70 // in "result" .... we then need to generate the guard and inclusion inside of inner rule
74 cr.outputline("// embedding " + rule.getLabel() );
76 SetQuantifier sq = (SetQuantifier) rule.quantifiers().next(); // get first qunatifier
77 VarDescriptor vd = sq.getVar();
78 cr.outputline("int " + vd.getSafeSymbol() + " = " + result + ";");
80 cr.pushSymbolTable(rule.getSymbolTable());
82 VarDescriptor guardval = VarDescriptor.makeNew();
83 rule.getGuardExpr().generate(cr, guardval);
85 cr.outputline("if (" + guardval.getSafeSymbol() + ")");
87 rule.getInclusion().generate(cr);
97 // constraints!!!!!!!!!!!!!!
99 ListIterator allconstraints = constraints.listIterator();
100 while (allconstraints.hasNext()) {
101 Constraint constraint = (Constraint) allconstraints.next();
103 // ok... um... we need to grab teh vardescripntor of the first quantifier which is guaranteed
104 // to be a setquantifier... we then need to bind it to variable, generatedresult.
105 // once this is done we can generated the logicstatement and we can then test for pass/fail
110 cr.outputline("// checking embedded " + constraint.getLabel() );
112 SetQuantifier sq = (SetQuantifier) constraint.quantifiers().next(); // get first qunatifier
113 VarDescriptor vd = sq.getVar();
114 cr.outputline("int " + vd.getSafeSymbol() + " = " + result + ";");
116 cr.pushSymbolTable(constraint.getSymbolTable());
118 cr.outputline("int maybe = 0;");
120 /* now we have to generate the guard test */
122 VarDescriptor constraintboolean = VarDescriptor.makeNew("constraintboolean");
123 constraint.getLogicStatement().generate(cr, constraintboolean);
125 cr.outputline("if (maybe)");
128 cr.outputline("__Success = 0;");
129 cr.outputline("printf(\"maybe fail " + constraint.getNum() + ". \");");
130 cr.outputline("exit(1);");
133 cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");
136 cr.outputline("__Success = 0;");
137 cr.outputline("printf(\"fail " + constraint.getNum() + ". \");");
138 cr.outputline("exit(1);");