From: Chris Lattner Date: Wed, 12 Dec 2007 07:30:05 +0000 (+0000) Subject: start cleaning up interfaces for objc bits and pieces by switching to an X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0157c5144513438bb74aebf50d18f95df4104acb;p=clang start cleaning up interfaces for objc bits and pieces by switching to an iterator interface. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44926 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Decl.cpp b/AST/Decl.cpp index 188f3255de..c71fbca348 100644 --- a/AST/Decl.cpp +++ b/AST/Decl.cpp @@ -406,8 +406,8 @@ ObjcIvarDecl *ObjcInterfaceDecl::lookupInstanceVariable( return NULL; } -// lookupInstanceMethod - This method returns an instance method by looking in -// the class, it's categories, and it's super classes (using a linear search). +/// lookupInstanceMethod - This method returns an instance method by looking in +/// the class, it's categories, and it's super classes (using a linear search). ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) { ObjcInterfaceDecl* ClassDecl = this; while (ClassDecl != NULL) { @@ -488,24 +488,20 @@ ObjcMethodDecl *ObjcInterfaceDecl::lookupClassMethod(Selector &Sel) { return NULL; } -// lookupInstanceMethod - This method returns an instance method by looking in -// the class implementation. Unlike interfaces, we don't look outside the -// implementation. -ObjcMethodDecl *ObjcImplementationDecl::lookupInstanceMethod(Selector &Sel) { - ObjcMethodDecl *const*methods = getInstanceMethods(); - int methodCount = getNumInstanceMethods(); - for (int i = 0; i < methodCount; ++i) { - if (methods[i]->getSelector() == Sel) { - return methods[i]; - } - } +/// lookupInstanceMethod - This method returns an instance method by looking in +/// the class implementation. Unlike interfaces, we don't look outside the +/// implementation. +ObjcMethodDecl *ObjcImplementationDecl::lookupInstanceMethod(Selector Sel) { + for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) + if ((*I)->getSelector() == Sel) + return *I; return NULL; } -// lookupClassMethod - This method returns an instance method by looking in -// the class implementation. Unlike interfaces, we don't look outside the -// implementation. -ObjcMethodDecl *ObjcImplementationDecl::lookupClassMethod(Selector &Sel) { +/// lookupClassMethod - This method returns a class method by looking in +/// the class implementation. Unlike interfaces, we don't look outside the +/// implementation. +ObjcMethodDecl *ObjcImplementationDecl::lookupClassMethod(Selector Sel) { ObjcMethodDecl *const*methods = getClassMethods(); int methodCount = getNumClassMethods(); for (int i = 0; i < methodCount; ++i) { diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 4a4bcf10db..d9d17b3678 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -589,12 +589,34 @@ public: } int getNumClassMethods() const { return ClassMethods.size(); } - ObjcMethodDecl *lookupInstanceMethod(Selector &Sel); - ObjcMethodDecl *lookupClassMethod(Selector &Sel); - ObjcIvarDecl **getImplDeclIVars() const { return Ivars; } int getImplDeclNumIvars() const { return NumIvars; } - + + + typedef llvm::SmallVector::const_iterator + instmeth_iterator; + instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); } + instmeth_iterator instmeth_end() const { return InstanceMethods.end(); } + + typedef llvm::SmallVector::const_iterator + classmeth_iterator; + classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); } + classmeth_iterator classmeth_end() const { return ClassMethods.end(); } + + /// lookupInstanceMethod - This method returns an instance method by looking + /// in the class implementation. Unlike interfaces, we don't look outside the + /// implementation. + ObjcMethodDecl *lookupInstanceMethod(Selector Sel); + + /// lookupClassMethod - This method returns a class method by looking in + /// the class implementation. Unlike interfaces, we don't look outside the + /// implementation. + ObjcMethodDecl *lookupClassMethod(Selector Sel); + + typedef ObjcIvarDecl * const *ivar_iterator; + ivar_iterator ivar_begin() const { return Ivars; } + ivar_iterator ivar_end() const { return Ivars+NumIvars; } + static bool classof(const Decl *D) { return D->getKind() == ObjcImplementation; }