name_ref.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/check/name_ref.h"
  5. #include "toolchain/check/inst.h"
  6. namespace Carbon::Check {
  7. auto BuildNameRef(Context& context, SemIR::LocId loc_id, SemIR::NameId name_id,
  8. SemIR::InstId inst_id, SemIR::SpecificId specific_id)
  9. -> SemIR::InstId {
  10. auto type_id =
  11. SemIR::GetTypeOfInstInSpecific(context.sem_ir(), specific_id, inst_id);
  12. CARBON_CHECK(type_id.has_value(), "Missing type for {0}",
  13. context.insts().Get(inst_id));
  14. // If the named entity has a constant value that depends on its specific,
  15. // store the specific too.
  16. if (specific_id.has_value() &&
  17. context.constant_values().Get(inst_id).is_symbolic()) {
  18. inst_id = AddInst<SemIR::SpecificConstant>(
  19. context, loc_id,
  20. {.type_id = type_id, .inst_id = inst_id, .specific_id = specific_id});
  21. }
  22. return AddInst<SemIR::NameRef>(
  23. context, loc_id,
  24. {.type_id = type_id, .name_id = name_id, .value_id = inst_id});
  25. }
  26. } // namespace Carbon::Check