Use the new diagnostics for wgsl the parser
Keep the `ParserImpl::error()` format identical to the old error style for now. Use the explicit `ParserImpl::diagnostics()` method for the error message tests, updating the tests to match the new, improved output. Bug: tint:282 Change-Id: Ia7e1237170f0f5203a8cfa256322df29e90e2791 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31481 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
0a06243a70
commit
3d54f13613
|
@ -132,27 +132,15 @@ ParserImpl::~ParserImpl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserImpl::set_error(const Token& t, const std::string& err) {
|
void ParserImpl::set_error(const Token& t, const std::string& err) {
|
||||||
auto prefix = std::to_string(t.source().range.begin.line) + ":" +
|
diag::Diagnostic diagnostic;
|
||||||
std::to_string(t.source().range.begin.column) + ": ";
|
diagnostic.severity = diag::Severity::Error;
|
||||||
|
diagnostic.message = err;
|
||||||
if (t.IsReservedKeyword()) {
|
diagnostic.source = t.source();
|
||||||
error_ = prefix + "reserved token (" + t.to_str() + ") found";
|
diags_.add(std::move(diagnostic));
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (t.IsError()) {
|
|
||||||
error_ = prefix + t.to_str();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err.size() != 0) {
|
|
||||||
error_ = prefix + err;
|
|
||||||
} else {
|
|
||||||
error_ = prefix + "invalid token (" + t.to_name() + ") encountered";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserImpl::set_error(const Token& t) {
|
void ParserImpl::set_error(const Token& t) {
|
||||||
set_error(t, "");
|
set_error(t, "invalid token (" + t.to_name() + ") encountered");
|
||||||
}
|
}
|
||||||
|
|
||||||
Token ParserImpl::next() {
|
Token ParserImpl::next() {
|
||||||
|
|
|
@ -45,6 +45,8 @@
|
||||||
#include "src/ast/variable.h"
|
#include "src/ast/variable.h"
|
||||||
#include "src/ast/variable_decoration.h"
|
#include "src/ast/variable_decoration.h"
|
||||||
#include "src/context.h"
|
#include "src/context.h"
|
||||||
|
#include "src/diagnostic/diagnostic.h"
|
||||||
|
#include "src/diagnostic/formatter.h"
|
||||||
#include "src/reader/wgsl/token.h"
|
#include "src/reader/wgsl/token.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
@ -99,9 +101,15 @@ class ParserImpl {
|
||||||
bool Parse();
|
bool Parse();
|
||||||
|
|
||||||
/// @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 {
|
||||||
|
return diag::Formatter::create(false, false, false)->format(diags_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @returns the 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.
|
||||||
ast::Module module() { return std::move(module_); }
|
ast::Module module() { return std::move(module_); }
|
||||||
|
@ -418,7 +426,7 @@ class ParserImpl {
|
||||||
uint32_t depth);
|
uint32_t depth);
|
||||||
|
|
||||||
Context& ctx_;
|
Context& ctx_;
|
||||||
std::string error_;
|
diag::List diags_;
|
||||||
std::unique_ptr<Lexer> lexer_;
|
std::unique_ptr<Lexer> lexer_;
|
||||||
std::deque<Token> token_queue_;
|
std::deque<Token> token_queue_;
|
||||||
std::unordered_map<std::string, ast::type::Type*> registered_constructs_;
|
std::unordered_map<std::string, ast::type::Type*> registered_constructs_;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue