[cfe-commits] r111275 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Basic/DiagnosticSemaKinds.td lib/AST/AttrImpl.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriter.cpp lib/Sema/SemaDeclAttr.cpp test/SemaObjC/iboutletcollection-attr.m

Fariborz Jahanian fjahanian at apple.com
Tue Aug 17 13:23:12 PDT 2010


Author: fjahanian
Date: Tue Aug 17 15:23:12 2010
New Revision: 111275

URL: http://llvm.org/viewvc/llvm-project?rev=111275&view=rev
Log:
Patch to add type parameter support for attribute iboutletcollection.
Radar 8308053.

Added:
    cfe/trunk/test/SemaObjC/iboutletcollection-attr.m
Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/AST/AttrImpl.cpp
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=111275&r1=111274&r2=111275&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Tue Aug 17 15:23:12 2010
@@ -17,6 +17,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/ADT/StringRef.h"
 #include "clang/Basic/AttrKinds.h"
+#include "clang/AST/Type.h"
 #include <cassert>
 #include <cstring>
 #include <algorithm>
@@ -27,6 +28,7 @@
   class IdentifierInfo;
   class ObjCInterfaceDecl;
   class Expr;
+  class QualType;
 }
 
 // Defined in ASTContext.h
@@ -286,12 +288,12 @@
 };
 
 class IBOutletCollectionAttr : public Attr {
-  const ObjCInterfaceDecl *D;
+  QualType QT;
 public:
-  IBOutletCollectionAttr(const ObjCInterfaceDecl *d = 0)
-    : Attr(attr::IBOutletCollection), D(d) {}
+  IBOutletCollectionAttr(QualType qt = QualType())
+    : Attr(attr::IBOutletCollection), QT(qt) {}
 
-  const ObjCInterfaceDecl *getClass() const { return D; }
+  QualType getType() const { return QT; }
 
   virtual Attr *clone(ASTContext &C) const;
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=111275&r1=111274&r2=111275&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Aug 17 15:23:12 2010
@@ -826,6 +826,8 @@
   "%0 and %1 attributes are not compatible">;
 def err_attribute_wrong_number_arguments : Error<
   "attribute requires %0 argument(s)">;
+def err_iboutletcollection_type : Error<
+  "invalid type %0 as argument of iboutletcollection attribue">;
 def err_attribute_missing_parameter_name : Error<
   "attribute requires unquoted parameter">;
 def err_attribute_invalid_vector_type : Error<"invalid vector element type %0">;

Modified: cfe/trunk/lib/AST/AttrImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/AttrImpl.cpp?rev=111275&r1=111274&r2=111275&view=diff
==============================================================================
--- cfe/trunk/lib/AST/AttrImpl.cpp (original)
+++ cfe/trunk/lib/AST/AttrImpl.cpp Tue Aug 17 15:23:12 2010
@@ -163,7 +163,7 @@
 }
 
 Attr *IBOutletCollectionAttr::clone(ASTContext &C) const {
-  return ::new (C) IBOutletCollectionAttr(D);
+  return ::new (C) IBOutletCollectionAttr(QT);
 }
 
 Attr *IBActionAttr::clone(ASTContext &C) const {

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=111275&r1=111274&r2=111275&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Tue Aug 17 15:23:12 2010
@@ -1190,9 +1190,8 @@
       break;
 
     case attr::IBOutletCollection: {
-      ObjCInterfaceDecl *D =
-        cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
-      New = ::new (*Context) IBOutletCollectionAttr(D);
+      QualType QT = GetType(Record[Idx++]);
+      New = ::new (*Context) IBOutletCollectionAttr(QT);
       break;
     }
 

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=111275&r1=111274&r2=111275&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Tue Aug 17 15:23:12 2010
@@ -2051,7 +2051,7 @@
 
     case attr::IBOutletCollection: {
       const IBOutletCollectionAttr *ICA = cast<IBOutletCollectionAttr>(Attr);
-      AddDeclRef(ICA->getClass(), Record);
+      AddTypeRef(ICA->getType(), Record);
       break;
     }
 

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=111275&r1=111274&r2=111275&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Aug 17 15:23:12 2010
@@ -263,7 +263,7 @@
                                      Sema &S) {
 
   // The iboutletcollection attribute can have zero or one arguments.
-  if (Attr.getNumArgs() > 1) {
+  if (Attr.getParameterName() && Attr.getNumArgs() > 0) {
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
     return;
   }
@@ -274,9 +274,26 @@
     S.Diag(Attr.getLoc(), diag::err_attribute_iboutlet) << Attr.getName();
     return;
   }
-
-  // FIXME: Eventually accept the type argument.
-  d->addAttr(::new (S.Context) IBOutletCollectionAttr());
+  IdentifierInfo *II = Attr.getParameterName();
+  if (!II)
+    II = &S.Context.Idents.get("id");
+  Sema::TypeTy *TypeRep = S.getTypeName(*II, Attr.getLoc(), 
+                        S.getScopeForContext(d->getDeclContext()->getParent()));
+  if (!TypeRep) {
+    S.Diag(Attr.getLoc(), diag::err_iboutletcollection_type) << II;
+    return;
+  }
+  QualType QT(QualType::getFromOpaquePtr(TypeRep));
+  // Diagnose use of non-object type in iboutletcollection attribute.
+  // FIXME. Gnu attribute extension ignores use of builtin types in
+  // attributes. So, __attribute__((iboutletcollection(char))) will be
+  // treated as __attribute__((iboutletcollection())).
+  if (!QT->isObjCIdType() && !QT->isObjCClassType() &&
+      !QT->isObjCObjectType()) {
+    S.Diag(Attr.getLoc(), diag::err_iboutletcollection_type) << II;
+    return;
+  }
+  d->addAttr(::new (S.Context) IBOutletCollectionAttr(QT));
 }
 
 static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {

Added: cfe/trunk/test/SemaObjC/iboutletcollection-attr.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/iboutletcollection-attr.m?rev=111275&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/iboutletcollection-attr.m (added)
+++ cfe/trunk/test/SemaObjC/iboutletcollection-attr.m Tue Aug 17 15:23:12 2010
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s
+// rdar: // 8308053
+
+ at interface I {
+    __attribute__((iboutletcollection(I))) id ivar1;
+    __attribute__((iboutletcollection(id))) id ivar2;
+    __attribute__((iboutletcollection())) id ivar3;
+    __attribute__((iboutletcollection)) id ivar4;
+}
+ at property (nonatomic, retain) __attribute__((iboutletcollection(I))) id prop1;
+ at property (nonatomic, retain) __attribute__((iboutletcollection(id))) id prop2;
+ at property (nonatomic, retain) __attribute__((iboutletcollection())) id prop3;
+ at property (nonatomic, retain) __attribute__((iboutletcollection)) id prop4;
+ at end
+
+typedef void *PV;
+ at interface BAD {
+    __attribute__((iboutletcollection(I, 1))) id ivar1; // expected-error {{attribute requires 1 argument(s)}}
+    __attribute__((iboutletcollection(B))) id ivar2; // expected-error {{invalid type 'B' as argument of iboutletcollection attribue}}
+    __attribute__((iboutletcollection(PV))) id ivar3; // // expected-error {{invalid type 'PV' as argument of iboutletcollection attribue}}
+}
+ at property (nonatomic, retain) __attribute__((iboutletcollection(I,2,3))) id prop1; // expected-error {{attribute requires 1 argument(s)}}
+ at property (nonatomic, retain) __attribute__((iboutletcollection(B))) id prop2; // expected-error {{invalid type 'B' as argument of iboutletcollection attribue}}
+ at end
+





More information about the cfe-commits mailing list