This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
f0d4d9a
commit 5f12c73
Showing
14 changed files
with
374 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:ffigen/src/code_generator.dart'; | ||
import 'package:ffigen/src/header_parser/data.dart'; | ||
import 'package:ffigen/src/header_parser/includer.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
import '../clang_bindings/clang_bindings.dart' as clang_types; | ||
import '../data.dart'; | ||
import '../utils.dart'; | ||
|
||
final _logger = Logger('ffigen.header_parser.var_parser'); | ||
|
||
/// Parses a global variable | ||
Global? parseVarDeclaration(clang_types.CXCursor cursor) { | ||
final name = cursor.spelling(); | ||
final usr = cursor.usr(); | ||
if (bindingsIndex.isSeenGlobalVar(usr)) { | ||
return bindingsIndex.getSeenGlobalVar(usr); | ||
} | ||
if (!shouldIncludeGlobalVar(usr, name)) { | ||
return null; | ||
} | ||
|
||
_logger.fine('++++ Adding Global: ${cursor.completeStringRepr()}'); | ||
|
||
final type = cursor.type().toCodeGenType(); | ||
if (type.getBaseType().broadType == BroadType.Unimplemented || | ||
type.getBaseType().isIncompleteStruct) { | ||
_logger.fine( | ||
'---- Removed Global, reason: unsupported type: ${cursor.completeStringRepr()}'); | ||
_logger.warning("Skipped global variable '$name', type not supported."); | ||
return null; | ||
} | ||
|
||
final global = Global( | ||
originalName: name, | ||
name: config.globals.renameUsingConfig(name), | ||
usr: usr, | ||
type: type, | ||
dartDoc: getCursorDocComment(cursor), | ||
); | ||
bindingsIndex.addGlobalVarToSeen(usr, global); | ||
return global; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
bool coolGlobal; | ||
int32_t myInt; | ||
int32_t *aGlobalPointer; | ||
long double longDouble; | ||
long double *pointerToLongDouble; | ||
|
||
// This should be ignored | ||
int GlobalIgnore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:ffigen/src/code_generator.dart'; | ||
import 'package:ffigen/src/header_parser.dart' as parser; | ||
import 'package:ffigen/src/config_provider.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:yaml/yaml.dart' as yaml; | ||
import 'package:ffigen/src/strings.dart' as strings; | ||
|
||
import '../test_utils.dart'; | ||
|
||
late Library actual, expected; | ||
|
||
void main() { | ||
group('globals_test', () { | ||
setUpAll(() { | ||
logWarnings(); | ||
expected = expectedLibrary(); | ||
actual = parser.parse( | ||
Config.fromYaml(yaml.loadYaml(''' | ||
${strings.name}: 'NativeLibrary' | ||
${strings.description}: 'Globals Test' | ||
${strings.output}: 'unused' | ||
${strings.headers}: | ||
${strings.entryPoints}: | ||
- 'test/header_parser_tests/globals.h' | ||
${strings.includeDirectives}: | ||
- '**globals.h' | ||
${strings.globals}: | ||
${strings.exclude}: | ||
- GlobalIgnore | ||
# Needed for stdbool.h in MacOS | ||
${strings.compilerOpts}: '-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Headers/ -Wno-nullability-completeness' | ||
''') as yaml.YamlMap), | ||
); | ||
}); | ||
|
||
test('Total bindings count', () { | ||
expect(actual.bindings.length, expected.bindings.length); | ||
}); | ||
|
||
test('Parse global Values', () { | ||
expect(actual.getBindingAsString('coolGlobal'), | ||
expected.getBindingAsString('coolGlobal')); | ||
expect(actual.getBindingAsString('myInt'), | ||
expected.getBindingAsString('myInt')); | ||
expect(actual.getBindingAsString('aGlobalPointer'), | ||
expected.getBindingAsString('aGlobalPointer')); | ||
}); | ||
|
||
test('Ignore global values', () { | ||
expect(() => actual.getBindingAsString('GlobalIgnore'), | ||
throwsA(TypeMatcher<NotFoundException>())); | ||
expect(() => actual.getBindingAsString('longDouble'), | ||
throwsA(TypeMatcher<NotFoundException>())); | ||
expect(() => actual.getBindingAsString('pointerToLongDouble'), | ||
throwsA(TypeMatcher<NotFoundException>())); | ||
}); | ||
}); | ||
} | ||
|
||
Library expectedLibrary() { | ||
return Library( | ||
name: 'Bindings', | ||
bindings: [ | ||
Global(type: Type.boolean(), name: 'coolGlobal'), | ||
Global(type: Type.nativeType(SupportedNativeType.Int32), name: 'myInt'), | ||
Global( | ||
type: Type.pointer(Type.nativeType(SupportedNativeType.Int32)), | ||
name: 'aGlobalPointer'), | ||
], | ||
); | ||
} |
Oops, something went wrong.