CallGraph:

- add IfStmt visitor.
 - print information only when a function has callee. Otherwise its ASTContext
   map is NULL.

llvm-svn: 76156
This commit is contained in:
Zhongxing Xu 2009-07-17 05:49:16 +00:00
parent aaf48343fb
commit 6c1b35a0ef
2 changed files with 14 additions and 6 deletions

View File

@ -43,6 +43,8 @@ public:
CalledFunctions.push_back(std::make_pair(L, Node));
}
bool hasCallee() const { return begin() != end(); }
const char *getName(ASTContext &Ctx) { return F->getName(Ctx); }
};

View File

@ -37,6 +37,10 @@ public:
VisitChildren(S);
}
void VisitIfStmt(IfStmt *S) {
VisitChildren(S);
}
void VisitCallExpr(CallExpr *CE);
void VisitChildren(Stmt *S) {
@ -106,13 +110,15 @@ CallGraphNode *CallGraph::getOrInsertFunction(Entity *F) {
void CallGraph::print(llvm::raw_ostream &os) {
for (iterator I = begin(), E = end(); I != E; ++I) {
ASTContext &Ctx = *CallerCtx[I->second];
os << "function: " << I->first->getName(Ctx) << " calls:\n";
for (CallGraphNode::iterator CI = I->second->begin(), CE = I->second->end();
CI != CE; ++CI) {
os << " " << CI->second->getName(Ctx);
if (I->second->hasCallee()) {
ASTContext &Ctx = *CallerCtx[I->second];
os << "function: " << I->first->getName(Ctx) << " calls:\n";
for (CallGraphNode::iterator CI = I->second->begin(),
CE = I->second->end(); CI != CE; ++CI) {
os << " " << CI->second->getName(Ctx);
}
os << '\n';
}
os << '\n';
}
}