[analyzer] Refactoring: Move stuff into namespace 'GR'.
[clang.git] / include / clang / GR / PathSensitive / GRWorkList.h
blob87a3b364b6a4514ac3d9becdc25c536fed05d1c1
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_GR_GRWORKLIST
16 #define LLVM_CLANG_GR_GRWORKLIST
18 #include "clang/GR/PathSensitive/GRBlockCounter.h"
19 #include <cstddef>
21 namespace clang {
23 class CFGBlock;
25 namespace GR {
27 class ExplodedNode;
28 class ExplodedNodeImpl;
30 class GRWorkListUnit {
31 ExplodedNode* Node;
32 GRBlockCounter Counter;
33 const CFGBlock* Block;
34 unsigned BlockIdx; // This is the index of the next statement.
36 public:
37 GRWorkListUnit(ExplodedNode* N, GRBlockCounter C,
38 const CFGBlock* B, unsigned idx)
39 : Node(N),
40 Counter(C),
41 Block(B),
42 BlockIdx(idx) {}
44 explicit GRWorkListUnit(ExplodedNode* N, GRBlockCounter C)
45 : Node(N),
46 Counter(C),
47 Block(NULL),
48 BlockIdx(0) {}
50 ExplodedNode* getNode() const { return Node; }
51 GRBlockCounter getBlockCounter() const { return Counter; }
52 const CFGBlock* getBlock() const { return Block; }
53 unsigned getIndex() const { return BlockIdx; }
56 class GRWorkList {
57 GRBlockCounter CurrentCounter;
58 public:
59 virtual ~GRWorkList();
60 virtual bool hasWork() const = 0;
62 virtual void Enqueue(const GRWorkListUnit& U) = 0;
64 void Enqueue(ExplodedNode* N, const CFGBlock* B, unsigned idx) {
65 Enqueue(GRWorkListUnit(N, CurrentCounter, B, idx));
68 void Enqueue(ExplodedNode* N) {
69 Enqueue(GRWorkListUnit(N, CurrentCounter));
72 virtual GRWorkListUnit Dequeue() = 0;
74 void setBlockCounter(GRBlockCounter C) { CurrentCounter = C; }
75 GRBlockCounter getBlockCounter() const { return CurrentCounter; }
77 class Visitor {
78 public:
79 Visitor() {}
80 virtual ~Visitor();
81 virtual bool Visit(const GRWorkListUnit &U) = 0;
83 virtual bool VisitItemsInWorkList(Visitor &V) = 0;
85 static GRWorkList *MakeDFS();
86 static GRWorkList *MakeBFS();
87 static GRWorkList *MakeBFSBlockDFSContents();
90 } // end GR namespace
92 } // end clang namespace
94 #endif