Adding functionality for printing sets.
[repair.git] / Repair / RepairCompiler / MCC / IR / RepairGenerator.java
index 9d236e8cd469fea56f2b5ab90a78a508a6d365ac..71ff6edc3b7c0651e4eae60f558eab817a605cdf 100755 (executable)
@@ -88,6 +88,7 @@ public class RepairGenerator {
        generate_call();
        generate_start();
         generate_rules();
        generate_call();
        generate_start();
         generate_rules();
+       generate_print();
         generate_checks();
         generate_teardown();
        CodeWriter crhead = new StandardCodeWriter(this.outputhead);
         generate_checks();
         generate_teardown();
        CodeWriter crhead = new StandardCodeWriter(this.outputhead);
@@ -474,6 +475,52 @@ public class RepairGenerator {
        cr.endblock();
     }
 
        cr.endblock();
     }
 
+    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;
     private void generate_rules() {
        /* first we must sort the rules */
     Set ruleset=null;
     private void generate_rules() {
        /* first we must sort the rules */
@@ -630,16 +677,19 @@ public class RepairGenerator {
     private void generate_checks() {
 
         /* do constraint checks */
     private void generate_checks() {
 
         /* do constraint checks */
-        Vector constraints = state.vConstraints;
+       //        Vector constraints = state.vConstraints;
 
 
-        for (int i = 0; i < constraints.size(); i++) {
-            Constraint constraint = (Constraint) constraints.elementAt(i); 
+
+       //        for (int i = 0; i < constraints.size(); i++) {
+       //            Constraint constraint = (Constraint) constraints.elementAt(i); 
+       for (Iterator i = termination.constraintdependence.computeOrdering().iterator(); i.hasNext();) {
+           Constraint constraint = (Constraint) ((GraphNode)i.next()).getOwner();
            
             {
                final SymbolTable st = constraint.getSymbolTable();
            
             {
                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();
 
                cr.outputline("// checking " + escape(constraint.toString()));
                 cr.startblock();
 
@@ -938,25 +988,8 @@ public class RepairGenerator {
        ExprPredicate ep=(ExprPredicate)dpred.getPredicate();
        OpExpr expr=(OpExpr)ep.expr;
        Opcode opcode=expr.getOpcode();
        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;
        MultUpdateNode munremove;
 
        MultUpdateNode munadd;
@@ -1004,6 +1037,12 @@ public class RepairGenerator {
        } else {
            throw new Error("Unrecognized Opcode");
        }
        } 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()+"++)");
        Descriptor d=ep.getDescriptor();
        if (generateremove) {
            cr.outputline("for(;"+change.getSafeSymbol()+"<0;"+change.getSafeSymbol()+"++)");