|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.source.util.TreeScanner<R,P> com.sun.source.util.TreePathScanner<Void,Void> checkers.flow.Flow
public class Flow
Provides a generalized flow-sensitive qualifier inference for the checkers framework.
This implementation is based largely on javac
's dataflow analysis
module, which may be found in com.sun.tools.javac.comp.Flow
from 13
Sep 2007. It differs from that class in two ways:
1. It performs a GEN-KILL analysis for qualifiers that is similar to the
initialization/uninitialization analysis in javac
's Flow
.
It does not perform exception analysis, and performs liveness analysis only
to the extent required for the GEN-KILL analysis.
2. Whenever possible, this implementation prefers the use of classes in the
public API (BitSet
, the Compiler Tree API) over those in
com.sun.tools.javac
(for these reasons, examining a diff against that
class would not be particularly enlightening).
As in javac
's Flow
class, methods named "visit*" perform
analysis for a particular type of tree node, while methods named "scan*"
perform the analysis for a general, higher-level class of structural element.
Typically "visit*" methods delegate to "scan*" methods. As an example,
visitIf(com.sun.source.tree.IfTree, java.lang.Void)
, visitWhileLoop(com.sun.source.tree.WhileLoopTree, java.lang.Void)
, visitAssert(com.sun.source.tree.AssertTree, java.lang.Void)
, and
visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree, java.lang.Void)
all use scanCond(com.sun.source.tree.Tree)
for analyzing
conditions and handling branching.
A separate instance of the analysis must be created for each compilation unit.
Field Summary | |
---|---|
protected QualifierHierarchy |
annoRelations
The hierarchy for the type qualifiers that this class infers. |
protected GenKillBits<AnnotationMirror> |
annos
Tracks the annotated state of each variable during flow. |
protected GenKillBits<AnnotationMirror> |
annosWhenFalse
Tracks the annotated state of each variable in a false branch. |
protected GenKillBits<AnnotationMirror> |
annosWhenTrue
Tracks the annotated state of each variable in a true branch. |
protected Set<AnnotationMirror> |
annotations
The annotations (qualifiers) to infer. |
protected AnnotatedTypes |
atypes
Utility class for operations on annotated types. |
protected SourceChecker |
checker
The checker to which this instance belongs. |
protected Elements |
elements
Utilities for Element s. |
protected ProcessingEnvironment |
env
The processing environment to use. |
protected AnnotatedTypeFactory |
factory
Utility class for determining annotated types. |
protected Map<Location,AnnotationMirror> |
flowResults
Stores the results of the analysis (source location to qualifier). |
protected CompilationUnitTree |
root
The file that's being analyzed. |
protected SourcePositions |
source
Utility class for getting source positions. |
protected List<VariableElement> |
vars
Maps variables to a bit index. |
Constructor Summary | |
---|---|
Flow(BaseTypeChecker checker,
CompilationUnitTree root,
Set<AnnotationMirror> annotations,
AnnotatedTypeFactory factory)
Creates a new analysis. |
Method Summary | |
---|---|
protected void |
recordBits(TreePath path)
Record the value of the annotation bit for the given usage of a variable, so that a type-checker may use its value after the analysis has finished. |
Void |
scan(Tree tree,
Void p)
|
protected void |
scanCond(Tree tree)
Called whenever a conditional expression is scanned. |
protected void |
scanDef(Tree tree)
Called whenever a definition is scanned. |
protected void |
scanExpr(ExpressionTree tree)
Called whenever an expression is scanned. |
protected void |
scanStat(StatementTree tree)
Called whenever a statement is scanned. |
protected void |
scanStats(List<? extends StatementTree> trees)
Called whenever a block of statements is scanned. |
void |
setDebug(PrintStream debug)
Sets the PrintStream for printing debug messages, such as
System.out or System.err , or null if no debugging output
should be emitted. |
AnnotationMirror |
test(Tree tree)
Determines the inference result for tree. |
Void |
visitAnnotation(AnnotationTree tree,
Void p)
|
Void |
visitAssert(AssertTree node,
Void p)
|
Void |
visitAssignment(AssignmentTree node,
Void p)
|
Void |
visitBlock(BlockTree node,
Void p)
|
Void |
visitBreak(BreakTree node,
Void p)
|
Void |
visitClass(ClassTree node,
Void p)
|
Void |
visitCompoundAssignment(CompoundAssignmentTree node,
Void p)
|
Void |
visitConditionalExpression(ConditionalExpressionTree node,
Void p)
|
Void |
visitContinue(ContinueTree node,
Void p)
|
Void |
visitEnhancedForLoop(EnhancedForLoopTree node,
Void p)
|
Void |
visitIdentifier(IdentifierTree node,
Void p)
|
Void |
visitIf(IfTree node,
Void p)
|
Void |
visitImport(ImportTree tree,
Void p)
|
Void |
visitMemberSelect(MemberSelectTree node,
Void p)
|
Void |
visitMethod(MethodTree node,
Void p)
|
Void |
visitMethodInvocation(MethodInvocationTree node,
Void p)
|
Void |
visitReturn(ReturnTree node,
Void p)
|
Void |
visitThrow(ThrowTree node,
Void p)
|
Void |
visitTry(TryTree node,
Void p)
|
Void |
visitTypeCast(TypeCastTree node,
Void p)
|
Void |
visitVariable(VariableTree node,
Void p)
|
Void |
visitWhileLoop(WhileLoopTree node,
Void p)
|
Methods inherited from class com.sun.source.util.TreePathScanner |
---|
getCurrentPath, scan |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final SourceChecker checker
protected final ProcessingEnvironment env
protected final CompilationUnitTree root
protected final Set<AnnotationMirror> annotations
BaseTypeChecker.getQualifierHierarchy()
. By
consulting the hierarchy, the analysis will only infer a qualifier on a
type if it is more restrictive (i.e. a subtype) than the existing
qualifier for that type.
protected final SourcePositions source
protected final AnnotatedTypeFactory factory
protected final AnnotatedTypes atypes
protected final List<VariableElement> vars
protected final Map<Location,AnnotationMirror> flowResults
protected GenKillBits<AnnotationMirror> annos
vars
. This field is set to
null immediately after splitting for a branch, and is set to some
combination (usually boolean "and") of annosWhenTrue
and
annosWhenFalse
after merging. Since it is used when visiting the
true and false branches, however, it may be non-null concurrently with
annosWhenTrue
and annosWhenFalse
.
protected GenKillBits<AnnotationMirror> annosWhenTrue
javac
's Flow
, saving/restoring via local variables
handles nested branches. Bit indices correspond exactly to indices in
vars
. This field is copied from annos
when splitting
for a branch and is set to null immediately after merging.
annos
protected GenKillBits<AnnotationMirror> annosWhenFalse
javac
's Flow
, saving/restoring via local variables
handles nested branches. Bit indices correspond exactly to indices in
vars
. This field is copied from annos
when splitting
for a branch and is set to null immediately after merging.
annos
protected final QualifierHierarchy annoRelations
protected final Elements elements
Element
s.
Constructor Detail |
---|
public Flow(BaseTypeChecker checker, CompilationUnitTree root, Set<AnnotationMirror> annotations, AnnotatedTypeFactory factory)
AnnotatedTypeFactory
to obtain annotated types.
checker
- the current checkerroot
- the compilation unit that will be scannedannotations
- the annotations to trackfactory
- the factory class that will be used to get annotated
types, or null
if the default factory should be usedMethod Detail |
---|
public void setDebug(PrintStream debug)
PrintStream
for printing debug messages, such as
System.out
or System.err
, or null if no debugging output
should be emitted.
public Void scan(Tree tree, Void p)
scan
in class TreePathScanner<Void,Void>
public AnnotationMirror test(Tree tree)
tree
- the tree to test
protected void recordBits(TreePath path)
path
- protected void scanDef(Tree tree)
tree
- the definition being scannedprotected void scanStat(StatementTree tree)
tree
- the statement being scannedprotected void scanStats(List<? extends StatementTree> trees)
trees
- the statements being scannedprotected void scanCond(Tree tree)
tree
- the condition being scannedprotected void scanExpr(ExpressionTree tree)
tree
- the expression being scannedpublic Void visitClass(ClassTree node, Void p)
visitClass
in interface TreeVisitor<Void,Void>
visitClass
in class TreeScanner<Void,Void>
public Void visitImport(ImportTree tree, Void p)
visitImport
in interface TreeVisitor<Void,Void>
visitImport
in class TreeScanner<Void,Void>
public Void visitTypeCast(TypeCastTree node, Void p)
visitTypeCast
in interface TreeVisitor<Void,Void>
visitTypeCast
in class TreeScanner<Void,Void>
public Void visitAnnotation(AnnotationTree tree, Void p)
visitAnnotation
in interface TreeVisitor<Void,Void>
visitAnnotation
in class TreeScanner<Void,Void>
public Void visitIdentifier(IdentifierTree node, Void p)
visitIdentifier
in interface TreeVisitor<Void,Void>
visitIdentifier
in class TreeScanner<Void,Void>
public Void visitMemberSelect(MemberSelectTree node, Void p)
visitMemberSelect
in interface TreeVisitor<Void,Void>
visitMemberSelect
in class TreeScanner<Void,Void>
public Void visitVariable(VariableTree node, Void p)
visitVariable
in interface TreeVisitor<Void,Void>
visitVariable
in class TreeScanner<Void,Void>
public Void visitAssignment(AssignmentTree node, Void p)
visitAssignment
in interface TreeVisitor<Void,Void>
visitAssignment
in class TreeScanner<Void,Void>
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p)
visitCompoundAssignment
in interface TreeVisitor<Void,Void>
visitCompoundAssignment
in class TreeScanner<Void,Void>
public Void visitEnhancedForLoop(EnhancedForLoopTree node, Void p)
visitEnhancedForLoop
in interface TreeVisitor<Void,Void>
visitEnhancedForLoop
in class TreeScanner<Void,Void>
public Void visitAssert(AssertTree node, Void p)
visitAssert
in interface TreeVisitor<Void,Void>
visitAssert
in class TreeScanner<Void,Void>
public Void visitIf(IfTree node, Void p)
visitIf
in interface TreeVisitor<Void,Void>
visitIf
in class TreeScanner<Void,Void>
public Void visitConditionalExpression(ConditionalExpressionTree node, Void p)
visitConditionalExpression
in interface TreeVisitor<Void,Void>
visitConditionalExpression
in class TreeScanner<Void,Void>
public Void visitWhileLoop(WhileLoopTree node, Void p)
visitWhileLoop
in interface TreeVisitor<Void,Void>
visitWhileLoop
in class TreeScanner<Void,Void>
public Void visitBreak(BreakTree node, Void p)
visitBreak
in interface TreeVisitor<Void,Void>
visitBreak
in class TreeScanner<Void,Void>
public Void visitContinue(ContinueTree node, Void p)
visitContinue
in interface TreeVisitor<Void,Void>
visitContinue
in class TreeScanner<Void,Void>
public Void visitReturn(ReturnTree node, Void p)
visitReturn
in interface TreeVisitor<Void,Void>
visitReturn
in class TreeScanner<Void,Void>
public Void visitThrow(ThrowTree node, Void p)
visitThrow
in interface TreeVisitor<Void,Void>
visitThrow
in class TreeScanner<Void,Void>
public Void visitTry(TryTree node, Void p)
visitTry
in interface TreeVisitor<Void,Void>
visitTry
in class TreeScanner<Void,Void>
public Void visitMethodInvocation(MethodInvocationTree node, Void p)
visitMethodInvocation
in interface TreeVisitor<Void,Void>
visitMethodInvocation
in class TreeScanner<Void,Void>
public Void visitBlock(BlockTree node, Void p)
visitBlock
in interface TreeVisitor<Void,Void>
visitBlock
in class TreeScanner<Void,Void>
public Void visitMethod(MethodTree node, Void p)
visitMethod
in interface TreeVisitor<Void,Void>
visitMethod
in class TreeScanner<Void,Void>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |