r178374 - When looking for overridden ObjC methods, don't ignore 'hidden' ones.

Jordan Rose jordan_rose at apple.com
Fri Mar 29 14:54:56 PDT 2013


Test case?

On Mar 29, 2013, at 14:51 , Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:

> Author: akirtzidis
> Date: Fri Mar 29 16:51:48 2013
> New Revision: 178374
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=178374&view=rev
> Log:
> When looking for overridden ObjC methods, don't ignore 'hidden' ones.
> 
> When using modules we should not ignore overridden methods from
> categories that are hidden because the module is not visible.
> This will give more consistent results (when imports change) and it's more
> correct since the methods are indeed overridden even if they are not "visible"
> for lookup purposes.
> 
> rdar://13350796
> 
> Modified:
>    cfe/trunk/include/clang/AST/DeclObjC.h
>    cfe/trunk/lib/AST/DeclObjC.cpp
>    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> 
> Modified: cfe/trunk/include/clang/AST/DeclObjC.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=178374&r1=178373&r2=178374&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/DeclObjC.h (original)
> +++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Mar 29 16:51:48 2013
> @@ -537,12 +537,14 @@ public:
>   }
> 
>   // Get the local instance/class method declared in this interface.
> -  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const;
> -  ObjCMethodDecl *getInstanceMethod(Selector Sel) const {
> -    return getMethod(Sel, true/*isInstance*/);
> +  ObjCMethodDecl *getMethod(Selector Sel, bool isInstance,
> +                            bool AllowHidden = false) const;
> +  ObjCMethodDecl *getInstanceMethod(Selector Sel,
> +                                    bool AllowHidden = false) const {
> +    return getMethod(Sel, true/*isInstance*/, AllowHidden);
>   }
> -  ObjCMethodDecl *getClassMethod(Selector Sel) const {
> -    return getMethod(Sel, false/*isInstance*/);
> +  ObjCMethodDecl *getClassMethod(Selector Sel, bool AllowHidden = false) const {
> +    return getMethod(Sel, false/*isInstance*/, AllowHidden);
>   }
>   bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
>   ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
> 
> Modified: cfe/trunk/lib/AST/DeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=178374&r1=178373&r2=178374&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/DeclObjC.cpp (original)
> +++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Mar 29 16:51:48 2013
> @@ -65,12 +65,13 @@ ObjCContainerDecl::getIvarDecl(Identifie
> 
> // Get the local instance/class method declared in this interface.
> ObjCMethodDecl *
> -ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const {
> +ObjCContainerDecl::getMethod(Selector Sel, bool isInstance,
> +                             bool AllowHidden) const {
>   // If this context is a hidden protocol definition, don't find any
>   // methods there.
>   if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) {
>     if (const ObjCProtocolDecl *Def = Proto->getDefinition())
> -      if (Def->isHidden())
> +      if (Def->isHidden() && !AllowHidden)
>         return 0;
>   }
> 
> @@ -854,7 +855,8 @@ static void CollectOverriddenMethodsRecu
>     if (MovedToSuper)
>       if (ObjCMethodDecl *
>             Overridden = Container->getMethod(Method->getSelector(),
> -                                              Method->isInstanceMethod()))
> +                                              Method->isInstanceMethod(),
> +                                              /*AllowHidden=*/true))
>         if (Method != Overridden) {
>           // We found an override at this category; there is no need to look
>           // into its protocols.
> @@ -872,7 +874,8 @@ static void CollectOverriddenMethodsRecu
>   // Check whether we have a matching method at this level.
>   if (const ObjCMethodDecl *
>         Overridden = Container->getMethod(Method->getSelector(),
> -                                                    Method->isInstanceMethod()))
> +                                          Method->isInstanceMethod(),
> +                                          /*AllowHidden=*/true))
>     if (Method != Overridden) {
>       // We found an override at this level; there is no need to look
>       // into other protocols or categories.
> @@ -894,9 +897,9 @@ static void CollectOverriddenMethodsRecu
>          P != PEnd; ++P)
>       CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper);
> 
> -    for (ObjCInterfaceDecl::visible_categories_iterator
> -           Cat = Interface->visible_categories_begin(),
> -           CatEnd = Interface->visible_categories_end();
> +    for (ObjCInterfaceDecl::known_categories_iterator
> +           Cat = Interface->known_categories_begin(),
> +           CatEnd = Interface->known_categories_end();
>          Cat != CatEnd; ++Cat) {
>       CollectOverriddenMethodsRecurse(*Cat, Method, Methods,
>                                       MovedToSuper);
> @@ -931,7 +934,8 @@ static void collectOverriddenMethodsSlow
>     // Start searching for overridden methods using the method from the
>     // interface as starting point.
>     if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
> -                                                  Method->isInstanceMethod()))
> +                                                    Method->isInstanceMethod(),
> +                                                    /*AllowHidden=*/true))
>       Method = IFaceMeth;
>     CollectOverriddenMethods(ID, Method, overridden);
> 
> @@ -943,7 +947,8 @@ static void collectOverriddenMethodsSlow
>     // Start searching for overridden methods using the method from the
>     // interface as starting point.
>     if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
> -                                                  Method->isInstanceMethod()))
> +                                                     Method->isInstanceMethod(),
> +                                                     /*AllowHidden=*/true))
>       Method = IFaceMeth;
>     CollectOverriddenMethods(ID, Method, overridden);
> 
> @@ -962,9 +967,9 @@ static void collectOnCategoriesAfterLoca
>   if (!Class)
>     return;
> 
> -  for (ObjCInterfaceDecl::visible_categories_iterator
> -         Cat = Class->visible_categories_begin(),
> -         CatEnd = Class->visible_categories_end();
> +  for (ObjCInterfaceDecl::known_categories_iterator
> +         Cat = Class->known_categories_begin(),
> +         CatEnd = Class->known_categories_end();
>        Cat != CatEnd; ++Cat) {
>     if (SM.isBeforeInTranslationUnit(Loc, Cat->getLocation()))
>       CollectOverriddenMethodsRecurse(*Cat, Method, Methods, true);
> 
> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=178374&r1=178373&r2=178374&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Mar 29 16:51:48 2013
> @@ -2727,9 +2727,9 @@ private:
>       return;
> 
>     //   - categories,
> -    for (ObjCInterfaceDecl::visible_categories_iterator
> -           cat = iface->visible_categories_begin(),
> -           catEnd = iface->visible_categories_end();
> +    for (ObjCInterfaceDecl::known_categories_iterator
> +           cat = iface->known_categories_begin(),
> +           catEnd = iface->known_categories_end();
>          cat != catEnd; ++cat) {
>       search(*cat);
>     }
> @@ -2759,7 +2759,8 @@ private:
>   void search(ObjCContainerDecl *container) {
>     // Check for a method in this container which matches this selector.
>     ObjCMethodDecl *meth = container->getMethod(Method->getSelector(),
> -                                                Method->isInstanceMethod());
> +                                                Method->isInstanceMethod(),
> +                                                /*AllowHidden=*/true);
> 
>     // If we find one, record it and bail out.
>     if (meth) {
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130329/4030dc52/attachment.html>


More information about the cfe-commits mailing list