edu.umd.cs.findbugs.ba.bcp
Class PatternMatcher

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.bcp.PatternMatcher
All Implemented Interfaces:
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.

Author:
David Hovemeyer
See Also:
ByteCodePattern

Nested Class Summary
private  class PatternMatcher.State
          Object representing the current state of the matching algorithm.
 
Field Summary
private  CFG cfg
           
private  org.apache.bcel.generic.ConstantPoolGen cpg
           
private static boolean DEBUG
           
private  DepthFirstSearch dfs
           
private  DominatorsAnalysis domAnalysis
           
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
PatternMatcher(ByteCodePattern pattern, ClassContext classContext, org.apache.bcel.classfile.Method method)
          Constructor.
 
Method Summary
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.
 PatternMatcher execute()
          Search for examples of the ByteCodePattern.
private  void work(PatternMatcher.State state)
          Match a sequence of pattern elements, starting at the given one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG

SHOW_WILD

private static final boolean SHOW_WILD

pattern

private ByteCodePattern pattern

cfg

private CFG cfg

cpg

private org.apache.bcel.generic.ConstantPoolGen cpg

dfs

private DepthFirstSearch dfs

vnaDataflow

private ValueNumberDataflow vnaDataflow

domAnalysis

private DominatorsAnalysis domAnalysis

workList

private java.util.LinkedList<BasicBlock> workList

visitedBlockMap

private java.util.IdentityHashMap<BasicBlock,BasicBlock> visitedBlockMap

resultList

private java.util.LinkedList<ByteCodePatternMatch> resultList
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 of
classContext - ClassContext for the class to analyze
method - 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 block
instructionIterator - the instruction iterator positioned just before the first instruction to be matched
Throws:
DataflowAnalysisException

work

private void work(PatternMatcher.State state)
           throws DataflowAnalysisException
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.

Throws:
DataflowAnalysisException