[cfe-commits] r117439 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/AST/ExprCXX.cpp
Chandler Carruth
chandlerc at gmail.com
Tue Oct 26 23:55:41 PDT 2010
Author: chandlerc
Date: Wed Oct 27 01:55:41 2010
New Revision: 117439
URL: http://llvm.org/viewvc/llvm-project?rev=117439&view=rev
Log:
Add helper for extracting the CXXRecordDecl for the implicit argument to
a member call expression. This has proved to be a common pattern for users of
RecursiveASTVisitor.
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/lib/AST/ExprCXX.cpp
Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=117439&r1=117438&r2=117439&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Wed Oct 27 01:55:41 2010
@@ -100,6 +100,13 @@
/// operation would return "x".
Expr *getImplicitObjectArgument();
+ /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
+ /// the implicit object argument. Note that this is may not be the same
+ /// declaration as that of the class context of the CXXMethodDecl which this
+ /// function is calling.
+ /// FIXME: Returns 0 for member pointer call exprs.
+ CXXRecordDecl *getRecordDecl();
+
virtual SourceRange getSourceRange() const;
static bool classof(const Stmt *T) {
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=117439&r1=117438&r2=117439&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Wed Oct 27 01:55:41 2010
@@ -385,6 +385,17 @@
return 0;
}
+CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
+ Expr* ThisArg = getImplicitObjectArgument();
+ if (!ThisArg)
+ return 0;
+
+ if (ThisArg->getType()->isAnyPointerType())
+ return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
+
+ return ThisArg->getType()->getAsCXXRecordDecl();
+}
+
SourceRange CXXMemberCallExpr::getSourceRange() const {
SourceLocation LocStart = getCallee()->getLocStart();
if (LocStart.isInvalid() && getNumArgs() > 0)
More information about the cfe-commits
mailing list