public interface WholeProgramInference
WholeProgramInference
is misleading.
This interface has update* methods that should be called at certain (pseudo-)assignments, and they may update the type of the LHS of the (pseudo-)assignment based on the type of the RHS. In case the element on the LHS already had an inferred type, its new type will be the LUB between the previous and new types.
Modifier and Type | Interface and Description |
---|---|
static class |
WholeProgramInference.OutputFormat
The kinds of output that whole-program inference can produce.
|
Modifier and Type | Method and Description |
---|---|
void |
addMethodDeclarationAnnotation(ExecutableElement methodElt,
AnnotationMirror anno)
Updates a method to add a declaration annotation.
|
void |
preprocessClassTree(ClassTree classTree)
Performs any preparation required for inference on Elements of a class.
|
void |
updateContracts(Analysis.BeforeOrAfter preOrPost,
ExecutableElement methodElement,
CFAbstractStore<?,?> store)
Updates the preconditions or postconditions of the current method, from a store.
|
void |
updateFieldFromType(Tree lhsTree,
Element element,
String fieldName,
AnnotatedTypeMirror rhsATM)
Updates the type of
field based on an assignment whose right-hand side has type rhsATM . |
void |
updateFromFieldAssignment(Node field,
Node rhs)
Updates the type of
field based on an assignment of rhs to field . |
void |
updateFromFormalParameterAssignment(LocalVariableNode lhs,
Node rhs,
VariableElement paramElt)
Updates the type of
lhs based on an assignment of rhs to lhs . |
void |
updateFromMethodInvocation(MethodInvocationNode methodInvNode,
ExecutableElement methodElt,
CFAbstractStore<?,?> store)
Updates the parameter types of the method
methodElt based on the arguments in the
method invocation methodInvNode . |
void |
updateFromObjectCreation(ObjectCreationNode objectCreationNode,
ExecutableElement constructorElt,
CFAbstractStore<?,?> store)
Updates the parameter types of the constructor
constructorElt based on the arguments in
objectCreationNode . |
void |
updateFromOverride(MethodTree methodTree,
ExecutableElement methodElt,
AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethod)
Updates the parameter types (including the receiver) of the method
methodTree based on
the parameter types of the overridden method overriddenMethod . |
void |
updateFromReturn(ReturnNode retNode,
com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol,
MethodTree methodTree,
Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods)
Updates the return type of the method
methodTree based on returnedExpression . |
void |
writeResultsToFile(WholeProgramInference.OutputFormat format,
BaseTypeChecker checker)
Writes the inferred results to a file.
|
void updateFromObjectCreation(ObjectCreationNode objectCreationNode, ExecutableElement constructorElt, CFAbstractStore<?,?> store)
constructorElt
based on the arguments in
objectCreationNode
.
For each parameter in constructorElt:
objectCreationNode
- the Node that invokes the constructorconstructorElt
- the Element of the constructorstore
- the store just before the callvoid updateFromMethodInvocation(MethodInvocationNode methodInvNode, ExecutableElement methodElt, CFAbstractStore<?,?> store)
methodElt
based on the arguments in the
method invocation methodInvNode
.
For each formal parameter in methodElt (including the receiver):
methodInvNode
- the node representing a method invocationmethodElt
- the element of the method being invokedstore
- the store before the method call, used for inferring method preconditionsvoid updateFromOverride(MethodTree methodTree, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethod)
methodTree
based on
the parameter types of the overridden method overriddenMethod
.
For each formal parameter in methodElt:
methodTree
- the tree of the method that contains the parameter(s)methodElt
- the element of the methodoverriddenMethod
- the AnnotatedExecutableType of the overridden methodvoid updateFromFormalParameterAssignment(LocalVariableNode lhs, Node rhs, VariableElement paramElt)
lhs
based on an assignment of rhs
to lhs
.
lhs
- the node representing the formal parameterrhs
- the node being assigned to the parameter in the method bodyparamElt
- the formal parametervoid updateFromFieldAssignment(Node field, Node rhs)
field
based on an assignment of rhs
to field
. If
the field has a declaration annotation with the IgnoreInWholeProgramInference
meta-annotation, no type annotation will be inferred for that field.
If there is no stored entry for the field lhs, the entry will be created and its type will be the type of rhs. If there is a stored entry/type for lhs, its new type will be the LUB between the previous type and the type of rhs.
field
- the field whose type will be refined. Must be either a FieldAccessNode or a
LocalVariableNode whose element kind is FIELD.rhs
- the expression being assigned to the fieldvoid updateFieldFromType(Tree lhsTree, Element element, String fieldName, AnnotatedTypeMirror rhsATM)
field
based on an assignment whose right-hand side has type rhsATM
. See more details at updateFromFieldAssignment(org.checkerframework.dataflow.cfg.node.Node, org.checkerframework.dataflow.cfg.node.Node)
.lhsTree
- the tree for the field whose type will be refinedelement
- the element for the field whose type will be refinedfieldName
- the name of the field whose type will be refinedrhsATM
- the type of the expression being assigned to the fieldvoid updateFromReturn(ReturnNode retNode, com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol, MethodTree methodTree, Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods)
methodTree
based on returnedExpression
.
Also updates the return types of any methods that this method overrides that are available as
source code.
If there is no stored annotated return type for the method methodTree, then the type of the return expression will be added to the return type of that method. If there is a stored annotated return type for the method methodTree, its new type will be the LUB between the previous type and the type of the return expression.
retNode
- the node that contains the expression returnedclassSymbol
- the symbol of the class that contains the methodmethodTree
- the tree of the method whose return type may be updatedoverriddenMethods
- the methods that the given method return overrides, indexed by the
annotated type of the superclass in which each method is definedvoid updateContracts(Analysis.BeforeOrAfter preOrPost, ExecutableElement methodElement, CFAbstractStore<?,?> store)
methodElement
- the method or constructor whose preconditions or postconditions to updatepreOrPost
- whether to update preconditions or postconditionsstore
- the store at the method's entry or normal exit, for reading types of expressionsvoid addMethodDeclarationAnnotation(ExecutableElement methodElt, AnnotationMirror anno)
methodElt
- the method to annotateanno
- the declaration annotation to add to the methodvoid writeResultsToFile(WholeProgramInference.OutputFormat format, BaseTypeChecker checker)
format
- the file format in which to write the resultschecker
- the checker from which this method is called, for naming stub filesvoid preprocessClassTree(ClassTree classTree)
classTree
- the class to preprocess