public class CFGBuilder
extends java.lang.Object
CallInliner
implementationsModifier and Type | Method and Description |
---|---|
CFGBuilder |
assign()
Generate instructions to assign top stack value to the second stack value
(usually pushed via
pushForWrite(DfaVariableValue) ). |
CFGBuilder |
assign(DfaValue target,
DfType source)
Generate instructions to assign given source value to the given target value and leave the result on stack.
|
CFGBuilder |
assignAndPop(DfaValue target,
DfType source)
Generate instructions to assign given source value to the given target value.
|
CFGBuilder |
assignTo(DfaVariableValue var)
Generate instructions to assign top stack value to the specified variable
|
CFGBuilder |
assignTo(PsiVariable var)
Generate instructions to assign top stack value to the specified variable
|
CFGBuilder |
boxUnbox(PsiExpression expression,
PsiType expectedType)
Generate instructions to box or unbox stack top value if necessary to satisfy the specified expected type.
|
CFGBuilder |
boxUnbox(PsiExpression expression,
PsiType expressionType,
PsiType expectedType)
Generate instructions to box or unbox stack top value if necessary to satisfy the specified expected type.
|
CFGBuilder |
call(PsiMethodCallExpression call)
Generate instructions to perform a method call without inlining
|
CFGBuilder |
catchAll()
Start catch section; must be created after
doTry(PsiElement) section and finished with end() . |
CFGBuilder |
chain(java.util.function.Consumer<? super CFGBuilder> operation)
A convenient method to chain specific builder operation
|
DfaVariableValue |
createTempVariable(PsiType type)
Create a synthetic variable (not declared in the original code) to be used within this control flow.
|
CFGBuilder |
doThrow(PsiType exceptionType)
Adds instructions to throw an exception of given type
|
CFGBuilder |
doTry(PsiElement anchor)
Start try section.
|
CFGBuilder |
doWhileUnknown()
Generate instructions to start a loop.
|
CFGBuilder |
dup()
Generate instructions to duplicate top stack value
|
CFGBuilder |
elseBranch()
Generate instructions to finish a "then-branch" and start an "else-branch" of a conditional block started
with
ifCondition(IElementType) , ifConditionIs(boolean) , ifNull() or ifNotNull() . |
CFGBuilder |
end()
Generate instructions to finish a conditional block or a loop.
|
CFGBuilder |
evaluateFunction(PsiExpression functionalExpression)
Generate instructions to evaluate functional expression (but not invoke the function itself
-- see
invokeFunction(int, PsiExpression) ). |
CFGBuilder |
flush(DfaValue value)
Generate instruction to flush given value if it's variable.
|
CFGBuilder |
flushFields()
Generate instructions to flush known values of non-final fields of mutable classes.
|
DfaValueFactory |
getFactory()
Returns a
DfaValueFactory associated with current control flow. |
CFGBuilder |
ifCondition(IElementType relation)
Generate instructions to start a conditional block based on result of comparison of
two stack values with given relation (e.g.
|
CFGBuilder |
ifConditionIs(boolean value)
Generate instructions to start a conditional block based on stack top value, consuming this value
|
CFGBuilder |
ifNotNull()
Generate instructions to start a conditional block which is executed if top stack value is not null.
|
CFGBuilder |
ifNull()
Generate instructions to start a conditional block which is executed if top stack value is null.
|
CFGBuilder |
invokeFunction(int argCount,
PsiExpression functionalExpression)
Generates instructions to invoke functional expression (inlining it if possible) which
consumes given amount of stack arguments, assuming that it was previously evaluated
(see
evaluateFunction(PsiExpression) ). |
CFGBuilder |
invokeFunction(int argCount,
PsiExpression functionalExpression,
Nullability resultNullability)
Generates instructions to invoke functional expression (inlining it if possible) which
consumes given amount of stack arguments, assuming that it was previously evaluated
(see
evaluateFunction(PsiExpression) ). |
CFGBuilder |
isInstance(PsiExpression anchor,
PsiExpression operand,
PsiType castType)
Generate instructions to perform an instanceof operation
|
CFGBuilder |
isInstance(PsiMethodCallExpression anchor)
Generate instructions to perform an Class.isInstance operation
|
CFGBuilder |
loopOver(PsiExpression[] expressions,
DfaVariableValue targetVariable) |
CFGBuilder |
objectOf()
Generate instructions to replace class value on top of stack with the corresponding object value
|
CFGBuilder |
pop()
Generate instructions to pop single DfaValue from stack
|
CFGBuilder |
push(DfaValue value)
Generate instructions to push given DfaValue on stack.
|
CFGBuilder |
push(DfaValue value,
PsiExpression expression)
Generate instructions to push given DfaValue on stack and bind it to given expression.
|
CFGBuilder |
push(DfType value)
Generate instructions to push given DfType on stack.
|
CFGBuilder |
push(DfType value,
PsiExpression expression)
Generate instructions to push given DfType on stack and bind it to given expression.
|
CFGBuilder |
pushExpression(PsiExpression expression)
Generate instructions to evaluate given expression and push its result on stack.
|
CFGBuilder |
pushExpression(PsiExpression expression,
NullabilityProblemKind<? super PsiExpression> kind)
Generate instructions to evaluate given expression and push its result on stack
checking for custom nullability problem which cannot be found automatically from context.
|
CFGBuilder |
pushForWrite(DfaVariableValue variable)
Generate instructions to push given variable value on stack for subsequent write.
|
CFGBuilder |
pushNull()
Generate instructions to push null DfaValue on stack.
|
CFGBuilder |
pushUnknown()
Generate instructions to push unknown DfaValue on stack.
|
CFGBuilder |
resultOf(PsiExpression expression)
Generate instructions to bind top-of-stack value to the given expression.
|
CFGBuilder |
splice(int count,
int... replacement)
Generate instructions to pop given number of stack values, then push some or all of popped values referred by indices,
possibly duplicating them
|
CFGBuilder |
swap()
Generate instructions to swap two top stack values
|
boolean |
tryInlineLambda(int argCount,
PsiExpression functionalExpression,
Nullability resultNullability,
java.lang.Runnable pushArgs) |
CFGBuilder |
unwrap(SpecialField descriptor)
Generate instructions to load a special field value which qualifier is on the stack
|
public CFGBuilder pushUnknown()
Stack before: ...
Stack after: ... unknown
public CFGBuilder pushNull()
Stack before: ...
Stack after: ... null
public CFGBuilder pushExpression(PsiExpression expression)
Stack before: ...
Stack after: ... expression_result
expression
- expression to evaluatepublic CFGBuilder pushExpression(PsiExpression expression, NullabilityProblemKind<? super PsiExpression> kind)
Stack before: ...
Stack after: ... expression_result
expression
- expression to evaluatekind
- kind of nullability problem. Use NullabilityProblemKind.noProblem
to suppress automatically found problem.
Passing null
means no custom problem to register (just like pushExpression(PsiExpression)
).public CFGBuilder unwrap(SpecialField descriptor)
Stack before: ... qualifier
Stack after: ... loaded_field
descriptor
- a SpecialField
which describes a field to getpublic CFGBuilder pushForWrite(DfaVariableValue variable)
Stack before: ...
Stack after: ... variable
variable
- to pushpublic CFGBuilder push(DfaValue value)
Stack before: ...
Stack after: ... value
value
- value to pushpublic CFGBuilder push(DfaValue value, PsiExpression expression)
Stack before: ...
Stack after: ... value
value
- value to pushexpression
- expression which result is being pushedpublic CFGBuilder push(DfType value)
Stack before: ...
Stack after: ... value
value
- value to pushpublic CFGBuilder push(DfType value, PsiExpression expression)
Stack before: ...
Stack after: ... value
value
- value to pushexpression
- expression which result is being pushedpublic CFGBuilder pop()
Stack before: ... value
Stack after: ...
public CFGBuilder dup()
Stack before: ... value
Stack after: ... value value
public CFGBuilder splice(int count, int... replacement)
E.g. splice(2, 0, 1, 0)
will change "... val1 val2" stack to "... val2 val1 val2".
Stack depth is increased by replacement.length - count
.
count
- number of values to popreplacement
- replacement indices from 0 to count-1
. Index 0 = top stack value, index 1 = next value and so on.public CFGBuilder swap()
Stack before: ... val1 val2
Stack after: ... val2 val1
public CFGBuilder objectOf()
Stack before: ... class_value
Stack after: ... object_value
public CFGBuilder resultOf(PsiExpression expression)
expression
- expression to bind top-of-stack value topublic CFGBuilder isInstance(PsiMethodCallExpression anchor)
Stack before: ... object class_object
Stack after: ... result
anchor
- element to bind this instruction topublic CFGBuilder isInstance(PsiExpression anchor, PsiExpression operand, PsiType castType)
Stack before: ... object cast_type
Stack after: ... result
anchor
- element to bind this instruction tooperand
- operand expression (pushed before)castType
- cast type (pushed before)public CFGBuilder ifConditionIs(boolean value)
Stack before: ... condition
Stack after: ...
The conditional block must end with end()
and may contain one elseBranch()
inside.
Nested conditional blocks are acceptable.
value
- a value condition must have to visit conditional blockpublic CFGBuilder ifCondition(IElementType relation)
JavaTokenType.GT
), consuming these values.
Stack before: ... val1 val2
Stack after: ...
The conditional block must end with end()
and may contain one elseBranch()
inside.
Nested conditional blocks are acceptable.
relation
- a relation to use to compare two stack values. Conditional block will be executed if "val1 relation val2" is true.public CFGBuilder ifNotNull()
Stack before: ... value
Stack after: ...
The conditional block must end with end()
and may contain one elseBranch()
inside.
Nested conditional blocks are acceptable.
public CFGBuilder ifNull()
Stack before: ... value
Stack after: ...
The conditional block must end with end()
and may contain one elseBranch()
inside.
Nested conditional blocks are acceptable.
public CFGBuilder end()
public CFGBuilder elseBranch()
ifCondition(IElementType)
, ifConditionIs(boolean)
, ifNull()
or ifNotNull()
.
Stack is unchanged.public CFGBuilder doWhileUnknown()
end()
.
Nested loops are acceptable.public CFGBuilder boxUnbox(PsiExpression expression, PsiType expectedType)
Stack before: ... value
Stack after: ... boxed_or_unboxed_value
expression
- an expression which result is placed on the top of stackexpectedType
- an expected typepublic CFGBuilder boxUnbox(PsiExpression expression, PsiType expressionType, PsiType expectedType)
Stack before: ... value
Stack after: ... boxed_or_unboxed_value
expression
- an expression which is used to anchor instructions so issued warnings can point to this expressionexpressionType
- an actual type of the expression on top of stackexpectedType
- an expected typepublic CFGBuilder flushFields()
public CFGBuilder flush(DfaValue value)
value
- value to flushpublic CFGBuilder assign()
pushForWrite(DfaVariableValue)
).
Stack before: ... variable_for_write value
Stack after: ... variable
public CFGBuilder assignAndPop(DfaValue target, DfType source)
target
- target to writesource
- source valuepublic CFGBuilder assign(DfaValue target, DfType source)
Stack before: ...
Stack after: ... target
target
- target to writesource
- source valuepublic CFGBuilder doTry(PsiElement anchor)
anchor
- PSI anchor to handle nested trapspublic CFGBuilder catchAll()
doTry(PsiElement)
section and finished with end()
.public CFGBuilder doThrow(PsiType exceptionType)
exceptionType
- exception type to throwpublic CFGBuilder call(PsiMethodCallExpression call)
Stack before: ... qualifier arg1 ... argN
Stack after: ... method result
call
- call to addpublic CFGBuilder assignTo(PsiVariable var)
Stack before: ... value
Stack after: ... variable
public CFGBuilder assignTo(DfaVariableValue var)
Stack before: ... value
Stack after: ... variable
public DfaValueFactory getFactory()
DfaValueFactory
associated with current control flow.DfaValueFactory
associated with current control flow.public CFGBuilder evaluateFunction(PsiExpression functionalExpression)
invokeFunction(int, PsiExpression)
). Stack is unchanged.functionalExpression
- a functional expression to evaluatepublic CFGBuilder invokeFunction(int argCount, PsiExpression functionalExpression)
evaluateFunction(PsiExpression)
).argCount
- number of stack arguments to consumefunctionalExpression
- a functional expression to invokepublic CFGBuilder invokeFunction(int argCount, PsiExpression functionalExpression, Nullability resultNullability)
evaluateFunction(PsiExpression)
).argCount
- number of stack arguments to consumefunctionalExpression
- a functional expression to invokeresultNullability
- an expected nullability of the lambda resultpublic boolean tryInlineLambda(int argCount, PsiExpression functionalExpression, Nullability resultNullability, java.lang.Runnable pushArgs)
public CFGBuilder loopOver(PsiExpression[] expressions, DfaVariableValue targetVariable)
public DfaVariableValue createTempVariable(PsiType type)
type
- a type of variable to createpublic CFGBuilder chain(java.util.function.Consumer<? super CFGBuilder> operation)
operation
- to execute on this builder