mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +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:
committed by
Commit Bot service account
parent
ecea5c8aec
commit
d59a5da9e5
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "src/ast/module.h"
|
||||
#include "src/context.h"
|
||||
#include "src/diagnostic/diagnostic.h"
|
||||
#include "src/diagnostic/formatter.h"
|
||||
|
||||
namespace tint {
|
||||
namespace reader {
|
||||
@@ -32,10 +34,17 @@ class Reader {
|
||||
/// @returns true if the parse was successful
|
||||
virtual bool Parse() = 0;
|
||||
|
||||
/// @returns true if an error was encountered
|
||||
bool has_error() const { return error_.size() > 0; }
|
||||
/// @returns true if an error was encountered.
|
||||
bool has_error() const { return diags_.contains_errors(); }
|
||||
|
||||
/// @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.
|
||||
virtual ast::Module module() = 0;
|
||||
@@ -45,15 +54,15 @@ class Reader {
|
||||
/// @param ctx the context object, must be non-null
|
||||
explicit Reader(Context* ctx);
|
||||
|
||||
/// Sets the error string
|
||||
/// @param msg the error message
|
||||
void set_error(const std::string& msg) { error_ = msg; }
|
||||
/// Sets the diagnostic messages
|
||||
/// @param diags the list of diagnostic messages
|
||||
void set_diagnostics(const diag::List& diags) { diags_ = diags; }
|
||||
|
||||
/// The Tint context object
|
||||
Context& ctx_;
|
||||
|
||||
/// An error message, if an error was encountered
|
||||
std::string error_;
|
||||
/// All diagnostic messages from the reader.
|
||||
diag::List diags_;
|
||||
};
|
||||
|
||||
} // namespace reader
|
||||
|
||||
@@ -27,7 +27,14 @@ Parser::~Parser() = default;
|
||||
|
||||
bool Parser::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;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ Parser::~Parser() = default;
|
||||
bool Parser::Parse() {
|
||||
bool ret = impl_->Parse();
|
||||
|
||||
if (impl_->has_error())
|
||||
set_error(impl_->error());
|
||||
set_diagnostics(std::move(impl_->diagnostics()));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -111,6 +111,9 @@ class ParserImpl {
|
||||
/// @returns the diagnostic messages
|
||||
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.
|
||||
ast::Module module() { return std::move(module_); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user