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

Commit

Permalink
Merge b36ae53 into f2acaae
Browse files Browse the repository at this point in the history
  • Loading branch information
mannprerak2 committed Aug 12, 2020
2 parents f2acaae + b36ae53 commit 88c752a
Show file tree
Hide file tree
Showing 19 changed files with 410 additions and 61 deletions.
26 changes: 23 additions & 3 deletions example/c_json/cjson_generated_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
// Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Holds bindings to cJSON.
Expand Down
21 changes: 21 additions & 0 deletions example/c_json/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,24 @@ ffigen:
include-directives:
- '**cJSON.h'
comments: false

preamble: |
// Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
12 changes: 8 additions & 4 deletions example/libclang-example/generated_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
// Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Holds bindings to LibClang.
Expand Down
13 changes: 7 additions & 6 deletions example/libclang-example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ ffigen:
# False by default.
array-workaround: true

# The header of the file, this is pasted as it is.
preamble: |
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
# Doc Comments for generated binings.
# Comments can be disabled by using comments: false
comments:
style: doxygen # Options - doxygen(default) / any.
length: full # Options - brief / full(default).

# The header of the file, this is pasted as it is.
preamble: |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
// Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 changes: 3 additions & 3 deletions example/simple/generated_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Bindings to `headers/example.h`.
Expand Down
14 changes: 13 additions & 1 deletion lib/src/code_generator/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class UniqueNamer {
UniqueNamer clone() => UniqueNamer._raw({..._usedUpNames});
}

/// Converts [text] to a dart doc comment.
/// Converts [text] to a dart doc comment(`///`).
///
/// Comment is split on new lines only.
String makeDartDoc(String text) {
Expand All @@ -58,3 +58,15 @@ String makeDartDoc(String text) {

return s.toString();
}

/// Converts [text] to a dart comment (`//`).
///
/// Comment is split on new lines only.
String makeDoc(String text) {
final s = StringBuffer();
s.write('// ');
s.writeAll(text.split('\n'), '\n// ');
s.write('\n');

return s.toString();
}
8 changes: 4 additions & 4 deletions lib/src/code_generator/writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class Writer {
if (header != null) {
s.write(header);
s.write('\n');
} else {
// Write default header, in case none was provided.
s.write(makeDartDoc(
'AUTO GENERATED FILE, DO NOT EDIT.\n\nGenerated by `package:ffigen`.'));
}

// Write auto generated declaration.
s.write(makeDoc(
'AUTO GENERATED FILE, DO NOT EDIT.\n\nGenerated by `package:ffigen`.'));

// Write neccesary imports.
s.write("import 'dart:ffi' as $ffiLibraryPrefix;\n");
s.write('\n');
Expand Down
11 changes: 8 additions & 3 deletions lib/src/header_parser/clang_bindings/clang_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
// Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Holds bindings to LibClang.
Expand Down
42 changes: 21 additions & 21 deletions test/code_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ void main() {
'test/debug_generated/Function-Binding-test-output.dart',
);
try {
expect(gen, '''/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
expect(gen, '''// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;
class Bindings{
Expand Down Expand Up @@ -232,9 +232,9 @@ typedef _dart_withPointerParam = ffi.Pointer<ffi.Double> Function(
final file = File('test/debug_generated/Struct-Binding-test-output.dart');

try {
expect(gen, '''/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
expect(gen, '''// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;
/// Just a test struct
Expand Down Expand Up @@ -333,9 +333,9 @@ class WithPointerMember extends ffi.Struct{
File('test/debug_generated/Func-n-Struct-Binding-test-output.dart');
try {
//expect
expect(gen, '''/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
expect(gen, '''// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;
class Bindings{
Expand Down Expand Up @@ -428,9 +428,9 @@ typedef _dart_someFunc = ffi.Pointer<SomeStruc> Function(
'test/debug_generated/Global-Binding-test-output.dart',
);
try {
expect(gen, '''/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
expect(gen, '''// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;
class Bindings{
Expand Down Expand Up @@ -489,9 +489,9 @@ class Some extends ffi.Struct{
'test/debug_generated/Constant-test-output.dart',
);
try {
expect(gen, '''/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
expect(gen, '''// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;
const int test1 = 20;
Expand Down Expand Up @@ -534,9 +534,9 @@ const double test2 = 20.0;
'test/debug_generated/enum-class-test-output.dart',
);
try {
expect(gen, '''/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
expect(gen, '''// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;
/// test line 1
Expand Down Expand Up @@ -608,9 +608,9 @@ abstract class Constants {
'test/debug_generated/internal-conflict-resolution.dart',
);
try {
expect(gen, r'''/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
expect(gen, r'''// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;
class init_dylib_1{
Expand Down
20 changes: 20 additions & 0 deletions test/example_tests/cjson_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ ${strings.headers}:
${strings.includeDirectives}:
- '**cJSON.h'
${strings.comments}: false
${strings.preamble}: |
// Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
''') as YamlMap);
final library = parse(config);

Expand Down
10 changes: 6 additions & 4 deletions test/example_tests/libclang_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ ${strings.enums}:
${strings.name}: 'LibClang'
${strings.description}: 'Holds bindings to LibClang.'
${strings.arrayWorkaround}: true
${strings.preamble}: |
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
${strings.comments}:
${strings.style}: ${strings.doxygen}
${strings.length}: ${strings.full}
${strings.preamble}: |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
// Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
''') as YamlMap);
final library = parse(config);

Expand Down
6 changes: 3 additions & 3 deletions test/large_integration_tests/_expected_cjson_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Bindings to Cjson.
Expand Down
6 changes: 3 additions & 3 deletions test/large_integration_tests/_expected_libclang_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Bindings to LibClang.
Expand Down
6 changes: 3 additions & 3 deletions test/large_integration_tests/_expected_sqlite_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Bindings to SQLite.
Expand Down
6 changes: 3 additions & 3 deletions test/native_test/native_test_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Native tests.
Expand Down
24 changes: 24 additions & 0 deletions third_party/cjson_library/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


Files generated from cJSON source code are
- example/c_json/cjson_generated_bindings.dart
- test/large_integration_tests/_expected_cjson_bindings.dart
Loading

0 comments on commit 88c752a

Please sign in to comment.