From 70b5e5116aa23561dfa1326b8eeb7821a6ebfdd1 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Sat, 14 Aug 2004 05:09:53 +0000 Subject: [PATCH] Update virtual pointers for C++ code...Various fixes to emit extern declarations. --- .../MCC/IR/RepairGenerator.java | 17 +++++++++++- Repair/RepairCompiler/MCC/IR/Sources.java | 27 ++++++++++--------- .../MCC/IR/StructureTypeDescriptor.java | 8 ++++++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java index 0f21555..f1ff4d3 100755 --- a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java @@ -387,7 +387,22 @@ public class RepairGenerator { 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 "); diff --git a/Repair/RepairCompiler/MCC/IR/Sources.java b/Repair/RepairCompiler/MCC/IR/Sources.java index 0db5228..73af689 100755 --- a/Repair/RepairCompiler/MCC/IR/Sources.java +++ b/Repair/RepairCompiler/MCC/IR/Sources.java @@ -2,6 +2,7 @@ package MCC.IR; import MCC.State; import MCC.Compiler; +import java.util.Iterator; public class Sources { State state; @@ -43,13 +44,20 @@ 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()+");"); 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(); - 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); } } diff --git a/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java b/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java index c5f197b..a04b416 100755 --- a/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java +++ b/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java @@ -17,6 +17,14 @@ public class StructureTypeDescriptor extends TypeDescriptor { 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); } -- 2.34.1