[cfe-commits] r76164 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Analysis/CFG.cpp lib/Analysis/CallGraph.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Fri Jul 17 00:29:52 PDT 2009
Author: zhongxingxu
Date: Fri Jul 17 02:29:51 2009
New Revision: 76164
URL: http://llvm.org/viewvc/llvm-project?rev=76164&view=rev
Log:
Refactor code into a new CallExpr::getDirectCallee() method. Simplify some
code with the new method.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Analysis/CallGraph.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=76164&r1=76163&r2=76164&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Jul 17 02:29:51 2009
@@ -964,7 +964,10 @@
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; }
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=76164&r1=76163&r2=76164&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Jul 17 02:29:51 2009
@@ -224,6 +224,16 @@
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.
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=76164&r1=76163&r2=76164&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Fri Jul 17 02:29:51 2009
@@ -475,14 +475,9 @@
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;
Modified: cfe/trunk/lib/Analysis/CallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CallGraph.cpp?rev=76164&r1=76163&r2=76164&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CallGraph.cpp (original)
+++ cfe/trunk/lib/Analysis/CallGraph.cpp Fri Jul 17 02:29:51 2009
@@ -66,21 +66,10 @@
}
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);
}
}
More information about the cfe-commits
mailing list