]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator: Infer property in the presense
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 18 Sep 2013 17:22:25 +0000 (17:22 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 18 Sep 2013 17:22:25 +0000 (17:22 +0000)
of methods annotated with attributes.
// rdar://14987909

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190947 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-property.m
test/ARCMT/objcmt-property.m.result

index 65a00331c5b69c229879d697f009f7381a2312ae..08444442c76f5d20d6dba6f80411e7aa7040082c 100644 (file)
@@ -721,6 +721,33 @@ static bool TypeIsInnerPointer(QualType T) {
   return true;
 }
 
+static bool AttributesMatch(const Decl *Decl1, const Decl *Decl2) {
+  if (Decl1->hasAttrs() != Decl2->hasAttrs())
+    return false;
+  
+  if (!Decl1->hasAttrs())
+    return true;
+  
+  const AttrVec &Attrs1 = Decl1->getAttrs();
+  const AttrVec &Attrs2 = Decl2->getAttrs();
+  // This list is very small, so this need not be optimized.
+  for (unsigned i = 0, e = Attrs1.size(); i != e; i++) {
+    bool match = false;
+    for (unsigned j = 0, f = Attrs2.size(); j != f; j++) {
+      // Matching attribute kind only. We are not getting into
+      // details of the attributes. For all practical purposes
+      // this is sufficient.
+      if (Attrs1[i]->getKind() == Attrs2[j]->getKind()) {
+        match = true;
+        break;
+      }
+    }
+    if (!match)
+      return false;
+  }
+  return true;
+}
+
 bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
                              ObjCContainerDecl *D,
                              ObjCMethodDecl *Method) {
@@ -731,9 +758,6 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
   QualType GRT = Method->getResultType();
   if (GRT->isVoidType())
     return false;
-  // FIXME. Don't know what todo with attributes, skip for now.
-  if (Method->hasAttrs())
-    return false;
   
   Selector GetterSelector = Method->getSelector();
   IdentifierInfo *getterName = GetterSelector.getIdentifierInfoForSlot(0);
@@ -770,16 +794,17 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
   }
   
   if (SetterMethod) {
-    if (SetterMethod->isDeprecated())
+    if (SetterMethod->isDeprecated() ||
+        !AttributesMatch(Method, SetterMethod))
       return false;
+    
     // Is this a valid setter, matching the target getter?
     QualType SRT = SetterMethod->getResultType();
     if (!SRT->isVoidType())
       return false;
     const ParmVarDecl *argDecl = *SetterMethod->param_begin();
     QualType ArgType = argDecl->getType();
-    if (!Ctx.hasSameUnqualifiedType(ArgType, GRT) ||
-        SetterMethod->hasAttrs())
+    if (!Ctx.hasSameUnqualifiedType(ArgType, GRT))
       return false;
     edit::Commit commit(*Editor);
     rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit,
index 5b11c4aa3a75cee1741fc50ba4295f72b6703a98..03aaaa0619e824835b40dfaa3fa8bf5f99715820 100644 (file)
@@ -176,3 +176,35 @@ DEPRECATED
 - (id)xxxdelegateYYY DEPRECATED;
 - (void)setXxxdelegateYYY:(id)delegate DEPRECATED;
 @end
+
+// rdar://14987909
+#define NS_AVAILABLE __attribute__((availability(macosx,introduced=10.0)))
+#define NORETURN __attribute__((noreturn))
+#define ALIGNED __attribute__((aligned(16)))
+
+@interface NSURL
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURL NS_AVAILABLE;
+- (void) setAppStoreReceiptURL : (NSURL *)object;
+
+- (NSURL *)appStoreReceiptURLX NS_AVAILABLE;
+- (void) setAppStoreReceiptURLX : (NSURL *)object NS_AVAILABLE;
+
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURLY ;
+- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
+
+- (id)OkToInfer NS_AVAILABLE;
+
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURLZ ;
+- (void) setAppStoreReceiptURLZ : (NSURL *)object NS_AVAILABLE;
+
+// Do not infer a property.
+- (id) t1 NORETURN NS_AVAILABLE;
+- (void) setT1 : (id) arg NS_AVAILABLE;
+
+- (id)method1 ALIGNED NS_AVAILABLE;
+- (void) setMethod1 : (id) object NS_AVAILABLE ALIGNED;
+
+@end
index 39b0a8740f26300d493b23cf693af2f5b819dfbc..30bd028008fb8b28a081e6964213edf38b34a7ca 100644 (file)
@@ -30,8 +30,8 @@ typedef char BOOL;
 - (NSString *) UnavailProp  __attribute__((unavailable));
 - (void) setUnavailProp  : (NSString *)Val;
 
-- (NSString *) UnavailProp1  __attribute__((unavailable));
-- (void) setUnavailProp1  : (NSString *)Val  __attribute__((unavailable));
+@property(nonatomic, retain) NSString * UnavailProp1  __attribute__((unavailable));
+
 
 - (NSString *) UnavailProp2;
 - (void) setUnavailProp2  : (NSString *)Val  __attribute__((unavailable));
@@ -176,3 +176,35 @@ DEPRECATED
 - (id)xxxdelegateYYY DEPRECATED;
 - (void)setXxxdelegateYYY:(id)delegate DEPRECATED;
 @end
+
+// rdar://14987909
+#define NS_AVAILABLE __attribute__((availability(macosx,introduced=10.0)))
+#define NORETURN __attribute__((noreturn))
+#define ALIGNED __attribute__((aligned(16)))
+
+@interface NSURL
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURL NS_AVAILABLE;
+- (void) setAppStoreReceiptURL : (NSURL *)object;
+
+@property(nonatomic, retain) NSURL * appStoreReceiptURLX NS_AVAILABLE;
+
+
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURLY ;
+- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
+
+@property(nonatomic, readonly) id OkToInfer NS_AVAILABLE;
+
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURLZ ;
+- (void) setAppStoreReceiptURLZ : (NSURL *)object NS_AVAILABLE;
+
+// Do not infer a property.
+- (id) t1 NORETURN NS_AVAILABLE;
+- (void) setT1 : (id) arg NS_AVAILABLE;
+
+@property(nonatomic, retain) id method1 ALIGNED NS_AVAILABLE;
+
+
+@end