Skip to content

Commit 5d58bea

Browse files
committed
refactor: fix vestigial references to 'error' -> 'diag'
1 parent 2f4ec0a commit 5d58bea

15 files changed

+68
-66
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ quick_lint_js_add_library(
251251
quick-lint-js-lib-debug
252252
char8-debug.cpp
253253
cli-location-debug.cpp
254+
diag-debug.cpp
254255
emacs-location-debug.cpp
255-
error-debug.cpp
256256
language-debug.cpp
257257
lex-debug.cpp
258258
lsp-location-debug.cpp

src/c-api-diag-reporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void c_api_diag_reporter<Diagnostic, Locator>::report_impl(diag_type type,
4242

4343
template <class Diagnostic, class Locator>
4444
const Diagnostic *c_api_diag_reporter<Diagnostic, Locator>::get_diagnostics() {
45-
// Null-terminate the returned errors.
45+
// Null-terminate the returned diagnostics.
4646
this->diagnostics_.emplace_back();
4747

4848
return this->diagnostics_.data();

src/diag-code-list.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ parsed_diag_code_list parse_diag_code_list(
3838
return '0' <= c && c <= '9';
3939
};
4040

41-
parsed_diag_code_list errors;
41+
parsed_diag_code_list diag_codes;
4242
std::size_t i = 0;
4343
bool need_comma = false;
4444

@@ -54,15 +54,16 @@ parsed_diag_code_list parse_diag_code_list(
5454
};
5555

5656
if (raw_diag_code_list[i] == 'E') {
57-
(is_include ? errors.included_codes : errors.excluded_codes)
57+
(is_include ? diag_codes.included_codes : diag_codes.excluded_codes)
5858
.emplace_back(parse_word(is_continue_code_character));
5959
return true;
6060
} else if (is_initial_category_character(raw_diag_code_list[i])) {
61-
(is_include ? errors.included_categories : errors.excluded_categories)
61+
(is_include ? diag_codes.included_categories
62+
: diag_codes.excluded_categories)
6263
.emplace_back(parse_word(is_continue_category_character));
6364
return true;
6465
} else {
65-
errors.unexpected.emplace_back(&raw_diag_code_list[i], 1);
66+
diag_codes.unexpected.emplace_back(&raw_diag_code_list[i], 1);
6667
return false;
6768
}
6869
};
@@ -73,7 +74,7 @@ parsed_diag_code_list parse_diag_code_list(
7374
break;
7475
}
7576
if (need_comma && raw_diag_code_list[i] != ',') {
76-
errors.unexpected.emplace_back(&raw_diag_code_list[i], 1);
77+
diag_codes.unexpected.emplace_back(&raw_diag_code_list[i], 1);
7778
break;
7879
}
7980
i = i + std::strspn(&raw_diag_code_list[i], " \t,");
@@ -91,18 +92,18 @@ parsed_diag_code_list parse_diag_code_list(
9192
if (!try_parse_category_or_code(/*is_include=*/true)) {
9293
break;
9394
}
94-
errors.override_defaults = true;
95+
diag_codes.override_defaults = true;
9596
}
9697
}
9798

98-
return errors;
99+
return diag_codes;
99100
}
100101

