]> granicus.if.org Git - clang/commitdiff
Refactor code into a new CallExpr::getDirectCallee() method. Simplify some
authorZhongxing Xu <xuzhongxing@gmail.com>
Fri, 17 Jul 2009 07:29:51 +0000 (07:29 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Fri, 17 Jul 2009 07:29:51 +0000 (07:29 +0000)
code with the new method.

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

include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/Analysis/CFG.cpp
lib/Analysis/CallGraph.cpp

index 1fc35ba8d548149e2dbfcc50683016418f803495..9d967dec037c130922140357d0c2b2bad726136f 100644 (file)
@@ -964,7 +964,10 @@ public:
   const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
   Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
   void setCallee(Expr *F) { SubExprs[FN] = F; }
-  
+
+  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
+  FunctionDecl *getDirectCallee();
+
   /// getNumArgs - Return the number of actual arguments to this call.
   ///
   unsigned getNumArgs() const { return NumArgs; }
index 63a6d3153c742dbe104b0f7bb2e89e8e5111b75e..320a4f1f72e43d1dd6f423bcff4fd89eb446fac7 100644 (file)
@@ -224,6 +224,16 @@ void CallExpr::Destroy(ASTContext& C) {
   C.Deallocate(this);
 }
 
+FunctionDecl *CallExpr::getDirectCallee() {
+  Expr *CEE = getCallee()->IgnoreParenCasts();
+  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
+    // FIXME: We can follow objective-c methods and C++ member functions...
+    return dyn_cast<FunctionDecl>(DRE->getDecl());
+  }
+
+  return 0;
+}
+
 /// setNumArgs - This changes the number of arguments present in this call.
 /// Any orphaned expressions are deleted by this, and any new operands are set
 /// to null.
index 884bc177fdc839a05a48e5de4c8f260faf60465f..02fe22c00fea84925f22afd577e9c5fc7e2b5ef0 100644 (file)
@@ -475,14 +475,9 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) {
   case Stmt::CallExprClass: {
     bool NoReturn = false;
     CallExpr *C = cast<CallExpr>(Terminator);
-    Expr *CEE = C->getCallee()->IgnoreParenCasts();
-    if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
-      // FIXME: We can follow objective-c methods and C++ member functions...
-      if (FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
-        if (FD->hasAttr<NoReturnAttr>())
-          NoReturn = true;
-      }
-    }
+    if (FunctionDecl *FD = C->getDirectCallee())
+      if (FD->hasAttr<NoReturnAttr>())
+        NoReturn = true;
 
     if (!NoReturn)
       break;
index 16f14d787f4fcb961dc397a8f020cac4772e1311..d49e8ec11be00b5fecca08ceb4a78dceb494f254 100644 (file)
@@ -66,21 +66,10 @@ public:
 }
 
 void CGBuilder::VisitCallExpr(CallExpr *CE) {
-  Expr *Callee = CE->getCallee();
-
-  if (CastExpr *CE = dyn_cast<CastExpr>(Callee))
-    Callee = CE->getSubExpr();
-
-  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
-    Decl *D = DRE->getDecl();
-    if (FunctionDecl *CalleeDecl = dyn_cast<FunctionDecl>(D)) {
-
-      Entity *Ent = Entity::get(CalleeDecl, G.getProgram());
-
-      CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent);
-
-      CallerNode->addCallee(ASTLocation(FD, CE), CalleeNode);
-    }
+  if (FunctionDecl *CalleeDecl = CE->getDirectCallee()) {
+    Entity *Ent = Entity::get(CalleeDecl, G.getProgram());
+    CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent);
+    CallerNode->addCallee(ASTLocation(FD, CE), CalleeNode);
   }
 }