KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > InsnMultiDimArrayNew


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27 import java.io.PrintStream JavaDoc;
28
29 /**
30  * Special instruction form for the opc_multianewarray instruction
31  */

32
33 public class InsnMultiDimArrayNew extends Insn {
34   /* The array class for creation */
35   private ConstClass classOp;
36
37   /* The number of dimensions present on the stack */
38   private int nDimsOp;
39
40   /* public accessors */
41
42   public boolean isSimpleLoad() {
43     return false;
44   }
45
46   public int nStackArgs() {
47     return nDimsOp;
48   }
49
50   public int nStackResults() {
51     return 1;
52   }
53
54   /**
55    * What are the types of the stack operands ?
56    */

57   public String JavaDoc argTypes() {
58     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
59     for (int i=0; i<nDimsOp; i++) {
60         buf.append("I");//NOI18N
61
}
62     return buf.toString();
63   }
64
65   /**
66    * What are the types of the stack results?
67    */

68   public String JavaDoc resultTypes() {
69       return "A";//NOI18N
70
}
71
72   public boolean branches() {
73     return false;
74   }
75
76   /**
77    * Return the array class being created
78    */

79   public ConstClass arrayClass() {
80     return classOp;
81   }
82
83   /**
84    * Sets the array class being created
85    */

86   public void setArrayClass(ConstClass classOp) {
87     this.classOp = classOp;
88   }
89
90   /**
91    * Return the number of dimensions of the array class being created
92    */

93   public int nDims() {
94     return nDimsOp;
95   }
96
97   /**
98    * Constructor for opc_multianewarray.
99    * classOp must be an array class
100    * nDimsOp must be > 0 and <= number of array dimensions for classOp
101    */

102   public InsnMultiDimArrayNew (ConstClass classOp, int nDimsOp) {
103     this(classOp, nDimsOp, NO_OFFSET);
104   }
105
106   /* package local methods */
107
108   InsnMultiDimArrayNew (ConstClass classOp, int nDimsOp, int offset) {
109     super(opc_multianewarray, offset);
110
111     this.classOp = classOp;
112     this.nDimsOp = nDimsOp;
113
114     if (classOp == null || nDimsOp < 1)
115     throw new InsnError ("attempt to create an opc_multianewarray" +//NOI18N
116
" with invalid operands");//NOI18N
117
}
118
119   
120
121   void print (PrintStream JavaDoc out, int indent) {
122     ClassPrint.spaces(out, indent);
123     out.println(offset() + " opc_multianewarray pool(" +//NOI18N
124
classOp.getIndex() + ")," + nDimsOp);//NOI18N
125
}
126
127   int store(byte[] buf, int index) {
128     buf[index++] = (byte) opcode();
129     index = storeShort(buf, index, (short) classOp.getIndex());
130     buf[index++] = (byte) nDimsOp;
131     return index;
132   }
133
134   int size() {
135     return 4;
136   }
137
138   static InsnMultiDimArrayNew read (InsnReadEnv insnEnv, int myPC) {
139     ConstClass classOp = (ConstClass)
140       insnEnv.pool().constantAt(insnEnv.getUShort());
141     int nDims = insnEnv.getUByte();
142     return new InsnMultiDimArrayNew(classOp, nDims, myPC);
143   }
144
145 }
146
Popular Tags