Add a macro for introducer tokens. (#4031)

Playing with the macro suggestion on #4028, replace DeclKind with some
templating that asserts the in-use token is an introducer token. This
allows type-safe usage of Lex::TokenKind, reducing the benefit of a
separate enum while improving stdout (since now this will ostream as the
keyword name).
This commit is contained in:
Jon Ross-Perkins
2024-06-05 21:04:53 +00:00
committed by GitHub
parent 7792e5fce3
commit d1862e829b
16 changed files with 92 additions and 113 deletions
+2 -2
View File
@@ -15,7 +15,7 @@ namespace Carbon::Check {
auto HandleExportIntroducer(Context& context,
Parse::ExportIntroducerId /*node_id*/) -> bool {
context.decl_introducer_state_stack().Push(DeclIntroducerState::Export);
context.decl_introducer_state_stack().Push<Lex::TokenKind::Export>();
// TODO: Probably need to update DeclNameStack to restrict to only namespaces.
context.decl_name_stack().PushScopeAndStartName();
return true;
@@ -27,7 +27,7 @@ auto HandleExportDecl(Context& context, Parse::ExportDeclId node_id) -> bool {
context.decl_name_stack().PopScope();
auto introducer =
context.decl_introducer_state_stack().Pop(DeclIntroducerState::Export);
context.decl_introducer_state_stack().Pop<Lex::TokenKind::Export>();
LimitModifiersOnDecl(context, introducer, KeywordModifierSet::None);
if (name_context.state == DeclNameStack::NameContext::State::Error) {