r197075 - [objcmt] When whitelisting the headers we want to modify, allow changing the

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Dec 11 13:39:00 PST 2013


Author: akirtzidis
Date: Wed Dec 11 15:39:00 2013
New Revision: 197075

URL: http://llvm.org/viewvc/llvm-project?rev=197075&view=rev
Log:
[objcmt] When whitelisting the headers we want to modify, allow changing the
the ObjC implementation declarations, just don't change implementations for
classes that are not in the whitelisted headers.

For example, if we change a method to return 'instancetype' we should also
update the method definition in the implementation.

Added:
    cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m
    cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m.result
Modified:
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
    cfe/trunk/test/ARCMT/whitelisted/header1.h
    cfe/trunk/test/ARCMT/whitelisted/header1.h.result
    cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=197075&r1=197074&r2=197075&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Dec 11 15:39:00 2013
@@ -144,6 +144,30 @@ protected:
     return WhiteListFilenames.find(llvm::sys::path::filename(Path))
         != WhiteListFilenames.end();
   }
+  bool canModifyFile(const FileEntry *FE) {
+    if (!FE)
+      return false;
+    return canModifyFile(FE->getName());
+  }
+  bool canModifyFile(FileID FID) {
+    if (FID.isInvalid())
+      return false;
+    return canModifyFile(PP.getSourceManager().getFileEntryForID(FID));
+  }
+
+  bool canModify(const Decl *D) {
+    if (!D)
+      return false;
+    if (const ObjCCategoryImplDecl *CatImpl = dyn_cast<ObjCCategoryImplDecl>(D))
+      return canModify(CatImpl->getCategoryDecl());
+    if (const ObjCImplementationDecl *Impl = dyn_cast<ObjCImplementationDecl>(D))
+      return canModify(Impl->getClassInterface());
+    if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
+      return canModify(cast<Decl>(MD->getDeclContext()));
+
+    FileID FID = PP.getSourceManager().getFileID(D->getLocation());
+    return canModifyFile(FID);
+  }
 };
 
 }
@@ -1651,20 +1675,25 @@ void ObjCMigrateASTConsumer::HandleTrans
         }
       
       if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
-        migrateObjCInterfaceDecl(Ctx, CDecl);
+        if (canModify(CDecl))
+          migrateObjCInterfaceDecl(Ctx, CDecl);
       if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(*D)) {
-        migrateObjCInterfaceDecl(Ctx, CatDecl);
+        if (canModify(CatDecl))
+          migrateObjCInterfaceDecl(Ctx, CatDecl);
       }
       else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D))
         ObjCProtocolDecls.insert(PDecl);
       else if (const ObjCImplementationDecl *ImpDecl =
                dyn_cast<ObjCImplementationDecl>(*D)) {
-        if (ASTMigrateActions & FrontendOptions::ObjCMT_ProtocolConformance)
+        if ((ASTMigrateActions & FrontendOptions::ObjCMT_ProtocolConformance) &&
+            canModify(ImpDecl))
           migrateProtocolConformance(Ctx, ImpDecl);
       }
       else if (const EnumDecl *ED = dyn_cast<EnumDecl>(*D)) {
         if (!(ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros))
           continue;
+        if (!canModify(ED))
+          continue;
         DeclContext::decl_iterator N = D;
         if (++N != DEnd) {
           const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N);
@@ -1677,6 +1706,8 @@ void ObjCMigrateASTConsumer::HandleTrans
       else if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*D)) {
         if (!(ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros))
           continue;
+        if (!canModify(TD))
+          continue;
         DeclContext::decl_iterator N = D;
         if (++N == DEnd)
           continue;
@@ -1698,22 +1729,27 @@ void ObjCMigrateASTConsumer::HandleTrans
         CacheObjCNSIntegerTypedefed(TD);
       }
       else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D)) {
-        if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation)
+        if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) &&
+            canModify(FD))
           migrateCFAnnotation(Ctx, FD);
       }
       
       if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D)) {
+        bool CanModify = canModify(CDecl);
         // migrate methods which can have instancetype as their result type.
-        if (ASTMigrateActions & FrontendOptions::ObjCMT_Instancetype)
+        if ((ASTMigrateActions & FrontendOptions::ObjCMT_Instancetype) &&
+            CanModify)
           migrateAllMethodInstaceType(Ctx, CDecl);
         // annotate methods with CF annotations.
-        if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation)
+        if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) &&
+            CanModify)
           migrateARCSafeAnnotation(Ctx, CDecl);
       }
 
       if (const ObjCImplementationDecl *
             ImplD = dyn_cast<ObjCImplementationDecl>(*D)) {
-        if (ASTMigrateActions & FrontendOptions::ObjCMT_DesignatedInitializer)
+        if ((ASTMigrateActions & FrontendOptions::ObjCMT_DesignatedInitializer) &&
+            canModify(ImplD))
           inferDesignatedInitializers(Ctx, ImplD);
       }
     }
