mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
[NFC] Convert NameScope from struct to class (#4623)
This is a preparation change for adding name poisoning support (https://github.com/carbon-language/carbon-lang/issues/4622), which is expected to require more elaborate logic around NameScope since a name can be not defined yet, defined, or poisoned. The API separates looking up a name from getting the full entry since we have cases where the entries are invalidated between the time we're looking for the name and when we access (and sometimes modify) the entry. This change has the following benefits: * `names` and `name_map` are internal to `NameScope` and are guaranteed to match. * `extended_scopes` and `import_ir_scopes` can not be manipulated (only new scopes can be added). * `inst_id`, `name_id` and `parent_scope_id` are constants. * `has_error` can only be mutated from false to true. --------- Co-authored-by: jonmeow <jperkins@google.com>
This commit is contained in:
@@ -410,7 +410,7 @@ auto HandleParseNode(Context& context, Parse::AdaptDeclId node_id) -> bool {
|
||||
// Extend the class scope with the adapted type's scope if requested.
|
||||
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Extend)) {
|
||||
auto& class_scope = context.name_scopes().Get(class_info.scope_id);
|
||||
class_scope.extended_scopes.push_back(adapted_inst_id);
|
||||
class_scope.AddExtendedScope(adapted_inst_id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -555,9 +555,9 @@ auto HandleParseNode(Context& context, Parse::BaseDeclId node_id) -> bool {
|
||||
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Extend)) {
|
||||
auto& class_scope = context.name_scopes().Get(class_info.scope_id);
|
||||
if (base_info.scope_id.is_valid()) {
|
||||
class_scope.extended_scopes.push_back(base_info.inst_id);
|
||||
class_scope.AddExtendedScope(base_info.inst_id);
|
||||
} else {
|
||||
class_scope.has_error = true;
|
||||
class_scope.set_has_error();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user