aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/Format.cpp21
-rw-r--r--lib/Format/UnwrappedLineParser.cpp15
-rw-r--r--lib/Format/UnwrappedLineParser.h7
3 files changed, 31 insertions, 12 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();
}
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index e9c6211313..a6c5c165ff 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -17,6 +17,7 @@
//===----------------------------------------------------------------------===//
#include "UnwrappedLineParser.h"
+#include "clang/Basic/Diagnostic.h"
#include "llvm/Support/raw_ostream.h"
// Uncomment to get debug output from the UnwrappedLineParser.
@@ -110,12 +111,12 @@ private:
bool PreBlockRootTokenInitialized;
};
-UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style,
- FormatTokenSource &Tokens,
- UnwrappedLineConsumer &Callback)
+UnwrappedLineParser::UnwrappedLineParser(
+ clang::DiagnosticsEngine &Diag, const FormatStyle &Style,
+ FormatTokenSource &Tokens, UnwrappedLineConsumer &Callback)
: Line(new UnwrappedLine), RootTokenInitialized(false),
- LastInCurrentLine(NULL), MustBreakBeforeNextToken(false), Style(Style),
- Tokens(&Tokens), Callback(Callback) {
+ LastInCurrentLine(NULL), MustBreakBeforeNextToken(false), Diag(Diag),
+ Style(Style), Tokens(&Tokens), Callback(Callback) {
}
bool UnwrappedLineParser::parse() {
@@ -149,7 +150,9 @@ bool UnwrappedLineParser::parseLevel(bool HasOpeningBrace) {
if (HasOpeningBrace) {
return false;
} else {
- // Stray '}' is an error.
+ Diag.Report(FormatTok.Tok.getLocation(),
+ Diag.getCustomDiagID(clang::DiagnosticsEngine::Error,
+ "Stray '}' found"));
Error = true;
nextToken();
addUnwrappedLine();
diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h
index 017daf587f..837b5391f6 100644
--- a/lib/Format/UnwrappedLineParser.h
+++ b/lib/Format/UnwrappedLineParser.h
@@ -27,6 +27,9 @@
#include <vector>
namespace clang {
+
+class DiagnosticsEngine;
+
namespace format {
/// \brief A wrapper around a \c Token storing information about the
@@ -116,7 +119,8 @@ public:
class UnwrappedLineParser {
public:
- UnwrappedLineParser(const FormatStyle &Style, FormatTokenSource &Tokens,
+ UnwrappedLineParser(clang::DiagnosticsEngine &Diag, const FormatStyle &Style,
+ FormatTokenSource &Tokens,
UnwrappedLineConsumer &Callback);
/// Returns true in case of a structural error.
@@ -161,6 +165,7 @@ private:
FormatToken FormatTok;
bool MustBreakBeforeNextToken;
+ clang::DiagnosticsEngine &Diag;
const FormatStyle &Style;
FormatTokenSource *Tokens;
UnwrappedLineConsumer &Callback;