public abstract class Instruction extends java.lang.Object implements net.covers1624.quack.util.Copyable<Instruction>
Created by covers1624 on 21/9/21.
| Modifier and Type | Field and Description |
|---|---|
InsnOpcode |
opcode |
| Modifier | Constructor and Description |
|---|---|
protected |
Instruction(InsnOpcode opcode) |
| Modifier and Type | Method and Description |
|---|---|
abstract <R,C> R |
accept(InsnVisitor<R,C> visitor,
C ctx)
Pass this
Instruction through the supplied InsnVisitor. |
<R> R |
accept(InsnVisitor<R,None> visitor)
Passes this
Instruction through the supplied InsnVisitor. |
void |
addRef()
Increments the reference count of this instruction.
|
<R extends Instruction> |
ancestorsOfType(InsnOpcode opcode)
Returns a filtered
FastStream of ancestors. |
protected EnumBitSet<InstructionFlag> |
computeFlags()
Called to compute the exposed flags exposed via
getFlags(). |
Instruction |
copy()
Deep copy this instruction.
|
<R extends Instruction> |
descendantsMatching(java.util.function.Function<Instruction,R> filter)
Returns a filtered
FastStream of descendants in post-order. |
<R extends Instruction> |
descendantsOfType(InsnOpcode opcode)
Returns a filtered
FastStream of descendants in post-order. |
<R extends Instruction> |
descendantsToList(InsnOpcode opcode)
Returns a
LinkedList of descendants in post-order. |
<R extends Instruction> |
descendantsToListWhere(java.util.function.Predicate<Instruction> filter)
Returns a
LinkedList of descendants in post-order. |
<R extends Instruction> |
descendantsWhere(java.util.function.Predicate<Instruction> filter)
Returns a filtered
FastStream of descendants in post-order. |
<R extends Instruction> |
firstAncestorOfType(InsnOpcode opcode)
Returns the first parent
Instruction with the provided InsnOpcode. |
int |
getBytecodeOffset()
Gets the offset of this instruction in bytecode.
|
net.covers1624.quack.collection.FastStream<Instruction> |
getChildren()
Gets a
FastStream containing this
Instructions children. |
net.covers1624.quack.collection.FastStream<Instruction> |
getDescendants()
Gets a
FastStream iterating all descendants
including this Instruction in post-order. |
abstract EnumBitSet<InstructionFlag> |
getDirectFlags()
Any direct flags for this
Instruction. |
Instruction |
getFirstChild()
This
Instructions first child instruction. |
@Nullable Instruction |
getFirstChildOrNull()
This
Instructions first child instruction. |
EnumBitSet<InstructionFlag> |
getFlags()
Gets the flags describing the behavior of this
Instruction. |
Instruction |
getLastChild()
This
Instructions last child instruction. |
@Nullable Instruction |
getLastChildOrNull()
This
Instructions last child instruction. |
Instruction |
getNextSibling()
This
Instructions next sibling instruction. |
@Nullable Instruction |
getNextSiblingOrNull()
This
Instructions next sibling instruction. |
Instruction |
getParent()
The
Instruction which this instruction is a child of. |
@Nullable Instruction |
getParentOrNull()
The
Instruction which this instruction is a child of. |
Instruction |
getPrevSibling()
This
Instructions previous sibling instruction. |
@Nullable Instruction |
getPrevSiblingOrNull()
This
Instructions previous sibling instruction. |
abstract AType |
getResultType()
Gets the stack type of the value produced by this
Instruction. |
int |
getSourceLine()
Gets the captured source line as represented by the LineNumberTable.
|
@Nullable InsnTag |
getTag()
An optional data tag for this instruction.
|
boolean |
hasDirectFlag(InstructionFlag flag)
Returns weather this instruction exposes this specific flag directly.
|
boolean |
hasFlag(InstructionFlag flag)
Returns weather this instruction exposes this specific flag either
directly, or from one of its children.
|
void |
insertAfter(Instruction value)
Inserts an
Instruction after this one inside an InstructionCollection. |
void |
insertBefore(Instruction value)
Inserts an
Instruction before this one inside an InstructionCollection. |
protected void |
invalidateFlags() |
boolean |
isConnected()
Used to check if this
Instruction has any references
and is connected to a tree. |
boolean |
isDescendantOf(@Nullable Instruction possibleAncestor)
Checks if this
Instruction or one of its parents
is possibleAncestor. |
protected void |
onChildModified() |
protected void |
onConnected() |
protected void |
onDisconnected() |
void |
releaseRef()
Decrements the reference count of this instruction.
|
void |
remove()
Removes this
Instruction from an InstructionCollection. |
<T extends Instruction> |
replaceWith(T value)
Replace this
Instruction in the tree with another Instruction. |
void |
setBytecodeOffset(int bytecodeOffset)
Set the offset for this instruction in bytecode.
|
void |
setOffsets(Instruction sourceInsn)
Sets the bytecode offset and tracked source line of this instruction
to that of the given instruction.
|
void |
setSourceLine(int sourceLine)
Sets the captured source line.
|
void |
setTag(@Nullable InsnTag tag)
Sets the optional data tag for this instruction.
|
java.lang.String |
toString() |
java.lang.String |
toString(DebugPrintOptions opts) |
<T extends Instruction> |
withOffsets(Instruction sourceInsn)
Sets the bytecode offset and tracked source line of this instruction
to that of the given instruction.
|
public final InsnOpcode opcode
protected Instruction(InsnOpcode opcode)
public abstract AType getResultType()
Instruction.AType.public Instruction copy()
This many not be supported by all instructions.
Implementors should use copy-constructor syntax.
copy in interface net.covers1624.quack.util.Copyable<Instruction>java.lang.UnsupportedOperationException - If this instruction does not support being copied.public abstract EnumBitSet<InstructionFlag> getDirectFlags()
Instruction.
The return value should be cached statically inside the Instruction impl.
EnumBitSet representing the flags.getFlags()public final EnumBitSet<InstructionFlag> getFlags()
Instruction.
This method wil compute the flags on-demand and caches the
result, until some changes the AST invalidate the cache.EnumBitSet representing the flags.getDirectFlags()public final boolean hasFlag(InstructionFlag flag)
flag - The flag to check.public final boolean hasDirectFlag(InstructionFlag flag)
flag - The flag to check.public abstract <R,C> R accept(InsnVisitor<R,C> visitor, C ctx)
Instruction through the supplied InsnVisitor.visitor - The InsnVisitor.ctx - The context.InsnVisitor.public final <R> R accept(InsnVisitor<R,None> visitor)
Instruction through the supplied InsnVisitor.
This method will assume the generic of None for the Context
generic provided by InsnVisitorvisitor - The InsnVisitor.InsnVisitor.@Nullable public final @Nullable Instruction getParentOrNull()
Instruction which this instruction is a child of.Instruction or nullgetParent()public final Instruction getParent()
Instruction which this instruction is a child of.Instruction.getParentOrNull()@Nullable public final @Nullable Instruction getNextSiblingOrNull()
Instructions next sibling instruction.Instruction or null.getNextSibling()public final Instruction getNextSibling()
Instructions next sibling instruction.Instruction.getNextSiblingOrNull()@Nullable public final @Nullable Instruction getPrevSiblingOrNull()
Instructions previous sibling instruction.Instruction or null.getPrevSibling()public final Instruction getPrevSibling()
Instructions previous sibling instruction.Instruction.getPrevSiblingOrNull()@Nullable public final @Nullable Instruction getFirstChildOrNull()
Instructions first child instruction.Instruction
or null if this instruction has no children.getFirstChild()public final Instruction getFirstChild()
Instructions first child instruction.Instruction.getFirstChildOrNull()@Nullable public final @Nullable Instruction getLastChildOrNull()
Instructions last child instruction.Instruction
or null if this instruction has no children.getLastChild()public final Instruction getLastChild()
Instructions last child instruction.Instruction.getLastChildOrNull()public final net.covers1624.quack.collection.FastStream<Instruction> getChildren()
FastStream containing this
Instructions children.FastStream.public final net.covers1624.quack.collection.FastStream<Instruction> getDescendants()
FastStream iterating all descendants
including this Instruction in post-order.FastStream.public final <R extends Instruction> net.covers1624.quack.collection.FastStream<R> descendantsOfType(InsnOpcode opcode)
FastStream of descendants in post-order.opcode - The InsnOpcode to filter by.FastStream.public final <R extends Instruction> net.covers1624.quack.collection.FastStream<R> descendantsWhere(java.util.function.Predicate<Instruction> filter)
FastStream of descendants in post-order.
This function is intended to be used by static matching methods.
filter - The filter to apply.FastStream.public final <R extends Instruction> net.covers1624.quack.collection.FastStream<R> descendantsMatching(java.util.function.Function<Instruction,R> filter)
FastStream of descendants in post-order.
This function is intended to be used by static matching methods which return
null to indicate a failed match.
filter - The filter to apply.FastStream.public final <R extends Instruction> java.util.LinkedList<R> descendantsToList(InsnOpcode opcode)
LinkedList of descendants in post-order.opcode - The InsnOpcode to filter by.LinkedList.public final <R extends Instruction> java.util.LinkedList<R> descendantsToListWhere(java.util.function.Predicate<Instruction> filter)
LinkedList of descendants in post-order.
This function is intended to be used by static matching methods.
filter - The filter to apply.LinkedList.public final <R extends Instruction> R firstAncestorOfType(InsnOpcode opcode)
Instruction with the provided InsnOpcode.opcode - The InsnOpcode to filter by.Instruction.public final <R extends Instruction> net.covers1624.quack.collection.FastStream<R> ancestorsOfType(InsnOpcode opcode)
FastStream of ancestors.opcode - The InsnOpcode to filter by.FastStream.public final boolean isDescendantOf(@Nullable
@Nullable Instruction possibleAncestor)
Instruction or one of its parents
is possibleAncestor.possibleAncestor - The ancestor to check against.Instruction is a descendant of possibleAncestor.public final void addRef()
This should generally not be directly used.
// TODO, document what a 'reference' ispublic final void releaseRef()
This should generally not be directly used.
addRef()public final boolean isConnected()
Instruction has any references
and is connected to a tree.Instruction is connected.public final void remove()
Instruction from an InstructionCollection.java.lang.UnsupportedOperationException - If this Instruction is not contained within a collection.public final void insertBefore(Instruction value)
Instruction before this one inside an InstructionCollection.value - The Instruction to insert.java.lang.UnsupportedOperationException - If this Instruction is not containpublic final void insertAfter(Instruction value)
Instruction after this one inside an InstructionCollection.value - The Instruction to insert.java.lang.UnsupportedOperationException - If this Instruction is not containpublic final <T extends Instruction> T replaceWith(T value)
Instruction in the tree with another Instruction.
This function will efficiently remove and unlink the instruction from wherever else it was in the tree prior if required.
value - The value to replace with.@Nullable public final @Nullable InsnTag getTag()
public final void setTag(@Nullable
@Nullable InsnTag tag)
tag - The data tag. null to clear.sjava.lang.IllegalStateException - If this Instruction already has a tag set.public final int getBytecodeOffset()
public final void setBytecodeOffset(int bytecodeOffset)
bytecodeOffset - The offset.public final <T extends Instruction> T withOffsets(Instruction sourceInsn)
sourceInsn - The source instruction to copy from.public final void setOffsets(Instruction sourceInsn)
sourceInsn - The source instruction to copy from.public final int getSourceLine()
public final void setSourceLine(int sourceLine)
sourceLine - The source line.public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toString(DebugPrintOptions opts)
protected void invalidateFlags()
@MustBeInvokedByOverriders protected void onConnected()
@MustBeInvokedByOverriders protected void onDisconnected()
protected void onChildModified()
protected EnumBitSet<InstructionFlag> computeFlags()
getFlags().