Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid redundantly specifying Id::Kind. #4911

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions toolchain/check/node_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,24 @@ auto NodeStack::PrintForStackDump(int indent, llvm::raw_ostream& output) const
}
}

// NOLINTNEXTLINE(readability-function-size)
auto NodeStack::CheckIdKindTable() -> void {
#define CARBON_PARSE_NODE_KIND(Name) \
{ \
constexpr auto from_category = \
NodeCategoryToIdKind(Parse::Name::Kind.category(), true); \
constexpr auto from_kind = \
NodeKindToIdKindSpecialCases(Parse::Name::Kind); \
static_assert(from_category || from_kind, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW !!from_category != !!to_category would check that only one exists in a single assertion, but then you don't have two descriptive errors, dunno if you'd prefer that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the extra code is worth it for the improved diagnostic.

"Id::Kind not specified for " #Name \
"; add to NodeStack::NodeKindToIdKindSpecialCases or " \
"specify a node category in typed_nodes.h"); \
static_assert(!from_category || !from_kind, \
"Special case Id::Kind specified for " #Name \
", but node category has an Id::Kind; remove from " \
"NodeStack::NodeKindToIdKindSpecialCases"); \
}
#include "toolchain/parse/node_kind.def"
}

} // namespace Carbon::Check
Loading