CodeWriter crhead = new StandardCodeWriter(this.outputhead);
CodeWriter craux = new StandardCodeWriter(this.outputaux);
crhead.outputline("};");
- craux.outputline("};");
+ craux.outputline("}");
generate_updates();
}
+ String ststate="state";
+ String stmodel="model";
+ String strepairtable="repairtable";
+ String stleft="left";
+ String stright="right";
+
private void generate_updates() {
int count=0;
CodeWriter crhead = new StandardCodeWriter(outputhead);
CodeWriter craux = new StandardCodeWriter(outputaux);
- String state="state";
- String model="model";
- String repairtable="repairtable";
- String left="left";
- String right="right";
+
+ /* Rewrite globals */
+
+ for (Iterator it=this.state.stGlobals.descriptors();it.hasNext();) {
+ VarDescriptor vd=(VarDescriptor)it.next();
+ craux.outputline("#define "+vd.getSafeSymbol()+" "+ststate+"->"+vd.getSafeSymbol());
+ }
+
for(Iterator it=termination.updatenodes.iterator();it.hasNext();) {
GraphNode gn=(GraphNode) it.next();
TermNode tn=(TermNode) gn.getOwner();
switch(mun.op) {
case MultUpdateNode.ADD:
if (isrelation) {
- crhead.outputline("void "+methodname+"("+name+"_state * " +state+","+name+" * "+model+", RepairHash * "+repairtable+", int "+left+", int "+right+");");
- craux.outputline("void "+methodname+"("+name+"_state * "+ state+","+name+" * "+model+", RepairHash * "+repairtable+", int "+left+", int "+right+")");
+ crhead.outputline("void "+methodname+"("+name+"_state * " +ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+", int "+stright+");");
+ craux.outputline("void "+methodname+"("+name+"_state * "+ ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+", int "+stright+")");
} else {
- crhead.outputline("void "+methodname+"("+name+"_state * "+ state+","+name+" * "+model+", RepairHash * "+repairtable+", int "+left+");");
- craux.outputline("void "+methodname+"("+name+"_state * "+state+","+name+" * "+model+", RepairHash * "+repairtable+", int "+left+")");
+ crhead.outputline("void "+methodname+"("+name+"_state * "+ ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+");");
+ craux.outputline("void "+methodname+"("+name+"_state * "+ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+")");
}
craux.startblock();
- un.generate(craux, false, left,right);
+ final SymbolTable st = un.getRule().getSymbolTable();
+ CodeWriter cr = new StandardCodeWriter(outputaux) {
+ public SymbolTable getSymbolTable() { return st; }
+ };
+ un.generate(cr, false, stleft,stright,this);
craux.endblock();
break;
case MultUpdateNode.REMOVE:
Rule r=un.getRule();
- String methodcall="void "+methodname+"("+name+"_state * "+state+","+name+" * "+model+", RepairHash * "+repairtable;
+ String methodcall="void "+methodname+"("+name+"_state * "+ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable;
for(int j=0;j<r.numQuantifiers();j++) {
Quantifier q=r.getQuantifier(j);
if (q instanceof SetQuantifier) {
crhead.outputline(methodcall+";");
craux.outputline(methodcall);
craux.startblock();
- un.generate(craux, true, null,null);
+ final SymbolTable st2 = un.getRule().getSymbolTable();
+ CodeWriter cr2 = new StandardCodeWriter(outputaux) {
+ public SymbolTable getSymbolTable() { return st2; }
+ };
+ un.generate(cr2, true, null,null,this);
craux.endblock();
break;
case MultUpdateNode.MODIFY:
private void generate_teardown() {
CodeWriter cr = new StandardCodeWriter(outputaux);
- cr.outputline("if ("+repairtable.getSafeSymbol()+")");
- cr.outputline("delete "+repairtable.getSafeSymbol()+";");
- cr.outputline("if ("+oldmodel.getSafeSymbol()+")");
- cr.outputline("delete "+oldmodel.getSafeSymbol()+";");
- cr.outputline("delete "+newmodel.getSafeSymbol()+";");
- cr.outputline("delete "+worklist.getSafeSymbol()+";");
cr.endblock();
}
cr2.outputline("exit(1);");
cr2.endblock();
// end block created for worklist
+ cr2.outputline(worklist.getSafeSymbol()+"->pop();");
cr2.endblock();
}
VarDescriptor mincost=VarDescriptor.makeNew("mincost");
VarDescriptor mincostindex=VarDescriptor.makeNew("mincostindex");
DNFConstraint dnfconst=constraint.dnfconstraint;
- cr.outputline("int "+mincostindex.getSafeSymbol()+";");
+ if (dnfconst.size()<=1) {
+ cr.outputline("int "+mincostindex.getSafeSymbol()+"=0;");
+ }
if (dnfconst.size()>1) {
+ cr.outputline("int "+mincostindex.getSafeSymbol()+";");
boolean first=true;
for(int j=0;j<dnfconst.size();j++) {
Conjunction conj=dnfconst.get(j);
cr.outputline("if ("+oldmodel.getSafeSymbol()+")");
cr.outputline("delete "+oldmodel.getSafeSymbol()+";");
cr.outputline(oldmodel.getSafeSymbol()+"="+newmodel.getSafeSymbol()+";");
- cr.outputline("break;"); /* Rebuild model and all */
+ cr.outputline("goto rebuild;"); /* Rebuild model and all */
cr.endblock();
cr.endblock();
}
cr.outputline("if ("+goodflag.getSafeSymbol()+")");
+ cr.startblock();
+ cr.outputline("if ("+repairtable.getSafeSymbol()+")");
+ cr.outputline("delete "+repairtable.getSafeSymbol()+";");
+ cr.outputline("if ("+oldmodel.getSafeSymbol()+")");
+ cr.outputline("delete "+oldmodel.getSafeSymbol()+";");
+ cr.outputline("delete "+newmodel.getSafeSymbol()+";");
+ cr.outputline("delete "+worklist.getSafeSymbol()+";");
cr.outputline("break;");
+ cr.endblock();
+ cr.outputline("rebuild:");
+ cr.outputline(";");
cr.endblock();
cr.outputline("");
cr.outputline("");