Jump to page: 1 2 3
Thread overview
C++ parser
May 22, 2013
IgorStepanov
May 22, 2013
Jacob Carlborg
May 22, 2013
IgorStepanov
May 22, 2013
Jacob Carlborg
May 22, 2013
Jacob Carlborg
May 22, 2013
Igor Stepanov
May 22, 2013
nazriel
May 22, 2013
1100110
May 23, 2013
Jacob Carlborg
May 22, 2013
1100110
May 22, 2013
Dicebot
May 22, 2013
1100110
May 22, 2013
Dicebot
May 22, 2013
1100110
May 23, 2013
Jacob Carlborg
May 23, 2013
1100110
May 23, 2013
Jacob Carlborg
May 23, 2013
1100110
May 23, 2013
Jacob Carlborg
May 23, 2013
Jacob Carlborg
May 22, 2013
Dicebot
May 22, 2013
Dejan Lekic
May 22, 2013
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: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
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 files. Pull request are welcome :)
>
> https://github.com/jacob-carlborg/dstep

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?
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.html

> First 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:
>
>> 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.html

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=FKceA691Wcg

>> First goal
>> is a parse and syntax analyse of this header. Do libclang provide me
>> this functional?

Yes, 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 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:
>> 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

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.
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 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 files. Pull request are welcome :)
>>
>> https://github.com/jacob-carlborg/dstep
> 
> I am afraid it doesn't build anymore with DMD git-head.
> It isn't dstep itself but one of its dependencies.


Yeah, I was afraid of that...

So, Now the next easiest thing is probably SWIG.

> 
> 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.

Well, I don't think he'll have it any easier there...  I've tried Binding rust, I sucked worse than binding D.



« First   ‹ Prev
1 2 3