Adding functionality for printing sets.
authorcristic <cristic>
Mon, 26 Apr 2004 20:44:56 +0000 (20:44 +0000)
committercristic <cristic>
Mon, 26 Apr 2004 20:44:56 +0000 (20:44 +0000)
Repair/RepairCompiler/MCC/IR/RepairGenerator.java
Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java

index 356c56da2c500e290cb3cd51d502452d97320d43..71ff6edc3b7c0651e4eae60f558eab817a605cdf 100755 (executable)
@@ -88,6 +88,7 @@ public class RepairGenerator {
        generate_call();
        generate_start();
         generate_rules();
+       generate_print();
         generate_checks();
         generate_teardown();
        CodeWriter crhead = new StandardCodeWriter(this.outputhead);
@@ -474,6 +475,52 @@ public class RepairGenerator {
        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 */
index 9128a4335087750a10ee2ed4dce2451aeeaf15fe..f7e19dcb49663b79c18bb89117044cc7232ada8a 100755 (executable)
@@ -138,4 +138,24 @@ public class StructureTypeDescriptor extends TypeDescriptor {
         }
     }
 
+    public void generate_printout(CodeWriter cr, VarDescriptor vd) {
+       // #TBD#: does not support printing out fields that have variable size, substructures, etc
+
+       cr.outputline("printf(\"" + getSymbol() + " %p: \", " + vd.getSafeSymbol() + ");");     
+       for (int i = 0; i < fieldlist.size(); i++) {
+           FieldDescriptor fd = (FieldDescriptor) fieldlist.elementAt(i);                                                      
+           cr.outputline("printf(\"\\n\\t" + fd.getSymbol() + " = \");");
+           if (fd.getPtr()) { 
+               cr.outputline("printf(\"(" + fd.getType().getSymbol() + ") %p \", ((int *)" + vd.getSafeSymbol() + ")[" + i + "]);");
+           } else if ( fd.getType() instanceof ReservedTypeDescriptor) {
+               cr.outputline("printf(\"%d \", ((int *)" + vd.getSafeSymbol() + ")[" + i + "]);");              
+           } else {
+               cr.outputline("printf(\"unsupported, breaking\");");
+               break;
+           }
+       }
+       
+       cr.outputline("printf(\"\\n\");");
+    }
+
 }