r190947 - ObjectiveC migrator: Infer property in the presense
Fariborz Jahanian
fjahanian at apple.com
Wed Sep 18 10:22:26 PDT 2013
Author: fjahanian
Date: Wed Sep 18 12:22:25 2013
New Revision: 190947
URL: http://llvm.org/viewvc/llvm-project?rev=190947&view=rev
Log:
ObjectiveC migrator: Infer property in the presense
of methods annotated with attributes.
// rdar://14987909
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-property.m
cfe/trunk/test/ARCMT/objcmt-property.m.result
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=190947&r1=190946&r2=190947&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Sep 18 12:22:25 2013
@@ -721,6 +721,33 @@ static bool TypeIsInnerPointer(QualType
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::migrateProp
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::migrateProp
}
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,
Modified: cfe/trunk/test/ARCMT/objcmt-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m?rev=190947&r1=190946&r2=190947&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m Wed Sep 18 12:22:25 2013
@@ -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)))
+
+ at 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;
+
+ at end
Modified: cfe/trunk/test/ARCMT/objcmt-property.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m.result?rev=190947&r1=190946&r2=190947&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Wed Sep 18 12:22:25 2013
@@ -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));
+ at 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)))
+
+ at interface NSURL
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURL NS_AVAILABLE;
+- (void) setAppStoreReceiptURL : (NSURL *)object;
+
+ at property(nonatomic, retain) NSURL * appStoreReceiptURLX NS_AVAILABLE;
+
+
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURLY ;
+- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
+
+ at 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;
+
+ at property(nonatomic, retain) id method1 ALIGNED NS_AVAILABLE;
+
+
+ at end
More information about the cfe-commits
mailing list