Make Parse::NodeCategory printable (#3548)

Completes TODO in `parse/extract.cpp`, moving the printing code for
`NodeCategory` out of the implementation of
`Extractable<NodeIdInCategory<T>>`.
This commit is contained in:
josh11b
2023-12-28 20:04:54 +00:00
committed by GitHub
parent 73cf277bdf
commit 83b5db9c1e
3 changed files with 31 additions and 23 deletions
+23
View File
@@ -5,10 +5,33 @@
#include "toolchain/parse/node_kind.h"
#include "common/check.h"
#include "llvm/ADT/StringExtras.h"
#include "toolchain/parse/typed_nodes.h"
namespace Carbon::Parse {
auto operator<<(llvm::raw_ostream& output, NodeCategory category)
-> llvm::raw_ostream& {
if (!category) {
output << "<none>";
} else {
llvm::ListSeparator sep("|");
#define CARBON_NODE_CATEGORY(Name) \
if (!!(category & NodeCategory::Name)) { \
output << sep << #Name; \
}
CARBON_NODE_CATEGORY(Decl);
CARBON_NODE_CATEGORY(Expr);
CARBON_NODE_CATEGORY(Modifier);
CARBON_NODE_CATEGORY(NameComponent);
CARBON_NODE_CATEGORY(Pattern);
CARBON_NODE_CATEGORY(Statement);
#undef CARBON_NODE_CATEGORY
}
return output;
}
CARBON_DEFINE_ENUM_CLASS_NAMES(NodeKind) = {
#define CARBON_PARSE_NODE_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
#include "toolchain/parse/node_kind.def"