/* type var = [*(int *)] (base + offset) */
writer.outputline("int " + dest.getSafeSymbol()+"=0;");
writer.outputline("if ("+leftd.getSafeSymbol()+")");
+ writer.startblock();
writer.outputline(dest.getSafeSymbol() +
" = " + ptr + "(" + leftd.getSafeSymbol() + " + " + offset + ");");
- writer.outputline("else maybe=1;");
if (fd.getPtr()) {
+ writer.outputline("if ("+dest.getSafeSymbol()+")");
+ writer.startblock();
VarDescriptor typevar=VarDescriptor.makeNew("typechecks");
if (DOMEMCHECKS&&(!DOTYPECHECKS)) {
- writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+ writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
dotypecheck = true;
} else if (DOTYPECHECKS) {
- writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+ writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
}
writer.outputline("if (!"+typevar.getSafeSymbol()+")");
writer.startblock();
if (DONULL)
writer.outputline(ptr + "(" + leftd.getSafeSymbol() + " + " + offset + ")=0;");
writer.endblock();
+ writer.endblock();
}
+ writer.endblock();
+ writer.outputline("else maybe=1;");
}
} else { /* offset in bits is an expression that must be generated */
VarDescriptor ob = VarDescriptor.makeNew("offsetinbits");
/* type var = [*(int *)] (base + offset) */
writer.outputline("int " + dest.getSafeSymbol() +"=0;");
writer.outputline("if ("+leftd.getSafeSymbol()+")");
+ writer.startblock();
writer.outputline(dest.getSafeSymbol() +
" = " + ptr + "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ");");
- writer.outputline("else maybe=1;");
if (fd.getPtr()) {
+ writer.outputline("if ("+dest.getSafeSymbol()+")");
+ writer.startblock();
VarDescriptor typevar=VarDescriptor.makeNew("typechecks");
if (DOMEMCHECKS&&(!DOTYPECHECKS)) {
- writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+ writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
dotypecheck = true;
} else if (DOTYPECHECKS) {
- writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+ writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
}
writer.outputline("if (!"+typevar.getSafeSymbol()+")");
writer.startblock();
if (DONULL)
writer.outputline(ptr + "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ")=0;");
writer.endblock();
+ writer.endblock();
}
+ writer.endblock();
+ writer.outputline("else maybe=1;");
}
}
}
private void generatecalls() {
int max=TypeDescriptor.counter;
cr.outputline("int arsize["+max+"];");
+ cr.outputline("int arsizeBytes["+max+"];");
for(int i=0;i<max;i++) {
TypeDescriptor ttd=tdarray[i];
cr.outputline("return arsize[type];");
cr.outputline("}");
+ cr.outputline("int typeobject::sizeBytes(int type) {");
+ cr.outputline("return arsizeBytes[type];");
+ cr.outputline("}");
+
cr.outputline("int typeobject::numElements(int type, int fieldindex) {");
cr.outputline("return arnumelements[type][fieldindex];");
cr.outputline("}");
int max=TypeDescriptor.counter;
cr.outputline("void typeobject::computesizes("+rg.name+"_state * obj) {");
cr.outputline("obj->computesizes(arsize,arnumelements);");
+ cr.outputline("for(int i=0;i<"+max+";i++) {");
+ cr.outputline("int bits=arsize[i];");
+ cr.outputline("int bytes=bits>>3;");
+ cr.outputline("if (bits%8) bytes++;");
+ cr.outputline("arsizeBytes[i]=bytes;");
+ cr.outputline("}");
cr.outputline("}");
}
crhead.outputline("int isPtr(int type, int fieldindex);");
crhead.outputline("int numElements(int type, int fieldindex);");
crhead.outputline("int size(int type);");
+ crhead.outputline("int sizeBytes(int type);");
crhead.outputline("int getnumfields(int type);");
crhead.outputline("bool issubtype(int subtype, int type);");
crhead.outputline("void computesizes("+rg.name+"_state *);");