Improve ClangDeclStore ergonomics (#7311)

Change `Lookup` by InstId to return a ClangDecl pointer. All callers
were immediately calling `Get` anyway, so this makes call sites a little
shorter. The other `Lookup` method, by ClangDeclKey, is sometimes called
without calling `Get`, so left that as-is, but renamed to `LookupId`.

Also add a `decl` method to ClangDecl so that the commonly repeated
`clang_decl->key.decl` can be written `clang_decl->decl()`.
This commit is contained in:
Nicholas Bishop
2026-06-05 20:49:34 +00:00
committed by GitHub
parent 44b17ff436
commit 5e62791ad2
16 changed files with 70 additions and 95 deletions
+3 -5
View File
@@ -732,12 +732,10 @@ static auto GetAsCppFunctionDecl(Context& context, SemIR::InstId inst_id)
if (!function_type) {
return nullptr;
}
SemIR::ClangDeclId clang_decl_id = context.clang_decls().Lookup(
const auto* clang_decl = context.clang_decls().Lookup(
context.functions().Get(function_type->function_id).first_decl_id());
return clang_decl_id.has_value()
? dyn_cast<clang::FunctionDecl>(
context.clang_decls().Get(clang_decl_id).key.decl)
: nullptr;
return clang_decl ? dyn_cast<clang::FunctionDecl>(clang_decl->decl())
: nullptr;
}
auto IsCppOperatorMethod(Context& context, SemIR::InstId inst_id) -> bool {