diff options
| author | Nico Weber <nicolasweber@gmx.de> | 2015-10-21 17:13:45 +0000 |
|---|---|---|
| committer | Nico Weber <nicolasweber@gmx.de> | 2015-10-21 17:13:45 +0000 |
| commit | ff06370e12fb279275c24905659c6d5b4c6a8a7f (patch) | |
| tree | 8a095ad74d935b22193e1503b278edbdecd37d01 /clang/lib | |
| parent | da9dd05011be9f9d6576299a24aee639d212faff (diff) | |
| download | bcm5719-llvm-ff06370e12fb279275c24905659c6d5b4c6a8a7f.tar.gz bcm5719-llvm-ff06370e12fb279275c24905659c6d5b4c6a8a7f.zip | |
clang-format: Teach --sort-includes to interleave #include and #import.
clang accepts both #include and #import for includes (the latter having an
implicit header guard). Let clang-format interleave both types if
--sort-includes is passed. #import is used frequently in Objective-C code.
http://reviews.llvm.org/D13853
llvm-svn: 250909
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 2595a666699..365c22a8ec2 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1732,7 +1732,7 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, unsigned Prev = 0; unsigned SearchFrom = 0; llvm::Regex IncludeRegex( - R"(^[\t\ ]*#[\t\ ]*include[^"<]*(["<][^">]*[">]))"); + R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))"); SmallVector<StringRef, 4> Matches; SmallVector<IncludeDirective, 16> IncludesInBlock; @@ -1762,20 +1762,21 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev); if (!Line.endswith("\\")) { if (IncludeRegex.match(Line, &Matches)) { + StringRef IncludeName = Matches[2]; unsigned Category; - if (LookForMainHeader && !Matches[1].startswith("<")) { + if (LookForMainHeader && !IncludeName.startswith("<")) { Category = 0; } else { Category = UINT_MAX; for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i) { - if (CategoryRegexs[i].match(Matches[1])) { + if (CategoryRegexs[i].match(IncludeName)) { Category = Style.IncludeCategories[i].Priority; break; } } } LookForMainHeader = false; - IncludesInBlock.push_back({Matches[1], Line, Prev, Category}); + IncludesInBlock.push_back({IncludeName, Line, Prev, Category}); } else if (!IncludesInBlock.empty()) { sortIncludes(Style, IncludesInBlock, Ranges, FileName, Replaces); IncludesInBlock.clear(); |

