]> granicus.if.org Git - clang/commitdiff
Added parsing/sema support for __attribute__ ((IBOutlet)), a clang-specific attribute...
authorTed Kremenek <kremenek@apple.com>
Tue, 15 Jul 2008 22:26:48 +0000 (22:26 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 15 Jul 2008 22:26:48 +0000 (22:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53644 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Attr.h
include/clang/Basic/DiagnosticKinds.def
include/clang/Parse/AttributeList.h
lib/Parse/AttributeList.cpp
lib/Sema/SemaDeclAttr.cpp

index c7da6d924bccf9733040372474c4119968f81e47..c659454b8320b5176703045b53c022c7153f7b41 100644 (file)
@@ -37,7 +37,9 @@ public:
     Visibility,
     FastCall,
     StdCall,
-    TransparentUnion
+    TransparentUnion,
+    IBOutletKind // Clang-specific.  Use "Kind" suffix to not conflict with
+                 // the IBOutlet macro.
   };
     
 private:
@@ -120,6 +122,17 @@ public:
   static bool classof(const Attr *A) { return A->getKind() == Alias; }
   static bool classof(const AliasAttr *A) { return true; }
 };
+  
+class IBOutletAttr : public Attr {
+public:
+  IBOutletAttr() : Attr(IBOutletKind) {}
+  
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Attr *A) {
+    return A->getKind() == IBOutletKind;
+  }
+  static bool classof(const IBOutletAttr *A) { return true; }
+};
 
 class NoReturnAttr : public Attr {
 public:
index c0a2ea0221c13acbbf1c17be9f7210c8c2804d0a..d1c4bd9080e8de48db277529fa0983a74e71156f 100644 (file)
@@ -672,6 +672,10 @@ DIAG(err_mode_wrong_type, ERROR,
      "type of machine mode does not match type of base type")
 DIAG(err_attr_wrong_decl, ERROR,
      "'%0' attribute invalid on this declaration, requires typedef or value")
+     
+// Clang-Specific Attributes
+DIAG(err_attribute_iboutlet_non_ivar, ERROR,
+     "'IBOutlet' attribute can only be applied to instance variables")
 
 // Function Parameter Semantic Analysis.
 DIAG(err_param_with_void_type, ERROR,
index 112a495e6e391b012784c9e4f9099ed818ebd686..18a26163a37b36b111ef861270c747fd84041e97 100644 (file)
@@ -52,6 +52,7 @@ public:
     AT_ext_vector_type,
     AT_fastcall,
     AT_format,
+    AT_IBOutlet,          // Clang-specific.
     AT_malloc,
     AT_mode,
     AT_noinline,
index 8697d4ece8a57bfa05bac52f59a3a50097cd4da2..9d84a0f1890d61c54274e9fd0b4e4cb04dfca395 100644 (file)
@@ -49,7 +49,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
     Str += 2;
     Len -= 4;
   }
-
+  
   switch (Len) {
   case 4:
     if (!memcmp(Str, "weak", 4)) return AT_weak;
@@ -76,6 +76,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
     if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
     if (!memcmp(Str, "noinline", 8)) return AT_noinline;
     if (!memcmp(Str, "fastcall", 8)) return AT_fastcall;
+    if (!memcmp(Str, "IBOutlet", 8)) return AT_IBOutlet;
     break;
   case 9:
     if (!memcmp(Str, "dllimport", 9)) return AT_dllimport;
index e6dac4901edd38a0d40de394c8f4e2f7746f5fac..f8217b362f214a0ef0340805aca54b32c4a4c8e4 100644 (file)
@@ -217,6 +217,22 @@ static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
            Attr.getName()->getName());
 }
 
+static void HandleIBOutletAttr(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,
+           std::string("0"));
+    return;
+  }
+  
+  // The IBOutlet attribute only applies to instance variables of Objective-C
+  // classes.
+  if (ObjCIvarDecl *ID = dyn_cast<ObjCIvarDecl>(d))
+    ID->addAttr(new IBOutletAttr());
+  else
+    S.Diag(Attr.getLoc(), diag::err_attribute_iboutlet_non_ivar);
+}
+
 static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   // check the attribute arguments.
   if (Attr.getNumArgs() != 1) {
@@ -746,6 +762,7 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) {
   case AttributeList::AT_annotate:    HandleAnnotateAttr  (D, Attr, S); break;
   case AttributeList::AT_noreturn:    HandleNoReturnAttr  (D, Attr, S); break;
   case AttributeList::AT_format:      HandleFormatAttr    (D, Attr, S); break;
+  case AttributeList::AT_IBOutlet:    HandleIBOutletAttr  (D, Attr, S); break;    
   case AttributeList::AT_transparent_union:
     HandleTransparentUnionAttr(D, Attr, S);
     break;