V
- the type of the value objectspublic interface ValueStack<V>
extends java.lang.Iterable<V>
takeSnapshot()
and restoreSnapshot(Object)
()}, whose implementations should be
super efficient since they are being used extensively during a parsing run. A ValueStack also serves as an Iterable
over the current stack values (the values are being provided with the last value (on top of the stack) first).Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all values.
|
void |
dup()
Duplicates the top value.
|
boolean |
isEmpty()
Determines whether the stack is empty.
|
V |
peek()
Returns the value at the top of the stack without removing it.
|
V |
peek(int down)
Returns the value the given number of elements below the top of the stack without removing it.
|
void |
poke(int down,
V value)
Replaces the element the given number of elements below the current top of the stack.
|
void |
poke(V value)
Replaces the current top value with the given value.
|
V |
pop()
Removes the value at the top of the stack and returns it.
|
V |
pop(int down)
Removes the value the given number of elements below the top of the stack.
|
void |
push(int down,
V value)
Inserts the given value a given number of elements below the current top of the stack.
|
void |
push(V value)
Pushes the given value onto the stack.
|
void |
pushAll(java.lang.Iterable<V> values)
Pushes all given elements onto the stack (in the order as given).
|
void |
pushAll(V firstValue,
V... moreValues)
Pushes all given elements onto the stack (in the order as given).
|
void |
restoreSnapshot(java.lang.Object snapshot)
Restores the stack state as previously returned by
takeSnapshot() . |
int |
size()
Returns the number of elements currently on the stack.
|
void |
swap()
Swaps the top two stack values.
|
void |
swap3()
Reverses the order of the top 3 stack values.
|
void |
swap4()
Reverses the order of the top 4 stack values.
|
void |
swap5()
Reverses the order of the top 5 stack values.
|
void |
swap6()
Reverses the order of the top 5 stack values.
|
java.lang.Object |
takeSnapshot()
Returns an object representing the current state of the stack.
|
boolean isEmpty()
int size()
void clear()
java.lang.Object takeSnapshot()
void restoreSnapshot(java.lang.Object snapshot)
takeSnapshot()
.
This cost of running this operation is negligible and independent from the size of the stack.snapshot
- a snapshot object previously returned by takeSnapshot()
void push(V value)
value
- the valuevoid push(int down, V value)
down
- the number of elements to skip before inserting the value (0 being equivalent to push(value))value
- the valuejava.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationvoid pushAll(V firstValue, V... moreValues)
firstValue
- the first valuemoreValues
- the other valuesvoid pushAll(java.lang.Iterable<V> values)
values
- the valuesV pop()
java.lang.IllegalArgumentException
- if the stack is emptyV pop(int down)
down
- the number of elements to skip before removing the value (0 being equivalent to pop())java.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationV peek()
java.lang.IllegalArgumentException
- if the stack is emptyV peek(int down)
down
- the number of elements to skip (0 being equivalent to peek())java.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationvoid poke(V value)
value
- the valuejava.lang.IllegalArgumentException
- if the stack is emptyvoid poke(int down, V value)
down
- the number of elements to skip before replacing the value (0 being equivalent to poke(value))value
- the value to replace withjava.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationvoid dup()
java.lang.IllegalArgumentException
- if the stack is emptyvoid swap()
GrammarException
- if the stack does not contain at least two elementsvoid swap3()
GrammarException
- if the stack does not contain at least 3 elementsvoid swap4()
GrammarException
- if the stack does not contain at least 4 elementsvoid swap5()
GrammarException
- if the stack does not contain at least 5 elementsvoid swap6()
GrammarException
- if the stack does not contain at least 5 elements