Remove diagnostics from clang-format.

We only ever implemented one and that one is not actually all that
helpful (e.g. gets incorrectly triggered by macros).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181871 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Jasper 2013-05-15 08:14:19 +00:00
Родитель a8fda85af8
Коммит caf42a3ef1
6 изменённых файлов: 13 добавлений и 46 удалений

Просмотреть файл

@ -177,15 +177,11 @@ std::string configurationAsText(const FormatStyle &Style);
/// everything that might influence its formatting or might be influenced by its /// everything that might influence its formatting or might be influenced by its
/// formatting. /// formatting.
/// ///
/// \param DiagClient A custom DiagnosticConsumer. Can be 0, in this case
/// diagnostic is output to llvm::errs().
///
/// Returns the \c Replacements necessary to make all \p Ranges comply with /// Returns the \c Replacements necessary to make all \p Ranges comply with
/// \p Style. /// \p Style.
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
SourceManager &SourceMgr, SourceManager &SourceMgr,
std::vector<CharSourceRange> Ranges, std::vector<CharSourceRange> Ranges);
DiagnosticConsumer *DiagClient = 0);
/// \brief Returns the \c LangOpts that the formatter expects you to set. /// \brief Returns the \c LangOpts that the formatter expects you to set.
LangOptions getFormattingLangOpts(); LangOptions getFormattingLangOpts();

Просмотреть файл

@ -19,11 +19,9 @@
#include "TokenAnnotator.h" #include "TokenAnnotator.h"
#include "UnwrappedLineParser.h" #include "UnwrappedLineParser.h"
#include "WhitespaceManager.h" #include "WhitespaceManager.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/OperatorPrecedence.h" #include "clang/Basic/OperatorPrecedence.h"
#include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h" #include "clang/Format/Format.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Lex/Lexer.h" #include "clang/Lex/Lexer.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Allocator.h" #include "llvm/Support/Allocator.h"
@ -1140,17 +1138,16 @@ private:
class Formatter : public UnwrappedLineConsumer { class Formatter : public UnwrappedLineConsumer {
public: public:
Formatter(DiagnosticsEngine &Diag, const FormatStyle &Style, Lexer &Lex, Formatter(const FormatStyle &Style, Lexer &Lex, SourceManager &SourceMgr,
SourceManager &SourceMgr,
const std::vector<CharSourceRange> &Ranges) const std::vector<CharSourceRange> &Ranges)
: Diag(Diag), Style(Style), Lex(Lex), SourceMgr(SourceMgr), : Style(Style), Lex(Lex), SourceMgr(SourceMgr),
Whitespaces(SourceMgr, Style), Ranges(Ranges) {} Whitespaces(SourceMgr, Style), Ranges(Ranges) {}
virtual ~Formatter() {} virtual ~Formatter() {}
tooling::Replacements format() { tooling::Replacements format() {
LexerBasedFormatTokenSource Tokens(Lex, SourceMgr); LexerBasedFormatTokenSource Tokens(Lex, SourceMgr);
UnwrappedLineParser Parser(Diag, Style, Tokens, *this); UnwrappedLineParser Parser(Style, Tokens, *this);
bool StructuralError = Parser.parse(); bool StructuralError = Parser.parse();
unsigned PreviousEndOfLineColumn = 0; unsigned PreviousEndOfLineColumn = 0;
TokenAnnotator Annotator(Style, SourceMgr, Lex, TokenAnnotator Annotator(Style, SourceMgr, Lex,
@ -1529,7 +1526,6 @@ private:
} }
} }
DiagnosticsEngine &Diag;
FormatStyle Style; FormatStyle Style;
Lexer &Lex; Lexer &Lex;
SourceManager &SourceMgr; SourceManager &SourceMgr;
@ -1540,20 +1536,8 @@ private:
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
SourceManager &SourceMgr, SourceManager &SourceMgr,
std::vector<CharSourceRange> Ranges, std::vector<CharSourceRange> Ranges) {
DiagnosticConsumer *DiagClient) { Formatter formatter(Style, Lex, SourceMgr, Ranges);
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
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,
DiagClient, false);
Diagnostics.setSourceManager(&SourceMgr);
Formatter formatter(Diagnostics, Style, Lex, SourceMgr, Ranges);
return formatter.format(); return formatter.format();
} }

