-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer/ffi] Support packed
Structs
s
This CL does not add packed structs to `dart:ffi` yet, only to the mock SDK in the analyzer for testing the analyzer. This means we can review and land it separately. Bug: #38158 Split off https://dart-review.googlesource.com/c/sdk/+/186143. Change-Id: I9c9ac9154e3dec0e05242f57cf7dddf8406df5fb Cq-Include-Trybots: luci.dart.try:analyzer-analysis-server-linux-try,analyzer-linux-release-try,analyzer-nnbd-linux-release-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191700 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
- Loading branch information
Showing
8 changed files
with
360 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
pkg/analyzer/test/src/diagnostics/packed_annotation_alignment_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
import 'package:analyzer/src/dart/error/ffi_code.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/context_collection_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(PackedAnnotationAlignment); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class PackedAnnotationAlignment extends PubPackageResolutionTest { | ||
test_error() async { | ||
await assertErrorsInCode(r''' | ||
import 'dart:ffi'; | ||
@Packed(3) | ||
class C extends Struct { | ||
external Pointer<Uint8> notEmpty; | ||
} | ||
''', [ | ||
error(FfiCode.PACKED_ANNOTATION_ALIGNMENT, 20, 10), | ||
]); | ||
} | ||
|
||
test_no_error() async { | ||
await assertNoErrorsInCode(r''' | ||
import 'dart:ffi'; | ||
@Packed(1) | ||
class C extends Struct { | ||
external Pointer<Uint8> notEmpty; | ||
} | ||
'''); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
pkg/analyzer/test/src/diagnostics/packed_annotation_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
import 'package:analyzer/src/dart/error/ffi_code.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/context_collection_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(PackedAnnotation); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class PackedAnnotation extends PubPackageResolutionTest { | ||
test_error() async { | ||
await assertErrorsInCode(r''' | ||
import 'dart:ffi'; | ||
@Packed(1) | ||
@Packed(1) | ||
class C extends Struct { | ||
external Pointer<Uint8> notEmpty; | ||
} | ||
''', [ | ||
error(FfiCode.PACKED_ANNOTATION, 31, 10), | ||
]); | ||
} | ||
|
||
test_no_error_1() async { | ||
await assertNoErrorsInCode(r''' | ||
import 'dart:ffi'; | ||
class C extends Struct { | ||
external Pointer<Uint8> notEmpty; | ||
} | ||
'''); | ||
} | ||
|
||
test_no_error_2() async { | ||
await assertNoErrorsInCode(r''' | ||
import 'dart:ffi'; | ||
@Packed(1) | ||
class C extends Struct { | ||
external Pointer<Uint8> notEmpty; | ||
} | ||
'''); | ||
} | ||
} |
Oops, something went wrong.