mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Change how to get info for a parameter (#4366)
Updates `SemIR::Function::GetParamFromParamRefId` to return more information in the form of a new `ParamInfo` struct. This struct has a method for getting the `NameId` from the name binding instruction. The callers previously got it from the `Param` instruction, but the plan is for that instruction to no longer be associated with a name. --------- Co-authored-by: Josh L <josh11b@users.noreply.github.com> Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
co-authored by
Josh L
Geoff Romer
parent
568ad197d1
commit
82937e1a3c
@@ -43,20 +43,28 @@ auto GetCalleeFunction(const File& sem_ir, InstId callee_id) -> CalleeFunction {
|
||||
}
|
||||
|
||||
auto Function::GetParamFromParamRefId(const File& sem_ir, InstId param_ref_id)
|
||||
-> std::pair<InstId, Param> {
|
||||
-> ParamInfo {
|
||||
auto ref = sem_ir.insts().Get(param_ref_id);
|
||||
|
||||
if (auto addr_pattern = ref.TryAs<SemIR::AddrPattern>()) {
|
||||
if (auto addr_pattern = ref.TryAs<AddrPattern>()) {
|
||||
param_ref_id = addr_pattern->inner_id;
|
||||
ref = sem_ir.insts().Get(param_ref_id);
|
||||
}
|
||||
|
||||
if (auto bind_name = ref.TryAs<SemIR::AnyBindName>()) {
|
||||
auto bind_name = ref.TryAs<AnyBindName>();
|
||||
if (bind_name) {
|
||||
param_ref_id = bind_name->value_id;
|
||||
ref = sem_ir.insts().Get(param_ref_id);
|
||||
}
|
||||
return {param_ref_id, ref.As<Param>(), bind_name};
|
||||
}
|
||||
|
||||
return {param_ref_id, ref.As<SemIR::Param>()};
|
||||
auto Function::ParamInfo::GetNameId(const File& sem_ir) -> NameId {
|
||||
if (bind_name) {
|
||||
return sem_ir.entity_names().Get(bind_name->entity_name_id).name_id;
|
||||
} else {
|
||||
return NameId::Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
auto Function::GetDeclaredReturnType(const File& file,
|
||||
|
||||
Reference in New Issue
Block a user