X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Repair%2FRepairCompiler%2FMCC%2FIR%2FRepairGenerator.java;h=0f21555cc39f8cf04682f9f7c6ee3b2d2c75a19e;hb=67dcbdb36743f6c386db45d66a9e2d17b4a71e43;hp=1419a6856587d768d07a4674fb258ad901bdbe2c;hpb=42d062915995953ad3e0eb1baf823a1db2fe3971;p=repair.git diff --git a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java index 1419a68..0f21555 100755 --- a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java @@ -25,7 +25,6 @@ public class RepairGenerator { HashSet togenerate; static boolean DEBUG=false; Cost cost; - Sources sources; ModelRuleDependence mrd; public RepairGenerator(State state, Termination t) { @@ -40,7 +39,6 @@ public class RepairGenerator { togenerate.removeAll(removed); GraphNode.computeclosure(togenerate,removed); cost=new Cost(); - sources=new Sources(state); mrd=ModelRuleDependence.doAnalysis(state); Repair.repairgenerator=this; } @@ -88,12 +86,20 @@ public class RepairGenerator { generate_call(); generate_start(); generate_rules(); + if (!Compiler.REPAIR||Compiler.GENERATEDEBUGPRINT) { + generate_print(); + } generate_checks(); generate_teardown(); CodeWriter crhead = new StandardCodeWriter(this.outputhead); CodeWriter craux = new StandardCodeWriter(this.outputaux); crhead.outputline("};"); craux.outputline("}"); + + if (Compiler.GENERATEDEBUGHOOKS) { + crhead.outputline("void debughook();"); + craux.outputline("void debughook() {}"); + } generatetypechecks(false); generate_computesizes(); generatetypechecks(true); @@ -116,6 +122,8 @@ public class RepairGenerator { int count=0; CodeWriter crhead = new StandardCodeWriter(outputhead); CodeWriter craux = new StandardCodeWriter(outputaux); + RelationDescriptor.prefix = "model->"; + SetDescriptor.prefix = "model->"; /* Rewrite globals */ @@ -145,6 +153,9 @@ public class RepairGenerator { } craux.startblock(); craux.outputline("int maybe=0;"); + if (Compiler.GENERATEINSTRUMENT) + craux.outputline("updatecount++;"); + final SymbolTable st = un.getRule().getSymbolTable(); CodeWriter cr = new StandardCodeWriter(outputaux) { public SymbolTable getSymbolTable() { return st; } @@ -176,6 +187,8 @@ public class RepairGenerator { craux.outputline(methodcall); craux.startblock(); craux.outputline("int maybe=0;"); + if (Compiler.GENERATEINSTRUMENT) + craux.outputline("updatecount++;"); final SymbolTable st2 = un.getRule().getSymbolTable(); CodeWriter cr2 = new StandardCodeWriter(outputaux) { public SymbolTable getSymbolTable() { return st2; } @@ -203,12 +216,14 @@ public class RepairGenerator { methodcall+=", int "+fq.getVar().getSafeSymbol(); } } - methodcall+=", "+stleft+", "+stright+", "+stnew; + methodcall+=", int "+stleft+", int "+stright+", int "+stnew; methodcall+=")"; crhead.outputline(methodcall+";"); craux.outputline(methodcall); craux.startblock(); craux.outputline("int maybe=0;"); + if (Compiler.GENERATEINSTRUMENT) + craux.outputline("updatecount++;"); final SymbolTable st2 = un.getRule().getSymbolTable(); CodeWriter cr2 = new StandardCodeWriter(outputaux) { public SymbolTable getSymbolTable() { return st2; } @@ -288,6 +303,7 @@ public class RepairGenerator { }; cr.outputline("void "+name+"_state::computesizes(int *sizearray,int **numele) {"); + cr.outputline("int maybe=0;"); for(int i=0;ireset();"); + if (Compiler.GENERATEINSTRUMENT) + craux.outputline("rebuildcount++;"); } private void generate_teardown() { CodeWriter cr = new StandardCodeWriter(outputaux); cr.endblock(); + if (Compiler.GENERATEINSTRUMENT) { + cr.outputline("printf(\"updatecount=%d\\n\",updatecount);"); + cr.outputline("printf(\"rebuildcount=%d\\n\",rebuildcount);"); + cr.outputline("printf(\"abstractcount=%d\\n\",abstractcount);"); + } + + } + + private void generate_print() { + + final SymbolTable st = new SymbolTable(); + + CodeWriter cr = new StandardCodeWriter(outputaux) { + public SymbolTable getSymbolTable() { return st; } + }; + + cr.outputline("// printing sets!"); + cr.outputline("printf(\"\\n\\nPRINTING SETS AND RELATIONS\\n\");"); + + Iterator setiterator = state.stSets.descriptors(); + while (setiterator.hasNext()) { + SetDescriptor sd = (SetDescriptor) setiterator.next(); + if (sd.getSymbol().equals("int") || sd.getSymbol().equals("token")) { + continue; + } + + String setname = sd.getSafeSymbol(); + + cr.startblock(); + cr.outputline("// printing set " + setname); + cr.outputline("printf(\"\\nPrinting set " + sd.getSymbol() + " - %d elements \\n\", " + setname + "_hash->count());"); + cr.outputline("SimpleIterator __setiterator;"); + cr.outputline("" + setname + "_hash->iterator(__setiterator);"); + cr.outputline("while (__setiterator.hasNext())"); + cr.startblock(); + cr.outputline("int __setval = (int) __setiterator.next();"); + + TypeDescriptor td = sd.getType(); + if (td instanceof StructureTypeDescriptor) { + StructureTypeDescriptor std = (StructureTypeDescriptor) td; + VarDescriptor vd = new VarDescriptor ("__setval", "__setval", td, false); + std.generate_printout(cr, vd); + } else { // Missing type descriptor or reserved type, just print int + cr.outputline("printf(\"<%d> \", __setval);"); + } + + + cr.endblock(); + cr.endblock(); + } + + cr.outputline("printf(\"\\n\\n------------------- END PRINTING\\n\");"); } Set ruleset=null; @@ -488,15 +574,54 @@ public class RepairGenerator { Iterator iterator_rs = ruleset.iterator(); while (iterator_rs.hasNext()) { Rule rule = (Rule) iterator_rs.next(); + if (rule.getnogenerate()) + continue; { final SymbolTable st = rule.getSymbolTable(); CodeWriter cr = new StandardCodeWriter(outputaux) { public SymbolTable getSymbolTable() { return st; } }; + InvariantValue ivalue=new InvariantValue(); + cr.setInvariantValue(ivalue); + cr.outputline("// build " +escape(rule.toString())); cr.startblock(); cr.outputline("int maybe=0;"); - ListIterator quantifiers = rule.quantifiers(); + + Expr ruleexpr=rule.getGuardExpr(); + HashSet invariantvars=new HashSet(); + Set invariants=ruleexpr.findInvariants(invariantvars); + + if ((ruleexpr instanceof BooleanLiteralExpr)&& + ((BooleanLiteralExpr)ruleexpr).getValue()) { + if (rule.getInclusion() instanceof SetInclusion) { + invariants.addAll(((SetInclusion)rule.getInclusion()).getExpr().findInvariants(invariantvars)); + } else if (rule.getInclusion() instanceof RelationInclusion) { + invariants.addAll(((RelationInclusion)rule.getInclusion()).getLeftExpr().findInvariants(invariantvars)); + invariants.addAll(((RelationInclusion)rule.getInclusion()).getRightExpr().findInvariants(invariantvars)); + } + } + ListIterator quantifiers = rule.quantifiers(); + while (quantifiers.hasNext()) { + Quantifier quantifier = (Quantifier) quantifiers.next(); + if (quantifier instanceof ForQuantifier) { + ForQuantifier fq=(ForQuantifier)quantifier; + invariants.addAll(fq.lower.findInvariants(invariantvars)); + invariants.addAll(fq.upper.findInvariants(invariantvars)); + } + } + + for(Iterator invit=invariants.iterator();invit.hasNext();) { + Expr invexpr=(Expr)invit.next(); + VarDescriptor tmpvd=VarDescriptor.makeNew("tmpvar"); + VarDescriptor maybevd=VarDescriptor.makeNew("maybevar"); + invexpr.generate(cr,tmpvd); + cr.outputline("int "+maybevd.getSafeSymbol()+"=maybe;"); + cr.outputline("maybe=0;"); + ivalue.assignPair(invexpr,tmpvd,maybevd); + } + + quantifiers = rule.quantifiers(); while (quantifiers.hasNext()) { Quantifier quantifier = (Quantifier) quantifiers.next(); quantifier.generate_open(cr); @@ -628,27 +753,33 @@ public class RepairGenerator { } private void generate_checks() { - /* do constraint checks */ - Vector constraints = state.vConstraints; - - for (int i = 0; i < constraints.size(); i++) { - Constraint constraint = (Constraint) constraints.elementAt(i); + Iterator i; + if (Compiler.REPAIR) + i=termination.constraintdependence.computeOrdering().iterator(); + else + i=state.vConstraints.iterator(); + for (; i.hasNext();) { + Constraint constraint; + if (Compiler.REPAIR) + constraint= (Constraint) ((GraphNode)i.next()).getOwner(); + else + constraint=(Constraint)i.next(); { final SymbolTable st = constraint.getSymbolTable(); - CodeWriter cr = new StandardCodeWriter(outputaux) { - public SymbolTable getSymbolTable() { return st; } - }; + CodeWriter cr = new StandardCodeWriter(outputaux); + cr.pushSymbolTable(constraint.getSymbolTable()); + cr.outputline("// checking " + escape(constraint.toString())); cr.startblock(); ListIterator quantifiers = constraint.quantifiers(); while (quantifiers.hasNext()) { - Quantifier quantifier = (Quantifier) quantifiers.next(); + Quantifier quantifier = (Quantifier) quantifiers.next(); quantifier.generate_open(cr); - } + } cr.outputline("int maybe = 0;"); @@ -660,25 +791,29 @@ public class RepairGenerator { cr.outputline("if (maybe)"); cr.startblock(); cr.outputline("printf(\"maybe fail " + escape(constraint.toString()) + ". \\n\");"); - cr.outputline("exit(1);"); + //cr.outputline("exit(1);"); cr.endblock(); cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")"); cr.startblock(); - if (!Compiler.REPAIR) + if (!Compiler.REPAIR||Compiler.GENERATEDEBUGHOOKS) cr.outputline("printf(\"fail " + escape(constraint.toString()) + ". \\n\");"); - else { + + if (Compiler.REPAIR) { /* Do repairs */ /* Build new repair table */ cr.outputline("if ("+repairtable.getSafeSymbol()+")"); cr.outputline("delete "+repairtable.getSafeSymbol()+";"); cr.outputline(repairtable.getSafeSymbol()+"=new RepairHash();"); - + if (Compiler.GENERATEDEBUGHOOKS) + cr.outputline("debughook();"); /* Compute cost of each repair */ VarDescriptor mincost=VarDescriptor.makeNew("mincost"); VarDescriptor mincostindex=VarDescriptor.makeNew("mincostindex"); - DNFConstraint dnfconst=constraint.dnfconstraint; + Vector dnfconst=new Vector(); + dnfconst.addAll((Set)termination.conjunctionmap.get(constraint)); + if (dnfconst.size()<=1) { cr.outputline("int "+mincostindex.getSafeSymbol()+"=0;"); } @@ -686,8 +821,8 @@ public class RepairGenerator { cr.outputline("int "+mincostindex.getSafeSymbol()+";"); boolean first=true; for(int j=0;jget("+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); } else { - expr.getLeftExpr().generate(cr,rightside); + ((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,rightside); expr.getRightExpr().generate(cr,newvalue); cr.outputline(rd.getDomain().getType().getGenerateType().getSafeSymbol()+" "+leftside.getSafeSymbol()+";"); - cr.outputline(rd.getSafeSymbol()+"_hashinv->get("+leftside.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); + cr.outputline(rd.getSafeSymbol()+"_hashinv->get("+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); } - if (negated) - if (opcode==Opcode.GT) { - opcode=Opcode.LE; - } else if (opcode==Opcode.GE) { - opcode=Opcode.LT; - } else if (opcode==Opcode.LT) { - opcode=Opcode.GE; - } else if (opcode==Opcode.LE) { - opcode=Opcode.GT; - } else if (opcode==Opcode.EQ) { - opcode=Opcode.NE; - } else if (opcode==Opcode.NE) { - opcode=Opcode.EQ; - } else { - throw new Error("Unrecognized Opcode"); - } + + opcode=Opcode.translateOpcode(negated,opcode); if (opcode==Opcode.GT) { cr.outputline(newvalue.getSafeSymbol()+"++;"); @@ -870,7 +1043,7 @@ public class RepairGenerator { /* Equal */ } else if (opcode==Opcode.EQ) { /* Equal */ - } else if (opcode==Opcode.NE) { + } else if (opcode==Opcode.NE) { /* search for FLAGNE if this is changed*/ cr.outputline(newvalue.getSafeSymbol()+"++;"); } else { throw new Error("Unrecognized Opcode"); @@ -878,6 +1051,35 @@ public class RepairGenerator { /* Do abstract repairs */ if (usageimage) { cr.outputline(rd.getSafeSymbol()+"_hash->remove("+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); + } + if (usageinvimage) { + cr.outputline(rd.getSafeSymbol()+"_hashinv->remove("+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); + } + + if (needremoveloop) { + if (!inverted) { + cr.outputline("if ("+rd.getSafeSymbol()+"_hash->contains("+leftside.getSafeSymbol()+")) {"); + } else { + cr.outputline("if ("+rd.getSafeSymbol()+"_hashinv->contains("+rightside.getSafeSymbol()+")) {"); + } + for(int i=0;iaddrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");"); + } + } + } + } + cr.outputline("continue;"); + cr.outputline("}"); + } + + if (usageimage) { if (!inverted) { cr.outputline(rd.getSafeSymbol()+"_hash->add("+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");"); } else { @@ -885,7 +1087,6 @@ public class RepairGenerator { } } if (usageinvimage) { - cr.outputline(rd.getSafeSymbol()+"_hashinv->remove("+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); if (!inverted) { cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+newvalue.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); } else { @@ -893,12 +1094,12 @@ public class RepairGenerator { } } /* Do concrete repairs */ - if (munmodify!=null) { + if (munmodify!=null&&(!ar.mayNeedFunctionEnforcement(state))||(munadd==null)||(ar.needsRemoves(state)&&(munremove==null))) { for(int i=0;iaddrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");"); + if (ar.needsRemoves(state)) + for(int i=0;iaddrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");"); + } } } } - } /* Now do addition */ UpdateNode un=munadd.getUpdate(0); String name=(String)updatenames.get(un); @@ -932,31 +1133,18 @@ public class RepairGenerator { cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); } } + if (needremoveloop) { + cr.outputline("break;"); + cr.outputline("}"); + } } public void generatesizerepair(Conjunction conj, DNFPredicate dpred, CodeWriter cr) { ExprPredicate ep=(ExprPredicate)dpred.getPredicate(); OpExpr expr=(OpExpr)ep.expr; Opcode opcode=expr.getOpcode(); - { - boolean negated=dpred.isNegated(); - if (negated) - if (opcode==Opcode.GT) { - opcode=Opcode.LE; - } else if (opcode==Opcode.GE) { - opcode=Opcode.LT; - } else if (opcode==Opcode.LT) { - opcode=Opcode.GE; - } else if (opcode==Opcode.LE) { - opcode=Opcode.GT; - } else if (opcode==Opcode.EQ) { - opcode=Opcode.NE; - } else if (opcode==Opcode.NE) { - opcode=Opcode.EQ; - } else { - throw new Error("Unrecognized Opcode"); - } - } + opcode=Opcode.translateOpcode(dpred.isNegated(),opcode); + MultUpdateNode munremove; MultUpdateNode munadd; @@ -967,7 +1155,7 @@ public class RepairGenerator { munremove=getmultupdatenode(conj,dpred,AbstractRepair.REMOVEFROMSET); munadd=getmultupdatenode(conj,dpred,AbstractRepair.ADDTOSET); } - int size=ep.leftsize(); + int size=ep.rightSize(); VarDescriptor sizevar=VarDescriptor.makeNew("size"); ((OpExpr)expr).left.generate(cr, sizevar); VarDescriptor change=VarDescriptor.makeNew("change"); @@ -1004,6 +1192,12 @@ public class RepairGenerator { } else { throw new Error("Unrecognized Opcode"); } + +// In some cases the analysis has determined that generating removes +// is unnecessary + if (generateremove&&munremove==null) + generateremove=false; + Descriptor d=ep.getDescriptor(); if (generateremove) { cr.outputline("for(;"+change.getSafeSymbol()+"<0;"+change.getSafeSymbol()+"++)"); @@ -1064,24 +1258,25 @@ public class RepairGenerator { if (d instanceof RelationDescriptor) { VarDescriptor otherside=((ImageSetExpr)((SizeofExpr)((OpExpr)ep.expr).left).setexpr).vd; RelationDescriptor rd=(RelationDescriptor)d; - if (sources.relsetSource(rd,!ep.inverted())) { + if (termination.sources.relsetSource(rd,!ep.inverted())) { /* Set Source */ - SetDescriptor sd=sources.relgetSourceSet(rd,!ep.inverted()); + SetDescriptor sd=termination.sources.relgetSourceSet(rd,!ep.inverted()); VarDescriptor iterator=VarDescriptor.makeNew("iterator"); cr.outputline(sd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";"); - cr.outputline("for("+iterator.getSafeSymbol()+"="+sd.getSafeSymbol()+"_hash->iterator();"+iterator.getSafeSymbol()+".hasNext();)"); + cr.outputline("SimpleIterator "+iterator.getSafeSymbol()+";"); + cr.outputline("for("+sd.getSafeSymbol()+"_hash->iterator("+ iterator.getSafeSymbol() +");"+iterator.getSafeSymbol()+".hasNext();)"); cr.startblock(); if (ep.inverted()) { - cr.outputline("if !"+rd.getSafeSymbol()+"_hashinv->contains("+iterator.getSafeSymbol()+"->key(),"+otherside.getSafeSymbol()+")"); + cr.outputline("if (!"+rd.getSafeSymbol()+"_hashinv->contains("+iterator.getSafeSymbol()+".key(),"+otherside.getSafeSymbol()+"))"); } else { - cr.outputline("if !"+rd.getSafeSymbol()+"_hash->contains("+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+"->key())"); + cr.outputline("if (!"+rd.getSafeSymbol()+"_hash->contains("+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+".key()))"); } cr.outputline(newobject.getSafeSymbol()+"="+iterator.getSafeSymbol()+".key();"); - cr.outputline(iterator.getSafeSymbol()+"->next();"); + cr.outputline(iterator.getSafeSymbol()+".next();"); cr.endblock(); - } else if (sources.relallocSource(rd,!ep.inverted())) { + } else if (termination.sources.relallocSource(rd,!ep.inverted())) { /* Allocation Source*/ - sources.relgenerateSourceAlloc(cr,newobject,rd,!ep.inverted()); + termination.sources.relgenerateSourceAlloc(cr,newobject,rd,!ep.inverted()); } else throw new Error("No source for adding to Relation"); if (ep.inverted()) { boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE); @@ -1107,21 +1302,22 @@ public class RepairGenerator { } } else { SetDescriptor sd=(SetDescriptor)d; - if (sources.setSource(sd)) { + if (termination.sources.setSource(sd)) { /* Set Source */ /* Set Source */ - SetDescriptor sourcesd=sources.getSourceSet(sd); + SetDescriptor sourcesd=termination.sources.getSourceSet(sd); VarDescriptor iterator=VarDescriptor.makeNew("iterator"); cr.outputline(sourcesd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";"); - cr.outputline("for("+iterator.getSafeSymbol()+"="+sourcesd.getSafeSymbol()+"_hash->iterator();"+iterator.getSafeSymbol()+".hasNext();)"); + cr.outputline("SimpleIterator "+iterator.getSafeSymbol()+";"); + cr.outputline("for("+sourcesd.getSafeSymbol()+"_hash->iterator("+iterator.getSafeSymbol()+");"+iterator.getSafeSymbol()+".hasNext();)"); cr.startblock(); - cr.outputline("if !"+sd.getSafeSymbol()+"_hash->contains("+iterator.getSafeSymbol()+"->key())"); + cr.outputline("if (!"+sd.getSafeSymbol()+"_hash->contains("+iterator.getSafeSymbol()+".key()))"); cr.outputline(newobject.getSafeSymbol()+"="+iterator.getSafeSymbol()+".key();"); - cr.outputline(iterator.getSafeSymbol()+"->next();"); + cr.outputline(iterator.getSafeSymbol()+".next();"); cr.endblock(); - } else if (sources.allocSource(sd)) { + } else if (termination.sources.allocSource(sd)) { /* Allocation Source*/ - sources.generateSourceAlloc(cr,newobject,sd); + termination.sources.generateSourceAlloc(cr,newobject,sd); } else throw new Error("No source for adding to Set"); cr.outputline(sd.getSafeSymbol()+"_hash->add("+newobject.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); UpdateNode un=munadd.getUpdate(0); @@ -1162,7 +1358,7 @@ public class RepairGenerator { Rule r=(Rule)state.vRules.get(i); if (r.getInclusion().getTargetDescriptors().contains(rd)) { for(int j=0;j"+rd.getJustSafeSymbol()+"_hash->contains("+leftvar+","+rightvar+"))"); - else - cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hashinv->contains("+rightvar+","+leftvar+"))"); - cr.startblock(); { - /* Adding new item */ - /* Perform safety checks */ - cr.outputline("if ("+repairtable.getSafeSymbol()+"&&"); - cr.outputline(repairtable.getSafeSymbol()+"->containsrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+"))"); + if (Compiler.REPAIR) { + cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&"); + if (usageimage) + cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hash->contains("+leftvar+","+rightvar+"))"); + else + cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hashinv->contains("+rightvar+","+leftvar+"))"); + cr.startblock(); { - /* Have update to call into */ - VarDescriptor mdfyptr=VarDescriptor.makeNew("modifyptr"); - cr.outputline("int "+mdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->getrelation2("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); - - String parttype=""; - for(int i=0;icontainsrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+"))"); + cr.startblock(); { + /* Have update to call into */ + VarDescriptor mdfyptr=VarDescriptor.makeNew("modifyptr"); + VarDescriptor ismdfyptr=VarDescriptor.makeNew("ismodifyptr"); + cr.outputline("int "+ismdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->ismodify("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); - - cr.outputline("void *"+tmpptr.getSafeSymbol()+"="); - cr.outputline("(void *) "+repairtable.getSafeSymbol()+"->getrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); - cr.outputline("if ("+mdfyptr.getSafeSymbol()+")"); - { - cr.startblock(); - cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+"int,int,int)="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+"int,int,int)) "+tmpptr.getSafeSymbol()); - cr.outputline(methodcall+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");"); - cr.endblock(); - } - cr.outputline("else "); - { - cr.startblock(); - cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol()); - cr.outputline(methodcall+");"); - cr.endblock(); + + + String parttype=""; + for(int i=0;igetrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); + cr.outputline("if ("+ismdfyptr.getSafeSymbol()+")"); + { + cr.startblock(); + cr.outputline("int "+mdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->getrelation2("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); + cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+",int,int,int)="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+",int,int,int)) "+tmpptr.getSafeSymbol()+";"); + cr.outputline(methodcall+","+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");"); + cr.endblock(); + } + cr.outputline("else "); + { + cr.startblock(); + cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol()+";"); + cr.outputline(methodcall+");"); + cr.endblock(); + } + cr.outputline("delete "+newmodel.getSafeSymbol()+";"); + cr.outputline("goto rebuild;"); } - cr.outputline("goto rebuild;"); - } - cr.endblock(); - /* Build standard compensation actions */ - if (need_compensation(currentrule)) { - UpdateNode un=find_compensation(currentrule); - String name=(String)updatenames.get(un); - usedupdates.add(un); /* Mark as used */ - String methodcall=name+"(this,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol(); - for(int i=0;iadd((int)" + leftvar + ", (int)" + rightvar+ ");"); } if (rd.testUsage(RelationDescriptor.INVIMAGE)) { + cr.outputline(ifstring); cr.outputline(addeditem + " = " + rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar + ", (int)" + leftvar + ");"); } - cr.outputline("if (" + addeditem + ")"); - cr.startblock(); Vector dispatchrules = getrulelist(rd); @@ -1406,12 +1633,12 @@ public class RepairGenerator { dispatchrules.removeAll(toremove); if (dispatchrules.size() == 0) { cr.outputline("// nothing to dispatch"); - cr.endblock(); return; } - - cr.outputline("if ("+addeditem+")"); + + cr.outputline("if (" + addeditem + ")"); cr.startblock(); + for(int i = 0; i < dispatchrules.size(); i++) { Rule rule = (Rule) dispatchrules.elementAt(i); if (rule.getGuardExpr().getRequiredDescriptors().contains(rd)) { @@ -1427,86 +1654,108 @@ public class RepairGenerator { } } } - cr.endblock(); + cr.endblock(); } public void generate_dispatch(CodeWriter cr, SetDescriptor sd, String setvar) { - - cr.outputline("// SET DISPATCH "); - - cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&"); - cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+sd.getJustSafeSymbol()+"_hash->contains("+setvar+"))"); - cr.startblock(); { - /* Adding new item */ - /* Perform safety checks */ - cr.outputline("if ("+repairtable.getSafeSymbol()+"&&"); - cr.outputline(repairtable.getSafeSymbol()+"->containsset("+sd.getNum()+","+currentrule.getNum()+","+setvar+"))"); + cr.outputline("// SET DISPATCH "); + if (Compiler.REPAIR) { + cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&"); + cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+sd.getJustSafeSymbol()+"_hash->contains("+setvar+"))"); cr.startblock(); { - /* Have update to call into */ - VarDescriptor funptr=VarDescriptor.makeNew("updateptr"); - String parttype=""; - for(int i=0;igetset("+sd.getNum()+","+currentrule.getNum()+","+setvar+");"); - String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+ - repairtable.getSafeSymbol(); - for(int i=0;icontainsset("+sd.getNum()+","+currentrule.getNum()+","+setvar+"))"); + cr.startblock(); { + /* Have update to call into */ + VarDescriptor funptr=VarDescriptor.makeNew("updateptr"); + String parttype=""; + for(int i=0;igetset("+sd.getNum()+","+currentrule.getNum()+","+setvar+");"); + String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+ + repairtable.getSafeSymbol(); + for(int i=0;i"+sdrule.getJustSafeSymbol()+"_hash->contains("+setvar+"))"); + cr.startblock(); + } + cr.outputline(methodcall); + cr.outputline("delete "+newmodel.getSafeSymbol()+";"); + cr.outputline("goto rebuild;"); + cr.endblock(); } + if (currentrule==itrule) + cr.endblock(); } - methodcall+=");"; - cr.outputline(methodcall); - cr.outputline("goto rebuild;"); } } - cr.endblock(); String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol(); - cr.outputline("int " + addeditem + " = 1;"); + cr.outputline("int " + addeditem + " = 0;"); + if (sd.getType() instanceof StructureTypeDescriptor) { + cr.outputline("if (!maybe&&"+setvar+")"); + } else + cr.outputline("if (!maybe)"); cr.outputline(addeditem + " = " + sd.getSafeSymbol() + "_hash->add((int)" + setvar + ", (int)" + setvar + ");"); cr.startblock(); Vector dispatchrules = getrulelist(sd); @@ -1524,6 +1773,7 @@ public class RepairGenerator { cr.endblock(); return; } + /* Add item to worklist if new */ cr.outputline("if ("+addeditem+")"); cr.startblock(); for(int i = 0; i < dispatchrules.size(); i++) { @@ -1541,7 +1791,6 @@ public class RepairGenerator { } } } - cr.endblock(); cr.endblock(); }