r213185 - Objective-C. Changes per A. Ballman's comment

Aaron Ballman aaron at aaronballman.com
Wed Jul 16 13:08:38 PDT 2014


On Wed, Jul 16, 2014 at 3:44 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Wed Jul 16 14:44:34 2014
> New Revision: 213185
>
> URL: http://llvm.org/viewvc/llvm-project?rev=213185&view=rev
> Log:
> Objective-C. Changes per A. Ballman's comment
> for my last patch. // rdar://17631257
>
> Added:
>     cfe/trunk/test/SemaObjC/objc-asm-attribute-neg-test.m
> Modified:
>     cfe/trunk/include/clang/AST/DeclObjC.h
>     cfe/trunk/include/clang/Basic/Attr.td
>     cfe/trunk/include/clang/Basic/AttrDocs.td
>     cfe/trunk/lib/AST/DeclObjC.cpp
>     cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>
> Modified: cfe/trunk/include/clang/AST/DeclObjC.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=213185&r1=213184&r2=213185&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/DeclObjC.h (original)
> +++ cfe/trunk/include/clang/AST/DeclObjC.h Wed Jul 16 14:44:34 2014
> @@ -955,6 +955,9 @@ public:
>    void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
>                                         unsigned Num,
>                                         ASTContext &C);
> +
> +  /// Produce a name to be used for class's metadata. It comes either via
> +  /// objc_runtime_name attribute or class name.
>    StringRef getObjCRuntimeNameAsString() const;
>
>    /// Returns the designated initializers for the interface.
> @@ -1654,6 +1657,8 @@ public:
>    /// \brief Starts the definition of this Objective-C protocol.
>    void startDefinition();
>
> +  /// Produce a name to be used for protocol's metadata. It comes either via
> +  /// objc_runtime_name attribute or protocol name.
>    StringRef getObjCRuntimeNameAsString() const;
>
>    SourceRange getSourceRange() const override LLVM_READONLY {
> @@ -2104,6 +2109,8 @@ public:
>      return getName();
>    }
>
> +  /// Produce a name to be used for class's metadata. It comes either via
> +  /// class's objc_runtime_name attribute or class name.
>    StringRef getObjCRuntimeNameAsString() const;
>
>    const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=213185&r1=213184&r2=213185&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Wed Jul 16 14:44:34 2014
> @@ -993,8 +993,8 @@ def ObjCRuntimeName : Attr {
>      let Spellings = [GNU<"objc_runtime_name">];
>      let Subjects = SubjectList<[ObjCInterface, ObjCProtocol], ErrorDiag,
>      "ExpectedObjectiveCInterfaceOrProtocol">;
> -    let Args = [StringArgument<"MetadataName", 1>];
> -    let Documentation = [Undocumented];
> +    let Args = [StringArgument<"MetadataName">];
> +    let Documentation = [ObjCRuntimeNameDocs];
>  }
>
>  def OptimizeNone : InheritableAttr {
>
> Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=213185&r1=213184&r2=213185&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
> +++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed Jul 16 14:44:34 2014
> @@ -426,6 +426,25 @@ implementation of an override in a subcl
>    }];
>  }
>
> +def ObjCRuntimeNameDocs : Documentation {
> +    let Category = DocCatFunction;
> +    let Content = [{
> +        Annotation of Objective-C classes and protocols with this attribute allow to
> +        use an alternative name for metadata names which normally use class or protocol
> +        names as part of their names.

The phrasing here is a bit hard to understand. Would this capture the
meaning sufficiently?

By default, the Objective-C interface or protocol identifier is used
as the metadata name for that object. The `objc_runtime_name`
attribute allows annotated interfaces or protocols to use the
specified string argument as the object's metadata name instead of the
default name.

> +
> +        **Usage**: ``__attribute__((objc_runtime_name("MyLocalName")))``.  This attribute
> +        can only be placed before an @protocol or @interface declaration:
> +
> +        .. code-block:: objc
> +
> +        __attribute__((objc_runtime_name("MyLocalName")))
> +        @interface Message
> +        @end
> +
> +    }];
> +}
> +
>  def AvailabilityDocs : Documentation {
>    let Category = DocCatFunction;
>    let Content = [{
>
> Modified: cfe/trunk/lib/AST/DeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=213185&r1=213184&r2=213185&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/DeclObjC.cpp (original)
> +++ cfe/trunk/lib/AST/DeclObjC.cpp Wed Jul 16 14:44:34 2014
> @@ -1201,18 +1201,19 @@ bool ObjCInterfaceDecl::hasDesignatedIni
>
>  StringRef
>  ObjCInterfaceDecl::getObjCRuntimeNameAsString() const {
> -    if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
> -        return ObjCRTName->getMetadataName();
> -    return getName();
> +  if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
> +    return ObjCRTName->getMetadataName();
> +
> +  return getName();
>  }
>
>  StringRef
>  ObjCImplementationDecl::getObjCRuntimeNameAsString() const {
> -    if (ObjCInterfaceDecl *ID =
> -        const_cast<ObjCImplementationDecl*>(this)->getClassInterface())
> -        return ID->getObjCRuntimeNameAsString();
> +  if (ObjCInterfaceDecl *ID =
> +      const_cast<ObjCImplementationDecl*>(this)->getClassInterface())
> +    return ID->getObjCRuntimeNameAsString();
>
> -    return getName();
> +  return getName();
>  }
>
>  ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
> @@ -1621,9 +1622,10 @@ void ObjCProtocolDecl::collectInheritedP
>
>  StringRef
>  ObjCProtocolDecl::getObjCRuntimeNameAsString() const {
> -    if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
> -        return ObjCRTName->getMetadataName();
> -    return getName();
> +  if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>())
> +    return ObjCRTName->getMetadataName();
> +
> +  return getName();
>  }
>
>  //===----------------------------------------------------------------------===//
>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=213185&r1=213184&r2=213185&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Jul 16 14:44:34 2014
> @@ -3599,12 +3599,13 @@ static void handleObjCDesignatedInitiali
>
>  static void handleObjCRuntimeName(Sema &S, Decl *D,
>                                    const AttributeList &Attr) {
> -    StringRef MetaDataName;
> -    if (!S.checkStringLiteralArgumentAttr(Attr, 0, MetaDataName))
> -        return;
> -    D->addAttr(::new (S.Context)
> -               ObjCRuntimeNameAttr(Attr.getRange(), S.Context,
> -                                   MetaDataName, 0));
> +  StringRef MetaDataName;
> +  if (!S.checkStringLiteralArgumentAttr(Attr, 0, MetaDataName))
> +    return;
> +  D->addAttr(::new (S.Context)
> +             ObjCRuntimeNameAttr(Attr.getRange(), S.Context,
> +                                 MetaDataName,
> +                                 Attr.getAttributeSpellingListIndex()));
>  }
>
>  static void handleObjCOwnershipAttr(Sema &S, Decl *D,
>
> Added: cfe/trunk/test/SemaObjC/objc-asm-attribute-neg-test.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-asm-attribute-neg-test.m?rev=213185&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/objc-asm-attribute-neg-test.m (added)
> +++ cfe/trunk/test/SemaObjC/objc-asm-attribute-neg-test.m Wed Jul 16 14:44:34 2014
> @@ -0,0 +1,42 @@
> +// RUN: %clang_cc1  -fsyntax-only -verify -Wno-objc-root-class %s
> +// rdar://16462586
> +
> +__attribute__((objc_runtime_name)) // expected-error {{'objc_runtime_name' attribute takes one argument}}
> + at interface BInterface
> + at end
> +
> +__attribute__((objc_runtime_name(123))) // expected-error {{'objc_runtime_name' attribute requires a string}}
> + at protocol BProtocol1
> + at end
> +
> +__attribute__((objc_runtime_name("MySecretNamespace.Protocol")))
> + at protocol Protocol
> + at end
> +
> +__attribute__((objc_runtime_name("MySecretNamespace.Message")))
> + at interface Message <Protocol> {
> +__attribute__((objc_runtime_name("MySecretNamespace.Message"))) // expected-error {{'objc_runtime_name' attribute only applies to interface or protocol declarations}}
> +  id MyIVAR;
> +}
> +__attribute__((objc_runtime_name("MySecretNamespace.Message")))
> + at property int MyProperty; // expected-error {{prefix attribute must be followed by an interface or protocol}}}}
> +
> +- (int) getMyProperty __attribute__((objc_runtime_name("MySecretNamespace.Message"))); // expected-error {{'objc_runtime_name' attribute only applies to interface or protocol declarations}}
> +
> +- (void) setMyProperty : (int) arg __attribute__((objc_runtime_name("MySecretNamespace.Message"))); // expected-error {{'objc_runtime_name' attribute only applies to interface or protocol declarations}}
> +
> + at end
> +
> +__attribute__((objc_runtime_name("MySecretNamespace.ForwardClass")))
> + at class ForwardClass; // expected-error {{prefix attribute must be followed by an interface or protocol}}
> +
> +__attribute__((objc_runtime_name("MySecretNamespace.ForwardProtocol")))
> + at protocol ForwardProtocol;
> +
> +__attribute__((objc_runtime_name("MySecretNamespace.Message")))
> + at implementation Message // expected-error {{prefix attribute must be followed by an interface or protocol}}
> +__attribute__((objc_runtime_name("MySecretNamespace.Message")))
> +- (id) MyMethod {
> +  return MyIVAR;
> +}
> + at end
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

~Aaron



More information about the cfe-commits mailing list