operator.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. std::optional<Context::BuildDiagnosticFn>
  22. missing_impl_diagnoser = std::nullopt)
  23. -> SemIR::InstId;
  24. // Checks and builds SemIR for a binary operator expression. For example,
  25. // `lhs_id * rhs_id`. If specified, `missing_impl_diagnoser` is used to build a
  26. // custom error diagnostic for the case where impl lookup for the operator
  27. // fails.
  28. auto BuildBinaryOperator(Context& context, SemIR::LocId loc_id, Operator op,
  29. SemIR::InstId lhs_id, SemIR::InstId rhs_id,
  30. std::optional<Context::BuildDiagnosticFn>
  31. missing_impl_diagnoser = std::nullopt)
  32. -> SemIR::InstId;
  33. } // namespace Carbon::Check
  34. #endif // CARBON_TOOLCHAIN_CHECK_OPERATOR_H_