dart-sdk/sdk/lib/ffi/annotations.dart

28 lines
1.2 KiB
Dart
Raw Permalink Normal View History

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of dart.ffi;
Reland "[vm/ffi] Add class modifiers" This is a reland of commit 1755f8909264330a207a0e0e44d31f5fec9c489a Can land after (or with) the Flutter PR: https://github.com/flutter/engine/pull/40434 Original change's description: > [vm/ffi] Add class modifiers > > Adds class modifiers to `dart:ffi`. > > Migrates all user-defined subclasses of `Struct`, `Union`, `Opaque`, > and `AbiSpecificInteger` to be `final class`es. > > Does not remove the manual error checking, so some errors will show up > twice now in language version 3.0. In language version <3.0, only the > FFI-specific error will show up. > > In a follow-up CL, we will try to make the language-errors to show up > also <3.0 so that we can remove the FFI-specific errors. > > Examples of duplicated errors: > pkg/analyzer/test/src/diagnostics/subtype_of_ffi_class_test.dart > > TEST=pkg/analyzer/test/ (for the analyzer) > TEST=pkg/front_end/testcases/ (for the CFE) > TEST=test/ffi/ (for the VM) > > CoreLibraryReviewExempt: No need for dart2js to review. > Bug: https://github.com/dart-lang/sdk/issues/51683 > Change-Id: I2964ceccb7db59fbdaf6be5319f5e4ec2dabe0f3 > Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-win-release-try,pkg-mac-release-try,vm-precomp-ffi-qemu-linux-release-riscv64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-reload-rollback-linux-debug-x64-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289223 > Reviewed-by: Johnni Winther <johnniwinther@google.com> > Reviewed-by: Devon Carew <devoncarew@google.com> > Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> > Reviewed-by: Jackson Gardner <jacksongardner@google.com> > Reviewed-by: Lasse Nielsen <lrn@google.com> > Commit-Queue: Daco Harkes <dacoharkes@google.com> TEST=pkg/analyzer/test/ (for the analyzer) TEST=pkg/front_end/testcases/ (for the CFE) TEST=test/ffi/ (for the VM) CoreLibraryReviewExempt: No need for dart2js to review. Bug: https://github.com/dart-lang/sdk/issues/51683 Change-Id: I2ee3f0ac31d4162068a2346a06320029b2263ee2 Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-win-release-try,pkg-mac-release-try,vm-precomp-ffi-qemu-linux-release-riscv64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-reload-rollback-linux-debug-x64-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289781 Reviewed-by: Devon Carew <devoncarew@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-03-21 15:25:10 +00:00
final class DartRepresentationOf {
/// Represents the Dart type corresponding to a [NativeType].
///
/// [Int8] -> [int]
/// [Int16] -> [int]
/// [Int32] -> [int]
/// [Int64] -> [int]
/// [Uint8] -> [int]
/// [Uint16] -> [int]
/// [Uint32] -> [int]
/// [Uint64] -> [int]
/// [IntPtr] -> [int]
/// [Double] -> [double]
/// [Float] -> [double]
/// [Pointer]<T> -> [Pointer]<T>
/// [NativeFunction]<T1 Function(T2, T3) -> S1 Function(S2, S3)
/// where DartRepresentationOf(Tn) -> Sn
[vm/ffi] Introduce `SizedNativeType` Both `sizeOf` and `AllocatorAlloc.call` use the new type as bound. This prevents runtime errors on trying to call these two static methods with unsized native types. All tests testing for these runtime errors have been deleted. The `NativeTypes` implementing `SizedNativeType` are as follows: * The native integer types, `Float`, and `Double`. * `AbiSpecificInteger` and it's subtypes. * `Struct` and `Union` and their subtypes. The The `NativeTypes` not implementing `SizedNativeType` are as follows: * `Void` has no size. * `Opaque` and subtypes have unknown size. * `Handle` is considered opaque. Cannot be used as field in compounds. * `Array` does not carry a size in its type. Can be used as fields in compounds with an annotation specifying the size. * `NativeFunction` is considered opaque. Would have variable size. * `VarArgs` is only a marker in function signatures. `Struct`s and `Union`s can have only `SizedNativeType`s and `Array`s as fields. Documentation for these is in flux in another CL, so we should update it there. This CL also replaces a bunch of `extends NativeType` with `implements` clauses and made `NativeType` itself `abstract`. TEST=Dart SDK build TEST=ffi test suite Bug: https://github.com/dart-lang/sdk/issues/54542 CoreLibraryReviewExempt: VM and dart2wasm feature only. Change-Id: Ib4f6b58f7204bd063ace20133162798d8c9483e8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345221 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-01-12 10:13:39 +00:00
/// T extends Struct -> T
/// T extends Union -> T
const DartRepresentationOf(String nativeType);
}