[cfe-commits] r96562 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Feb 18 08:11:19 PST 2010


Is this a gcc supported attribute? Test case please.

- Fariborz

On Feb 17, 2010, at 7:08 PM, Ted Kremenek wrote:

> Author: kremenek
> Date: Wed Feb 17 21:08:58 2010
> New Revision: 96562
>
> URL: http://llvm.org/viewvc/llvm-project?rev=96562&view=rev
> Log:
> Change the behavior of ibaction attributes to be attached to  
> methods, not ivars.
>
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=96562&r1=96561&r2=96562&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb 17  
> 21:08:58 2010
> @@ -846,9 +846,11 @@
>
>
> // Clang-Specific Attributes
> -def err_attribute_ib : Error<
> -  "%0 attribute can only be applied to instance variables or "
> +def err_attribute_iboutlet : Error<
> +  "iboutlet attribute can only be applied to instance variables or "
>   "properties">;
> +def err_attribute_ibaction: Error<
> +  "ibaction attribute can only be applied to Objective-C instance  
> methods">;
> def err_attribute_overloadable_not_function : Error<
>   "'overloadable' attribute can only be applied to a function">;
> def err_attribute_overloadable_missing : Error<
>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=96562&r1=96561&r2=96562&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Feb 17 21:08:58 2010
> @@ -225,29 +225,38 @@
>     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) <<  
> Attr.getName();
> }
>
> -static void HandleIBAttr(Decl *d, const AttributeList &Attr, Sema  
> &S) {
> +static void HandleIBAction(Decl *d, const AttributeList &Attr, Sema  
> &S) {
>   // check the attribute arguments.
>   if (Attr.getNumArgs() > 0) {
>     S.Diag(Attr.getLoc(),  
> diag::err_attribute_wrong_number_arguments) << 0;
>     return;
>   }
>
> -  // The IBOutlet/IBAction attributes only apply to instance  
> variables of
> +  // The IBAction attributes only apply to instance methods.
> +  if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(d))
> +    if (MD->isInstanceMethod()) {
> +      d->addAttr(::new (S.Context) IBActionAttr());
> +      return;
> +    }
> +
> +  S.Diag(Attr.getLoc(), diag::err_attribute_ibaction) <<  
> Attr.getName();
> +}
> +
> +static void HandleIBOutlet(Decl *d, const AttributeList &Attr, Sema  
> &S) {
> +  // check the attribute arguments.
> +  if (Attr.getNumArgs() > 0) {
> +    S.Diag(Attr.getLoc(),  
> diag::err_attribute_wrong_number_arguments) << 0;
> +    return;
> +  }
> +
> +  // The IBOutlet attributes only apply to instance variables of
>   // Objective-C classes.
>   if (isa<ObjCIvarDecl>(d) || isa<ObjCPropertyDecl>(d)) {
> -    switch (Attr.getKind()) {
> -      case AttributeList::AT_IBAction:
> -        d->addAttr(::new (S.Context) IBActionAttr());
> -        break;
> -      case AttributeList::AT_IBOutlet:
> -        d->addAttr(::new (S.Context) IBOutletAttr());
> -        break;
> -      default:
> -        llvm_unreachable("Invalid IB attribute");
> -    }
> +    d->addAttr(::new (S.Context) IBOutletAttr());
> +    return;
>   }
> -  else
> -    S.Diag(Attr.getLoc(), diag::err_attribute_ib) << Attr.getName();
> +
> +  S.Diag(Attr.getLoc(), diag::err_attribute_iboutlet) <<  
> Attr.getName();
> }
>
> static void HandleNonNullAttr(Decl *d, const AttributeList &Attr,  
> Sema &S) {
> @@ -1745,8 +1754,8 @@
>     // FIXME: Try to deal with other __declspec attributes!
>     return;
>   switch (Attr.getKind()) {
> -  case AttributeList::AT_IBAction:
> -  case AttributeList::AT_IBOutlet:    HandleIBAttr          (D,  
> Attr, S); break;
> +  case AttributeList::AT_IBAction:            HandleIBAction(D,  
> Attr, S); break;
> +  case AttributeList::AT_IBOutlet:            HandleIBOutlet(D,  
> Attr, S); break;
>   case AttributeList::AT_address_space:
>   case AttributeList::AT_objc_gc:
>   case AttributeList::AT_vector_size:
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list