mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
When performing impl lookup for `Core.Copy` for a C++ class type, look for a copy constructor. If we find one, synthesize an impl witness that calls the constructor. This adds initial support for impl lookup to delegate to the C++ interop logic for queries involving C++ types. For now, we don't implement the rules from #6166 that compare a synthesized type structure for the C++ impl against the best Carbon type structure, but the framework for building that support is established here. Currently there is no caching of the lookup here, and we build unique `ImplWitnessTable`s for each lookup, which leads to each impl lookup producing a distinct facet value. This results in some errors in generic contexts; this will be addressed in follow-up changes. This PR aims only to support the non-generic case. --------- Co-authored-by: Dana Jansens <danakj@orodu.net> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
37 lines
1.5 KiB
C++
37 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_CPP_OPERATORS_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_CPP_OPERATORS_H_
|
|
|
|
#include "toolchain/check/context.h"
|
|
#include "toolchain/check/operator.h"
|
|
#include "toolchain/sem_ir/ids.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// Looks up the given operator in the Clang AST generated when importing C++
|
|
// code using argument dependent lookup (ADL) and return overload set
|
|
// instruction.
|
|
auto LookupCppOperator(Context& context, SemIR::LocId loc_id, Operator op,
|
|
llvm::ArrayRef<SemIR::InstId> arg_ids) -> SemIR::InstId;
|
|
|
|
// Returns whether the decl is an operator member function.
|
|
auto IsCppOperatorMethodDecl(clang::Decl* decl) -> bool;
|
|
|
|
// Returns whether the specified instruction refers to a C++ overloaded operator
|
|
// that is a method. If so, the first operand will be passed as `self` rather
|
|
// than as the first argument.
|
|
auto IsCppOperatorMethod(Context& context, SemIR::InstId inst_id) -> bool;
|
|
|
|
// Returns whether the specified instruction refers to a C++ constructor or
|
|
// non-operator method. If so, when mapping from a Carbon interface to a C++
|
|
// call, we pass a `self` parameter as the first argument instead.
|
|
auto IsCppConstructorOrNonMethodOperator(Context& context,
|
|
SemIR::InstId inst_id) -> bool;
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_CPP_OPERATORS_H_
|