[cfe-commits] r90509 - in /cfe/trunk: include/clang/Analysis/PathSensitive/AnalysisContext.h include/clang/Analysis/PathSensitive/AnalysisManager.h lib/Analysis/AnalysisContext.cpp
Ted Kremenek
kremenek at apple.com
Thu Dec 3 17:28:56 PST 2009
Author: kremenek
Date: Thu Dec 3 19:28:56 2009
New Revision: 90509
URL: http://llvm.org/viewvc/llvm-project?rev=90509&view=rev
Log:
Refactor LocationContext creation logic into a single member template.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h
cfe/trunk/lib/Analysis/AnalysisContext.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h?rev=90509&r1=90508&r2=90509&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h Thu Dec 3 19:28:56 2009
@@ -29,6 +29,7 @@
class LiveVariables;
class ParentMap;
class ImplicitParamDecl;
+class LocationContextManager;
/// AnalysisContext contains the context data for the function or method under
/// analysis.
@@ -91,7 +92,7 @@
: Kind(k), Ctx(ctx), Parent(parent) {}
public:
- virtual ~LocationContext() {}
+ virtual ~LocationContext();
ContextKind getKind() const { return Kind; }
@@ -115,16 +116,11 @@
return Ctx->getSelfDecl();
}
- virtual void Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, Kind, Ctx, Parent);
- }
-
- static void Profile(llvm::FoldingSetNodeID &ID, ContextKind k,
- AnalysisContext *ctx, const LocationContext *parent);
+ virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
static bool classof(const LocationContext*) { return true; }
-protected:
+public:
static void ProfileCommon(llvm::FoldingSetNodeID &ID,
ContextKind ck,
AnalysisContext *ctx,
@@ -134,15 +130,16 @@
class StackFrameContext : public LocationContext {
const Stmt *CallSite;
-public:
+
+ friend class LocationContextManager;
StackFrameContext(AnalysisContext *ctx, const LocationContext *parent,
const Stmt *s)
: LocationContext(StackFrame, ctx, parent), CallSite(s) {}
-
- virtual ~StackFrameContext() {}
+public:
+ ~StackFrameContext() {}
- Stmt const *getCallSite() const { return CallSite; }
+ const Stmt *getCallSite() const { return CallSite; }
void Profile(llvm::FoldingSetNodeID &ID);
@@ -158,12 +155,14 @@
class ScopeContext : public LocationContext {
const Stmt *Enter;
-public:
+
+ friend class LocationContextManager;
ScopeContext(AnalysisContext *ctx, const LocationContext *parent,
const Stmt *s)
: LocationContext(Scope, ctx, parent), Enter(s) {}
-
- virtual ~ScopeContext() {}
+
+public:
+ ~ScopeContext() {}
void Profile(llvm::FoldingSetNodeID &ID);
@@ -179,11 +178,13 @@
class BlockInvocationContext : public LocationContext {
const BlockDecl *BD;
-public:
- BlockInvocationContext(const BlockDecl *bd, AnalysisContext *ctx,
- const LocationContext *parent = 0)
+
+ friend class LocationContextManager;
+ BlockInvocationContext(AnalysisContext *ctx, const LocationContext *parent,
+ const BlockDecl *bd)
: LocationContext(Block, ctx, parent), BD(bd) {}
-
+
+public:
~BlockInvocationContext() {}
const BlockDecl *getBlockDecl() const { return BD; }
@@ -202,19 +203,28 @@
class LocationContextManager {
llvm::FoldingSet<LocationContext> Contexts;
-
public:
~LocationContextManager();
- StackFrameContext *getStackFrame(AnalysisContext *ctx,
- const LocationContext *parent,
- const Stmt *s);
-
- ScopeContext *getScope(AnalysisContext *ctx, const LocationContext *parent,
- const Stmt *s);
+ const StackFrameContext *getStackFrame(AnalysisContext *ctx,
+ const LocationContext *parent,
+ const Stmt *s);
+
+ const ScopeContext *getScope(AnalysisContext *ctx,
+ const LocationContext *parent,
+ const Stmt *s);
+
+ const BlockInvocationContext *
+ getBlockInvocation(AnalysisContext *ctx, const LocationContext *parent,
+ const BlockDecl *BD);
/// Discard all previously created LocationContext objects.
void clear();
+private:
+ template <typename LOC, typename DATA>
+ const LOC *getLocationContext(AnalysisContext *ctx,
+ const LocationContext *parent,
+ const DATA *d);
};
} // end clang namespace
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h?rev=90509&r1=90508&r2=90509&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h Thu Dec 3 19:28:56 2009
@@ -132,7 +132,7 @@
}
// Get the top level stack frame.
- StackFrameContext *getStackFrame(Decl const *D) {
+ const StackFrameContext *getStackFrame(Decl const *D) {
return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), 0, 0);
}
Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=90509&r1=90508&r2=90509&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Thu Dec 3 19:28:56 2009
@@ -84,20 +84,14 @@
// FoldingSet profiling.
//===----------------------------------------------------------------------===//
-void LocationContext::Profile(llvm::FoldingSetNodeID &ID, ContextKind k,
- AnalysisContext *ctx,
- const LocationContext *parent) {
- ID.AddInteger(k);
- ID.AddPointer(ctx);
- ID.AddPointer(parent);
-}
-
void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
ContextKind ck,
AnalysisContext *ctx,
const LocationContext *parent,
const void* data) {
- LocationContext::Profile(ID, ck, ctx, parent);
+ ID.AddInteger(ck);
+ ID.AddPointer(ctx);
+ ID.AddPointer(parent);
ID.AddPointer(data);
}
@@ -114,56 +108,46 @@
}
//===----------------------------------------------------------------------===//
-// Cleanup.
+// LocationContext creation.
//===----------------------------------------------------------------------===//
-LocationContextManager::~LocationContextManager() {
- clear();
-}
-
-void LocationContextManager::clear() {
- for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
- E = Contexts.end(); I != E; ) {
- LocationContext *LC = &*I;
- ++I;
- delete LC;
- }
+template <typename LOC, typename DATA>
+const LOC*
+LocationContextManager::getLocationContext(AnalysisContext *ctx,
+ const LocationContext *parent,
+ const DATA *d) {
+ llvm::FoldingSetNodeID ID;
+ LOC::Profile(ID, ctx, parent, d);
+ void *InsertPos;
- Contexts.clear();
+ LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
+
+ if (!L) {
+ L = new LOC(ctx, parent, d);
+ Contexts.InsertNode(L, InsertPos);
+ }
+ return L;
}
-StackFrameContext*
+const StackFrameContext*
LocationContextManager::getStackFrame(AnalysisContext *ctx,
const LocationContext *parent,
const Stmt *s) {
- llvm::FoldingSetNodeID ID;
- StackFrameContext::Profile(ID, ctx, parent, s);
- void *InsertPos;
-
- StackFrameContext *f =
- cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
- if (!f) {
- f = new StackFrameContext(ctx, parent, s);
- Contexts.InsertNode(f, InsertPos);
- }
- return f;
+ return getLocationContext<StackFrameContext, Stmt>(ctx, parent, s);
}
-ScopeContext *LocationContextManager::getScope(AnalysisContext *ctx,
- const LocationContext *parent,
- const Stmt *s) {
- llvm::FoldingSetNodeID ID;
- ScopeContext::Profile(ID, ctx, parent, s);
- void *InsertPos;
-
- ScopeContext *scope =
- cast_or_null<ScopeContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
+const ScopeContext *
+LocationContextManager::getScope(AnalysisContext *ctx,
+ const LocationContext *parent,
+ const Stmt *s) {
+ return getLocationContext<ScopeContext, Stmt>(ctx, parent, s);
+}
- if (!scope) {
- scope = new ScopeContext(ctx, parent, s);
- Contexts.InsertNode(scope, InsertPos);
- }
- return scope;
+const BlockInvocationContext *
+LocationContextManager::getBlockInvocation(AnalysisContext *ctx,
+ const LocationContext *parent,
+ const BlockDecl *BD) {
+ return getLocationContext<BlockInvocationContext, BlockDecl>(ctx, parent, BD);
}
//===----------------------------------------------------------------------===//
@@ -237,3 +221,21 @@
for (ContextMap::iterator I = Contexts.begin(), E = Contexts.end(); I!=E; ++I)
delete I->second;
}
+
+LocationContext::~LocationContext() {}
+
+LocationContextManager::~LocationContextManager() {
+ clear();
+}
+
+void LocationContextManager::clear() {
+ for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
+ E = Contexts.end(); I != E; ) {
+ LocationContext *LC = &*I;
+ ++I;
+ delete LC;
+ }
+
+ Contexts.clear();
+}
+
More information about the cfe-commits
mailing list