author | joehw |
Sun, 13 Aug 2017 21:10:40 -0700 | |
changeset 46174 | 5611d2529b49 |
parent 44797 | 8b3b3b911b8a |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
*/ |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
21 |
|
6 | 22 |
package com.sun.org.apache.bcel.internal.generic; |
23 |
||
46174 | 24 |
import java.io.DataOutputStream; |
25 |
import java.io.IOException; |
|
26 |
||
27 |
import com.sun.org.apache.bcel.internal.ExceptionConst; |
|
6 | 28 |
import com.sun.org.apache.bcel.internal.util.ByteSequence; |
29 |
||
30 |
/** |
|
31 |
* NEWARRAY - Create new array of basic type (int, short, ...) |
|
32 |
* <PRE>Stack: ..., count -> ..., arrayref</PRE> |
|
33 |
* type must be one of T_INT, T_SHORT, ... |
|
34 |
* |
|
46174 | 35 |
* @version $Id: NEWARRAY.java 1747278 2016-06-07 17:28:43Z britter $ |
6 | 36 |
*/ |
46174 | 37 |
public class NEWARRAY extends Instruction implements AllocationInstruction, ExceptionThrower, |
38 |
StackProducer { |
|
39 |
||
40 |
private byte type; |
|
41 |
||
6 | 42 |
|
46174 | 43 |
/** |
44 |
* Empty constructor needed for the Class.newInstance() statement in |
|
45 |
* Instruction.readInstruction(). Not to be used otherwise. |
|
46 |
*/ |
|
47 |
NEWARRAY() { |
|
48 |
} |
|
6 | 49 |
|
46174 | 50 |
|
51 |
public NEWARRAY(final byte type) { |
|
52 |
super(com.sun.org.apache.bcel.internal.Const.NEWARRAY, (short) 2); |
|
53 |
this.type = type; |
|
54 |
} |
|
55 |
||
6 | 56 |
|
46174 | 57 |
public NEWARRAY(final BasicType type) { |
58 |
this(type.getType()); |
|
59 |
} |
|
60 |
||
6 | 61 |
|
46174 | 62 |
/** |
63 |
* Dump instruction as byte code to stream out. |
|
64 |
* @param out Output stream |
|
65 |
*/ |
|
66 |
@Override |
|
67 |
public void dump( final DataOutputStream out ) throws IOException { |
|
68 |
out.writeByte(super.getOpcode()); |
|
69 |
out.writeByte(type); |
|
70 |
} |
|
6 | 71 |
|
46174 | 72 |
|
73 |
/** |
|
74 |
* @return numeric code for basic element type |
|
75 |
*/ |
|
76 |
public final byte getTypecode() { |
|
77 |
return type; |
|
78 |
} |
|
79 |
||
6 | 80 |
|
46174 | 81 |
/** |
82 |
* @return type of constructed array |
|
83 |
*/ |
|
84 |
public final Type getType() { |
|
85 |
return new ArrayType(BasicType.getType(type), 1); |
|
86 |
} |
|
87 |
||
88 |
||
89 |
/** |
|
90 |
* @return mnemonic for instruction |
|
91 |
*/ |
|
92 |
@Override |
|
93 |
public String toString( final boolean verbose ) { |
|
94 |
return super.toString(verbose) + " " + com.sun.org.apache.bcel.internal.Const.getTypeName(type); |
|
95 |
} |
|
96 |
||
97 |
||
98 |
/** |
|
99 |
* Read needed data (e.g. index) from file. |
|
100 |
*/ |
|
101 |
@Override |
|
102 |
protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException { |
|
103 |
type = bytes.readByte(); |
|
104 |
super.setLength(2); |
|
105 |
} |
|
6 | 106 |
|
46174 | 107 |
|
108 |
@Override |
|
109 |
public Class<?>[] getExceptions() { |
|
110 |
return new Class[] { |
|
111 |
ExceptionConst.NEGATIVE_ARRAY_SIZE_EXCEPTION |
|
112 |
}; |
|
113 |
} |
|
114 |
||
6 | 115 |
|
46174 | 116 |
/** |
117 |
* Call corresponding visitor method(s). The order is: |
|
118 |
* Call visitor methods of implemented interfaces first, then |
|
119 |
* call methods according to the class hierarchy in descending order, |
|
120 |
* i.e., the most specific visitXXX() call comes last. |
|
121 |
* |
|
122 |
* @param v Visitor object |
|
123 |
*/ |
|
124 |
@Override |
|
125 |
public void accept( final Visitor v ) { |
|
126 |
v.visitAllocationInstruction(this); |
|
127 |
v.visitExceptionThrower(this); |
|
128 |
v.visitStackProducer(this); |
|
129 |
v.visitNEWARRAY(this); |
|
130 |
} |
|
6 | 131 |
} |