Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 1 | //=== AnalysisContext.h - Analysis context for Path Sens analysis --*- 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 AnalysisContext, a class that manages the analysis context |
| 11 | // data for path sensitive analysis. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_CLANG_ANALYSIS_ANALYSISCONTEXT_H |
| 16 | #define LLVM_CLANG_ANALYSIS_ANALYSISCONTEXT_H |
| 17 | |
| 18 | #include "clang/AST/Decl.h" |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Ted Kremenek | b8ad5ee | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 20 | #include "clang/Analysis/CFG.h" |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/OwningPtr.h" |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/FoldingSet.h" |
| 24 | #include "llvm/ADT/PointerUnion.h" |
| 25 | #include "llvm/ADT/DenseMap.h" |
| 26 | #include "llvm/Support/Allocator.h" |
| 27 | |
| 28 | namespace clang { |
| 29 | |
| 30 | class Decl; |
| 31 | class Stmt; |
Ted Kremenek | af13d5b | 2011-03-19 01:00:33 +0000 | [diff] [blame] | 32 | class CFGReverseBlockReachabilityAnalysis; |
Ted Kremenek | 283a358 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 33 | class CFGStmtMap; |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 34 | class LiveVariables; |
| 35 | class ParentMap; |
Tom Care | db34ab7 | 2010-08-23 19:51:57 +0000 | [diff] [blame] | 36 | class PseudoConstantAnalysis; |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 37 | class ImplicitParamDecl; |
| 38 | class LocationContextManager; |
| 39 | class StackFrameContext; |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 40 | |
Zhongxing Xu | c6238d2 | 2010-07-19 01:31:21 +0000 | [diff] [blame] | 41 | namespace idx { class TranslationUnit; } |
| 42 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 43 | /// AnalysisContext contains the context data for the function or method under |
| 44 | /// analysis. |
| 45 | class AnalysisContext { |
| 46 | const Decl *D; |
| 47 | |
Zhongxing Xu | c6238d2 | 2010-07-19 01:31:21 +0000 | [diff] [blame] | 48 | // TranslationUnit is NULL if we don't have multiple translation units. |
Zhongxing Xu | 2ce43c8 | 2010-07-22 13:52:13 +0000 | [diff] [blame] | 49 | idx::TranslationUnit *TU; |
Zhongxing Xu | c6238d2 | 2010-07-19 01:31:21 +0000 | [diff] [blame] | 50 | |
Ted Kremenek | b8ad5ee | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 51 | llvm::OwningPtr<CFG> cfg, completeCFG; |
| 52 | llvm::OwningPtr<CFGStmtMap> cfgStmtMap; |
| 53 | |
| 54 | CFG::BuildOptions cfgBuildOptions; |
| 55 | CFG::BuildOptions::ForcedBlkExprs *forcedBlkExprs; |
| 56 | |
Ted Kremenek | ad5a894 | 2010-08-02 23:46:59 +0000 | [diff] [blame] | 57 | bool builtCFG, builtCompleteCFG; |
Ted Kremenek | b8ad5ee | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 58 | |
| 59 | llvm::OwningPtr<LiveVariables> liveness; |
| 60 | llvm::OwningPtr<LiveVariables> relaxedLiveness; |
| 61 | llvm::OwningPtr<ParentMap> PM; |
| 62 | llvm::OwningPtr<PseudoConstantAnalysis> PCA; |
Ted Kremenek | af13d5b | 2011-03-19 01:00:33 +0000 | [diff] [blame] | 63 | llvm::OwningPtr<CFGReverseBlockReachabilityAnalysis> CFA; |
Ted Kremenek | b8ad5ee | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 64 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 65 | llvm::BumpPtrAllocator A; |
Ted Kremenek | b8ad5ee | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 66 | |
| 67 | // FIXME: remove. |
| 68 | llvm::DenseMap<const BlockDecl*,void*> *ReferencedBlockVars; |
| 69 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 70 | public: |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 71 | AnalysisContext(const Decl *d, idx::TranslationUnit *tu); |
| 72 | |
Zhongxing Xu | 2ce43c8 | 2010-07-22 13:52:13 +0000 | [diff] [blame] | 73 | AnalysisContext(const Decl *d, idx::TranslationUnit *tu, |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 74 | const CFG::BuildOptions &buildOptions); |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 75 | |
| 76 | ~AnalysisContext(); |
| 77 | |
| 78 | ASTContext &getASTContext() { return D->getASTContext(); } |
Zhongxing Xu | c6238d2 | 2010-07-19 01:31:21 +0000 | [diff] [blame] | 79 | const Decl *getDecl() const { return D; } |
| 80 | |
Zhongxing Xu | 2ce43c8 | 2010-07-22 13:52:13 +0000 | [diff] [blame] | 81 | idx::TranslationUnit *getTranslationUnit() const { return TU; } |
Zhongxing Xu | c6238d2 | 2010-07-19 01:31:21 +0000 | [diff] [blame] | 82 | |
Ted Kremenek | 74fb1a4 | 2011-07-19 14:18:43 +0000 | [diff] [blame] | 83 | /// Return the build options used to construct the CFG. |
| 84 | CFG::BuildOptions &getCFGBuildOptions() { |
| 85 | return cfgBuildOptions; |
| 86 | } |
| 87 | |
| 88 | const CFG::BuildOptions &getCFGBuildOptions() const { |
| 89 | return cfgBuildOptions; |
| 90 | } |
| 91 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 92 | /// getAddEHEdges - Return true iff we are adding exceptional edges from |
| 93 | /// callExprs. If this is false, then try/catch statements and blocks |
| 94 | /// reachable from them can appear to be dead in the CFG, analysis passes must |
| 95 | /// cope with that. |
Ted Kremenek | b8ad5ee | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 96 | bool getAddEHEdges() const { return cfgBuildOptions.AddEHEdges; } |
| 97 | bool getUseUnoptimizedCFG() const { |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 98 | return !cfgBuildOptions.PruneTriviallyFalseEdges; |
Ted Kremenek | b8ad5ee | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 99 | } |
| 100 | bool getAddImplicitDtors() const { return cfgBuildOptions.AddImplicitDtors; } |
| 101 | bool getAddInitializers() const { return cfgBuildOptions.AddInitializers; } |
Ted Kremenek | 9b823e8 | 2010-08-03 00:09:51 +0000 | [diff] [blame] | 102 | |
Ted Kremenek | 0d28d36 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 103 | void registerForcedBlockExpression(const Stmt *stmt); |
| 104 | const CFGBlock *getBlockForRegisteredExpression(const Stmt *stmt); |
| 105 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 106 | Stmt *getBody(); |
| 107 | CFG *getCFG(); |
Ted Kremenek | 283a358 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 108 | |
| 109 | CFGStmtMap *getCFGStmtMap(); |
Anders Carlsson | 04eeba4 | 2011-01-16 22:05:23 +0000 | [diff] [blame] | 110 | |
Ted Kremenek | af13d5b | 2011-03-19 01:00:33 +0000 | [diff] [blame] | 111 | CFGReverseBlockReachabilityAnalysis *getCFGReachablityAnalysis(); |
Ted Kremenek | 42461ee | 2011-02-23 01:51:59 +0000 | [diff] [blame] | 112 | |
Ted Kremenek | ad5a894 | 2010-08-02 23:46:59 +0000 | [diff] [blame] | 113 | /// Return a version of the CFG without any edges pruned. |
| 114 | CFG *getUnoptimizedCFG(); |
| 115 | |
Anders Carlsson | 04eeba4 | 2011-01-16 22:05:23 +0000 | [diff] [blame] | 116 | void dumpCFG(); |
| 117 | |
Chandler Carruth | 5d98994 | 2011-07-06 16:21:37 +0000 | [diff] [blame] | 118 | /// \brief Returns true if we have built a CFG for this analysis context. |
| 119 | /// Note that this doesn't correspond to whether or not a valid CFG exists, it |
| 120 | /// corresponds to whether we *attempted* to build one. |
| 121 | bool isCFGBuilt() const { return builtCFG; } |
| 122 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 123 | ParentMap &getParentMap(); |
Tom Care | db34ab7 | 2010-08-23 19:51:57 +0000 | [diff] [blame] | 124 | PseudoConstantAnalysis *getPseudoConstantAnalysis(); |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 125 | LiveVariables *getLiveVariables(); |
Tom Care | ec49bf4 | 2010-08-27 22:30:10 +0000 | [diff] [blame] | 126 | LiveVariables *getRelaxedLiveVariables(); |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 127 | |
| 128 | typedef const VarDecl * const * referenced_decls_iterator; |
| 129 | |
| 130 | std::pair<referenced_decls_iterator, referenced_decls_iterator> |
| 131 | getReferencedBlockVars(const BlockDecl *BD); |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 132 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 133 | /// Return the ImplicitParamDecl* associated with 'self' if this |
| 134 | /// AnalysisContext wraps an ObjCMethodDecl. Returns NULL otherwise. |
| 135 | const ImplicitParamDecl *getSelfDecl() const; |
| 136 | }; |
| 137 | |
| 138 | class AnalysisContextManager { |
| 139 | typedef llvm::DenseMap<const Decl*, AnalysisContext*> ContextMap; |
| 140 | ContextMap Contexts; |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 141 | CFG::BuildOptions cfgBuildOptions; |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 142 | public: |
Marcin Swiderski | 9121ba2 | 2010-09-30 07:41:24 +0000 | [diff] [blame] | 143 | AnalysisContextManager(bool useUnoptimizedCFG = false, |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 144 | bool addImplicitDtors = false, |
| 145 | bool addInitializers = false); |
Ted Kremenek | 9b823e8 | 2010-08-03 00:09:51 +0000 | [diff] [blame] | 146 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 147 | ~AnalysisContextManager(); |
| 148 | |
Zhongxing Xu | 2ce43c8 | 2010-07-22 13:52:13 +0000 | [diff] [blame] | 149 | AnalysisContext *getContext(const Decl *D, idx::TranslationUnit *TU = 0); |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 150 | |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 151 | bool getUseUnoptimizedCFG() const { |
| 152 | return !cfgBuildOptions.PruneTriviallyFalseEdges; |
| 153 | } |
| 154 | |
| 155 | CFG::BuildOptions &getCFGBuildOptions() { |
| 156 | return cfgBuildOptions; |
| 157 | } |
Ted Kremenek | 9b823e8 | 2010-08-03 00:09:51 +0000 | [diff] [blame] | 158 | |
Ted Kremenek | bc5cb8a | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 159 | /// Discard all previously created AnalysisContexts. |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 160 | void clear(); |
| 161 | }; |
| 162 | |
| 163 | class LocationContext : public llvm::FoldingSetNode { |
| 164 | public: |
| 165 | enum ContextKind { StackFrame, Scope, Block }; |
| 166 | |
| 167 | private: |
| 168 | ContextKind Kind; |
Zhongxing Xu | a02d893 | 2010-07-20 02:14:22 +0000 | [diff] [blame] | 169 | |
| 170 | // AnalysisContext can't be const since some methods may modify its member. |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 171 | AnalysisContext *Ctx; |
Zhongxing Xu | a02d893 | 2010-07-20 02:14:22 +0000 | [diff] [blame] | 172 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 173 | const LocationContext *Parent; |
| 174 | |
| 175 | protected: |
| 176 | LocationContext(ContextKind k, AnalysisContext *ctx, |
| 177 | const LocationContext *parent) |
| 178 | : Kind(k), Ctx(ctx), Parent(parent) {} |
| 179 | |
| 180 | public: |
| 181 | virtual ~LocationContext(); |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 182 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 183 | ContextKind getKind() const { return Kind; } |
| 184 | |
| 185 | AnalysisContext *getAnalysisContext() const { return Ctx; } |
| 186 | |
Zhongxing Xu | 2ce43c8 | 2010-07-22 13:52:13 +0000 | [diff] [blame] | 187 | idx::TranslationUnit *getTranslationUnit() const { |
Zhongxing Xu | c6238d2 | 2010-07-19 01:31:21 +0000 | [diff] [blame] | 188 | return Ctx->getTranslationUnit(); |
| 189 | } |
| 190 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 191 | const LocationContext *getParent() const { return Parent; } |
| 192 | |
Zhongxing Xu | 8ddf7ce | 2010-02-17 08:45:06 +0000 | [diff] [blame] | 193 | bool isParentOf(const LocationContext *LC) const; |
| 194 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 195 | const Decl *getDecl() const { return getAnalysisContext()->getDecl(); } |
| 196 | |
| 197 | CFG *getCFG() const { return getAnalysisContext()->getCFG(); } |
| 198 | |
| 199 | LiveVariables *getLiveVariables() const { |
| 200 | return getAnalysisContext()->getLiveVariables(); |
| 201 | } |
| 202 | |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 203 | ParentMap &getParentMap() const { |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 204 | return getAnalysisContext()->getParentMap(); |
| 205 | } |
| 206 | |
| 207 | const ImplicitParamDecl *getSelfDecl() const { |
| 208 | return Ctx->getSelfDecl(); |
| 209 | } |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 210 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 211 | const StackFrameContext *getCurrentStackFrame() const; |
| 212 | const StackFrameContext * |
| 213 | getStackFrameForDeclContext(const DeclContext *DC) const; |
| 214 | |
| 215 | virtual void Profile(llvm::FoldingSetNodeID &ID) = 0; |
| 216 | |
| 217 | static bool classof(const LocationContext*) { return true; } |
| 218 | |
| 219 | public: |
| 220 | static void ProfileCommon(llvm::FoldingSetNodeID &ID, |
| 221 | ContextKind ck, |
| 222 | AnalysisContext *ctx, |
| 223 | const LocationContext *parent, |
Ted Kremenek | 9c378f7 | 2011-08-12 23:37:29 +0000 | [diff] [blame^] | 224 | const void *data); |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | class StackFrameContext : public LocationContext { |
Zhongxing Xu | 26c9cb5 | 2011-01-10 11:28:29 +0000 | [diff] [blame] | 228 | // The callsite where this stack frame is established. |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 229 | const Stmt *CallSite; |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 230 | |
| 231 | // The parent block of the callsite. |
| 232 | const CFGBlock *Block; |
| 233 | |
| 234 | // The index of the callsite in the CFGBlock. |
| 235 | unsigned Index; |
| 236 | |
| 237 | friend class LocationContextManager; |
| 238 | StackFrameContext(AnalysisContext *ctx, const LocationContext *parent, |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 239 | const Stmt *s, const CFGBlock *blk, |
Zhongxing Xu | d706434 | 2010-11-24 13:08:51 +0000 | [diff] [blame] | 240 | unsigned idx) |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 241 | : LocationContext(StackFrame, ctx, parent), CallSite(s), |
Zhongxing Xu | d706434 | 2010-11-24 13:08:51 +0000 | [diff] [blame] | 242 | Block(blk), Index(idx) {} |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 243 | |
| 244 | public: |
| 245 | ~StackFrameContext() {} |
| 246 | |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 247 | const Stmt *getCallSite() const { return CallSite; } |
Zhongxing Xu | d706434 | 2010-11-24 13:08:51 +0000 | [diff] [blame] | 248 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 249 | const CFGBlock *getCallSiteBlock() const { return Block; } |
| 250 | |
| 251 | unsigned getIndex() const { return Index; } |
| 252 | |
| 253 | void Profile(llvm::FoldingSetNodeID &ID); |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 254 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 255 | static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx, |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 256 | const LocationContext *parent, const Stmt *s, |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 257 | const CFGBlock *blk, unsigned idx) { |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 258 | ProfileCommon(ID, StackFrame, ctx, parent, s); |
| 259 | ID.AddPointer(blk); |
| 260 | ID.AddInteger(idx); |
| 261 | } |
| 262 | |
Ted Kremenek | 9c378f7 | 2011-08-12 23:37:29 +0000 | [diff] [blame^] | 263 | static bool classof(const LocationContext *Ctx) { |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 264 | return Ctx->getKind() == StackFrame; |
| 265 | } |
| 266 | }; |
| 267 | |
| 268 | class ScopeContext : public LocationContext { |
| 269 | const Stmt *Enter; |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 270 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 271 | friend class LocationContextManager; |
| 272 | ScopeContext(AnalysisContext *ctx, const LocationContext *parent, |
| 273 | const Stmt *s) |
| 274 | : LocationContext(Scope, ctx, parent), Enter(s) {} |
| 275 | |
| 276 | public: |
| 277 | ~ScopeContext() {} |
| 278 | |
| 279 | void Profile(llvm::FoldingSetNodeID &ID); |
| 280 | |
| 281 | static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx, |
| 282 | const LocationContext *parent, const Stmt *s) { |
| 283 | ProfileCommon(ID, Scope, ctx, parent, s); |
| 284 | } |
| 285 | |
Ted Kremenek | 9c378f7 | 2011-08-12 23:37:29 +0000 | [diff] [blame^] | 286 | static bool classof(const LocationContext *Ctx) { |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 287 | return Ctx->getKind() == Scope; |
| 288 | } |
| 289 | }; |
| 290 | |
| 291 | class BlockInvocationContext : public LocationContext { |
| 292 | // FIXME: Add back context-sensivity (we don't want libAnalysis to know |
| 293 | // about MemRegion). |
| 294 | const BlockDecl *BD; |
| 295 | |
| 296 | friend class LocationContextManager; |
| 297 | |
| 298 | BlockInvocationContext(AnalysisContext *ctx, const LocationContext *parent, |
| 299 | const BlockDecl *bd) |
| 300 | : LocationContext(Block, ctx, parent), BD(bd) {} |
| 301 | |
| 302 | public: |
| 303 | ~BlockInvocationContext() {} |
| 304 | |
| 305 | const BlockDecl *getBlockDecl() const { return BD; } |
| 306 | |
| 307 | void Profile(llvm::FoldingSetNodeID &ID); |
| 308 | |
| 309 | static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx, |
| 310 | const LocationContext *parent, const BlockDecl *bd) { |
| 311 | ProfileCommon(ID, Block, ctx, parent, bd); |
| 312 | } |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 313 | |
Ted Kremenek | 9c378f7 | 2011-08-12 23:37:29 +0000 | [diff] [blame^] | 314 | static bool classof(const LocationContext *Ctx) { |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 315 | return Ctx->getKind() == Block; |
| 316 | } |
| 317 | }; |
| 318 | |
| 319 | class LocationContextManager { |
| 320 | llvm::FoldingSet<LocationContext> Contexts; |
| 321 | public: |
| 322 | ~LocationContextManager(); |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 323 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 324 | const StackFrameContext *getStackFrame(AnalysisContext *ctx, |
| 325 | const LocationContext *parent, |
Ted Kremenek | 892697d | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 326 | const Stmt *s, |
Zhongxing Xu | d706434 | 2010-11-24 13:08:51 +0000 | [diff] [blame] | 327 | const CFGBlock *blk, unsigned idx); |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 328 | |
| 329 | const ScopeContext *getScope(AnalysisContext *ctx, |
| 330 | const LocationContext *parent, |
| 331 | const Stmt *s); |
Ted Kremenek | d064fdc | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 332 | |
Ted Kremenek | 326be56 | 2010-01-25 05:19:37 +0000 | [diff] [blame] | 333 | /// Discard all previously created LocationContext objects. |
| 334 | void clear(); |
| 335 | private: |
| 336 | template <typename LOC, typename DATA> |
| 337 | const LOC *getLocationContext(AnalysisContext *ctx, |
| 338 | const LocationContext *parent, |
| 339 | const DATA *d); |
| 340 | }; |
| 341 | |
| 342 | } // end clang namespace |
| 343 | #endif |