Package edu.umd.cs.findbugs.ba.bcp
Class PatternMatcher
- java.lang.Object
-
- edu.umd.cs.findbugs.ba.bcp.PatternMatcher
-
- All Implemented Interfaces:
DFSEdgeTypes
,DFSEdgeTypes
public class PatternMatcher extends java.lang.Object implements DFSEdgeTypes
Match a ByteCodePattern against the code of a method, represented by a CFG. Produces some number of ByteCodePatternMatch objects, which indicate how the pattern matched the bytecode instructions in the method.
This code is a hack and should probably be rewritten.
- See Also:
ByteCodePattern
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
PatternMatcher.State
Object representing the current state of the matching algorithm.
-
Field Summary
Fields Modifier and Type Field Description private CFG
cfg
private org.apache.bcel.generic.ConstantPoolGen
cpg
(package private) int
depth
Match a sequence of pattern elements, starting at the given one.private DepthFirstSearch
dfs
private DominatorsAnalysis
domAnalysis
private static org.slf4j.Logger
LOG
private int
nextPath
private ByteCodePattern
pattern
private java.util.LinkedList<ByteCodePatternMatch>
resultList
private static boolean
SHOW_WILD
private java.util.IdentityHashMap<BasicBlock,BasicBlock>
visitedBlockMap
private ValueNumberDataflow
vnaDataflow
private java.util.LinkedList<BasicBlock>
workList
-
Fields inherited from interface edu.umd.cs.findbugs.graph.DFSEdgeTypes
BACK_EDGE, CROSS_EDGE, FORWARD_EDGE, TREE_EDGE, UNKNOWN_EDGE
-
-
Constructor Summary
Constructors Constructor Description PatternMatcher(ByteCodePattern pattern, ClassContext classContext, org.apache.bcel.classfile.Method method)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
attemptMatch(BasicBlock basicBlock, BasicBlock.InstructionIterator instructionIterator)
Attempt to begin a match.java.util.Iterator<ByteCodePatternMatch>
byteCodePatternMatchIterator()
Return an Iterator over the ByteCodePatternMatch objects representing successful matches of the ByteCodePattern.private void
debug(java.lang.String s)
PatternMatcher
execute()
Search for examples of the ByteCodePattern.private void
work(PatternMatcher.State state)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
SHOW_WILD
private static final boolean SHOW_WILD
-
pattern
private final ByteCodePattern pattern
-
cfg
private final CFG cfg
-
cpg
private final org.apache.bcel.generic.ConstantPoolGen cpg
-
dfs
private final DepthFirstSearch dfs
-
vnaDataflow
private final ValueNumberDataflow vnaDataflow
-
domAnalysis
private final DominatorsAnalysis domAnalysis
-
workList
private final java.util.LinkedList<BasicBlock> workList
-
visitedBlockMap
private final java.util.IdentityHashMap<BasicBlock,BasicBlock> visitedBlockMap
-
resultList
private final java.util.LinkedList<ByteCodePatternMatch> resultList
-
nextPath
private int nextPath
-
depth
int depth
Match a sequence of pattern elements, starting at the given one. The InstructionIterator should generally be positioned just before the next instruction to be matched. However, it may be positioned at the end of a basic block, in which case nothing will happen except that we will try to continue the match in the non-backedge successors of the basic block.
-
-
Constructor Detail
-
PatternMatcher
public PatternMatcher(ByteCodePattern pattern, ClassContext classContext, org.apache.bcel.classfile.Method method) throws CFGBuilderException, DataflowAnalysisException
Constructor.- Parameters:
pattern
- the ByteCodePattern to look for examples ofclassContext
- ClassContext for the class to analyzemethod
- the Method to analyze- Throws:
CFGBuilderException
DataflowAnalysisException
-
-
Method Detail
-
execute
public PatternMatcher execute() throws DataflowAnalysisException
Search for examples of the ByteCodePattern.- Returns:
- this object
- Throws:
DataflowAnalysisException
- if the ValueNumberAnalysis did not produce useful values for the method
-
byteCodePatternMatchIterator
public java.util.Iterator<ByteCodePatternMatch> byteCodePatternMatchIterator()
Return an Iterator over the ByteCodePatternMatch objects representing successful matches of the ByteCodePattern.
-
attemptMatch
private void attemptMatch(BasicBlock basicBlock, BasicBlock.InstructionIterator instructionIterator) throws DataflowAnalysisException
Attempt to begin a match.- Parameters:
basicBlock
- the basic blockinstructionIterator
- the instruction iterator positioned just before the first instruction to be matched- Throws:
DataflowAnalysisException
-
debug
private void debug(java.lang.String s)
-
work
private void work(PatternMatcher.State state) throws DataflowAnalysisException
- Throws:
DataflowAnalysisException
-
-