@@ -2017,12 +2017,114 @@ auto ImportNameFromCpp(Context& context, SemIR::LocId loc_id,
2017
2017
access);
2018
2018
}
2019
2019
2020
- static auto GetOperatorKind (Context& context, SemIR::LocId loc_id,
2021
- llvm::StringLiteral interface_name)
2020
+ static auto GetClangOperatorKind (Context& context, SemIR::LocId loc_id,
2021
+ llvm::StringLiteral interface_name,
2022
+ llvm::StringLiteral op_name)
2022
2023
-> std::optional<clang::OverloadedOperatorKind> {
2024
+ // Arithmetic Operators.
2023
2025
if (interface_name == " AddWith" ) {
2026
+ CARBON_CHECK (op_name == " Op" );
2024
2027
return clang::OO_Plus;
2025
2028
}
2029
+ if (interface_name == " SubWith" ) {
2030
+ CARBON_CHECK (op_name == " Op" );
2031
+ return clang::OO_Minus;
2032
+ }
2033
+ if (interface_name == " MulWith" ) {
2034
+ CARBON_CHECK (op_name == " Op" );
2035
+ return clang::OO_Star;
2036
+ }
2037
+ if (interface_name == " DivWith" ) {
2038
+ CARBON_CHECK (op_name == " Op" );
2039
+ return clang::OO_Slash;
2040
+ }
2041
+ if (interface_name == " ModWith" ) {
2042
+ CARBON_CHECK (op_name == " Op" );
2043
+ return clang::OO_Percent;
2044
+ }
2045
+
2046
+ // Bitwise Operators.
2047
+ if (interface_name == " BitAndWith" ) {
2048
+ CARBON_CHECK (op_name == " Op" );
2049
+ return clang::OO_Amp;
2050
+ }
2051
+ if (interface_name == " BitOrWith" ) {
2052
+ CARBON_CHECK (op_name == " Op" );
2053
+ return clang::OO_Pipe;
2054
+ }
2055
+ if (interface_name == " BitXorWith" ) {
2056
+ CARBON_CHECK (op_name == " Op" );
2057
+ return clang::OO_Caret;
2058
+ }
2059
+ if (interface_name == " LeftShiftWith" ) {
2060
+ CARBON_CHECK (op_name == " Op" );
2061
+ return clang::OO_LessLess;
2062
+ }
2063
+ if (interface_name == " RightShiftWith" ) {
2064
+ CARBON_CHECK (op_name == " Op" );
2065
+ return clang::OO_GreaterGreater;
2066
+ }
2067
+
2068
+ // Compound Assignment Arithmetic Operators.
2069
+ if (interface_name == " AddAssignWith" ) {
2070
+ CARBON_CHECK (op_name == " Op" );
2071
+ return clang::OO_PlusEqual;
2072
+ }
2073
+ if (interface_name == " SubAssignWith" ) {
2074
+ CARBON_CHECK (op_name == " Op" );
2075
+ return clang::OO_MinusEqual;
2076
+ }
2077
+ if (interface_name == " MulAssignWith" ) {
2078
+ CARBON_CHECK (op_name == " Op" );
2079
+ return clang::OO_StarEqual;
2080
+ }
2081
+ if (interface_name == " DivAssignWith" ) {
2082
+ CARBON_CHECK (op_name == " Op" );
2083
+ return clang::OO_SlashEqual;
2084
+ }
2085
+ if (interface_name == " ModAssignWith" ) {
2086
+ CARBON_CHECK (op_name == " Op" );
2087
+ return clang::OO_PercentEqual;
2088
+ }
2089
+
2090
+ // Compound Assignment Bitwise Operators.
2091
+ if (interface_name == " BitAndAssignWith" ) {
2092
+ CARBON_CHECK (op_name == " Op" );
2093
+ return clang::OO_AmpEqual;
2094
+ }
2095
+ if (interface_name == " BitOrAssignWith" ) {
2096
+ CARBON_CHECK (op_name == " Op" );
2097
+ return clang::OO_PipeEqual;
2098
+ }
2099
+ if (interface_name == " BitXorAssignWith" ) {
2100
+ CARBON_CHECK (op_name == " Op" );
2101
+ return clang::OO_CaretEqual;
2102
+ }
2103
+ // TODO: Add support for `LeftShiftAssignWith` (`OO_LessLessEqual`) and
2104
+ // `RightShiftAssignWith` (`OO_GreaterGreaterEqual`) when references are
2105
+ // supported.
2106
+
2107
+ // Relational Operators.
2108
+ if (interface_name == " EqWith" ) {
2109
+ if (op_name == " Equal" ) {
2110
+ return clang::OO_EqualEqual;
2111
+ }
2112
+ CARBON_CHECK (op_name == " NotEqual" );
2113
+ return clang::OO_ExclaimEqual;
2114
+ }
2115
+ if (interface_name == " OrderedWith" ) {
2116
+ if (op_name == " Less" ) {
2117
+ return clang::OO_Less;
2118
+ }
2119
+ if (op_name == " Greater" ) {
2120
+ return clang::OO_Greater;
2121
+ }
2122
+ if (op_name == " LessOrEquivalent" ) {
2123
+ return clang::OO_LessEqual;
2124
+ }
2125
+ CARBON_CHECK (op_name == " GreaterOrEquivalent" );
2126
+ return clang::OO_GreaterEqual;
2127
+ }
2026
2128
2027
2129
context.TODO (loc_id, llvm::formatv (" Unsupported operator interface `{0}`" ,
2028
2130
interface_name));
@@ -2038,7 +2140,8 @@ auto ImportOperatorFromCpp(Context& context, SemIR::LocId loc_id, Operator op)
2038
2140
builder.Note (loc_id, InCppOperatorLookup, op.interface_name .str ());
2039
2141
});
2040
2142
2041
- auto op_kind = GetOperatorKind (context, loc_id, op.interface_name );
2143
+ auto op_kind =
2144
+ GetClangOperatorKind (context, loc_id, op.interface_name , op.op_name );
2042
2145
if (!op_kind) {
2043
2146
return SemIR::ScopeLookupResult::MakeNotFound ();
2044
2147
}
0 commit comments