www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Oh My Gentool [v0.0.1] (Yet another binding generator)

reply evilrat <evilrat666 gmail.com> writes:
(Oh My) Gentool v0.0.1 is just released!

What it is?
Binding generator with C/C++ support(primarilly C++) that outputs 
D bindings.

Internally it is using clang for all heavy lifting work. The code 
itself is not yet stabilized but is open for everyone to play 
with or use in just any way possible.

This is the first public "stable" release.


Why?
I just needed something that generates stuff to use C++ libs from 
D.
Doing this manually is tiresome, so I made this tool to help me 
automate the process. It is not fully automated, I just use it to 
generate bulk of the code, and then do necessary fixes and 
clean-ups here and there.
I know there is already several tools existed, but I don't care 
much about C(which they DO care) and others proves to be too 
complicated to set up or use (or both)(esp. on Windows)
It just generates bindings that is available for tools to parse 
to provide autocompletion.


Target audience?
- Let's be honest - Me, and only me.

But here is who might be interested as well:
- Experienced C++ users who wants to move to D for whatever 
reason but needs their usual stuff that doesn't have analogs in 
D. (sorry, but no Boost support and so on)
- Gamedev people?
- Any other users who wants to try this fancy C++ library but 
lacks C++ skills.
- As for me - I did it to reuse existing gamedev and content 
pipeline libs, because reimplementing all the stuff in D is not 
feasible and impractical from maintenance point of view. Not 
mentioning that not all of them provided with sources.


Limitations?
There are many.
The most important is - It doesn't tries to 'port' STL or BOOST 
or any other template-only library.
It is targeting D 2.083 with namespaces as string by default, 
there is no option to generate legacy style namespaces. (ok, 
there is hacky one, but it is hard coded option)
Not all language contructs are supported, or their support 
quality is poor.
Now when I added separate preprocessor pass one can enjoy the 
full genuine C++ compilation speed(lack of), yay \0/


Links:

Sources is available at
https://github.com/Superbelko/ohmygentool

There is few short wiki pages available at
https://github.com/Superbelko/ohmygentool/wiki

This release comes with prebuilt binaries for Linux x64 and 
Windows x64
https://github.com/Superbelko/ohmygentool/releases

(Since I'm linux noob this linux binaries might be screwed up and 
just not work at all)
Oct 23
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2018-10-23 09:42, evilrat wrote:

 I know there is already several tools existed, but I don't care much 
 about C(which they DO care)
To be able to handle C++ one needs to be able to handle C. It makes sense to start with C. -- /Jacob Carlborg
Oct 23
parent evilrat <evilrat666 gmail.com> writes:
On Tuesday, 23 October 2018 at 09:25:50 UTC, Jacob Carlborg wrote:
 On 2018-10-23 09:42, evilrat wrote:

 I know there is already several tools existed, but I don't 
 care much about C(which they DO care)
To be able to handle C++ one needs to be able to handle C. It makes sense to start with C.
I'm sorry if this is confusing. It does handle C as well, it just does so as by-product, and this is not my goal, C++ is. All I said is that there is tools that does C just fine, it is just C++ that lacks them. If that's not what you mean can you then explain what is the problem?
Oct 23
prev sibling next sibling parent reply 12345swordy <alexanderheistermann gmail.com> writes:
On Tuesday, 23 October 2018 at 07:42:56 UTC, evilrat wrote:
 (Oh My) Gentool v0.0.1 is just released!

 What it is?
 Binding generator with C/C++ support(primarilly C++) that 
 outputs D bindings.

 [...]
Don't we have dpp for this?
Oct 23
parent reply Andrea Fontana <nospam example.com> writes:
On Tuesday, 23 October 2018 at 14:45:06 UTC, 12345swordy wrote:
 On Tuesday, 23 October 2018 at 07:42:56 UTC, evilrat wrote:
 (Oh My) Gentool v0.0.1 is just released!

 What it is?
 Binding generator with C/C++ support(primarilly C++) that 
 outputs D bindings.

 [...]
Don't we have dpp for this?
Not yet :)
Oct 23
parent reply Atila Neves <atila.neves gmail.com> writes:
On Tuesday, 23 October 2018 at 15:44:06 UTC, Andrea Fontana wrote:
 On Tuesday, 23 October 2018 at 14:45:06 UTC, 12345swordy wrote:
 On Tuesday, 23 October 2018 at 07:42:56 UTC, evilrat wrote:
 (Oh My) Gentool v0.0.1 is just released!

 What it is?
 Binding generator with C/C++ support(primarilly C++) that 
 outputs D bindings.

 [...]
