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