mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-30 18:33:46 +00:00
Have tint executable use the diagnostic printer
Will now print with better formatting and colors on terminals that support it. Bug: tint:282 Change-Id: Ibff341cb1dc2dcbda6fa0d72e24fdcb172990138 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31570 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
ecea5c8aec
commit
d59a5da9e5
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include "tint/tint.h"
|
#include "tint/tint.h"
|
||||||
|
|
||||||
|
#include "src/diagnostic/printer.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum class Format {
|
enum class Format {
|
||||||
@ -478,7 +480,8 @@ int main(int argc, const char** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!reader->Parse()) {
|
if (!reader->Parse()) {
|
||||||
std::cerr << "Parse: " << reader->error() << std::endl;
|
auto printer = tint::diag::Printer::create(stderr, true);
|
||||||
|
tint::diag::Formatter().format(reader->diagnostics(), printer.get());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,13 @@ namespace diag {
|
|||||||
|
|
||||||
List::List() = default;
|
List::List() = default;
|
||||||
List::List(std::initializer_list<Diagnostic> list) : entries_(list) {}
|
List::List(std::initializer_list<Diagnostic> list) : entries_(list) {}
|
||||||
|
List::List(const List&) = default;
|
||||||
|
List::List(List&&) = default;
|
||||||
|
|
||||||
List::~List() = default;
|
List::~List() = default;
|
||||||
|
|
||||||
|
List& List::operator=(const List&) = default;
|
||||||
|
List& List::operator=(List&&) = default;
|
||||||
|
|
||||||
} // namespace diag
|
} // namespace diag
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
@ -54,12 +54,30 @@ class List {
|
|||||||
/// Constructs the list with no elements.
|
/// Constructs the list with no elements.
|
||||||
List();
|
List();
|
||||||
|
|
||||||
/// Constructs the list with a copy of the diagnostics in |list|.
|
/// Copy constructor. Copies the diagnostics from |list| into this list.
|
||||||
/// @param list the list of diagnostics to copy into this list.
|
/// @param list the list of diagnostics to copy into this list.
|
||||||
List(std::initializer_list<Diagnostic> list);
|
List(std::initializer_list<Diagnostic> list);
|
||||||
|
|
||||||
|
/// Copy constructor. Copies the diagnostics from |list| into this list.
|
||||||
|
/// @param list the list of diagnostics to copy into this list.
|
||||||
|
List(const List& list);
|
||||||
|
|
||||||
|
/// Move constructor. Moves the diagnostics from |list| into this list.
|
||||||
|
/// @param list the list of diagnostics to move into this list.
|
||||||
|
List(List&& list);
|
||||||
~List();
|
~List();
|
||||||
|
|
||||||
|
/// Assignment operator. Copies the diagnostics from |list| into this list.
|
||||||
|
/// @param list the list to copy into this list.
|
||||||
|
/// @return this list.
|
||||||
|
List& operator=(const List& list);
|
||||||
|
|
||||||
|
/// Assignment move operator. Moves the diagnostics from |list| into this
|
||||||
|
/// list.
|
||||||
|
/// @param list the list to move into this list.
|
||||||
|
/// @return this list.
|
||||||
|
List& operator=(List&& list);
|
||||||
|
|
||||||
/// adds a diagnostic to the end of this list.
|
/// adds a diagnostic to the end of this list.
|
||||||
/// @param diag the diagnostic to append to this list.
|
/// @param diag the diagnostic to append to this list.
|
||||||
void add(Diagnostic&& diag) {
|
void add(Diagnostic&& diag) {
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/context.h"
|
#include "src/context.h"
|
||||||
|
#include "src/diagnostic/diagnostic.h"
|
||||||
|
#include "src/diagnostic/formatter.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace reader {
|
namespace reader {
|
||||||
@ -32,10 +34,17 @@ class Reader {
|
|||||||
/// @returns true if the parse was successful
|
/// @returns true if the parse was successful
|
||||||
virtual bool Parse() = 0;
|
virtual bool Parse() = 0;
|
||||||
|
|
||||||
/// @returns true if an error was encountered
|
/// @returns true if an error was encountered.
|
||||||
bool has_error() const { return error_.size() > 0; }
|
bool has_error() const { return diags_.contains_errors(); }
|
||||||
|
|
||||||
/// @returns the parser error string
|
/// @returns the parser error string
|
||||||
const std::string& error() const { return error_; }
|
std::string error() const {
|
||||||
|
diag::Formatter formatter{{false, false, false}};
|
||||||
|
return formatter.format(diags_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @returns the full list of diagnostic messages.
|
||||||
|
const diag::List& diagnostics() const { return diags_; }
|
||||||
|
|
||||||
/// @returns the module. The module in the parser will be reset after this.
|
/// @returns the module. The module in the parser will be reset after this.
|
||||||
virtual ast::Module module() = 0;
|
virtual ast::Module module() = 0;
|
||||||
@ -45,15 +54,15 @@ class Reader {
|
|||||||
/// @param ctx the context object, must be non-null
|
/// @param ctx the context object, must be non-null
|
||||||
explicit Reader(Context* ctx);
|
explicit Reader(Context* ctx);
|
||||||
|
|
||||||
/// Sets the error string
|
/// Sets the diagnostic messages
|
||||||
/// @param msg the error message
|
/// @param diags the list of diagnostic messages
|
||||||
void set_error(const std::string& msg) { error_ = msg; }
|
void set_diagnostics(const diag::List& diags) { diags_ = diags; }
|
||||||
|
|
||||||
/// The Tint context object
|
/// The Tint context object
|
||||||
Context& ctx_;
|
Context& ctx_;
|
||||||
|
|
||||||
/// An error message, if an error was encountered
|
/// All diagnostic messages from the reader.
|
||||||
std::string error_;
|
diag::List diags_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace reader
|
} // namespace reader
|
||||||
|
@ -27,7 +27,14 @@ Parser::~Parser() = default;
|
|||||||
|
|
||||||
bool Parser::Parse() {
|
bool Parser::Parse() {
|
||||||
const auto result = impl_->Parse();
|
const auto result = impl_->Parse();
|
||||||
set_error(impl_->error());
|
auto err_msg = impl_->error();
|
||||||
|
if (!err_msg.empty()) {
|
||||||
|
// TODO(bclayton): Migrate spirv::ParserImpl to using diagnostics.
|
||||||
|
diag::Diagnostic error{};
|
||||||
|
error.severity = diag::Severity::Error;
|
||||||
|
error.message = err_msg;
|
||||||
|
set_diagnostics({error});
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +28,7 @@ Parser::~Parser() = default;
|
|||||||
bool Parser::Parse() {
|
bool Parser::Parse() {
|
||||||
bool ret = impl_->Parse();
|
bool ret = impl_->Parse();
|
||||||
|
|
||||||
if (impl_->has_error())
|
set_diagnostics(std::move(impl_->diagnostics()));
|
||||||
set_error(impl_->error());
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,9 @@ class ParserImpl {
|
|||||||
/// @returns the diagnostic messages
|
/// @returns the diagnostic messages
|
||||||
const diag::List& diagnostics() const { return diags_; }
|
const diag::List& diagnostics() const { return diags_; }
|
||||||
|
|
||||||
|
/// @returns the diagnostic messages
|
||||||
|
diag::List& diagnostics() { return diags_; }
|
||||||
|
|
||||||
/// @returns the module. The module in the parser will be reset after this.
|
/// @returns the module. The module in the parser will be reset after this.
|
||||||
ast::Module module() { return std::move(module_); }
|
ast::Module module() { return std::move(module_); }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user