r190532 - ObjectiveC migrator. methods which look like a getter and
Fariborz Jahanian
fjahanian at apple.com
Wed Sep 11 10:05:16 PDT 2013
Author: fjahanian
Date: Wed Sep 11 12:05:15 2013
New Revision: 190532
URL: http://llvm.org/viewvc/llvm-project?rev=190532&view=rev
Log:
ObjectiveC migrator. methods which look like a getter and
start with "get" are inferreed as a readonly properties.
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=190532&r1=190531&r2=190532&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Sep 11 12:05:15 2013
@@ -249,12 +249,12 @@ static void append_attr(std::string &Pro
static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter,
const ObjCMethodDecl *Setter,
const NSAPI &NS, edit::Commit &commit,
- bool GetterHasIsPrefix) {
+ unsigned LengthOfPrefix) {
ASTContext &Context = NS.getASTContext();
std::string PropertyString = "@property(nonatomic";
std::string PropertyNameString = Getter->getNameAsString();
StringRef PropertyName(PropertyNameString);
- if (GetterHasIsPrefix) {
+ if (LengthOfPrefix > 0) {
PropertyString += ", getter=";
PropertyString += PropertyNameString;
}
@@ -305,11 +305,11 @@ static bool rewriteToObjCProperty(const
PropertyString += " ";
PropertyString += RT.getAsString(Context.getPrintingPolicy());
PropertyString += " ";
- if (GetterHasIsPrefix) {
+ 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(2);
+ PropertyNameStringRef = PropertyNameStringRef.drop_front(LengthOfPrefix);
PropertyNameString = PropertyNameStringRef;
std::string NewPropertyNameString = PropertyNameString;
NewPropertyNameString[0] = toLowercase(NewPropertyNameString[0]);
@@ -732,13 +732,19 @@ bool ObjCMigrateASTConsumer::migrateProp
PP.getSelectorTable(),
getterName);
ObjCMethodDecl *SetterMethod = D->lookupMethod(SetterSelector, true);
- bool GetterHasIsPrefix = false;
+ unsigned LengthOfPrefix = 0;
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;
+ bool IsPrefix = getterNameString.startswith("is");
+ if ((IsPrefix && !GRT->isObjCRetainableType()) ||
+ getterNameString.startswith("get")) {
+ LengthOfPrefix = (IsPrefix ? 2 : 3);
+ const char *CGetterName = getterNameString.data() + LengthOfPrefix;
+ // Make sure that first character after "is" or "get" prefix can
+ // start an identifier.
+ if (!isIdentifierHead(CGetterName[0]))
+ return false;
if (CGetterName[0] && isUppercase(CGetterName[0])) {
getterName = &Ctx.Idents.get(CGetterName);
SetterSelector =
@@ -761,7 +767,7 @@ bool ObjCMigrateASTConsumer::migrateProp
return false;
edit::Commit commit(*Editor);
rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit,
- GetterHasIsPrefix);
+ LengthOfPrefix);
Editor->commit(commit);
return true;
}
@@ -770,7 +776,7 @@ bool ObjCMigrateASTConsumer::migrateProp
// as a 'readonly' property.
edit::Commit commit(*Editor);
rewriteToObjCProperty(Method, 0 /*SetterMethod*/, *NSAPIObj, commit,
- GetterHasIsPrefix);
+ LengthOfPrefix);
Editor->commit(commit);
return true;
}
Modified: cfe/trunk/test/ARCMT/objcmt-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m?rev=190532&r1=190531&r2=190532&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m Wed Sep 11 12:05:15 2013
@@ -98,6 +98,14 @@ typedef char BOOL;
+ (double) D;
- (void *)JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
- (BOOL)isIgnoringInteractionEvents;
+
+- (NSString *)getStringValue;
+- (BOOL)getCounterValue;
+- (void)setStringValue:(NSString *)stringValue AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
+- (NSDictionary *)getns_dixtionary;
+
+- (BOOL)is3bar; // watch out
+- (NSString *)get3foo; // watch out
@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=190532&r1=190531&r2=190532&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Wed Sep 11 12:05:15 2013
@@ -98,6 +98,14 @@ typedef char BOOL;
+ (double) D;
@property(nonatomic, readonly) void * JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
@property(nonatomic, getter=isIgnoringInteractionEvents, readonly) BOOL ignoringInteractionEvents;
+
+ at property(nonatomic, getter=getStringValue, retain) NSString * stringValue;
+ at property(nonatomic, getter=getCounterValue, readonly) BOOL counterValue;
+
+ at property(nonatomic, getter=getns_dixtionary, readonly) NSDictionary * ns_dixtionary;
+
+- (BOOL)is3bar; // watch out
+- (NSString *)get3foo; // watch out
@end
More information about the cfe-commits
mailing list