r190223 - ObjectiveC migrator: When inferring a property,
Fariborz Jahanian
fjahanian at apple.com
Fri Sep 6 16:45:20 PDT 2013
Author: fjahanian
Date: Fri Sep 6 18:45:20 2013
New Revision: 190223
URL: http://llvm.org/viewvc/llvm-project?rev=190223&view=rev
Log:
ObjectiveC migrator: When inferring a property,
preserve getter's attribute. Also, do not attach
an inferred NS_RETURNS_INNER_POINTER to the inferred
property (it is illegal).
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=190223&r1=190222&r2=190223&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Fri Sep 6 18:45:20 2013
@@ -51,6 +51,7 @@ class ObjCMigrateASTConsumer : public AS
void migrateMethods(ASTContext &Ctx, ObjCContainerDecl *CDecl);
void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM);
+ bool migrateProperty(ASTContext &Ctx, ObjCInterfaceDecl *D, ObjCMethodDecl *OM);
void migrateNsReturnsInnerPointer(ASTContext &Ctx, ObjCMethodDecl *OM);
void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM,
@@ -316,8 +317,13 @@ static bool rewriteToObjCProperty(const
}
else
PropertyString += PropertyNameString;
+ SourceLocation StartGetterSelectorLoc = Getter->getSelectorStartLoc();
+ Selector GetterSelector = Getter->getSelector();
+
+ SourceLocation EndGetterSelectorLoc =
+ StartGetterSelectorLoc.getLocWithOffset(GetterSelector.getNameForSlot(0).size());
commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(),
- Getter->getDeclaratorEndLoc()),
+ EndGetterSelectorLoc),
PropertyString);
if (Setter) {
SourceLocation EndLoc = Setter->getDeclaratorEndLoc();
@@ -333,64 +339,8 @@ void ObjCMigrateASTConsumer::migrateObjC
for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end();
M != MEnd; ++M) {
ObjCMethodDecl *Method = (*M);
- if (Method->isPropertyAccessor() || !Method->isInstanceMethod() ||
- Method->param_size() != 0)
- continue;
- // Is this method candidate to be a getter?
- QualType GRT = Method->getResultType();
- if (GRT->isVoidType())
- continue;
- // FIXME. Don't know what todo with attributes, skip for now.
- if (Method->hasAttrs())
- continue;
-
- Selector GetterSelector = Method->getSelector();
- IdentifierInfo *getterName = GetterSelector.getIdentifierInfoForSlot(0);
- Selector SetterSelector =
- SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
- PP.getSelectorTable(),
- getterName);
- ObjCMethodDecl *SetterMethod = D->lookupMethod(SetterSelector, true);
- bool GetterHasIsPrefix = false;
- if (!SetterMethod) {
- // try a different naming convention for getter: isXxxxx
- StringRef getterNameString = getterName->getName();
- if (getterNameString.startswith("is") && !GRT->isObjCRetainableType()) {
- GetterHasIsPrefix = true;
- const char *CGetterName = getterNameString.data() + 2;
- if (CGetterName[0] && isUppercase(CGetterName[0])) {
- getterName = &Ctx.Idents.get(CGetterName);
- SetterSelector =
- SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
- PP.getSelectorTable(),
- getterName);
- SetterMethod = D->lookupMethod(SetterSelector, true);
- }
- }
- }
- if (SetterMethod) {
- // Is this a valid setter, matching the target getter?
- QualType SRT = SetterMethod->getResultType();
- if (!SRT->isVoidType())
- continue;
- const ParmVarDecl *argDecl = *SetterMethod->param_begin();
- QualType ArgType = argDecl->getType();
- if (!Ctx.hasSameUnqualifiedType(ArgType, GRT) ||
- SetterMethod->hasAttrs())
- continue;
- edit::Commit commit(*Editor);
- rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit,
- GetterHasIsPrefix);
- Editor->commit(commit);
- }
- else if (MigrateReadonlyProperty) {
- // Try a non-void method with no argument (and no setter or property of same name
- // as a 'readonly' property.
- edit::Commit commit(*Editor);
- rewriteToObjCProperty(Method, 0 /*SetterMethod*/, *NSAPIObj, commit,
- false /*GetterHasIsPrefix*/);
- Editor->commit(commit);
- }
+ if (!migrateProperty(Ctx, D, Method))
+ migrateNsReturnsInnerPointer(Ctx, Method);
}
}
@@ -747,6 +697,72 @@ static bool TypeIsInnerPointer(QualType
return true;
}
+bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
+ ObjCInterfaceDecl *D,
+ ObjCMethodDecl *Method) {
+ if (Method->isPropertyAccessor() || !Method->isInstanceMethod() ||
+ Method->param_size() != 0)
+ return false;
+ // Is this method candidate to be a getter?
+ 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);
+ Selector SetterSelector =
+ SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
+ PP.getSelectorTable(),
+ getterName);
+ ObjCMethodDecl *SetterMethod = D->lookupMethod(SetterSelector, true);
+ bool GetterHasIsPrefix = false;
+ if (!SetterMethod) {
+ // try a different naming convention for getter: isXxxxx
+ StringRef getterNameString = getterName->getName();
+ if (getterNameString.startswith("is") && !GRT->isObjCRetainableType()) {
+ GetterHasIsPrefix = true;
+ const char *CGetterName = getterNameString.data() + 2;
+ if (CGetterName[0] && isUppercase(CGetterName[0])) {
+ getterName = &Ctx.Idents.get(CGetterName);
+ SetterSelector =
+ SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
+ PP.getSelectorTable(),
+ getterName);
+ SetterMethod = D->lookupMethod(SetterSelector, true);
+ }
+ }
+ }
+ if (SetterMethod) {
+ // 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())
+ return false;
+ edit::Commit commit(*Editor);
+ rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit,
+ GetterHasIsPrefix);
+ Editor->commit(commit);
+ return true;
+ }
+ else if (MigrateReadonlyProperty) {
+ // Try a non-void method with no argument (and no setter or property of same name
+ // as a 'readonly' property.
+ edit::Commit commit(*Editor);
+ rewriteToObjCProperty(Method, 0 /*SetterMethod*/, *NSAPIObj, commit,
+ false /*GetterHasIsPrefix*/);
+ Editor->commit(commit);
+ return true;
+ }
+ return false;
+}
+
void ObjCMigrateASTConsumer::migrateNsReturnsInnerPointer(ASTContext &Ctx,
ObjCMethodDecl *OM) {
if (OM->hasAttr<ObjCReturnsInnerPointerAttr>())
@@ -770,7 +786,6 @@ void ObjCMigrateASTConsumer::migrateMeth
M != MEnd; ++M) {
ObjCMethodDecl *Method = (*M);
migrateMethodInstanceType(Ctx, CDecl, Method);
- migrateNsReturnsInnerPointer(Ctx, Method);
}
}
Modified: cfe/trunk/test/ARCMT/objcmt-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m?rev=190223&r1=190222&r2=190223&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m Fri Sep 6 18:45:20 2013
@@ -3,6 +3,10 @@
// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
+#define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION
+#define WEAK_IMPORT_ATTRIBUTE __attribute__((objc_arc_weak_reference_unavailable))
+#define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+
typedef char BOOL;
@class NSString;
@protocol NSCopying @end
@@ -92,4 +96,7 @@ typedef char BOOL;
- (int) Length;
- (id) object;
+ (double) D;
+- (void *)JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
@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=190223&r1=190222&r2=190223&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Fri Sep 6 18:45:20 2013
@@ -3,6 +3,10 @@
// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
+#define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION
+#define WEAK_IMPORT_ATTRIBUTE __attribute__((objc_arc_weak_reference_unavailable))
+#define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+
typedef char BOOL;
@class NSString;
@protocol NSCopying @end
@@ -92,4 +96,7 @@ typedef char BOOL;
@property(nonatomic, readonly) int Length;
@property(nonatomic, readonly) id object;
+ (double) D;
+ at property(nonatomic, readonly) void * JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
@end
+
+
More information about the cfe-commits
mailing list