private static class Compiler.LogicalData
extends java.lang.Object
true
or false
) are assembled into bytecode
instructions, this object is consulted to determine whether the flow
of control should proceed normally to the next instruction, or whether
it should branch to another instruction, effectively bypassing sets of
instructions made irrelevant at runtime.
An instance of this class defines a trueTarget
, which is
the AST which logically represents the destination instruction in the
event the underlying logical test evaluates to true
. It
also defines a falseTarget
, which is the AST which
logically represents the destination instruction in the event the
underlying test evaluates to false
. Since branching
instructions which test a condition only allow a jump in one case or
the other (otherwise execution proceeds normally to the next
instruction in the bytecode array), only one target can be active.
The active target is defined by the trigger
flag. The
preprocess step of compilation does the hard work of determining how
to apply instances of this class to AST nodes appropriately, based
upon some basic rules of boolean algebra.
An extra
field exists to hold the data previously stored
in the extra
field of the associated AST. This is
necessary because we usurp that field in the AST to store an instance
of this class, but we do not want to lose the original data, which
is still needed after preprocessing the expression AST.
Finally, this class defines a topOfBranch
flag, which is
used to denote that the associated AST represents the highest level
logical operation in a chain. This may be the root of the entire
expression, or it may be the base of an AST branch which resolves to
a boolean value, but whose parent is not a logical operator (for
example, the parent could represent a method call which accepts a
boolean argument, but does not have a boolean return type). In either
case the topOfBranch
designation is used to determine
that an additional pair of instructions is necessary as the targets
of the top level AST: one that pushes a true
result onto
the runtime stack, and one that pushes a false
result
onto the stack. These then become the targets of the top level, logical
operation, since no other natural jump target exists.
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
extra
Data object originally stored in the extra field of an AST
|
private ExtraAst |
falseTarget
AST which defines the destination instruction for a false result
|
private boolean |
topOfBranch
Flag indicating AST represents top of chain of logical operations
|
private boolean |
trigger
Logical test result which will trigger a jump
|
private ExtraAst |
trueTarget
AST which defines the destination instruction for a true result
|
Constructor and Description |
---|
LogicalData(boolean trigger,
java.lang.Object extra)
Constructor which defines this object's trigger condition and stores
the "extra" data previously stored in this object's new host AST.
|
Modifier and Type | Method and Description |
---|---|
(package private) java.lang.Object |
getExtra()
Get the "extra" data previously associated with the underlying AST.
|
(package private) ExtraAst |
getFalseTarget()
Get the AST which represents this object's logical destination if
a
false result is achieved. |
(package private) ExtraAst |
getTarget()
Get the AST which represents the target to which the underlying
AST's compiled code will jump when the trigger result is produced.
|
(package private) boolean |
getTrigger()
Get the trigger condition for this object.
|
(package private) ExtraAst |
getTrueTarget()
Get the AST which represents this object's logical destination if
a
true result is achieved. |
(package private) boolean |
isTopOfBranch()
Report whether the underlying AST represents the base of a branch
of logical operations.
|
(package private) void |
setFalseTarget(ExtraAst falseTarget)
Set the AST which represents this object's logical destination if
a
false result is achieved. |
(package private) void |
setTopOfBranch(boolean topOfBranch)
Set whether the underlying AST represents the base of a branch
of logical operations.
|
(package private) void |
setTrueTarget(ExtraAst trueTarget)
Set the AST which represents this object's logical destination if
a
true result is achieved. |
java.lang.String |
toString()
Generate a string representation of this object for debugging
purposes.
|
private ExtraAst trueTarget
private ExtraAst falseTarget
private java.lang.Object extra
private boolean trigger
private boolean topOfBranch
LogicalData(boolean trigger, java.lang.Object extra)
trigger
- true
to jump to trueTarget
on a
true
result; false
to jump to
falseTarget
on a false
result.extra
- "Extra" data previously stored in this object's new host
AST.boolean getTrigger()
true
if we jump on true
;
false
if we jump on false
.boolean isTopOfBranch()
true
if AST is such a node, else
false
.void setTopOfBranch(boolean topOfBranch)
topOfBranch
- true
if AST is such a node, else
false
.java.lang.Object getExtra()
ExtraAst getTarget()
true
or
false
. The opposite result will cause execution to
proceed normally to the next instruction in the bytecode array
instead of causing a jump.trueTarget
defined for this object if
its trigger
is true
; else its
falseTarget
.ExtraAst getTrueTarget()
true
result is achieved. This transition represents
a branch only if trigger
is true
;
otherwise it represents normal, contiguous execution.true
result.void setTrueTarget(ExtraAst trueTarget)
true
result is achieved.trueTarget
- Target AST for a true
result.ExtraAst getFalseTarget()
false
result is achieved. This transition represents
a branch only if trigger
is false
;
otherwise it represents normal, contiguous execution.false
result.void setFalseTarget(ExtraAst falseTarget)
false
result is achieved.falseTarget
- Target AST for a false
result.public java.lang.String toString()
toString
in class java.lang.Object