clang API Documentation
00001 //==- WorkList.h - Worklist class used by CoreEngine ---------------*- C++ -*-// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines WorkList, a pure virtual class that represents an opaque 00011 // worklist used by CoreEngine to explore the reachability state space. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_WORKLIST_H 00016 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_WORKLIST_H 00017 00018 #include "clang/StaticAnalyzer/Core/PathSensitive/BlockCounter.h" 00019 #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h" 00020 #include <cassert> 00021 00022 namespace clang { 00023 00024 class CFGBlock; 00025 00026 namespace ento { 00027 00028 class WorkListUnit { 00029 ExplodedNode *node; 00030 BlockCounter counter; 00031 const CFGBlock *block; 00032 unsigned blockIdx; // This is the index of the next statement. 00033 00034 public: 00035 WorkListUnit(ExplodedNode *N, BlockCounter C, 00036 const CFGBlock *B, unsigned idx) 00037 : node(N), 00038 counter(C), 00039 block(B), 00040 blockIdx(idx) {} 00041 00042 explicit WorkListUnit(ExplodedNode *N, BlockCounter C) 00043 : node(N), 00044 counter(C), 00045 block(nullptr), 00046 blockIdx(0) {} 00047 00048 /// Returns the node associated with the worklist unit. 00049 ExplodedNode *getNode() const { return node; } 00050 00051 /// Returns the block counter map associated with the worklist unit. 00052 BlockCounter getBlockCounter() const { return counter; } 00053 00054 /// Returns the CFGblock associated with the worklist unit. 00055 const CFGBlock *getBlock() const { return block; } 00056 00057 /// Return the index within the CFGBlock for the worklist unit. 00058 unsigned getIndex() const { return blockIdx; } 00059 }; 00060 00061 class WorkList { 00062 BlockCounter CurrentCounter; 00063 public: 00064 virtual ~WorkList(); 00065 virtual bool hasWork() const = 0; 00066 00067 virtual void enqueue(const WorkListUnit& U) = 0; 00068 00069 void enqueue(ExplodedNode *N, const CFGBlock *B, unsigned idx) { 00070 enqueue(WorkListUnit(N, CurrentCounter, B, idx)); 00071 } 00072 00073 void enqueue(ExplodedNode *N) { 00074 assert(N->getLocation().getKind() != ProgramPoint::PostStmtKind); 00075 enqueue(WorkListUnit(N, CurrentCounter)); 00076 } 00077 00078 virtual WorkListUnit dequeue() = 0; 00079 00080 void setBlockCounter(BlockCounter C) { CurrentCounter = C; } 00081 BlockCounter getBlockCounter() const { return CurrentCounter; } 00082 00083 class Visitor { 00084 public: 00085 Visitor() {} 00086 virtual ~Visitor(); 00087 virtual bool visit(const WorkListUnit &U) = 0; 00088 }; 00089 virtual bool visitItemsInWorkList(Visitor &V) = 0; 00090 00091 static WorkList *makeDFS(); 00092 static WorkList *makeBFS(); 00093 static WorkList *makeBFSBlockDFSContents(); 00094 }; 00095 00096 } // end GR namespace 00097 00098 } // end clang namespace 00099 00100 #endif