mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:54:41 +01:00
Rename enclosing scope to parent scope (#4020)
Following up on discussion from #3948, doing a general rename of "enclosing scope" to "parent scope" (and "enclosing scopes" to "ancestor scopes"). The intent is to improve understandability and collide less with C++ terminology for "enclosing scope". Note this changes most uses of "enclosing", but leaves behind a few like "enclosing function" and "enclosing block". Note this does create some "parent class" mentions for "adapt" and "var" (the class they're within), which is maybe unfortunate, but we'd probably say "base class" if we meant inheritance so perhaps that's okay. Along the same lines, these are the only `parent_class` uses I see now, and we do have a few `base_class`.
This commit is contained in:
@@ -69,9 +69,9 @@ static auto TryAsClassScope(Context& context, SemIR::NameScopeId scope_id)
|
||||
}
|
||||
|
||||
static auto GetDefaultSelfType(Context& context) -> SemIR::TypeId {
|
||||
auto enclosing_scope_id = context.decl_name_stack().PeekEnclosingScopeId();
|
||||
auto parent_scope_id = context.decl_name_stack().PeekParentScopeId();
|
||||
|
||||
if (auto class_decl = TryAsClassScope(context, enclosing_scope_id)) {
|
||||
if (auto class_decl = TryAsClassScope(context, parent_scope_id)) {
|
||||
return context.classes().Get(class_decl->class_id).self_type_id;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ auto HandleDefaultSelfImplAs(Context& context,
|
||||
}
|
||||
|
||||
// There's no need to push `Self` into scope here, because we can find it in
|
||||
// the enclosing class scope.
|
||||
// the parent class scope.
|
||||
context.node_stack().Push(node_id, self_type_id);
|
||||
return true;
|
||||
}
|
||||
@@ -103,11 +103,11 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node,
|
||||
Parse::NodeId self_type_node, SemIR::TypeId self_type_id,
|
||||
Parse::NodeId params_node, SemIR::TypeId constraint_id)
|
||||
-> void {
|
||||
auto enclosing_scope_id = context.decl_name_stack().PeekEnclosingScopeId();
|
||||
auto& enclosing_scope = context.name_scopes().Get(enclosing_scope_id);
|
||||
auto parent_scope_id = context.decl_name_stack().PeekParentScopeId();
|
||||
auto& parent_scope = context.name_scopes().Get(parent_scope_id);
|
||||
|
||||
// TODO: This is also valid in a mixin.
|
||||
if (!TryAsClassScope(context, enclosing_scope_id)) {
|
||||
if (!TryAsClassScope(context, parent_scope_id)) {
|
||||
CARBON_DIAGNOSTIC(ExtendImplOutsideClass, Error,
|
||||
"`extend impl` can only be used in a class.");
|
||||
context.emitter().Emit(node_id, ExtendImplOutsideClass);
|
||||
@@ -118,7 +118,7 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node,
|
||||
CARBON_DIAGNOSTIC(ExtendImplForall, Error,
|
||||
"Cannot `extend` a parameterized `impl`.");
|
||||
context.emitter().Emit(extend_node, ExtendImplForall);
|
||||
enclosing_scope.has_error = true;
|
||||
parent_scope.has_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node,
|
||||
// If the explicit self type is not the default, just bail out.
|
||||
if (self_type_id != GetDefaultSelfType(context)) {
|
||||
diag.Emit();
|
||||
enclosing_scope.has_error = true;
|
||||
parent_scope.has_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node,
|
||||
context.types().TryGetAs<SemIR::InterfaceType>(constraint_id);
|
||||
if (!interface_type) {
|
||||
context.TODO(node_id, "extending non-interface constraint");
|
||||
enclosing_scope.has_error = true;
|
||||
parent_scope.has_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -164,11 +164,11 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node,
|
||||
constraint_id);
|
||||
context.NoteUndefinedInterface(interface_type->interface_id, diag);
|
||||
diag.Emit();
|
||||
enclosing_scope.has_error = true;
|
||||
parent_scope.has_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
enclosing_scope.extended_scopes.push_back(interface.scope_id);
|
||||
parent_scope.extended_scopes.push_back(interface.scope_id);
|
||||
}
|
||||
|
||||
// Build an ImplDecl describing the signature of an impl. This handles the
|
||||
@@ -252,7 +252,7 @@ auto HandleImplDefinitionStart(Context& context,
|
||||
impl_info.definition_id = impl_decl_id;
|
||||
impl_info.scope_id = context.name_scopes().Add(
|
||||
impl_decl_id, SemIR::NameId::Invalid,
|
||||
context.decl_name_stack().PeekEnclosingScopeId());
|
||||
context.decl_name_stack().PeekParentScopeId());
|
||||
}
|
||||
|
||||
context.scope_stack().Push(impl_decl_id, impl_info.scope_id);
|
||||
|
||||
Reference in New Issue
Block a user