Files
carbon-lang/toolchain/check/operator.h
T
Jon Ross-Perkins c0b335b87f Add well-known identifier caching (#6486)
I'm doing this because I figured it'd be an incremental improvement for
all the operator lookups that we do. Even to the extent that we've
discussed witness caching, I think it'll still apply. It does add one
more step to adding new interfaces (before, you'd just write the string,
now you add it to the def file and reference it).

I'll claim it makes GetClangOperatorKind a lot friendlier to read/edit,
nevermind removing the string comparisons. :)
2025-12-11 21:41:47 +00:00

42 lines
1.5 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/check/core_identifier.h"
#include "toolchain/parse/node_ids.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::Check {
struct Operator {
CoreIdentifier interface_name;
llvm::ArrayRef<SemIR::InstId> interface_args_ref = {};
CoreIdentifier op_name = CoreIdentifier::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,
MakeDiagnosticBuilderFn missing_impl_diagnoser = nullptr) -> 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,
MakeDiagnosticBuilderFn missing_impl_diagnoser = nullptr) -> SemIR::InstId;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_OPERATOR_H_