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

Initial generator: functions, structs, enums #2

Merged
merged 91 commits into from
Jun 25, 2020
Merged

Initial generator: functions, structs, enums #2

merged 91 commits into from
Jun 25, 2020

Conversation

mannprerak2
Copy link
Contributor

@mannprerak2 mannprerak2 commented Jun 18, 2020

Features

  • Extract functions, structs, enums

Configurations

  • Specify list of headers (exact file path, or using glob)
  • Filtering
    • header_filters - filter declarations from a particular header using header name (base name only)
    • declaration filters - filter functions, structs, enums using regexp, name matching
    • pass compiler opts to clang
    • boolean flags to sort generated bindings, extract Doxygen doc comments from headers

mannprerak2 and others added 30 commits May 13, 2020 21:26
Commits till now:

Prerak Mann (6):
      init stagehand dart package template, minor changes
      Updated Project Structure, Readme
      Reading pubspec configuration via yaml package
      setup tool - libclang_binding_generator
      restructure code
      setup basic classes for code_generator
- updated code_generator's Func, Struct, Typedef to not use const, as it makes list unmodifiable
- added example from previous prototype
- print stack trace of dart functions called via C
- Updated dartdocs on clang_binding functions
- Added dispose methods in cx.. ..cursor,..type, ..string
- Updated parser code to handle disposing
- added new libclang example
- moved old example to example/simple
- Added sort method in code_generator library
- Sorted generated clang_bindings
- Added typedef declaration visitor for extracting typestring of typedef parameters
- Added new methods to wrapper.c for getting type declarations
Merge branch 'master' of github.com:dart-lang/ffigen into v0.1
- prefer_final_fields
- prefer_final_locals
- prefer_final_in_for_each
User now has an option to provide a seperate folder containing the dynamic library
The default is to use the dynamic libraries in the tool/wrapped_libclang folder
User can provide any file path or glob matcher.
If clang can't parse a header, we print a severe log
and skip that header
@mit-mit
Copy link
Contributor

mit-mit commented Jun 22, 2020

Test comment for cla bot

@mit-mit
Copy link
Contributor

mit-mit commented Jun 22, 2020

@mit-mit It looks like the Google copyright bot does not check copyright at the moment. Is this is because our repo is private?

CLA bot has been fixed (there was a mis-config)

pubspec.yaml Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
example/c_json/third_party/cjson_library/cJSON.c Outdated Show resolved Hide resolved
lib/src/code_generator/library.dart Outdated Show resolved Hide resolved
example/simple/generated_bindings.dart Outdated Show resolved Hide resolved
example/libclang-example/pubspec.yaml Outdated Show resolved Hide resolved
example/libclang-example/pubspec.yaml Outdated Show resolved Hide resolved
example/simple/generated_bindings.dart Outdated Show resolved Hide resolved
example/simple/.gitignore Outdated Show resolved Hide resolved
- Added test/native_function_test/build_test_dylib.dart
- Updated comments
- Added top level third_party folder
- Updated examples, test with fixed comments
Preamble on generated files is now
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
.gitignore Outdated Show resolved Hide resolved
bin/generate.dart Outdated Show resolved Hide resolved
example/c_json/main.dart Show resolved Hide resolved
example/libclang-example/pubspec.yaml Outdated Show resolved Hide resolved
lib/src/code_generator/binding_string.dart Outdated Show resolved Hide resolved
tool/wrapped_libclang/build.dart Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@@ -0,0 +1,1447 @@
/// AUTO GENERATED FILE, DO NOT EDIT.
///
/// Generated by `package:ffigen`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be kind of nice to know the relative path of the config that generated this. (As you mentioned absolute paths may not make sense and are OS specific.) It will be hard for people to figure out that they need to follow the command in tool/*.yaml

Also: please regen with the latest code. I have same changes when I run it locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a preamble config in another branch(prefix_and_names). Using which we can add anything as the file header.
Should I do it using that? If yes, maybe I can do this in that PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it in the PR instead then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: please regen with the latest code. I have some changes...

