[cfe-commits] r77961 - in /cfe/trunk: include/clang/Analysis/PathSensitive/AnalysisContext.h include/clang/Analysis/PathSensitive/AnalysisManager.h lib/Analysis/AnalysisContext.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Mon Aug 3 00:23:23 PDT 2009
Author: zhongxingxu
Date: Mon Aug 3 02:23:22 2009
New Revision: 77961
URL: http://llvm.org/viewvc/llvm-project?rev=77961&view=rev
Log:
add a bunch of routine methods to AnalysisContext.
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=77961&r1=77960&r2=77961&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h Mon Aug 3 02:23:22 2009
@@ -65,32 +65,77 @@
private:
ContextKind Kind;
- LocationContext *Parent;
AnalysisContext *Ctx;
+ LocationContext *Parent;
protected:
- LocationContext(ContextKind k, LocationContext *parent, AnalysisContext *ctx)
- : Kind(k), Parent(parent), Ctx(ctx) {}
+ LocationContext(ContextKind k, AnalysisContext *ctx, LocationContext *parent)
+ : Kind(k), Ctx(ctx), Parent(parent) {}
+
+public:
+ ContextKind getKind() const { return Kind; }
+
+ AnalysisContext *getAnalysisContext() const { return Ctx; }
+
+ LocationContext *getParent() const { return Parent; }
+
+ void Profile(llvm::FoldingSetNodeID &ID) {
+ Profile(ID, Kind, Ctx, Parent);
+ }
+
+ static void Profile(llvm::FoldingSetNodeID &ID, ContextKind k,
+ AnalysisContext *ctx, LocationContext *parent);
+
+ static bool classof(const LocationContext*) { return true; }
};
class StackFrameContext : public LocationContext {
Stmt *CallSite;
public:
- StackFrameContext(Stmt *s, LocationContext *parent, AnalysisContext *ctx)
- : LocationContext(StackFrame, parent, ctx), CallSite(s) {}
+ StackFrameContext(AnalysisContext *ctx, LocationContext *parent, Stmt *s)
+ : LocationContext(StackFrame, ctx, parent), CallSite(s) {}
+
+ void Profile(llvm::FoldingSetNodeID &ID) {
+ Profile(ID, getAnalysisContext(), getParent(), CallSite);
+ }
+
+ static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
+ LocationContext *parent, Stmt *s);
+
+ static bool classof(const LocationContext* Ctx) {
+ return Ctx->getKind() == StackFrame;
+ }
};
class ScopeContext : public LocationContext {
Stmt *Enter;
public:
- ScopeContext(Stmt *s, LocationContext *parent, AnalysisContext *ctx)
- : LocationContext(Scope, parent, ctx), Enter(s) {}
+ ScopeContext(AnalysisContext *ctx, LocationContext *parent, Stmt *s)
+ : LocationContext(Scope, ctx, parent), Enter(s) {}
+
+ void Profile(llvm::FoldingSetNodeID &ID) {
+ Profile(ID, getAnalysisContext(), getParent(), Enter);
+ }
+
+ static void Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
+ LocationContext *parent, Stmt *s);
+
+ static bool classof(const LocationContext* Ctx) {
+ return Ctx->getKind() == Scope;
+ }
};
class LocationContextManager {
llvm::FoldingSet<LocationContext> Contexts;
+
+public:
+ StackFrameContext *getStackFrame(AnalysisContext *ctx,LocationContext *parent,
+ Stmt *s);
+
+ ScopeContext *getScope(AnalysisContext *ctx,LocationContext *parent, Stmt *s);
+
};
}
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=77961&r1=77960&r2=77961&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h Mon Aug 3 02:23:22 2009
@@ -23,7 +23,9 @@
class AnalysisManager : public BugReporterData {
AnalysisContextManager ContextMgr;
- AnalysisContext *CurrentContext;
+ AnalysisContext *RootContext;
+
+ LocationContextManager LocCtxMgr;
ASTContext &Ctx;
Diagnostic &Diags;
@@ -57,7 +59,7 @@
VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
EagerlyAssume(eager), TrimGraph(trim) {
- CurrentContext = ContextMgr.getContext(d);
+ RootContext = ContextMgr.getContext(d);
}
AnalysisManager(ASTContext &ctx, Diagnostic &diags,
@@ -73,21 +75,21 @@
VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
EagerlyAssume(eager), TrimGraph(trim) {
- CurrentContext = 0;
+ RootContext = 0;
}
void setContext(Decl *D) {
- CurrentContext = ContextMgr.getContext(D);
+ RootContext = ContextMgr.getContext(D);
}
Decl *getCodeDecl() const {
assert (AScope == ScopeDecl);
- return CurrentContext->getDecl();
+ return RootContext->getDecl();
}
Stmt *getBody() const {
assert (AScope == ScopeDecl);
- return CurrentContext->getBody();
+ return RootContext->getBody();
}
StoreManagerCreator getStoreManagerCreator() {
@@ -99,15 +101,15 @@
}
virtual CFG *getCFG() {
- return CurrentContext->getCFG();
+ return RootContext->getCFG();
}
virtual ParentMap &getParentMap() {
- return CurrentContext->getParentMap();
+ return RootContext->getParentMap();
}
virtual LiveVariables *getLiveVariables() {
- return CurrentContext->getLiveVariables();
+ return RootContext->getLiveVariables();
}
virtual ASTContext &getContext() {
@@ -129,6 +131,10 @@
virtual PathDiagnosticClient *getPathDiagnosticClient() {
return PD.get();
}
+
+ StackFrameContext *getRootStackFrame() {
+ return LocCtxMgr.getStackFrame(RootContext, 0, 0);
+ }
bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=77961&r1=77960&r2=77961&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Mon Aug 3 02:23:22 2009
@@ -72,3 +72,53 @@
Ctx.setDecl(D);
return &Ctx;
}
+
+void LocationContext::Profile(llvm::FoldingSetNodeID &ID, ContextKind k,
+ AnalysisContext *ctx, LocationContext *parent) {
+ ID.AddInteger(k);
+ ID.AddPointer(ctx);
+ ID.AddPointer(parent);
+}
+
+void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID,AnalysisContext *ctx,
+ LocationContext *parent, Stmt *s) {
+ LocationContext::Profile(ID, StackFrame, ctx, parent);
+ ID.AddPointer(s);
+}
+
+void ScopeContext::Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
+ LocationContext *parent, Stmt *s) {
+ LocationContext::Profile(ID, Scope, ctx, parent);
+ ID.AddPointer(s);
+}
+
+StackFrameContext *LocationContextManager::getStackFrame(AnalysisContext *ctx,
+ LocationContext *parent, 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;
+}
+
+ScopeContext *LocationContextManager::getScope(AnalysisContext *ctx,
+ LocationContext *parent, Stmt *s) {
+ llvm::FoldingSetNodeID ID;
+ ScopeContext::Profile(ID, ctx, parent, s);
+ void *InsertPos;
+
+ ScopeContext *scope =
+ cast_or_null<ScopeContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
+
+ if (!scope) {
+ scope = new ScopeContext(ctx, parent, s);
+ Contexts.InsertNode(scope, InsertPos);
+ }
+ return scope;
+}
More information about the cfe-commits
mailing list