clang API Documentation

WorkList.h
Go to the documentation of this file.
00001 //==- WorkList.h - Worklist class used by CoreEngine ---------------*- C++ -*-//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines WorkList, a pure virtual class that represents an opaque
00011 //  worklist used by CoreEngine to explore the reachability state space.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_GR_WORKLIST
00016 #define LLVM_CLANG_GR_WORKLIST
00017 
00018 #include "clang/StaticAnalyzer/Core/PathSensitive/BlockCounter.h"
00019 #include <cstddef>
00020 
00021 namespace clang {
00022   
00023 class CFGBlock;
00024 
00025 namespace ento {
00026 
00027 class ExplodedNode;
00028 class ExplodedNodeImpl;
00029 
00030 class WorkListUnit {
00031   ExplodedNode *node;
00032   BlockCounter counter;
00033   const CFGBlock *block;
00034   unsigned blockIdx; // This is the index of the next statement.
00035 
00036 public:
00037   WorkListUnit(ExplodedNode *N, BlockCounter C,
00038                const CFGBlock *B, unsigned idx)
00039   : node(N),
00040     counter(C),
00041     block(B),
00042     blockIdx(idx) {}
00043 
00044   explicit WorkListUnit(ExplodedNode *N, BlockCounter C)
00045   : node(N),
00046     counter(C),
00047     block(NULL),
00048     blockIdx(0) {}
00049 
00050   /// Returns the node associated with the worklist unit.
00051   ExplodedNode *getNode() const { return node; }
00052   
00053   /// Returns the block counter map associated with the worklist unit.
00054   BlockCounter getBlockCounter() const { return counter; }
00055 
00056   /// Returns the CFGblock associated with the worklist unit.
00057   const CFGBlock *getBlock() const { return block; }
00058   
00059   /// Return the index within the CFGBlock for the worklist unit.
00060   unsigned getIndex() const { return blockIdx; }
00061 };
00062 
00063 class WorkList {
00064   BlockCounter CurrentCounter;
00065 public:
00066   virtual ~WorkList();
00067   virtual bool hasWork() const = 0;
00068 
00069   virtual void enqueue(const WorkListUnit& U) = 0;
00070 
00071   void enqueue(ExplodedNode *N, const CFGBlock *B, unsigned idx) {
00072     enqueue(WorkListUnit(N, CurrentCounter, B, idx));
00073   }
00074 
00075   void enqueue(ExplodedNode *N) {
00076     assert(N->getLocation().getKind() != ProgramPoint::PostStmtKind);
00077     enqueue(WorkListUnit(N, CurrentCounter));
00078   }
00079 
00080   virtual WorkListUnit dequeue() = 0;
00081 
00082   void setBlockCounter(BlockCounter C) { CurrentCounter = C; }
00083   BlockCounter getBlockCounter() const { return CurrentCounter; }
00084 
00085   class Visitor {
00086   public:
00087     Visitor() {}
00088     virtual ~Visitor();
00089     virtual bool visit(const WorkListUnit &U) = 0;
00090   };
00091   virtual bool visitItemsInWorkList(Visitor &V) = 0;
00092   
00093   static WorkList *makeDFS();
00094   static WorkList *makeBFS();
00095   static WorkList *makeBFSBlockDFSContents();
00096 };
00097 
00098 } // end GR namespace
00099 
00100 } // end clang namespace
00101 
00102 #endif