Re: [pygccxml-development] C type normalization utility function?
Brought to you by:
mbaas,
roman_yakovenko
From: Gustavo C. <gjc...@gm...> - 2008-06-13 22:04:49
|
2008/6/13 Gustavo Carneiro <gjc...@gm...>: > 2008/6/11 Gustavo Carneiro <gjc...@gm...>: > >> 2008/6/10 Roman Yakovenko <rom...@gm...>: >> >>> On Mon, Jun 9, 2008 at 1:36 PM, Gustavo Carneiro <gjc...@gm...> >>> wrote: >>> > As seen in >>> > >>> > https://bugs.launchpad.net/bugs/238455 >>> > >>> > I am getting problems in PyBindGen related to differences in types like >>> > "char*" vs "char *", also the position of the 'const' keyword may >>> change, >>> > etc. >>> > >>> > I am looking for some robust, pure python code to parse C types and >>> extract >>> > features from it, or produce a canonical type string, so that I can use >>> it >>> > PyBindGen. Does something like this exist in pygccxml >>> >>> No, but we can discuss such addition to pygccxml. I think this is a >>> nice & useful feature. >>> >>> > or elsewhere that I can steal? :-) >>> >>> May be from here: http://code.google.com/p/cppclean/wiki/InternalDesign >> >> >> Thanks for the link! This code looks nice, if excessive for what I want. >> Using and adapting this code to parse C types is now on my medium priority >> TODO list. If I get something useful out of it, I'll post here the result. >> > > OK, I have results :-) > Due to the mailing list rejecting ZIP files, the zip file I sent can be found here: http://telecom.inescporto.pt/~gjc/ctypeparser.zip Regards. > > > gjc@dark-tower:ctypeparser$ python ctypeparser.py > 'char *' => 'char *' > 'const foo::bar<const char*, zbr&>*' => 'foo::bar< char const *, zbr & > > const *' > 'const ::bar*' => '::bar const *' > 'const char*const' => 'char const * const' > 'const char*const*const' => 'char const * const * const' > > > This code uses the tokenizer from cppclean project, with minor > modifications. On top of it it I wrote a minimal type parser which reorders > 'const' modifiers to _a_ canonical position (to the right, in this case), > and finally converts the result back to a string with deterministic spacing > applied to tokens. It also handles templated types recursively. > > Let me know what you think. > > If it is suitable, next step is add some unit tests and then you can copy > it to pygccxml, if you want. I'll add another copy to pybindgen. > > One thing I am not completely sure yet is how to handle namespaced > identififers. I am tempted to assume a context where no 'using namespace > xxx' statment would have been used and assume all identifiers are relative > to the root namespace. On that assumption I would like to remove any > leading :: in identifiers. Any thoughts? > > Regards. > > > -- > Gustavo J. A. M. Carneiro > INESC Porto, Telecommunications and Multimedia Unit > "The universe is always one step beyond logic." -- Frank Herbert > -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert |