Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 28, 2016 C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Hello, I am working on a C++ to D converter. The project is opensource, on github : https://github.com/lhamot/CPP2D Clang is used to parse the C++ code and get the abstract syntax tree. Then I can visit the AST to print it to D language. Some tricks are used to convert the simplest macros to mixin. Some C++ features which are not straightforward to convert are already handled, like (A not exhaustive list): class constructor/destructor virtual abstract override initialization list call base constructor Operator overloading member free left or right Template function function specialization class class/struct specialization class/struct partial specialization arrays static dynamic Some examples here : https://github.com/lhamot/CPP2D/wiki/Conversion-samples If somebody is interested to use this software, or to participate, do not hesitate to contact me. Regards |
May 28, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Loïc HAMOT | On Saturday, 28 May 2016 at 11:02:37 UTC, Loïc HAMOT wrote: > Hello, > > I am working on a C++ to D converter. > The project is opensource, on github : https://github.com/lhamot/CPP2D > > Clang is used to parse the C++ code and get the abstract syntax tree. Then I can visit the AST to print it to D language. > Some tricks are used to convert the simplest macros to mixin. > > Some C++ features which are not straightforward to convert are already handled, like (A not exhaustive list): > class > constructor/destructor > virtual > abstract > override > initialization list > call base constructor > Operator overloading > member > free > left or right > Template > function > function specialization > class > class/struct specialization > class/struct partial specialization > arrays > static > dynamic > > Some examples here : https://github.com/lhamot/CPP2D/wiki/Conversion-samples > > If somebody is interested to use this software, or to participate, do not hesitate to contact me. > > Regards That's a great project! IIRC Walter still searches for someone to convert the dmd backend to D. Btw do you know about Daniel's porting tool that was used to migrate the dmd frontend to D? https://github.com/yebblies/magicport2 |
May 28, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Loïc HAMOT | On Saturday, 28 May 2016 at 11:02:37 UTC, Loïc HAMOT wrote:
> Hello,
>
> I am working on a C++ to D converter.
> The project is opensource, on github : https://github.com/lhamot/CPP2D
>
> [...]
Very nice! Looking at your examples, you should know that the default protection in D classes is public.
-Steve
|
May 28, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Loïc HAMOT | On Saturday, 28 May 2016 at 11:02:37 UTC, Loïc HAMOT wrote:
> Hello,
>
> I am working on a C++ to D converter.
> The project is opensource, on github : https://github.com/lhamot/CPP2D
>
> [...]
Interesting!
|
May 28, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Saturday, 28 May 2016 at 11:26:23 UTC, Seb wrote:
> On Saturday, 28 May 2016 at 11:02:37 UTC, Loïc HAMOT wrote:
>> Hello,
>>
>> I am working on a C++ to D converter.
>> The project is opensource, on github : https://github.com/lhamot/CPP2D
>>
>> [...]
>>
>> If somebody is interested to use this software, or to participate, do not hesitate to contact me.
>>
>> Regards
>
> That's a great project! IIRC Walter still searches for someone to convert the dmd backend to D.
> Btw do you know about Daniel's porting tool that was used to migrate the dmd frontend to D?
> https://github.com/yebblies/magicport2
I gave a try to magicport2, but I read it is specifically done for DMD. Moreover is seams to have some limitations which don't fit for my needs : template, C++11, ...
I also tried the cpp2d project inside VisualD. But is has also many limitations in the C++ features it can parse (and the parser is pretty hard to extend).
This is why I finally decided to use an existing, robust and reusable C++ parser : clang.
I am far away to be able to convert the full DMD backend, but this is a very interesting challenge!
|
June 01, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Loïc HAMOT | On 2016-05-28 13:02, Loïc HAMOT wrote: > Hello, > > I am working on a C++ to D converter. > The project is opensource, on github : https://github.com/lhamot/CPP2D Is there a reason to reinvent the wheel instead of contributing to DStep [1]? [1] https://github.com/jacob-carlborg/dstep -- /Jacob Carlborg |
June 01, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Wednesday, 1 June 2016 at 06:45:09 UTC, Jacob Carlborg wrote:
> On 2016-05-28 13:02, Loïc HAMOT wrote:
>> Hello,
>>
>> I am working on a C++ to D converter.
>> The project is opensource, on github : https://github.com/lhamot/CPP2D
>
> Is there a reason to reinvent the wheel instead of contributing to DStep [1]?
>
> [1] https://github.com/jacob-carlborg/dstep
Hello Jacob.
It think DStep and CPP2D have very different objectives.
DStep target C and Objective-C headers, but CPP2D target C++ full source code.
Maybe do you think I could participate to DStep in order to extend it to full C++ source handling?
Yes I could. Like I could participate to VisualD/cpp2d or magicport2 projects.
But the reason why I didn't is I want to test the feasibility of a C++ to D conversion using the clang parser.
Now, I think I passed the proof of concept step, and merge my work in an other project is not out of the question.
|
June 01, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Loïc HAMOT | On 2016-06-01 10:55, Loïc HAMOT wrote: > Hello Jacob. > It think DStep and CPP2D have very different objectives. > DStep target C and Objective-C headers, but CPP2D target C++ full source > code. No. Targeting C++ is not against the objectives of DStep. C and Objective-C just happens to be what DStep currently supports. It make sense to start with C since it's a subset of both Objective-C and C++. Also, when I started the C++ support in D didn't exist or was very limited. > Maybe do you think I could participate to DStep in order to extend it to > full C++ source handling? Yes ;) > Yes I could. Like I could participate to VisualD/cpp2d or magicport2 > projects. Anything that is not using a real front end is a lost cause. > But the reason why I didn't is I want to test the feasibility of a C++ > to D conversion using the clang parser. I don't see a reason why it was necessary to create a completely new project for that. > Now, I think I passed the proof of concept step, and merge my work in an > other project is not out of the question. Not sure how easy it would be to integrate in DStep. I'm guessing you're using the C++ API while DStep is written in D and is using the C API. -- /Jacob Carlborg |
June 01, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 1/06/2016 9:40 PM, Jacob Carlborg wrote:
>> Yes I could. Like I could participate to VisualD/cpp2d or magicport2
>> projects.
>
> Anything that is not using a real front end is a lost cause.
>
Haha that really depends on your goals.
|
June 02, 2016 Re: C++ to D converter based on clang | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | On 2016-06-01 14:50, Daniel Murphy wrote: > Haha that really depends on your goals. Yeah, I know magicport can translate DMD. The goal there is to translate arbitrary C++ code to D. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation