diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2010-10-27 06:55:41 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2010-10-27 06:55:41 +0000 |
commit | 007a9b1c632bfaac20e41c60cbe07fdc6d0e647c (patch) | |
tree | 720ace3eba0c42e697d8917d4bf2fe919cae030f | |
parent | a1898ddd5d0e46330898930b9185b628b5cede63 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117439 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/ExprCXX.h | 7 | ||||
-rw-r--r-- | lib/AST/ExprCXX.cpp | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index b9ab813a7d..a0a059ef95 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -100,6 +100,13 @@ public: /// 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) { diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 0cdf8dd075..1e0691830a 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -385,6 +385,17 @@ Expr *CXXMemberCallExpr::getImplicitObjectArgument() { 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) |