Strange I don't see any changes when I re-generate bindings, can you describe the changes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I replied in the PR thread instead of this one. Looks like my version of clang/llvm is different, so it generates less constants. Probably nothing to worry about.

Do we have a minimum clang/llvm version required for this to work? (e.g. when were the methods/constants added which we use in this package?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to test this

tool/libclang_config.yaml Outdated Show resolved Hide resolved
- Added map of <String, Options> for storing default values for all platforms
- Using Options instead of global variables
@dcharkes
Copy link
Contributor

dcharkes commented Jun 24, 2020

diff --git a/lib/src/header_parser/clang_bindings/clang_bindings.dart b/lib/src/header_parser/clang_bindings/clang_bindings.dart
index f701971..788ccd2 100644
--- a/lib/src/header_parser/clang_bindings/clang_bindings.dart
+++ b/lib/src/header_parser/clang_bindings/clang_bindings.dart
@@ -279,13 +279,7 @@ class CXCursorKind {
   static const int CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective =
       278;
   static const int CXCursor_OMPTargetTeamsDistributeSimdDirective = 279;
-  static const int CXCursor_BuiltinBitCastExpr = 280;
-  static const int CXCursor_OMPMasterTaskLoopDirective = 281;
-  static const int CXCursor_OMPParallelMasterTaskLoopDirective = 282;
-  static const int CXCursor_OMPMasterTaskLoopSimdDirective = 283;
-  static const int CXCursor_OMPParallelMasterTaskLoopSimdDirective = 284;
-  static const int CXCursor_OMPParallelMasterDirective = 285;
-  static const int CXCursor_LastStmt = 285;
+  static const int CXCursor_LastStmt = 279;
   static const int CXCursor_TranslationUnit = 300;
   static const int CXCursor_FirstAttr = 400;
   static const int CXCursor_UnexposedAttr = 400;
@@ -308,29 +302,7 @@ class CXCursorKind {
   static const int CXCursor_VisibilityAttr = 417;
   static const int CXCursor_DLLExport = 418;
   static const int CXCursor_DLLImport = 419;
-  static const int CXCursor_NSReturnsRetained = 420;
-  static const int CXCursor_NSReturnsNotRetained = 421;
-  static const int CXCursor_NSReturnsAutoreleased = 422;
-  static const int CXCursor_NSConsumesSelf = 423;
-  static const int CXCursor_NSConsumed = 424;
-  static const int CXCursor_ObjCException = 425;
-  static const int CXCursor_ObjCNSObject = 426;
-  static const int CXCursor_ObjCIndependentClass = 427;
-  static const int CXCursor_ObjCPreciseLifetime = 428;
-  static const int CXCursor_ObjCReturnsInnerPointer = 429;
-  static const int CXCursor_ObjCRequiresSuper = 430;
-  static const int CXCursor_ObjCRootClass = 431;
-  static const int CXCursor_ObjCSubclassingRestricted = 432;
-  static const int CXCursor_ObjCExplicitProtocolImpl = 433;
-  static const int CXCursor_ObjCDesignatedInitializer = 434;
-  static const int CXCursor_ObjCRuntimeVisible = 435;
-  static const int CXCursor_ObjCBoxable = 436;
-  static const int CXCursor_FlagEnum = 437;
-  static const int CXCursor_ConvergentAttr = 438;
-  static const int CXCursor_WarnUnusedAttr = 439;
-  static const int CXCursor_WarnUnusedResultAttr = 440;
-  static const int CXCursor_AlignedAttr = 441;
-  static const int CXCursor_LastAttr = 441;
+  static const int CXCursor_LastAttr = 419;
   static const int CXCursor_PreprocessingDirective = 500;
   static const int CXCursor_MacroDefinition = 501;
   static const int CXCursor_MacroExpansion = 502;
@@ -443,10 +415,6 @@ class CXTranslationUnit_Flags {
   static const int CXTranslationUnit_KeepGoing = 512;
   static const int CXTranslationUnit_SingleFileParse = 1024;
   static const int CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 2048;
-  static const int CXTranslationUnit_IncludeAttributedTypes = 4096;
-  static const int CXTranslationUnit_VisitImplicitAttributes = 8192;
-  static const int CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles = 16384;
-  static const int CXTranslationUnit_RetainExcludedConditionalBlocks = 32768;
 }
 
 /// The type of an element in the abstract syntax tree.
@@ -614,22 +582,6 @@ class CXTypeKind {
   static const int CXType_OCLEvent = 158;
   static const int CXType_OCLQueue = 159;
   static const int CXType_OCLReserveID = 160;
-  static const int CXType_ObjCObject = 161;
-  static const int CXType_ObjCTypeParam = 162;
-  static const int CXType_Attributed = 163;
-  static const int CXType_OCLIntelSubgroupAVCMcePayload = 164;
-  static const int CXType_OCLIntelSubgroupAVCImePayload = 165;
-  static const int CXType_OCLIntelSubgroupAVCRefPayload = 166;
-  static const int CXType_OCLIntelSubgroupAVCSicPayload = 167;
-  static const int CXType_OCLIntelSubgroupAVCMceResult = 168;
-  static const int CXType_OCLIntelSubgroupAVCImeResult = 169;
-  static const int CXType_OCLIntelSubgroupAVCRefResult = 170;
-  static const int CXType_OCLIntelSubgroupAVCSicResult = 171;
-  static const int CXType_OCLIntelSubgroupAVCImeResultSingleRefStreamout = 172;
-  static const int CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout = 173;
-  static const int CXType_OCLIntelSubgroupAVCImeSingleRefStreamin = 174;
-  static const int CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175;
-  static const int CXType_ExtVector = 176;
 }
 
 /// Provides the contents of a file that has not yet been saved to disk.
diff --git a/tool/libclang_config.yaml b/tool/libclang_config.yaml
index 144eb97..575a440 100644
--- a/tool/libclang_config.yaml
+++ b/tool/libclang_config.yaml
@@ -12,7 +12,7 @@
 output: '../lib/src/header_parser/clang_bindings/clang_bindings.dart'
 libclang-dylib-folder: 'wrapped_libclang'
 sort: true
-compiler-opts: '-I/usr/lib/llvm-9/include/ -I/usr/lib/llvm-10/include/ -I/usr/local/opt/llvm/include/'
+compiler-opts: '-I/usr/lib/llvm-9/include/ -I/usr/lib/llvm-10/include/ -I/usr/local/opt/llvm/include/ -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/'
 headers:
   - 'wrapped_libclang/wrapper.c'
 header-filter:
diff --git a/tool/wrapped_libclang/.gitignore b/tool/wrapped_libclang/.gitignore
index 2b64ac7..29e318c 100644
--- a/tool/wrapped_libclang/.gitignore
+++ b/tool/wrapped_libclang/.gitignore
@@ -10,3 +10,4 @@ install_manifest.txt
 compile_commands.json
 CTestTestfile.cmake
 _deps
+libwrapped_clang.dylib

(diff on Mac)

tool/libclang_config.yaml Outdated Show resolved Hide resolved
example/c_json/main.dart Outdated Show resolved Hide resolved
lib/src/header_parser/sub_parsers/structdecl_parser.dart Outdated Show resolved Hide resolved
lib/src/header_parser/utils.dart Show resolved Hide resolved
lib/src/code_generator/writer.dart Outdated Show resolved Hide resolved
lib/src/config_provider/spec_utils.dart Outdated Show resolved Hide resolved
lib/src/header_parser/utils.dart Show resolved Hide resolved
lib/src/header_parser/parser.dart Outdated Show resolved Hide resolved
lib/src/header_parser/parser.dart Outdated Show resolved Hide resolved
lib/src/header_parser/translation_unit_parser.dart Outdated Show resolved Hide resolved
lib/src/code_generator/library.dart Outdated Show resolved Hide resolved
@dcharkes dcharkes changed the title V0.1 Initial generator: functions, structs, enums Jun 25, 2020
@dcharkes dcharkes merged commit be5ed0d into dart-archive:master Jun 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants