diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-23 01:02:12 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-23 01:02:12 +0000 |
commit | 653f1b1bf293a9bd96fd4dd6372e779cc7af1597 (patch) | |
tree | 8f4f4bbb5f2d6fa627550d8d8c94d5ec5e059b39 /lib/AST/DeclObjC.cpp | |
parent | 70e5a14c6076d63833c62d1d6d628c26309897c1 (diff) |
Eliminate the three SmallVectors in ObjCImplDecl (for instance
methods, class methods, and property implementations) and instead
place all of these entities into the DeclContext.
This eliminates more linear walks when looking for class or instance
methods and should make PCH (de-)serialization of ObjCDecls trivial
(and lazy).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69849 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclObjC.cpp')
-rw-r--r-- | lib/AST/DeclObjC.cpp | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 1e05eb6141..3bffbf54ac 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -541,13 +541,20 @@ ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, } +void ObjCImplDecl::addPropertyImplementation(ASTContext &Context, + ObjCPropertyImplDecl *property) { + property->setLexicalDeclContext(this); + addDecl(Context, property); +} + /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of /// properties implemented in this category @implementation block and returns /// the implemented property that uses it. /// ObjCPropertyImplDecl *ObjCImplDecl:: -FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { - for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ +FindPropertyImplIvarDecl(ASTContext &Context, IdentifierInfo *ivarId) const { + for (propimpl_iterator i = propimpl_begin(Context), e = propimpl_end(Context); + i != e; ++i){ ObjCPropertyImplDecl *PID = *i; if (PID->getPropertyIvarDecl() && PID->getPropertyIvarDecl()->getIdentifier() == ivarId) @@ -561,8 +568,9 @@ FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { /// category @implementation block. /// ObjCPropertyImplDecl *ObjCImplDecl:: -FindPropertyImplDecl(IdentifierInfo *Id) const { - for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ +FindPropertyImplDecl(ASTContext &Context, IdentifierInfo *Id) const { + for (propimpl_iterator i = propimpl_begin(Context), e = propimpl_end(Context); + i != e; ++i){ ObjCPropertyImplDecl *PID = *i; if (PID->getPropertyDecl()->getIdentifier() == Id) return PID; @@ -573,22 +581,47 @@ FindPropertyImplDecl(IdentifierInfo *Id) const { // getInstanceMethod - This method returns an instance method by looking in // the class implementation. Unlike interfaces, we don't look outside the // implementation. -ObjCMethodDecl *ObjCImplDecl::getInstanceMethod(Selector Sel) const { - for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) - if ((*I)->getSelector() == Sel) - return *I; - return NULL; +ObjCMethodDecl *ObjCImplDecl::getInstanceMethod(ASTContext &Context, + Selector Sel) const { + // Since instance & class methods can have the same name, the loop below + // ensures we get the correct method. + // + // @interface Whatever + // - (int) class_method; + // + (float) class_method; + // @end + // + lookup_const_iterator Meth, MethEnd; + for (llvm::tie(Meth, MethEnd) = lookup(Context, Sel); + Meth != MethEnd; ++Meth) { + ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); + if (MD && MD->isInstanceMethod()) + return MD; + } + return 0; } // getClassMethod - This method returns an instance method by looking in // the class implementation. Unlike interfaces, we don't look outside the // implementation. -ObjCMethodDecl *ObjCImplDecl::getClassMethod(Selector Sel) const { - for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); - I != E; ++I) - if ((*I)->getSelector() == Sel) - return *I; - return NULL; +ObjCMethodDecl *ObjCImplDecl::getClassMethod(ASTContext &Context, + Selector Sel) const { + // Since instance & class methods can have the same name, the loop below + // ensures we get the correct method. + // + // @interface Whatever + // - (int) class_method; + // + (float) class_method; + // @end + // + lookup_const_iterator Meth, MethEnd; + for (llvm::tie(Meth, MethEnd) = lookup(Context, Sel); + Meth != MethEnd; ++Meth) { + ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); + if (MD && MD->isClassMethod()) + return MD; + } + return 0; } //===----------------------------------------------------------------------===// |