From 63e5d7c85299134f088033614afd9eb213c50b48 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 18 Feb 2010 03:08:58 +0000 Subject: [PATCH] Change the behavior of ibaction attributes to be attached to methods, not ivars. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96562 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 6 ++-- lib/Sema/SemaDeclAttr.cpp | 41 +++++++++++++--------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 7f23c1adf2..52d4dd26ff 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -846,9 +846,11 @@ def err_attribute_regparm_invalid_number : Error< // 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< diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index bb47ae7ea8..ef82d53b5c 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -225,29 +225,38 @@ static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) { 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(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(d) || isa(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 @@ static void ProcessDeclAttribute(Scope *scope, Decl *D, // 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: -- 2.40.0