mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Add specific_id and pattern_inst_id to ClangDecl (#7583)
Exporting class fields in class specifics will require looking up `ClangDecl`s by the field's `InstId` and the class's `SpecificId`. Add the `specific_id` to ClangeDecl, and rework the reverse lookup to use a `Set` with a `KeyContext` rather than a `Map`. The `Lookup` method now takes an optional `SpecificId` argument, although currently it is always `None`. For `VarStorage`, reverse lookup is performed by the pattern `InstId` rather than the `InstId` of the `VarStorage` itself, so also add `pattern_inst_id` to `ClangDecl`, and provide a separate `LookupByPatternInstId` method for reverse lookups. For this lookup, the `inst_id` part of the key is set to `None`, so only the pattern's `InstId` is used for lookup.
This commit is contained in:
@@ -441,7 +441,12 @@ static auto LookupClangDeclInstId(Context& context, SemIR::ClangDeclKey key)
|
||||
const auto& clang_decls = context.clang_decls();
|
||||
if (auto context_clang_decl_id = clang_decls.LookupId(key);
|
||||
context_clang_decl_id.has_value()) {
|
||||
return clang_decls.Get(context_clang_decl_id).inst_id;
|
||||
const auto& clang_decl = clang_decls.Get(context_clang_decl_id);
|
||||
if (clang_decl.var_storage_inst_id.has_value()) {
|
||||
return clang_decl.var_storage_inst_id;
|
||||
} else {
|
||||
return clang_decls.Get(context_clang_decl_id).inst_id;
|
||||
}
|
||||
}
|
||||
return SemIR::InstId::None;
|
||||
}
|
||||
@@ -2143,10 +2148,10 @@ static auto ImportVarDecl(Context& context, SemIR::LocId loc_id,
|
||||
context.imports().push_back(var_storage_inst_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);
|
||||
context.clang_decls().Add({.key = SemIR::ClangDeclKey(var_decl),
|
||||
.inst_id = pattern_id,
|
||||
.var_storage_inst_id = var_storage_inst_id,
|
||||
.is_imported = true});
|
||||
|
||||
// Inform Clang that the variable has been referenced.
|
||||
context.clang_sema().MarkVariableReferenced(GetCppLocation(context, loc_id),
|
||||
|
||||
Reference in New Issue
Block a user