Class BinaryComparison
java.lang.Object
org.jfuncmachine.compiler.model.SourceElement
org.jfuncmachine.compiler.model.expr.bool.BooleanExpr
org.jfuncmachine.compiler.model.expr.bool.BinaryComparison
Represents a comparison of two expressions.
This class takes care of figuring out how to do the requested comparisons based on
the available instructions in the Java Virtual Machine. For example, to compare double values,
it has to use the dcmpl and dcmpg instructions in combination with ifeq, ifne, etc.
For integers, it can use if_icmpeq, if_icmpne, etc. It does any autoboxing necessary (if enabled), so
it can compare java.lang.Float values, for example. It has support for string comparisons, including
those that ignore case. It calls the appropriate compareTo or compareToIgnoreCase and then uses
ifeq, ifne, etc. to evaluate the comparison.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe expression to evaluate if the comparison is falseThe expression on the left side of the comparisonThe expression on the right side of the comparisonThe type of comparison to be done.The expression to evaluate if the comparison is trueFields inherited from class org.jfuncmachine.compiler.model.expr.bool.BooleanExpr
labelFields inherited from class org.jfuncmachine.compiler.model.SourceElement
filename, lineNumber -
Constructor Summary
ConstructorsConstructorDescriptionBinaryComparison(Test test, Expression left, Expression right) Create a new BinaryComparison with the given test, and left and right expressionsBinaryComparison(Test test, Expression left, Expression right, String filename, int lineNumber) Create a new BinaryComparison with the given test, and left and right expressions -
Method Summary
Modifier and TypeMethodDescriptioncomputeSequence(BooleanExpr trueNext, BooleanExpr falseNext, List<BooleanExpr> tests) Compute a sequence of tests to determine if this expression is true or falsevoidfindCaptured(Environment env) Identify any variables captured by the left and right hand expressionsvoidgenerate(ClassGenerator generator, Environment env, BooleanExpr next) Generate Java bytecode for this comparisoninvert()Invert this expression, which may involve reversing comparisons or changing and to or with inverted tests, etc.Remove any not expressions from a tree of boolean expressions by inverting the expression under the notvoidreset()Resets any values modified during code generationMethods inherited from class org.jfuncmachine.compiler.model.SourceElement
generateException
-
Field Details
-
test
The type of comparison to be done. -
left
The expression on the left side of the comparison -
right
The expression on the right side of the comparison -
truePath
The expression to evaluate if the comparison is true -
falsePath
The expression to evaluate if the comparison is false
-
-
Constructor Details
-
BinaryComparison
Create a new BinaryComparison with the given test, and left and right expressions- Parameters:
test- The test to performleft- The left-hand side of the comparisonright- The right-hand side of the comparison
-
BinaryComparison
public BinaryComparison(Test test, Expression left, Expression right, String filename, int lineNumber) Create a new BinaryComparison with the given test, and left and right expressions- Parameters:
test- The test to performleft- The left-hand side of the comparisonright- The right-hand side of the comparisonfilename- The source filename this expression is associated withlineNumber- The source line number this expression is associated with
-
-
Method Details
-
invert
Description copied from class:BooleanExprInvert this expression, which may involve reversing comparisons or changing and to or with inverted tests, etc.- Specified by:
invertin classBooleanExpr- Returns:
- An inverted boolean expression
-
removeNot
Description copied from class:BooleanExprRemove any not expressions from a tree of boolean expressions by inverting the expression under the not- Specified by:
removeNotin classBooleanExpr- Returns:
- a BooleanExpr with any nested Not constructions removed
-
reset
public void reset()Description copied from class:BooleanExprResets any values modified during code generation- Overrides:
resetin classBooleanExpr
-
computeSequence
public BooleanExpr computeSequence(BooleanExpr trueNext, BooleanExpr falseNext, List<BooleanExpr> tests) Description copied from class:BooleanExprCompute a sequence of tests to determine if this expression is true or false- Specified by:
computeSequencein classBooleanExpr- Parameters:
trueNext- The next expression to evaluate if this expression is truefalseNext- The next expression to evaluate if this expression is falsetests- An accumulator for the tests to be executed- Returns:
- The beginning of the sequence
-
findCaptured
Identify any variables captured by the left and right hand expressions- Parameters:
env- The environment chain to be searched
-
generate
Generate Java bytecode for this comparison- Parameters:
generator- The class generator that is generating the current classenv- The environment containing all visible variablesnext- The next boolean expr in the chain
-