From a4ae9f30ef7bccdaa3feef8036af07fbb91f107c Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Mon, 14 Jan 2013 11:34:14 +0000 Subject: 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 --- lib/Format/Format.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib/Format/Format.cpp') 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 &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 Ranges) { + std::vector Ranges, + DiagnosticConsumer *DiagClient) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts); - DiagnosticPrinter.BeginSourceFile(Lex.getLangOpts(), Lex.getPP()); + OwningPtr DiagPrinter; + if (DiagClient == 0) { + DiagPrinter.reset(new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts)); + DiagPrinter->BeginSourceFile(Lex.getLangOpts(), Lex.getPP()); + DiagClient = DiagPrinter.get(); + } DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr(new DiagnosticIDs()), &*DiagOpts, - &DiagnosticPrinter, false); + DiagClient, false); Diagnostics.setSourceManager(&SourceMgr); Formatter formatter(Diagnostics, Style, Lex, SourceMgr, Ranges); return formatter.format(); -- cgit v1.2.3-18-g5258