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

Skip inline functions #147

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.0.0-dev.6
- Functions marked `inline` are now skipped.

# 2.0.0-dev.5
- Use `Opaque` for representing empty `Struct`s.

Expand Down
23 changes: 23 additions & 0 deletions lib/src/header_parser/clang_bindings/clang_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,21 @@ class Clang {

_dart_clang_Cursor_isMacroBuiltin? _clang_Cursor_isMacroBuiltin;

/// Determine whether a CXCursor that is a function declaration, is an
/// inline declaration.
int clang_Cursor_isFunctionInlined(
CXCursor C,
) {
return (_clang_Cursor_isFunctionInlined ??= _dylib.lookupFunction<
_c_clang_Cursor_isFunctionInlined,
_dart_clang_Cursor_isFunctionInlined>(
'clang_Cursor_isFunctionInlined'))(
C,
);
}

_dart_clang_Cursor_isFunctionInlined? _clang_Cursor_isFunctionInlined;

/// For pointer types, returns the type of the pointee.
CXType clang_getPointeeType(
CXType T,
Expand Down Expand Up @@ -2563,6 +2578,14 @@ typedef _dart_clang_Cursor_isMacroBuiltin = int Function(
CXCursor C,
);

typedef _c_clang_Cursor_isFunctionInlined = ffi.Uint32 Function(
CXCursor C,
);

typedef _dart_clang_Cursor_isFunctionInlined = int Function(
CXCursor C,
);

typedef _c_clang_getPointeeType = CXType Function(
CXType T,
);
Expand Down
10 changes: 10 additions & 0 deletions lib/src/header_parser/sub_parsers/functiondecl_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ Func? parseFunctionDeclaration(clang_types.CXCursor cursor) {
final rt = _getFunctionReturnType(cursor);
final parameters = _getParameters(cursor, funcName);

if (clang.clang_Cursor_isFunctionInlined(cursor) != 0) {
_logger.fine(
'---- Removed Function, reason: inline function: ${cursor.completeStringRepr()}');
_logger.warning(
"Skipped Function '$funcName', inline functions are not supported.");
return _stack
.pop()
.func; // Returning null so that [addToBindings] function excludes this.
}

if (rt.isIncompleteStruct || _stack.top.incompleteStructParameter) {
_logger.fine(
'---- Removed Function, reason: Incomplete struct pass/return by value: ${cursor.completeStringRepr()}');
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# BSD-style license that can be found in the LICENSE file.

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

Expand Down
3 changes: 3 additions & 0 deletions test/header_parser_tests/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ void *func4(int8_t **, double, int32_t ***);
typedef void shortHand(void(b)());
// Would be treated as `void func5(shortHand *a, void (*b)())`.
void func5(shortHand a, void(b)());

// Should be skipped as inline functions are not supported.
static inline void inlineFunc();
5 changes: 5 additions & 0 deletions test/header_parser_tests/functions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ ${strings.headers}:
expect(actual.getBindingAsString('func5'),
expected.getBindingAsString('func5'));
});

test('Skip inline functions', () {
expect(() => actual.getBindingAsString('inlineFunc'),
throwsA(TypeMatcher<NotFoundException>()));
});
});
}

Expand Down
1 change: 1 addition & 0 deletions tool/libclang_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ functions:
- clang_Cursor_isAnonymousRecordDecl
- clang_getCursorUSR
- clang_getFieldDeclBitWidth
- clang_Cursor_isFunctionInlined