WorkList.h revision 226633
160107Sobrien//==- WorkList.h - Worklist class used by CoreEngine ---------------*- C++ -*-//
22786Ssos//
32786Ssos//                     The LLVM Compiler Infrastructure
42786Ssos//
52786Ssos// This file is distributed under the University of Illinois Open Source
62786Ssos// License. See LICENSE.TXT for details.
732822Syokota//
82786Ssos//===----------------------------------------------------------------------===//
92786Ssos//
102786Ssos//  This file defines WorkList, a pure virtual class that represents an opaque
11192766Smarkm//  worklist used by CoreEngine to explore the reachability state space.
122786Ssos//
132786Ssos//===----------------------------------------------------------------------===//
142786Ssos
152786Ssos#ifndef LLVM_CLANG_GR_WORKLIST
162786Ssos#define LLVM_CLANG_GR_WORKLIST
172786Ssos
1838140Syokota#include "clang/StaticAnalyzer/Core/PathSensitive/BlockCounter.h"
192786Ssos#include <cstddef>
207420Ssos
212786Ssosnamespace clang {
222786Ssos
232786Ssosclass CFGBlock;
2461118Sroberto
252786Ssosnamespace ento {
262786Ssos
272786Ssosclass ExplodedNode;
282786Ssosclass ExplodedNodeImpl;
292786Ssos
302786Ssosclass WorkListUnit {
312786Ssos  ExplodedNode *node;
322786Ssos  BlockCounter counter;
332786Ssos  const CFGBlock *block;
342786Ssos  unsigned blockIdx; // This is the index of the next statement.
352786Ssos
362786Ssospublic:
372786Ssos  WorkListUnit(ExplodedNode *N, BlockCounter C,
382786Ssos               const CFGBlock *B, unsigned idx)
392786Ssos  : node(N),
402786Ssos    counter(C),
412786Ssos    block(B),
422786Ssos    blockIdx(idx) {}
432786Ssos
442786Ssos  explicit WorkListUnit(ExplodedNode *N, BlockCounter C)
452786Ssos  : node(N),
462786Ssos    counter(C),
4744160Syokota    block(NULL),
482786Ssos    blockIdx(0) {}
49270153Sse
502786Ssos  /// Returns the node associated with the worklist unit.
512786Ssos  ExplodedNode *getNode() const { return node; }
522786Ssos
532786Ssos  /// Returns the block counter map associated with the worklist unit.
542786Ssos  BlockCounter getBlockCounter() const { return counter; }
552786Ssos
562786Ssos  /// Returns the CFGblock associated with the worklist unit.
572786Ssos  const CFGBlock *getBlock() const { return block; }
582786Ssos
592786Ssos  /// Return the index within the CFGBlock for the worklist unit.
602786Ssos  unsigned getIndex() const { return blockIdx; }
6143334Syokota};
622786Ssos
6332822Syokotaclass WorkList {
6462420Sjoe  BlockCounter CurrentCounter;
652786Ssospublic:
662786Ssos  virtual ~WorkList();
672786Ssos  virtual bool hasWork() const = 0;
682786Ssos
692786Ssos  virtual void enqueue(const WorkListUnit& U) = 0;
702786Ssos
712786Ssos  void enqueue(ExplodedNode *N, const CFGBlock *B, unsigned idx) {
722786Ssos    enqueue(WorkListUnit(N, CurrentCounter, B, idx));
732786Ssos  }
742786Ssos
7543334Syokota  void enqueue(ExplodedNode *N) {
7643334Syokota    enqueue(WorkListUnit(N, CurrentCounter));
772786Ssos  }
782786Ssos
792786Ssos  virtual WorkListUnit dequeue() = 0;
8043334Syokota
812786Ssos  void setBlockCounter(BlockCounter C) { CurrentCounter = C; }
825994Ssos  BlockCounter getBlockCounter() const { return CurrentCounter; }
8343334Syokota
842786Ssos  class Visitor {
852786Ssos  public:
862786Ssos    Visitor() {}
872786Ssos    virtual ~Visitor();
882786Ssos    virtual bool visit(const WorkListUnit &U) = 0;
896045Ssos  };
9043334Syokota  virtual bool visitItemsInWorkList(Visitor &V) = 0;
912786Ssos
922786Ssos  static WorkList *makeDFS();
932786Ssos  static WorkList *makeBFS();
942786Ssos  static WorkList *makeBFSBlockDFSContents();
9518194Ssos};
962786Ssos
972786Ssos} // end GR namespace
9874119Sache
992786Ssos} // end clang namespace
1002786Ssos
1012786Ssos#endif
1022786Ssos