diff --git a/toolchain/check/handle_modifier.cpp b/toolchain/check/handle_modifier.cpp index 8413a3fafa48..1724d4dc0468 100644 --- a/toolchain/check/handle_modifier.cpp +++ b/toolchain/check/handle_modifier.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include "toolchain/check/context.h" +#include "toolchain/check/decl_state.h" #include "toolchain/lex/token_kind.h" namespace Carbon::Check { @@ -33,28 +34,16 @@ static auto EmitNotAllowedWithDiagnostic(Context& context, .Emit(); } -static auto GetAccessModifierEnum(Lex::TokenKind token_kind) - -> KeywordModifierSet { - switch (token_kind) { - case Lex::TokenKind::Private: - return KeywordModifierSet::Private; - case Lex::TokenKind::Protected: - return KeywordModifierSet::Protected; - default: - CARBON_FATAL() << "Unhandled access modifier keyword"; - } -} - -auto HandleAccessModifierKeyword(Context& context, Parse::NodeId parse_node) - -> bool { - auto keyword = GetAccessModifierEnum( - context.tokens().GetKind(context.parse_tree().node_token(parse_node))); +static auto HandleModifier(Context& context, Parse::NodeId parse_node, + KeywordModifierSet keyword) -> bool { auto& s = context.decl_state_stack().innermost(); + bool is_access = !!(keyword & KeywordModifierSet::Access); + auto& saw_modifier = is_access ? s.saw_access_modifier : s.saw_decl_modifier; if (!!(s.modifier_set & keyword)) { - EmitRepeatedDiagnostic(context, s.saw_access_modifier, parse_node); - } else if (s.saw_access_modifier.is_valid()) { - EmitNotAllowedWithDiagnostic(context, s.saw_access_modifier, parse_node); - } else if (s.saw_decl_modifier.is_valid()) { + EmitRepeatedDiagnostic(context, saw_modifier, parse_node); + } else if (saw_modifier.is_valid()) { + EmitNotAllowedWithDiagnostic(context, saw_modifier, parse_node); + } else if (is_access && s.saw_decl_modifier.is_valid()) { CARBON_DIAGNOSTIC(ModifierMustAppearBefore, Error, "`{0}` must appear before `{1}`.", Lex::TokenKind, Lex::TokenKind); @@ -67,52 +56,20 @@ auto HandleAccessModifierKeyword(Context& context, Parse::NodeId parse_node) .Emit(); } else { s.modifier_set |= keyword; - s.saw_access_modifier = parse_node; - s.first_node = parse_node; - } - - return true; -} - -static auto GetDeclModifierEnum(Lex::TokenKind token_kind) - -> KeywordModifierSet { - switch (token_kind) { - case Lex::TokenKind::Abstract: - return KeywordModifierSet::Abstract; - case Lex::TokenKind::Base: - return KeywordModifierSet::Base; - case Lex::TokenKind::Default: - return KeywordModifierSet::Default; - case Lex::TokenKind::Extend: - return KeywordModifierSet::Extend; - case Lex::TokenKind::Final: - return KeywordModifierSet::Final; - case Lex::TokenKind::Impl: - return KeywordModifierSet::Impl; - case Lex::TokenKind::Virtual: - return KeywordModifierSet::Virtual; - default: - CARBON_FATAL() << "Unhandled declaration modifier keyword"; - } -} - -auto HandleDeclModifierKeyword(Context& context, Parse::NodeId parse_node) - -> bool { - auto keyword = GetDeclModifierEnum( - context.tokens().GetKind(context.parse_tree().node_token(parse_node))); - auto& s = context.decl_state_stack().innermost(); - if (!!(s.modifier_set & keyword)) { - EmitRepeatedDiagnostic(context, s.saw_decl_modifier, parse_node); - } else if (s.saw_decl_modifier.is_valid()) { - EmitNotAllowedWithDiagnostic(context, s.saw_decl_modifier, parse_node); - } else { - s.modifier_set |= keyword; - s.saw_decl_modifier = parse_node; - if (s.saw_access_modifier == Parse::NodeId::Invalid) { + saw_modifier = parse_node; + if (is_access || !s.saw_access_modifier.is_valid()) { s.first_node = parse_node; } } return true; } +#define CARBON_PARSE_NODE_KIND(...) +#define CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name, ...) \ + auto Handle##Name##Modifier(Context& context, Parse::NodeId parse_node) \ + ->bool { \ + return HandleModifier(context, parse_node, KeywordModifierSet::Name); \ + } +#include "toolchain/parse/node_kind.def" + } // namespace Carbon::Check diff --git a/toolchain/check/node_stack.h b/toolchain/check/node_stack.h index f7127c7c1d87..c922b05a7f28 100644 --- a/toolchain/check/node_stack.h +++ b/toolchain/check/node_stack.h @@ -330,11 +330,6 @@ class NodeStack { case Parse::NodeKind::StructFieldType: case Parse::NodeKind::StructTypeLiteral: case Parse::NodeKind::TupleLiteral: -// Use x-macros to handle literal cases. -#define CARBON_PARSE_NODE_KIND(...) -#define CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(Name, ...) \ - case Parse::NodeKind::Name: -#include "toolchain/parse/node_kind.def" return IdKind::InstId; case Parse::NodeKind::IfCondition: case Parse::NodeKind::IfExprIf: @@ -350,11 +345,9 @@ class NodeStack { case Parse::NodeKind::BaseName: case Parse::NodeKind::Name: return IdKind::NameId; - case Parse::NodeKind::AccessModifierKeyword: case Parse::NodeKind::ArrayExprSemi: case Parse::NodeKind::ClassIntroducer: case Parse::NodeKind::CodeBlockStart: - case Parse::NodeKind::DeclModifierKeyword: case Parse::NodeKind::FunctionIntroducer: case Parse::NodeKind::IfStatementElse: case Parse::NodeKind::ImplicitParamListStart: @@ -370,6 +363,15 @@ class NodeStack { case Parse::NodeKind::VariableInitializer: case Parse::NodeKind::VariableIntroducer: return IdKind::SoloParseNode; +// Use x-macros to handle token cases. +#define CARBON_PARSE_NODE_KIND(...) +#define CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(Name, ...) \ + case Parse::NodeKind::Name: \ + return IdKind::InstId; +#define CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name, ...) \ + case Parse::NodeKind::Name##Modifier: \ + return IdKind::SoloParseNode; +#include "toolchain/parse/node_kind.def" default: return IdKind::Unused; } diff --git a/toolchain/parse/handle_decl_scope_loop.cpp b/toolchain/parse/handle_decl_scope_loop.cpp index 1ad52535ccf0..7f026160c14f 100644 --- a/toolchain/parse/handle_decl_scope_loop.cpp +++ b/toolchain/parse/handle_decl_scope_loop.cpp @@ -120,15 +120,32 @@ auto HandleDeclScopeLoop(Context& context) -> void { bool saw_modifier = false; while (true) { switch (context.PositionKind()) { - // If we see a access modifier keyword token, add it as a leaf node - // and repeat with the next token. + // If we see a modifier keyword token, add it as a leaf node and loop to + // the next token. + case Lex::TokenKind::Abstract: + context.AddLeafNode(NodeKind::AbstractModifier, context.Consume()); + saw_modifier = true; + break; + case Lex::TokenKind::Default: + context.AddLeafNode(NodeKind::DefaultModifier, context.Consume()); + saw_modifier = true; + break; + case Lex::TokenKind::Final: + context.AddLeafNode(NodeKind::FinalModifier, context.Consume()); + saw_modifier = true; + break; case Lex::TokenKind::Private: - case Lex::TokenKind::Protected: { - auto modifier_token = context.Consume(); - context.AddLeafNode(NodeKind::AccessModifierKeyword, modifier_token); + context.AddLeafNode(NodeKind::PrivateModifier, context.Consume()); + saw_modifier = true; + break; + case Lex::TokenKind::Protected: + context.AddLeafNode(NodeKind::ProtectedModifier, context.Consume()); + saw_modifier = true; + break; + case Lex::TokenKind::Virtual: + context.AddLeafNode(NodeKind::VirtualModifier, context.Consume()); saw_modifier = true; break; - } case Lex::TokenKind::Base: // `base` may be followed by: @@ -160,26 +177,16 @@ auto HandleDeclScopeLoop(Context& context) -> void { OutputInvalidParseSubtree(context, state.subtree_start); return; } - [[fallthrough]]; - - // If we see a declaration modifier keyword token, add it as a leaf node - // and repeat with the next token. - case Lex::TokenKind::Abstract: - case Lex::TokenKind::Default: - case Lex::TokenKind::Final: - case Lex::TokenKind::Virtual: { - auto modifier_token = context.Consume(); - context.AddLeafNode(NodeKind::DeclModifierKeyword, modifier_token); + context.AddLeafNode(NodeKind::BaseModifier, context.Consume()); saw_modifier = true; break; - } case Lex::TokenKind::Impl: { // `impl` is considered a declaration modifier if it is followed by // another modifier or an introducer. if (TokenIsModifierOrIntroducer( context.PositionKind(Lookahead::NextToken))) { - context.AddLeafNode(NodeKind::DeclModifierKeyword, context.Consume()); + context.AddLeafNode(NodeKind::ImplModifier, context.Consume()); saw_modifier = true; } else { // TODO: Treat this `impl` token as a declaration introducer @@ -194,7 +201,7 @@ auto HandleDeclScopeLoop(Context& context) -> void { // another modifier or an introducer. if (TokenIsModifierOrIntroducer( context.PositionKind(Lookahead::NextToken))) { - context.AddLeafNode(NodeKind::DeclModifierKeyword, context.Consume()); + context.AddLeafNode(NodeKind::ExtendModifier, context.Consume()); saw_modifier = true; } else { // TODO: Treat this `extend` token as a declaration introducer diff --git a/toolchain/parse/node_kind.def b/toolchain/parse/node_kind.def index 9a9224869eb7..7f1dbd363698 100644 --- a/toolchain/parse/node_kind.def +++ b/toolchain/parse/node_kind.def @@ -17,9 +17,12 @@ // - CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ChildCount, LexTokenKinds) // Defines a parse node with a set number of children, often 0. This count // must be correct even when the node contains errors. -// - CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(Name, TokenIndex) +// - CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(Name, LexTokenKinds) // Defines a parse node that corresponds to a token that is a single-token // literal. The token is wrapped for LexTokenKinds. +// - CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name) +// A token-based modifier. The Name is the TokenKind, and will be appended +// with "Modifier" for the parse kind. // // In both cases, LexTokenKinds says which Lex::TokenKind values that this // parse node can correspond to, and is a sequence of: @@ -60,6 +63,16 @@ CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, 0, LexTokenKinds) #endif +// This is expected to be used with something like: +// +// // Use x-macros to handle modifier cases. +// #define CARBON_PARSE_NODE_KIND(...) +// #define CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name, ...) +#ifndef CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER +#define CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Name) \ + CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name##Modifier, 0, CARBON_TOKEN(Name)) +#endif + // The start of the file. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileStart, 0, CARBON_TOKEN(FileStart)) @@ -182,7 +195,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(CodeBlock, CodeBlockStart, // `fn`: // FunctionIntroducer -// _repeated_ _external_: AccessModifierKeyword or DeclModifierKeyword +// _repeated_ _external_: modifier // _external_: Name or QualifiedDecl // _external_: ParamList // _external_: type expression @@ -252,7 +265,7 @@ CARBON_PARSE_NODE_KIND_CHILD_COUNT(Template, 1, CARBON_TOKEN(Template)) // `let`: // LetIntroducer -// _repeated_ _external_: AccessModifierKeyword or DeclModifierKeyword +// _repeated_ _external_: modifier // _external_: BindingPattern // LetInitializer // _external_: expression @@ -267,7 +280,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(LetDecl, LetIntroducer, // `var` and `returned var`: // VariableIntroducer -// _repeated_ _external_: AccessModifierKeyword or DeclModifierKeyword +// _repeated_ _external_: modifier // _optional_ ReturnedModifier // _external_: BindingPattern // VariableInitializer @@ -448,8 +461,7 @@ CARBON_PARSE_NODE_KIND_CHILD_COUNT(PointerMemberAccessExpr, 2, // A value literal. CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(BoolLiteralFalse, CARBON_TOKEN(False)) CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(BoolLiteralTrue, CARBON_TOKEN(True)) -CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(IntLiteral, - CARBON_TOKEN(IntLiteral)) +CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(IntLiteral, CARBON_TOKEN(IntLiteral)) CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(RealLiteral, CARBON_TOKEN(RealLiteral)) CARBON_PARSE_NODE_KIND_TOKEN_LITERAL(StringLiteral, CARBON_TOKEN(StringLiteral)) @@ -586,35 +598,20 @@ CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral, StructLiteralOrStructTypeLiteralStart, CARBON_TOKEN(CloseCurlyBrace)) -// TODO: Is there a benefit to having different parse node kinds for every -// different modifier token? - -// Access modifier keywords `private` or `protected`: -// AccessModifierKeyword -// -// The kind of keyword is determined by looking at the token kind. -// These may be repeated, including possibly zero times. -CARBON_PARSE_NODE_KIND_CHILD_COUNT(AccessModifierKeyword, 0, - CARBON_TOKEN(Private) - CARBON_TOKEN(Protected)) - -// Declaration modifier keywords such as `abstract` or `virtual`: -// DeclModifierKeyword -// -// The kind of keyword is determined by looking at the token kind. -// These may be repeated, including possibly zero times. -CARBON_PARSE_NODE_KIND_CHILD_COUNT(DeclModifierKeyword, 0, - CARBON_TOKEN(Abstract) - CARBON_TOKEN(Base) - CARBON_TOKEN(Default) - CARBON_TOKEN(Extend) - CARBON_TOKEN(Final) - CARBON_TOKEN(Impl) - CARBON_TOKEN(Virtual)) +// Various modifiers. These are all a single token. +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Abstract) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Base) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Default) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Extend) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Final) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Impl) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Private) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Protected) +CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER(Virtual) // `class`: // ClassIntroducer -// _repeated_ _external_: AccessModifierKeyword or DeclModifierKeyword +// _repeated_ _external_: modifier // _external_: Name or QualifiedDecl // ClassDefinitionStart // _external_: declarations @@ -634,7 +631,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(ClassDecl, ClassIntroducer, // `base`: // BaseIntroducer -// _repeated_ _external_: AccessModifierKeyword or DeclModifierKeyword +// _repeated_ _external_: modifier // BaseColon // _external_: expression // BaseDecl @@ -646,7 +643,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(BaseDecl, BaseIntroducer, // `interface`: // InterfaceIntroducer -// _repeated_ _external_: AccessModifierKeyword or DeclModifierKeyword +// _repeated_ _external_: modifier // _external_: Name or QualifiedDecl // InterfaceDefinitionStart // _external_: declarations @@ -667,7 +664,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDecl, InterfaceIntroducer, // `constraint`: // NamedConstraintIntroducer -// _repeated_ _external_: AccessModifierKeyword or DeclModifierKeyword +// _repeated_ _external_: modifier // _external_: Name or QualifiedDecl // NamedConstraintDefinitionStart // _external_: declarations @@ -714,6 +711,7 @@ CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageExpr, 0, CARBON_TOKEN(Package)) #undef CARBON_PARSE_NODE_KIND_BRACKET #undef CARBON_PARSE_NODE_KIND_CHILD_COUNT #undef CARBON_PARSE_NODE_KIND_TOKEN_LITERAL +#undef CARBON_PARSE_NODE_KIND_TOKEN_MODIFIER #undef CARBON_TOKEN #undef CARBON_ANY_TOKEN #undef CARBON_IF_ERROR diff --git a/toolchain/parse/testdata/basics/fail_modifiers_before_semi.carbon b/toolchain/parse/testdata/basics/fail_modifiers_before_semi.carbon index cd505060f7f9..5ee62a625380 100644 --- a/toolchain/parse/testdata/basics/fail_modifiers_before_semi.carbon +++ b/toolchain/parse/testdata/basics/fail_modifiers_before_semi.carbon @@ -13,8 +13,8 @@ protected virtual; // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'InvalidParseStart', text: ';', has_error: yes}, -// CHECK:STDOUT: {kind: 'AccessModifierKeyword', text: 'protected'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'virtual'}, +// CHECK:STDOUT: {kind: 'ProtectedModifier', text: 'protected'}, +// CHECK:STDOUT: {kind: 'VirtualModifier', text: 'virtual'}, // CHECK:STDOUT: {kind: 'InvalidParseSubtree', text: ';', has_error: yes, subtree_size: 4}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/class/base.carbon b/toolchain/parse/testdata/class/base.carbon index f9cd3003dab4..ca68e253d1fd 100644 --- a/toolchain/parse/testdata/class/base.carbon +++ b/toolchain/parse/testdata/class/base.carbon @@ -17,7 +17,7 @@ class D { // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, // CHECK:STDOUT: {kind: 'Name', text: 'B'}, // CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 5}, @@ -29,17 +29,17 @@ class D { // CHECK:STDOUT: {kind: 'NameExpr', text: 'B1'}, // CHECK:STDOUT: {kind: 'BaseDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'BaseIntroducer', text: 'base'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'extend'}, +// CHECK:STDOUT: {kind: 'ExtendModifier', text: 'extend'}, // CHECK:STDOUT: {kind: 'BaseColon', text: ':'}, // CHECK:STDOUT: {kind: 'NameExpr', text: 'B2'}, // CHECK:STDOUT: {kind: 'BaseDecl', text: ';', subtree_size: 5}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, // CHECK:STDOUT: {kind: 'Name', text: 'Nested'}, // CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'AccessModifierKeyword', text: 'private'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, +// CHECK:STDOUT: {kind: 'PrivateModifier', text: 'private'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, // CHECK:STDOUT: {kind: 'Name', text: 'PrivateNested'}, // CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 5}, // CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 22}, diff --git a/toolchain/parse/testdata/class/fail_base_misplaced.carbon b/toolchain/parse/testdata/class/fail_base_misplaced.carbon index 6a1e4437f132..814ab4365b1e 100644 --- a/toolchain/parse/testdata/class/fail_base_misplaced.carbon +++ b/toolchain/parse/testdata/class/fail_base_misplaced.carbon @@ -17,7 +17,7 @@ fn F() { // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, // CHECK:STDOUT: {kind: 'Name', text: 'B'}, // CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 5}, diff --git a/toolchain/parse/testdata/class/introducer.carbon b/toolchain/parse/testdata/class/introducer.carbon index 490ec809a28e..5db7a77afa24 100644 --- a/toolchain/parse/testdata/class/introducer.carbon +++ b/toolchain/parse/testdata/class/introducer.carbon @@ -19,11 +19,11 @@ abstract class C {} // CHECK:STDOUT: {kind: 'Name', text: 'A'}, // CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, // CHECK:STDOUT: {kind: 'Name', text: 'B'}, // CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'abstract'}, +// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'}, // CHECK:STDOUT: {kind: 'Name', text: 'C'}, // CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, @@ -31,12 +31,12 @@ abstract class C {} // CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 3}, // CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, // CHECK:STDOUT: {kind: 'Name', text: 'B'}, // CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 5}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'abstract'}, +// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'}, // CHECK:STDOUT: {kind: 'Name', text: 'C'}, // CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 4}, // CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 5}, diff --git a/toolchain/parse/testdata/class/mismatched_introducer.carbon b/toolchain/parse/testdata/class/mismatched_introducer.carbon index 1f449ba6c530..cb8825a426ef 100644 --- a/toolchain/parse/testdata/class/mismatched_introducer.carbon +++ b/toolchain/parse/testdata/class/mismatched_introducer.carbon @@ -13,18 +13,18 @@ abstract base class C; // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'InterfaceIntroducer', text: 'interface'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'abstract'}, +// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'}, // CHECK:STDOUT: {kind: 'Name', text: 'I'}, // CHECK:STDOUT: {kind: 'InterfaceDecl', text: ';', subtree_size: 4}, // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, // CHECK:STDOUT: {kind: 'Name', text: 'F'}, // CHECK:STDOUT: {kind: 'ParamListStart', text: '('}, // CHECK:STDOUT: {kind: 'ParamList', text: ')', subtree_size: 2}, // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 6}, // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'abstract'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, +// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, // CHECK:STDOUT: {kind: 'Name', text: 'C'}, // CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 5}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, diff --git a/toolchain/parse/testdata/function/declaration/impl_fn.carbon b/toolchain/parse/testdata/function/declaration/impl_fn.carbon index 3c313a99d9da..1d457282b9cd 100644 --- a/toolchain/parse/testdata/function/declaration/impl_fn.carbon +++ b/toolchain/parse/testdata/function/declaration/impl_fn.carbon @@ -13,29 +13,29 @@ private impl default fn I(); // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'impl'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, // CHECK:STDOUT: {kind: 'Name', text: 'F'}, // CHECK:STDOUT: {kind: 'ParamListStart', text: '('}, // CHECK:STDOUT: {kind: 'ParamList', text: ')', subtree_size: 2}, // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 6}, // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'abstract'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'impl'}, +// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, // CHECK:STDOUT: {kind: 'Name', text: 'G'}, // CHECK:STDOUT: {kind: 'ParamListStart', text: '('}, // CHECK:STDOUT: {kind: 'ParamList', text: ')', subtree_size: 2}, // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 7}, // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'impl'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'abstract'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, +// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'}, // CHECK:STDOUT: {kind: 'Name', text: 'H'}, // CHECK:STDOUT: {kind: 'ParamListStart', text: '('}, // CHECK:STDOUT: {kind: 'ParamList', text: ')', subtree_size: 2}, // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 7}, // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'}, -// CHECK:STDOUT: {kind: 'AccessModifierKeyword', text: 'private'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'impl'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'default'}, +// CHECK:STDOUT: {kind: 'PrivateModifier', text: 'private'}, +// CHECK:STDOUT: {kind: 'ImplModifier', text: 'impl'}, +// CHECK:STDOUT: {kind: 'DefaultModifier', text: 'default'}, // CHECK:STDOUT: {kind: 'Name', text: 'I'}, // CHECK:STDOUT: {kind: 'ParamListStart', text: '('}, // CHECK:STDOUT: {kind: 'ParamList', text: ')', subtree_size: 2}, diff --git a/toolchain/parse/testdata/namespace/fail_modifiers.carbon b/toolchain/parse/testdata/namespace/fail_modifiers.carbon index 93395481b201..a904082560c7 100644 --- a/toolchain/parse/testdata/namespace/fail_modifiers.carbon +++ b/toolchain/parse/testdata/namespace/fail_modifiers.carbon @@ -18,11 +18,11 @@ impl namespace // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'InvalidParseStart', text: 'namespace', has_error: yes}, -// CHECK:STDOUT: {kind: 'AccessModifierKeyword', text: 'private'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'abstract'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'base'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'default'}, -// CHECK:STDOUT: {kind: 'DeclModifierKeyword', text: 'final'}, +// CHECK:STDOUT: {kind: 'PrivateModifier', text: 'private'}, +// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'}, +// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'}, +// CHECK:STDOUT: {kind: 'DefaultModifier', text: 'default'}, +// CHECK:STDOUT: {kind: 'FinalModifier', text: 'final'}, // CHECK:STDOUT: {kind: 'InvalidParseSubtree', text: ';', has_error: yes, subtree_size: 7}, // CHECK:STDOUT: {kind: 'InvalidParseStart', text: 'impl', has_error: yes}, // CHECK:STDOUT: {kind: 'InvalidParseSubtree', text: 'namespace', has_error: yes, subtree_size: 2},