Files
carbon-lang/toolchain/check/operator.h
T
Richard SmithandJon Ross-Perkins 187a3608df Use As and ImplicitAs interfaces for conversions. (#4209)
Add these interfaces to the core library. For now, they're two separate
interfaces because we don't yet support one interface extending another.

This collapses a lot of the layering in check: for example, the call
building logic depends on implicit conversions, conversions now depend
on the overloaded operator machinery, and that machinery depends on
building calls.

In passing, improve the diagnostics for failing to find a name required
from the prelude. Also convert all the transitively-called code from
`NodeId` to `LocId` given the latter is what the conversion machinery
has available.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2024-09-05 23:39:58 +00:00

43 lines
1.7 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_CHECK_OPERATOR_H_
#define CARBON_TOOLCHAIN_CHECK_OPERATOR_H_
#include "toolchain/check/context.h"
#include "toolchain/parse/node_ids.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::Check {
struct Operator {
llvm::StringLiteral interface_name;
llvm::ArrayRef<SemIR::InstId> interface_args_ref = {};
llvm::StringLiteral op_name = "Op";
};
// Checks and builds SemIR for a unary operator expression. For example,
// `*operand` or `operand*`. If specified, `missing_impl_diagnoser` is used to
// build a custom error diagnostic for the case where impl lookup for the
// operator fails.
auto BuildUnaryOperator(Context& context, SemIR::LocId loc_id, Operator op,
SemIR::InstId operand_id,
std::optional<Context::BuildDiagnosticFn>
missing_impl_diagnoser = std::nullopt)
-> SemIR::InstId;
// Checks and builds SemIR for a binary operator expression. For example,
// `lhs_id * rhs_id`. If specified, `missing_impl_diagnoser` is used to build a
// custom error diagnostic for the case where impl lookup for the operator
// fails.
auto BuildBinaryOperator(Context& context, SemIR::LocId loc_id, Operator op,
SemIR::InstId lhs_id, SemIR::InstId rhs_id,
std::optional<Context::BuildDiagnosticFn>
missing_impl_diagnoser = std::nullopt)
-> SemIR::InstId;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_OPERATOR_H_