[analyzer] Refactoring: include/clang/Checker -> include/clang/GR
[clang.git] / include / clang / GR / PathSensitive / GRWorkList.h
blob062df9480280dd861510e8770b2eee2456018d9f
1 //==- GRWorkList.h - Worklist class used by GRCoreEngine -----------*- C++ -*-//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines GRWorkList, a pure virtual class that represents an opaque
11 // worklist used by GRCoreEngine to explore the reachability state space.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_ANALYSIS_GRWORKLIST
16 #define LLVM_CLANG_ANALYSIS_GRWORKLIST
18 #include "clang/GR/PathSensitive/GRBlockCounter.h"
19 #include <cstddef>
21 namespace clang {
23 class CFGBlock;
24 class ExplodedNode;
25 class ExplodedNodeImpl;
27 class GRWorkListUnit {
28 ExplodedNode* Node;
29 GRBlockCounter Counter;
30 const CFGBlock* Block;
31 unsigned BlockIdx; // This is the index of the next statement.
33 public:
34 GRWorkListUnit(ExplodedNode* N, GRBlockCounter C,
35 const CFGBlock* B, unsigned idx)
36 : Node(N),
37 Counter(C),
38 Block(B),
39 BlockIdx(idx) {}
41 explicit GRWorkListUnit(ExplodedNode* N, GRBlockCounter C)
42 : Node(N),
43 Counter(C),
44 Block(NULL),
45 BlockIdx(0) {}
47 ExplodedNode* getNode() const { return Node; }
48 GRBlockCounter getBlockCounter() const { return Counter; }
49 const CFGBlock* getBlock() const { return Block; }
50 unsigned getIndex() const { return BlockIdx; }
53 class GRWorkList {
54 GRBlockCounter CurrentCounter;
55 public:
56 virtual ~GRWorkList();
57 virtual bool hasWork() const = 0;
59 virtual void Enqueue(const GRWorkListUnit& U) = 0;
61 void Enqueue(ExplodedNode* N, const CFGBlock* B, unsigned idx) {
62 Enqueue(GRWorkListUnit(N, CurrentCounter, B, idx));
65 void Enqueue(ExplodedNode* N) {
66 Enqueue(GRWorkListUnit(N, CurrentCounter));
69 virtual GRWorkListUnit Dequeue() = 0;
71 void setBlockCounter(GRBlockCounter C) { CurrentCounter = C; }
72 GRBlockCounter getBlockCounter() const { return CurrentCounter; }
74 class Visitor {
75 public:
76 Visitor() {}
77 virtual ~Visitor();
78 virtual bool Visit(const GRWorkListUnit &U) = 0;
80 virtual bool VisitItemsInWorkList(Visitor &V) = 0;
82 static GRWorkList *MakeDFS();
83 static GRWorkList *MakeBFS();
84 static GRWorkList *MakeBFSBlockDFSContents();
86 } // end clang namespace
87 #endif