[cfe-commits] r50057 - in /cfe/trunk: include/clang/AST/DeclObjC.h include/clang/Basic/DiagnosticKinds.def lib/Parse/ParseObjc.cpp lib/Sema/SemaDeclObjC.cpp test/Sema/objc-property-1.m

Fariborz Jahanian fjahanian at apple.com
Mon Apr 21 14:05:54 PDT 2008


Author: fjahanian
Date: Mon Apr 21 16:05:54 2008
New Revision: 50057

URL: http://llvm.org/viewvc/llvm-project?rev=50057&view=rev
Log:
Support for @dynamic AST build.
More property semantics checking.
First test case for ObjC2's property implementation.

Added:
    cfe/trunk/test/Sema/objc-property-1.m
Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Parse/ParseObjc.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=50057&r1=50056&r2=50057&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Apr 21 16:05:54 2008
@@ -1066,6 +1066,8 @@
   static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L, 
                                   IdentifierInfo *Id, QualType T);
   QualType getType() const { return DeclType; }
+  QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
+  
   PropertyAttributeKind getPropertyAttributes() const {
     return PropertyAttributeKind(PropertyAttributes);
   }

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=50057&r1=50056&r2=50057&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Mon Apr 21 16:05:54 2008
@@ -492,15 +492,21 @@
 DIAG(error_bad_property_context, ERROR,
      "property implementation must be in a class or category implementation")
 DIAG(error_bad_property_decl, ERROR,
-     "property implementation must have the declaration in the class '%0'")
+     "property implementation must have its declaration in the class '%0'")
+DIAG(error_bad_category_property_decl, ERROR,
+     "property implementation must have its declaration in the category '%0'")
 DIAG(error_property_ivar_decl, ERROR,
      "property synthesize requires specification of an ivar")
 DIAG(error_dynamic_property_ivar_decl, ERROR,
      "dynamic property can not have ivar specification")
 DIAG(error_missing_property_interface, ERROR,
-     "property implementation in a class/category implementation with no interface")
+     "property implementation in a category with no category declaration")
 DIAG(error_missing_property_ivar_decl, ERROR,
      "property synthesize requires a previously declared ivar")
+DIAG(error_synthesize_category_decl, ERROR,
+     "@synthesize not allowed in a category's implementation")
+DIAG(error_property_ivar_type, ERROR,
+     "type of property '%0'  does not match type of ivar '%1'") 
 
 //===----------------------------------------------------------------------===//
 // Semantic Analysis

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=50057&r1=50056&r2=50057&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Apr 21 16:05:54 2008
@@ -1077,7 +1077,11 @@
     return 0;
   }
   while (Tok.is(tok::identifier)) {
-    ConsumeToken(); // consume property name
+    IdentifierInfo *propertyId = Tok.getIdentifierInfo();
+    SourceLocation propertyLoc = ConsumeToken(); // consume property name
+    Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl,
+                                  propertyId, 0);
+
     if (Tok.isNot(tok::comma))
       break;
     ConsumeToken(); // consume ','

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=50057&r1=50056&r2=50057&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Apr 21 16:05:54 2008
@@ -952,10 +952,11 @@
   if (ObjCImplementationDecl *IC = 
         dyn_cast<ObjCImplementationDecl>(ClassImpDecl)) {
     IDecl = getObjCInterfaceDecl(IC->getIdentifier());
-    if (!IDecl) {
-      Diag(AtLoc, diag::error_missing_property_interface);
-      return 0;
-    }
+    // We always synthesize an interface for an implementation
+    // without an interface decl. So, IDecl is always non-zero.
+    assert(IDecl && 
+           "ActOnPropertyImplDecl - @implementation without @interface");
+    
     // Look for this property declaration in the @implementation's @interface
     property = IDecl->FindPropertyDeclaration(PropertyId);
     if (!property) {
@@ -965,6 +966,10 @@
   }
   else if (ObjCCategoryImplDecl* CatImplClass = 
             dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl)) {
+    if (Synthesize) {
+      Diag(AtLoc, diag::error_synthesize_category_decl);
+      return 0;
+    }    
     IDecl = CatImplClass->getClassInterface();
     if (!IDecl) {
       Diag(AtLoc, diag::error_missing_property_interface);
@@ -980,7 +985,7 @@
     // Look for this property declaration in @implementation's category
     property = Category->FindPropertyDeclaration(PropertyId);
     if (!property) {
-      Diag(PropertyLoc, diag::error_bad_property_decl, 
+      Diag(PropertyLoc, diag::error_bad_category_property_decl, 
            Category->getName());
       return 0;
     }
@@ -998,16 +1003,23 @@
       return 0;
     }
     // Check that this is a previously declared 'ivar' in 'IDecl' interface
-    if (!IDecl->FindIvarDeclaration(PropertyIvar)) {
+    ObjCIvarDecl *Ivar = IDecl->FindIvarDeclaration(PropertyIvar);
+    if (!Ivar) {
       Diag(PropertyLoc, diag::error_missing_property_ivar_decl);
       return 0;
     }
+    // Check that type of property and its ivar match. 
+    if (Ivar->getCanonicalType() != property->getCanonicalType()) {
+      Diag(PropertyLoc, diag::error_property_ivar_type, property->getName(),
+           Ivar->getName());
+      return 0;
+    }
+      
   } else if (PropertyIvar) {
     // @dynamic
     Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl);
     return 0;
   }
-  // TODO: More diagnostics go here !!
   assert (property && "ActOnPropertyImplDecl - property declaration missing");
   // TODO: Build the property implementation AST, pushes it into its 
   // class/cateogory implementation's vector of property implementations

Added: cfe/trunk/test/Sema/objc-property-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-property-1.m?rev=50057&view=auto

==============================================================================
--- cfe/trunk/test/Sema/objc-property-1.m (added)
+++ cfe/trunk/test/Sema/objc-property-1.m Mon Apr 21 16:05:54 2008
@@ -0,0 +1,36 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface I 
+{
+	int IVAR;
+}
+ at property int d1;
+ at property id  prop_id;
+ at end
+
+ at interface I(CAT)
+ at property int d1;
+ at end
+
+ at implementation I
+ at synthesize d1;		// expected-error {{property synthesize requires specification of an ivar}}
+ at dynamic    bad;	// expected-error {{property implementation must have its declaration in the class 'I'}}
+ at synthesize prop_id;	// expected-error {{property synthesize requires specification of an ivar}}
+ at synthesize prop_id = IVAR;	// expected-error {{type of property 'prop_id'  does not match type of ivar 'IVAR'}}
+ at end
+
+ at implementation I(CAT)
+ at synthesize d1;		// expected-error {{@synthesize not allowed in a category's implementation}}
+ at dynamic bad;		// expected-error {{property implementation must have its declaration in the category 'CAT'}}
+ at end
+
+ at implementation E	// expected-warning {{cannot find interface declaration for 'E'}}
+ at dynamic d;		// expected-error {{property implementation must have its declaration in the class 'E'}}
+ at end
+
+ at implementation Q(MYCAT)  // expected-error {{cannot find interface declaration for 'Q'}}
+ at dynamic d;		// expected-error {{property implementation in a category with no category declaration}}
+ at end
+
+
+





More information about the cfe-commits mailing list