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

Commit

Permalink
Allow extern inline functions to be generated. (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
mannprerak2 authored Jul 24, 2023
1 parent af6d72c commit 05f0952
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 9.0.1

- Fix doc comment missing on struct/union array fields.
- Allow extern inline functions to be generated.

# 9.0.0

Expand Down
31 changes: 31 additions & 0 deletions lib/src/header_parser/clang_bindings/clang_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,24 @@ class Clang {
_clang_Cursor_isAnonymousRecordDeclPtr
.asFunction<int Function(CXCursor)>();

/// Returns the storage class for a function or variable declaration.
///
/// If the passed in Cursor is not a function or variable declaration,
/// CX_SC_Invalid is returned else the storage class.
int clang_Cursor_getStorageClass(
CXCursor arg0,
) {
return _clang_Cursor_getStorageClass(
arg0,
);
}

late final _clang_Cursor_getStorageClassPtr =
_lookup<ffi.NativeFunction<ffi.Int32 Function(CXCursor)>>(
'clang_Cursor_getStorageClass');
late final _clang_Cursor_getStorageClass =
_clang_Cursor_getStorageClassPtr.asFunction<int Function(CXCursor)>();

/// Visit the children of a particular cursor.
///
/// This function visits all the direct children of the given cursor,
Expand Down Expand Up @@ -2564,6 +2582,19 @@ abstract class CXTypeLayoutError {
static const int CXTypeLayoutError_Undeduced = -6;
}

/// Represents the storage classes as declared in the source. CX_SC_Invalid
/// was added for the case that the passed cursor in not a declaration.
abstract class CX_StorageClass {
static const int CX_SC_Invalid = 0;
static const int CX_SC_None = 1;
static const int CX_SC_Extern = 2;
static const int CX_SC_Static = 3;
static const int CX_SC_PrivateExtern = 4;
static const int CX_SC_OpenCLWorkGroupLocal = 5;
static const int CX_SC_Auto = 6;
static const int CX_SC_Register = 7;
}

/// Describes how the traversal of the children of a particular
/// cursor should proceed after visiting a particular child cursor.
///
Expand Down
5 changes: 3 additions & 2 deletions lib/src/header_parser/sub_parsers/functiondecl_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ List<Func>? parseFunctionDeclaration(clang_types.CXCursor cursor) {

final rt = _getFunctionReturnType(cursor);
final parameters = _getParameters(cursor, funcName);

if (clang.clang_Cursor_isFunctionInlined(cursor) != 0) {
if (clang.clang_Cursor_isFunctionInlined(cursor) != 0 &&
clang.clang_Cursor_getStorageClass(cursor) !=
clang_types.CX_StorageClass.CX_SC_Extern) {
_logger.fine('---- Removed Function, reason: inline function: '
'${cursor.completeStringRepr()}');
_logger.warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ class NativeLibrary {
void Function(ffi.Pointer<shortHand>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>();

void externInlineFunc(
int a,
) {
return _externInlineFunc(
a,
);
}

late final _externInlineFuncPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>(
'externInlineFunc');
late final _externInlineFunc =
_externInlineFuncPtr.asFunction<void Function(int)>();

int diffChars(
int a,
int b,
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 @@ -20,4 +20,7 @@ void func5(shortHand a, void(b)());
// Should be skipped as inline functions are not supported.
static inline void inlineFunc();

// Not skipped since it is extern.
extern inline void externInlineFunc(int a);

char diffChars(unsigned char a, signed char b);
1 change: 1 addition & 0 deletions tool/libclang_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ functions:
- clang_getNumArgTypes
- clang_getArgType
- clang_isFunctionTypeVariadic
- clang_Cursor_getStorageClass
- clang_getCursorResultType
- clang_getEnumConstantDeclValue
- clang_equalRanges
Expand Down

0 comments on commit 05f0952

Please sign in to comment.