]> granicus.if.org Git - clang/commitdiff
Objective-C SDK modernization. import Foundation even
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 9 Oct 2014 22:04:27 +0000 (22:04 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 9 Oct 2014 22:04:27 +0000 (22:04 +0000)
when a previous definition of NS_OPTION is available
; e.g. from a pch. enhancement to rdar://18498550

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219448 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-ns-macros.m.result
test/ARCMT/objcmt-undefined-ns-macros.m.result

index 7eebdb78d8982acd2538f4981f314682834ecd42..c6e4aaaac0c6336c22eff23c76e914812b74903d 100644 (file)
@@ -918,8 +918,7 @@ bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
     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::migrateNSEnumDecl(ASTContext &Ctx,
   
   // 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::InsertFoundation(ASTContext &Ctx,
     return false;
   edit::Commit commit(*Editor);
   if (Ctx.getLangOpts().Modules)
-    commit.insert(Loc, "@import Foundation;\n");
+    commit.insert(Loc, "#ifndef NS_ENUM\n@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;
index 42f3239c84b414c032116787725ceeea4e7e4ca7..9087065c2912882812b42c2e893439c444336633 100644 (file)
@@ -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
index 92cdfe3d7cfdc8bc8788c82ce708660f71b03abc..866e4d0e0f15fa709d83ffa463581d3ec513bc08 100644 (file)
@@ -5,7 +5,9 @@
 // rdar://18498550
 
 typedef long NSInteger;
+#ifndef NS_ENUM
 @import Foundation;
+#endif
 typedef NS_OPTIONS(NSUInteger, UITableStyle) {
     UIViewNone         = 0x0,
     UIViewMargin       = 0x1,