diff options
| author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-07-17 07:29:51 +0000 | 
|---|---|---|
| committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-07-17 07:29:51 +0000 | 
| commit | 3c8fa978adee9387a1e3a1f60e8fe5d6b9ccc14a (patch) | |
| tree | bdc1ee3e89b5bb4f4716372437fa259560b60651 /clang | |
| parent | 6a60a66b2be5b527ca46b9c381fd21d0e124be9e (diff) | |
| download | bcm5719-llvm-3c8fa978adee9387a1e3a1f60e8fe5d6b9ccc14a.tar.gz bcm5719-llvm-3c8fa978adee9387a1e3a1f60e8fe5d6b9ccc14a.zip  | |
Refactor code into a new CallExpr::getDirectCallee() method. Simplify some
code with the new method.
llvm-svn: 76164
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/Expr.h | 5 | ||||
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Analysis/CFG.cpp | 11 | ||||
| -rw-r--r-- | clang/lib/Analysis/CallGraph.cpp | 19 | 
4 files changed, 21 insertions, 24 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 1fc35ba8d54..9d967dec037 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -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; } diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 63a6d3153c7..320a4f1f72e 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -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. diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 884bc177fdc..02fe22c00fe 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -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; diff --git a/clang/lib/Analysis/CallGraph.cpp b/clang/lib/Analysis/CallGraph.cpp index 16f14d787f4..d49e8ec11be 100644 --- a/clang/lib/Analysis/CallGraph.cpp +++ b/clang/lib/Analysis/CallGraph.cpp @@ -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);    }  }  | 

