Re: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor
----- Original Message ----
From: Nindi Singh <nindi73@yahoo.co.uk> To: Development of Python/C++ integration <c++-sig@python.org> Sent: Friday, 28 December, 2007 9:36:26 PM Subject: Re: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor
In my previous 2 emails, in my c++ code I instantiated vector with
template vector;
This is a typo and should have read
template class vector;
Secondly after a little further investigation
pygccxml script: ______________________________________________________________ import sys from pygccxml import parser from pygccxml import declarations from pygccxml.declarations import templates from pygccxml.declarations import type_traits
decls = parser.parse( ['example.hpp'])#, config ) global_ns = declarations.get_global_namespace( decls )
query = declarations.custom_matcher_t (lambda vec :
templates.name(vec.name).endswith('vector'))
vectorClass = global_ns.classes(function=query)
def processArgument(arg): if type_traits.is_const(arg): return 'const '+processArgument(type_traits.remove_const(arg))
+ ' '
if type_traits.is_reference(arg): return processArgument(type_traits.remove_reference(arg)) +
'&'
if type_traits.is_pointer(arg): return processArgument(type_traits.remove_pointer(arg)) + '*' if type_traits.is_fundamental(arg): return str(arg) if type_traits.is_class(arg): theType = type_traits.remove_declarated(arg) return theType.demangled if type_traits.is_class_declaration(arg): theType = type_traits.remove_declarated(arg) return theType.demangled
for class_ in vectorClass: theConstructors = class_.constructors() for c in theConstructors: print '\n\n' print 'name :',c.demangled print 'location :',c.location.file_name if len(c.required_args)==0: print 'No required args' else : print 'required args:' for a in c.required_args: print ' ',processArgument(a.type) if len(c.optional_args)==0: print 'No optional args' else : print 'optional args:' for a in c.optional_args: print ' ',processArgument(a.type)
___________________________________________________________________
c++ header file: ___________________________________________________________________ #ifndef TESTVECTOR #define TESTVECTOR
class egclass{};
template class vector { vector(unsigned long i, const egclass = egclass() ){} };
class xvector { xvector(unsigned long i, const egclass = egclass() ){} };
template class vector«double»;
#endif
__________________________________________________________________ The ouput is __________________________________________________________________ INFO Parsing source file "example.hpp" ...
INFO gccxml cmd: /usr/bin/gccxml -I"." "example.hpp"
-fxml="/tmp/tmp7BA-U2.xml"
name : xvector::xvector(xvector const&) location : /b/Papa/Workspace/pygccxmlTest/example.hpp required args: const xvector & No optional args
name : xvector::xvector(unsigned long, egclass) location : /b/Papa/Workspace/pygccxmlTest/example.hpp required args: long unsigned int optional args: const egclass
name : vector::vector(vector const&) location : /b/Papa/Workspace/pygccxmlTest/example.hpp required args: const vector & No optional args
name : vector::vector(unsigned long, egclass) location : /b/Papa/Workspace/pygccxmlTest/example.hpp required args: long unsigned int const egclass No optional args
___________________________________________________________________
So interestingly the problem is with templated classes. Is this a problem with pygccxml or gccxml ? I'll try to look at the xml file.
More progress. I firstly checked out and built gccxml from cvs. I then tried the same excerises as in my previous emails and got the same results. Also I had a look at the resulting xml file from running gcccxml on example.hpp in my last email. These two lines looked intersting : _____________________________________________________________________________________________________ <Constructor id="_138" name="vector" context="_40" access="private" mangled="_ZN6vectorIdEC1Em7egclass *INTERNAL* " demangled="vector<double>::vector(unsigned long, egclass)" location="f1:9" file="f1" line="9" inline="1"> <Argument name="i" type="_149" location="f1:9" file="f1" line="9"/> <Argument type="_90c" location="f1:9" file="f1" line="9" default="<gccxml-cast-expr>"/> </Constructor> <Constructor id="_145" name="xvector" context="_89" access="private" mangled="_ZN7xvectorC1Em7egclass *INTERNAL* " demangled="xvector::xvector(unsigned long, egclass)" location="f1:13" file="f1" line="13" inline="1"> <Argument name="i" type="_149" location="f1:13" file="f1" line="13"/> <Argument type="_90c" location="f1:13" file="f1" line="13" default="egclass()"/> </Constructor> ______________________________________________________________________________________________________ The default values look interesting. gccxml does pick up that there is a default value for the second parameter of the constructor in both the templated and non-templated classes. However <gccxml-cast-expr> is something I do not understand, it should be the same as egclass() I suspect. pygccxml does not pick this up at all and it doesn't show there being a default value where there is one. ___________________________________________________________ Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now. http://uk.answers.yahoo.com/
participants (1)
-
Nindi Singh