Class OperandStack
- java.lang.Object
-
- org.apache.bcel.verifier.structurals.OperandStack
-
- All Implemented Interfaces:
java.lang.Cloneable
public class OperandStack extends java.lang.Object implements java.lang.Cloneable
This class implements a stack used for symbolic JVM stack simulation. [It's used as an operand stack substitute.] Elements of this stack areTypeobjects.
-
-
Constructor Summary
Constructors Constructor Description OperandStack(int maxStack)Creates an empty stack with a maximum of maxStack slots.OperandStack(int maxStack, ObjectType obj)Creates an otherwise empty stack with a maximum of maxStack slots and the ObjectType 'obj' at the top.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the stack.java.lang.Objectclone()Returns a deep copy of this object; that means, the clone operates on a new stack.booleanequals(java.lang.Object o)Returns true if and only if this OperandStack equals another, meaning equal lengths and equal objects on the stacks.OperandStackgetClone()Returns a (typed!) clone of this.inthashCode()Gets the hash code.voidinitializeObject(UninitializedObjectType u)Replaces all occurrences of u in this OperandStack instance with an "initialized" ObjectType.booleanisEmpty()Returns true IFF this OperandStack is empty.intmaxStack()Returns the number of stack slots this stack can hold.voidmerge(OperandStack s)Merges another stack state into this instance's stack state.Typepeek()Returns the element on top of the stack.Typepeek(int depth)Returns the element that's i elements below the top element; that means, iff i==0 the top element is returned.Typepop()Returns the element on top of the stack.Typepop(int count)Pops i elements off the stack.voidpush(Type type)Pushes a Type object onto the stack.intsize()Returns the size of this OperandStack; that means, how many Type objects there are.intslotsUsed()Returns the number of stack slots used.java.lang.StringtoString()Returns a String representation of this OperandStack instance.
-
-
-
Constructor Detail
-
OperandStack
public OperandStack(int maxStack)
Creates an empty stack with a maximum of maxStack slots.- Parameters:
maxStack- The maximum stack size.
-
OperandStack
public OperandStack(int maxStack, ObjectType obj)
Creates an otherwise empty stack with a maximum of maxStack slots and the ObjectType 'obj' at the top.- Parameters:
maxStack- The maximum stack size.obj- The object type to place at the top.
-
-
Method Detail
-
clear
public void clear()
Clears the stack.
-
clone
public java.lang.Object clone()
Returns a deep copy of this object; that means, the clone operates on a new stack. However, the Type objects on the stack are shared.- Overrides:
clonein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
Returns true if and only if this OperandStack equals another, meaning equal lengths and equal objects on the stacks.- Overrides:
equalsin classjava.lang.Object
-
getClone
public OperandStack getClone()
Returns a (typed!) clone of this.- Returns:
- A clone of this operand stack.
- See Also:
clone()
-
hashCode
public int hashCode()
Gets the hash code.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A hash code value for the object.
-
initializeObject
public void initializeObject(UninitializedObjectType u)
Replaces all occurrences of u in this OperandStack instance with an "initialized" ObjectType.- Parameters:
u- The uninitialized object type.
-
isEmpty
public boolean isEmpty()
Returns true IFF this OperandStack is empty.- Returns:
- true if empty, false otherwise.
-
maxStack
public int maxStack()
Returns the number of stack slots this stack can hold.- Returns:
- The maximum stack size.
-
merge
public void merge(OperandStack s)
Merges another stack state into this instance's stack state. See the Java Virtual Machine Specification, Second Edition, page 146: 4.9.2 for details.- Parameters:
s- The stack to merge.
-
peek
public Type peek()
Returns the element on top of the stack. The element is not popped off the stack!- Returns:
- The top element.
-
peek
public Type peek(int depth)
Returns the element that's i elements below the top element; that means, iff i==0 the top element is returned. The element is not popped off the stack!- Parameters:
depth- The depth.- Returns:
- The element at the specified depth.
-
pop
public Type pop()
Returns the element on top of the stack. The element is popped off the stack.- Returns:
- The popped element.
-
pop
public Type pop(int count)
Pops i elements off the stack. Always returns null.- Parameters:
count- The number of elements to pop.- Returns:
- Always returns null.
-
push
public void push(Type type)
Pushes a Type object onto the stack.- Parameters:
type- The type to push.
-
size
public int size()
Returns the size of this OperandStack; that means, how many Type objects there are.- Returns:
- The stack size.
-
slotsUsed
public int slotsUsed()
Returns the number of stack slots used.- Returns:
- The number of slots used.
- See Also:
maxStack()
-
toString
public java.lang.String toString()
Returns a String representation of this OperandStack instance.- Overrides:
toStringin classjava.lang.Object- Returns:
- string representation.
-
-