aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-01-10 15:05:09 +0000
committerAlexander Kornienko <alexfh@google.com>2013-01-10 15:05:09 +0000
commit3048aeae0654b34dcae561494c1b28872c88a5c8 (patch)
treec1e7d87e4041429ea47308b19cfca5244f7ec83f /lib/Format/Format.cpp
parent2851c16443dcdb9d8bb509d321fb827a560b47bc (diff)
Basic support for diagnostics.
Summary: Uses DiagnosticsEngine to output diagnostics. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D278 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172071 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index f64e51f2d7..09874bbd77 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -18,8 +18,10 @@
#include "clang/Format/Format.h"
#include "UnwrappedLineParser.h"
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/OperatorPrecedence.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Lex/Lexer.h"
#include <string>
@@ -1222,10 +1224,11 @@ private:
class Formatter : public UnwrappedLineConsumer {
public:
- Formatter(const FormatStyle &Style, Lexer &Lex, SourceManager &SourceMgr,
+ Formatter(clang::DiagnosticsEngine &Diag, const FormatStyle &Style,
+ Lexer &Lex, SourceManager &SourceMgr,
const std::vector<CharSourceRange> &Ranges)
- : Style(Style), Lex(Lex), SourceMgr(SourceMgr), Ranges(Ranges),
- StructuralError(false) {
+ : Diag(Diag), Style(Style), Lex(Lex), SourceMgr(SourceMgr),
+ Ranges(Ranges), StructuralError(false) {
}
virtual ~Formatter() {
@@ -1233,7 +1236,7 @@ public:
tooling::Replacements format() {
LexerBasedFormatTokenSource Tokens(Lex, SourceMgr);
- UnwrappedLineParser Parser(Style, Tokens, *this);
+ UnwrappedLineParser Parser(Diag, Style, Tokens, *this);
StructuralError = Parser.parse();
unsigned PreviousEndOfLineColumn = 0;
for (std::vector<UnwrappedLine>::iterator I = UnwrappedLines.begin(),
@@ -1284,6 +1287,7 @@ private:
1;
}
+ clang::DiagnosticsEngine &Diag;
FormatStyle Style;
Lexer &Lex;
SourceManager &SourceMgr;
@@ -1296,7 +1300,14 @@ private:
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
SourceManager &SourceMgr,
std::vector<CharSourceRange> Ranges) {
- Formatter formatter(Style, Lex, SourceMgr, Ranges);
+ IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
+ TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts);
+ DiagnosticPrinter.BeginSourceFile(Lex.getLangOpts(), Lex.getPP());
+ DiagnosticsEngine Diagnostics(
+ llvm::IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
+ &DiagnosticPrinter, false);
+ Diagnostics.setSourceManager(&SourceMgr);
+ Formatter formatter(Diagnostics, Style, Lex, SourceMgr, Ranges);
return formatter.format();
}