Class CFGTranslationPhaseOne
- java.lang.Object
-
- com.sun.source.util.TreeScanner<Node,java.lang.Void>
-
- org.checkerframework.dataflow.cfg.builder.CFGTranslationPhaseOne
-
- All Implemented Interfaces:
com.sun.source.tree.TreeVisitor<Node,java.lang.Void>
- Direct Known Subclasses:
CFCFGBuilder.CFCFGTranslationPhaseOne
public class CFGTranslationPhaseOne extends com.sun.source.util.TreeScanner<Node,java.lang.Void>
Class that performs phase one of the translation process. It generates the following information:- A sequence of extended nodes.
- A set of bindings from
Label
s to positions in the node sequence. - A set of leader nodes that give rise to basic blocks in phase two.
- A mapping from AST tree nodes to
Node
s.
The return type of this scanner is
Node
. For expressions, the corresponding node is returned to allow linking between different nodes.However, for statements there is usually no single
Node
that is created, and thus no node is returned (rather, null is returned).Every
visit*
method is assumed to add at least one extended node to the list of nodes (which might only be a jump).The entry point to process a single body (e.g., method) is
process(TreePath, UnderlyingAST)
.
-
-
Field Summary
Fields Modifier and Type Field Description protected AnnotationProvider
annotationProvider
The annotation provider, e.g., a type factory.protected javax.lang.model.type.TypeMirror
arithmeticExceptionType
The ArithmeticException type.protected javax.lang.model.type.TypeMirror
arrayIndexOutOfBoundsExceptionType
The ArrayIndexOutOfBoundsException type.protected javax.lang.model.type.TypeMirror
assertionErrorType
The AssertionError type.protected boolean
assumeAssertionsDisabled
Can assertions be assumed to be disabled?protected boolean
assumeAssertionsEnabled
Can assertions be assumed to be enabled?protected javax.lang.model.type.TypeMirror
classCastExceptionType
The ClassCastException type .protected @Nullable javax.lang.model.type.TypeMirror
classCircularityErrorType
The ClassCircularityError type.protected @Nullable javax.lang.model.type.TypeMirror
classFormatErrorType
The ClassFormatErrorType type.protected com.sun.source.tree.VariableTree
ea
TheVariableTree
that indicates whether assertions are enabled or not.protected javax.lang.model.util.Elements
elements
Element utilities.protected javax.annotation.processing.ProcessingEnvironment
env
Annotation processing environment.protected javax.lang.model.type.TypeMirror
iterableType
The Iterable type (erased).protected javax.lang.model.type.TypeMirror
negativeArraySizeExceptionType
The NegativeArraySizeException type.protected java.util.Set<javax.lang.model.type.TypeMirror>
newArrayExceptionTypes
Exceptions that can be thrown by array creation "new SomeType[]".protected @Nullable javax.lang.model.type.TypeMirror
noClassDefFoundErrorType
The NoClassDefFoundError type.protected javax.lang.model.type.TypeMirror
nullPointerExceptionType
The NullPointerException type .protected @Nullable javax.lang.model.type.TypeMirror
outOfMemoryErrorType
The OutOfMemoryError type.protected javax.lang.model.type.TypeMirror
stringType
The String type.protected javax.lang.model.type.TypeMirror
throwableType
The Throwable type.protected TreeBuilder
treeBuilder
TreeBuilder instance.protected com.sun.source.util.Trees
trees
Tree utilities.protected javax.lang.model.util.Types
types
Type utilities.protected long
uid
The UID for the next unique name.protected java.util.Set<javax.lang.model.type.TypeMirror>
uncheckedExceptionTypes
Supertypes of all unchecked exceptions.
-
Constructor Summary
Constructors Constructor Description CFGTranslationPhaseOne(TreeBuilder treeBuilder, AnnotationProvider annotationProvider, boolean assumeAssertionsEnabled, boolean assumeAssertionsDisabled, javax.annotation.processing.ProcessingEnvironment env)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addLabelForNextNode(Label l)
Add the labell
to the extended node that will be placed next in the sequence.protected void
addToConvertedLookupMap(com.sun.source.tree.Tree tree, Node node)
Add a node in the post-conversion lookup map.protected void
addToConvertedLookupMap(Node node)
Add a node in the post-conversion lookup map.protected void
addToLookupMap(Node node)
Add a node to the lookup map if it not already present.protected Node
assignConvert(Node node, javax.lang.model.type.TypeMirror varType)
Perform assignment conversion so that it can be assigned to a variable of the given type.protected boolean
assumeAssertionsEnabledFor(com.sun.source.tree.AssertTree tree)
Should assertions be assumed to be executed for a givenAssertTree
? False by default.protected Node
binaryNumericPromotion(Node node, javax.lang.model.type.TypeMirror exprType)
Perform binary numeric promotion on the input node to make it match the expression type.protected javax.lang.model.type.TypeMirror
binaryPromotedType(javax.lang.model.type.TypeMirror left, javax.lang.model.type.TypeMirror right)
Compute the type to which two numeric types must be promoted before performing a binary numeric operation on them.protected Node
box(Node node)
If the input node is an unboxed primitive type, insert a call to the appropriate valueOf method, otherwise leave it alone.protected Node
commonConvert(Node node, javax.lang.model.type.TypeMirror varType, boolean contextAllowsNarrowing)
Assignment conversion and method invocation conversion are almost identical, except that assignment conversion allows narrowing.protected Node
conditionalExprPromotion(Node node, javax.lang.model.type.TypeMirror destType)
Convert an operand of a conditional expression to the type of the whole expression.protected boolean
conversionRequiresNarrowing(javax.lang.model.type.TypeMirror varType, Node node)
Return whether a conversion from the type of the node to varType requires narrowing.protected java.util.List<Node>
convertCallArguments(javax.lang.model.element.ExecutableElement executable, javax.lang.model.type.ExecutableType executableType, java.util.List<? extends com.sun.source.tree.ExpressionTree> actualExprs, @Nullable com.sun.source.tree.NewClassTree newClassTree)
Given a method element, its type at the call site, and a list of argument expressions, return a list ofNode
s representing the arguments converted for a call of the method.protected com.sun.source.tree.VariableTree
createEnhancedForLoopArrayVariable(com.sun.source.tree.ExpressionTree expression, javax.lang.model.element.VariableElement variableElement)
protected com.sun.source.tree.VariableTree
createEnhancedForLoopIteratorVariable(com.sun.source.tree.MethodInvocationTree iteratorCall, javax.lang.model.element.VariableElement variableElement)
protected org.checkerframework.dataflow.cfg.builder.NodeWithExceptionsHolder
extendWithClassNameNode(ClassNameNode node)
Extend a list of extended nodes with a ClassName node.protected void
extendWithExtendedNode(ExtendedNode n)
Extend the list of extended nodes with an extended node.protected void
extendWithNode(Node node)
Extend the list of extended nodes with a node.protected org.checkerframework.dataflow.cfg.builder.NodeWithExceptionsHolder
extendWithNodeWithException(Node node, javax.lang.model.type.TypeMirror cause)
Extend the list of extended nodes with a node, wherenode
might throw the exceptioncause
.protected org.checkerframework.dataflow.cfg.builder.NodeWithExceptionsHolder
extendWithNodeWithExceptions(Node node, java.util.Set<javax.lang.model.type.TypeMirror> causes)
Extend the list of extended nodes with a node, wherenode
might throw any of the exceptions incauses
.protected com.sun.source.tree.VariableTree
getAssertionsEnabledVariable()
Get a syntheticVariableTree
that indicates whether assertions are enabled or not.com.sun.source.util.TreePath
getCurrentPath()
Returns the current path for the tree currently being scanned.protected @Nullable javax.lang.model.element.Name
getLabel(com.sun.source.util.TreePath path)
Returns the labelName
of the leaf in the argument path, or null if the leaf is not a labeled statement.protected javax.lang.model.type.TypeMirror
getTypeMirror(java.lang.Class<?> clazz)
Returns the TypeMirror for the given class.void
handleArtificialTree(com.sun.source.tree.Tree tree)
Perform any actions required when CFG translation creates a new Tree that is not part of the original AST.protected void
insertExtendedNodeAfter(ExtendedNode n, Node pred)
Insertn
after the nodepred
in the list of extended nodes, or appendn
ifpred
is not present.protected <T extends Node>
TinsertNodeAfter(T node, Node pred)
Insertnode
afterpred
in the list of extended nodes, or append to the list ifpred
is not present.protected org.checkerframework.dataflow.cfg.builder.NodeWithExceptionsHolder
insertNodeWithExceptionsAfter(Node node, java.util.Set<javax.lang.model.type.TypeMirror> causes, Node pred)
Insert anode
that might throw the exceptions incauses
afterpred
in the list of extended nodes, or append to the list ifpred
is not present.protected boolean
isNumericOrBoxed(javax.lang.model.type.TypeMirror type)
Returns true if the argument type is a numeric primitive or a boxed numeric primitive and false otherwise.protected @Nullable javax.lang.model.type.TypeMirror
maybeGetTypeMirror(java.lang.Class<?> clazz)
Returns the TypeMirror for the given class, ornull
if the type is not present.protected Node
methodInvocationConvert(Node node, javax.lang.model.type.TypeMirror formalType)
Perform method invocation conversion so that the node can be passed as a formal parameter of the given type.protected Node
narrow(Node node, javax.lang.model.type.TypeMirror destType)
Perform narrowing conversion on the input node to make it match the destination type.protected Node
narrowAndBox(Node node, javax.lang.model.type.TypeMirror destType)
Perform narrowing conversion and optionally boxing conversion on the input node to make it match the destination type.PhaseOneResult
process(com.sun.source.tree.CompilationUnitTree root, UnderlyingAST underlyingAST)
Process a single body withinroot
.PhaseOneResult
process(com.sun.source.util.TreePath bodyPath, UnderlyingAST underlyingAST)
Performs the actual work of phase one: processing a single body (of a method, lambda, top-level block, etc.).Node
scan(com.sun.source.tree.Tree tree, java.lang.Void p)
protected Node
stringConversion(Node node)
Convert the input node to String type, if it isn't already.protected void
translateAssertWithAssertionsEnabled(com.sun.source.tree.AssertTree tree)
Translates an assertion statement to the correct CFG nodes.protected AssignmentNode
translateAssignment(com.sun.source.tree.Tree tree, Node target, com.sun.source.tree.ExpressionTree rhs)
Translate an assignment.protected AssignmentNode
translateAssignment(com.sun.source.tree.Tree tree, Node target, Node expression)
Translate an assignment where the RHS has already been scanned.protected Node
unaryNumericPromotion(Node node)
Perform unary numeric promotion on the input node.protected Node
unbox(Node node)
If the input node is a boxed type, unbox it, otherwise leave it alone.protected java.lang.String
uniqueName(java.lang.String prefix)
Returns a unique name starting withprefix
.Node
visitAnnotatedType(com.sun.source.tree.AnnotatedTypeTree tree, java.lang.Void p)
Node
visitAnnotation(com.sun.source.tree.AnnotationTree tree, java.lang.Void p)
Node
visitArrayAccess(com.sun.source.tree.ArrayAccessTree tree, java.lang.Void p)
Node
visitArrayType(com.sun.source.tree.ArrayTypeTree tree, java.lang.Void p)
Node
visitAssert(com.sun.source.tree.AssertTree tree, java.lang.Void p)
Node
visitAssignment(com.sun.source.tree.AssignmentTree tree, java.lang.Void p)
Node
visitBinary(com.sun.source.tree.BinaryTree tree, java.lang.Void p)
Node
visitBindingPattern17(com.sun.source.tree.Tree bindingPatternTree, java.lang.Void p)
Visit a BindingPatternTreeNode
visitBlock(com.sun.source.tree.BlockTree tree, java.lang.Void p)
Node
visitBreak(com.sun.source.tree.BreakTree tree, java.lang.Void p)
Node
visitCase(com.sun.source.tree.CaseTree tree, java.lang.Void p)
Node
visitCatch(com.sun.source.tree.CatchTree tree, java.lang.Void p)
Node
visitClass(com.sun.source.tree.ClassTree tree, java.lang.Void p)
Node
visitCompilationUnit(com.sun.source.tree.CompilationUnitTree tree, java.lang.Void p)
Node
visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree tree, java.lang.Void p)
Node
visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree tree, java.lang.Void p)
Node
visitContinue(com.sun.source.tree.ContinueTree tree, java.lang.Void p)
Node
visitDeconstructionPattern21(com.sun.source.tree.Tree deconstructionPatternTree, java.lang.Void p)
Visit a DeconstructionPatternTree.Node
visitDoWhileLoop(com.sun.source.tree.DoWhileLoopTree tree, java.lang.Void p)
Node
visitEmptyStatement(com.sun.source.tree.EmptyStatementTree tree, java.lang.Void p)
Node
visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree tree, java.lang.Void p)
Node
visitErroneous(com.sun.source.tree.ErroneousTree tree, java.lang.Void p)
Node
visitExpressionStatement(com.sun.source.tree.ExpressionStatementTree tree, java.lang.Void p)
Node
visitForLoop(com.sun.source.tree.ForLoopTree tree, java.lang.Void p)
Node
visitIdentifier(com.sun.source.tree.IdentifierTree tree, java.lang.Void p)
Node
visitIf(com.sun.source.tree.IfTree tree, java.lang.Void p)
Node
visitImport(com.sun.source.tree.ImportTree tree, java.lang.Void p)
Node
visitInstanceOf(com.sun.source.tree.InstanceOfTree tree, java.lang.Void p)
Node
visitLabeledStatement(com.sun.source.tree.LabeledStatementTree tree, java.lang.Void p)
Node
visitLambdaExpression(com.sun.source.tree.LambdaExpressionTree tree, java.lang.Void p)
Node
visitLiteral(com.sun.source.tree.LiteralTree tree, java.lang.Void p)
Node
visitMemberReference(com.sun.source.tree.MemberReferenceTree tree, java.lang.Void p)
Node
visitMemberSelect(com.sun.source.tree.MemberSelectTree tree, java.lang.Void p)
Node
visitMethod(com.sun.source.tree.MethodTree tree, java.lang.Void p)
MethodInvocationNode
visitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, java.lang.Void p)
Node
visitModifiers(com.sun.source.tree.ModifiersTree tree, java.lang.Void p)
Node
visitNewArray(com.sun.source.tree.NewArrayTree tree, java.lang.Void p)
Node
visitNewClass(com.sun.source.tree.NewClassTree tree, java.lang.Void p)
Node
visitOther(com.sun.source.tree.Tree tree, java.lang.Void p)
Node
visitParameterizedType(com.sun.source.tree.ParameterizedTypeTree tree, java.lang.Void p)
Node
visitParenthesized(com.sun.source.tree.ParenthesizedTree tree, java.lang.Void p)
Node
visitPrimitiveType(com.sun.source.tree.PrimitiveTypeTree tree, java.lang.Void p)
Node
visitReturn(com.sun.source.tree.ReturnTree tree, java.lang.Void p)
Node
visitSwitch(com.sun.source.tree.SwitchTree tree, java.lang.Void p)
Node
visitSwitchExpression17(com.sun.source.tree.Tree switchExpressionTree, java.lang.Void p)
Visit a SwitchExpressionTreeNode
visitSynchronized(com.sun.source.tree.SynchronizedTree tree, java.lang.Void p)
Node
visitThrow(com.sun.source.tree.ThrowTree tree, java.lang.Void p)
Node
visitTry(com.sun.source.tree.TryTree tree, java.lang.Void p)
Node
visitTypeCast(com.sun.source.tree.TypeCastTree tree, java.lang.Void p)
Node
visitTypeParameter(com.sun.source.tree.TypeParameterTree tree, java.lang.Void p)
Node
visitUnary(com.sun.source.tree.UnaryTree tree, java.lang.Void p)
Node
visitUnionType(com.sun.source.tree.UnionTypeTree tree, java.lang.Void p)
Node
visitVariable(com.sun.source.tree.VariableTree tree, java.lang.Void p)
Node
visitWhileLoop(com.sun.source.tree.WhileLoopTree tree, java.lang.Void p)
Node
visitWildcard(com.sun.source.tree.WildcardTree tree, java.lang.Void p)
Node
visitYield17(com.sun.source.tree.Tree yieldTree, java.lang.Void p)
Visit a SwitchExpressionTree.protected Node
widen(Node node, javax.lang.model.type.TypeMirror destType)
Perform widening primitive conversion on the input node to make it match the destination type.protected com.sun.source.tree.Tree.Kind
withoutAssignment(com.sun.source.tree.Tree.Kind kind)
Map an operation with assignment to the corresponding operation without assignment.
-
-
-
Field Detail
-
env
protected final javax.annotation.processing.ProcessingEnvironment env
Annotation processing environment.
-
elements
protected final javax.lang.model.util.Elements elements
Element utilities.
-
types
protected final javax.lang.model.util.Types types
Type utilities.
-
trees
protected final com.sun.source.util.Trees trees
Tree utilities.
-
treeBuilder
protected final TreeBuilder treeBuilder
TreeBuilder instance.
-
annotationProvider
protected final AnnotationProvider annotationProvider
The annotation provider, e.g., a type factory.
-
assumeAssertionsDisabled
protected final boolean assumeAssertionsDisabled
Can assertions be assumed to be disabled?
-
assumeAssertionsEnabled
protected final boolean assumeAssertionsEnabled
Can assertions be assumed to be enabled?
-
arithmeticExceptionType
protected final javax.lang.model.type.TypeMirror arithmeticExceptionType
The ArithmeticException type.
-
arrayIndexOutOfBoundsExceptionType
protected final javax.lang.model.type.TypeMirror arrayIndexOutOfBoundsExceptionType
The ArrayIndexOutOfBoundsException type.
-
assertionErrorType
protected final javax.lang.model.type.TypeMirror assertionErrorType
The AssertionError type.
-
classCastExceptionType
protected final javax.lang.model.type.TypeMirror classCastExceptionType
The ClassCastException type .
-
iterableType
protected final javax.lang.model.type.TypeMirror iterableType
The Iterable type (erased).
-
negativeArraySizeExceptionType
protected final javax.lang.model.type.TypeMirror negativeArraySizeExceptionType
The NegativeArraySizeException type.
-
nullPointerExceptionType
protected final javax.lang.model.type.TypeMirror nullPointerExceptionType
The NullPointerException type .
-
outOfMemoryErrorType
protected final @Nullable javax.lang.model.type.TypeMirror outOfMemoryErrorType
The OutOfMemoryError type.
-
classCircularityErrorType
protected final @Nullable javax.lang.model.type.TypeMirror classCircularityErrorType
The ClassCircularityError type.
-
classFormatErrorType
protected final @Nullable javax.lang.model.type.TypeMirror classFormatErrorType
The ClassFormatErrorType type.
-
noClassDefFoundErrorType
protected final @Nullable javax.lang.model.type.TypeMirror noClassDefFoundErrorType
The NoClassDefFoundError type.
-
stringType
protected final javax.lang.model.type.TypeMirror stringType
The String type.
-
throwableType
protected final javax.lang.model.type.TypeMirror throwableType
The Throwable type.
-
uncheckedExceptionTypes
protected final java.util.Set<javax.lang.model.type.TypeMirror> uncheckedExceptionTypes
Supertypes of all unchecked exceptions. The size is 2 and the contents areRuntimeException
andError
.
-
newArrayExceptionTypes
protected final java.util.Set<javax.lang.model.type.TypeMirror> newArrayExceptionTypes
Exceptions that can be thrown by array creation "new SomeType[]". The size is 2 and the contents areNegativeArraySizeException
andOutOfMemoryError
. This list comes from JLS 15.10.1 "Run-Time Evaluation of Array Creation Expressions".
-
uid
protected long uid
The UID for the next unique name.
-
ea
protected com.sun.source.tree.VariableTree ea
TheVariableTree
that indicates whether assertions are enabled or not.
-
-
Constructor Detail
-
CFGTranslationPhaseOne
public CFGTranslationPhaseOne(TreeBuilder treeBuilder, AnnotationProvider annotationProvider, boolean assumeAssertionsEnabled, boolean assumeAssertionsDisabled, javax.annotation.processing.ProcessingEnvironment env)
- Parameters:
treeBuilder
- builder for new AST nodesannotationProvider
- extracts annotations from AST nodesassumeAssertionsDisabled
- can assertions be assumed to be disabled?assumeAssertionsEnabled
- can assertions be assumed to be enabled?env
- annotation processing environment containing type utilities
-
-
Method Detail
-
process
public PhaseOneResult process(com.sun.source.util.TreePath bodyPath, UnderlyingAST underlyingAST)
Performs the actual work of phase one: processing a single body (of a method, lambda, top-level block, etc.).- Parameters:
bodyPath
- path to the body of the underlying AST's methodunderlyingAST
- the AST for which the CFG is to be built- Returns:
- the result of phase one
-
process
public PhaseOneResult process(com.sun.source.tree.CompilationUnitTree root, UnderlyingAST underlyingAST)
Process a single body withinroot
. This method does not process the entire given CompilationUnitTree. Rather, it processes one body (of a method/lambda/etc.) within it, which corresponds tounderlyingAST
.- Parameters:
root
- the compilation unitunderlyingAST
- the AST corresponding to the body to process- Returns:
- a PhaseOneResult
-
handleArtificialTree
public void handleArtificialTree(com.sun.source.tree.Tree tree)
Perform any actions required when CFG translation creates a new Tree that is not part of the original AST.- Parameters:
tree
- the newly created Tree
-
getCurrentPath
public com.sun.source.util.TreePath getCurrentPath()
Returns the current path for the tree currently being scanned.- Returns:
- the current path
-
scan
public Node scan(com.sun.source.tree.Tree tree, java.lang.Void p)
- Overrides:
scan
in classcom.sun.source.util.TreeScanner<Node,java.lang.Void>
-
visitYield17
public Node visitYield17(com.sun.source.tree.Tree yieldTree, java.lang.Void p)
Visit a SwitchExpressionTree.- Parameters:
yieldTree
- a YieldTree, typed as Tree to be backward-compatiblep
- parameter- Returns:
- the result of visiting the switch expression tree
-
visitSwitchExpression17
public Node visitSwitchExpression17(com.sun.source.tree.Tree switchExpressionTree, java.lang.Void p)
Visit a SwitchExpressionTree- Parameters:
switchExpressionTree
- a SwitchExpressionTree, typed as Tree to be backward-compatiblep
- parameter- Returns:
- the result of visiting the switch expression tree
-
visitBindingPattern17
public Node visitBindingPattern17(com.sun.source.tree.Tree bindingPatternTree, java.lang.Void p)
Visit a BindingPatternTree- Parameters:
bindingPatternTree
- a BindingPatternTree, typed as Tree to be backward-compatiblep
- parameter- Returns:
- the result of visiting the binding pattern tree
-
visitDeconstructionPattern21
public Node visitDeconstructionPattern21(com.sun.source.tree.Tree deconstructionPatternTree, java.lang.Void p)
Visit a DeconstructionPatternTree.- Parameters:
deconstructionPatternTree
- a DeconstructionPatternTree, typed as Tree so the Checker Framework compiles under JDK 20 and earlierp
- an unused parameter- Returns:
- the result of visiting the tree
-
addToLookupMap
protected void addToLookupMap(Node node)
Add a node to the lookup map if it not already present.- Parameters:
node
- the node to add to the lookup map
-
addToConvertedLookupMap
protected void addToConvertedLookupMap(Node node)
Add a node in the post-conversion lookup map. The node should refer to a Tree and that Tree should already be in the pre-conversion lookup map. This method is used to update the Tree-Node mapping with conversion nodes.- Parameters:
node
- the node to add to the lookup map
-
addToConvertedLookupMap
protected void addToConvertedLookupMap(com.sun.source.tree.Tree tree, Node node)
Add a node in the post-conversion lookup map. The tree argument should already be in the pre-conversion lookup map. This method is used to update the Tree-Node mapping with conversion nodes.- Parameters:
tree
- the tree used as a key in the mapnode
- the node to add to the lookup map
-
extendWithNode
protected void extendWithNode(Node node)
Extend the list of extended nodes with a node.- Parameters:
node
- the node to add
-
extendWithNodeWithException
protected org.checkerframework.dataflow.cfg.builder.NodeWithExceptionsHolder extendWithNodeWithException(Node node, javax.lang.model.type.TypeMirror cause)
Extend the list of extended nodes with a node, wherenode
might throw the exceptioncause
.- Parameters:
node
- the node to addcause
- an exception that the node might throw- Returns:
- the node holder
-
extendWithNodeWithExceptions
protected org.checkerframework.dataflow.cfg.builder.NodeWithExceptionsHolder extendWithNodeWithExceptions(Node node, java.util.Set<javax.lang.model.type.TypeMirror> causes)
Extend the list of extended nodes with a node, wherenode
might throw any of the exceptions incauses
.- Parameters:
node
- the node to addcauses
- set of exceptions that the node might throw- Returns:
- the node holder
-
extendWithClassNameNode
protected org.checkerframework.dataflow.cfg.builder.NodeWithExceptionsHolder extendWithClassNameNode(ClassNameNode node)
Extend a list of extended nodes with a ClassName node.Evaluating a class literal kicks off class loading (JLS 15.8.2) which can fail and throw one of the specified subclasses of a LinkageError or an OutOfMemoryError (JLS 12.2.1).
- Parameters:
node
- the ClassName node to add- Returns:
- the node holder
-
insertNodeAfter
protected <T extends Node> T insertNodeAfter(T node, Node pred)
Insertnode
afterpred
in the list of extended nodes, or append to the list ifpred
is not present.- Parameters:
node
- the node to addpred
- the desired predecessor of node- Returns:
- the node holder
-
insertNodeWithExceptionsAfter
protected org.checkerframework.dataflow.cfg.builder.NodeWithExceptionsHolder insertNodeWithExceptionsAfter(Node node, java.util.Set<javax.lang.model.type.TypeMirror> causes, Node pred)
Insert anode
that might throw the exceptions incauses
afterpred
in the list of extended nodes, or append to the list ifpred
is not present.- Parameters:
node
- the node to addcauses
- set of exceptions that the node might throwpred
- the desired predecessor of node- Returns:
- the node holder
-
extendWithExtendedNode
protected void extendWithExtendedNode(ExtendedNode n)
Extend the list of extended nodes with an extended node.- Parameters:
n
- the extended node
-
insertExtendedNodeAfter
protected void insertExtendedNodeAfter(ExtendedNode n, @FindDistinct Node pred)
Insertn
after the nodepred
in the list of extended nodes, or appendn
ifpred
is not present.- Parameters:
n
- the extended nodepred
- the desired predecessor
-
addLabelForNextNode
protected void addLabelForNextNode(Label l)
Add the labell
to the extended node that will be placed next in the sequence.- Parameters:
l
- the node to add to the forthcoming extended node
-
uniqueName
protected java.lang.String uniqueName(java.lang.String prefix)
Returns a unique name starting withprefix
.- Parameters:
prefix
- the prefix of the unique name- Returns:
- a unique name starting with
prefix
-
box
protected Node box(Node node)
If the input node is an unboxed primitive type, insert a call to the appropriate valueOf method, otherwise leave it alone.- Parameters:
node
- in input node- Returns:
- a Node representing the boxed version of the input, which may simply be the input node
-
unbox
protected Node unbox(Node node)
If the input node is a boxed type, unbox it, otherwise leave it alone.- Parameters:
node
- in input node- Returns:
- a Node representing the unboxed version of the input, which may simply be the input node
-
stringConversion
protected Node stringConversion(Node node)
Convert the input node to String type, if it isn't already.- Parameters:
node
- an input node- Returns:
- a Node with the value promoted to String, which may be the input node
-
unaryNumericPromotion
protected Node unaryNumericPromotion(Node node)
Perform unary numeric promotion on the input node.- Parameters:
node
- a node producing a value of numeric primitive or boxed type- Returns:
- a Node with the value promoted to the int, long, float, or double; may return be the input node
-
isNumericOrBoxed
protected boolean isNumericOrBoxed(javax.lang.model.type.TypeMirror type)
Returns true if the argument type is a numeric primitive or a boxed numeric primitive and false otherwise.
-
binaryPromotedType
protected javax.lang.model.type.TypeMirror binaryPromotedType(javax.lang.model.type.TypeMirror left, javax.lang.model.type.TypeMirror right)
Compute the type to which two numeric types must be promoted before performing a binary numeric operation on them. The input types must both be numeric and the output type is primitive.- Parameters:
left
- the type of the left operandright
- the type of the right operand- Returns:
- a TypeMirror representing the binary numeric promoted type
-
binaryNumericPromotion
protected Node binaryNumericPromotion(Node node, javax.lang.model.type.TypeMirror exprType)
Perform binary numeric promotion on the input node to make it match the expression type.- Parameters:
node
- a node producing a value of numeric primitive or boxed typeexprType
- the type to promote the value to- Returns:
- a Node with the value promoted to the exprType, which may be the input node
-
widen
protected Node widen(Node node, javax.lang.model.type.TypeMirror destType)
Perform widening primitive conversion on the input node to make it match the destination type.- Parameters:
node
- a node producing a value of numeric primitive typedestType
- the type to widen the value to- Returns:
- a Node with the value widened to the exprType, which may be the input node
-
narrow
protected Node narrow(Node node, javax.lang.model.type.TypeMirror destType)
Perform narrowing conversion on the input node to make it match the destination type.- Parameters:
node
- a node producing a value of numeric primitive typedestType
- the type to narrow the value to- Returns:
- a Node with the value narrowed to the exprType, which may be the input node
-
narrowAndBox
protected Node narrowAndBox(Node node, javax.lang.model.type.TypeMirror destType)
Perform narrowing conversion and optionally boxing conversion on the input node to make it match the destination type.- Parameters:
node
- a node producing a value of numeric primitive typedestType
- the type to narrow the value to (possibly boxed)- Returns:
- a Node with the value narrowed and boxed to the destType, which may be the input node
-
conversionRequiresNarrowing
protected boolean conversionRequiresNarrowing(javax.lang.model.type.TypeMirror varType, Node node)
Return whether a conversion from the type of the node to varType requires narrowing.- Parameters:
varType
- the type of a variable (or general LHS) to be converted tonode
- a node whose value is being converted- Returns:
- whether this conversion requires narrowing to succeed
-
commonConvert
protected Node commonConvert(Node node, javax.lang.model.type.TypeMirror varType, boolean contextAllowsNarrowing)
Assignment conversion and method invocation conversion are almost identical, except that assignment conversion allows narrowing. We factor out the common logic here.- Parameters:
node
- a Node producing a valuevarType
- the type of a variablecontextAllowsNarrowing
- whether to allow narrowing (for assignment conversion) or not (for method invocation conversion)- Returns:
- a Node with the value converted to the type of the variable, which may be the input node itself
-
assignConvert
protected Node assignConvert(Node node, javax.lang.model.type.TypeMirror varType)
Perform assignment conversion so that it can be assigned to a variable of the given type.- Parameters:
node
- a Node producing a valuevarType
- the type of a variable- Returns:
- a Node with the value converted to the type of the variable, which may be the input node itself
-
methodInvocationConvert
protected Node methodInvocationConvert(Node node, javax.lang.model.type.TypeMirror formalType)
Perform method invocation conversion so that the node can be passed as a formal parameter of the given type.- Parameters:
node
- a Node producing a valueformalType
- the type of a formal parameter- Returns:
- a Node with the value converted to the type of the formal, which may be the input node itself
-
convertCallArguments
protected java.util.List<Node> convertCallArguments(javax.lang.model.element.ExecutableElement executable, javax.lang.model.type.ExecutableType executableType, java.util.List<? extends com.sun.source.tree.ExpressionTree> actualExprs, @Nullable com.sun.source.tree.NewClassTree newClassTree)
Given a method element, its type at the call site, and a list of argument expressions, return a list ofNode
s representing the arguments converted for a call of the method. This method applies to both method invocations and constructor calls. The argument of newClassTree is null when we visitMethodInvocationTree
, and is non-null when we visitNewClassTree
.- Parameters:
executable
- an ExecutableElement representing a method/constructor to be calledexecutableType
- an ExecutableType representing the type of the method/constructor call; the type must be viewpoint-adapted to the callactualExprs
- a List of argument expressions to a callnewClassTree
- the NewClassTree if the method is the invocation of a constructor- Returns:
- a List of
Node
s representing arguments after conversions required by a call to this method
-
conditionalExprPromotion
protected Node conditionalExprPromotion(Node node, javax.lang.model.type.TypeMirror destType)
Convert an operand of a conditional expression to the type of the whole expression.- Parameters:
node
- a node occurring as the second or third operand of a conditional expressiondestType
- the type to promote the value to- Returns:
- a Node with the value promoted to the destType, which may be the input node
-
getLabel
protected @Nullable javax.lang.model.element.Name getLabel(com.sun.source.util.TreePath path)
Returns the labelName
of the leaf in the argument path, or null if the leaf is not a labeled statement.
-
visitAnnotatedType
public Node visitAnnotatedType(com.sun.source.tree.AnnotatedTypeTree tree, java.lang.Void p)
-
visitAnnotation
public Node visitAnnotation(com.sun.source.tree.AnnotationTree tree, java.lang.Void p)
-
visitMethodInvocation
public MethodInvocationNode visitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, java.lang.Void p)
-
visitAssert
public Node visitAssert(com.sun.source.tree.AssertTree tree, java.lang.Void p)
-
assumeAssertionsEnabledFor
protected boolean assumeAssertionsEnabledFor(com.sun.source.tree.AssertTree tree)
Should assertions be assumed to be executed for a givenAssertTree
? False by default.
-
getAssertionsEnabledVariable
protected com.sun.source.tree.VariableTree getAssertionsEnabledVariable()
Get a syntheticVariableTree
that indicates whether assertions are enabled or not.
-
translateAssertWithAssertionsEnabled
protected void translateAssertWithAssertionsEnabled(com.sun.source.tree.AssertTree tree)
Translates an assertion statement to the correct CFG nodes. The translation assumes that assertions are enabled.
-
visitAssignment
public Node visitAssignment(com.sun.source.tree.AssignmentTree tree, java.lang.Void p)
-
translateAssignment
protected AssignmentNode translateAssignment(com.sun.source.tree.Tree tree, Node target, com.sun.source.tree.ExpressionTree rhs)
Translate an assignment.
-
translateAssignment
protected AssignmentNode translateAssignment(com.sun.source.tree.Tree tree, Node target, Node expression)
Translate an assignment where the RHS has already been scanned.
-
withoutAssignment
protected com.sun.source.tree.Tree.Kind withoutAssignment(com.sun.source.tree.Tree.Kind kind)
Map an operation with assignment to the corresponding operation without assignment.- Parameters:
kind
- a Tree.Kind representing an operation with assignment- Returns:
- the Tree.Kind for the same operation without assignment
-
visitCompoundAssignment
public Node visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree tree, java.lang.Void p)
-
visitBinary
public Node visitBinary(com.sun.source.tree.BinaryTree tree, java.lang.Void p)
-
visitBlock
public Node visitBlock(com.sun.source.tree.BlockTree tree, java.lang.Void p)
-
visitBreak
public Node visitBreak(com.sun.source.tree.BreakTree tree, java.lang.Void p)
-
visitSwitch
public Node visitSwitch(com.sun.source.tree.SwitchTree tree, java.lang.Void p)
-
visitCase
public Node visitCase(com.sun.source.tree.CaseTree tree, java.lang.Void p)
-
visitCatch
public Node visitCatch(com.sun.source.tree.CatchTree tree, java.lang.Void p)
-
visitClass
public Node visitClass(com.sun.source.tree.ClassTree tree, java.lang.Void p)
-
visitConditionalExpression
public Node visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree tree, java.lang.Void p)
-
visitContinue
public Node visitContinue(com.sun.source.tree.ContinueTree tree, java.lang.Void p)
-
visitDoWhileLoop
public Node visitDoWhileLoop(com.sun.source.tree.DoWhileLoopTree tree, java.lang.Void p)
-
visitErroneous
public Node visitErroneous(com.sun.source.tree.ErroneousTree tree, java.lang.Void p)
-
visitExpressionStatement
public Node visitExpressionStatement(com.sun.source.tree.ExpressionStatementTree tree, java.lang.Void p)
-
visitEnhancedForLoop
public Node visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree tree, java.lang.Void p)
-
createEnhancedForLoopIteratorVariable
protected com.sun.source.tree.VariableTree createEnhancedForLoopIteratorVariable(com.sun.source.tree.MethodInvocationTree iteratorCall, javax.lang.model.element.VariableElement variableElement)
-
createEnhancedForLoopArrayVariable
protected com.sun.source.tree.VariableTree createEnhancedForLoopArrayVariable(com.sun.source.tree.ExpressionTree expression, javax.lang.model.element.VariableElement variableElement)
-
visitForLoop
public Node visitForLoop(com.sun.source.tree.ForLoopTree tree, java.lang.Void p)
-
visitIdentifier
public Node visitIdentifier(com.sun.source.tree.IdentifierTree tree, java.lang.Void p)
-
visitIf
public Node visitIf(com.sun.source.tree.IfTree tree, java.lang.Void p)
-
visitImport
public Node visitImport(com.sun.source.tree.ImportTree tree, java.lang.Void p)
-
visitArrayAccess
public Node visitArrayAccess(com.sun.source.tree.ArrayAccessTree tree, java.lang.Void p)
-
visitLabeledStatement
public Node visitLabeledStatement(com.sun.source.tree.LabeledStatementTree tree, java.lang.Void p)
-
visitLiteral
public Node visitLiteral(com.sun.source.tree.LiteralTree tree, java.lang.Void p)
-
visitMethod
public Node visitMethod(com.sun.source.tree.MethodTree tree, java.lang.Void p)
-
visitModifiers
public Node visitModifiers(com.sun.source.tree.ModifiersTree tree, java.lang.Void p)
-
visitNewArray
public Node visitNewArray(com.sun.source.tree.NewArrayTree tree, java.lang.Void p)
-
visitNewClass
public Node visitNewClass(com.sun.source.tree.NewClassTree tree, java.lang.Void p)
-
visitParenthesized
public Node visitParenthesized(com.sun.source.tree.ParenthesizedTree tree, java.lang.Void p)
-
visitReturn
public Node visitReturn(com.sun.source.tree.ReturnTree tree, java.lang.Void p)
-
visitMemberSelect
public Node visitMemberSelect(com.sun.source.tree.MemberSelectTree tree, java.lang.Void p)
-
visitEmptyStatement
public Node visitEmptyStatement(com.sun.source.tree.EmptyStatementTree tree, java.lang.Void p)
-
visitSynchronized
public Node visitSynchronized(com.sun.source.tree.SynchronizedTree tree, java.lang.Void p)
-
visitThrow
public Node visitThrow(com.sun.source.tree.ThrowTree tree, java.lang.Void p)
-
visitCompilationUnit
public Node visitCompilationUnit(com.sun.source.tree.CompilationUnitTree tree, java.lang.Void p)
-
visitTry
public Node visitTry(com.sun.source.tree.TryTree tree, java.lang.Void p)
-
visitParameterizedType
public Node visitParameterizedType(com.sun.source.tree.ParameterizedTypeTree tree, java.lang.Void p)
-
visitUnionType
public Node visitUnionType(com.sun.source.tree.UnionTypeTree tree, java.lang.Void p)
-
visitArrayType
public Node visitArrayType(com.sun.source.tree.ArrayTypeTree tree, java.lang.Void p)
-
visitTypeCast
public Node visitTypeCast(com.sun.source.tree.TypeCastTree tree, java.lang.Void p)
-
visitPrimitiveType
public Node visitPrimitiveType(com.sun.source.tree.PrimitiveTypeTree tree, java.lang.Void p)
-
visitTypeParameter
public Node visitTypeParameter(com.sun.source.tree.TypeParameterTree tree, java.lang.Void p)
-
visitInstanceOf
public Node visitInstanceOf(com.sun.source.tree.InstanceOfTree tree, java.lang.Void p)
-
visitUnary
public Node visitUnary(com.sun.source.tree.UnaryTree tree, java.lang.Void p)
-
visitVariable
public Node visitVariable(com.sun.source.tree.VariableTree tree, java.lang.Void p)
-
visitWhileLoop
public Node visitWhileLoop(com.sun.source.tree.WhileLoopTree tree, java.lang.Void p)
-
visitLambdaExpression
public Node visitLambdaExpression(com.sun.source.tree.LambdaExpressionTree tree, java.lang.Void p)
-
visitMemberReference
public Node visitMemberReference(com.sun.source.tree.MemberReferenceTree tree, java.lang.Void p)
-
visitWildcard
public Node visitWildcard(com.sun.source.tree.WildcardTree tree, java.lang.Void p)
-
visitOther
public Node visitOther(com.sun.source.tree.Tree tree, java.lang.Void p)
-
getTypeMirror
protected javax.lang.model.type.TypeMirror getTypeMirror(java.lang.Class<?> clazz)
Returns the TypeMirror for the given class.- Parameters:
clazz
- a class- Returns:
- the TypeMirror for the class
-
maybeGetTypeMirror
protected @Nullable javax.lang.model.type.TypeMirror maybeGetTypeMirror(java.lang.Class<?> clazz)
Returns the TypeMirror for the given class, ornull
if the type is not present.This can be used to handle system types that are not present. For example, in Java code that is translated to JavaScript using j2cl, the custom bootclasspath contains APIs that are emulated in JavaScript, so some types such as OutOfMemoryError are deliberately not present.
- Parameters:
clazz
- a class, which must have a canonical name- Returns:
- the TypeMirror for the class, or
null
if the type is not present
-
-