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

dart-lang / ffigen / 5844146996

01 Aug 2023 11:10PM UTC coverage: 92.332%. Remained the same
5844146996

push

github

web-flow
Bump coverallsapp/github-action from 2.2.0 to 2.2.1 (#596)

Bumps [coverallsapp/github-action](https://github.com/coverallsapp/github-action) from 2.2.0 to 2.2.1.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/coverallsapp/github-action/commit/<a class=hub.com/dart-lang/ffigen/commit/95b1a2355bd0e526ad2fd62da9fd386ad4c98474">95b1a2355<a href="https://github.com/dart-lang/ffigen/commit/daa06036c457277aa7ddbf734123bf76ec921e44">&quot;&gt;&lt;code&gt;95b1a23&lt;/code&gt;&lt;/a&gt; feat: add files option (&lt;a href=&quot;https://redirect.github.com/coverallsapp/github-action/issues/185">#185</a>)</li>
<li><a href="https://github.com/coverallsapp/github-action/commit/<a class="double-link" href="https://github.com/dart-lang/ffigen/commit/12d23ccd512af6f292f5eaf42c191d64928b135c">12d23ccd5</a><a href="https://github.com/dart-lang/ffigen/commit/daa06036c457277aa7ddbf734123bf76ec921e44">&quot;&gt;&lt;code&gt;12d23cc&lt;/code&gt;&lt;/a&gt; feat: add fail-on-error option (&lt;a href=&quot;https://redirect.github.com/coverallsapp/github-action/issues/184&quot;&gt;#184&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/coverallsapp/github-action/commit/</a><a class="double-link" href="https://github.com/dart-lang/ffigen/commit/8e1cba00ac8bb526c6a1b96b810071687e5e8310">8e1cba00a</a><a href="https://github.com/dart-lang/ffigen/commit/daa06036c457277aa7ddbf734123bf76ec921e44">&quot;&gt;&lt;code&gt;8e1cba0&lt;/code&gt;&lt;/a&gt; feat: add measure option (&lt;a href=&quot;https://redirect.github.com/coverallsapp/github-action/issues/183&quot;&gt;#183&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/coverallsapp/github-action/commit/</a><a class="double-link" href="https://github.com/dart-lang/ffigen/commit/cb1c78cc8dd8522acce1a460c643e67515393ef6">cb1c78cc8</a><a href="https://github.com/dart-lang/ffigen/commit/daa06036c457277aa7ddbf734123bf76ec921e44">&quot;&gt;&lt;code&gt;cb1c78c&lt;/code&gt;&lt;/a&gt; docs: clarify coveralls repo permissions (&lt;a href=&quot;https://redirect.github.com/coverallsapp/github-action/issues/182&quot;&gt;#182&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/coverallsapp/github-action/commit/3b7440a0f"><code>3b7440a</code></a> Update README.md (<a href="https://redirect.github.com/coverallsapp/github-action/issues/181">#181</a>)</li>
<li>See full diff in <a href="https://github.com/coverallsapp/github-action/compare/c7885c00c...95b1a2355bd0e526ad2fd62da9fd386ad4c98474">compare view



[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=coverallsapp/github-action&package-manager=github_actions&previous-version=2.2.0&new-version=2.2.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabo... (continued)

3576 of 3873 relevant lines covered (92.33%)

28.42 hits per line

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

83.33
/lib/src/config_provider/config_types.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
/// Contains all the neccesary classes required by config.
6
import 'dart:io';
7

8
import 'package:ffigen/src/code_generator.dart';
9
import 'package:quiver/pattern.dart' as quiver;
10

11
import 'path_finder.dart';
12

13
enum Language { c, objc }
14

15
class CommentType {
16
  CommentStyle style;
17
  CommentLength length;
18
  CommentType(this.style, this.length);
3✔
19

20
  /// Sets default style as [CommentStyle.doxygen], default length as
21
  /// [CommentLength.full].
22
  CommentType.def()
46✔
23
      : style = CommentStyle.doxygen,
24
        length = CommentLength.full;
25

26
  /// Disables any comments.
27
  CommentType.none()
1✔
28
      : style = CommentStyle.doxygen,
29
        length = CommentLength.none;
30
}
31

32
enum CommentStyle { doxygen, any }
33

34
enum CommentLength { none, brief, full }
35

36
enum CompoundDependencies { full, opaque }
37

38
/// Holds config for how Structs Packing will be overriden.
39
class StructPackingOverride {
40
  final Map<RegExp, int?> _matcherMap;
41

42
  StructPackingOverride({Map<RegExp, int?>? matcherMap})
50✔
43
      : _matcherMap = matcherMap ?? {};
49✔
44

45
  /// Returns true if the user has overriden the pack value.
46
  bool isOverriden(String name) {
25✔
47
    for (final key in _matcherMap.keys) {
51✔
48
      if (quiver.matchesFull(key, name)) {
1✔
49
        return true;
50
      }
51
    }
52
    return false;
53
  }
54

55
  /// Returns pack value for [name]. Ensure that value [isOverriden] before
56
  /// using the returned value.
57
  int? getOverridenPackValue(String name) {
1✔
58
    for (final opv in _matcherMap.entries) {
3✔
59
      if (quiver.matchesFull(opv.key, name)) {
2✔
60
        return opv.value;
1✔
61
      }
62
    }
63
    return null;
64
  }
65
}
66

67
// Holds headers and filters for header.
68
class Headers {
69
  /// Path to headers.
70
  ///
71
  /// This contains all the headers, after extraction from Globs.
72
  final List<String> entryPoints;
73

74
  /// Include filter for headers.
75
  final HeaderIncludeFilter includeFilter;
76

77
  Headers({List<String>? entryPoints, HeaderIncludeFilter? includeFilter})
50✔
78
      : entryPoints = entryPoints ?? [],
×
79
        includeFilter = includeFilter ?? GlobHeaderFilter();
×
80
}
81

82
abstract class HeaderIncludeFilter {
83
  bool shouldInclude(String headerSourceFile);
84
}
85

86
class GlobHeaderFilter extends HeaderIncludeFilter {
87
  List<quiver.Glob>? includeGlobs = [];
88

89
  GlobHeaderFilter({
50✔
90
    this.includeGlobs,
91
  });
92

93
  @override
33✔
94
  bool shouldInclude(String headerSourceFile) {
95
    // Return true if header was included.
96
    for (final globPattern in includeGlobs!) {
76✔
97
      if (quiver.matchesFull(globPattern, headerSourceFile)) {
10✔
98
        return true;
99
      }
100
    }
101

102
    // If any includedInclusionHeaders is provided, return false.
103
    if (includeGlobs!.isNotEmpty) {
66✔
104
      return false;
105
    } else {
106
      return true;
107
    }
108
  }
109
}
110

111
/// A generic declaration config, used for Functions, Structs, Enums, Macros,
112
/// unnamed Enums and Globals.
113
class Declaration {
114
  final Includer _includer;
115
  final Renamer _renamer;
116
  final MemberRenamer _memberRenamer;
117
  final Includer _symbolAddressIncluder;
118

119
  Declaration({
50✔
120
    Includer? includer,
121
    Renamer? renamer,
122
    MemberRenamer? memberRenamer,
123
    Includer? symbolAddressIncluder,
124
  })  : _includer = includer ?? Includer(),
×
125
        _renamer = renamer ?? Renamer(),
×
126
        _memberRenamer = memberRenamer ?? MemberRenamer(),
×
127
        _symbolAddressIncluder =
128
            symbolAddressIncluder ?? Includer.excludeByDefault();
50✔
129

130
  /// Applies renaming and returns the result.
131
  String renameUsingConfig(String name) => _renamer.rename(name);
99✔
132

133
  /// Applies member renaming and returns the result.
134
  String renameMemberUsingConfig(String declaration, String member) =>
29✔
135
      _memberRenamer.rename(declaration, member);
58✔
136

137
  /// Checks if a name is allowed by a filter.
138
  bool shouldInclude(String name, bool excludeAllByDefault) =>
33✔
139
      _includer.shouldInclude(name, excludeAllByDefault);
66✔
140

141
  /// Checks if the symbol address should be included for this name.
142
  bool shouldIncludeSymbolAddress(String name) =>
24✔
143
      _symbolAddressIncluder.shouldInclude(name);
48✔
144
}
145

146
/// Matches `$<single_digit_int>`, value can be accessed in group 1 of match.
147
final replaceGroupRegexp = RegExp(r'\$([0-9])');
3✔
148

149
/// Match/rename using [regExp].
150
class RegExpRenamer {
151
  final RegExp regExp;
152
  final String replacementPattern;
153

154
  RegExpRenamer(this.regExp, this.replacementPattern);
2✔
155

156
  /// Returns true if [str] has a full match with [regExp].
157
  bool matches(String str) => quiver.matchesFull(regExp, str);
3✔
158

159
  /// Renames [str] according to [replacementPattern].
160
  ///
161
  /// Returns [str] if [regExp] doesn't have a full match.
162
  String rename(String str) {
1✔
163
    if (matches(str)) {
1✔
164
      // Get match.
165
      final regExpMatch = regExp.firstMatch(str)!;
2✔
166

167
      /// Get group values.
168
      /// E.g for `str`: `clang_dispose` and `regExp`: `clang_(.*)`
169
      /// groups will be `0`: `clang_disponse`, `1`: `dispose`.
170
      final groups = regExpMatch.groups(
1✔
171
          List.generate(regExpMatch.groupCount, (index) => index) +
4✔
172
              [regExpMatch.groupCount]);
2✔
173

174
      /// Replace all `$<int>` symbols with respective groups (if any).
175
      final result =
176
          replacementPattern.replaceAllMapped(replaceGroupRegexp, (match) {
4✔
177
        final groupInt = int.parse(match.group(1)!);
2✔
178
        return groups[groupInt]!;
1✔
179
      });
180
      return result;
181
    } else {
182
      return str;
183
    }
184
  }
185

186
  @override
×
187
  String toString() {
188
    return 'Regexp: $regExp, ReplacementPattern: $replacementPattern';
×
189
  }
190
}
191

192
/// Handles `include/exclude` logic for a declaration.
193
class Includer {
194
  final List<RegExp> _includeMatchers;
195
  final Set<String> _includeFull;
196
  final List<RegExp> _excludeMatchers;
197
  final Set<String> _excludeFull;
198

199
  Includer({
50✔
200
    List<RegExp>? includeMatchers,
201
    Set<String>? includeFull,
202
    List<RegExp>? excludeMatchers,
203
    Set<String>? excludeFull,
204
  })  : _includeMatchers = includeMatchers ?? [],
×
205
        _includeFull = includeFull ?? {},
206
        _excludeMatchers = excludeMatchers ?? [],
×
207
        _excludeFull = excludeFull ?? {};
208

209
  Includer.excludeByDefault()
50✔
210
      : _includeMatchers = [],
50✔
211
        _includeFull = {},
212
        _excludeMatchers = [RegExp('.*', dotAll: true)],
100✔
213
        _excludeFull = {};
214

215
  /// Returns true if [name] is allowed.
216
  ///
217
  /// Exclude overrides include.
218
  bool shouldInclude(String name, [bool excludeAllByDefault = false]) {
33✔
219
    if (_excludeFull.contains(name)) {
66✔
220
      return false;
221
    }
222

223
    for (final em in _excludeMatchers) {
57✔
224
      if (quiver.matchesFull(em, name)) {
24✔
225
        return false;
226
      }
227
    }
228

229
    if (_includeFull.contains(name)) {
66✔
230
      return true;
231
    }
232

233
    for (final im in _includeMatchers) {
34✔
234
      if (quiver.matchesFull(im, name)) {
1✔
235
        return true;
236
      }
237
    }
238

239
    // If user has provided 'include' field in the filter, then default
240
    // matching is false.
241
    if (_includeMatchers.isNotEmpty || _includeFull.isNotEmpty) {
132✔
242
      return false;
243
    } else {
244
      // Otherwise, fall back to the default behavior for empty filters.
245
      return !excludeAllByDefault;
246
    }
247
  }
248
}
249

250
/// Handles `full/regexp` renaming logic.
251
class Renamer {
252
  final Map<String, String> _renameFull;
253
  final List<RegExpRenamer> _renameMatchers;
254

255
  Renamer({
50✔
256
    List<RegExpRenamer>? renamePatterns,
257
    Map<String, String>? renameFull,
258
  })  : _renameMatchers = renamePatterns ?? [],
×
259
        _renameFull = renameFull ?? {};
×
260

261
  Renamer.noRename()
×
262
      : _renameMatchers = [],
×
263
        _renameFull = {};
×
264

265
  String rename(String name) {
33✔
266
    // Apply full rename (if any).
267
    if (_renameFull.containsKey(name)) {
66✔
268
      return _renameFull[name]!;
2✔
269
    }
270

271
    // Apply rename regexp (if matches).
272
    for (final renamer in _renameMatchers) {
34✔
273
      if (renamer.matches(name)) {
1✔
274
        return renamer.rename(name);
1✔
275
      }
276
    }
277

278
    // No renaming is provided for this declaration, return unchanged.
279
    return name;
280
  }
281
}
282

283
/// Match declaration name using [declarationRegExp].
284
class RegExpMemberRenamer {
285
  final RegExp declarationRegExp;
286
  final Renamer memberRenamer;
287

288
  RegExpMemberRenamer(this.declarationRegExp, this.memberRenamer);
1✔
289

290
  /// Returns true if [declaration] has a full match with [regExp].
291
  bool matchesDeclarationName(String declaration) =>
1✔
292
      quiver.matchesFull(declarationRegExp, declaration);
2✔
293

294
  @override
×
295
  String toString() {
296
    return 'DeclarationRegExp: $declarationRegExp, MemberRenamer: $memberRenamer';
×
297
  }
298
}
299

300
/// Handles `full/regexp` member renaming.
301
class MemberRenamer {
302
  final Map<String, Renamer> _memberRenameFull;
303
  final List<RegExpMemberRenamer> _memberRenameMatchers;
304

305
  final Map<String, Renamer> _cache = {};
306

307
  MemberRenamer({
50✔
308
    Map<String, Renamer>? memberRenameFull,
309
    List<RegExpMemberRenamer>? memberRenamePattern,
310
  })  : _memberRenameFull = memberRenameFull ?? {},
×
311
        _memberRenameMatchers = memberRenamePattern ?? [];
×
312

313
  String rename(String declaration, String member) {
29✔
314
    if (_cache.containsKey(declaration)) {
58✔
315
      return _cache[declaration]!.rename(member);
3✔
316
    }
317

318
    // Apply full rename (if any).
319
    if (_memberRenameFull.containsKey(declaration)) {
58✔
320
      // Add to cache.
321
      _cache[declaration] = _memberRenameFull[declaration]!;
4✔
322
      return _cache[declaration]!.rename(member);
3✔
323
    }
324

325
    // Apply rename regexp (if matches).
326
    for (final renamer in _memberRenameMatchers) {
30✔
327
      if (renamer.matchesDeclarationName(declaration)) {
1✔
328
        // Add to cache.
329
        _cache[declaration] = renamer.memberRenamer;
3✔
330
        return _cache[declaration]!.rename(member);
3✔
331
      }
332
    }
333

334
    // No renaming is provided for this declaration, return unchanged.
335
    return member;
336
  }
337
}
338

339
/// Handles config for automatically added compiler options.
340
class CompilerOptsAuto {
341
  final bool macIncludeStdLib;
342

343
  CompilerOptsAuto({bool? macIncludeStdLib})
50✔
344
      : macIncludeStdLib = macIncludeStdLib ?? true;
345

346
  /// Extracts compiler options based on OS and config.
347
  List<String> extractCompilerOpts() {
50✔
348
    if (Platform.isMacOS && macIncludeStdLib) {
100✔
349
      return getCStandardLibraryHeadersForMac();
49✔
350
    }
351

352
    return [];
1✔
353
  }
354
}
355

356
class _ObjCModulePrefixerEntry {
357
  final RegExp pattern;
358
  final String moduleName;
359

360
  _ObjCModulePrefixerEntry(this.pattern, this.moduleName);
2✔
361
}
362

363
/// Handles applying module prefixes to ObjC classes.
364
class ObjCModulePrefixer {
365
  final _prefixes = <_ObjCModulePrefixerEntry>[];
366

367
  ObjCModulePrefixer(Map<String, String> prefixes) {
50✔
368
    for (final entry in prefixes.entries) {
52✔
369
      _prefixes.add(_ObjCModulePrefixerEntry(RegExp(entry.key), entry.value));
12✔
370
    }
371
  }
372

373
  /// If any of the prefixing patterns match, applies that module prefix.
374
  /// Otherwise returns the class name unmodified.
375
  String applyPrefix(String className) {
2✔
376
    for (final entry in _prefixes) {
3✔
377
      if (quiver.matchesFull(entry.pattern, className)) {
2✔
378
        return '${entry.moduleName}.$className';
2✔
379
      }
380
    }
381
    return className;
382
  }
383
}
384

385
class FfiNativeConfig {
386
  final bool enabled;
387
  final String? asset;
388

389
  const FfiNativeConfig({required this.enabled, this.asset});
105✔
390
}
391

392
class SymbolFile {
393
  final String importPath;
394
  final String output;
395

396
  SymbolFile(this.importPath, this.output);
1✔
397
}
398

399
class OutputConfig {
400
  final String output;
401
  final SymbolFile? symbolFile;
402

403
  OutputConfig(this.output, this.symbolFile);
50✔
404
}
405

406
class RawVarArgFunction {
407
  String? postfix;
408
  final List<String> rawTypeStrings;
409

410
  RawVarArgFunction(this.postfix, this.rawTypeStrings);
1✔
411
}
412

413
class VarArgFunction {
414
  final String postfix;
415
  final List<Type> types;
416

417
  VarArgFunction(this.postfix, this.types);
23✔
418
}
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