Don't we have dpp for this?
Not yet :)
We do - it's just very far from being complete. dpp can do some simple C++ and would have been able to do C-with-classes-style C++ ages ago. My focus is on templates though, since for me I can't see any useful C++ libraries that I'd actually want to call from D that don't use templates. And sometimes it's as silly as wanting to bind to an existing not-that-complicated library that happens to have a std::vector in its structs. For that, you need to be able to translate the standard library. A cursory glance shows me that Oh My Gentool doesn't yet do operator overloading or move/copy constructors yet for instance, and dpp does both of those right now (modulo bugs). However, the more, the merrier!
Oct 23
parent reply Andrea Fontana <nospam example.com> writes:
On Tuesday, 23 October 2018 at 20:03:42 UTC, Atila Neves wrote:
 We do - it's just very far from being complete. dpp can do some 
 simple C++ and would have been able to do C-with-classes-style 
 C++ ages ago. My focus is on templates though, since for me I 
 can't see any useful C++ libraries that I'd actually want to 
 call from D that don't use templates. And sometimes it's as 
 silly as wanting to bind to an existing not-that-complicated 
 library that happens to have a std::vector in its structs. For 
 that, you need to be able to translate the standard library.
Interesting. I'm using it for many different c libraries but I didn't think it worked for c++ already! The only problem I found with DPP is that simple consts declared with #define are not translated if not explicitly used. I think i can understand the reason (macro evaluation, I guess) but it would be useful to have a way to export them if they are simple consts...
Oct 23
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2018-10-23 22:32, Andrea Fontana wrote:

 Interesting. I'm using it for many different c libraries but I didn't 
 think it worked for c++  already!
 
 The only problem I found with DPP is that simple consts declared with 
 #define are not translated if not explicitly used. I think i can 
 understand the reason (macro evaluation, I guess) but it would be useful 
 to have a way to export them if they are simple consts...
DStep [1] will do that (build from master). But you might need dpp for different reasons. [1] http://github.com/jacob-carlborg/dstep -- /Jacob Carlborg
Oct 24
prev sibling parent reply Atila Neves <atila.neves gmail.com> writes:
On Tuesday, 23 October 2018 at 20:32:29 UTC, Andrea Fontana wrote:
 On Tuesday, 23 October 2018 at 20:03:42 UTC, Atila Neves wrote:
 We do - it's just very far from being complete. dpp can do 
 some simple C++ and would have been able to do 
 C-with-classes-style C++ ages ago. My focus is on templates 
 though, since for me I can't see any useful C++ libraries that 
 I'd actually want to call from D that don't use templates. And 
 sometimes it's as silly as wanting to bind to an existing 
 not-that-complicated library that happens to have a 
 std::vector in its structs. For that, you need to be able to 
 translate the standard library.
Interesting. I'm using it for many different c libraries but I didn't think it worked for c++ already! The only problem I found with DPP is that simple consts declared with #define are not translated if not explicitly used. I think i can understand the reason (macro evaluation, I guess) but it would be useful to have a way to export them if they are simple consts...
The whole idea of dpp is to be able to use headers as they are used in C and C++. Macros there don't exist unless they're expanded, so it's the same thing with dpp. Maybe it's good idea to add a runtime flag to translate non-function-like macros as enums... hmm.
Oct 27
parent evilrat <evilrat666 gmail.com> writes:
On Saturday, 27 October 2018 at 16:55:23 UTC, Atila Neves wrote:
 On Tuesday, 23 October 2018 at 20:32:29 UTC, Andrea Fontana 
 wrote:
 On Tuesday, 23 October 2018 at 20:03:42 UTC, Atila Neves wrote:
 We do - it's just very far from being complete. dpp can do 
 some simple C++ and would have been able to do 
 C-with-classes-style C++ ages ago. My focus is on templates 
 though, since for me I can't see any useful C++ libraries 
 that I'd actually want to call from D that don't use 
 templates. And sometimes it's as silly as wanting to bind to 
 an existing not-that-complicated library that happens to have 
 a std::vector in its structs. For that, you need to be able 
 to translate the standard library.
Interesting. I'm using it for many different c libraries but I didn't think it worked for c++ already! The only problem I found with DPP is that simple consts declared with #define are not translated if not explicitly used. I think i can understand the reason (macro evaluation, I guess) but it would be useful to have a way to export them if they are simple consts...
The whole idea of dpp is to be able to use headers as they are used in C and C++. Macros there don't exist unless they're expanded, so it's the same thing with dpp. Maybe it's good idea to add a runtime flag to translate non-function-like macros as enums... hmm.
My tool already does simple value-macro extraction, I also thinking about replacing macro with shortcut-to-self(see below) so in AST it will look like a function call, then the user can convert the macro itself to a template or mixin, so this way the code can be preserved more or less as-is. Though I don't have exact date or plan. ``` #define REG_FN(A) gContext->reg(#A) ... // somewhere in code REG_FN(sum); ``` So in this trivial example REG_FN will be preserved in code as written. This way in more complex cases, such as whole class creation with macro, it should be possible to retain that information. But again this will require studying, it might sound useful in theory, however bindings is done for a specific conditions, and so whether it is really useful or not is an open question.
Oct 27
prev sibling parent Andrea Fontana <nospam example.com> writes:
On Tuesday, 23 October 2018 at 07:42:56 UTC, evilrat wrote:
 (Oh My) Gentool v0.0.1 is just released!

 What it is?
 Binding generator with C/C++ support(primarilly C++) that 
 outputs D bindings.
Wow! I tried it and it seems to work, but fails with this: #include <stddef.h> void test(char* a = NULL); it misses NULL macro and generate this: extern(C++) void test (char* a = ); Anyway that's a good news for me too! Andrea
Oct 23