operator.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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/parse/node_ids.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::Check {
  10. struct Operator {
  11. llvm::StringLiteral interface_name;
  12. llvm::ArrayRef<SemIR::InstId> interface_args_ref = {};
  13. llvm::StringLiteral op_name = "Op";
  14. };
  15. // Checks and builds SemIR for a unary operator expression. For example,
  16. // `*operand` or `operand*`. If specified, `missing_impl_diagnoser` is used to
  17. // build a custom error diagnostic for the case where impl lookup for the
  18. // operator fails.
  19. auto BuildUnaryOperator(Context& context, SemIR::LocId loc_id, Operator op,
  20. SemIR::InstId operand_id,
  21. Context::BuildDiagnosticFn missing_impl_diagnoser =
  22. nullptr) -> SemIR::InstId;
  23. // Checks and builds SemIR for a binary operator expression. For example,
  24. // `lhs_id * rhs_id`. If specified, `missing_impl_diagnoser` is used to build a
  25. // custom error diagnostic for the case where impl lookup for the operator
  26. // fails.
  27. auto BuildBinaryOperator(Context& context, SemIR::LocId loc_id, Operator op,
  28. SemIR::InstId lhs_id, SemIR::InstId rhs_id,
  29. Context::BuildDiagnosticFn missing_impl_diagnoser =
  30. nullptr) -> SemIR::InstId;
  31. } // namespace Carbon::Check
  32. #endif // CARBON_TOOLCHAIN_CHECK_OPERATOR_H_