1 //==- WorkList.h - Worklist class used by CoreEngine ---------------*- C++ -*-//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines WorkList, a pure virtual class that represents an opaque
11 // worklist used by CoreEngine to explore the reachability state space.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_GR_WORKLIST
16 #define LLVM_CLANG_GR_WORKLIST
18 #include "clang/StaticAnalyzer/Core/PathSensitive/BlockCounter.h"
28 class ExplodedNodeImpl;
33 const CFGBlock* block;
34 unsigned blockIdx; // This is the index of the next statement.
37 WorkListUnit(ExplodedNode* N, BlockCounter C,
38 const CFGBlock* B, unsigned idx)
44 explicit WorkListUnit(ExplodedNode* N, BlockCounter C)
50 /// Returns the node associated with the worklist unit.
51 ExplodedNode *getNode() const { return node; }
53 /// Returns the block counter map associated with the worklist unit.
54 BlockCounter getBlockCounter() const { return counter; }
56 /// Returns the CFGblock associated with the worklist unit.
57 const CFGBlock *getBlock() const { return block; }
59 /// Return the index within the CFGBlock for the worklist unit.
60 unsigned getIndex() const { return blockIdx; }
64 BlockCounter CurrentCounter;
67 virtual bool hasWork() const = 0;
69 virtual void enqueue(const WorkListUnit& U) = 0;
71 void enqueue(ExplodedNode *N, const CFGBlock *B, unsigned idx) {
72 enqueue(WorkListUnit(N, CurrentCounter, B, idx));
75 void enqueue(ExplodedNode *N) {
76 enqueue(WorkListUnit(N, CurrentCounter));
79 virtual WorkListUnit dequeue() = 0;
81 void setBlockCounter(BlockCounter C) { CurrentCounter = C; }
82 BlockCounter getBlockCounter() const { return CurrentCounter; }
88 virtual bool visit(const WorkListUnit &U) = 0;
90 virtual bool visitItemsInWorkList(Visitor &V) = 0;
92 static WorkList *makeDFS();
93 static WorkList *makeBFS();
94 static WorkList *makeBFSBlockDFSContents();
99 } // end clang namespace