1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
//==- WorkList.h - Worklist class used by CoreEngine ---------------*- C++ -*-//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines WorkList, a pure virtual class that represents an opaque
// worklist used by CoreEngine to explore the reachability state space.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_GR_WORKLIST
#define LLVM_CLANG_GR_WORKLIST
#include "clang/GR/PathSensitive/BlockCounter.h"
#include <cstddef>
namespace clang {
class CFGBlock;
namespace ento {
class ExplodedNode;
class ExplodedNodeImpl;
class WorkListUnit {
ExplodedNode* Node;
BlockCounter Counter;
const CFGBlock* Block;
unsigned BlockIdx; // This is the index of the next statement.
public:
WorkListUnit(ExplodedNode* N, BlockCounter C,
const CFGBlock* B, unsigned idx)
: Node(N),
Counter(C),
Block(B),
BlockIdx(idx) {}
explicit WorkListUnit(ExplodedNode* N, BlockCounter C)
: Node(N),
Counter(C),
Block(NULL),
BlockIdx(0) {}
ExplodedNode* getNode() const { return Node; }
BlockCounter getBlockCounter() const { return Counter; }
const CFGBlock* getBlock() const { return Block; }
unsigned getIndex() const { return BlockIdx; }
};
class WorkList {
BlockCounter CurrentCounter;
public:
virtual ~WorkList();
virtual bool hasWork() const = 0;
virtual void Enqueue(const WorkListUnit& U) = 0;
void Enqueue(ExplodedNode* N, const CFGBlock* B, unsigned idx) {
Enqueue(WorkListUnit(N, CurrentCounter, B, idx));
}
void Enqueue(ExplodedNode* N) {
Enqueue(WorkListUnit(N, CurrentCounter));
}
virtual WorkListUnit Dequeue() = 0;
void setBlockCounter(BlockCounter C) { CurrentCounter = C; }
BlockCounter getBlockCounter() const { return CurrentCounter; }
class Visitor {
public:
Visitor() {}
virtual ~Visitor();
virtual bool Visit(const WorkListUnit &U) = 0;
};
virtual bool VisitItemsInWorkList(Visitor &V) = 0;
static WorkList *MakeDFS();
static WorkList *MakeBFS();
static WorkList *MakeBFSBlockDFSContents();
};
} // end GR namespace
} // end clang namespace
#endif
|