mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 10:54:49 +01:00
Refactor NodeCategory to provide a class API (#4004)
Mirroring #4003 for NodeCategory. Note we template a lot more on NodeCategory's enum, so this is a slightly more awkward delta. Also, switch from Enum in KeywordModifierSet to RawEnumType for consistency with EnumBase. The templating on NodeCategory had me thinking about that more.
This commit is contained in:
@@ -50,14 +50,14 @@ const NodeKind& NodeIdForKind<K>::Kind = K;
|
||||
#include "toolchain/parse/node_kind.def"
|
||||
|
||||
// NodeId that matches any NodeKind whose `category()` overlaps with `Category`.
|
||||
template <NodeCategory Category>
|
||||
template <NodeCategory::RawEnumType Category>
|
||||
struct NodeIdInCategory : public NodeId {
|
||||
// Support conversion from `NodeIdForKind<Kind>` if Kind's category
|
||||
// overlaps with `Category`.
|
||||
template <const NodeKind& Kind>
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
NodeIdInCategory(NodeIdForKind<Kind> node_id) : NodeId(node_id) {
|
||||
CARBON_CHECK(!!(Kind.category() & Category));
|
||||
CARBON_CHECK(Kind.category().HasAnyOf(Category));
|
||||
}
|
||||
|
||||
constexpr explicit NodeIdInCategory(NodeId node_id) : NodeId(node_id) {}
|
||||
|
||||
Reference in New Issue
Block a user