mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Remove CppGlobalVarStore (#7309)
Replace all uses of CppGlobalVarStore store with ClangDeclStore. Adding a VarStorage->VarDecl mapping to ClangDeclStore is now done with the `AddVar` method, which takes an extra `pattern_id` arg. While the corresponding `ClangDecl` is unchanged from before, the reverse mapping in `inst_id_to_clang_decl_id_` now uses the `pattern_id` as the key. This is necessary because in some places the original VarStorage instructions gets replaced (e.g. by a call to `Convert`). The `pattern_id` remains stable in those cases. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
d652cb0dfd
commit
1aa34d7642
@@ -2132,14 +2132,11 @@ static auto ImportVarDecl(Context& context, SemIR::LocId loc_id,
|
||||
.pattern_id = pattern_id}});
|
||||
context.imports().push_back(var_storage_inst_id);
|
||||
|
||||
// Register the variable so we don't create it again, and track the
|
||||
// corresponding declaration to use for mangling.
|
||||
auto clang_decl_id =
|
||||
context.clang_decls().Add({.key = SemIR::ClangDeclKey(var_decl),
|
||||
.inst_id = var_storage_inst_id,
|
||||
.is_imported = true});
|
||||
context.cpp_global_names().Add({.key = {.entity_name_id = entity_name_id},
|
||||
.clang_decl_id = clang_decl_id});
|
||||
// Register the variable so we don't create it again.
|
||||
context.clang_decls().AddVar({.key = SemIR::ClangDeclKey(var_decl),
|
||||
.inst_id = var_storage_inst_id,
|
||||
.is_imported = true},
|
||||
pattern_id);
|
||||
|
||||
// Inform Clang that the variable has been referenced.
|
||||
context.clang_sema().MarkVariableReferenced(GetCppLocation(context, loc_id),
|
||||
@@ -2640,15 +2637,8 @@ auto GetAsClangVarDecl(Context& context, SemIR::InstId inst_id)
|
||||
-> clang::VarDecl* {
|
||||
if (const auto& var_storage =
|
||||
context.insts().TryGetAs<SemIR::VarStorage>(inst_id)) {
|
||||
auto var_name_id = SemIR::GetFirstBindingNameFromPatternId(
|
||||
context.sem_ir(), var_storage->pattern_id);
|
||||
if (auto cpp_global_var_id = context.sem_ir().cpp_global_vars().Lookup(
|
||||
{.entity_name_id = var_name_id});
|
||||
cpp_global_var_id.has_value()) {
|
||||
SemIR::ClangDeclId clang_decl_id = context.sem_ir()
|
||||
.cpp_global_vars()
|
||||
.Get(cpp_global_var_id)
|
||||
.clang_decl_id;
|
||||
auto clang_decl_id = context.clang_decls().Lookup(var_storage->pattern_id);
|
||||
if (clang_decl_id.has_value()) {
|
||||
return cast<clang::VarDecl>(
|
||||
context.clang_decls().Get(clang_decl_id).key.decl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user