Class StackIndexHelper
java.lang.Object
eu.cloudnetservice.driver.util.asm.StackIndexHelper
A small helper class that helps keeping track of bytecode stack indices while pushing/loading from it.
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateStackIndexHelper(int initialVarIndex) Constructs a new stack index helper instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull StackIndexHelpercreate()Creates a new stack index helper which uses 0 as the initial index.static @NonNull StackIndexHelpercreate(int initialVarIndex) Constructs a new stack index helper with the given initial var index.Loads an element of the given type onto the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.Loads an element of the given type onto the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.Stores an element of the given type on the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.Stores an element of the given type on the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.skip(int depth) Skips the given amount of indices and uses the resulting value as the next var index to read/write from/to.skipNext()Skips the next (one) element of the current stack.
-
Field Details
-
nextVarIndex
private int nextVarIndex
-
-
Constructor Details
-
StackIndexHelper
private StackIndexHelper(int initialVarIndex) Constructs a new stack index helper instance.- Parameters:
initialVarIndex- the initial var index for the first element to load/store from/to the stack.
-
-
Method Details
-
create
Creates a new stack index helper which uses 0 as the initial index.- Returns:
- a stack index helper that uses 0 as the initial index.
-
create
Constructs a new stack index helper with the given initial var index.- Parameters:
initialVarIndex- the initial var index for the first element to load/store from/to the stack.- Returns:
- a stack index helper that uses the given initial var index.
-
skipNext
Skips the next (one) element of the current stack. This method implies that the next element has a size of one.- Returns:
- this index helper, for chaining.
-
skip
Skips the given amount of indices and uses the resulting value as the next var index to read/write from/to.- Parameters:
depth- the stack depth to skip.- Returns:
- this index helper, for chaining.
-
push
@NonNull public @NonNull StackIndexHelper push(@NonNull @NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull @NonNull Class<?> type) Stores an element of the given type on the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.- Parameters:
methodVisitor- the method visitor to notify about the store operation.type- the type to store on the stack.- Returns:
- this index helper, for chaining.
- Throws:
NullPointerException- if the given visitor or type is null.
-
push
@NonNull public @NonNull StackIndexHelper push(@NonNull @NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull @NonNull org.objectweb.asm.Type type) Stores an element of the given type on the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.- Parameters:
methodVisitor- the method visitor to notify about the store operation.type- the type to store on the stack.- Returns:
- this index helper, for chaining.
- Throws:
NullPointerException- if the given visitor or type is null.
-
load
@NonNull public @NonNull StackIndexHelper load(@NonNull @NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull @NonNull Class<?> type) Loads an element of the given type onto the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.- Parameters:
methodVisitor- the method visitor to notify about the load operation.type- the type to load from the stack.- Returns:
- this index helper, for chaining.
- Throws:
NullPointerException- if the given visitor or type is null.
-
load
@NonNull public @NonNull StackIndexHelper load(@NonNull @NonNull org.objectweb.asm.MethodVisitor methodVisitor, @NonNull @NonNull org.objectweb.asm.Type type) Loads an element of the given type onto the stack using the appropriate opcode based on the given type and skips to the next var index based on the size of the type.- Parameters:
methodVisitor- the method visitor to notify about the load operation.type- the type to load from the stack.- Returns:
- this index helper, for chaining.
- Throws:
NullPointerException- if the given visitor or type is null.
-