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

dart-lang / ffigen / 6366517051

28 Sep 2023 08:12PM UTC coverage: 92.593% (+0.08%) from 92.509%
6366517051

push

github

web-flow
Handle ObjC nullable annotations (#624)

* Fix #334

* Fix analysis

* fix swift test

* Fix tests

* Fix nullability bug

* Fix formatting

* Fix linker error

* Fix static methods bug

* fix objective_c_example_test

87 of 87 new or added lines in 7 files covered. (100.0%)

3700 of 3996 relevant lines covered (92.59%)

28.32 hits per line

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

93.33
/lib/src/code_generator/type.dart
1
// Copyright (c) 2020, 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 'package:ffigen/src/code_generator.dart';
6

7
import 'writer.dart';
8

9
/// Type class for return types, variable types, etc.
10
///
11
/// Implementers should extend either Type, or BindingType if the type is also a
12
/// binding, and override at least getCType and toString.
13
abstract class Type {
14
  const Type();
149✔
15

16
  /// Get all dependencies of this type and save them in [dependencies].
17
  void addDependencies(Set<Binding> dependencies) {}
35✔
18

19
  /// Get base type for any type.
20
  ///
21
  /// E.g int** has base [Type] of int.
22
  /// double[2][3] has base [Type] of double.
23
  Type get baseType => this;
31✔
24

25
  /// Get base Array type.
26
  ///
27
  /// Returns itself if it's not an Array Type.
28
  Type get baseArrayType => this;
8✔
29

30
  /// Get base typealias type.
31
  ///
32
  /// Returns itself if it's not a Typealias.
33
  Type get typealiasType => this;
26✔
34

35
  /// Returns true if the type is a [Compound] and is incomplete.
36
  bool get isIncompleteCompound => false;
30✔
37

38
  /// Returns the C type of the Type. This is the FFI compatible type that is
39
  /// passed to native code.
40
  String getCType(Writer w) => throw 'No mapping for type: $this';
×
41

42
  /// Returns the Dart type of the Type. This is the type that is passed from
43
  /// FFI to Dart code.
44
  String getFfiDartType(Writer w) => getCType(w);
50✔
45

46
  /// Returns the user type of the Type. This is the type that is presented to
47
  /// users by the ffigened API to users. For C bindings this is always the same
48
  /// as getFfiDartType. For ObjC bindings this refers to the wrapper object.
49
  String getDartType(Writer w) => getFfiDartType(w);
4✔
50

51
  /// Returns the string representation of the Type, for debugging purposes
52
  /// only. This string should not be printed as generated code.
53
  @override
54
  String toString();
55

56
  /// Cache key used in various places to dedupe Types. By default this is just
57
  /// the hash of the Type, but in many cases this does not dedupe sufficiently.
58
  /// So Types that may be duplicated should override this to return a more
59
  /// specific key. Types that are already deduped don't need to override this.
60
  /// toString() is not a valid cache key as there may be name collisions.
61
  String cacheKey() => hashCode.toRadixString(36);
6✔
62

63
  /// Returns a string of code that creates a default value for this type. For
64
  /// example, for int types this returns the string '0'. A null return means
65
  /// that default values aren't supported for this type, eg void.
66
  String? getDefaultValue(Writer w, String nativeLib) => null;
2✔
67
}
68

69
/// Function to check if the dart and C type string are same.
70
bool sameDartAndCType(Type t, Writer w) => t.getCType(w) == t.getFfiDartType(w);
92✔
71

72
/// Base class for all Type bindings.
73
///
74
/// Since Dart doesn't have multiple inheritance, this type exists so that we
75
/// don't have to reimplement the default methods in all the classes that want
76
/// to extend both NoLookUpBinding and Type.
77
abstract class BindingType extends NoLookUpBinding implements Type {
78
  BindingType({
33✔
79
    String? usr,
80
    String? originalName,
81
    required String name,
82
    String? dartDoc,
83
    bool isInternal = false,
84
  }) : super(
33✔
85
          usr: usr,
86
          originalName: originalName,
87
          name: name,
88
          dartDoc: dartDoc,
89
          isInternal: isInternal,
90
        );
91

92
  @override
22✔
93
  Type get baseType => this;
94

95
  @override
3✔
96
  Type get baseArrayType => this;
97

98
  @override
10✔
99
  Type get typealiasType => this;
100

101
  @override
5✔
102
  bool get isIncompleteCompound => false;
103

104
  @override
13✔
105
  String getFfiDartType(Writer w) => getCType(w);
13✔
106

107
  @override
2✔
108
  String getDartType(Writer w) => getFfiDartType(w);
2✔
109

110
  @override
2✔
111
  String toString() => originalName;
2✔
112

113
  @override
2✔
114
  String cacheKey() => hashCode.toRadixString(36);
4✔
115

116
  @override
×
117
  String? getDefaultValue(Writer w, String nativeLib) => null;
118
}
119

120
/// Represents an unimplemented type. Used as a marker, so that declarations
121
/// having these can exclude them.
122
class UnimplementedType extends Type {
123
  String reason;
124
  UnimplementedType(this.reason);
12✔
125

126
  @override
3✔
127
  String toString() => '(Unimplemented: $reason)';
6✔
128
}
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

© 2025 Coveralls, Inc