call.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #ifndef CARBON_TOOLCHAIN_CHECK_CPP_CALL_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CPP_CALL_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // Converts a call argument list into a Clang template argument list for a given
  10. // template. Returns true on success, or false if an error was diagnosed.
  11. //
  12. // If `diagnose` is false, errors will be suppressed.
  13. auto ConvertArgsToTemplateArgs(Context& context,
  14. clang::TemplateDecl* template_decl,
  15. llvm::ArrayRef<SemIR::InstId> arg_ids,
  16. clang::TemplateArgumentListInfo& arg_list,
  17. bool diagnose = true) -> bool;
  18. // Checks and builds SemIR for a call to a C++ function in the given overload
  19. // set with self `self_id` and arguments `arg_ids`. `is_desugared`
  20. // indicates that this call was was produced by desugaring, not written as a
  21. // function call in user code, so arguments to `ref` parameters aren't required
  22. // to have `ref` tags.
  23. //
  24. // Chooses the best viable C++ function by performing Clang overloading
  25. // resolution over the overload set.
  26. //
  27. // Preserves the given self, if set. If not set, and the function is a C++
  28. // member operator, self will be set to the first argument, which in turn will
  29. // be removed from the given args.
  30. //
  31. // A set with a single non-templated function goes through the same rules for
  32. // overloading resolution. This is to make sure that calls that have no viable
  33. // implicit conversion sequence are rejected even when an implicit conversion is
  34. // possible. Keeping the same behavior here for consistency and supporting
  35. // migrations so that the migrated callers from C++ remain valid.
  36. auto PerformCallToCppFunction(Context& context, SemIR::LocId loc_id,
  37. SemIR::CppOverloadSetId overload_set_id,
  38. SemIR::InstId self_id,
  39. llvm::ArrayRef<SemIR::InstId> arg_ids,
  40. bool is_desugared) -> SemIR::InstId;
  41. // Checks and builds SemIR for a call to a C++ template name with arguments
  42. // `arg_ids`.
  43. //
  44. // Converts the arguments to a C++ template argument list and attempts to
  45. // instantiate a template specialization and import a declaration of it.
  46. auto PerformCallToCppTemplateName(Context& context, SemIR::LocId loc_id,
  47. SemIR::ClangDeclId template_decl_id,
  48. llvm::ArrayRef<SemIR::InstId> arg_ids)
  49. -> SemIR::InstId;
  50. } // namespace Carbon::Check
  51. #endif // CARBON_TOOLCHAIN_CHECK_CPP_CALL_H_