r275589 - [objcmt] Don't add an #import of Foundation unnecessarily, if the NS_ENUM macro is already defined.

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 15 11:11:27 PDT 2016


Author: akirtzidis
Date: Fri Jul 15 13:11:27 2016
New Revision: 275589

URL: http://llvm.org/viewvc/llvm-project?rev=275589&view=rev
Log:
[objcmt] Don't add an #import of Foundation unnecessarily, if the NS_ENUM macro is already defined.

Modified:
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
    cfe/trunk/test/ARCMT/objcmt-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=275589&r1=275588&r2=275589&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Fri Jul 15 13:11:27 2016
@@ -1737,6 +1737,11 @@ bool ObjCMigrateASTConsumer::InsertFound
     return true;
   if (Loc.isInvalid())
     return false;
+  auto *nsEnumId = &Ctx.Idents.get("NS_ENUM");
+  if (PP.getMacroDefinitionAtLoc(nsEnumId, Loc)) {
+    FoundationIncluded = true;
+    return true;
+  }
   edit::Commit commit(*Editor);
   if (Ctx.getLangOpts().Modules)
     commit.insert(Loc, "#ifndef NS_ENUM\n at import Foundation;\n#endif\n");

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=275589&r1=275588&r2=275589&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result Fri Jul 15 13:11:27 2016
@@ -19,9 +19,6 @@ 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




More information about the cfe-commits mailing list