From 761c7b936a202b707bec37da8595774ed8ecc6f2 Mon Sep 17 00:00:00 2001 From: Tyler K Date: Wed, 20 Nov 2024 12:30:49 -0800 Subject: [PATCH] Dart generation --- .../dart/lib/src/CyclicStructC.g.dart | 54 +++++++++++++++++++ feature_tests/dart/lib/src/lib.g.dart | 1 + 2 files changed, 55 insertions(+) create mode 100644 feature_tests/dart/lib/src/CyclicStructC.g.dart diff --git a/feature_tests/dart/lib/src/CyclicStructC.g.dart b/feature_tests/dart/lib/src/CyclicStructC.g.dart new file mode 100644 index 000000000..557d351d2 --- /dev/null +++ b/feature_tests/dart/lib/src/CyclicStructC.g.dart @@ -0,0 +1,54 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +final class _CyclicStructCFfi extends ffi.Struct { + external _CyclicStructAFfi a; +} + +final class CyclicStructC { + CyclicStructA a; + + CyclicStructC({required this.a}); + + // This struct contains borrowed fields, so this takes in a list of + // "edges" corresponding to where each lifetime's data may have been borrowed from + // and passes it down to individual fields containing the borrow. + // This method does not attempt to handle any dependencies between lifetimes, the caller + // should handle this when constructing edge arrays. + // ignore: unused_element + CyclicStructC._fromFfi(_CyclicStructCFfi ffi) : + a = CyclicStructA._fromFfi(ffi.a); + + // ignore: unused_element + _CyclicStructCFfi _toFfi(ffi.Allocator temp) { + final struct = ffi.Struct.create<_CyclicStructCFfi>(); + struct.a = a._toFfi(temp); + return struct; + } + + String cyclicOut() { + final temp = _FinalizedArena(); + final write = _Write(); + _CyclicStructC_cyclic_out(_toFfi(temp.arena), write._ffi); + return write.finalize(); + } + + + @override + bool operator ==(Object other) => + other is CyclicStructC && + other.a == a; + + @override + int get hashCode => Object.hashAll([ + a, + ]); +} + +@meta.RecordUse() +@ffi.Native)>(isLeaf: true, symbol: 'CyclicStructC_cyclic_out') +// ignore: non_constant_identifier_names +external void _CyclicStructC_cyclic_out(_CyclicStructCFfi self, ffi.Pointer write); + + diff --git a/feature_tests/dart/lib/src/lib.g.dart b/feature_tests/dart/lib/src/lib.g.dart index 07e1507de..c00c757cb 100644 --- a/feature_tests/dart/lib/src/lib.g.dart +++ b/feature_tests/dart/lib/src/lib.g.dart @@ -18,6 +18,7 @@ part 'BorrowedFieldsWithBounds.g.dart'; part 'ContiguousEnum.g.dart'; part 'CyclicStructA.g.dart'; part 'CyclicStructB.g.dart'; +part 'CyclicStructC.g.dart'; part 'ErrorEnum.g.dart'; part 'ErrorStruct.g.dart'; part 'Float64Vec.g.dart';