mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Defer parsing of method bodies until the end of a suitable enclosing scope. (#3832)
In parse, form a list of methods that are defined inline, tracking where they start, where they end, and which other inline methods are nested within them. In check, when we reach an inline method body, skip it and add it to a worklist to be processed later. We also track when we reach the start and end of a context in which inline method bodies are deferred, so that we know when to replay the bodies. When suspending a function definition to be processed later, the `DeclNameStack` entry is moved to separate storage, including popping the corresponding scopes from the scope stack and removing the corresponding lexical names from lexical lookup. Later, when we return to the function and parse its definition, the `DeclNameStack` entry is restored. The same is done when we reach the end of a nested context that can have inline methods, so that we can reenter the nested scope before processing its members. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
d7fb1b287d
commit
f9ce0b194d
@@ -44,8 +44,8 @@ auto HandleFunctionSignatureFinish(Context& context) -> void {
|
||||
break;
|
||||
}
|
||||
case Lex::TokenKind::OpenCurlyBrace: {
|
||||
context.AddNode(NodeKind::FunctionDefinitionStart, context.Consume(),
|
||||
state.subtree_start, state.has_error);
|
||||
context.AddFunctionDefinitionStart(context.Consume(), state.subtree_start,
|
||||
state.has_error);
|
||||
// Any error is recorded on the FunctionDefinitionStart.
|
||||
state.has_error = false;
|
||||
context.PushState(state, State::FunctionDefinitionFinish);
|
||||
@@ -93,8 +93,8 @@ auto HandleFunctionSignatureFinish(Context& context) -> void {
|
||||
|
||||
auto HandleFunctionDefinitionFinish(Context& context) -> void {
|
||||
auto state = context.PopState();
|
||||
context.AddNode(NodeKind::FunctionDefinition, context.Consume(),
|
||||
state.subtree_start, state.has_error);
|
||||
context.AddFunctionDefinition(context.Consume(), state.subtree_start,
|
||||
state.has_error);
|
||||
}
|
||||
|
||||
} // namespace Carbon::Parse
|
||||
|
||||
Reference in New Issue
Block a user