diff options
author | Daniel Jasper <djasper@google.com> | 2015-10-06 11:54:18 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-10-06 11:54:18 +0000 |
commit | 8ce1b8df7690bc25788c7da1b464c654461489b0 (patch) | |
tree | cdcbaf11e6ceaa0e0788dfdcc4050fbcb63ce4bd /clang/lib/Format/Format.cpp | |
parent | 9b30e2b50bcae9615afdbf9bea56deb21686039a (diff) | |
download | llvm-8ce1b8df7690bc25788c7da1b464c654461489b0.zip llvm-8ce1b8df7690bc25788c7da1b464c654461489b0.tar.gz llvm-8ce1b8df7690bc25788c7da1b464c654461489b0.tar.bz2 |
clang-format: Make IncludeCategories configurable in .clang-format file.
This was made much easier by introducing an IncludeCategory struct to
replace the previously used std::pair.
Also, cleaned up documentation and added examples.
llvm-svn: 249392
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 62f94b8..e9a02a0 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -37,6 +37,7 @@ using clang::format::FormatStyle; LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(std::string) +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory) namespace llvm { namespace yaml { @@ -247,6 +248,7 @@ template <> struct MappingTraits<FormatStyle> { IO.mapOptional("ExperimentalAutoDetectBinPacking", Style.ExperimentalAutoDetectBinPacking); IO.mapOptional("ForEachMacros", Style.ForEachMacros); + IO.mapOptional("IncludeCategories", Style.IncludeCategories); IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels); IO.mapOptional("IndentWidth", Style.IndentWidth); IO.mapOptional("IndentWrappedFunctionNames", @@ -307,6 +309,13 @@ template <> struct MappingTraits<FormatStyle::BraceWrappingFlags> { } }; +template <> struct MappingTraits<FormatStyle::IncludeCategory> { + static void mapping(IO &IO, FormatStyle::IncludeCategory &Category) { + IO.mapOptional("Regex", Category.Regex); + IO.mapOptional("Priority", Category.Priority); + } +}; + // Allows to read vector<FormatStyle> while keeping default values. // IO.getContext() should contain a pointer to the FormatStyle structure, that // will be used to get default values for missing keys. @@ -1737,8 +1746,8 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, // Create pre-compiled regular expressions for the #include categories. SmallVector<llvm::Regex, 4> CategoryRegexs; - for (const auto &IncludeBlock : Style.IncludeCategories) - CategoryRegexs.emplace_back(IncludeBlock.first); + for (const auto &Category : Style.IncludeCategories) + CategoryRegexs.emplace_back(Category.Regex); for (;;) { auto Pos = Code.find('\n', SearchFrom); @@ -1753,7 +1762,7 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, Category = UINT_MAX; for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i) { if (CategoryRegexs[i].match(Matches[1])) { - Category = Style.IncludeCategories[i].second; + Category = Style.IncludeCategories[i].Priority; break; } } |