operator.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_OPERATOR_H_
  5. #define CARBON_TOOLCHAIN_CHECK_OPERATOR_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/check/core_identifier.h"
  8. #include "toolchain/parse/node_ids.h"
  9. #include "toolchain/sem_ir/ids.h"
  10. namespace Carbon::Check {
  11. struct Operator {
  12. CoreIdentifier interface_name;
  13. llvm::ArrayRef<SemIR::InstId> interface_args_ref = {};
  14. CoreIdentifier op_name = CoreIdentifier::Op;
  15. };
  16. // Checks and builds SemIR for a unary operator expression. For example,
  17. // `*operand` or `operand*`.
  18. //
  19. // On failure, an ErrorInst is returned and a diagnostic is produced unless
  20. // `diagnose` is false. It is incorrect to specify `diagnose` as false if the
  21. // resulting ErrorInst may appear in the produced SemIR.
  22. //
  23. // If specified, `missing_impl_diagnostic_context` is used to provide context
  24. // for the diagnostic if the impl lookup for the operator fails.
  25. auto BuildUnaryOperator(Context& context, SemIR::LocId loc_id, Operator op,
  26. SemIR::InstId operand_id, bool diagnose = true,
  27. DiagnosticContextFn missing_impl_diagnostic_context =
  28. nullptr) -> SemIR::InstId;
  29. // Checks and builds SemIR for a binary operator expression. For example,
  30. // `lhs_id * rhs_id`.
  31. //
  32. // // On failure, an ErrorInst is returned and a diagnostic is produced unless
  33. // `diagnose` is false. It is incorrect to specify `diagnose` as false if the
  34. // resulting ErrorInst may appear in the produced SemIR.
  35. //
  36. // If specified, `missing_impl_diagnostic_context` is used to provide context
  37. // for the diagnostic if the impl lookup for the operator fails.
  38. auto BuildBinaryOperator(
  39. Context& context, SemIR::LocId loc_id, Operator op, SemIR::InstId lhs_id,
  40. SemIR::InstId rhs_id, bool diagnose = true,
  41. DiagnosticContextFn missing_impl_diagnostic_context = nullptr)
  42. -> SemIR::InstId;
  43. } // namespace Carbon::Check
  44. #endif // CARBON_TOOLCHAIN_CHECK_OPERATOR_H_