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:
Jon Ross-Perkins
2024-05-29 22:47:50 +00:00
committed by GitHub
parent 419d2e39d8
commit cda5f66d22
10 changed files with 79 additions and 58 deletions
+6 -8
View File
@@ -10,16 +10,15 @@
namespace Carbon::Parse {
auto operator<<(llvm::raw_ostream& output, NodeCategory category)
-> llvm::raw_ostream& {
if (!category) {
output << "<none>";
auto NodeCategory::Print(llvm::raw_ostream& out) const -> void {
if (!value_) {
out << "<none>";
} else {
llvm::ListSeparator sep("|");
#define CARBON_NODE_CATEGORY(Name) \
if (!!(category & NodeCategory::Name)) { \
output << sep << #Name; \
#define CARBON_NODE_CATEGORY(Name) \
if (value_ & NodeCategory::Name) { \
out << sep << #Name; \
}
CARBON_NODE_CATEGORY(Decl);
CARBON_NODE_CATEGORY(Expr);
@@ -31,7 +30,6 @@ auto operator<<(llvm::raw_ostream& output, NodeCategory category)
CARBON_NODE_CATEGORY(Statement);
#undef CARBON_NODE_CATEGORY
}
return output;
}
CARBON_DEFINE_ENUM_CLASS_NAMES(NodeKind) = {