summaryrefslogtreecommitdiffstats
path: root/tools/clang-format/ClangFormat.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-09-29 07:53:08 +0000
committerDaniel Jasper <djasper@google.com>2015-09-29 07:53:08 +0000
commit8580b330e6deb73c9f71eaa1757abd16ac6c91a1 (patch)
tree0ac612018c95cd933233be97958b65522d5fcee9 /tools/clang-format/ClangFormat.cpp
parenta981b2df0484fe4530123bd8305b78324807ed1f (diff)
clang-format: Extend #include sorting functionality
Recognize the main module header as well as different #include categories. This should now mimic the behavior of llvm/utils/sort_includes.py as well as clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp very closely. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248782 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format/ClangFormat.cpp')
-rw-r--r--tools/clang-format/ClangFormat.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp
index ce9324e304..3d6fef0d09 100644
--- a/tools/clang-format/ClangFormat.cpp
+++ b/tools/clang-format/ClangFormat.cpp
@@ -73,7 +73,7 @@ FallbackStyle("fallback-style",
cl::init("LLVM"), cl::cat(ClangFormatCategory));
static cl::opt<std::string>
-AssumeFilename("assume-filename",
+AssumeFileName("assume-filename",
cl::desc("When reading from stdin, clang-format assumes this\n"
"filename to look for a style config file (with\n"
"-style=file) and to determine the language."),
@@ -239,13 +239,13 @@ static bool format(StringRef FileName) {
std::vector<tooling::Range> Ranges;
if (fillRanges(Code.get(), Ranges))
return true;
- FormatStyle FormatStyle = getStyle(
- Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle);
+ StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
+ FormatStyle FormatStyle = getStyle(Style, AssumedFileName, FallbackStyle);
Replacements Replaces;
std::string ChangedCode;
if (SortIncludes) {
Replaces =
- sortIncludes(FormatStyle, Code->getBuffer(), Ranges, FileName);
+ sortIncludes(FormatStyle, Code->getBuffer(), Ranges, AssumedFileName);
ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replaces);
for (const auto &R : Replaces)
Ranges.push_back({R.getOffset(), R.getLength()});
@@ -324,7 +324,7 @@ int main(int argc, const char **argv) {
if (DumpConfig) {
std::string Config =
clang::format::configurationAsText(clang::format::getStyle(
- Style, FileNames.empty() ? AssumeFilename : FileNames[0],
+ Style, FileNames.empty() ? AssumeFileName : FileNames[0],
FallbackStyle));
llvm::outs() << Config << "\n";
return 0;