[WIP] Generate C++ header files from public extern (C++) declarations#5082
[WIP] Generate C++ header files from public extern (C++) declarations#5082yebblies wants to merge 15 commits intodlang:masterfrom
Conversation
ad4c252 to
72084ac
Compare
|
While on the one hand I see this as not being friendly with dmd's c++ mangling rules. I see this as a recipe to break existing ports of D. Not that they weren't already broken because of the switch. But I think the correct thing to do is to map all types to fixed sized integers. That should guarantee that data passing between the two sides should work. |
|
Defining them to anything other than what dmd uses for mangling will break (d)dmd, so it's not going to happen. It's only set up for win32 until I get around to fixing the other platforms. win32 is currently working perfectly. |
|
Yep. I'm probably thinking too hard about this, but perhaps I should get round to adding some kind of |
src/dmodule.d
Outdated
| File* objfile; // output .obj file | ||
| File* hdrfile; // 'header' file | ||
| File* docfile; // output documentation file | ||
| File* cppfile; // output documentation file |
There was a problem hiding this comment.
Forgot to modify the comment
42304f3 to
12841da
Compare
The halt() line was last touched in 2.025 and seems to be left over from debugging.
This works around a name conflict between the auto-generated frontend header file and the system Mach-O headers.s
|
@ibuclaw Ping on the gdb failures |
|
@yebblies - not related to gdb, but FYI. This is because of the following in This should be removed. (You have ulong.max in D :-) |
|
I can reproduce gdb failure on gdb-7.11. |
| infobuf->write("Digital Mars D "); | ||
| infobuf->writeString(global.version); // DW_AT_producer | ||
| infobuf->write("Digital Mars D 2.0xx"); | ||
| // infobuf->writeString(global.version); // DW_AT_producer |
There was a problem hiding this comment.
Here is your problem:
Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0xfd (32-bit)
Version: 3
Abbrev Offset: 0x0
Pointer Size: 8
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_producer : Digital Mars D 2.0xx�runnable/gdb4149.d
<34> DW_AT_language : 47 (Unknown: 2f)
<35> DW_AT_name : home/ibuclaw/src/dmd/dmd/test
<53> DW_AT_comp_dir :
<54> DW_AT_low_pc : 0x0
<5c> DW_AT_entry_pc : 0x0
<64> DW_AT_ranges : 0x0
<68> DW_AT_stmt_list : 0x2000000
<1><6c>: Abbrev Number: 103
There was a problem hiding this comment.
After that:
objdump: Warning: DIE at offset 0x6c refers to abbreviation number 103 which does not exist
I don't follow dmd for that long, but this seems to me a serious improvement as forgetting to update the header files seems to be a common problem around here ;-)
|
|
It's not quite that big a deal, because the autotester catches most broken changes. This PR is (or was) mostly complete, but is a little messy when it comes to platform differences. There is also hard-coded exclusion of ddmd.root which needs to be re-thought. I don't know what you mean by new features breaking the generation. The generator ignores everything except extern(C/C++) declarations which generally aren't affected by new features. As well as that, the autotester would catch it if it started generating broken C++ code (hopefully). |
|
hmm .... C header generations seems useful, I might adopt this one. |
|
It's pretty messy - I'm hoping to push this out to an external compiler-as-a-library tool. |
|
hmm ... it only needs to be concerned with extern C/C++ stuff. |
|
Yeah, and it can be done pretty well without semantic analysis. I mean, I did it like that in the other direction, and this doesn't need to do statements/expressions. The part I'm not so keen on having in the compiler is the special cases and rewrites that inevitably come up. Eg which modules to export, things to exclude, translations for variable sized types, automatic header includes, etc |
|
I hear you. |
|
I'm currently working on this using the parser library I just merged. I'm starting with the simple case: top level functions, classes, structs and variables that are declared extern(C++). This should be extremely simple. After that, I'm going to tackle more complex cases like having an extern function in a class that's not extern. Ideas and help would be appreciated. @UplinkCoder |
|
@RazvanN7 If you push your progress to a visible branch, I can have a look. |
|
Hmm, no need to do anything that isn't toplevel. The only complex things that need handling are:
And even then, they aren't even that complex to handle IMO. Just make sure you emit them in the correct order. :-) |
|
Revamped this in #8591 |
If I can get this to work, it means no more maintaining header files for the frontend.
This generates one mega-header, since it needs to reorder declarations to avoid forward references. I need to work out what to do about declarations that can't be automatically converted but are referenced from the converted ones, like
ArrayandRootObject.