[cfe-commits] r50228 - in /cfe/trunk: include/clang/Parse/Action.h lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Apr 24 12:58:34 PDT 2008


Author: fjahanian
Date: Thu Apr 24 14:58:34 2008
New Revision: 50228

URL: http://llvm.org/viewvc/llvm-project?rev=50228&view=rev
Log:
Patch to diagnose inconsistancies between properties declared in current and
its super class. This patch is incomplete.

Modified:
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=50228&r1=50227&r2=50228&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Apr 24 14:58:34 2008
@@ -718,8 +718,14 @@
                                        llvm::SmallVector<DeclTy *, 8> &
                                        Protocols) {
   }
-                                               
-                                               
+
+  /// ComparePropertiesInBaseAndSuper - This routine compares property
+  /// declarations in base and its super class, if any, and issues
+  /// diagnostics in a variety of inconsistant situations.
+  ///
+  virtual void ComparePropertiesInBaseAndSuper(SourceLocation *PropertyLoc,
+                                               DeclTy *ClassInterface) {
+  }
   //===----------------------- Obj-C Expressions --------------------------===//
 
   virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=50228&r1=50227&r2=50228&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Apr 24 14:58:34 2008
@@ -652,6 +652,9 @@
                                        llvm::SmallVector<DeclTy *, 8> & 
                                        Protocols);
 
+  virtual void ComparePropertiesInBaseAndSuper(SourceLocation *PropertyLoc,
+                                               DeclTy *ClassInterface);
+  
   virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
                       DeclTy **allMethods = 0, unsigned allNum = 0,
                       DeclTy **allProperties = 0, unsigned pNum = 0);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Apr 24 14:58:34 2008
@@ -246,6 +246,74 @@
   }
 }
 
+/// DiagnosePropertyMismatch - Compares two properties for their
+/// attributes and types and warns on a variety of inconsistancies.
+///
+// TODO: Incomplete. 
+//
+static void
+DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 
+                         ObjCPropertyDecl *SuperProperty) {
+  ObjCPropertyDecl::PropertyAttributeKind CAttr = 
+  Property->getPropertyAttributes();
+  ObjCPropertyDecl::PropertyAttributeKind SAttr = 
+  SuperProperty->getPropertyAttributes();
+  if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
+      && (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite))
+    ; // ???
+  
+  if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy)
+      != (SAttr & ObjCPropertyDecl::OBJC_PR_copy))
+    ; //
+  else if ((CAttr & ObjCPropertyDecl::OBJC_PR_retain)
+           != (SAttr & ObjCPropertyDecl::OBJC_PR_retain))
+    ; // ???
+  
+  if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)
+      != (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic))
+    ; //
+  
+  if (Property->getSetterName() != SuperProperty->getSetterName())
+    ; //
+  if (Property->getGetterName() != SuperProperty->getGetterName())
+    ; //
+  
+  if (Property->getCanonicalType() != SuperProperty->getCanonicalType()) {
+    if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
+        && (SAttr & ObjCPropertyDecl::OBJC_PR_readonly))
+       // && objc_compare_types(...))
+      ;
+    else
+      ; //
+  }
+  
+}
+
+/// ComparePropertiesInBaseAndSuper - This routine compares property
+/// declarations in base and its super class, if any, and issues
+/// diagnostics in a variety of inconsistant situations.
+///
+void 
+Sema::ComparePropertiesInBaseAndSuper(SourceLocation *PropertyLoc,
+                                      DeclTy *D) {
+  ObjCInterfaceDecl *IDecl = 
+    dyn_cast<ObjCInterfaceDecl>(static_cast<Decl *>(D));
+  ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
+  if (!SDecl)
+    return;
+  for (ObjCInterfaceDecl::classprop_iterator I = SDecl->classprop_begin(),
+       E = SDecl->classprop_end(); I != E; ++I) {
+    ObjCPropertyDecl *SuperPDecl = (*I);
+    // Does property in super class has declaration in current class?
+    for (ObjCInterfaceDecl::classprop_iterator I = IDecl->classprop_begin(),
+         E = IDecl->classprop_end(); I != E; ++I) {
+      ObjCPropertyDecl *PDecl = (*I);
+      if (SuperPDecl->getIdentifier() == PDecl->getIdentifier())
+          DiagnosePropertyMismatch(PDecl, SuperPDecl);
+    }
+  }
+}
+
 /// ActOnForwardProtocolDeclaration - 
 Action::DeclTy *
 Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,





More information about the cfe-commits mailing list