Index: . =================================================================== --- . (revision 601279) +++ . (working copy) @@ -21,6 +21,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.List; import org.apache.harmony.pack200.bytecode.Attribute; import org.apache.harmony.pack200.bytecode.BCIRenumberedAttribute; @@ -26,7 +27,6 @@ import org.apache.harmony.pack200.bytecode.BCIRenumberedAttribute; import org.apache.harmony.pack200.bytecode.ByteCode; import org.apache.harmony.pack200.bytecode.CodeAttribute; -import org.apache.harmony.pack200.bytecode.LineNumberTableAttribute; import org.apache.harmony.pack200.bytecode.OperandManager; /** @@ -40,7 +40,7 @@ // The bands // TODO: Haven't resolved references yet. Do we want to? private int[] bcCaseCount; - private int[][] bcCaseValue; + private int[] bcCaseValue; private int[] bcByte; private int[] bcLocal; private int[] bcShort; @@ -126,6 +126,8 @@ AttributeLayout.CONTEXT_METHOD); methodByteCodePacked = new byte[classCount][][]; int bcParsed = 0; + + List switchIsTableSwitch = new ArrayList(); for (int c = 0; c < classCount; c++) { int numberOfMethods = methodFlags[c].length; methodByteCodePacked[c] = new byte[numberOfMethods][]; @@ -200,7 +202,12 @@ bcLabelCount++; break; case 170: // tableswitch + switchIsTableSwitch.add(new Boolean(true)); + bcCaseCountCount++; + bcLabelCount++; + break; case 171: // lookupswitch + switchIsTableSwitch.add(new Boolean(false)); bcCaseCountCount++; bcLabelCount++; break; @@ -299,7 +306,22 @@ // other bytecode bands debug("Parsed *bc_codes (" + bcParsed + ")"); bcCaseCount = decodeBandInt("bc_case_count", in, Codec.UNSIGNED5, bcCaseCountCount); - bcCaseValue = decodeBandInt("bc_case_value", in, Codec.DELTA5, bcCaseCount); + int bcCaseValueCount = 0; + for (int i = 0; i < bcCaseCount.length; i++) { + boolean isTableSwitch = ((Boolean)switchIsTableSwitch.get(i)).booleanValue(); + if(isTableSwitch) { + bcCaseValueCount += 1; + } else { + bcCaseValueCount += bcCaseCount[i]; + } + } + bcCaseValue = decodeBandInt("bc_case_value", in, Codec.DELTA5, bcCaseValueCount ); + // Every case value needs a label. We weren't able to count these + // above, because we didn't know how many cases there were. + // Have to correct it now. + for(int index=0; index < bcCaseCountCount; index++) { + bcLabelCount += bcCaseCount[index]; + } bcByte = decodeBandInt("bc_byte", in, Codec.BYTE1, bcByteCount); bcShort = decodeBandInt("bc_short", in, Codec.DELTA5, bcShortCount); bcLocal = decodeBandInt("bc_local", in, Codec.UNSIGNED5, bcLocalCount); @@ -337,10 +359,10 @@ bcEscSize = decodeBandInt("bc_escsize", in, Codec.UNSIGNED5, bcEscCount); bcEscByte = decodeBandInt("bc_escbyte", in, Codec.BYTE1, bcEscSize); - OperandManager operandManager = new OperandManager(bcByte, bcShort, - bcLocal, bcLabel, bcIntRef, bcFloatRef, bcLongRef, bcDoubleRef, - bcStringRef, bcClassRef, bcFieldRef, bcMethodRef, bcIMethodRef, - bcThisField, bcSuperField, bcThisMethod, bcSuperMethod, + OperandManager operandManager = new OperandManager(bcCaseCount, bcCaseValue, + bcByte, bcShort, bcLocal, bcLabel, bcIntRef, bcFloatRef, bcLongRef, + bcDoubleRef, bcStringRef, bcClassRef, bcFieldRef, bcMethodRef, + bcIMethodRef, bcThisField, bcSuperField, bcThisMethod, bcSuperMethod, bcInitRef); operandManager.setSegment(segment); @@ -373,7 +395,9 @@ // broken because these tables don't get renumbered // properly. Commenting out the add so the class files // will verify. - //attr.attributes.add(currentAttribute); + // if(currentAttribute.getClass() == LineNumberTableAttribute.class) { + attr.attributes.add(currentAttribute); + // } // Fix up the line numbers if needed if(currentAttribute.hasBCIRenumbering()) { ((BCIRenumberedAttribute)currentAttribute).renumber(attr.byteCodeOffsets); @@ -407,7 +431,7 @@ return bcCaseCount; } - public int[][] getBcCaseValue() { + public int[] getBcCaseValue() { return bcCaseValue; }