]> granicus.if.org Git - clang/commitdiff
Add helper for extracting the CXXRecordDecl for the implicit argument to
authorChandler Carruth <chandlerc@gmail.com>
Wed, 27 Oct 2010 06:55:41 +0000 (06:55 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 27 Oct 2010 06:55:41 +0000 (06:55 +0000)
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

include/clang/AST/ExprCXX.h
lib/AST/ExprCXX.cpp

index b9ab813a7dc84f252db667087dead505f0f705be..a0a059ef95b5b45da8c8e09ab9fe6cfb1bd22f54 100644 (file)
@@ -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) {
index 0cdf8dd075d6f4b2029c092c33e8b0f22389c7e5..1e0691830aa8ba6a9b1773d6f6495b53a74da106 100644 (file)
@@ -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)