mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 13:55:53 +01:00
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:
@@ -245,20 +245,19 @@ struct CalleeFunctionInfo {
|
||||
|
||||
auto IsCppThunkRequired(Context& context, const SemIR::Function& function)
|
||||
-> bool {
|
||||
auto clang_decl_id = context.clang_decls().Lookup(function.first_decl_id());
|
||||
if (!clang_decl_id.has_value()) {
|
||||
const auto* clang_decl =
|
||||
context.clang_decls().Lookup(function.first_decl_id());
|
||||
if (!clang_decl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& decl_info = context.clang_decls().Get(clang_decl_id);
|
||||
|
||||
if (!decl_info.is_imported) {
|
||||
if (!clang_decl->is_imported) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& signature =
|
||||
context.clang_decl_signatures().Get(decl_info.key.signature_id);
|
||||
auto* decl = cast<clang::FunctionDecl>(decl_info.key.decl);
|
||||
context.clang_decl_signatures().Get(clang_decl->key.signature_id);
|
||||
auto* decl = cast<clang::FunctionDecl>(clang_decl->decl());
|
||||
if (signature.kind != SemIR::ClangDeclSignature::Normal ||
|
||||
signature.num_params != static_cast<int>(decl->getNumNonObjectParams())) {
|
||||
// We require a thunk if the number of parameters we want isn't all of them.
|
||||
@@ -652,9 +651,7 @@ static auto BuildThunkBody(CppContext& cpp_context, clang::Sema& sema,
|
||||
auto BuildCppThunk(Context& context, const SemIR::Function& callee_function)
|
||||
-> clang::FunctionDecl* {
|
||||
auto clang_decl_key =
|
||||
context.clang_decls()
|
||||
.Get(context.clang_decls().Lookup(callee_function.first_decl_id()))
|
||||
.key;
|
||||
context.clang_decls().Lookup(callee_function.first_decl_id())->key;
|
||||
clang::FunctionDecl* callee_function_decl =
|
||||
clang_decl_key.decl->getAsFunction();
|
||||
CARBON_CHECK(callee_function_decl);
|
||||
|
||||
Reference in New Issue
Block a user