Skip to content
This repository was archived by the owner on Jan 28, 2024. It is now read-only.

Commit f3b001d

Browse files
authored
Skip inline functions (#147) (#167)
1 parent 60718d1 commit f3b001d

File tree

7 files changed

+46
-1
lines changed

7 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 2.0.0-dev.6
2+
- Functions marked `inline` are now skipped.
3+
14
# 2.0.0-dev.5
25
- Use `Opaque` for representing empty `Struct`s.
36

lib/src/header_parser/clang_bindings/clang_bindings.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,21 @@ class Clang {
510510

511511
_dart_clang_Cursor_isMacroBuiltin? _clang_Cursor_isMacroBuiltin;
512512

513+
/// Determine whether a CXCursor that is a function declaration, is an
514+
/// inline declaration.
515+
int clang_Cursor_isFunctionInlined(
516+
CXCursor C,
517+
) {
518+
return (_clang_Cursor_isFunctionInlined ??= _dylib.lookupFunction<
519+
_c_clang_Cursor_isFunctionInlined,
520+
_dart_clang_Cursor_isFunctionInlined>(
521+
'clang_Cursor_isFunctionInlined'))(
522+
C,
523+
);
524+
}
525+
526+
_dart_clang_Cursor_isFunctionInlined? _clang_Cursor_isFunctionInlined;
527+
513528
/// For pointer types, returns the type of the pointee.
514529
CXType clang_getPointeeType(
515530
CXType T,
@@ -2563,6 +2578,14 @@ typedef _dart_clang_Cursor_isMacroBuiltin = int Function(
25632578
CXCursor C,
25642579
);
25652580

2581+
typedef _c_clang_Cursor_isFunctionInlined = ffi.Uint32 Function(
2582+
CXCursor C,
2583+
);
2584+
2585+
typedef _dart_clang_Cursor_isFunctionInlined = int Function(
2586+
CXCursor C,
2587+
);
2588+
25662589
typedef _c_clang_getPointeeType = CXType Function(
25672590
CXType T,
25682591
);

lib/src/header_parser/sub_parsers/functiondecl_parser.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ Func? parseFunctionDeclaration(clang_types.CXCursor cursor) {
3535
final rt = _getFunctionReturnType(cursor);
3636
final parameters = _getParameters(cursor, funcName);
3737

38+
if (clang.clang_Cursor_isFunctionInlined(cursor) != 0) {
39+
_logger.fine(
40+
'---- Removed Function, reason: inline function: ${cursor.completeStringRepr()}');
41+
_logger.warning(
42+
"Skipped Function '$funcName', inline functions are not supported.");
43+
return _stack
44+
.pop()
45+
.func; // Returning null so that [addToBindings] function excludes this.
46+
}
47+
3848
if (rt.isIncompleteStruct || _stack.top.incompleteStructParameter) {
3949
_logger.fine(
4050
'---- Removed Function, reason: Incomplete struct pass/return by value: ${cursor.completeStringRepr()}');

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# BSD-style license that can be found in the LICENSE file.
44

55
name: ffigen
6-
version: 2.0.0-dev.5
6+
version: 2.0.0-dev.6
77
homepage: https://github.com/dart-lang/ffigen
88
description: Experimental generator for FFI bindings, using LibClang to parse C header files.
99

test/header_parser_tests/functions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ void *func4(int8_t **, double, int32_t ***);
1616
typedef void shortHand(void(b)());
1717
// Would be treated as `void func5(shortHand *a, void (*b)())`.
1818
void func5(shortHand a, void(b)());
19+
20+
// Should be skipped as inline functions are not supported.
21+
static inline void inlineFunc();

test/header_parser_tests/functions_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ ${strings.headers}:
5858
expect(actual.getBindingAsString('func5'),
5959
expected.getBindingAsString('func5'));
6060
});
61+
62+
test('Skip inline functions', () {
63+
expect(() => actual.getBindingAsString('inlineFunc'),
64+
throwsA(TypeMatcher<NotFoundException>()));
65+
});
6166
});
6267
}
6368

tool/libclang_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ functions:
101101
- clang_Cursor_isAnonymousRecordDecl
102102
- clang_getCursorUSR
103103
- clang_getFieldDeclBitWidth
104+
- clang_Cursor_isFunctionInlined

0 commit comments

Comments
 (0)