mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 18:51:09 +01:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user