Record that we allocated a new object.
[repair.git] / Repair / RepairCompiler / MCC / IR / Sources.java
index d5cd1def9aa77a28d9b2d887a3e85733086be739..da41331993a17e23987906569d991798bde6b30b 100755 (executable)
@@ -1,6 +1,8 @@
 package MCC.IR;
 
 import MCC.State;
+import MCC.Compiler;
+import java.util.Iterator;
 
 public class Sources {
     State state;
@@ -10,7 +12,12 @@ public class Sources {
     }
 
     public boolean setSource(SetDescriptor sd) {
-       if (sd.getSymbol().equals("InodeBitmapBlock"))
+       SetDescriptor usedblock=(SetDescriptor)state.stSets.get("UsedBlock");
+       SetDescriptor usedinode=(SetDescriptor)state.stSets.get("UsedInode");
+
+       if (usedblock!=null&&usedblock.isSubset(sd))
+           return true;
+       if (usedinode!=null&&usedinode.isSubset(sd))
            return true;
 
        return false;
@@ -19,10 +26,17 @@ public class Sources {
        return !setSource(sd);
     }
     public SetDescriptor getSourceSet(SetDescriptor sd) {
-       if (sd.getSymbol().equals("InodeBitmapBlock"))
+       SetDescriptor usedblock=(SetDescriptor)state.stSets.get("UsedBlock");
+       SetDescriptor usedinode=(SetDescriptor)state.stSets.get("UsedInode");
+
+       if (usedblock!=null&&usedblock.isSubset(sd))
            return (SetDescriptor)state.stSets.get("FreeBlock");
+       if (usedinode!=null&&usedinode.isSubset(sd))
+           return (SetDescriptor)state.stSets.get("FreeInode");
+
        return null;
     }
+
     public void generateSourceAlloc(CodeWriter cr,VarDescriptor vd, SetDescriptor sd) {
        TypeDescriptor td=sd.getType();
        Expr e=td.getSizeExpr();
@@ -30,7 +44,21 @@ public class Sources {
        cr.pushSymbolTable(state.stGlobals);
        e.generate(cr, size);
        cr.popSymbolTable();
-       cr.outputline(td.getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") malloc("+size.getSafeSymbol()+");");
+       cr.outputline(td.getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") calloc(1,"+size.getSafeSymbol()+");");
+       cr.outputline("alloc("+vd.getSafeSymbol()+","+size.getSafeSymbol()+");");
+       if (Compiler.ALLOCATECPLUSPLUS) {
+           if (td instanceof StructureTypeDescriptor) {
+               if (((StructureTypeDescriptor)td).size()>0) {
+                   FieldDescriptor fd=((StructureTypeDescriptor)td).get(0);
+                   if (fd.getSymbol().startsWith("_vptr_")) {
+                       String vtable="_ZTV";
+                       vtable+=td.getSymbol().length();
+                       vtable+=td.getSymbol();
+                       cr.outputline("((int**) "+vd.getSafeSymbol()+")[0] = (int *) & "+vtable+"+2;");
+                   }
+               }
+           }
+       }
     }
 
     public boolean relsetSource(RelationDescriptor rd, boolean domain) {
@@ -55,13 +83,7 @@ public class Sources {
            sd=rd.getDomain();
        else
            sd=rd.getRange();
-       TypeDescriptor td=sd.getType();
-       Expr e=td.getSizeExpr();
-       VarDescriptor size=VarDescriptor.makeNew("size");
-       cr.pushSymbolTable(state.stGlobals);
-       e.generate(cr, size);
-       cr.popSymbolTable();
-       cr.outputline(td.getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") malloc("+size.getSafeSymbol()+");");
+       
+       generateSourceAlloc(cr, vd, sd);
     }
-
 }