Add interop support for complement and subscript operators. (#6576)

Also add the code to support interop with simple assignment. This
doesn't yet work because we don't support overloaded simple assignment
in general yet.
This commit is contained in:
Richard Smith
2026-01-10 07:50:00 +00:00
committed by GitHub
parent 6985ecb1d4
commit 87e588c334
2 changed files with 124 additions and 4 deletions
+23 -1
View File
@@ -29,6 +29,7 @@ static auto GetClangOperatorKind(Context& context, SemIR::LocId loc_id,
case CoreIdentifier::Destroy:
case CoreIdentifier::As:
case CoreIdentifier::ImplicitAs:
case CoreIdentifier::UnsafeAs:
case CoreIdentifier::Copy: {
// TODO: Support destructors and conversions.
return std::nullopt;
@@ -50,6 +51,12 @@ static auto GetClangOperatorKind(Context& context, SemIR::LocId loc_id,
return clang::OO_Minus;
}
// Bitwise.
case CoreIdentifier::BitComplement: {
CARBON_CHECK(op_name == CoreIdentifier::Op);
return clang::OO_Tilde;
}
// Binary operators.
// Arithmetic operators.
@@ -96,6 +103,14 @@ static auto GetClangOperatorKind(Context& context, SemIR::LocId loc_id,
return clang::OO_GreaterGreater;
}
// Assignment.
case CoreIdentifier::AssignWith: {
// TODO: This is not yet reached because we don't use the `AssignWith`
// interface for assignment yet.
CARBON_CHECK(op_name == CoreIdentifier::Op);
return clang::OO_Equal;
}
// Compound assignment arithmetic operators.
case CoreIdentifier::AddAssignWith: {
CARBON_CHECK(op_name == CoreIdentifier::Op);
@@ -163,10 +178,17 @@ static auto GetClangOperatorKind(Context& context, SemIR::LocId loc_id,
}
}
default:
// Array indexing.
case CoreIdentifier::IndexWith: {
CARBON_CHECK(op_name == CoreIdentifier::At);
return clang::OO_Subscript;
}
default: {
context.TODO(loc_id, llvm::formatv("Unsupported operator interface `{0}`",
interface_name));
return std::nullopt;
}
}
}