Просмотреть файл

@ -16,7 +16,6 @@
#define DEBUG_TYPE "format-parser" #define DEBUG_TYPE "format-parser"
#include "UnwrappedLineParser.h" #include "UnwrappedLineParser.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
namespace clang { namespace clang {
@ -125,11 +124,11 @@ private:
UnwrappedLine *PreBlockLine; UnwrappedLine *PreBlockLine;
}; };
UnwrappedLineParser::UnwrappedLineParser( UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style,
clang::DiagnosticsEngine &Diag, const FormatStyle &Style, FormatTokenSource &Tokens,
FormatTokenSource &Tokens, UnwrappedLineConsumer &Callback) UnwrappedLineConsumer &Callback)
: Line(new UnwrappedLine), MustBreakBeforeNextToken(false), : Line(new UnwrappedLine), MustBreakBeforeNextToken(false),
CurrentLines(&Lines), StructuralError(false), Diag(Diag), Style(Style), CurrentLines(&Lines), StructuralError(false), Style(Style),
Tokens(&Tokens), Callback(Callback) {} Tokens(&Tokens), Callback(Callback) {}
bool UnwrappedLineParser::parse() { bool UnwrappedLineParser::parse() {
@ -173,9 +172,6 @@ void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) {
case tok::r_brace: case tok::r_brace:
if (HasOpeningBrace) if (HasOpeningBrace)
return; return;
Diag.Report(FormatTok.Tok.getLocation(),
Diag.getCustomDiagID(clang::DiagnosticsEngine::Error,
"unexpected '}'"));
StructuralError = true; StructuralError = true;
nextToken(); nextToken();
addUnwrappedLine(); addUnwrappedLine();

Просмотреть файл

@ -23,9 +23,6 @@
#include <list> #include <list>
namespace clang { namespace clang {
class DiagnosticsEngine;
namespace format { namespace format {
/// \brief A wrapper around a \c Token storing information about the /// \brief A wrapper around a \c Token storing information about the
@ -129,8 +126,7 @@ public:
class UnwrappedLineParser { class UnwrappedLineParser {
public: public:
UnwrappedLineParser(clang::DiagnosticsEngine &Diag, const FormatStyle &Style, UnwrappedLineParser(const FormatStyle &Style, FormatTokenSource &Tokens,
FormatTokenSource &Tokens,
UnwrappedLineConsumer &Callback); UnwrappedLineConsumer &Callback);
/// Returns true in case of a structural error. /// Returns true in case of a structural error.
@ -203,7 +199,6 @@ private:
// indentation levels. // indentation levels.
bool StructuralError; bool StructuralError;
clang::DiagnosticsEngine &Diag;
const FormatStyle &Style; const FormatStyle &Style;
FormatTokenSource *Tokens; FormatTokenSource *Tokens;
UnwrappedLineConsumer &Callback; UnwrappedLineConsumer &Callback;

Просмотреть файл

@ -1,4 +0,0 @@
// RUN: clang-format 2>&1 >/dev/null %s |FileCheck %s
}
// CHECK: diagnostic.cpp:[[@LINE-1]]:1: error: unexpected '}'

Просмотреть файл

@ -32,8 +32,8 @@ protected:
CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length))); CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length)));
Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources, Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources,
getFormattingLangOpts()); getFormattingLangOpts());
tooling::Replacements Replace = reformat( tooling::Replacements Replace =
Style, Lex, Context.Sources, Ranges, new IgnoringDiagConsumer()); reformat(Style, Lex, Context.Sources, Ranges);
ReplacementCount = Replace.size(); ReplacementCount = Replace.size();
EXPECT_TRUE(applyAllReplacements(Replace, Context.Rewrite)); EXPECT_TRUE(applyAllReplacements(Replace, Context.Rewrite));
DEBUG(llvm::errs() << "\n" << Context.getRewrittenText(ID) << "\n\n"); DEBUG(llvm::errs() << "\n" << Context.getRewrittenText(ID) << "\n\n");