mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user