|
10 | 10 | #include "toolchain/base/kind_switch.h"
|
11 | 11 | #include "toolchain/check/cpp/import.h"
|
12 | 12 | #include "toolchain/check/cpp/location.h"
|
| 13 | +#include "toolchain/check/cpp/operators.h" |
13 | 14 | #include "toolchain/check/cpp/type_mapping.h"
|
14 | 15 | #include "toolchain/check/member_access.h"
|
15 | 16 | #include "toolchain/check/name_lookup.h"
|
@@ -116,18 +117,10 @@ static auto CheckOverloadAccess(Context& context, SemIR::LocId loc_id,
|
116 | 117 | .highest_allowed_access = allowed_access_kind});
|
117 | 118 | }
|
118 | 119 |
|
119 |
| -// Returns whether the decl is an operator member function. |
120 |
| -static auto IsOperatorMethodDecl(clang::Decl* decl) -> bool { |
121 |
| - auto* clang_method_decl = dyn_cast<clang::CXXMethodDecl>(decl); |
122 |
| - return clang_method_decl && clang_method_decl->isOverloadedOperator(); |
123 |
| -} |
124 |
| - |
125 |
| -// Resolve which function to call, or returns an error instruction if overload |
126 |
| -// resolution failed. |
127 |
| -static auto ResolveCalleeId(Context& context, SemIR::LocId loc_id, |
128 |
| - SemIR::CppOverloadSetId overload_set_id, |
129 |
| - SemIR::InstId self_id, |
130 |
| - llvm::ArrayRef<SemIR::InstId> arg_ids) |
| 120 | +auto PerformCppOverloadResolution(Context& context, SemIR::LocId loc_id, |
| 121 | + SemIR::CppOverloadSetId overload_set_id, |
| 122 | + SemIR::InstId self_id, |
| 123 | + llvm::ArrayRef<SemIR::InstId> arg_ids) |
131 | 124 | -> SemIR::InstId {
|
132 | 125 | // Register an annotation scope to flush any Clang diagnostics when we return.
|
133 | 126 | // This is important to ensure that Clang diagnostics are properly interleaved
|
@@ -177,7 +170,7 @@ static auto ResolveCalleeId(Context& context, SemIR::LocId loc_id,
|
177 | 170 | context, loc_id, best_viable_fn->Function,
|
178 | 171 | // If this is an operator method, the first arg will be used as self.
|
179 | 172 | arg_exprs.size() -
|
180 |
| - (IsOperatorMethodDecl(best_viable_fn->Function) ? 1 : 0)); |
| 173 | + (IsCppOperatorMethodDecl(best_viable_fn->Function) ? 1 : 0)); |
181 | 174 | CheckOverloadAccess(context, loc_id, overload_set,
|
182 | 175 | best_viable_fn->FoundDecl, result_id);
|
183 | 176 | return result_id;
|
@@ -208,50 +201,4 @@ static auto ResolveCalleeId(Context& context, SemIR::LocId loc_id,
|
208 | 201 | }
|
209 | 202 | }
|
210 | 203 |
|
211 |
| -// Returns whether the function is an imported C++ operator member function. |
212 |
| -static auto IsCppOperatorMethod(Context& context, SemIR::FunctionId function_id) |
213 |
| - -> bool { |
214 |
| - SemIR::ClangDeclId clang_decl_id = |
215 |
| - context.functions().Get(function_id).clang_decl_id; |
216 |
| - return clang_decl_id.has_value() && |
217 |
| - IsOperatorMethodDecl( |
218 |
| - context.clang_decls().Get(clang_decl_id).key.decl); |
219 |
| -} |
220 |
| - |
221 |
| -auto PerformCppOverloadResolution(Context& context, SemIR::LocId loc_id, |
222 |
| - SemIR::CppOverloadSetId overload_set_id, |
223 |
| - SemIR::InstId self_id, |
224 |
| - llvm::ArrayRef<SemIR::InstId> arg_ids) |
225 |
| - -> CppOverloadResolutionResult { |
226 |
| - CppOverloadResolutionResult result = { |
227 |
| - .callee_id = |
228 |
| - ResolveCalleeId(context, loc_id, overload_set_id, self_id, arg_ids), |
229 |
| - .arg_ids = arg_ids}; |
230 |
| - SemIR::Callee callee = GetCallee(context.sem_ir(), result.callee_id); |
231 |
| - CARBON_KIND_SWITCH(callee) { |
232 |
| - case CARBON_KIND(SemIR::CalleeError _): { |
233 |
| - result.callee_id = SemIR::ErrorInst::InstId; |
234 |
| - return result; |
235 |
| - } |
236 |
| - case CARBON_KIND(SemIR::CalleeFunction fn): { |
237 |
| - CARBON_CHECK(!fn.self_id.has_value()); |
238 |
| - if (self_id.has_value()) { |
239 |
| - // Preserve the `self` argument from the original callee. |
240 |
| - fn.self_id = self_id; |
241 |
| - } else if (IsCppOperatorMethod(context, fn.function_id)) { |
242 |
| - // Adjust `self` and args for C++ overloaded operator methods. |
243 |
| - fn.self_id = result.arg_ids.consume_front(); |
244 |
| - } |
245 |
| - result.callee_function = fn; |
246 |
| - return result; |
247 |
| - } |
248 |
| - case CARBON_KIND(SemIR::CalleeCppOverloadSet _): { |
249 |
| - CARBON_FATAL("overloads can't be recursive"); |
250 |
| - } |
251 |
| - case CARBON_KIND(SemIR::CalleeNonFunction _): { |
252 |
| - CARBON_FATAL("overloads should produce functions"); |
253 |
| - } |
254 |
| - } |
255 |
| -} |
256 |
| - |
257 | 204 | } // namespace Carbon::Check
|
0 commit comments