зеркало из https://github.com/microsoft/clang-1.git
Refactor LocationContext creation logic into a single member template.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90509 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
dc0d909f0f
Коммит
0ee4124012
|
@ -29,6 +29,7 @@ class CFG;
|
|||
class LiveVariables;
|
||||
class ParentMap;
|
||||
class ImplicitParamDecl;
|
||||
class LocationContextManager;
|
||||
|
||||
/// AnalysisContext contains the context data for the function or method under
|
||||
/// analysis.
|
||||
|
@ -91,7 +92,7 @@ protected:
|
|||
: Kind(k), Ctx(ctx), Parent(parent) {}
|
||||
|
||||
public:
|
||||
virtual ~LocationContext() {}
|
||||
virtual ~LocationContext();
|
||||
|
||||
ContextKind getKind() const { return Kind; }
|
||||
|
||||
|
@ -115,16 +116,11 @@ public:
|
|||
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 @@ protected:
|
|||
|
||||
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 @@ public:
|
|||
|
||||
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 @@ public:
|
|||
|
||||
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 @@ public:
|
|||
|
||||
class LocationContextManager {
|
||||
llvm::FoldingSet<LocationContext> Contexts;
|
||||
|
||||
public:
|
||||
~LocationContextManager();
|
||||
|
||||
StackFrameContext *getStackFrame(AnalysisContext *ctx,
|
||||
const LocationContext *parent,
|
||||
const Stmt *s);
|
||||
const StackFrameContext *getStackFrame(AnalysisContext *ctx,
|
||||
const LocationContext *parent,
|
||||
const Stmt *s);
|
||||
|
||||
ScopeContext *getScope(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
|
||||
|
|
|
@ -132,7 +132,7 @@ public:
|
|||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,20 +84,14 @@ AnalysisContext *AnalysisContextManager::getContext(const Decl *D) {
|
|||
// 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 @@ void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
|
|||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// 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;
|
||||
const ScopeContext *
|
||||
LocationContextManager::getScope(AnalysisContext *ctx,
|
||||
const LocationContext *parent,
|
||||
const Stmt *s) {
|
||||
return getLocationContext<ScopeContext, Stmt>(ctx, parent, s);
|
||||
}
|
||||
|
||||
ScopeContext *scope =
|
||||
cast_or_null<ScopeContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
|
||||
|
||||
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 @@ AnalysisContextManager::~AnalysisContextManager() {
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче