aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-09-11 17:05:15 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-09-11 17:05:15 +0000
commitca39960f31794edb380c4723e34e2de919e3f4f6 (patch)
tree39f2af92ec053bf55989180d43bce8acaa5d81b5 /clang
parent60ac1269c639a5969237ba496a3544c9175157f6 (diff)
downloadllvm-ca39960f31794edb380c4723e34e2de919e3f4f6.zip
llvm-ca39960f31794edb380c4723e34e2de919e3f4f6.tar.gz
llvm-ca39960f31794edb380c4723e34e2de919e3f4f6.tar.bz2
ObjectiveC migrator. methods which look like a getter and
start with "get" are inferreed as a readonly properties. llvm-svn: 190532
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/ARCMigrate/ObjCMT.cpp26
-rw-r--r--clang/test/ARCMT/objcmt-property.m8
-rw-r--r--clang/test/ARCMT/objcmt-property.m.result8
3 files changed, 32 insertions, 10 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index efe2e85..f550e7c 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -249,12 +249,12 @@ static void append_attr(std::string &PropertyString, const char *attr) {
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 ObjCMethodDecl *Getter,
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::migrateProperty(ASTContext &Ctx,
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::migrateProperty(ASTContext &Ctx,
return false;
edit::Commit commit(*Editor);
rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit,
- GetterHasIsPrefix);
+ LengthOfPrefix);
Editor->commit(commit);
return true;
}
@@ -770,7 +776,7 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
// as a 'readonly' property.
edit::Commit commit(*Editor);
rewriteToObjCProperty(Method, 0 /*SetterMethod*/, *NSAPIObj, commit,
- GetterHasIsPrefix);
+ LengthOfPrefix);
Editor->commit(commit);
return true;
}
diff --git a/clang/test/ARCMT/objcmt-property.m b/clang/test/ARCMT/objcmt-property.m
index 8f9c5f7..9246798 100644
--- a/clang/test/ARCMT/objcmt-property.m
+++ b/clang/test/ARCMT/objcmt-property.m
@@ -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
diff --git a/clang/test/ARCMT/objcmt-property.m.result b/clang/test/ARCMT/objcmt-property.m.result
index a2cecd5..f1caec3 100644
--- a/clang/test/ARCMT/objcmt-property.m.result
+++ b/clang/test/ARCMT/objcmt-property.m.result
@@ -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;
+
+@property(nonatomic, getter=getStringValue, retain) NSString * stringValue;
+@property(nonatomic, getter=getCounterValue, readonly) BOOL counterValue;
+
+@property(nonatomic, getter=getns_dixtionary, readonly) NSDictionary * ns_dixtionary;
+
+- (BOOL)is3bar; // watch out
+- (NSString *)get3foo; // watch out
@end