mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Change NodeIdOneOf and similar to use "requires" and explicit UnsafeMake (#5084)
This doesn't change functionality, but I was seeing better diagnostics in VS Code. This also changes the NodeId constructors for related types (also NodeCategory and NodeIdForKind) to use UnsafeMake for construction. That originated from avoiding ambiguity coming from `requires`, but the constructor mode is also one we should typically avoid (e.g., preferring `Parse::Tree::As`).
This commit is contained in:
@@ -140,8 +140,8 @@ class NodeStack {
|
||||
auto PopForSoloNodeId() -> Parse::NodeIdForKind<RequiredParseKind> {
|
||||
Entry back = PopEntry<SemIR::InstId>();
|
||||
RequireIdKind(RequiredParseKind, Id::Kind::None);
|
||||
RequireParseKind<RequiredParseKind>(back.node_id);
|
||||
return Parse::NodeIdForKind<RequiredParseKind>(back.node_id);
|
||||
return parse_tree_->As<Parse::NodeIdForKind<RequiredParseKind>>(
|
||||
back.node_id);
|
||||
}
|
||||
|
||||
// Pops the top of the stack if it is the given kind, and returns the
|
||||
@@ -192,7 +192,7 @@ class NodeStack {
|
||||
template <const Parse::NodeKind& RequiredParseKind>
|
||||
auto PopWithNodeId() -> auto {
|
||||
auto id = Peek<RequiredParseKind>();
|
||||
Parse::NodeIdForKind<RequiredParseKind> node_id(
|
||||
auto node_id = parse_tree_->As<Parse::NodeIdForKind<RequiredParseKind>>(
|
||||
stack_.pop_back_val().node_id);
|
||||
return std::make_pair(node_id, id);
|
||||
}
|
||||
@@ -201,8 +201,9 @@ class NodeStack {
|
||||
template <Parse::NodeCategory::RawEnumType RequiredParseCategory>
|
||||
auto PopWithNodeId() -> auto {
|
||||
auto id = Peek<RequiredParseCategory>();
|
||||
Parse::NodeIdInCategory<RequiredParseCategory> node_id(
|
||||
stack_.pop_back_val().node_id);
|
||||
auto node_id =
|
||||
parse_tree_->As<Parse::NodeIdInCategory<RequiredParseCategory>>(
|
||||
stack_.pop_back_val().node_id);
|
||||
return std::make_pair(node_id, id);
|
||||
}
|
||||
|
||||
@@ -302,7 +303,9 @@ class NodeStack {
|
||||
template <const Parse::NodeKind& RequiredParseKind>
|
||||
auto Peek() const -> auto {
|
||||
Entry back = stack_.back();
|
||||
RequireParseKind<RequiredParseKind>(back.node_id);
|
||||
CARBON_CHECK(RequiredParseKind == parse_tree_->node_kind(back.node_id),
|
||||
"Expected {0}, found {1}", RequiredParseKind,
|
||||
parse_tree_->node_kind(back.node_id));
|
||||
constexpr Id::Kind RequiredIdKind = NodeKindToIdKind(RequiredParseKind);
|
||||
return Peek<RequiredIdKind>();
|
||||
}
|
||||
@@ -589,14 +592,6 @@ class NodeStack {
|
||||
SemIR::IdKind(NodeKindToIdKind(parse_kind)));
|
||||
}
|
||||
|
||||
// Require an entry to have the given Parse::NodeKind.
|
||||
template <const Parse::NodeKind& RequiredParseKind>
|
||||
auto RequireParseKind(Parse::NodeId node_id) const -> void {
|
||||
auto actual_kind = parse_tree_->node_kind(node_id);
|
||||
CARBON_CHECK(RequiredParseKind == actual_kind, "Expected {0}, found {1}",
|
||||
RequiredParseKind, actual_kind);
|
||||
}
|
||||
|
||||
// Require an entry to have the given Parse::NodeCategory.
|
||||
template <Parse::NodeCategory::RawEnumType RequiredParseCategory>
|
||||
auto RequireParseCategory(Parse::NodeId node_id) const -> void {
|
||||
|
||||
Reference in New Issue
Block a user