From: Fariborz Jahanian Date: Thu, 9 Oct 2014 22:04:27 +0000 (+0000) Subject: Objective-C SDK modernization. import Foundation even X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d0bde8b47fb354c81cb8c6dcced45f253ec0a71;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219448 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 7eebdb78d8..c6e4aaaac0 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -918,8 +918,7 @@ bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, if (const EnumType *EnumTy = qt->getAs()) { 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 \n"); + commit.insert(Loc, "#ifndef NS_ENUM\n#import \n#endif\n"); Editor->commit(commit); FoundationIncluded = true; return true; diff --git a/test/ARCMT/objcmt-ns-macros.m.result b/test/ARCMT/objcmt-ns-macros.m.result index 42f3239c84..9087065c29 100644 --- a/test/ARCMT/objcmt-ns-macros.m.result +++ b/test/ARCMT/objcmt-ns-macros.m.result @@ -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 +#endif typedef NS_ENUM(NSInteger, wibble) { blah, blarg diff --git a/test/ARCMT/objcmt-undefined-ns-macros.m.result b/test/ARCMT/objcmt-undefined-ns-macros.m.result index 92cdfe3d7c..866e4d0e0f 100644 --- a/test/ARCMT/objcmt-undefined-ns-macros.m.result +++ b/test/ARCMT/objcmt-undefined-ns-macros.m.result @@ -5,7 +5,9 @@ // rdar://18498550 typedef long NSInteger; +#ifndef NS_ENUM @import Foundation; +#endif typedef NS_OPTIONS(NSUInteger, UITableStyle) { UIViewNone = 0x0, UIViewMargin = 0x1,