mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Rename Parse::State to Parse::StateKind (#5249)
Also renames variables of that type to match. A follow-up PR will rename `Parse::StateStackEntry` to `Parse::State`. This is more consistent with the naming of similar enums elsewhere in the toolchain, and with the prevailing practice of using `state` rather than e.g. `entry` as the name of a `StateStackEntry`. See also discussion [here](https://discord.com/channels/655572317891461132/963846118964350976/1326280585592700990)
This commit is contained in:
@@ -33,12 +33,12 @@ static auto HandleUnrecognizedDecl(Context& context, int32_t subtree_start)
|
||||
// Replaces the introducer placeholder node, and pushes the introducer state for
|
||||
// processing.
|
||||
static auto ApplyIntroducer(Context& context, Context::StateStackEntry state,
|
||||
NodeKind introducer_kind, State next_state)
|
||||
NodeKind introducer_kind, StateKind next_state_kind)
|
||||
-> void {
|
||||
context.ReplacePlaceholderNode(state.subtree_start, introducer_kind,
|
||||
context.Consume());
|
||||
// Reuse state here to retain its `subtree_start`.
|
||||
context.PushState(state, next_state);
|
||||
context.PushState(state, next_state_kind);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -53,7 +53,7 @@ enum class DeclIntroducerKind : int8_t {
|
||||
struct DeclIntroducerInfo {
|
||||
DeclIntroducerKind introducer_kind;
|
||||
NodeKind node_kind;
|
||||
State state;
|
||||
StateKind state_kind;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -62,52 +62,55 @@ static constexpr auto DeclIntroducers = [] {
|
||||
#define CARBON_TOKEN(Name) \
|
||||
{.introducer_kind = DeclIntroducerKind::Unrecognized, \
|
||||
.node_kind = NodeKind::InvalidParse, \
|
||||
.state = State::Invalid},
|
||||
.state_kind = StateKind::Invalid},
|
||||
#include "toolchain/lex/token_kind.def"
|
||||
};
|
||||
auto set = [&](Lex::TokenKind token_kind, NodeKind node_kind, State state) {
|
||||
auto set = [&](Lex::TokenKind token_kind, NodeKind node_kind,
|
||||
StateKind state) {
|
||||
introducers[token_kind.AsInt()] = {
|
||||
.introducer_kind = DeclIntroducerKind::NonPackagingDecl,
|
||||
.node_kind = node_kind,
|
||||
.state = state};
|
||||
.state_kind = state};
|
||||
};
|
||||
auto set_packaging = [&](Lex::TokenKind token_kind, NodeKind node_kind,
|
||||
State state) {
|
||||
StateKind state) {
|
||||
introducers[token_kind.AsInt()] = {
|
||||
.introducer_kind = DeclIntroducerKind::PackagingDecl,
|
||||
.node_kind = node_kind,
|
||||
.state = state};
|
||||
.state_kind = state};
|
||||
};
|
||||
|
||||
set(Lex::TokenKind::Adapt, NodeKind::AdaptIntroducer,
|
||||
State::AdaptAfterIntroducer);
|
||||
set(Lex::TokenKind::Alias, NodeKind::AliasIntroducer, State::Alias);
|
||||
StateKind::AdaptAfterIntroducer);
|
||||
set(Lex::TokenKind::Alias, NodeKind::AliasIntroducer, StateKind::Alias);
|
||||
set(Lex::TokenKind::Base, NodeKind::BaseIntroducer,
|
||||
State::BaseAfterIntroducer);
|
||||
StateKind::BaseAfterIntroducer);
|
||||
set(Lex::TokenKind::Choice, NodeKind::ChoiceIntroducer,
|
||||
State::ChoiceIntroducer);
|
||||
StateKind::ChoiceIntroducer);
|
||||
set(Lex::TokenKind::Class, NodeKind::ClassIntroducer,
|
||||
State::TypeAfterIntroducerAsClass);
|
||||
StateKind::TypeAfterIntroducerAsClass);
|
||||
set(Lex::TokenKind::Constraint, NodeKind::NamedConstraintIntroducer,
|
||||
State::TypeAfterIntroducerAsNamedConstraint);
|
||||
set(Lex::TokenKind::Export, NodeKind::ExportIntroducer, State::ExportName);
|
||||
StateKind::TypeAfterIntroducerAsNamedConstraint);
|
||||
set(Lex::TokenKind::Export, NodeKind::ExportIntroducer,
|
||||
StateKind::ExportName);
|
||||
// TODO: Treat `extend` as a declaration introducer.
|
||||
set(Lex::TokenKind::Fn, NodeKind::FunctionIntroducer,
|
||||
State::FunctionIntroducer);
|
||||
StateKind::FunctionIntroducer);
|
||||
set(Lex::TokenKind::Impl, NodeKind::ImplIntroducer,
|
||||
State::ImplAfterIntroducer);
|
||||
StateKind::ImplAfterIntroducer);
|
||||
set(Lex::TokenKind::Interface, NodeKind::InterfaceIntroducer,
|
||||
State::TypeAfterIntroducerAsInterface);
|
||||
set(Lex::TokenKind::Namespace, NodeKind::NamespaceStart, State::Namespace);
|
||||
set(Lex::TokenKind::Let, NodeKind::LetIntroducer, State::Let);
|
||||
set(Lex::TokenKind::Var, NodeKind::VariableIntroducer, State::VarAsDecl);
|
||||
StateKind::TypeAfterIntroducerAsInterface);
|
||||
set(Lex::TokenKind::Namespace, NodeKind::NamespaceStart,
|
||||
StateKind::Namespace);
|
||||
set(Lex::TokenKind::Let, NodeKind::LetIntroducer, StateKind::Let);
|
||||
set(Lex::TokenKind::Var, NodeKind::VariableIntroducer, StateKind::VarAsDecl);
|
||||
|
||||
set_packaging(Lex::TokenKind::Package, NodeKind::PackageIntroducer,
|
||||
State::Package);
|
||||
StateKind::Package);
|
||||
set_packaging(Lex::TokenKind::Library, NodeKind::LibraryIntroducer,
|
||||
State::Library);
|
||||
StateKind::Library);
|
||||
set_packaging(Lex::TokenKind::Import, NodeKind::ImportIntroducer,
|
||||
State::Import);
|
||||
StateKind::Import);
|
||||
return std::to_array(introducers);
|
||||
}();
|
||||
|
||||
@@ -152,7 +155,7 @@ static auto TryHandleAsDecl(Context& context, Context::StateStackEntry state,
|
||||
}
|
||||
}
|
||||
|
||||
ApplyIntroducer(context, state, info.node_kind, info.state);
|
||||
ApplyIntroducer(context, state, info.node_kind, info.state_kind);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -266,7 +269,7 @@ auto HandleDeclScopeLoop(Context& context) -> void {
|
||||
return;
|
||||
}
|
||||
|
||||
context.PushState(State::Decl);
|
||||
context.PushState(StateKind::Decl);
|
||||
}
|
||||
|
||||
} // namespace Carbon::Parse
|
||||
|
||||
Reference in New Issue
Block a user