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 ");
import MCC.State;
import MCC.Compiler;
+import java.util.Iterator;
public class Sources {
State state;
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;");
+ }
+ }
+ }
}
}
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);
}
}