01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.harmony.pack200.bytecode;
18:
19: import java.io.DataOutputStream;
20: import java.io.IOException;
21: import java.util.List;
22:
23: public abstract class BCIRenumberedAttribute extends Attribute {
24:
25: protected boolean renumbered = false;
26:
27: /* (non-Javadoc)
28: * @see org.apache.harmony.pack200.bytecode.Attribute#hasBCIRenumbering()
29: */
30: public boolean hasBCIRenumbering() {
31: return true;
32: }
33:
34: public BCIRenumberedAttribute(String attributeName) {
35: super (attributeName);
36: }
37:
38: protected abstract int getLength();
39:
40: protected abstract void writeBody(DataOutputStream dos)
41: throws IOException;
42:
43: public abstract String toString();
44:
45: protected abstract int[] getStartPCs();
46:
47: /**
48: * In Pack200, line number tables are BCI renumbered.
49: * This method takes the byteCodeOffsets (which is
50: * a List of Integers specifying the offset in the
51: * byte code array of each instruction) and updates the
52: * start_pcs so that it points to the instruction index
53: * itself, not the BCI renumbering of the instruction.
54: *
55: * @param byteCodeOffsets List of Integer offsets of the bytecode array
56: */
57: public void renumber(List byteCodeOffsets) {
58: if (renumbered) {
59: throw new Error(
60: "Trying to renumber a line number table that has already been renumbered");
61: }
62: renumbered = true;
63: int[] startPCs = getStartPCs();
64: for (int index = 0; index < startPCs.length; index++) {
65: startPCs[index] = ((Integer) byteCodeOffsets
66: .get(startPCs[index])).intValue();
67: }
68: }
69:
70: }
|