mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +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:
@@ -219,13 +219,11 @@ static auto ConvertArgToExpr(Context& context, SemIR::InstId arg_inst_id,
|
||||
}
|
||||
|
||||
auto EvalCppCall(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::ClangDeclId clang_decl_id, SemIR::InstBlockId args_id)
|
||||
const SemIR::ClangDecl& clang_decl, SemIR::InstBlockId args_id)
|
||||
-> SemIR::ConstantId {
|
||||
const auto& args = context.inst_blocks().Get(args_id);
|
||||
|
||||
auto* decl = context.clang_decls().Get(clang_decl_id).GetAsKey().decl;
|
||||
|
||||
auto* function_decl = cast<clang::FunctionDecl>(decl);
|
||||
auto* function_decl = cast<clang::FunctionDecl>(clang_decl.decl());
|
||||
|
||||
// Create expr for the function declaration.
|
||||
auto* decl_ref_expr = clang::DeclRefExpr::Create(
|
||||
@@ -305,10 +303,8 @@ auto MaybeModifyCppThunkCallForConstEval(Context& context, SemIR::Call* call)
|
||||
|
||||
function_decl = cast<clang::FunctionDecl>(
|
||||
context.clang_decls()
|
||||
.Get(context.clang_decls().Lookup(
|
||||
thunk_callee_function.first_decl_id()))
|
||||
.GetAsKey()
|
||||
.decl);
|
||||
.Lookup(thunk_callee_function.first_decl_id())
|
||||
->decl());
|
||||
|
||||
if (!(function_decl->isConstexpr() || function_decl->isConsteval())) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user