Add diag::List::add_error() helper

Refactors a common pattern in the tint codebase.

Change-Id: Ia8a70d952fd8c204facd0120f24e43ccc9305622
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38840
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2021-01-26 18:52:11 +00:00
committed by Commit Bot service account
parent a6b9a8eb2f
commit 1461cd96d6
9 changed files with 39 additions and 44 deletions

View File

@@ -98,6 +98,26 @@ class List {
}
}
/// adds the error message without a source to the end of this list.
/// @param err_msg the error message
void add_error(const std::string& err_msg) {
diag::Diagnostic error{};
error.severity = diag::Severity::Error;
error.message = err_msg;
add(std::move(error));
}
/// adds the error message with the given Source to the end of this list.
/// @param err_msg the error message
/// @param source the source of the error diagnostic
void add_error(const std::string& err_msg, const Source& source) {
diag::Diagnostic error{};
error.severity = diag::Severity::Error;
error.source = source;
error.message = err_msg;
add(std::move(error));
}
/// @returns true iff the diagnostic list contains errors diagnostics (or of
/// higher severity).
bool contains_errors() const { return error_count_ > 0; }