import java.util.*;
public class MetaInclusion extends Inclusion {
-
+
Inclusion inclusion;
Vector rules;
Vector constraints;
}
public void generate(CodeWriter cr) {
-
+
this.inclusion.generate(cr);
// for each of the rules, since they are guaranteed to be single quantifiers, and in fact,
- // even stricter, there only quantifier is the same quantifier just generated by
- // the inclusion constraint, we only need to bind each of there vardescriptors in there
+ // even stricter, there only quantifier is the same quantifier just generated by
+ // the inclusion constraint, we only need to bind each of there vardescriptors in there
// own blocks (to avoid name space clashes) to the newly quantified variable.
// we know that the inclusion is a setinlusion
cr.outputline("if (" + addeditem + ")");
cr.startblock();
-
+
ListIterator allrules = rules.listIterator();
while (allrules.hasNext()) {
Rule rule = (Rule) allrules.next();
-
+
// we need to grab the vardescriptor of the first quantifeir (which is a setquantifier)
// and we need to instantiate it inside a new block scope and set it equal to the value
// in "result" .... we then need to generate the guard and inclusion inside of inner rule
-
+
cr.startblock();{
- cr.outputline("// embedding " + rule.getLabel() );
-
+ cr.outputline("/* embedding " + rule.getLabel() +"*/");
+
SetQuantifier sq = (SetQuantifier) rule.quantifiers().next(); // get first qunatifier
VarDescriptor vd = sq.getVar();
cr.outputline("int " + vd.getSafeSymbol() + " = " + result + ";");
cr.pushSymbolTable(rule.getSymbolTable());
-
+
VarDescriptor guardval = VarDescriptor.makeNew();
rule.getGuardExpr().generate(cr, guardval);
-
+
cr.outputline("if (" + guardval.getSafeSymbol() + ")");
cr.startblock(); {
rule.getInclusion().generate(cr);
} cr.endblock();
cr.popSymbolTable();
-
- } cr.endblock();
+
+ } cr.endblock();
}
cr.endblock();
ListIterator allconstraints = constraints.listIterator();
while (allconstraints.hasNext()) {
Constraint constraint = (Constraint) allconstraints.next();
-
+
// ok... um... we need to grab teh vardescripntor of the first quantifier which is guaranteed
// to be a setquantifier... we then need to bind it to variable, generatedresult.
// once this is done we can generated the logicstatement and we can then test for pass/fail
cr.startblock(); {
- cr.outputline("// checking embedded " + constraint.getLabel() );
-
+ cr.outputline("/* checking embedded " + constraint.getLabel()+"*/" );
+
SetQuantifier sq = (SetQuantifier) constraint.quantifiers().next(); // get first qunatifier
VarDescriptor vd = sq.getVar();
cr.outputline("int " + vd.getSafeSymbol() + " = " + result + ";");
cr.pushSymbolTable(constraint.getSymbolTable());
-
+
cr.outputline("int maybe = 0;");
-
+
/* now we have to generate the guard test */
-
+
VarDescriptor constraintboolean = VarDescriptor.makeNew("constraintboolean");
constraint.getLogicStatement().generate(cr, constraintboolean);
-
+
cr.outputline("if (maybe)");
cr.startblock(); {
cr.outputline("__Success = 0;");
cr.outputline("printf(\"maybe fail " + constraint.getNum() + ". \");");
cr.outputline("exit(1);");
-
+
} cr.endblock();
- cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");
+ cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");
cr.startblock(); {
-
+
cr.outputline("__Success = 0;");
cr.outputline("printf(\"fail " + constraint.getNum() + ". \");");
cr.outputline("exit(1);");
} cr.endblock();
cr.popSymbolTable();
-
- } cr.endblock();
+
+ } cr.endblock();
}
}
}
-