built in import c header files

Atila Neves atila.neves at gmail.com
Thu Oct 8 07:12:19 UTC 2020


On Wednesday, 7 October 2020 at 11:14:02 UTC, norm wrote:
> On Wednesday, 7 October 2020 at 10:04:57 UTC, Atila Neves wrote:
>> On Wednesday, 7 October 2020 at 01:29:05 UTC, norm wrote:
>>> On Tuesday, 6 October 2020 at 22:42:11 UTC, 12345swordy wrote:
>>>> On Tuesday, 6 October 2020 at 21:04:20 UTC, Meta wrote:
>>>>> On Tuesday, 6 October 2020 at 20:59:54 UTC, 12345swordy 
>>>>> wrote:
>>>>>> I remember reading a reddit comment saying that if d were 
>>>>>> to import c header files directly without any 3rd party 
>>>>>> libraries it would be a game changer. The question is: how 
>>>>>> difficult to implement a C AST parser for the dmd front 
>>>>>> end?
>>>>>>
>>>>>>
>>>>>> -Alex
>>>>>
>>>>> You're in luck: https://github.com/atilaneves/dpp
>>>>
>>>> What part of "built in and not part of a 3rd party library" 
>>>> do you not understand?
>>>
>>> You could easily work it out for yourself by looking at any C 
>>> parser and the DMD front.
>>
>>> But why bother with C, it is trivial to generate C bindings 
>>> from headers.
>>
>
> Really? I have not had any issues before automatically creating 
> C bindings for D using codegen. Sure, occasionally a macro will 
> bite but it isn't that often nor difficult to fix.  They were 
> not the kernel but they were not small code bases without 
> macros either.

Imagine this and extrapolate to hundreds of headers:

---
// hdr0.h
struct struct0 {
     struct1* s1;
};
---

---
// hdr1.h
#define SILLY_MACRO struct2;
struct struct1 {
     SILLY_MACRO* s2;
}
----

---
// hdr2.h
struct struct2 {
     struct3* s3;
}
---


>
> TBH though now I just use dpp so I don't see the value of 
> bolting on a "C" parser to the D front end. C++ I have 
> struggled with that and it requires an annoying amount of 
> manual editing. DPP works well but even it falls over for some 
> C++ code bases I've tried.

dpp doesn't officially support C++ yet, because... it doesn't 
work yet. There are several reasons for this.

The first, and most annoying, is that libclang isn't all it's 
cracked up to be. There's a *lot* of functionality missing for 
C++ that the compiler frontend itself knows about but doesn't 
expose via the C API.

The second, and maybe unfixable reason, is how to translate 
C++-only concepts to D. Consider std::is_reference_v. That can't 
be written in D, not even by hand. What if that gets used in 
SFINAE? What about expression templates given how operator 
overloading in D is a lot different? I still don't know how to 
get around that.


More information about the Digitalmars-d mailing list