@@ -1733,8 +1769,6 @@ void ObjCMigrateASTConsumer::HandleTrans
     assert(file);
     if (IsReallyASystemHeader(Ctx, file, FID))
       continue;
-    if (!canModifyFile(file->getName()))
-      continue;
     SmallString<512> newText;
     llvm::raw_svector_ostream vecOS(newText);
     buf.write(vecOS);

Modified: cfe/trunk/test/ARCMT/whitelisted/header1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/header1.h?rev=197075&r1=197074&r2=197075&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/header1.h (original)
+++ cfe/trunk/test/ARCMT/whitelisted/header1.h Wed Dec 11 15:39:00 2013
@@ -2,4 +2,5 @@
 @interface I1 : NSObject
 -(int)prop;
 -(void)setProp:(int)p;
++(id)i1;
 @end

Modified: cfe/trunk/test/ARCMT/whitelisted/header1.h.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/header1.h.result?rev=197075&r1=197074&r2=197075&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/header1.h.result (original)
+++ cfe/trunk/test/ARCMT/whitelisted/header1.h.result Wed Dec 11 15:39:00 2013
@@ -1,4 +1,5 @@
 
 @interface I1 : NSObject
 @property (nonatomic) int prop;
++(instancetype)i1;
 @end

Added: cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m?rev=197075&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m (added)
+++ cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m Wed Dec 11 15:39:00 2013
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-readwrite-property -objcmt-migrate-instancetype -objcmt-white-list-dir-path=%S/Inputs %s -triple x86_64-apple-darwin11 -migrate -o %t.remap
+// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %S/header1.h.result %s.result
+
+ at interface NSObject
++ (id)alloc;
+ at end
+
+#include "header1.h"
+#include "header2.h"
+
+ at interface I2(cat)
+-(id)initInCat;
+ at end
+
+ at implementation I1
++(id)i1 {}
+ at end

Added: cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m.result?rev=197075&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m.result (added)
+++ cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist-impl.m.result Wed Dec 11 15:39:00 2013
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-readwrite-property -objcmt-migrate-instancetype -objcmt-white-list-dir-path=%S/Inputs %s -triple x86_64-apple-darwin11 -migrate -o %t.remap
+// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %S/header1.h.result %s.result
+
+ at interface NSObject
++ (id)alloc;
+ at end
+
+#include "header1.h"
+#include "header2.h"
+
+ at interface I2(cat)
+-(id)initInCat;
+ at end
+
+ at implementation I1
++(instancetype)i1 {}
+ at end

Modified: cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m?rev=197075&r1=197074&r2=197075&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m (original)
+++ cfe/trunk/test/ARCMT/whitelisted/objcmt-with-whitelist.m Wed Dec 11 15:39:00 2013
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -objcmt-migrate-readwrite-property %s -triple x86_64-apple-darwin11 -migrate -o %t.remap
+// RUN: %clang_cc1 -objcmt-migrate-readwrite-property -objcmt-migrate-instancetype %s -triple x86_64-apple-darwin11 -migrate -o %t.remap
 // RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %S/header1.h.result %S/header2.h.result
-// RUN: %clang_cc1 -objcmt-migrate-readwrite-property -objcmt-white-list-dir-path=%S/Inputs %s -triple x86_64-apple-darwin11 -migrate -o %t.remap
+// RUN: %clang_cc1 -objcmt-migrate-readwrite-property -objcmt-migrate-instancetype -objcmt-white-list-dir-path=%S/Inputs %s -triple x86_64-apple-darwin11 -migrate -o %t.remap
 // RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %S/header1.h.result
 
 @interface NSObject





More information about the cfe-commits mailing list