diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2017-06-29 23:20:54 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2017-06-29 23:20:54 +0000 |
commit | fe7b37a8ff38f40535f98de2e7b72bdd185cd1ae (patch) | |
tree | d845f2fc06ccbdee5d7f81a0c815153120f680ff /lib/Format | |
parent | ae1ed388cd6e265fdbb773a11f6797dee9d16fd6 (diff) |
[clang-format] Switch to case-insensitive header matching and use it to
improve support for LLVM-style include sorting.
This really is a collection of improvements to the rules for LLVM
include sorting:
- We have gmock headers now, so it adds support for those to one of the
categories.
- LLVM does use 'FooTest.cpp' files to test 'Foo.h' so it adds that
suffix for finding a main header.
- At times the test file's case may not match the header file's case, so
switch to case-insensitive regex matching of header names.
With this set of changes, I can't spot any misbehaviors when re-sorting
all of LLVM's unittest '#include' lines.
Thanks to Eric and Daniel for help testing and refining the patch during
review!
Differential Revision: https://reviews.llvm.org/D33932
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306759 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/Format.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 7659d56adf..94147fcbd2 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -579,9 +579,9 @@ FormatStyle getLLVMStyle() { LLVMStyle.ForEachMacros.push_back("Q_FOREACH"); LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH"); LLVMStyle.IncludeCategories = {{"^\"(llvm|llvm-c|clang|clang-c)/", 2}, - {"^(<|\"(gtest|isl|json)/)", 3}, + {"^(<|\"(gtest|gmock|isl|json)/)", 3}, {".*", 1}}; - LLVMStyle.IncludeIsMainRegex = "$"; + LLVMStyle.IncludeIsMainRegex = "(Test)?$"; LLVMStyle.IndentCaseLabels = false; LLVMStyle.IndentWrappedFunctionNames = false; LLVMStyle.IndentWidth = 2; @@ -1409,7 +1409,7 @@ public: : Style(Style), FileName(FileName) { FileStem = llvm::sys::path::stem(FileName); for (const auto &Category : Style.IncludeCategories) - CategoryRegexs.emplace_back(Category.Regex); + CategoryRegexs.emplace_back(Category.Regex, llvm::Regex::IgnoreCase); IsMainFile = FileName.endswith(".c") || FileName.endswith(".cc") || FileName.endswith(".cpp") || FileName.endswith(".c++") || FileName.endswith(".cxx") || FileName.endswith(".m") || @@ -1437,9 +1437,11 @@ private: return false; StringRef HeaderStem = llvm::sys::path::stem(IncludeName.drop_front(1).drop_back(1)); - if (FileStem.startswith(HeaderStem)) { + if (FileStem.startswith(HeaderStem) || + FileStem.startswith_lower(HeaderStem)) { llvm::Regex MainIncludeRegex( - (HeaderStem + Style.IncludeIsMainRegex).str()); + (HeaderStem + Style.IncludeIsMainRegex).str(), + llvm::Regex::IgnoreCase); if (MainIncludeRegex.match(FileStem)) return true; } |