r192226 - ObjectiveC migration. Add support for inferring
Fariborz Jahanian
fjahanian at apple.com
Tue Oct 8 13:14:24 PDT 2013
Author: fjahanian
Date: Tue Oct 8 15:14:24 2013
New Revision: 192226
URL: http://llvm.org/viewvc/llvm-project?rev=192226&view=rev
Log:
ObjectiveC migration. Add support for inferring
properties of block pointer types. Also, remove
strong lifetime attribute from property type
in this migration. This is wip.
// rdar://15082818
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=192226&r1=192225&r2=192226&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue Oct 8 15:14:24 2013
@@ -230,6 +230,36 @@ static void append_attr(std::string &Pro
PropertyString += attr;
}
+static
+void MigrateBlockOrFunctionPointerTypeVariable(std::string & PropertyString,
+ const std::string& TypeString,
+ const char *name) {
+ const char *argPtr = TypeString.c_str();
+ int paren = 0;
+ while (*argPtr) {
+ switch (*argPtr) {
+ case '(':
+ PropertyString += *argPtr;
+ paren++;
+ break;
+ case ')':
+ PropertyString += *argPtr;
+ paren--;
+ break;
+ case '^':
+ PropertyString += '^';
+ if (paren == 1)
+ PropertyString += name;
+ break;
+ default:
+ PropertyString += *argPtr;
+ break;
+ }
+ argPtr++;
+ }
+}
+
+
static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter,
const ObjCMethodDecl *Setter,
const NSAPI &NS, edit::Commit &commit,
@@ -245,7 +275,7 @@ static bool rewriteToObjCProperty(const
// Property with no setter may be suggested as a 'readonly' property.
if (!Setter)
append_attr(PropertyString, "readonly");
-
+
// Short circuit properties that contain the name "delegate" or "dataSource",
// or have exact name "target" to have unsafe_unretained attribute.
if (PropertyName.equals("target") ||
@@ -267,15 +297,17 @@ static bool rewriteToObjCProperty(const
else
append_attr(PropertyString, "retain");
}
+ else if (ArgType->isBlockPointerType())
+ append_attr(PropertyString, "copy");
} else if (propertyLifetime == Qualifiers::OCL_Weak)
// TODO. More precise determination of 'weak' attribute requires
// looking into setter's implementation for backing weak ivar.
append_attr(PropertyString, "weak");
else if (RetainableObject)
- append_attr(PropertyString, "retain");
+ append_attr(PropertyString,
+ ArgType->isBlockPointerType() ? "copy" : "retain");
}
PropertyString += ')';
-
QualType RT = Getter->getResultType();
if (!isa<TypedefType>(RT)) {
// strip off any ARC lifetime qualifier.
@@ -287,26 +319,32 @@ static bool rewriteToObjCProperty(const
}
}
PropertyString += " ";
- PropertyString += RT.getAsString(Context.getPrintingPolicy());
- char LastChar = PropertyString[PropertyString.size()-1];
- if (LastChar != '*')
- PropertyString += " ";
+ PrintingPolicy SubPolicy(Context.getPrintingPolicy());
+ SubPolicy.SuppressStrongLifetime = true;
+ std::string TypeString = RT.getAsString(SubPolicy);
if (LengthOfPrefix > 0) {
// property name must strip off "is" and lower case the first character
// after that; e.g. isContinuous will become continuous.
StringRef PropertyNameStringRef(PropertyNameString);
PropertyNameStringRef = PropertyNameStringRef.drop_front(LengthOfPrefix);
PropertyNameString = PropertyNameStringRef;
- std::string NewPropertyNameString = PropertyNameString;
- bool NoLowering = (isUppercase(NewPropertyNameString[0]) &&
- NewPropertyNameString.size() > 1 &&
- isUppercase(NewPropertyNameString[1]));
+ bool NoLowering = (isUppercase(PropertyNameString[0]) &&
+ PropertyNameString.size() > 1 &&
+ isUppercase(PropertyNameString[1]));
if (!NoLowering)
- NewPropertyNameString[0] = toLowercase(NewPropertyNameString[0]);
- PropertyString += NewPropertyNameString;
+ PropertyNameString[0] = toLowercase(PropertyNameString[0]);
}
- else
+ if (RT->isBlockPointerType() || RT->isFunctionPointerType())
+ MigrateBlockOrFunctionPointerTypeVariable(PropertyString,
+ TypeString,
+ PropertyNameString.c_str());
+ else {
+ char LastChar = TypeString[TypeString.size()-1];
+ PropertyString += TypeString;
+ if (LastChar != '*')
+ PropertyString += ' ';
PropertyString += PropertyNameString;
+ }
SourceLocation StartGetterSelectorLoc = Getter->getSelectorStartLoc();
Selector GetterSelector = Getter->getSelector();
Modified: cfe/trunk/test/ARCMT/objcmt-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m?rev=192226&r1=192225&r2=192226&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m Tue Oct 8 15:14:24 2013
@@ -1,7 +1,7 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -objcmt-migrate-readwrite-property -objcmt-migrate-readonly-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
+// RUN: %clang_cc1 -fblocks -objcmt-migrate-readwrite-property -objcmt-migrate-readonly-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
// 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 %s.result
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result
#define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION
#define WEAK_IMPORT_ATTRIBUTE __attribute__((objc_arc_weak_reference_unavailable))
@@ -215,3 +215,12 @@ DEPRECATED
- (BOOL)isDouble; // Not a valid property
@end
+
+// rdar://15082818
+ at class NSMutableDictionary;
+
+ at interface NSArray
+- (id (^)(id, NSArray *, NSMutableDictionary *)) expressionBlock;
+- (id (^)(id, NSArray *, NSMutableDictionary *)) MyBlock;
+- (void) setMyBlock : (id (^)(id, NSArray *, NSMutableDictionary *)) bl;
+ 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=192226&r1=192225&r2=192226&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Tue Oct 8 15:14:24 2013
@@ -1,7 +1,7 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -objcmt-migrate-readwrite-property -objcmt-migrate-readonly-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
+// RUN: %clang_cc1 -fblocks -objcmt-migrate-readwrite-property -objcmt-migrate-readonly-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
// 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 %s.result
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result
#define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION
#define WEAK_IMPORT_ATTRIBUTE __attribute__((objc_arc_weak_reference_unavailable))
@@ -215,3 +215,12 @@ DEPRECATED
- (BOOL)isDouble; // Not a valid property
@end
+
+// rdar://15082818
+ at class NSMutableDictionary;
+
+ at interface NSArray
+ at property (nonatomic, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+ at property (nonatomic, copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *);
+
+ at end
More information about the cfe-commits
mailing list