[GSoC] Header Generation for C/C++

Eduard Staniloiu edi33416 at gmail.com
Wed Jul 17 11:19:40 UTC 2019


On Tuesday, 16 July 2019 at 19:10:41 UTC, bachmeier wrote:
> On Tuesday, 16 July 2019 at 13:16:50 UTC, Eduard Staniloiu 
> wrote:
>
>> So, by running,
>> `dmd -HCf=ab.h -HCd=mypath/ a.d b.d` will write the generated 
>> header in `mypath/ab.h`, relative to the current directory.
>
> Will it be possible to extend this for other languages? That 
> would be a killer application. For instance
>
> dmd -HRuby=ab.rb -HCd=mypath/ a.d b.d
>
> goes a step further, converting what would have been the 
> generated C header to the file ab.rb containing (taken from 
> https://github.com/ffi/ffi/wiki/Examples)
>
> [ ... ]

This would best be done as a separate RubyVisitor that visits the 
AST nodes and
writes the expected FFI interface. If I didn't misunderstand the 
FFI readme, it only works with C interfaces, so this should 
probably simplify a great deal from the complexity.

 From the example it looks like FFI is meant to work only with 
opaque pointers, which means that you would only be interested in 
declaring `struct`s, defining `enum`s and function declarations.

The memory management bindings might be trickier, or they could 
be easy as I don't know either Ruby or FFI.

This being said, I believe that it should be done as a separate 
visitor so it wouldn't add more complexity to the C/C++ one.

This would be an interesting project :)


More information about the Digitalmars-d mailing list