diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-01-14 11:34:14 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-01-14 11:34:14 +0000 |
commit | a4ae9f30ef7bccdaa3feef8036af07fbb91f107c (patch) | |
tree | 8ad6c13025dcfb2778c32dfb3ff9772b99e4de2d /lib/Format | |
parent | 1b6f4bd8d7e75e775053b1cb1281c6a127746e93 (diff) |
Custom DiagnosticConsumer parameter of reformat() + silence diagnostics in unit tests.
Summary:
Added tests for clang-format diagnostics. Added DiagnosticConsumer
argument to clang::format::reformat().
Reviewers: klimek, djasper
Reviewed By: djasper
CC: cfe-commits, thakis, rafael.espindola
Differential Revision: http://llvm-reviews.chandlerc.com/D290
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172399 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/Format.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 67a5b8c4cd..548bdee2b2 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1331,7 +1331,7 @@ private: class Formatter : public UnwrappedLineConsumer { public: - Formatter(clang::DiagnosticsEngine &Diag, const FormatStyle &Style, + Formatter(DiagnosticsEngine &Diag, const FormatStyle &Style, Lexer &Lex, SourceManager &SourceMgr, const std::vector<CharSourceRange> &Ranges) : Diag(Diag), Style(Style), Lex(Lex), SourceMgr(SourceMgr), @@ -1517,7 +1517,7 @@ private: return Indent; } - clang::DiagnosticsEngine &Diag; + DiagnosticsEngine &Diag; FormatStyle Style; Lexer &Lex; SourceManager &SourceMgr; @@ -1529,13 +1529,18 @@ private: tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, SourceManager &SourceMgr, - std::vector<CharSourceRange> Ranges) { + std::vector<CharSourceRange> Ranges, + DiagnosticConsumer *DiagClient) { IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); - TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts); - DiagnosticPrinter.BeginSourceFile(Lex.getLangOpts(), Lex.getPP()); + OwningPtr<DiagnosticConsumer> DiagPrinter; + if (DiagClient == 0) { + DiagPrinter.reset(new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts)); + DiagPrinter->BeginSourceFile(Lex.getLangOpts(), Lex.getPP()); + DiagClient = DiagPrinter.get(); + } DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, - &DiagnosticPrinter, false); + DiagClient, false); Diagnostics.setSourceManager(&SourceMgr); Formatter formatter(Diagnostics, Style, Lex, SourceMgr, Ranges); return formatter.format(); |