operators.h 2.0 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. #ifndef CARBON_TOOLCHAIN_CHECK_CPP_OPERATORS_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CPP_OPERATORS_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/check/operator.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::Check {
  10. // Looks up the given operator in the Clang AST generated when importing C++
  11. // code using argument dependent lookup (ADL) and return overload set
  12. // instruction.
  13. auto LookupCppOperator(Context& context, SemIR::LocId loc_id, Operator op,
  14. llvm::ArrayRef<SemIR::InstId> arg_ids) -> SemIR::InstId;
  15. // Looks up the given operator in the Clang AST generated when importing C++
  16. // code using argument dependent lookup (ADL) and return overload set
  17. // instruction.
  18. //
  19. // This overload synthesises objects in an unevaluated context within the Clang
  20. // AST based on the types it is provided.
  21. auto LookupCppOperator(Context& context, SemIR::LocId loc_id, Operator op,
  22. llvm::ArrayRef<SemIR::TypeId> arg_type_ids)
  23. -> SemIR::InstId;
  24. // Returns whether the decl is an operator member function.
  25. auto IsCppOperatorMethodDecl(clang::Decl* decl) -> bool;
  26. // Returns whether the specified instruction refers to a C++ overloaded operator
  27. // that is a method. If so, the first operand will be passed as `self` rather
  28. // than as the first argument.
  29. auto IsCppOperatorMethod(Context& context, SemIR::InstId inst_id) -> bool;
  30. // Returns whether the specified instruction refers to a C++ constructor or
  31. // non-operator method. If so, when mapping from a Carbon interface to a C++
  32. // call, we pass a `self` parameter as the first argument instead.
  33. auto IsCppConstructorOrNonMethodOperator(Context& context,
  34. SemIR::InstId inst_id) -> bool;
  35. } // namespace Carbon::Check
  36. #endif // CARBON_TOOLCHAIN_CHECK_CPP_OPERATORS_H_