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:
Jon Ross-Perkins
2024-12-05 01:29:53 +00:00
committed by GitHub
parent a45cb86bf7
commit bc24a6c5d8
24 changed files with 503 additions and 507 deletions
+1 -1
View File
@@ -139,7 +139,7 @@ auto TreeAndSubtrees::PrintNode(llvm::raw_ostream& output, NodeId n, int depth,
// If children are being added, include node_index in order to disambiguate
// nodes.
if (preorder) {
output << "node_index: " << n << ", ";
output << "node_index: " << n.index << ", ";
}
output << "kind: '" << tree_->node_kind(n) << "', text: '"
<< tokens_->GetTokenText(tree_->node_token(n)) << "'";