101102
void compiled_diag_code_list::add(const parsed_diag_code_list& diag_code_list) {
102103
auto add_code = [this](std::string_view code, auto& code_set) -> void {
103-
std::optional<diag_type> code_error_type = diag_type_from_code_slow(code);
104-
if (code_error_type.has_value()) {
105-
code_set[static_cast<std::size_t>(*code_error_type)] = true;
104+
std::optional<diag_type> code_diag_type = diag_type_from_code_slow(code);
105+
if (code_diag_type.has_value()) {
106+
code_set[static_cast<std::size_t>(*code_diag_type)] = true;
106107
} else {
107108
this->unknown_codes_.emplace_back(code);
108109
}
@@ -164,12 +165,12 @@ bool compiled_diag_code_list::is_present(diag_type type) const noexcept {
164165
bool is_default = true; // For now, all codes are enabled by default.
165166
bool present = true;
166167
for (const codes& c : this->parsed_diag_code_lists_) {
167-
std::size_t error_type_index = static_cast<std::size_t>(type);
168-
if (c.override_defaults || c.excluded_codes[error_type_index] ||
168+
std::size_t diag_type_index = static_cast<std::size_t>(type);
169+
if (c.override_defaults || c.excluded_codes[diag_type_index] ||
169170
(is_default && contains(c.excluded_categories, "all"))) {
170171
present = false;
171172
}
172-
if (c.included_codes[error_type_index] ||
173+
if (c.included_codes[diag_type_index] ||
173174
(is_default && contains(c.included_categories, "all"))) {
174175
present = true;
175176
}
File renamed without changes.

src/lex.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ void token::report_errors_for_escape_sequences_in_template(
132132
diag_reporter* reporter) const {
133133
QLJS_ASSERT(this->type == token_type::complete_template ||
134134
this->type == token_type::incomplete_template);
135-
if (this->template_escape_sequence_errors) {
136-
this->template_escape_sequence_errors->move_into(reporter);
135+
if (this->template_escape_sequence_diagnostics) {
136+
this->template_escape_sequence_diagnostics->move_into(reporter);
137137
}
138138
}
139139

@@ -575,8 +575,8 @@ bool lexer::try_parse_current_token() {
575575
this->input_ += 1;
576576
parsed_template_body body = this->parse_template_body(
577577
this->input_, this->last_token_.begin, this->diag_reporter_);
578-
this->last_token_.template_escape_sequence_errors =
579-
body.escape_sequence_errors;
578+
this->last_token_.template_escape_sequence_diagnostics =
579+
body.escape_sequence_diagnostics;
580580
this->last_token_.type = body.type;
581581
this->input_ = body.end;
582582
this->last_token_.end = this->input_;
@@ -679,7 +679,7 @@ bool lexer::test_for_regexp(const char8* regexp_begin) {
679679
this->last_token_.begin = this->input_;
680680
this->reparse_as_regexp();
681681

682-
bool parsed_ok = !this->transaction_has_lex_errors(transaction);
682+
bool parsed_ok = !this->transaction_has_lex_diagnostics(transaction);
683683
this->roll_back_transaction(std::move(transaction));
684684
return parsed_ok;
685685
}
@@ -868,16 +868,16 @@ void lexer::skip_in_template(const char8* template_begin) {
868868
parsed_template_body body = this->parse_template_body(
869869
this->input_, template_begin, this->diag_reporter_);
870870
this->last_token_.type = body.type;
871-
this->last_token_.template_escape_sequence_errors =
872-
body.escape_sequence_errors;
871+
this->last_token_.template_escape_sequence_diagnostics =
872+
body.escape_sequence_diagnostics;
873873
this->input_ = body.end;
874874
this->last_token_.end = body.end;
875875
}
876876

877877
lexer::parsed_template_body lexer::parse_template_body(
878878
const char8* input, const char8* template_begin,
879879
diag_reporter* diag_reporter) {
880-
buffering_diag_reporter* escape_sequence_errors = nullptr;
880+
buffering_diag_reporter* escape_sequence_diagnostics = nullptr;
881881
const char8* c = input;
882882
for (;;) {
883883
switch (*c) {
@@ -886,7 +886,7 @@ lexer::parsed_template_body lexer::parse_template_body(
886886
diag_reporter->report(
887887
diag_unclosed_template{source_code_span(template_begin, c)});
888888
return parsed_template_body{token_type::complete_template, c,
889-
escape_sequence_errors};
889+
escape_sequence_diagnostics};
890890
} else {
891891
++c;
892892
break;
@@ -895,7 +895,7 @@ lexer::parsed_template_body lexer::parse_template_body(
895895
case '`':
896896
++c;
897897
return parsed_template_body{token_type::complete_template, c,
898-
escape_sequence_errors};
898+
escape_sequence_diagnostics};
899899

900900
case '\\': {
901901
const char8* escape_sequence_start = c;
@@ -906,19 +906,19 @@ lexer::parsed_template_body lexer::parse_template_body(
906906
diag_reporter->report(
907907
diag_unclosed_template{source_code_span(template_begin, c)});
908908
return parsed_template_body{token_type::complete_template, c,
909-
escape_sequence_errors};
909+
escape_sequence_diagnostics};
910910
} else {
911911
++c;
912912
break;
913913
}
914914
case 'u': {
915-
if (!escape_sequence_errors) {
916-
escape_sequence_errors =
915+
if (!escape_sequence_diagnostics) {
916+
escape_sequence_diagnostics =
917917
this->allocator_.new_object<buffering_diag_reporter>(
918918
&this->allocator_);
919919
}
920920
c = this->parse_unicode_escape(escape_sequence_start,
921-
escape_sequence_errors)
921+
escape_sequence_diagnostics)
922922
.end;
923923
break;
924924
}
@@ -933,7 +933,7 @@ lexer::parsed_template_body lexer::parse_template_body(
933933
if (c[1] == '{') {
934934
c += 2;
935935
return parsed_template_body{token_type::incomplete_template, c,
936-
escape_sequence_errors};
936+
escape_sequence_diagnostics};
937937
}
938938
++c;
939939
break;
@@ -1110,9 +1110,9 @@ lexer_transaction lexer::begin_transaction() {
11101110
}
11111111

11121112
void lexer::commit_transaction(lexer_transaction&& transaction) {
1113-
buffering_diag_reporter* buffered_errors =
1113+
buffering_diag_reporter* buffered_diagnostics =
11141114
static_cast<buffering_diag_reporter*>(this->diag_reporter_);
1115-
buffered_errors->move_into(transaction.old_diag_reporter);
1115+
buffered_diagnostics->move_into(transaction.old_diag_reporter);
11161116

11171117
this->diag_reporter_ = transaction.old_diag_reporter;
11181118
}
@@ -1124,11 +1124,11 @@ void lexer::roll_back_transaction(lexer_transaction&& transaction) {
11241124
this->diag_reporter_ = transaction.old_diag_reporter;
11251125
}
11261126

1127-
bool lexer::transaction_has_lex_errors(const lexer_transaction&) const
1127+
bool lexer::transaction_has_lex_diagnostics(const lexer_transaction&) const
11281128
noexcept {
1129-
buffering_diag_reporter* buffered_errors =
1129+
buffering_diag_reporter* buffered_diagnostics =
11301130
static_cast<buffering_diag_reporter*>(this->diag_reporter_);
1131-
return !buffered_errors->empty();
1131+
return !buffered_diagnostics->empty();
11321132
}
11331133

11341134
void lexer::insert_semicolon() {

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class any_diag_reporter {
121121
}
122122

123123
bool get_error() noexcept {
124-
return visit([](auto &r) { return r.found_matching_error(); }, this->tape_);
124+
return visit([](auto &r) { return r.found_matching_diag(); }, this->tape_);
125125
}
126126

127127
void finish() {

src/parse.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void parser::check_jsx_attribute(const identifier& attribute_name) {
178178

179179
if (!name_has_upper && is_event_attribute) {
180180
bump_vector<char8, monotonic_allocator> fixed_name(
181-
"check_jsx_attribute fixed_name", &this->error_memory_);
181+
"check_jsx_attribute fixed_name", &this->diagnostic_memory_);
182182
fixed_name += name;
183183
fixed_name[2] = toupper(fixed_name[2]);
184184
this->diag_reporter_->report(diag_jsx_event_attribute_should_be_camel_case{
@@ -266,7 +266,8 @@ expression* parser::maybe_wrap_erroneous_arrow_function(
266266
if (is_async_arrow_using_with_await_operator) {
267267
// await (x) => {} // Invalid.
268268
// await () => expr // Invalid.
269-
// We treated 'await' as 'async' elsewhere. Don't report any error here.
269+
// We treated 'await' as 'async' elsewhere. Don't report any diagnostic
270+
// here.
270271
return arrow_function;
271272
} else {
272273
// f() => {} // Invalid.
@@ -515,9 +516,9 @@ parser_transaction parser::begin_transaction() {
515516
}
516517

517518
void parser::commit_transaction(parser_transaction&& transaction) {
518-
auto* buffered_errors =
519+
auto* buffered_diagnostics =
519520
static_cast<buffering_diag_reporter*>(this->diag_reporter_);
520-
buffered_errors->move_into(transaction.old_diag_reporter);
521+
buffered_diagnostics->move_into(transaction.old_diag_reporter);
521522
this->diag_reporter_ = transaction.old_diag_reporter;
522523

523524
this->lexer_.commit_transaction(std::move(transaction.lex_transaction));

src/quick-lint-js/diag-reporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class diag_reporter {
2121

2222
#define QLJS_DIAG_TYPE(name, code, severity, struct_body, format) \
2323
void report(name diag) { \
24-
this->report_impl(error_type_from_type<name>, &diag); \
24+
this->report_impl(diag_type_from_type<name>, &diag); \
2525
}
2626
QLJS_X_DIAG_TYPES
2727
#undef QLJS_DIAG_TYPE

src/quick-lint-js/diagnostic-types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ QLJS_X_DIAG_TYPES
16441644
#undef QLJS_DIAG_TYPE
16451645

16461646
template <class Error>
1647-
inline constexpr diag_type error_type_from_type =
1647+
inline constexpr diag_type diag_type_from_type =
16481648
diag_type_from_type_detail<Error>::type;
16491649

16501650
inline constexpr int diag_type_count = 0

src/quick-lint-js/lex.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class lexer {
6565
// template literal (instead of a '}' token, an 'engineer' token, and the
6666
// beginning of another template literal).
6767
//
68-
// The given template_begin is used for error reporting.
68+
// The given template_begin is used for diagnostic reporting.
6969
//
7070
// Precondition: this->peek().type == token_type::right_curly
7171
void skip_in_template(const char8* template_begin);
@@ -118,8 +118,8 @@ class lexer {
118118
// You can call begin_transaction again before calling commit_transaction
119119
// or roll_back_transaction. Doing so begins a nested transaction.
120120
//
121-
// Inside a transaction, errors are not reported until commit_transaction is
122-
// called for the outer-most nested transaction.
121+
// Inside a transaction, diagnostics are not reported until commit_transaction
122+
// is called for the outer-most nested transaction.
123123
lexer_transaction begin_transaction();
124124

125125
// After calling commit_transaction, it's almost as if you never called
@@ -138,13 +138,13 @@ class lexer {
138138
// roll_back_transaction effectively undoes calls to skip, insert_semicolon,
139139
// etc.
140140
//
141-
// Calling roll_back_transaction will not report lexer errors which might have
142-
// been reported if it weren't for begin_transaction.
141+
// Calling roll_back_transaction will not report lexer diagnostics which might
142+
// have been reported if it weren't for begin_transaction.
143143
void roll_back_transaction(lexer_transaction&&);
144144

145-
// transaction_has_lex_errors can only be called while the given transaction
146-
// is the most recent active transaction.
147-
bool transaction_has_lex_errors(const lexer_transaction&) const noexcept;
145+
// transaction_has_lex_diagnostics can only be called while the given
146+
// transaction is the most recent active transaction.
147+
bool transaction_has_lex_diagnostics(const lexer_transaction&) const noexcept;
148148

149149
void insert_semicolon();
150150

@@ -172,7 +172,7 @@ class lexer {
172172
token_type type;
173173
const char8* end;
174174
// Might be null.
175-
buffering_diag_reporter* escape_sequence_errors;
175+
buffering_diag_reporter* escape_sequence_diagnostics;
176176
};
177177

178178
// The result of parsing an identifier.

0 commit comments

Comments
 (0)