<p dir="ltr">Test?</p>
<div class="gmail_quote">On Jan 10, 2013 10:07 AM, "Alexander Kornienko" <<a href="mailto:alexfh@google.com">alexfh@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: alexfh<br>
Date: Thu Jan 10 09:05:09 2013<br>
New Revision: 172071<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=172071&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=172071&view=rev</a><br>
Log:<br>
Basic support for diagnostics.<br>
<br>
Summary: Uses DiagnosticsEngine to output diagnostics.<br>
<br>
Reviewers: djasper, klimek<br>
<br>
Reviewed By: djasper<br>
<br>
CC: cfe-commits<br>
<br>
Differential Revision: <a href="http://llvm-reviews.chandlerc.com/D278" target="_blank">http://llvm-reviews.chandlerc.com/D278</a><br>
<br>
Modified:<br>
cfe/trunk/lib/Format/Format.cpp<br>
cfe/trunk/lib/Format/UnwrappedLineParser.cpp<br>
cfe/trunk/lib/Format/UnwrappedLineParser.h<br>
<br>
Modified: cfe/trunk/lib/Format/Format.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172071&r1=172070&r2=172071&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172071&r1=172070&r2=172071&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Thu Jan 10 09:05:09 2013<br>
@@ -18,8 +18,10 @@<br>
<br>
#include "clang/Format/Format.h"<br>
#include "UnwrappedLineParser.h"<br>
+#include "clang/Basic/Diagnostic.h"<br>
#include "clang/Basic/OperatorPrecedence.h"<br>
#include "clang/Basic/SourceManager.h"<br>
+#include "clang/Frontend/TextDiagnosticPrinter.h"<br>
#include "clang/Lex/Lexer.h"<br>
#include <string><br>
<br>
@@ -1222,10 +1224,11 @@<br>
<br>
class Formatter : public UnwrappedLineConsumer {<br>
public:<br>
- Formatter(const FormatStyle &Style, Lexer &Lex, SourceManager &SourceMgr,<br>
+ Formatter(clang::DiagnosticsEngine &Diag, const FormatStyle &Style,<br>
+ Lexer &Lex, SourceManager &SourceMgr,<br>
const std::vector<CharSourceRange> &Ranges)<br>
- : Style(Style), Lex(Lex), SourceMgr(SourceMgr), Ranges(Ranges),<br>
- StructuralError(false) {<br>
+ : Diag(Diag), Style(Style), Lex(Lex), SourceMgr(SourceMgr),<br>
+ Ranges(Ranges), StructuralError(false) {<br>
}<br>
<br>
virtual ~Formatter() {<br>
@@ -1233,7 +1236,7 @@<br>
<br>
tooling::Replacements format() {<br>
LexerBasedFormatTokenSource Tokens(Lex, SourceMgr);<br>
- UnwrappedLineParser Parser(Style, Tokens, *this);<br>
+ UnwrappedLineParser Parser(Diag, Style, Tokens, *this);<br>
StructuralError = Parser.parse();<br>
unsigned PreviousEndOfLineColumn = 0;<br>
for (std::vector<UnwrappedLine>::iterator I = UnwrappedLines.begin(),<br>
@@ -1284,6 +1287,7 @@<br>
1;<br>
}<br>
<br>
+ clang::DiagnosticsEngine &Diag;<br>
FormatStyle Style;<br>
Lexer &Lex;<br>
SourceManager &SourceMgr;<br>
@@ -1296,7 +1300,14 @@<br>
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,<br>
SourceManager &SourceMgr,<br>
std::vector<CharSourceRange> Ranges) {<br>
- Formatter formatter(Style, Lex, SourceMgr, Ranges);<br>
+ IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();<br>
+ TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts);<br>
+ DiagnosticPrinter.BeginSourceFile(Lex.getLangOpts(), Lex.getPP());<br>
+ DiagnosticsEngine Diagnostics(<br>
+ llvm::IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,<br>
+ &DiagnosticPrinter, false);<br>
+ Diagnostics.setSourceManager(&SourceMgr);<br>
+ Formatter formatter(Diagnostics, Style, Lex, SourceMgr, Ranges);<br>
return formatter.format();<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=172071&r1=172070&r2=172071&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=172071&r1=172070&r2=172071&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)<br>
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Jan 10 09:05:09 2013<br>
@@ -17,6 +17,7 @@<br>
//===----------------------------------------------------------------------===//<br>
<br>
#include "UnwrappedLineParser.h"<br>
+#include "clang/Basic/Diagnostic.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
<br>
// Uncomment to get debug output from the UnwrappedLineParser.<br>
@@ -110,12 +111,12 @@<br>
bool PreBlockRootTokenInitialized;<br>
};<br>
<br>
-UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style,<br>
- FormatTokenSource &Tokens,<br>
- UnwrappedLineConsumer &Callback)<br>
+UnwrappedLineParser::UnwrappedLineParser(<br>
+ clang::DiagnosticsEngine &Diag, const FormatStyle &Style,<br>
+ FormatTokenSource &Tokens, UnwrappedLineConsumer &Callback)<br>
: Line(new UnwrappedLine), RootTokenInitialized(false),<br>
- LastInCurrentLine(NULL), MustBreakBeforeNextToken(false), Style(Style),<br>
- Tokens(&Tokens), Callback(Callback) {<br>
+ LastInCurrentLine(NULL), MustBreakBeforeNextToken(false), Diag(Diag),<br>
+ Style(Style), Tokens(&Tokens), Callback(Callback) {<br>
}<br>
<br>
bool UnwrappedLineParser::parse() {<br>
@@ -149,7 +150,9 @@<br>
if (HasOpeningBrace) {<br>
return false;<br>
} else {<br>
- // Stray '}' is an error.<br>
+ Diag.Report(FormatTok.Tok.getLocation(),<br>
+ Diag.getCustomDiagID(clang::DiagnosticsEngine::Error,<br>
+ "Stray '}' found"));<br>
Error = true;<br>
nextToken();<br>
addUnwrappedLine();<br>
<br>
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=172071&r1=172070&r2=172071&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=172071&r1=172070&r2=172071&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)<br>
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Thu Jan 10 09:05:09 2013<br>
@@ -27,6 +27,9 @@<br>
#include <vector><br>
<br>
namespace clang {<br>
+<br>
+class DiagnosticsEngine;<br>
+<br>
namespace format {<br>
<br>
/// \brief A wrapper around a \c Token storing information about the<br>
@@ -116,7 +119,8 @@<br>
<br>
class UnwrappedLineParser {<br>
public:<br>
- UnwrappedLineParser(const FormatStyle &Style, FormatTokenSource &Tokens,<br>
+ UnwrappedLineParser(clang::DiagnosticsEngine &Diag, const FormatStyle &Style,<br>
+ FormatTokenSource &Tokens,<br>
UnwrappedLineConsumer &Callback);<br>
<br>
/// Returns true in case of a structural error.<br>
@@ -161,6 +165,7 @@<br>
FormatToken FormatTok;<br>
bool MustBreakBeforeNextToken;<br>
<br>
+ clang::DiagnosticsEngine &Diag;<br>
const FormatStyle &Style;<br>
FormatTokenSource *Tokens;<br>
UnwrappedLineConsumer &Callback;<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>