Package org.biojava.utils.bytecode
Class IfExpression
- java.lang.Object
-
- org.biojava.utils.bytecode.IfExpression
-
- All Implemented Interfaces:
CodeGenerator
public class IfExpression extends Object implements CodeGenerator
A CodeGenerator that provides something semanticaly identical to if.It generates code of the form:
conditional branch to trueLabel
ifFalse instructions here
branch to endLabel
trueLabel
ifTrue instructions here
endLabel- Author:
- Matthew Pocock
-
-
Constructor Summary
Constructors Constructor Description IfExpression(byte ifInstruction, CodeGenerator ifTrue, CodeGenerator ifFalse)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CodeGenerator
getIfFalse()
Instruction
getIfInstruction()
CodeGenerator
getIfTrue()
int
stackDelta()
Return the change in the stack dept this generator will cause.int
stackDepth()
Return the total depth of the stack required by this CodeGenerator.void
writeCode(CodeContext ctx)
Write the byte or bytes for this CodeGenerator to a CodeContext.
-
-
-
Constructor Detail
-
IfExpression
public IfExpression(byte ifInstruction, CodeGenerator ifTrue, CodeGenerator ifFalse)
-
-
Method Detail
-
getIfInstruction
public Instruction getIfInstruction()
-
getIfTrue
public CodeGenerator getIfTrue()
-
getIfFalse
public CodeGenerator getIfFalse()
-
writeCode
public void writeCode(CodeContext ctx) throws CodeException
Description copied from interface:CodeGenerator
Write the byte or bytes for this CodeGenerator to a CodeContext.- Specified by:
writeCode
in interfaceCodeGenerator
- Parameters:
ctx
- a CodeContext to write to- Throws:
CodeException
- if there was some failure in writing to the context
-
stackDepth
public int stackDepth()
Description copied from interface:CodeGenerator
Return the total depth of the stack required by this CodeGenerator.For single byte-code instructions, this will be the same as stackDelta() if stackDelta() is positive, zero otherwise. For a compound instruction, this will be the maximum stack depth required to execute all sub-instructions.
- Specified by:
stackDepth
in interfaceCodeGenerator
- Returns:
- the stack depth needed
-
stackDelta
public int stackDelta()
Description copied from interface:CodeGenerator
Return the change in the stack dept this generator will cause.In the case of an instruction that adds items to the stack, stackDelta will be positive. For instructions that removes items from the stack, this will be negative.
- Specified by:
stackDelta
in interfaceCodeGenerator
- Returns:
- the change between stack depth before and after execution of this code
-
-