Class ExpressionRecoverer
- java.lang.Object
-
- com.tonic.analysis.source.recovery.ExpressionRecoverer
-
public class ExpressionRecoverer extends Object
Converts SSA IR instructions to source Expression trees.
-
-
Constructor Summary
Constructors Constructor Description ExpressionRecoverer(RecoveryContext context)Creates a recoverer bound to a recovery context, with its own type recoverer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleaninliningWouldReorderEffects(SSAValue value)True when inlining a side-effecting definition at its use would move it past another side effect.booleanoperandInlinesSideEffect(Value value)True when recoveringvalueas an operand would inline an allocation or call - a side effect that must not be duplicated by re-emitting the expression.booleanoperandMayThrowInline(Value value)True when recoveringvalueas an operand would inline an operation that can throw at runtime.Expressionrecover(IRInstruction instr)Recovers the source expression an instruction produces.ExpressionrecoverConstant(Constant c, SourceType typeHint)Recovers a constant as a literal, using the hint to tell an int apart from a boolean or char.ExpressionrecoverOperand(Value value)Recovers an operand with no type hint, so booleans are inferred from the value alone.ExpressionrecoverOperand(Value value, SourceType typeHint)Recovers an operand, using the hint to tell a boolean from an int constant.booleanrenderingAtUseCrossesEffects(IRInstruction def, IRInstruction use)The same-block effect scan ofinliningWouldReorderEffects(com.tonic.analysis.ssa.value.SSAValue)without the single-use gate.
-
-
-
Constructor Detail
-
ExpressionRecoverer
public ExpressionRecoverer(RecoveryContext context)
Creates a recoverer bound to a recovery context, with its own type recoverer.- Parameters:
context- the per-method recovery state
-
-
Method Detail
-
recover
public Expression recover(IRInstruction instr)
Recovers the source expression an instruction produces.- Parameters:
instr- the instruction to translate- Returns:
- the expression, or null when the instruction has no expression form
-
recoverOperand
public Expression recoverOperand(Value value)
Recovers an operand with no type hint, so booleans are inferred from the value alone.- Parameters:
value- the operand to translate- Returns:
- the expression for the operand
-
recoverOperand
public Expression recoverOperand(Value value, SourceType typeHint)
Recovers an operand, using the hint to tell a boolean from an int constant.- Parameters:
value- the operand to translatetypeHint- the expected type, or null- Returns:
- the expression for the operand
-
inliningWouldReorderEffects
public boolean inliningWouldReorderEffects(SSAValue value)
True when inlining a side-effecting definition at its use would move it past another side effect.- Parameters:
value- the candidate for inlining, may be null- Returns:
- true if the value must take a name and stay where it is defined
-
renderingAtUseCrossesEffects
public boolean renderingAtUseCrossesEffects(IRInstruction def, IRInstruction use)
The same-block effect scan ofinliningWouldReorderEffects(com.tonic.analysis.ssa.value.SSAValue)without the single-use gate.- Parameters:
def- the defining instructionuse- the instruction the value would be rendered at- Returns:
- true if an unrelated effect sits between the two in the same block
-
operandInlinesSideEffect
public boolean operandInlinesSideEffect(Value value)
True when recoveringvalueas an operand would inline an allocation or call - a side effect that must not be duplicated by re-emitting the expression.- Parameters:
value- the operand to inspect- Returns:
- true if recovering it as an operand would inline an allocation or call
-
operandMayThrowInline
public boolean operandMayThrowInline(Value value)
True when recoveringvalueas an operand would inline an operation that can throw at runtime.- Parameters:
value- the operand to inspect- Returns:
- true if recovering it as an operand would inline an operation that can throw
-
recoverConstant
public Expression recoverConstant(Constant c, SourceType typeHint)
Recovers a constant as a literal, using the hint to tell an int apart from a boolean or char.- Parameters:
c- the constant to recovertypeHint- the expected source type, may be null- Returns:
- the literal expression, or a null literal for an unrecognized constant
-
-