]> granicus.if.org Git - clang/commitdiff
CallGraph:
authorZhongxing Xu <xuzhongxing@gmail.com>
Fri, 17 Jul 2009 05:49:16 +0000 (05:49 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Fri, 17 Jul 2009 05:49:16 +0000 (05:49 +0000)
 - add IfStmt visitor.
 - print information only when a function has callee. Otherwise its ASTContext
   map is NULL.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76156 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/CallGraph.h
lib/Analysis/CallGraph.cpp

index bf164c0e726f9a4d7ed52c44bb53a3056a91b6e0..8de0e9f9764934622236545b0d5fe91db481b329 100644 (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); }
 };
 
index a296f60553244c7c10d1dfd4fa7933615fd88c82..422c5013cc8d3922b2f41c69c8e343d58a29f686 100644 (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';
   }
 }