This repository was 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
Globals #139
Merged
Merged
Globals #139
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ee5a5f8
globals generated
TimWhiting 6dcd229
remove manual late initialization instead using the non-nullable late…
TimWhiting 7d41bd6
fix naming and globals test
TimWhiting 91651a9
add typedef dependencies of globals
TimWhiting ff8d605
just fixing some naming to make more sense
TimWhiting 3cf263e
updates with test, and exclude params
TimWhiting ab929f9
update readme to include globals
TimWhiting ef5b56f
address review comments
TimWhiting a50526a
a last log statement
TimWhiting 905ba09
address comments
TimWhiting File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
// Copyright (c) 2020, 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; | ||
} | ||
|
||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) 2020, the Dart project authors. Please see the AUTHORS file | ||
TimWhiting marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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 hidden or 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,73 @@ | ||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file | ||
TimWhiting marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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 | ||
''') 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.