From 512bdf16126c1db4c9f629cf04dc43d3026eb9ae Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 18 Mar 2021 14:14:34 +0000 Subject: [PATCH] Diagnostic: Replace 'info' with 'note' Change-Id: Icde015422882bad9a1427d5480718c822a28fd6a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45242 Commit-Queue: Ben Clayton Reviewed-by: David Neto --- src/diagnostic/diagnostic.h | 13 ++++++++++++- src/diagnostic/formatter.cc | 6 +++--- src/diagnostic/formatter_test.cc | 20 ++++++++++---------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/diagnostic/diagnostic.h b/src/diagnostic/diagnostic.h index a067855a69..79d978ffe5 100644 --- a/src/diagnostic/diagnostic.h +++ b/src/diagnostic/diagnostic.h @@ -25,7 +25,7 @@ namespace tint { namespace diag { /// Severity is an enumerator of diagnostic severities. -enum class Severity { Info, Warning, Error, InternalCompilerError, Fatal }; +enum class Severity { Note, Warning, Error, InternalCompilerError, Fatal }; /// @return true iff `a` is more than, or of equal severity to `b` inline bool operator>=(Severity a, Severity b) { @@ -97,6 +97,17 @@ class List { } } + /// adds the note message with the given Source to the end of this list. + /// @param note_msg the note message + /// @param source the source of the note diagnostic + void add_note(const std::string& note_msg, const Source& source) { + diag::Diagnostic error{}; + error.severity = diag::Severity::Note; + error.source = source; + error.message = note_msg; + add(std::move(error)); + } + /// 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) { diff --git a/src/diagnostic/formatter.cc b/src/diagnostic/formatter.cc index ccf85a9d67..6f5a9ecc1f 100644 --- a/src/diagnostic/formatter.cc +++ b/src/diagnostic/formatter.cc @@ -26,8 +26,8 @@ namespace { const char* to_str(Severity severity) { switch (severity) { - case Severity::Info: - return "info"; + case Severity::Note: + return "note"; case Severity::Warning: return "warning"; case Severity::Error: @@ -172,7 +172,7 @@ void Formatter::format(const Diagnostic& diag, State& state) const { Color severity_color = Color::kDefault; switch (diag.severity) { - case Severity::Info: + case Severity::Note: break; case Severity::Warning: severity_color = Color::kYellow; diff --git a/src/diagnostic/formatter_test.cc b/src/diagnostic/formatter_test.cc index 8bd763dd1a..0863030af4 100644 --- a/src/diagnostic/formatter_test.cc +++ b/src/diagnostic/formatter_test.cc @@ -31,7 +31,7 @@ the snail says ??? class DiagFormatterTest : public testing::Test { public: Source::File file{"file.name", content}; - Diagnostic diag_info{Severity::Info, + Diagnostic diag_note{Severity::Note, Source{Source::Range{Source::Location{1, 14}}, &file}, "purr"}; Diagnostic diag_warn{Severity::Warning, @@ -49,7 +49,7 @@ class DiagFormatterTest : public testing::Test { TEST_F(DiagFormatterTest, Simple) { Formatter fmt{{false, false, false, false}}; - auto got = fmt.format(List{diag_info, diag_warn, diag_err}); + auto got = fmt.format(List{diag_note, diag_warn, diag_err}); auto* expect = R"(1:14: purr 2:14: grrr 3:16 abc123: hiss)"; @@ -58,7 +58,7 @@ TEST_F(DiagFormatterTest, Simple) { TEST_F(DiagFormatterTest, SimpleNewlineAtEnd) { Formatter fmt{{false, false, false, true}}; - auto got = fmt.format(List{diag_info, diag_warn, diag_err}); + auto got = fmt.format(List{diag_note, diag_warn, diag_err}); auto* expect = R"(1:14: purr 2:14: grrr 3:16 abc123: hiss @@ -68,7 +68,7 @@ TEST_F(DiagFormatterTest, SimpleNewlineAtEnd) { TEST_F(DiagFormatterTest, SimpleNoSource) { Formatter fmt{{false, false, false, false}}; - Diagnostic diag{Severity::Info, Source{}, "no source!"}; + Diagnostic diag{Severity::Note, Source{}, "no source!"}; auto got = fmt.format(List{diag}); auto* expect = "no source!"; ASSERT_EQ(expect, got); @@ -76,7 +76,7 @@ TEST_F(DiagFormatterTest, SimpleNoSource) { TEST_F(DiagFormatterTest, WithFile) { Formatter fmt{{true, false, false, false}}; - auto got = fmt.format(List{diag_info, diag_warn, diag_err}); + auto got = fmt.format(List{diag_note, diag_warn, diag_err}); auto* expect = R"(file.name:1:14: purr file.name:2:14: grrr file.name:3:16 abc123: hiss)"; @@ -85,8 +85,8 @@ file.name:3:16 abc123: hiss)"; TEST_F(DiagFormatterTest, WithSeverity) { Formatter fmt{{false, true, false, false}}; - auto got = fmt.format(List{diag_info, diag_warn, diag_err}); - auto* expect = R"(1:14 info: purr + auto got = fmt.format(List{diag_note, diag_warn, diag_err}); + auto* expect = R"(1:14 note: purr 2:14 warning: grrr 3:16 error abc123: hiss)"; ASSERT_EQ(expect, got); @@ -94,7 +94,7 @@ TEST_F(DiagFormatterTest, WithSeverity) { TEST_F(DiagFormatterTest, WithLine) { Formatter fmt{{false, false, true, false}}; - auto got = fmt.format(List{diag_info, diag_warn, diag_err}); + auto got = fmt.format(List{diag_note, diag_warn, diag_err}); auto* expect = R"(1:14: purr the cat says meow ^ @@ -112,8 +112,8 @@ the snake says quack TEST_F(DiagFormatterTest, BasicWithFileSeverityLine) { Formatter fmt{{true, true, true, false}}; - auto got = fmt.format(List{diag_info, diag_warn, diag_err}); - auto* expect = R"(file.name:1:14 info: purr + auto got = fmt.format(List{diag_note, diag_warn, diag_err}); + auto* expect = R"(file.name:1:14 note: purr the cat says meow ^