r191584 - ObjectiveC migrator. Infer property from getters only

Fariborz Jahanian fjahanian at apple.com
Fri Sep 27 15:55:54 PDT 2013


Author: fjahanian
Date: Fri Sep 27 17:55:54 2013
New Revision: 191584

URL: http://llvm.org/viewvc/llvm-project?rev=191584&view=rev
Log:
ObjectiveC migrator. Infer property from getters only
if property name is a valid identifier in the underlying
language. // rdar://15044184

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=191584&r1=191583&r2=191584&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Fri Sep 27 17:55:54 2013
@@ -761,6 +761,16 @@ static bool AttributesMatch(const Decl *
   return true;
 }
 
+static bool IsValidIdentifier(ASTContext &Ctx,
+                              const char *Name) {
+  if (!isIdentifierHead(Name[0]))
+    return false;
+  std::string NameString = Name;
+  NameString[0] = toLowercase(NameString[0]);
+  IdentifierInfo *II = &Ctx.Idents.get(NameString);
+  return II->getTokenID() ==  tok::identifier;
+}
+
 bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
                              ObjCContainerDecl *D,
                              ObjCMethodDecl *Method) {
@@ -799,7 +809,7 @@ bool ObjCMigrateASTConsumer::migrateProp
       const char *CGetterName = getterNameString.data() + LengthOfPrefix;
       // Make sure that first character after "is" or "get" prefix can
       // start an identifier.
-      if (!isIdentifierHead(CGetterName[0]))
+      if (!IsValidIdentifier(Ctx, CGetterName))
         return false;
       if (CGetterName[0] && isUppercase(CGetterName[0])) {
         getterName = &Ctx.Idents.get(CGetterName);

Modified: cfe/trunk/test/ARCMT/objcmt-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m?rev=191584&r1=191583&r2=191584&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m Fri Sep 27 17:55:54 2013
@@ -210,4 +210,8 @@ DEPRECATED
 - (NSURL *)init;  // No Change
 + (id)alloc;      // No Change
 
+- (BOOL)is1stClass; // Not a valid property
+- (BOOL)isClass;    // This is a valid property 'class' is not a keyword in ObjC
+- (BOOL)isDouble; // Not a valid property
+
 @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=191584&r1=191583&r2=191584&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Fri Sep 27 17:55:54 2013
@@ -210,4 +210,8 @@ DEPRECATED
 - (NSURL *)init;  // No Change
 + (id)alloc;      // No Change
 
+- (BOOL)is1stClass; // Not a valid property
+ at property (nonatomic, getter=isClass, readonly) BOOL class;    // This is a valid property 'class' is not a keyword in ObjC
+- (BOOL)isDouble; // Not a valid property
+
 @end





More information about the cfe-commits mailing list