Skip to content

Commit 26311f5

Browse files
committed
refactor: rename diag_collector::error -> diag
1 parent eb5db3c commit 26311f5

File tree

7 files changed

+87
-92
lines changed

7 files changed

+87
-92
lines changed

test/diag-collector.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ void diag_collector::report_impl(diag_type type, void *diag) {
1919
}
2020

2121
#define QLJS_DIAG_TYPE(name, code, severity, struct_body, format_call) \
22-
diag_collector::error::error(const name &data) \
22+
diag_collector::diag::diag(const name &data) \
2323
: type_(diag_type::name), variant_##name##_(std::move(data)) {}
2424
QLJS_X_DIAG_TYPES
2525
#undef QLJS_DIAG_TYPE
2626

27-
diag_type diag_collector::error::type() const noexcept { return this->type_; }
27+
diag_type diag_collector::diag::type() const noexcept { return this->type_; }
2828

29-
const char *diag_collector::error::error_code() const noexcept {
29+
const char *diag_collector::diag::error_code() const noexcept {
3030
switch (this->type_) {
3131
#define QLJS_DIAG_TYPE(name, code, severity, struct_body, format_call) \
3232
case diag_type::name: \
@@ -37,25 +37,25 @@ const char *diag_collector::error::error_code() const noexcept {
3737
QLJS_UNREACHABLE();
3838
}
3939

40-
const void *diag_collector::error::data() const noexcept {
40+
const void *diag_collector::diag::data() const noexcept {
4141
return &this->variant_diag_unexpected_token_; // Arbitrary member.
4242
}
4343

44-
#define QLJS_DIAG_TYPE(name, code, severity, struct_body, format_call) \
45-
template <> \
46-
bool holds_alternative<name>(const diag_collector::error &e) noexcept { \
47-
return e.type_ == diag_type::name; \
48-
} \
49-
\
50-
template <> \
51-
const name &get<name>(const diag_collector::error &e) noexcept { \
52-
QLJS_ASSERT(holds_alternative<name>(e)); \
53-
return e.variant_##name##_; \
44+
#define QLJS_DIAG_TYPE(name, code, severity, struct_body, format_call) \
45+
template <> \
46+
bool holds_alternative<name>(const diag_collector::diag &e) noexcept { \
47+
return e.type_ == diag_type::name; \
48+
} \
49+
\
50+
template <> \
51+
const name &get<name>(const diag_collector::diag &e) noexcept { \
52+
QLJS_ASSERT(holds_alternative<name>(e)); \
53+
return e.variant_##name##_; \
5454
}
5555
QLJS_X_DIAG_TYPES
5656
#undef QLJS_DIAG_TYPE
5757

58-
void PrintTo(const diag_collector::error &e, std::ostream *out) {
58+
void PrintTo(const diag_collector::diag &e, std::ostream *out) {
5959
*out << e.type_;
6060
}
6161

test/error-matcher.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ error_matcher::error_matcher(padded_string_view input, diag_type type,
193193
: state_{type, input, {field_0, field_1, field_2}} {}
194194

195195
class error_matcher::impl
196-
: public testing::MatcherInterface<const diag_collector::error &> {
196+
: public testing::MatcherInterface<const diag_collector::diag &> {
197197
public:
198198
explicit impl(state s) : state_(std::move(s)) {}
199199

@@ -211,7 +211,7 @@ class error_matcher::impl
211211
// TODO(strager)
212212
}
213213

214-
bool MatchAndExplain(const diag_collector::error &error,
214+
bool MatchAndExplain(const diag_collector::diag &error,
215215
testing::MatchResultListener *listener) const override {
216216
bool type_matches = error.type() == this->state_.type;
217217
if (!type_matches) {
@@ -251,9 +251,8 @@ class error_matcher::impl
251251
};
252252

253253
/*implicit*/ error_matcher::operator testing::Matcher<
254-
const diag_collector::error &>() const {
255-
return testing::Matcher<const diag_collector::error &>(
256-
new impl(this->state_));
254+
const diag_collector::diag &>() const {
255+
return testing::Matcher<const diag_collector::diag &>(new impl(this->state_));
257256
}
258257
}
259258

test/quick-lint-js/diag-collector.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ namespace quick_lint_js {
1717
struct diag_collector : public diag_reporter {
1818
void report_impl(diag_type type, void *diag) override;
1919

20-
// Like std::variant<(error types)>, but with much faster compilation.
21-
class error {
20+
// Like std::variant<(diag types)>, but with much faster compilation.
21+
class diag {
2222
public:
2323
#define QLJS_DIAG_TYPE(name, code, severity, struct_body, format_call) \
24-
explicit error(const name &);
24+
explicit diag(const name &);
2525
QLJS_X_DIAG_TYPES
2626
#undef QLJS_DIAG_TYPE
2727

2828
diag_type type() const noexcept;
2929
const char *error_code() const noexcept;
3030
const void *data() const noexcept;
3131

32-
template <class Error>
33-
friend const Error &get(const error &) noexcept;
32+
template <class Diag>
33+
friend const Diag &get(const diag &) noexcept;
3434

35-
template <class Error>
36-
friend bool holds_alternative(const error &) noexcept;
35+
template <class Diag>
36+
friend bool holds_alternative(const diag &) noexcept;
3737

38-
friend void PrintTo(const error &, std::ostream *);
38+
friend void PrintTo(const diag &, std::ostream *);
3939

4040
private:
4141
diag_type type_;
@@ -47,16 +47,16 @@ struct diag_collector : public diag_reporter {
4747
};
4848
};
4949

50-
std::vector<error> errors;
50+
std::vector<diag> errors;
5151
};
5252

53-
template <class Error>
54-
const Error &get(const diag_collector::error &) noexcept;
53+
template <class Diag>
54+
const Diag &get(const diag_collector::diag &) noexcept;
5555

56-
template <class Error>
57-
bool holds_alternative(const diag_collector::error &) noexcept;
56+
template <class Diag>
57+
bool holds_alternative(const diag_collector::diag &) noexcept;
5858

59-
void PrintTo(const diag_collector::error &, std::ostream *);
59+
void PrintTo(const diag_collector::diag &, std::ostream *);
6060

6161
#define QLJS_DIAG_TYPE(name, code, severity, struct_body, format_call) \
6262
void PrintTo(const name &, std::ostream *);

test/quick-lint-js/error-matcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class error_matcher {
208208
error_matcher &operator=(const error_matcher &) = default;
209209
error_matcher &operator=(error_matcher &&) = default;
210210

211-
/*implicit*/ operator testing::Matcher<const diag_collector::error &>() const;
211+
/*implicit*/ operator testing::Matcher<const diag_collector::diag &>() const;
212212

213213
private:
214214
class impl;

test/quick-lint-js/parse-support.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class test_parser {
6262
return ast;
6363
}
6464

65-
const std::vector<diag_collector::error>& errors() const noexcept {
65+
const std::vector<diag_collector::diag>& errors() const noexcept {
6666
return this->errors_.errors;
6767
}
6868

0 commit comments

Comments
 (0)