digitalmars.D - C++ parser
- IgorStepanov (3/3) May 22 2013 Is there someone free C++ parser? I want to create simple util to
- Jacob Carlborg (6/9) May 22 2013 There's libclang. I already have a tool that handles C and Objective-C
- IgorStepanov (6/15) May 22 2013 Seems pretty. What I need to do first to start work over C++ to D
- Jacob Carlborg (7/13) May 22 2013 I'm not sure on how to best bind C++ code to D. D can handle some parts
- Jacob Carlborg (15/26) May 22 2013 There was a talk on the recent D conference about binding C++ code:
- Igor Stepanov (53/56) May 22 2013 Now extern(C++) interface allow to access to virtual and
- nazriel (8/17) May 22 2013 I am afraid it doesn't build anymore with DMD git-head.
- 1100110 (5/25) May 22 2013 Yeah, I was afraid of that...
- Jacob Carlborg (4/6) May 22 2013 Hey, at least give me a change to fix the problem.
- 1100110 (5/5) May 22 2013 Hmmm... Or you could try using pegged (or CTPG or goldie or dparser).
- Dicebot (3/11) May 22 2013 Writing C++ grammar parser in Pegged/Goldie from scratch so that
- 1100110 (5/16) May 22 2013 I know right? (I figured there's probably a half-baked one floating
- Dicebot (2/3) May 22 2013 I simply don't understand why do you find libclang unsuitable.
- 1100110 (7/12) May 22 2013 hmmm? I never said it was unsuitable, I think you mistaking me for
- Jacob Carlborg (5/11) May 22 2013 I'm here to help, DStep is also here to help. I'll see if I can get it
- 1100110 (5/19) May 23 2013 Hell yeah!
- Jacob Carlborg (7/10) May 23 2013 It works with DMD 2.062. To get it to work with DMD 2.063 there are is
- 1100110 (4/18) May 23 2013 That was fast.
- Jacob Carlborg (6/8) May 23 2013 Note, if you're using DVM you need to change the build.sh file to use
- Jacob Carlborg (6/10) May 22 2013 Could you use the pre compiled binary in the mean time:
- Dicebot (7/10) May 22 2013 Using libclang is probably most convenient and robust approach
- Dejan Lekic (3/6) May 22 2013 The easiest thing for you would be to use the GCCXML -
Is there someone free C++ parser? I want to create simple util to converting C++ headers to D like htod, but I want, if it possible, to dont write C++ parser. Any ideas?
May 22 2013
On 2013-05-22 10:05, IgorStepanov wrote:Is there someone free C++ parser? I want to create simple util to converting C++ headers to D like htod, but I want, if it possible, to dont write C++ parser. Any ideas?There's libclang. I already have a tool that handles C and Objective-C files. Pull request are welcome :) https://github.com/jacob-carlborg/dstep -- /Jacob Carlborg
May 22 2013
On Wednesday, 22 May 2013 at 08:10:31 UTC, Jacob Carlborg wrote:On 2013-05-22 10:05, IgorStepanov wrote:Seems pretty. What I need to do first to start work over C++ to D handle? As I think, I'll need to generate to one C++ header one .cpp glue file (with some hacking over header) and one .di file. First goal is a parse and syntax analyse of this header. Do libclang provide me this functional?Is there someone free C++ parser? I want to create simple util to converting C++ headers to D like htod, but I want, if it possible, to dont write C++ parser. Any ideas?There's libclang. I already have a tool that handles C and Objective-C files. Pull request are welcome :) https://github.com/jacob-carlborg/dstep
May 22 2013
On 2013-05-22 16:55, IgorStepanov wrote:Seems pretty. What I need to do first to start work over C++ to D handle? As I think, I'll need to generate to one C++ header one .cpp glue file (with some hacking over header) and one .di file.I'm not sure on how to best bind C++ code to D. D can handle some parts of the C++ ABI, like classes and virtual functions. dlang.org contains some information: http://dlang.org/cpp_interface.htmlFirst goal is a parse and syntax analyse of this header. Do libclang provide me this functional?-- /Jacob Carlborg
May 22 2013
On 2013-05-22 20:31, Jacob Carlborg wrote: I accidentally sent the message too soon.On 2013-05-22 16:55, IgorStepanov wrote:There was a talk on the recent D conference about binding C++ code: Reddit: http://www.reddit.com/r/programming/comments/1eiku4/dconf_2013_day_1_talk_5_using_d_alongside_a_game/ Youtube: http://www.youtube.com/watch?v=FKceA691WcgSeems pretty. What I need to do first to start work over C++ to D handle? As I think, I'll need to generate to one C++ header one .cpp glue file (with some hacking over header) and one .di file.I'm not sure on how to best bind C++ code to D. D can handle some parts of the C++ ABI, like classes and virtual functions. dlang.org contains some information: http://dlang.org/cpp_interface.htmlYes, libclang will lex, parse and do semantic analysis. You can then walk the AST and do want you want with it. You need to indicate it's C++ you want to parse using the -x flag. You need to add C++ in the "setupArguments" and "handleLanguage" functions. You can see that the "handleLanguage" function already contains a "case" for C++. After that you can put the C++ specific code in a new package: translator/cpp. -- /Jacob CarlborgFirst goal is a parse and syntax analyse of this header. Do libclang provide me this functional?
May 22 2013
I'm not sure on how to best bind C++ code to D. D can handle some parts of the C++ ABI, like classes and virtual functions. dlang.org contains some information:Now extern(C++) interface allow to access to virtual and non-virtual (with final annotation) methods, static methods. After my pull for posix and fix windows mangling (in work) static variables also be allowed. I've idea, how we can get access to fields: //C++ class Foo { public: int a; int b; //virtual methods and other stuff }; //Glue C++ (automatically generated) int& __accessor_Foo_a(Foo* f){return f->a;} int& __accessor_Foo_b(Foo* f){return f->b;} //also we can get access to private/protected methods with some header hack if in needed //D header extern(C++) { interface Foo { //we can implement final methods in interface property final ref int a() {return __accessor_Foo_a(this);} property final ref int b() {return __accessor_Foo_b(this);} //other stuff } ref int __accessor_Foo_a(Foo); ref int __accessor_Foo_b(Foo); } for get access to different special functions (like constructors, destructors, operators) we can use special methods + pragma(mangle) interface Foo { pragma(mangle, getCPPOperatorMangle!(Foo.__operator_idx, "[]")) int& __operator_idx(size_t); //get access to int& Foo::operator[](size_t) } There is small trouble with inlined functions: //C++ class Foo { protected: int foo(){return 5;} //this function is inline and there's a possibility that this function won't be written into object file. }; In this case, we must to do some actions to force write foo into object file. This is my ideas about binding C++ to D :) If I'll do all as I want, we'll get a simple interface to access to most of C++ code (except templates).
May 22 2013
On Wednesday, 22 May 2013 at 08:10:31 UTC, Jacob Carlborg wrote:On 2013-05-22 10:05, IgorStepanov wrote:I am afraid it doesn't build anymore with DMD git-head. It isn't dstep itself but one of its dependencies. I wanted to use it in order to create bindings for XCB but couldn't built it. Also AFAIK SiegeLord went with flow to Rust, so probably Tango-D2 dependency may start to be a problem soon. Just my 5 cents.Is there someone free C++ parser? I want to create simple util to converting C++ headers to D like htod, but I want, if it possible, to dont write C++ parser. Any ideas?There's libclang. I already have a tool that handles C and Objective-C files. Pull request are welcome :) https://github.com/jacob-carlborg/dstep
May 22 2013
On 05/22/2013 03:17 PM, nazriel wrote:On Wednesday, 22 May 2013 at 08:10:31 UTC, Jacob Carlborg wrote:On 2013-05-22 10:05, IgorStepanov wrote:Is there someone free C++ parser? I want to create simple util to converting C++ headers to D like htod, but I want, if it possible, to=dont write C++ parser. Any ideas?There's libclang. I already have a tool that handles C and Objective-C=Yeah, I was afraid of that... So, Now the next easiest thing is probably SWIG.files. Pull request are welcome :) https://github.com/jacob-carlborg/dstep=20 I am afraid it doesn't build anymore with DMD git-head. It isn't dstep itself but one of its dependencies.=20 I wanted to use it in order to create bindings for XCB but couldn't built it. Also AFAIK SiegeLord went with flow to Rust, so probably Tango-D2 dependency may start to be a problem soon. =20 Just my 5 cents.Well, I don't think he'll have it any easier there... I've tried Binding rust, I sucked worse than binding D.
May 22 2013
On 2013-05-22 22:33, 1100110 wrote:Yeah, I was afraid of that... So, Now the next easiest thing is probably SWIG.Hey, at least give me a change to fix the problem. -- /Jacob Carlborg
May 22 2013
Hmmm... Or you could try using pegged (or CTPG or goldie or dparser). I haven't played with it too much, but there's a C grammar, and it mentions the ability to specify semantic actions, so.... That's like 1/3 of the way to something usable. https://github.com/PhilippeSigaud/Pegged/wiki/Semantic-Actions
May 22 2013
On Wednesday, 22 May 2013 at 20:39:08 UTC, 1100110 wrote:Hmmm... Or you could try using pegged (or CTPG or goldie or dparser). I haven't played with it too much, but there's a C grammar, and it mentions the ability to specify semantic actions, so.... That's like 1/3 of the way to something usable. https://github.com/PhilippeSigaud/Pegged/wiki/Semantic-ActionsWriting C++ grammar parser in Pegged/Goldie from scratch so that it can produce usable AST... Well, good luck! :)
May 22 2013
On 05/22/2013 04:07 PM, Dicebot wrote:On Wednesday, 22 May 2013 at 20:39:08 UTC, 1100110 wrote:/3Hmmm... Or you could try using pegged (or CTPG or goldie or dparser). I haven't played with it too much, but there's a C grammar, and it mentions the ability to specify semantic actions, so.... That's like 1=of the way to something usable. https://github.com/PhilippeSigaud/Pegged/wiki/Semantic-Actions=20 Writing C++ grammar parser in Pegged/Goldie from scratch so that it can=produce usable AST... Well, good luck! :)I know right? (I figured there's probably a half-baked one floating around somewhere...) But we kinda need something good like http://luajit.org/ext_ffi.html...
May 22 2013
On Wednesday, 22 May 2013 at 21:38:49 UTC, 1100110 wrote:...I simply don't understand why do you find libclang unsuitable.
May 22 2013
On 05/22/2013 04:40 PM, Dicebot wrote:On Wednesday, 22 May 2013 at 21:38:49 UTC, 1100110 wrote:hmmm? I never said it was unsuitable, I think you mistaking me for someone else. (I also have no experience with libclang, and I'm tired of manually translating these things... So, am I looking for a way to not translate this? Yes.) Also I'm pretty sure I'd need help with something like this......=20 I simply don't understand why do you find libclang unsuitable. =20
May 22 2013
On 2013-05-23 00:17, 1100110 wrote:hmmm? I never said it was unsuitable, I think you mistaking me for someone else. (I also have no experience with libclang, and I'm tired of manually translating these things... So, am I looking for a way to not translate this? Yes.) Also I'm pretty sure I'd need help with something like this...I'm here to help, DStep is also here to help. I'll see if I can get it up an running again. -- /Jacob Carlborg
May 22 2013
On 05/23/2013 01:25 AM, Jacob Carlborg wrote:On 2013-05-23 00:17, 1100110 wrote: =20tehmmm? I never said it was unsuitable, I think you mistaking me for someone else. (I also have no experience with libclang, and I'm tired of manually translating these things... So, am I looking for a way to not transla=Hell yeah! I didn't realize dstep was yours. If I can do anything to help, let me know.this? Yes.) Also I'm pretty sure I'd need help with something like this...=20 I'm here to help, DStep is also here to help. I'll see if I can get it up an running again. =20
May 23 2013
On 2013-05-23 11:44, 1100110 wrote:Hell yeah! I didn't realize dstep was yours. If I can do anything to help, let me know.It works with DMD 2.062. To get it to work with DMD 2.063 there are is regression that needs to be fixed for find a workaround for. Tango fails to compile because of this. http://d.puremagic.com/issues/show_bug.cgi?id=10142 -- /Jacob Carlborg
May 23 2013
On 05/23/2013 07:33 AM, Jacob Carlborg wrote:On 2013-05-23 11:44, 1100110 wrote: =20sHell yeah! I didn't realize dstep was yours. If I can do anything to help, let me know.=20 It works with DMD 2.062. To get it to work with DMD 2.063 there are is regression that needs to be fixed for find a workaround for. Tango fail=to compile because of this. =20 http://d.puremagic.com/issues/show_bug.cgi?id=3D10142 =20That was fast. I'll check it out. Thank you.
May 23 2013
On 2013-05-23 16:46, 1100110 wrote:That was fast. I'll check it out. Thank you.Note, if you're using DVM you need to change the build.sh file to use DMD 2.062. Also, I don't know if there are other hidden compiler errors in Tango using DMD 2.063. -- /Jacob Carlborg
May 23 2013
On 2013-05-22 22:17, nazriel wrote:I am afraid it doesn't build anymore with DMD git-head. It isn't dstep itself but one of its dependencies. I wanted to use it in order to create bindings for XCB but couldn't built it.Could you use the pre compiled binary in the mean time: https://github.com/jacob-carlborg/dstep/downloads I forgot to put a link to the downloads on the front page. -- /Jacob Carlborg
May 22 2013
On Wednesday, 22 May 2013 at 08:05:06 UTC, IgorStepanov wrote:Is there someone free C++ parser? I want to create simple util to converting C++ headers to D like htod, but I want, if it possible, to dont write C++ parser. Any ideas?Using libclang is probably most convenient and robust approach nowadays. You can look at Jacob's DStep for inspiration : https://github.com/jacob-carlborg/dstep Actually, I would even recommend to work in improving dstep instead of wasting efforts on new tool as it does exactly what you want :)
May 22 2013
On Wednesday, 22 May 2013 at 08:05:06 UTC, IgorStepanov wrote:Is there someone free C++ parser? I want to create simple util to converting C++ headers to D like htod, but I want, if it possible, to dont write C++ parser. Any ideas?The easiest thing for you would be to use the GCCXML - http://gccxml.github.io/HTML/Index.html
May 22 2013