r219448 - Objective-C SDK modernization. import Foundation even

Fariborz Jahanian fjahanian at apple.com
Thu Oct 9 15:04:27 PDT 2014


Author: fjahanian
Date: Thu Oct  9 17:04:27 2014
New Revision: 219448

URL: http://llvm.org/viewvc/llvm-project?rev=219448&view=rev
Log:
Objective-C SDK modernization. import Foundation even
when a previous definition of NS_OPTION is available
; e.g. from a pch. enhancement to rdar://18498550

Modified:
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
    cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result
    cfe/trunk/test/ARCMT/objcmt-undefined-ns-macros.m.result

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=219448&r1=219447&r2=219448&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Thu Oct  9 17:04:27 2014
@@ -918,8 +918,7 @@ bool ObjCMigrateASTConsumer::migrateNSEn
     if (const EnumType *EnumTy = qt->getAs<EnumType>()) {
       if (EnumTy->getDecl() == EnumDcl) {
         bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl);
-        if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition() &&
-            !InsertFoundation(Ctx, TypedefDcl->getLocStart()))
+        if (!InsertFoundation(Ctx, TypedefDcl->getLocStart()))
           return false;
         edit::Commit commit(*Editor);
         rewriteToNSMacroDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, !NSOptions);
@@ -932,9 +931,7 @@ bool ObjCMigrateASTConsumer::migrateNSEn
   
   // We may still use NS_OPTIONS based on what we find in the enumertor list.
   bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl);
-  // For sanity check, see if macro NS_ENUM can be seen.
-  if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition()
-        && !InsertFoundation(Ctx, TypedefDcl->getLocStart()))
+  if (!InsertFoundation(Ctx, TypedefDcl->getLocStart()))
     return false;
   edit::Commit commit(*Editor);
   bool Res = rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj,
@@ -1727,9 +1724,9 @@ bool ObjCMigrateASTConsumer::InsertFound
     return false;
   edit::Commit commit(*Editor);
   if (Ctx.getLangOpts().Modules)
-    commit.insert(Loc, "@import Foundation;\n");
+    commit.insert(Loc, "#ifndef NS_ENUM\n at import Foundation;\n#endif\n");
   else
-    commit.insert(Loc, "#import <Foundation/Foundation.h>\n");
+    commit.insert(Loc, "#ifndef NS_ENUM\n#import <Foundation/Foundation.h>\n#endif\n");
   Editor->commit(commit);
   FoundationIncluded = true;
   return true;

Modified: cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result?rev=219448&r1=219447&r2=219448&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result Thu Oct  9 17:04:27 2014
@@ -19,6 +19,9 @@ typedef unsigned long long uint64_t;
 #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
 #define DEPRECATED  __attribute__((deprecated))
 
+#ifndef NS_ENUM
+#import <Foundation/Foundation.h>
+#endif
 typedef NS_ENUM(NSInteger, wibble) {
   blah,
   blarg

Modified: cfe/trunk/test/ARCMT/objcmt-undefined-ns-macros.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-undefined-ns-macros.m.result?rev=219448&r1=219447&r2=219448&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-undefined-ns-macros.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-undefined-ns-macros.m.result Thu Oct  9 17:04:27 2014
@@ -5,7 +5,9 @@
 // rdar://18498550
 
 typedef long NSInteger;
+#ifndef NS_ENUM
 @import Foundation;
+#endif
 typedef NS_OPTIONS(NSUInteger, UITableStyle) {
     UIViewNone         = 0x0,
     UIViewMargin       = 0x1,





More information about the cfe-commits mailing list