Update virtual pointers for C++ code...Various fixes to emit extern declarations.
authorbdemsky <bdemsky>
Sat, 14 Aug 2004 05:09:53 +0000 (05:09 +0000)
committerbdemsky <bdemsky>
Sat, 14 Aug 2004 05:09:53 +0000 (05:09 +0000)
Repair/RepairCompiler/MCC/IR/RepairGenerator.java
Repair/RepairCompiler/MCC/IR/Sources.java
Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java

index 0f21555cc39f8cf04682f9f7c6ee3b2d2c75a19e..f1ff4d3e28963c6021edf4a041fe989d22f8c871 100755 (executable)
@@ -387,7 +387,22 @@ public class RepairGenerator {
        crhead.outputline("~"+name+"();");
         craux.outputline("#include \""+headername+"\"");
         craux.outputline("#include \"size.h\"");
        crhead.outputline("~"+name+"();");
         craux.outputline("#include \""+headername+"\"");
         craux.outputline("#include \"size.h\"");
-
+       if (Compiler.ALLOCATECPLUSPLUS) {
+           for(Iterator it=state.stTypes.descriptors();it.hasNext();) {
+               TypeDescriptor td=(TypeDescriptor)it.next();
+               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();
+                           craux.outputline("extern void * "+vtable+";");
+                       }
+                   }
+               }
+           }
+       }
         craux.outputline(name+"::"+name+"() {");
         craux.outputline("// creating hashtables ");
         
         craux.outputline(name+"::"+name+"() {");
         craux.outputline("// creating hashtables ");
         
index 0db5228d4dca81699a9b731aa5412e9cdb9d716a..73af6898033014c7e4459edcfb1d90e88793d178 100755 (executable)
@@ -2,6 +2,7 @@ package MCC.IR;
 
 import MCC.State;
 import MCC.Compiler;
 
 import MCC.State;
 import MCC.Compiler;
+import java.util.Iterator;
 
 public class Sources {
     State state;
 
 public class Sources {
     State state;
@@ -43,13 +44,20 @@ public class Sources {
        cr.pushSymbolTable(state.stGlobals);
        e.generate(cr, size);
        cr.popSymbolTable();
        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()+");");
        
        if (Compiler.ALLOCATECPLUSPLUS) {
        
        if (Compiler.ALLOCATECPLUSPLUS) {
-           String vtable="_ZTV";
-           vtable+=sd.getType().getSafeSymbol().length();
-           vtable+=sd.getType().getSafeSymbol();
-           cr.outputline("((int**)"+vd.getSafeSymbol()+")[0] = (int *)"+vtable+"+2;");
+           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;");
+                   }
+               }
+           }
        }
     }
 
        }
     }
 
@@ -75,12 +83,7 @@ public class Sources {
            sd=rd.getDomain();
        else
            sd=rd.getRange();
            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);
     }
 }
     }
 }
index c5f197b0f5953af7a5f7a855ccaadbf05c89f0c4..a04b4162ead53f3e436c673f6c1b90266be8a5e0 100755 (executable)
@@ -17,6 +17,14 @@ public class StructureTypeDescriptor extends TypeDescriptor {
     Hashtable labels = new Hashtable();
 
 
     Hashtable labels = new Hashtable();
 
 
+    public int size() {
+       return fieldlist.size();
+    }
+
+    public FieldDescriptor get(int i) {
+       return (FieldDescriptor) fieldlist.get(i);
+    }
+
     public StructureTypeDescriptor(String name) {
         super(name);
     }
     public StructureTypeDescriptor(String name) {
         super(name);
     }