From: Argyrios Kyrtzidis Date: Tue, 21 Jul 2009 00:06:36 +0000 (+0000) Subject: Implement the virtual getNextRedeclaration() for ObjCMethodDecl. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57ea6bee79cc60ba20c7886b453f40f380dce1b1;p=clang Implement the virtual getNextRedeclaration() for ObjCMethodDecl. If it's in an ObjCContainerDecl, its "redeclaration" is the method definition in the corresponding ObjCImplDecl. If it's in an ObjCImplDecl, its "redeclaration" is the method in the interface. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76512 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 4242d8d8d0..91c5c87269 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -154,7 +154,12 @@ private: EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {} virtual ~ObjCMethodDecl() {} - + + /// \brief A definition will return its interface declaration. + /// An interface declaration will return its definition. + /// Otherwise it will return itself. + virtual ObjCMethodDecl *getNextRedeclaration(); + public: /// Destroy - Call destructors and release memory. diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 7b86bfd195..cd4c5c072e 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -272,6 +272,30 @@ void ObjCMethodDecl::Destroy(ASTContext &C) { Decl::Destroy(C); } +/// \brief A definition will return its interface declaration. +/// An interface declaration will return its definition. +/// Otherwise it will return itself. +ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { + ASTContext &Ctx = getASTContext(); + ObjCMethodDecl *Redecl = 0; + Decl *CtxD = cast(getDeclContext()); + + if (ObjCInterfaceDecl *IFD = dyn_cast(CtxD)) { + if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) + Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); + + } else if (ObjCCategoryDecl *CD = dyn_cast(CtxD)) { + if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) + Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); + + } else if (ObjCImplDecl *ImplD = dyn_cast(CtxD)) { + if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) + Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); + } + + return Redecl ? Redecl : this; +} + void ObjCMethodDecl::createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *OID) { QualType selfTy;