Просмотр исходного кода

Add comparisons for CppCompat.Long32 (#6639)

Support for both homogeneous and heterogeneous comparisons are added for
CppCompat.Long32.

Context: https://github.com/carbon-language/carbon-lang/issues/6275.

Part of https://github.com/carbon-language/carbon-lang/issues/5263.
Ivana Ivanovska 3 месяцев назад
Родитель
Сommit
c9dbf40f11
2 измененных файлов с 1764 добавлено и 22 удалено
  1. 46 1
      core/prelude/types/cpp/int.carbon
  2. 1718 21
      toolchain/check/testdata/interop/cpp/builtins.llp64.carbon

+ 46 - 1
core/prelude/types/cpp/int.carbon

@@ -63,7 +63,7 @@ final impl CppCompat.Long32 as ImplicitAs(IntLiteral()) {
 
 // TODO: ImplicitAs from Int(N) to Long32 if N < 32.
 impl i32 as ImplicitAs(CppCompat.Long32) {
-  fn Convert[self: Self]() -> CppCompat.Long32 = "int.convert_checked";
+  fn Convert[self: Self]() -> CppCompat.Long32 = "int.convert";
 }
 
 // TODO: ImplicitAs from Long32 to Int(N) if N > 32.
@@ -149,6 +149,51 @@ final impl CppCompat.ULongLong64 as ImplicitAs(u64) {
 // TODO: As from Int(N) to LongLong64 if N > 64.
 // TODO: As from UInt(N) to ULongLong64 if N > 64.
 
+// Comparisons.
+
+// - CppCompat.Long32 vs CppCompat.Long32.
+
+final impl CppCompat.Long32 as EqWith(CppCompat.Long32) {
+  fn Equal[self: Self](other: Self) -> bool = "int.eq";
+  fn NotEqual[self: Self](other: Self) -> bool = "int.neq";
+}
+
+final impl CppCompat.Long32 as OrderedWith(CppCompat.Long32) {
+  fn Less[self: Self](other: Self) -> bool = "int.less";
+  fn LessOrEquivalent[self: Self](other: Self) -> bool = "int.less_eq";
+  fn Greater[self: Self](other: Self) -> bool = "int.greater";
+  fn GreaterOrEquivalent[self: Self](other: Self) -> bool = "int.greater_eq";
+}
+
+// - CppCompat.Long32 on left-hand side.
+
+impl forall [T:! ImplicitAs(CppCompat.Long32)] CppCompat.Long32 as EqWith(T) {
+  fn Equal[self: Self](other: Self) -> bool = "int.eq";
+  fn NotEqual[self: Self](other: Self) -> bool = "int.neq";
+}
+
+impl forall [T:! ImplicitAs(CppCompat.Long32)] CppCompat.Long32 as OrderedWith(T) {
+  fn Less[self: Self](other: Self) -> bool = "int.less";
+  fn LessOrEquivalent[self: Self](other: Self) -> bool = "int.less_eq";
+  fn Greater[self: Self](other: Self) -> bool = "int.greater";
+  fn GreaterOrEquivalent[self: Self](other: Self) -> bool = "int.greater_eq";
+}
+
+// - CppCompat.Long32 on right-hand side.
+
+impl forall [T:! ImplicitAs(CppCompat.Long32)] T as EqWith(CppCompat.Long32) {
+  fn Equal[self: CppCompat.Long32](other: CppCompat.Long32) -> bool = "int.eq";
+  fn NotEqual[self: CppCompat.Long32](other: CppCompat.Long32) -> bool = "int.neq";
+}
+
+impl forall [T:! ImplicitAs(CppCompat.Long32)] T as OrderedWith(CppCompat.Long32) {
+  fn Less[self: CppCompat.Long32](other: CppCompat.Long32) -> bool = "int.less";
+  fn LessOrEquivalent[self: CppCompat.Long32](other: CppCompat.Long32) -> bool = "int.less_eq";
+  fn Greater[self: CppCompat.Long32](other: CppCompat.Long32) -> bool = "int.greater";
+  fn GreaterOrEquivalent[self: CppCompat.Long32](other: CppCompat.Long32) -> bool = "int.greater_eq";
+}
+
+// TODO: Comparisons for ULong32, LongLong64, ULongLong64.
 
 // Arithmetic.
 

Разница между файлами не показана из-за своего большого размера
+ 1718 - 21
toolchain/check/testdata/interop/cpp/builtins.llp64.carbon


Некоторые файлы не были показаны из-за большого количества измененных файлов