From cc1ccb74c8675a6379d9363433e843a8d78ccf5c Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 18 Jul 2009 00:33:46 +0000 Subject: [PATCH] Make ASTLocation accept a Stmt that is inside an ObjCMethodDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76271 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/ASTLocation.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Index/ASTLocation.cpp b/lib/Index/ASTLocation.cpp index 41846055da..f73ddc087a 100644 --- a/lib/Index/ASTLocation.cpp +++ b/lib/Index/ASTLocation.cpp @@ -13,6 +13,7 @@ #include "clang/Index/ASTLocation.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/Stmt.h" #include "clang/AST/Expr.h" using namespace clang; @@ -42,7 +43,7 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) { return 0; return isContainedInStatement(Node, Init) ? D : 0; } - + if (FunctionDecl *FD = dyn_cast(D)) { if (!FD->isThisDeclarationADefinition()) return 0; @@ -53,11 +54,26 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) { if (Child) return Child; } - + assert(FD->getBody() && "If not definition we should have exited already"); return isContainedInStatement(Node, FD->getBody()) ? D : 0; } - + + if (ObjCMethodDecl *MD = dyn_cast(D)) { + if (!MD->getBody()) + return 0; + + for (DeclContext::decl_iterator + I = MD->decls_begin(), E = MD->decls_end(); I != E; ++I) { + Decl *Child = FindImmediateParent(*I, Node); + if (Child) + return Child; + } + + assert(MD->getBody() && "If not definition we should have exited already"); + return isContainedInStatement(Node, MD->getBody()) ? D : 0; + } + return 0; } -- 2.50.1