X-Git-Url: http://plrg.eecs.uci.edu/git/?p=repair.git;a=blobdiff_plain;f=Repair%2FRepairCompiler%2FMCC%2FIR%2FStructureTypeDescriptor.java;h=f7e19dcb49663b79c18bb89117044cc7232ada8a;hp=222c6c1134fcb4d9eeeb25fe19791d39f4d51fb0;hb=04f85f882f97b329b34d2a898454af2c6382ab0f;hpb=0092f02d48abd3603fa7c5115e8f5a63ada45f68 diff --git a/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java b/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java index 222c6c1..f7e19dc 100755 --- a/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java +++ b/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java @@ -16,6 +16,7 @@ public class StructureTypeDescriptor extends TypeDescriptor { Vector fieldlist = new Vector(); /* ordering information */ Hashtable labels = new Hashtable(); + public StructureTypeDescriptor(String name) { super(name); } @@ -34,7 +35,10 @@ public class StructureTypeDescriptor extends TypeDescriptor { } public Expr getOffsetExpr(FieldDescriptor field) { - + /* Fix sizeof calculations */ + if ((field==null)&&(subtype!=null)) + return subtype.getSizeExpr(); + boolean aligned=true; Expr size = new IntegerLiteralExpr(0); @@ -45,7 +49,6 @@ public class StructureTypeDescriptor extends TypeDescriptor { boolean ptr = fd.getPtr(); Expr basesize; if (ptr) { /* ptrs are 32bits */ - basesize = new IntegerLiteralExpr(32); } else { basesize = td.getSizeExpr(); @@ -75,7 +78,7 @@ public class StructureTypeDescriptor extends TypeDescriptor { } if (fd == field) { /* stop, reached target field */ - break; + break; } size = new OpExpr(Opcode.ADD, fieldsize, size); @@ -117,11 +120,11 @@ public class StructureTypeDescriptor extends TypeDescriptor { 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; } @@ -129,8 +132,30 @@ public class StructureTypeDescriptor extends TypeDescriptor { 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\");"); + } + }