mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Previously, we created scopes for implicit parameter lists and tuple
patterns, but that meant that bindings went out of scope too soon. We
now keep them in scope until the end of the enclosing declaration. This
is accomplished by pushing a scope for parameters when we handle a name
that might have them, and then popping the scope again if it turns out
that there were no parameters.
For a case such as:
```carbon
fn A(T:! type).B(U:! type).F(x: T, y: U) {
var z: T;
}
```
... we now have the following scopes in the stack:
- A parameter scope containing `T`.
- A class scope for `A(T:! type)`.
- A parameter scope containing `U`.
- A class scope for `A(T:! type).B(U:! type)`.
- A parameter scope containing `x: T` and `y: U`.
- A function body scope containing `z: T`.
The innermost scope when check processes a declaration of a function,
class, or similar is now often a parameter scope rather than the
enclosing scope in which the class or function is declared, so the
target scope is now passed explicitly into the modifier checking code
that wants to inspect that enclosing scope.
51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "toolchain/check/context.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
auto HandleImplicitParamListStart(Context& context,
|
|
Parse::ImplicitParamListStartId parse_node)
|
|
-> bool {
|
|
context.node_stack().Push(parse_node);
|
|
context.ParamOrArgStart();
|
|
return true;
|
|
}
|
|
|
|
auto HandleImplicitParamList(Context& context,
|
|
Parse::ImplicitParamListId parse_node) -> bool {
|
|
auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::ImplicitParamListStart);
|
|
context.node_stack()
|
|
.PopAndDiscardSoloParseNode<Parse::NodeKind::ImplicitParamListStart>();
|
|
context.node_stack().Push(parse_node, refs_id);
|
|
// The implicit parameter list's scope extends to the end of the following
|
|
// parameter list.
|
|
return true;
|
|
}
|
|
|
|
auto HandleTuplePatternStart(Context& context,
|
|
Parse::TuplePatternStartId parse_node) -> bool {
|
|
context.node_stack().Push(parse_node);
|
|
context.ParamOrArgStart();
|
|
return true;
|
|
}
|
|
|
|
auto HandlePatternListComma(Context& context,
|
|
Parse::PatternListCommaId /*parse_node*/) -> bool {
|
|
context.ParamOrArgComma();
|
|
return true;
|
|
}
|
|
|
|
auto HandleTuplePattern(Context& context, Parse::TuplePatternId parse_node)
|
|
-> bool {
|
|
auto refs_id = context.ParamOrArgEnd(Parse::NodeKind::TuplePatternStart);
|
|
context.node_stack()
|
|
.PopAndDiscardSoloParseNode<Parse::NodeKind::TuplePatternStart>();
|
|
context.node_stack().Push(parse_node, refs_id);
|
|
return true;
|
|
}
|
|
|
|
} // namespace Carbon::Check
|