On Apr 16, 2010, at 3:57 AM, Dag Sverre Seljebotn wrote:

> Sebastien Binet wrote:
>> hi there,
>>
>> say I have a way to automatically generate a json structure
>> representing C++ classes, functions,... (the code to do so uses  
>> gccxml[0]
>> and Reflex[1]. once I migrated it to use the new gcc-4.5 plugin
>> architecture and/or clang, I'll release it under a BSD-like licence)
>>
>> this json structure looks like so for the moment (from cython C++
>> test-case class):
>>
>> {'bases': [],
>> 'dso': 'libFoo.so',
>> 'members': [{'name': 'number', 'offset': 0L, 'size': 8, 'type':
>> 'double'}],
>> 'methods': [{'args': [],
>>              'doc': '',
>>              'name': '~DoubleKeeper',
>>              'prototype': 'void DoubleKeeper::~DoubleKeeper()',
>>              'return': 'void'},
>>             {'args': [{'default': None,
>>                        'name': None,
>>                        'type': 'const DoubleKeeper&'}],
>>              'doc': '',
>>              'name': 'operator=',
>>              'prototype': 'DoubleKeeper&  
>> DoubleKeeper::operator=(const DoubleKeeper& )',
>>              'return': 'DoubleKeeper&'},
>>             {'args': [{'default': None,
>>                        'name': None,
>>                        'type': 'const DoubleKeeper&'}],
>>              'doc': '',
>>              'name': 'DoubleKeeper',
>>              'prototype': 'DoubleKeeper  
>> DoubleKeeper::DoubleKeeper(const DoubleKeeper& )',
>>              'return': 'DoubleKeeper'},
>>             {'args': [{'default': None,
>>                        'name': 'number',
>>                        'type': 'double'}],
>>              'doc': '',
>>              'name': 'DoubleKeeper',
>>              'prototype': 'DoubleKeeper  
>> DoubleKeeper::DoubleKeeper(double number)',
>>              'return': 'DoubleKeeper'},
>>             {'args': [{'default': None,
>>                        'name': 'num',
>>                        'type': 'double'}],
>>              'doc': '',
>>              'name': 'set_number',
>>              'prototype': 'void DoubleKeeper::set_number(double  
>> num)',
>>              'return': 'void'},
>>             {'args': [],
>>              'doc': '',
>>              'name': 'get_number',
>>              'prototype': 'double DoubleKeeper::get_number()',
>>              'return': 'double'},
>>             {'args': [{'default': None,
>>                        'name': 'value',
>>                        'type': 'double'}],
>>              'doc': '',
>>              'name': 'transmogrify',
>>              'prototype': 'double DoubleKeeper::transmogrify(double  
>> value)',
>>              'return': 'double'}],
>> 'name': 'DoubleKeeper',
>> 'size': 12,
>> 'typeinfo': '12DoubleKeeper'}
>>
>> which should be more or less self-describing.
>>
>> I am wondering if there is an API or a facility to write the
>> corresponding .pxd file ?
>>
> If you are willing to spend a little time to write a transform, then  
> it
> should be very straightforward:
>
> The json matches very well with the internal code tree which Cython
> uses. Basically, you'd import Cython itself and instantiate the node
> instances used internally (from Nodes.py and ExprNodes.py). Then, use
> the code in CodeWriter.py to dump it to a pxd file. (The CodeWriter  
> may
> need to be extended for some node types, but that is straightforward.)
>
> (The advantage of this approach is that one could very easily hook up
> whatever transform you make Cython understand the json files directly,
> rather than having to use a pxd file.)
>
> There's no docs on the internal Cython tree, but there's a decent  
> "print
> tree" functionality. Basically search for "pipeline" in Main.py and
> insert a line "dumptree," right after parsing. Then run Cython on a  
> pyx
> file containing the kind of tree you want to study, and a  
> representation
> will be dumped to screen.

I'd like to add that automatic generation of .pxd files from .h and .c  
files has been on our "we'd love to have that" list for a long time,  
so if you could put something like this together we'd love to ship it  
with Cython.

- Robert


_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to