diff options
Diffstat (limited to 'tools/clang-format/ClangFormat.cpp')
-rw-r--r-- | tools/clang-format/ClangFormat.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index 27577a5a336a..6c50daf53834 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/tools/clang-format/ClangFormat.cpp @@ -20,9 +20,7 @@ #include "clang/Basic/Version.h" #include "clang/Format/Format.h" #include "clang/Rewrite/Core/Rewriter.h" -#include "llvm/ADT/StringMap.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Signals.h" @@ -251,7 +249,8 @@ static bool format(StringRef FileName) { if (fillRanges(Code.get(), Ranges)) return true; StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName; - FormatStyle FormatStyle = getStyle(Style, AssumedFileName, FallbackStyle); + FormatStyle FormatStyle = + getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer()); if (SortIncludes.getNumOccurrences() != 0) FormatStyle.SortIncludes = SortIncludes; unsigned CursorPosition = Cursor; @@ -262,23 +261,22 @@ static bool format(StringRef FileName) { llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; return true; } - for (const auto &R : Replaces) - Ranges.push_back({R.getOffset(), R.getLength()}); - + // Get new affected ranges after sorting `#includes`. + Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges); bool IncompleteFormat = false; Replacements FormatChanges = reformat(FormatStyle, *ChangedCode, Ranges, AssumedFileName, &IncompleteFormat); - Replaces = tooling::mergeReplacements(Replaces, FormatChanges); + Replaces = Replaces.merge(FormatChanges); if (OutputXML) { outs() << "<?xml version='1.0'?>\n<replacements " "xml:space='preserve' incomplete_format='" << (IncompleteFormat ? "true" : "false") << "'>\n"; if (Cursor.getNumOccurrences() != 0) outs() << "<cursor>" - << tooling::shiftedCodePosition(FormatChanges, CursorPosition) + << FormatChanges.getShiftedCodePosition(CursorPosition) << "</cursor>\n"; - outputReplacementsXML(Replaces); + outputReplacementsXML(Replaces); outs() << "</replacements>\n"; } else { IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( @@ -300,7 +298,7 @@ static bool format(StringRef FileName) { } else { if (Cursor.getNumOccurrences() != 0) outs() << "{ \"Cursor\": " - << tooling::shiftedCodePosition(FormatChanges, CursorPosition) + << FormatChanges.getShiftedCodePosition(CursorPosition) << ", \"IncompleteFormat\": " << (IncompleteFormat ? "true" : "false") << " }\n"; Rewrite.getEditBuffer(ID).write(outs()); |