KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 import java.io.PrintStream JavaDoc;
29
30 /**
31  * Special instruction form for the opc_iinc instruction
32  */

33
34 public class InsnIInc extends Insn {
35
36   /* The local variable slot to be incremented */
37   private int localVarIndex;
38
39   /* The amount by which the slot is to be incremented */
40   private int value;
41
42   /* public accessors */
43
44   public int nStackArgs() {
45     return 0;
46   }
47
48   public int nStackResults() {
49     return 0;
50   }
51
52   /**
53    * What are the types of the stack operands ?
54    */

55   public String JavaDoc argTypes() {
56       return "";//NOI18N
57
}
58
59   /**
60    * What are the types of the stack results?
61    */

62   public String JavaDoc resultTypes() {
63       return "";//NOI18N
64
}
65
66   public boolean branches() {
67     return false;
68   }
69
70   /**
71    * The local variable slot to be incremented
72    */

73   public int varIndex() {
74     return localVarIndex;
75   }
76
77   /**
78    * The amount by which the slot is to be incremented
79    */

80   public int incrValue() {
81     return value;
82   }
83   
84   /**
85    * Constructor for opc_iinc instruction
86    */

87   public InsnIInc (int localVarIndex, int value) {
88     this(localVarIndex, value, NO_OFFSET);
89   }
90
91   /* package local methods */
92
93   InsnIInc (int localVarIndex, int value, int pc) {
94     super(opc_iinc, pc);
95
96     this.localVarIndex = localVarIndex;
97     this.value =value;
98   }
99
100   void print (PrintStream JavaDoc out, int indent) {
101     ClassPrint.spaces(out, indent);
102     out.println(offset() + " opc_iinc " + //NOI18N
103
localVarIndex + "," + value);//NOI18N
104
}
105
106   int store(byte[] buf, int index) {
107     if (isWide())
108       buf[index++] = (byte) opc_wide;
109     buf[index++] = (byte) opcode();
110     if (isWide()) {
111       index = storeShort(buf, index, (short) localVarIndex);
112       index = storeShort(buf, index, (short) value);
113     } else {
114       buf[index++] = (byte)localVarIndex;
115       buf[index++] = (byte)value;
116     }
117     return index;
118   }
119
120   int size() {
121     return isWide() ? 6 : 3;
122   }
123
124   private boolean isWide() {
125     return (value > 127 || value < -128 || localVarIndex > 255);
126   }
127
128 }
129
Popular Tags