aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Analysis/PathSensitive/GRWorkList.h
blob: 857fa316911fcd044b1e734eba7fac719e719234 (plain) (blame)
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
//==- GRWorkList.h - Worklist class used by GRCoreEngine -----------*- 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 GRWorkList, a pure virtual class that represents an opaque
//  worklist used by GRCoreEngine to explore the reachability state space.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_ANALYSIS_GRWORKLIST
#define LLVM_CLANG_ANALYSIS_GRWORKLIST

#include "clang/Analysis/PathSensitive/GRBlockCounter.h"
#include <cstddef>

namespace clang {
  
class CFGBlock;
class ExplodedNode;
class ExplodedNodeImpl;

class GRWorkListUnit {
  ExplodedNode* Node;
  GRBlockCounter Counter;
  CFGBlock* Block;
  unsigned BlockIdx; // This is the index of the next statement.

public:
  GRWorkListUnit(ExplodedNode* N, GRBlockCounter C,
                 CFGBlock* B, unsigned idx)
  : Node(N),
    Counter(C),
    Block(B),
    BlockIdx(idx) {}

  explicit GRWorkListUnit(ExplodedNode* N, GRBlockCounter C)
  : Node(N),
    Counter(C),
    Block(NULL),
    BlockIdx(0) {}

  ExplodedNode* getNode()         const { return Node; }
  GRBlockCounter    getBlockCounter() const { return Counter; }
  CFGBlock*         getBlock()        const { return Block; }
  unsigned          getIndex()        const { return BlockIdx; }
};

class GRWorkList {
  GRBlockCounter CurrentCounter;
public:
  virtual ~GRWorkList();
  virtual bool hasWork() const = 0;

  virtual void Enqueue(const GRWorkListUnit& U) = 0;

  void Enqueue(ExplodedNode* N, CFGBlock& B, unsigned idx) {
    Enqueue(GRWorkListUnit(N, CurrentCounter, &B, idx));
  }

  void Enqueue(ExplodedNode* N) {
    Enqueue(GRWorkListUnit(N, CurrentCounter));
  }

  virtual GRWorkListUnit Dequeue() = 0;

  void setBlockCounter(GRBlockCounter C) { CurrentCounter = C; }
  GRBlockCounter getBlockCounter() const { return CurrentCounter; }

  static GRWorkList *MakeDFS();
  static GRWorkList *MakeBFS();
  static GRWorkList *MakeBFSBlockDFSContents();
};
} // end clang namespace
#endif