diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-21 00:06:36 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-21 00:06:36 +0000 |
commit | a8cf0beeef6fdf2f66ec3a0163ccb641181feaba (patch) | |
tree | d1ececcd058395265575a3749094f66dae27b5ec | |
parent | 60e9b7cf58f17ec8b05f3774eea0c7cccc49f364 (diff) | |
download | bcm5719-llvm-a8cf0beeef6fdf2f66ec3a0163ccb641181feaba.tar.gz bcm5719-llvm-a8cf0beeef6fdf2f66ec3a0163ccb641181feaba.zip |
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.
llvm-svn: 76512
-rw-r--r-- | clang/include/clang/AST/DeclObjC.h | 7 | ||||
-rw-r--r-- | clang/lib/AST/DeclObjC.cpp | 24 |
2 files changed, 30 insertions, 1 deletions
diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index 4242d8d8d0a..91c5c872690 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/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/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 7b86bfd195c..cd4c5c072e4 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/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<Decl>(getDeclContext()); + + if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { + if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) + Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); + + } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { + if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) + Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); + + } else if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(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; |