[PATCH] D55545: Allow IncludeSorter to use #import for Objective-C files

Joe Turner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 10 20:03:35 PST 2018


compositeprimes created this revision.
compositeprimes added reviewers: klimek, alexfh.
Herald added a subscriber: cfe-commits.

The change infers whether a source file is Objective-C using LangOpts, and if it detects Objective-C, it uses "#import" instead of "#include" for all inserted imports.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D55545

Files:
  clang-tidy/utils/IncludeSorter.cpp


Index: clang-tidy/utils/IncludeSorter.cpp
===================================================================
--- clang-tidy/utils/IncludeSorter.cpp
+++ clang-tidy/utils/IncludeSorter.cpp
@@ -113,9 +113,10 @@
 
 Optional<FixItHint> IncludeSorter::CreateIncludeInsertion(StringRef FileName,
                                                           bool IsAngled) {
+  std::string IncludeDirective = LangOpts->ObjC ? "#import " : "#include ";
   std::string IncludeStmt =
-      IsAngled ? llvm::Twine("#include <" + FileName + ">\n").str()
-               : llvm::Twine("#include \"" + FileName + "\"\n").str();
+      IsAngled ? llvm::Twine(IncludeDirective + "<" + FileName + ">\n").str()
+               : llvm::Twine(IncludeDirective + "\"" + FileName + "\"\n").str();
   if (SourceLocations.empty()) {
     // If there are no includes in this file, add it in the first line.
     // FIXME: insert after the file comment or the header guard, if present.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55545.177653.patch
Type: text/x-patch
Size: 959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181211/75973700/attachment-0001.bin>


More information about the cfe-commits mailing list