Skip to content

Commit

Permalink
Version 3.4.0-83.0.dev
Browse files Browse the repository at this point in the history
Merge c2e15cf into dev
  • Loading branch information
Dart CI committed Jan 27, 2024
2 parents d0b48a0 + c2e15cf commit 422d048
Show file tree
Hide file tree
Showing 51 changed files with 939 additions and 58 deletions.
56 changes: 48 additions & 8 deletions pkg/analyzer/lib/src/generated/ffi_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
if (element is MethodElement) {
var enclosingElement = element.enclosingElement;
if (enclosingElement.isNativeStructPointerExtension ||
enclosingElement.isNativeStructArrayExtension) {
enclosingElement.isNativeStructArrayExtension ||
enclosingElement.isNativeUnionPointerExtension ||
enclosingElement.isNativeUnionArrayExtension) {
if (element.name == '[]') {
_validateRefIndexed(node);
}
Expand All @@ -232,10 +234,12 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
var constructor = node.constructorName.staticElement;
var class_ = constructor?.enclosingElement;
if (class_.isStructSubclass || class_.isUnionSubclass) {
_errorReporter.reportErrorForNode(
FfiCode.CREATION_OF_STRUCT_OR_UNION,
node.constructorName,
);
if (!constructor!.isFactory) {
_errorReporter.reportErrorForNode(
FfiCode.CREATION_OF_STRUCT_OR_UNION,
node.constructorName,
);
}
} else if (class_.isNativeCallable) {
_validateNativeCallable(node);
}
Expand Down Expand Up @@ -289,6 +293,10 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
} else if (element.name == 'elementAt') {
_validateElementAt(node);
}
} else if (enclosingElement.isStruct || enclosingElement.isUnion) {
if (element.name == 'create') {
_validateCreate(node, enclosingElement.name!);
}
} else if (enclosingElement.isNative) {
if (element.name == 'addressOf') {
_validateNativeAddressOf(node);
Expand Down Expand Up @@ -320,7 +328,8 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
var element = node.staticElement;
if (element != null) {
var enclosingElement = element.enclosingElement;
if (enclosingElement.isNativeStructPointerExtension) {
if (enclosingElement.isNativeStructPointerExtension ||
enclosingElement.isNativeUnionPointerExtension) {
if (element.name == 'ref') {
_validateRefPrefixedIdentifier(node);
}
Expand All @@ -334,7 +343,8 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
var element = node.propertyName.staticElement;
if (element != null) {
var enclosingElement = element.enclosingElement;
if (enclosingElement.isNativeStructPointerExtension) {
if (enclosingElement.isNativeStructPointerExtension ||
enclosingElement.isNativeUnionPointerExtension) {
if (element.name == 'ref') {
_validateRefPropertyAccess(node);
}
Expand Down Expand Up @@ -1163,6 +1173,22 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
}
}

void _validateCreate(MethodInvocation node, String errorClass) {
final typeArgumentTypes = node.typeArgumentTypes;
if (typeArgumentTypes == null || typeArgumentTypes.length != 1) {
return;
}
final DartType dartType = typeArgumentTypes[0];
if (!_isValidFfiNativeType(dartType)) {
final AstNode errorNode = node;
_errorReporter.reportErrorForNode(
FfiCode.NON_CONSTANT_TYPE_ARGUMENT,
errorNode,
['$errorClass.create'],
);
}
}

void _validateElementAt(MethodInvocation node) {
var targetType = node.realTarget?.staticType;
if (targetType is InterfaceType && targetType.isPointer) {
Expand Down Expand Up @@ -1625,7 +1651,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
/// Validate the invocation of the extension method
/// `Pointer<T extends Struct>.ref`.
void _validateRefPrefixedIdentifier(PrefixedIdentifier node) {
var targetType = node.prefix.typeOrThrow;
var targetType = node.prefix.staticType;
if (!_isValidFfiNativeType(targetType,
allowVoid: false, allowEmptyStruct: true)) {
final AstNode errorNode = node;
Expand Down Expand Up @@ -1922,6 +1948,20 @@ extension on Element? {
element.isFfiExtension;
}

bool get isNativeUnionArrayExtension {
final element = this;
return element is ExtensionElement &&
element.name == 'UnionArray' &&
element.isFfiExtension;
}

bool get isNativeUnionPointerExtension {
final element = this;
return element is ExtensionElement &&
element.name == 'UnionPointer' &&
element.isFfiExtension;
}

/// Return `true` if this represents the class `Opaque`.
bool get isOpaque {
final element = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ library /*isLegacy*/;
import self as self;
import "dart:core" as core;
import "dart:ffi" as ffi;
import "dart:typed_data" as typ;

import "dart:ffi";
import "package:ffi/ffi.dart";
Expand All @@ -18,6 +19,9 @@ class Coordinate extends ffi::Struct {
constructor #fromTypedDataBase(synthesized core::Object #typedDataBase) → self::Coordinate
: super ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized typ::TypedData #typedData, synthesized core::int #offset, synthesized core::int #sizeInBytes) → self::Coordinate
: super ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
static factory allocate(ffi::Allocator* allocator, core::double* x, core::double* y, ffi::Pointer<self::Coordinate*>* next) → self::Coordinate* {
return let final self::Coordinate* #t1 = new self::Coordinate::#fromTypedDataBase(allocator.{ffi::Allocator::allocate}<self::Coordinate*>(self::Coordinate::#sizeOf){(core::int, {alignment: core::int?}) → ffi::Pointer<self::Coordinate*>}!) in block {
#t1.{self::Coordinate::x} = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ library /*isLegacy*/;
import self as self;
import "dart:core" as core;
import "dart:ffi" as ffi;
import "dart:typed_data" as typ;

import "dart:ffi";
import "package:ffi/ffi.dart";
Expand All @@ -11,6 +12,9 @@ class Coordinate extends ffi::Struct {
constructor #fromTypedDataBase(synthesized core::Object #typedDataBase) → self::Coordinate
: super ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized typ::TypedData #typedData, synthesized core::int #offset, synthesized core::int #sizeInBytes) → self::Coordinate
: super ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
static factory allocate(ffi::Allocator* allocator, core::double* x, core::double* y, ffi::Pointer<self::Coordinate*>* next) → self::Coordinate* {
return let final self::Coordinate* #t1 = new self::Coordinate::#fromTypedDataBase(allocator.{ffi::Allocator::allocate}<self::Coordinate*>(self::Coordinate::#sizeOf){(core::int, {alignment: core::int?}) → ffi::Pointer<self::Coordinate*>}!) in block {
#t1.{self::Coordinate::x} = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ library from "org-dartlang-test:///lib.dart" as lib {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → lib::Y
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → lib::Y
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
@#C7
get yy() → dart.core::int
return dart.ffi::_loadUint32(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C9.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
Expand All @@ -35,6 +38,9 @@ library from "org-dartlang-test:///main.dart" as main {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → main::X
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → main::X
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get xx() → lib::Y
return new lib::Y::#fromTypedDataBase( block {
synthesized dart.core::Object #typedDataBase = this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ library from "org-dartlang-test:///lib.dart" as lib {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → lib::Y
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → lib::Y
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
@#C7
get yy() → dart.core::int
return dart.ffi::_loadUint32(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C9.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
Expand All @@ -35,6 +38,9 @@ library from "org-dartlang-test:///main.dart" as main {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → main::X
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → main::X
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get xx() → lib::Y
return new lib::Y::#fromTypedDataBase( block {
synthesized dart.core::Object #typedDataBase = this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ library from "org-dartlang-test:///structs.dart" as str {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → str::A
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → str::A
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get yy() → str::Y
return new str::Y::#fromTypedDataBase( block {
synthesized dart.core::Object #typedDataBase = this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object};
Expand All @@ -47,6 +50,9 @@ library from "org-dartlang-test:///structs.dart" as str {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → str::Y
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → str::Y
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
external get zz() → invalid-type;
external set zz(synthesized invalid-type #externalFieldValue) → void;
@#C10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ library from "org-dartlang-test:///structs.dart" as str {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → str::A
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → str::A
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get yy() → str::Y
return new str::Y::#fromTypedDataBase( block {
synthesized dart.core::Object #typedDataBase = this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object};
Expand All @@ -47,6 +50,9 @@ library from "org-dartlang-test:///structs.dart" as str {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → str::Y
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → str::Y
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
external get zz() → invalid-type;
external set zz(synthesized invalid-type #externalFieldValue) → void;
@#C10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ library from "org-dartlang-test:///lib.dart" as lib {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → lib::Coordinate
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → lib::Coordinate
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
@#C8
get x() → dart.core::double
return dart.ffi::_loadDouble(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C10.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ library from "org-dartlang-test:///lib.dart" as lib {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → lib::Coordinate
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → lib::Coordinate
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
@#C8
get x() → dart.core::double
return dart.ffi::_loadDouble(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C10.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ library from "org-dartlang-test:///lib.dart" as lib {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → lib::Coordinate
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → lib::Coordinate
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
@#C8
get x() → dart.core::double
return dart.ffi::_loadDouble(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C10.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ library from "org-dartlang-test:///a.dart" as a {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → a::StructA
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → a::StructA
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get a1() → dart.ffi::Pointer<dart.ffi::Void>
return dart.ffi::_loadPointer<dart.ffi::Void>(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C9.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
set a1(synthesized dart.ffi::Pointer<dart.ffi::Void> #externalFieldValue) → void
Expand Down Expand Up @@ -42,6 +45,9 @@ library from "org-dartlang-test:///a.dart" as a {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → a::NestedStruct
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → a::NestedStruct
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get n1() → dart.ffi::Pointer<dart.ffi::Void>
return dart.ffi::_loadPointer<dart.ffi::Void>(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C9.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
set n1(synthesized dart.ffi::Pointer<dart.ffi::Void> #externalFieldValue) → void
Expand Down Expand Up @@ -74,6 +80,9 @@ library from "org-dartlang-test:///b.dart" as b {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → b::StructB
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → b::StructB
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get b1() → a::StructA
return new a::StructA::#fromTypedDataBase( block {
synthesized dart.core::Object #typedDataBase = this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ library from "org-dartlang-test:///a.dart" as a {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → a::StructA
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → a::StructA
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get a1() → dart.ffi::Pointer<dart.ffi::Void>
return dart.ffi::_loadPointer<dart.ffi::Void>(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C9.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
set a1(synthesized dart.ffi::Pointer<dart.ffi::Void> #externalFieldValue) → void
Expand Down Expand Up @@ -42,6 +45,9 @@ library from "org-dartlang-test:///a.dart" as a {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → a::NestedStruct
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → a::NestedStruct
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get n1() → dart.ffi::Pointer<dart.ffi::Void>
return dart.ffi::_loadPointer<dart.ffi::Void>(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C9.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
set n1(synthesized dart.ffi::Pointer<dart.ffi::Void> #externalFieldValue) → void
Expand Down Expand Up @@ -74,6 +80,9 @@ library from "org-dartlang-test:///b.dart" as b {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → b::StructB
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → b::StructB
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
get b1() → a::StructA
return new a::StructA::#fromTypedDataBase( block {
synthesized dart.core::Object #typedDataBase = this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ library from "org-dartlang-test:///lib.dart" as lib {
constructor #fromTypedDataBase(synthesized dart.core::Object #typedDataBase) → lib::Coordinate
: super dart.ffi::Struct::_fromTypedDataBase(#typedDataBase)
;
constructor #fromTypedData(synthesized dart.typed_data::TypedData #typedData, synthesized dart.core::int #offset, synthesized dart.core::int #sizeInBytes) → lib::Coordinate
: super dart.ffi::Struct::_fromTypedData(#typedData, #offset, #sizeInBytes)
;
@#C8
get x() → dart.core::double
return dart.ffi::_loadDouble(this.{dart.ffi::_Compound::_typedDataBase}{dart.core::Object}, #C10.{dart.core::List::[]}(dart.ffi::_abi()){(dart.core::int) → dart.core::int*});
Expand Down
Loading

0 comments on commit 422d048

Please sign in to comment.