Vector fieldlist = new Vector(); /* ordering information */
Hashtable labels = new Hashtable();
+
public StructureTypeDescriptor(String name) {
super(name);
}
}
public Expr getOffsetExpr(FieldDescriptor field) {
-
+ /* Fix sizeof calculations */
+ if ((field==null)&&(subtype!=null))
+ return subtype.getSizeExpr();
+
boolean aligned=true;
Expr size = new IntegerLiteralExpr(0);
boolean ptr = fd.getPtr();
Expr basesize;
if (ptr) { /* ptrs are 32bits */
-
basesize = new IntegerLiteralExpr(32);
} else {
basesize = td.getSizeExpr();
}
if (fd == field) { /* stop, reached target field */
- break;
+ break;
}
size = new OpExpr(Opcode.ADD, fieldsize, size);
labels.put(ld.getSymbol(), ld);
}
- public TypeDescriptor getSubType() {
+ public TypeDescriptor getSuperType() {
return subtype;
}
- public void setSubType(TypeDescriptor td) {
+ public void setSuperType(TypeDescriptor td) {
subtype = td;
}
if (td == this) {
return true;
} else {
+ if (subtype==null)
+ return false;
return subtype.isSubtypeOf(td);
}
}
+ public void generate_printout(CodeWriter cr, VarDescriptor vd) {
+ // #TBD#: does not support printing out fields that have variable size, substructures, etc
+
+ cr.outputline("printf(\"" + getSymbol() + " %p: \", " + vd.getSafeSymbol() + ");");
+ for (int i = 0; i < fieldlist.size(); i++) {
+ FieldDescriptor fd = (FieldDescriptor) fieldlist.elementAt(i);
+ cr.outputline("printf(\"\\n\\t" + fd.getSymbol() + " = \");");
+ if (fd.getPtr()) {
+ cr.outputline("printf(\"(" + fd.getType().getSymbol() + ") %p \", ((int *)" + vd.getSafeSymbol() + ")[" + i + "]);");
+ } else if ( fd.getType() instanceof ReservedTypeDescriptor) {
+ cr.outputline("printf(\"%d \", ((int *)" + vd.getSafeSymbol() + ")[" + i + "]);");
+ } else {
+ cr.outputline("printf(\"unsupported, breaking\");");
+ break;
+ }
+ }
+
+ cr.outputline("printf(\"\\n\");");
+ }
+
}