call.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/cpp/call.h"
  5. #include "toolchain/base/kind_switch.h"
  6. #include "toolchain/check/call.h"
  7. #include "toolchain/check/cpp/operators.h"
  8. #include "toolchain/check/cpp/overload_resolution.h"
  9. #include "toolchain/sem_ir/function.h"
  10. #include "toolchain/sem_ir/ids.h"
  11. #include "toolchain/sem_ir/typed_insts.h"
  12. namespace Carbon::Check {
  13. auto PerformCallToCppFunction(Context& context, SemIR::LocId loc_id,
  14. SemIR::CppOverloadSetId overload_set_id,
  15. SemIR::InstId self_id,
  16. llvm::ArrayRef<SemIR::InstId> arg_ids)
  17. -> SemIR::InstId {
  18. SemIR::InstId callee_id = PerformCppOverloadResolution(
  19. context, loc_id, overload_set_id, self_id, arg_ids);
  20. SemIR::Callee callee = GetCallee(context.sem_ir(), callee_id);
  21. CARBON_KIND_SWITCH(callee) {
  22. case CARBON_KIND(SemIR::CalleeError _): {
  23. return SemIR::ErrorInst::InstId;
  24. }
  25. case CARBON_KIND(SemIR::CalleeFunction fn): {
  26. CARBON_CHECK(!fn.self_id.has_value());
  27. if (self_id.has_value()) {
  28. // Preserve the `self` argument from the original callee.
  29. fn.self_id = self_id;
  30. }
  31. return PerformCallToFunction(context, loc_id, callee_id, fn, arg_ids);
  32. }
  33. case CARBON_KIND(SemIR::CalleeCppOverloadSet _): {
  34. CARBON_FATAL("overloads can't be recursive");
  35. }
  36. case CARBON_KIND(SemIR::CalleeNonFunction _): {
  37. CARBON_FATAL("overloads should produce functions");
  38. }
  39. }
  40. }
  41. } // namespace Carbon::Check