using python clang.cindex library to generate bindings ?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

using python clang.cindex library to generate bindings ?

Sebastien Binet
hi there,

I just noticed that llvm/clang-2.7 provides a ctypes-based library
wrapping libCIndex.so for python.
Is it possible, planned or adviseable to use such a thing to
programatically generate a representation (say in json/xml) of some
C/C++ api so it could be then used to automatically generate bindings
in other high-level languages ?

cheers,
sebastien.
--
#########################################
# Dr. Sebastien Binet
# Laboratoire de l'Accelerateur Lineaire
# Universite Paris-Sud XI
# Batiment 200
# 91898 Orsay
#########################################
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: using python clang.cindex library to generate bindings ?

Daniel Dunbar
On Sat, May 1, 2010 at 1:05 AM, Sebastien Binet <[hidden email]> wrote:
> hi there,
>
> I just noticed that llvm/clang-2.7 provides a ctypes-based library
> wrapping libCIndex.so for python.
> Is it possible, planned or adviseable to use such a thing to
> programatically generate a representation (say in json/xml) of some
> C/C++ api so it could be then used to automatically generate bindings
> in other high-level languages ?

It seems possible, but now one is working on it as far as I know. As
far as advisable, its certainly a better approach than doing ad hoc
parsing of C/C++ code.

 - Daniel

>
> cheers,
> sebastien.
> --
> #########################################
> # Dr. Sebastien Binet
> # Laboratoire de l'Accelerateur Lineaire
> # Universite Paris-Sud XI
> # Batiment 200
> # 91898 Orsay
> #########################################
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: using python clang.cindex library to generate bindings ?

Stefan Seefeld-2
In reply to this post by Sebastien Binet
On 05/01/2010 04:05 AM, Sebastien Binet wrote:
> hi there,
>
> I just noticed that llvm/clang-2.7 provides a ctypes-based library
> wrapping libCIndex.so for python.
> Is it possible, planned or adviseable to use such a thing to
> programatically generate a representation (say in json/xml) of some
> C/C++ api so it could be then used to automatically generate bindings
> in other high-level languages ?
>    

I have been looking for such a thing myself. Working on Synopsis
(http://synopsis.fresco.org), I'm interested into CLang to generate /
populate Synopsis' abstract semantic graph (ASG) for the parsed code,
which I then could manipulate further using Synopsis scripts (for
example to generate API documentation).

It seems the CIndex API is by far not rich enough for my needs, and I'm
not sure whether that will change. I'm now looking into CLang's own AST
et al. APIs instead, even though that's said to be much less stable than
CIndex.

FWIW,
         Stefan

--

       ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: using python clang.cindex library to generate bindings ?

Sebastien Binet
In reply to this post by Daniel Dunbar
hi Daniel,

Excerpts from Daniel Dunbar's message of 2010-05-03 18:26:27 +0200:

> On Sat, May 1, 2010 at 1:05 AM, Sebastien Binet <[hidden email]> wrote:
> > hi there,
> >
> > I just noticed that llvm/clang-2.7 provides a ctypes-based library
> > wrapping libCIndex.so for python.
> > Is it possible, planned or adviseable to use such a thing to
> > programatically generate a representation (say in json/xml) of some
> > C/C++ api so it could be then used to automatically generate bindings
> > in other high-level languages ?
>
> It seems possible, but now one is working on it as far as I know. As
> far as advisable, its certainly a better approach than doing ad hoc
> parsing of C/C++ code.

ok, so if I were to volunteer myself (always a bit dangerous,) where
should I start ?
I suppose some struct to store the various DeclXyz informations would
have to be devised, or some way to expose the various bits and pieces
of what makes wrapping an API "interesting" (function arguments, their
type, name and default values, classes/structs - their fields, names,
types, access-specifiers,...)

(I actually started a JsonPrinter visitor modeled after the
PrintFunctionNames plugin example, as hacking on a little plugin .so
is easier on the turn-around and easier for out-of-tree development)

cheers,
sebastien.
--
#########################################
# Dr. Sebastien Binet
# Laboratoire de l'Accelerateur Lineaire
# Universite Paris-Sud XI
# Batiment 200
# 91898 Orsay
#########################################
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: using python clang.cindex library to generate bindings ?

John McCall
In reply to this post by Stefan Seefeld-2

On May 3, 2010, at 10:45 AM, Stefan Seefeld wrote:

> On 05/01/2010 04:05 AM, Sebastien Binet wrote:
>> hi there,
>>
>> I just noticed that llvm/clang-2.7 provides a ctypes-based library
>> wrapping libCIndex.so for python.
>> Is it possible, planned or adviseable to use such a thing to
>> programatically generate a representation (say in json/xml) of some
>> C/C++ api so it could be then used to automatically generate bindings
>> in other high-level languages ?
>>
>
> I have been looking for such a thing myself. Working on Synopsis
> (http://synopsis.fresco.org), I'm interested into CLang to generate /
> populate Synopsis' abstract semantic graph (ASG) for the parsed code,
> which I then could manipulate further using Synopsis scripts (for
> example to generate API documentation).
>
> It seems the CIndex API is by far not rich enough for my needs, and I'm
> not sure whether that will change. I'm now looking into CLang's own AST
> et al. APIs instead, even though that's said to be much less stable than
> CIndex.

We make absolutely no stability guarantees for interacting with the AST through C++.  Feel free to write code against it, but understand that your code will be version-locked and may need to be updated in possibly subtle ways every time you bump clang versions.  That said, it's absolutely going to be a richer interface than libclang (f.k.a. CIndex).

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: using python clang.cindex library to generate bindings ?

Martin C. Martin-2
In reply to this post by Daniel Dunbar
Until it exists, you might want to check out SWIG, which parses a subset
of C++ and automatically generates bindings in other high-level languages.

Best,
Martin

On 5/3/2010 12:26 PM, Daniel Dunbar wrote:

> On Sat, May 1, 2010 at 1:05 AM, Sebastien Binet<[hidden email]>  wrote:
>> hi there,
>>
>> I just noticed that llvm/clang-2.7 provides a ctypes-based library
>> wrapping libCIndex.so for python.
>> Is it possible, planned or adviseable to use such a thing to
>> programatically generate a representation (say in json/xml) of some
>> C/C++ api so it could be then used to automatically generate bindings
>> in other high-level languages ?
>
> It seems possible, but now one is working on it as far as I know. As
> far as advisable, its certainly a better approach than doing ad hoc
> parsing of C/C++ code.
>
>   - Daniel
>
>>
>> cheers,
>> sebastien.
>> --
>> #########################################
>> # Dr. Sebastien Binet
>> # Laboratoire de l'Accelerateur Lineaire
>> # Universite Paris-Sud XI
>> # Batiment 200
>> # 91898 Orsay
>> #########################################
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev