View Javadoc

1   // BasicBlockVisitor.java, created Fri Jan 11 16:42:38 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Compiler.Quad;
5   
6   /***
7    * Interface for the basic block visitor design pattern.
8    * Make your visitor object implement this class in order to visit 
9    * @author  John Whaley <jwhaley@alum.mit.edu>
10   * @see BasicBlock
11   * @version $Id: BasicBlockVisitor.java 1456 2004-03-09 22:01:46Z jwhaley $
12   */
13  public interface BasicBlockVisitor {
14      
15      /*** Visit a basic block.
16       * @param bb  basic block to visit */
17      void visitBasicBlock(BasicBlock bb);
18  
19      /***
20       * Empty basic block visitor for easy subclassing.
21       */
22      class EmptyVisitor implements BasicBlockVisitor {
23          /*** Visit a basic block.
24           * @param bb  basic block to visit */
25          public void visitBasicBlock(BasicBlock bb) {}
26      }
27      
28      /***
29       * Control flow graph visitor that visits all basic blocks in the CFG with a given
30       * basic block visitor.
31       * @see  ControlFlowGraph
32       * @see  ControlFlowGraphVisitor
33       */
34      class AllBasicBlockVisitor implements ControlFlowGraphVisitor {
35          private final BasicBlockVisitor bbv;
36          boolean trace;
37          /*** Construct a new AllBasicBlockVisitor.
38           * @param bbv  basic block visitor to visit each basic block with. */
39          public AllBasicBlockVisitor(BasicBlockVisitor bbv) { this.bbv = bbv; }
40          /*** Construct a new AllBasicBlockVisitor and set the trace flag to be the specified value.
41           * @param bbv  basic block visitor to visit each basic block with.
42           * @param trace  value of the trace flag */
43          public AllBasicBlockVisitor(BasicBlockVisitor bbv, boolean trace) { this.bbv = bbv; this.trace = trace; }
44          /*** Visit each of the basic blocks in the given control flow graph.
45           * @param cfg  control flow graph to visit
46           */
47          public void visitCFG(ControlFlowGraph cfg) {
48              cfg.visitBasicBlocks(bbv);
49          }
50      }
51      
52  }