diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-06-21 12:03:12 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-06-21 12:03:12 +0000 |
commit | b03877ab836bf58fee5228e4ab9348eb1f970abb (patch) | |
tree | 57d30ab0586af4c4885e44da15e613454a2e1110 /clang/lib/Format/Format.cpp | |
parent | 4a084cfde7b34d27da31e9eac9b58b310e40ba6e (diff) | |
download | llvm-b03877ab836bf58fee5228e4ab9348eb1f970abb.zip llvm-b03877ab836bf58fee5228e4ab9348eb1f970abb.tar.gz llvm-b03877ab836bf58fee5228e4ab9348eb1f970abb.tar.bz2 |
[clang-format] Support sorting using declarations
Summary:
This patch adds UsingDeclarationsSorter, a TokenAnalyzer that sorts consecutive
using declarations.
Reviewers: klimek
Reviewed By: klimek
Subscribers: Typz, djasper, cfe-commits, klimek, mgorny
Differential Revision: https://reviews.llvm.org/D33823
llvm-svn: 305901
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 39da87c..aebe22c 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -23,6 +23,7 @@ #include "TokenAnnotator.h" #include "UnwrappedLineFormatter.h" #include "UnwrappedLineParser.h" +#include "UsingDeclarationsSorter.h" #include "WhitespaceManager.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" @@ -1943,6 +1944,16 @@ tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style, return Fix.process(); } +tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, + StringRef Code, + ArrayRef<tooling::Range> Ranges, + StringRef FileName) { + std::unique_ptr<Environment> Env = + Environment::CreateVirtualEnvironment(Code, FileName, Ranges); + UsingDeclarationsSorter Sorter(*Env, Style); + return Sorter.process(); +} + LangOptions getFormattingLangOpts(const FormatStyle &Style) { LangOptions LangOpts; LangOpts.CPlusPlus = 1; |