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.forms;
18:
19: import org.apache.harmony.pack200.Pack200Exception;
20: import org.apache.harmony.pack200.SegmentConstantPool;
21: import org.apache.harmony.pack200.bytecode.ByteCode;
22: import org.apache.harmony.pack200.bytecode.CPClass;
23: import org.apache.harmony.pack200.bytecode.ClassFileEntry;
24: import org.apache.harmony.pack200.bytecode.OperandManager;
25:
26: /**
27: * This class is an extension of the ClassRefForm. It
28: * has two purposes:
29: * 1. To keep track of the last type used in a new()
30: * instruction in the current class.
31: * 2. To allow the sender to create instances of either
32: * a specified class (which then becomes the new
33: * class) or the last used new class.
34: */
35: public class NewClassRefForm extends ClassRefForm {
36:
37: public NewClassRefForm(int opcode, String name, int[] rewrite) {
38: super (opcode, name, rewrite);
39: // TODO Auto-generated constructor stub
40: }
41:
42: /* (non-Javadoc)
43: * @see org.apache.harmony.pack200.bytecode.forms.ReferenceForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandManager)
44: */
45: public void setByteCodeOperands(ByteCode byteCode,
46: OperandManager operandManager, int codeLength) {
47: ClassFileEntry[] nested = null;
48: int offset = getOffset(operandManager);
49: if (offset == 0) {
50: // Use current class
51: SegmentConstantPool globalPool = operandManager
52: .globalConstantPool();
53: nested = new ClassFileEntry[] { globalPool
54: .getClassPoolEntry(operandManager.getCurrentClass()) };
55: byteCode.setNested(nested);
56: byteCode.setNestedPositions(new int[][] { { 0, 2 } });
57: } else {
58: // Look up the class in the classpool
59: try {
60: setNestedEntries(byteCode, operandManager, offset - 1);
61: } catch (Pack200Exception ex) {
62: throw new Error("Got a pack200 exception. What to do?");
63: }
64: }
65: operandManager.setNewClass(((CPClass) byteCode
66: .getNestedClassFileEntries()[0]).getName());
67: }
68: }
|