mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Refactor IdBase to provide CRTP-based printing (#4626)
This removes a lot of boilerplate `Print` functions in favor of a CRTP-based approach that uses a `Label` field as an automatic prefix. This `Label` is also made available for other purposes, particularly `IdKind` crash messages in this change. In particular, for `RequireIdKind` in node_stack.h from using numeric IdKinds (e.g., 5 and 24) to something that will print `IdKind(<label>)` (this came up recently on #toolchain). While I'm in here, also doing some other tinkering: - Moving operators to be `friend` members, to reduce the extra templating now that the base types are templated. - Adjusts IntId diagnostics from `int [...]` to `int(...)` for consistency with other id printing. - Changes InstBlockId's label from "block" to "inst_block", since we have multiple blocks now. - Fixes StructTypeFieldsId to use "struct_type_fields" instead of "type_block" (from `TypeBlockId`) - Does some more adjustments from camelCase to snake_case for consistency
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Carbon::Check {
|
||||
class IdUnion {
|
||||
public:
|
||||
// The default constructor forms an invalid ID.
|
||||
explicit constexpr IdUnion() : index(IdBase::InvalidIndex) {}
|
||||
explicit constexpr IdUnion() : index(AnyIdBase::InvalidIndex) {}
|
||||
|
||||
template <typename IdT>
|
||||
requires SemIR::IdKind::Contains<IdT>
|
||||
@@ -49,7 +49,7 @@ class IdUnion {
|
||||
}
|
||||
|
||||
private:
|
||||
decltype(IdBase::index) index;
|
||||
decltype(AnyIdBase::index) index;
|
||||
};
|
||||
|
||||
// The stack of parse nodes representing the current state of a Check::Context.
|
||||
@@ -690,8 +690,8 @@ class NodeStack {
|
||||
-> void {
|
||||
CARBON_CHECK(NodeKindToIdKind(parse_kind) == id_kind,
|
||||
"Unexpected Id::Kind mapping for {0}: expected {1}, found {2}",
|
||||
parse_kind, static_cast<int>(id_kind),
|
||||
static_cast<int>(NodeKindToIdKind(parse_kind)));
|
||||
parse_kind, SemIR::IdKind(id_kind),
|
||||
SemIR::IdKind(NodeKindToIdKind(parse_kind)));
|
||||
}
|
||||
|
||||
// Require an entry to have the given Parse::NodeKind.
|
||||
|
||||
Reference in New Issue
Block a user