1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.interpreter.operations;
11
12 import java.lang.reflect.Array;
13
14 import nl.tudelft.simulation.dsol.interpreter.LocalVariable;
15 import nl.tudelft.simulation.dsol.interpreter.OperandStack;
16 import nl.tudelft.simulation.dsol.interpreter.classfile.Constant;
17
18 /***
19 * The ARRAYLENGTH operation as defined in <a
20 * href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc.html">
21 * http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc.html
22 * </a>.
23 * <p>
24 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
25 * University of Technology </a>, the Netherlands. <br>
26 * See for project information <a
27 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
28 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
29 * License (GPL) </a>, no warranty <br>
30 *
31 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
32 * Jacobs </a><a
33 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
34 * Verbraeck </a>
35 * @version 1.3 Apr 6, 2004
36 * @since 1.4
37 */
38 public class ARRAYLENGTH extends VoidOperation
39 {
40 /*** OP refers to the operand code */
41 public static final int OP = 190;
42
43 /***
44 * constructs a new ARRAYLENGTH
45 */
46 public ARRAYLENGTH()
47 {
48 super();
49 }
50
51 /***
52 * @see nl.tudelft.simulation.dsol.interpreter.operations.VoidOperation
53 * #execute(nl.tudelft.simulation.dsol.interpreter.OperandStack,
54 * nl.tudelft.simulation.dsol.interpreter.classfile.Constant[],
55 * nl.tudelft.simulation.dsol.interpreter.LocalVariable[])
56 */
57 public void execute(final OperandStack stack,
58 final Constant[] constantPool, final LocalVariable[] localVariables)
59 {
60 Object arrayref = stack.pop();
61 stack.push(new Integer(Array.getLength(arrayref)));
62 }
63
64 /***
65 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getByteLength()
66 */
67 public int getByteLength()
68 {
69 return OPCODE_BYTE_LENGTH;
70 }
71
72 /***
73 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getOpcode()
74 */
75 public int getOpcode()
76 {
77 return ARRAYLENGTH.OP;
78 }
79 }