• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dart-lang / ffigen / 4851318812

01 May 2023 01:06PM UTC coverage: 91.872% (-0.5%) from 92.376%
4851318812

push

github

GitHub
Support for generating Variadic functions (#515)

177 of 177 new or added lines in 9 files covered. (100.0%)

3357 of 3654 relevant lines covered (91.87%)

25.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.35
/lib/src/code_generator/imports.dart
1
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4

5
import 'struct.dart';
6
import 'type.dart';
7
import 'writer.dart';
8

9
/// A library import which will be written as an import in the generated file.
10
class LibraryImport {
11
  final String name;
12
  final String importPath;
13
  String prefix;
14

15
  LibraryImport(this.name, this.importPath) : prefix = name;
35✔
16

17
  @override
29✔
18
  bool operator ==(other) {
19
    return other is LibraryImport && name == other.name;
116✔
20
  }
21

22
  @override
32✔
23
  int get hashCode => name.hashCode;
64✔
24
}
25

26
/// An imported type which will be used in the generated code.
27
class ImportedType extends Type {
28
  final LibraryImport libraryImport;
29
  final String cType;
30
  final String dartType;
31
  final String? defaultValue;
32

33
  ImportedType(this.libraryImport, this.cType, this.dartType,
33✔
34
      [this.defaultValue]);
35

36
  @override
29✔
37
  String getCType(Writer w) {
38
    w.markImportUsed(libraryImport);
58✔
39
    return '${libraryImport.prefix}.$cType';
116✔
40
  }
41

42
  @override
28✔
43
  String getDartType(Writer w) => cType == dartType ? getCType(w) : dartType;
113✔
44

45
  @override
2✔
46
  String toString() => '${libraryImport.name}.$cType';
8✔
47

48
  @override
2✔
49
  String? getDefaultValue(Writer w, String nativeLib) => defaultValue;
2✔
50
}
51

52
/// An unchecked type similar to [ImportedType] which exists in the generated
53
/// binding itself.
54
class SelfImportedType extends Type {
55
  final String cType;
56
  final String dartType;
57
  final String? defaultValue;
58

59
  SelfImportedType(this.cType, this.dartType, [this.defaultValue]);
1✔
60

61
  @override
1✔
62
  String getCType(Writer w) => cType;
1✔
63

64
  @override
1✔
65
  String getDartType(Writer w) => dartType;
1✔
66

67
  @override
×
68
  String toString() => cType;
×
69
}
70

71
final ffiImport = LibraryImport('ffi', 'dart:ffi');
105✔
72
final ffiPkgImport = LibraryImport('pkg_ffi', 'package:ffi/ffi.dart');
15✔
73

74
final voidType = ImportedType(ffiImport, 'Void', 'void');
124✔
75

76
final unsignedCharType = ImportedType(ffiImport, 'UnsignedChar', 'int', '0');
124✔
77
final signedCharType = ImportedType(ffiImport, 'SignedChar', 'int', '0');
124✔
78
final charType = ImportedType(ffiImport, 'Char', 'int', '0');
128✔
79
final unsignedShortType = ImportedType(ffiImport, 'UnsignedShort', 'int', '0');
124✔
80
final shortType = ImportedType(ffiImport, 'Short', 'int', '0');
124✔
81
final unsignedIntType = ImportedType(ffiImport, 'UnsignedInt', 'int', '0');
124✔
82
final intType = ImportedType(ffiImport, 'Int', 'int', '0');
132✔
83
final unsignedLongType = ImportedType(ffiImport, 'UnsignedLong', 'int', '0');
124✔
84
final longType = ImportedType(ffiImport, 'Long', 'int', '0');
124✔
85
final unsignedLongLongType =
62✔
86
    ImportedType(ffiImport, 'UnsignedLongLong', 'int', '0');
62✔
87
final longLongType = ImportedType(ffiImport, 'LongLong', 'int', '0');
124✔
88

89
final floatType = ImportedType(ffiImport, 'Float', 'double', '0');
128✔
90
final doubleType = ImportedType(ffiImport, 'Double', 'double', '0');
128✔
91

92
final sizeType = ImportedType(ffiImport, 'Size', 'int', '0');
72✔
93
final wCharType = ImportedType(ffiImport, 'WChar', 'int', '0');
72✔
94

95
final objCObjectType = Struct(name: 'ObjCObject');
6✔
96
final objCSelType = Struct(name: 'ObjCSel');
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc