blob: 6b6f8ef2cc2896a8cfb18b40a64b29f708332308 [file] [log] [blame]
Ted Kremenek326be562010-01-25 05:19:37 +00001//=== 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//
David Blaikieba243b52011-11-09 06:07:30 +000010// This file defines AnalysisDeclContext, a class that manages the analysis
11// context data for path sensitive analysis.
Ted Kremenek326be562010-01-25 05:19:37 +000012//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_ANALYSIS_ANALYSISCONTEXT_H
16#define LLVM_CLANG_ANALYSIS_ANALYSISCONTEXT_H
17
18#include "clang/AST/Decl.h"
Ted Kremenek892697d2010-12-16 07:46:53 +000019#include "clang/AST/Expr.h"
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +000020#include "clang/Analysis/CFG.h"
Ted Kremenek326be562010-01-25 05:19:37 +000021#include "llvm/ADT/OwningPtr.h"
Ted Kremenekbc5cb8a2011-07-21 05:22:47 +000022#include "llvm/ADT/IntrusiveRefCntPtr.h"
Ted Kremenek326be562010-01-25 05:19:37 +000023#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/PointerUnion.h"
25#include "llvm/ADT/DenseMap.h"
26#include "llvm/Support/Allocator.h"
27
28namespace clang {
29
30class Decl;
31class Stmt;
Ted Kremenekaf13d5b2011-03-19 01:00:33 +000032class CFGReverseBlockReachabilityAnalysis;
Ted Kremenek283a3582011-02-23 01:51:53 +000033class CFGStmtMap;
Ted Kremenek326be562010-01-25 05:19:37 +000034class LiveVariables;
Ted Kremeneka5937bb2011-10-07 22:21:02 +000035class ManagedAnalysis;
Ted Kremenek326be562010-01-25 05:19:37 +000036class ParentMap;
Tom Caredb34ab72010-08-23 19:51:57 +000037class PseudoConstantAnalysis;
Ted Kremenek326be562010-01-25 05:19:37 +000038class ImplicitParamDecl;
39class LocationContextManager;
40class StackFrameContext;
Ted Kremenek1d26f482011-10-24 01:32:45 +000041class AnalysisDeclContextManager;
David Blaikieba243b52011-11-09 06:07:30 +000042class LocationContext;
Ted Kremenekb1b5daf2011-10-23 02:31:52 +000043
Zhongxing Xuc6238d22010-07-19 01:31:21 +000044namespace idx { class TranslationUnit; }
45
Ted Kremeneka5937bb2011-10-07 22:21:02 +000046/// The base class of a hierarchy of objects representing analyses tied
Ted Kremenek1d26f482011-10-24 01:32:45 +000047/// to AnalysisDeclContext.
Ted Kremeneka5937bb2011-10-07 22:21:02 +000048class ManagedAnalysis {
49protected:
50 ManagedAnalysis() {}
51public:
52 virtual ~ManagedAnalysis();
David Blaikieba243b52011-11-09 06:07:30 +000053
Ted Kremeneka5937bb2011-10-07 22:21:02 +000054 // Subclasses need to implement:
55 //
56 // static const void *getTag();
57 //
58 // Which returns a fixed pointer address to distinguish classes of
59 // analysis objects. They also need to implement:
60 //
Ted Kremenek1d26f482011-10-24 01:32:45 +000061 // static [Derived*] create(AnalysisDeclContext &Ctx);
Ted Kremeneka5937bb2011-10-07 22:21:02 +000062 //
Ted Kremenek1d26f482011-10-24 01:32:45 +000063 // which creates the analysis object given an AnalysisDeclContext.
Ted Kremeneka5937bb2011-10-07 22:21:02 +000064};
David Blaikieba243b52011-11-09 06:07:30 +000065
66
67/// AnalysisDeclContext contains the context data for the function or method
68/// under analysis.
Ted Kremenek1d26f482011-10-24 01:32:45 +000069class AnalysisDeclContext {
David Blaikieba243b52011-11-09 06:07:30 +000070 /// Backpoint to the AnalysisManager object that created this
71 /// AnalysisDeclContext. This may be null.
Ted Kremenek1d26f482011-10-24 01:32:45 +000072 AnalysisDeclContextManager *Manager;
David Blaikieba243b52011-11-09 06:07:30 +000073
Ted Kremenek326be562010-01-25 05:19:37 +000074 const Decl *D;
75
Zhongxing Xuc6238d22010-07-19 01:31:21 +000076 // TranslationUnit is NULL if we don't have multiple translation units.
Zhongxing Xu2ce43c82010-07-22 13:52:13 +000077 idx::TranslationUnit *TU;
Zhongxing Xuc6238d22010-07-19 01:31:21 +000078
Dylan Noblesmith6f42b622012-02-05 02:12:40 +000079 OwningPtr<CFG> cfg, completeCFG;
80 OwningPtr<CFGStmtMap> cfgStmtMap;
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +000081
82 CFG::BuildOptions cfgBuildOptions;
83 CFG::BuildOptions::ForcedBlkExprs *forcedBlkExprs;
David Blaikieba243b52011-11-09 06:07:30 +000084
Ted Kremenekad5a8942010-08-02 23:46:59 +000085 bool builtCFG, builtCompleteCFG;
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +000086
Dylan Noblesmith6f42b622012-02-05 02:12:40 +000087 OwningPtr<LiveVariables> liveness;
88 OwningPtr<LiveVariables> relaxedLiveness;
89 OwningPtr<ParentMap> PM;
90 OwningPtr<PseudoConstantAnalysis> PCA;
91 OwningPtr<CFGReverseBlockReachabilityAnalysis> CFA;
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +000092
Ted Kremenek326be562010-01-25 05:19:37 +000093 llvm::BumpPtrAllocator A;
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +000094
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +000095 llvm::DenseMap<const BlockDecl*,void*> *ReferencedBlockVars;
96
Ted Kremeneka5937bb2011-10-07 22:21:02 +000097 void *ManagedAnalyses;
98
Ted Kremenek326be562010-01-25 05:19:37 +000099public:
Ted Kremenek1d26f482011-10-24 01:32:45 +0000100 AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000101 const Decl *D,
102 idx::TranslationUnit *TU);
Ted Kremenekbc5cb8a2011-07-21 05:22:47 +0000103
Ted Kremenek1d26f482011-10-24 01:32:45 +0000104 AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000105 const Decl *D,
106 idx::TranslationUnit *TU,
107 const CFG::BuildOptions &BuildOptions);
Ted Kremenek326be562010-01-25 05:19:37 +0000108
Ted Kremenek1d26f482011-10-24 01:32:45 +0000109 ~AnalysisDeclContext();
Ted Kremenek326be562010-01-25 05:19:37 +0000110
111 ASTContext &getASTContext() { return D->getASTContext(); }
Zhongxing Xuc6238d22010-07-19 01:31:21 +0000112 const Decl *getDecl() const { return D; }
113
Zhongxing Xu2ce43c82010-07-22 13:52:13 +0000114 idx::TranslationUnit *getTranslationUnit() const { return TU; }
Zhongxing Xuc6238d22010-07-19 01:31:21 +0000115
Ted Kremenek74fb1a42011-07-19 14:18:43 +0000116 /// Return the build options used to construct the CFG.
117 CFG::BuildOptions &getCFGBuildOptions() {
118 return cfgBuildOptions;
119 }
120
121 const CFG::BuildOptions &getCFGBuildOptions() const {
122 return cfgBuildOptions;
123 }
David Blaikieba243b52011-11-09 06:07:30 +0000124
Ted Kremenek326be562010-01-25 05:19:37 +0000125 /// getAddEHEdges - Return true iff we are adding exceptional edges from
126 /// callExprs. If this is false, then try/catch statements and blocks
127 /// reachable from them can appear to be dead in the CFG, analysis passes must
128 /// cope with that.
David Blaikieba243b52011-11-09 06:07:30 +0000129 bool getAddEHEdges() const { return cfgBuildOptions.AddEHEdges; }
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000130 bool getUseUnoptimizedCFG() const {
Ted Kremenekbc5cb8a2011-07-21 05:22:47 +0000131 return !cfgBuildOptions.PruneTriviallyFalseEdges;
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000132 }
133 bool getAddImplicitDtors() const { return cfgBuildOptions.AddImplicitDtors; }
134 bool getAddInitializers() const { return cfgBuildOptions.AddInitializers; }
Ted Kremenek9b823e82010-08-03 00:09:51 +0000135
Ted Kremenek0d28d362011-03-10 03:50:34 +0000136 void registerForcedBlockExpression(const Stmt *stmt);
137 const CFGBlock *getBlockForRegisteredExpression(const Stmt *stmt);
David Blaikieba243b52011-11-09 06:07:30 +0000138
Anna Zaksa2d7e652011-09-19 23:17:48 +0000139 Stmt *getBody() const;
Ted Kremenek326be562010-01-25 05:19:37 +0000140 CFG *getCFG();
David Blaikieba243b52011-11-09 06:07:30 +0000141
Ted Kremenek283a3582011-02-23 01:51:53 +0000142 CFGStmtMap *getCFGStmtMap();
Anders Carlsson04eeba42011-01-16 22:05:23 +0000143
Ted Kremenekaf13d5b2011-03-19 01:00:33 +0000144 CFGReverseBlockReachabilityAnalysis *getCFGReachablityAnalysis();
David Blaikieba243b52011-11-09 06:07:30 +0000145
Ted Kremenekad5a8942010-08-02 23:46:59 +0000146 /// Return a version of the CFG without any edges pruned.
147 CFG *getUnoptimizedCFG();
148
Ted Kremenek682060c2011-12-22 23:33:52 +0000149 void dumpCFG(bool ShowColors);
Anders Carlsson04eeba42011-01-16 22:05:23 +0000150
Chandler Carruth5d989942011-07-06 16:21:37 +0000151 /// \brief Returns true if we have built a CFG for this analysis context.
152 /// Note that this doesn't correspond to whether or not a valid CFG exists, it
153 /// corresponds to whether we *attempted* to build one.
154 bool isCFGBuilt() const { return builtCFG; }
155
Ted Kremenek326be562010-01-25 05:19:37 +0000156 ParentMap &getParentMap();
Tom Caredb34ab72010-08-23 19:51:57 +0000157 PseudoConstantAnalysis *getPseudoConstantAnalysis();
Ted Kremenek326be562010-01-25 05:19:37 +0000158
159 typedef const VarDecl * const * referenced_decls_iterator;
160
161 std::pair<referenced_decls_iterator, referenced_decls_iterator>
162 getReferencedBlockVars(const BlockDecl *BD);
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000163
Ted Kremenek326be562010-01-25 05:19:37 +0000164 /// Return the ImplicitParamDecl* associated with 'self' if this
Ted Kremenek1d26f482011-10-24 01:32:45 +0000165 /// AnalysisDeclContext wraps an ObjCMethodDecl. Returns NULL otherwise.
Ted Kremenek326be562010-01-25 05:19:37 +0000166 const ImplicitParamDecl *getSelfDecl() const;
David Blaikieba243b52011-11-09 06:07:30 +0000167
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000168 const StackFrameContext *getStackFrame(LocationContext const *Parent,
169 const Stmt *S,
170 const CFGBlock *Blk,
David Blaikieba243b52011-11-09 06:07:30 +0000171 unsigned Idx);
172
Ted Kremeneka5937bb2011-10-07 22:21:02 +0000173 /// Return the specified analysis object, lazily running the analysis if
174 /// necessary. Return NULL if the analysis could not run.
175 template <typename T>
176 T *getAnalysis() {
177 const void *tag = T::getTag();
178 ManagedAnalysis *&data = getAnalysisImpl(tag);
179 if (!data) {
180 data = T::create(*this);
181 }
182 return static_cast<T*>(data);
183 }
184private:
185 ManagedAnalysis *&getAnalysisImpl(const void* tag);
David Blaikieba243b52011-11-09 06:07:30 +0000186
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000187 LocationContextManager &getLocationContextManager();
Ted Kremenek326be562010-01-25 05:19:37 +0000188};
189
190class LocationContext : public llvm::FoldingSetNode {
191public:
192 enum ContextKind { StackFrame, Scope, Block };
193
194private:
195 ContextKind Kind;
Zhongxing Xua02d8932010-07-20 02:14:22 +0000196
David Blaikieba243b52011-11-09 06:07:30 +0000197 // AnalysisDeclContext can't be const since some methods may modify its
198 // member.
Ted Kremenek1d26f482011-10-24 01:32:45 +0000199 AnalysisDeclContext *Ctx;
Zhongxing Xua02d8932010-07-20 02:14:22 +0000200
Ted Kremenek326be562010-01-25 05:19:37 +0000201 const LocationContext *Parent;
202
203protected:
Ted Kremenek1d26f482011-10-24 01:32:45 +0000204 LocationContext(ContextKind k, AnalysisDeclContext *ctx,
Ted Kremenek326be562010-01-25 05:19:37 +0000205 const LocationContext *parent)
206 : Kind(k), Ctx(ctx), Parent(parent) {}
207
208public:
209 virtual ~LocationContext();
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000210
Ted Kremenek326be562010-01-25 05:19:37 +0000211 ContextKind getKind() const { return Kind; }
212
Ted Kremenek1d26f482011-10-24 01:32:45 +0000213 AnalysisDeclContext *getAnalysisDeclContext() const { return Ctx; }
Ted Kremenek326be562010-01-25 05:19:37 +0000214
David Blaikieba243b52011-11-09 06:07:30 +0000215 idx::TranslationUnit *getTranslationUnit() const {
216 return Ctx->getTranslationUnit();
Zhongxing Xuc6238d22010-07-19 01:31:21 +0000217 }
218
Ted Kremenek326be562010-01-25 05:19:37 +0000219 const LocationContext *getParent() const { return Parent; }
220
Zhongxing Xu8ddf7ce2010-02-17 08:45:06 +0000221 bool isParentOf(const LocationContext *LC) const;
222
Ted Kremenek1d26f482011-10-24 01:32:45 +0000223 const Decl *getDecl() const { return getAnalysisDeclContext()->getDecl(); }
Ted Kremenek326be562010-01-25 05:19:37 +0000224
Ted Kremenek1d26f482011-10-24 01:32:45 +0000225 CFG *getCFG() const { return getAnalysisDeclContext()->getCFG(); }
Ted Kremenek326be562010-01-25 05:19:37 +0000226
Ted Kremeneka5937bb2011-10-07 22:21:02 +0000227 template <typename T>
228 T *getAnalysis() const {
Ted Kremenek1d26f482011-10-24 01:32:45 +0000229 return getAnalysisDeclContext()->getAnalysis<T>();
Ted Kremenek326be562010-01-25 05:19:37 +0000230 }
231
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000232 ParentMap &getParentMap() const {
Ted Kremenek1d26f482011-10-24 01:32:45 +0000233 return getAnalysisDeclContext()->getParentMap();
Ted Kremenek326be562010-01-25 05:19:37 +0000234 }
235
236 const ImplicitParamDecl *getSelfDecl() const {
237 return Ctx->getSelfDecl();
238 }
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000239
Ted Kremenek326be562010-01-25 05:19:37 +0000240 const StackFrameContext *getCurrentStackFrame() const;
241 const StackFrameContext *
242 getStackFrameForDeclContext(const DeclContext *DC) const;
243
244 virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
245
246 static bool classof(const LocationContext*) { return true; }
247
248public:
249 static void ProfileCommon(llvm::FoldingSetNodeID &ID,
250 ContextKind ck,
Ted Kremenek1d26f482011-10-24 01:32:45 +0000251 AnalysisDeclContext *ctx,
Ted Kremenek326be562010-01-25 05:19:37 +0000252 const LocationContext *parent,
Ted Kremenek9c378f72011-08-12 23:37:29 +0000253 const void *data);
Ted Kremenek326be562010-01-25 05:19:37 +0000254};
255
256class StackFrameContext : public LocationContext {
Zhongxing Xu26c9cb52011-01-10 11:28:29 +0000257 // The callsite where this stack frame is established.
Ted Kremenek892697d2010-12-16 07:46:53 +0000258 const Stmt *CallSite;
Ted Kremenek326be562010-01-25 05:19:37 +0000259
260 // The parent block of the callsite.
261 const CFGBlock *Block;
262
263 // The index of the callsite in the CFGBlock.
264 unsigned Index;
265
266 friend class LocationContextManager;
Ted Kremenek1d26f482011-10-24 01:32:45 +0000267 StackFrameContext(AnalysisDeclContext *ctx, const LocationContext *parent,
David Blaikieba243b52011-11-09 06:07:30 +0000268 const Stmt *s, const CFGBlock *blk,
Zhongxing Xud7064342010-11-24 13:08:51 +0000269 unsigned idx)
Ted Kremenek892697d2010-12-16 07:46:53 +0000270 : LocationContext(StackFrame, ctx, parent), CallSite(s),
Zhongxing Xud7064342010-11-24 13:08:51 +0000271 Block(blk), Index(idx) {}
Ted Kremenek326be562010-01-25 05:19:37 +0000272
273public:
274 ~StackFrameContext() {}
275
Ted Kremenek892697d2010-12-16 07:46:53 +0000276 const Stmt *getCallSite() const { return CallSite; }
Zhongxing Xud7064342010-11-24 13:08:51 +0000277
Ted Kremenek326be562010-01-25 05:19:37 +0000278 const CFGBlock *getCallSiteBlock() const { return Block; }
279
280 unsigned getIndex() const { return Index; }
281
282 void Profile(llvm::FoldingSetNodeID &ID);
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000283
Ted Kremenek1d26f482011-10-24 01:32:45 +0000284 static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx,
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000285 const LocationContext *parent, const Stmt *s,
Ted Kremenek892697d2010-12-16 07:46:53 +0000286 const CFGBlock *blk, unsigned idx) {
Ted Kremenek326be562010-01-25 05:19:37 +0000287 ProfileCommon(ID, StackFrame, ctx, parent, s);
288 ID.AddPointer(blk);
289 ID.AddInteger(idx);
290 }
291
Ted Kremenek9c378f72011-08-12 23:37:29 +0000292 static bool classof(const LocationContext *Ctx) {
Ted Kremenek326be562010-01-25 05:19:37 +0000293 return Ctx->getKind() == StackFrame;
294 }
295};
296
297class ScopeContext : public LocationContext {
298 const Stmt *Enter;
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000299
Ted Kremenek326be562010-01-25 05:19:37 +0000300 friend class LocationContextManager;
Ted Kremenek1d26f482011-10-24 01:32:45 +0000301 ScopeContext(AnalysisDeclContext *ctx, const LocationContext *parent,
Ted Kremenek326be562010-01-25 05:19:37 +0000302 const Stmt *s)
303 : LocationContext(Scope, ctx, parent), Enter(s) {}
304
305public:
306 ~ScopeContext() {}
307
308 void Profile(llvm::FoldingSetNodeID &ID);
309
Ted Kremenek1d26f482011-10-24 01:32:45 +0000310 static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx,
Ted Kremenek326be562010-01-25 05:19:37 +0000311 const LocationContext *parent, const Stmt *s) {
312 ProfileCommon(ID, Scope, ctx, parent, s);
313 }
314
Ted Kremenek9c378f72011-08-12 23:37:29 +0000315 static bool classof(const LocationContext *Ctx) {
Ted Kremenek326be562010-01-25 05:19:37 +0000316 return Ctx->getKind() == Scope;
317 }
318};
319
320class BlockInvocationContext : public LocationContext {
321 // FIXME: Add back context-sensivity (we don't want libAnalysis to know
322 // about MemRegion).
323 const BlockDecl *BD;
324
325 friend class LocationContextManager;
326
David Blaikieba243b52011-11-09 06:07:30 +0000327 BlockInvocationContext(AnalysisDeclContext *ctx,
328 const LocationContext *parent,
Ted Kremenek326be562010-01-25 05:19:37 +0000329 const BlockDecl *bd)
330 : LocationContext(Block, ctx, parent), BD(bd) {}
331
332public:
333 ~BlockInvocationContext() {}
334
335 const BlockDecl *getBlockDecl() const { return BD; }
336
337 void Profile(llvm::FoldingSetNodeID &ID);
338
Ted Kremenek1d26f482011-10-24 01:32:45 +0000339 static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx,
Ted Kremenek326be562010-01-25 05:19:37 +0000340 const LocationContext *parent, const BlockDecl *bd) {
341 ProfileCommon(ID, Block, ctx, parent, bd);
342 }
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000343
Ted Kremenek9c378f72011-08-12 23:37:29 +0000344 static bool classof(const LocationContext *Ctx) {
Ted Kremenek326be562010-01-25 05:19:37 +0000345 return Ctx->getKind() == Block;
346 }
347};
348
349class LocationContextManager {
350 llvm::FoldingSet<LocationContext> Contexts;
351public:
352 ~LocationContextManager();
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000353
Ted Kremenek1d26f482011-10-24 01:32:45 +0000354 const StackFrameContext *getStackFrame(AnalysisDeclContext *ctx,
Ted Kremenek326be562010-01-25 05:19:37 +0000355 const LocationContext *parent,
Ted Kremenek892697d2010-12-16 07:46:53 +0000356 const Stmt *s,
Zhongxing Xud7064342010-11-24 13:08:51 +0000357 const CFGBlock *blk, unsigned idx);
Ted Kremenek326be562010-01-25 05:19:37 +0000358
Ted Kremenek1d26f482011-10-24 01:32:45 +0000359 const ScopeContext *getScope(AnalysisDeclContext *ctx,
Ted Kremenek326be562010-01-25 05:19:37 +0000360 const LocationContext *parent,
361 const Stmt *s);
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000362
Ted Kremenek326be562010-01-25 05:19:37 +0000363 /// Discard all previously created LocationContext objects.
364 void clear();
365private:
366 template <typename LOC, typename DATA>
Ted Kremenek1d26f482011-10-24 01:32:45 +0000367 const LOC *getLocationContext(AnalysisDeclContext *ctx,
Ted Kremenek326be562010-01-25 05:19:37 +0000368 const LocationContext *parent,
369 const DATA *d);
370};
371
Ted Kremenek1d26f482011-10-24 01:32:45 +0000372class AnalysisDeclContextManager {
373 typedef llvm::DenseMap<const Decl*, AnalysisDeclContext*> ContextMap;
David Blaikieba243b52011-11-09 06:07:30 +0000374
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000375 ContextMap Contexts;
376 LocationContextManager LocContexts;
377 CFG::BuildOptions cfgBuildOptions;
David Blaikieba243b52011-11-09 06:07:30 +0000378
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000379public:
Ted Kremenek1d26f482011-10-24 01:32:45 +0000380 AnalysisDeclContextManager(bool useUnoptimizedCFG = false,
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000381 bool addImplicitDtors = false,
382 bool addInitializers = false);
David Blaikieba243b52011-11-09 06:07:30 +0000383
Ted Kremenek1d26f482011-10-24 01:32:45 +0000384 ~AnalysisDeclContextManager();
David Blaikieba243b52011-11-09 06:07:30 +0000385
Ted Kremenek1d26f482011-10-24 01:32:45 +0000386 AnalysisDeclContext *getContext(const Decl *D, idx::TranslationUnit *TU = 0);
David Blaikieba243b52011-11-09 06:07:30 +0000387
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000388 bool getUseUnoptimizedCFG() const {
389 return !cfgBuildOptions.PruneTriviallyFalseEdges;
390 }
David Blaikieba243b52011-11-09 06:07:30 +0000391
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000392 CFG::BuildOptions &getCFGBuildOptions() {
393 return cfgBuildOptions;
394 }
David Blaikieba243b52011-11-09 06:07:30 +0000395
Ted Kremenek1d26f482011-10-24 01:32:45 +0000396 const StackFrameContext *getStackFrame(AnalysisDeclContext *Ctx,
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000397 LocationContext const *Parent,
398 const Stmt *S,
399 const CFGBlock *Blk,
400 unsigned Idx) {
401 return LocContexts.getStackFrame(Ctx, Parent, S, Blk, Idx);
402 }
David Blaikieba243b52011-11-09 06:07:30 +0000403
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000404 // Get the top level stack frame.
David Blaikieba243b52011-11-09 06:07:30 +0000405 const StackFrameContext *getStackFrame(Decl const *D,
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000406 idx::TranslationUnit *TU) {
407 return LocContexts.getStackFrame(getContext(D, TU), 0, 0, 0, 0);
408 }
David Blaikieba243b52011-11-09 06:07:30 +0000409
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000410 // Get a stack frame with parent.
David Blaikieba243b52011-11-09 06:07:30 +0000411 StackFrameContext const *getStackFrame(const Decl *D,
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000412 LocationContext const *Parent,
413 const Stmt *S,
414 const CFGBlock *Blk,
415 unsigned Idx) {
416 return LocContexts.getStackFrame(getContext(D), Parent, S, Blk, Idx);
417 }
418
David Blaikieba243b52011-11-09 06:07:30 +0000419
Ted Kremenek1d26f482011-10-24 01:32:45 +0000420 /// Discard all previously created AnalysisDeclContexts.
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000421 void clear();
422
423private:
Ted Kremenek1d26f482011-10-24 01:32:45 +0000424 friend class AnalysisDeclContext;
Ted Kremenekb1b5daf2011-10-23 02:31:52 +0000425
426 LocationContextManager &getLocationContextManager() {
427 return LocContexts;
428 }
429};
430
Ted Kremenek326be562010-01-25 05:19:37 +0000431} // end clang namespace
432#endif