[pygccxml-commit] SF.net SVN: pygccxml: [1243] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-02-17 19:49:48
|
Revision: 1243 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1243&view=rev Author: roman_yakovenko Date: 2008-02-17 11:49:54 -0800 (Sun, 17 Feb 2008) Log Message: ----------- adding treatment to ellipsis ("...") in function definitions Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/calldef.py pygccxml_dev/pygccxml/declarations/cpptypes.py pygccxml_dev/pygccxml/declarations/namespace.py pygccxml_dev/pygccxml/parser/linker.py pygccxml_dev/pygccxml/parser/project_reader.py pygccxml_dev/pygccxml/parser/scanner.py pygccxml_dev/unittests/data/declarations_calldef.hpp pygccxml_dev/unittests/data/plain_c.c pygccxml_dev/unittests/decl_string_tester.py pygccxml_dev/unittests/declarations_tester.py pygccxml_dev/unittests/filters_tester.py pygccxml_dev/unittests/plain_c_tester.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -25,6 +25,7 @@ from cpptypes import type_t from cpptypes import dummy_type_t from cpptypes import unknown_t +from cpptypes import ellipsis_t from cpptypes import fundamental_t from cpptypes import void_t from cpptypes import char_t Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -39,7 +39,7 @@ class, that describes argument of "callable" declaration """ - def __init__( self, name='', type=None, default_value=None, attributes=None ): + def __init__( self, name='', type=None, default_value=None, attributes=None): object.__init__(self) self._name = name self._default_value = default_value @@ -52,6 +52,8 @@ return argument_t( name=keywd.get( 'name', self.name ) , type=keywd.get( 'type', self.type ) , default_value=keywd.get( 'default_value', self.default_value ) + , attributes=keywd.get( 'attributes', self.attributes ) ) + """ return argument_t( name=keywd.get( 'name', self.name ) , type=keywd.get( 'type', self.type ) @@ -59,10 +61,13 @@ , attributes=keywd.get( 'attributes', self.attributes ) ) def __str__(self): - if self.default_value==None: - return "%s %s"%(self.type, self.name) + if self.ellipsis: + return "..." else: - return "%s %s=%s"%(self.type, self.name, self.default_value) + if self.default_value==None: + return "%s %s"%(self.type, self.name) + else: + return "%s %s=%s"%(self.type, self.name, self.default_value) def __eq__(self, other): if not isinstance( other, self.__class__ ): @@ -89,6 +94,11 @@ , doc="""Argument name. @type: str""" ) + @property + def ellipsis(self): + """bool, if True argument represents ellipsis ( "..." ) in function definition""" + return isinstance( self.type, cpptypes.ellipsis_t ) + def _get_default_value(self): return self._default_value def _set_default_value(self, default_value): @@ -163,6 +173,10 @@ @type: list of L{argument_t}""") @property + def has_ellipsis( self ): + return self.arguments and self.arguments[-1].ellipsis + + @property def argument_types( self ): """list of all argument types""" return [ arg.type for arg in self.arguments ] @@ -209,21 +223,20 @@ , doc='''The type of the return value of the "callable" or None (constructors). @type: L{type_t} ''') - - def _get_overloads(self): + @property + def overloads(self): + """A list of overloaded "callables" (i.e. other callables with the same name within the same scope. + + @type: list of L{calldef_t} + """ if not self.parent: return [] # finding all functions with the same name - return self.parent.calldefs( - name=self.name - , function=lambda decl: not (decl is self ) - , allow_empty=True - , recursive=False ) + return self.parent.calldefs( name=self.name + , function=lambda decl: not (decl is self ) + , allow_empty=True + , recursive=False ) - overloads = property( _get_overloads - , doc="""A list of overloaded "callables" (i.e. other callables with the same name within the same scope. - @type: list of L{calldef_t}""" ) - def _get_has_extern(self): return self._has_extern def _set_has_extern(self, has_extern): Modified: pygccxml_dev/pygccxml/declarations/cpptypes.py =================================================================== --- pygccxml_dev/pygccxml/declarations/cpptypes.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/pygccxml/declarations/cpptypes.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -101,6 +101,17 @@ def _clone_impl( self ): return self +class ellipsis_t( type_t ): + """type, that represents "..." in function definition""" + def __init__( self ): + type_t.__init__( self ) + + def build_decl_string(self, with_defaults=True): + return '...' + + def _clone_impl( self ): + return self + ################################################################################ ## Fundamental types: @@ -460,6 +471,11 @@ self._arguments_types = new_arguments_types arguments_types = property( _get_arguments_types, _set_arguments_types , doc="list of argument L{types<type_t>}") + + @property + def has_ellipsis( self ): + return self.arguments_types and isinstance( self.arguments_types[-1], ellipsis_t ) + class free_function_type_t( type_t, calldef_type_t ): """describes free function type""" Modified: pygccxml_dev/pygccxml/declarations/namespace.py =================================================================== --- pygccxml_dev/pygccxml/declarations/namespace.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/pygccxml/declarations/namespace.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -72,7 +72,8 @@ , name=name , function=function , recursive=recursive ) - + ns = namespace + def namespaces( self, name=None, function=None, recursive=None, allow_empty=None ): """returns a set of namespace declarations, that are matched defined criterias""" return self._find_multiple( scopedef.scopedef_t._impl_matchers[ namespace_t.namespace ] @@ -80,7 +81,8 @@ , function=function , recursive=recursive , allow_empty=allow_empty) - + nss = namespaces + def free_function( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ): """returns reference to free function declaration, that is matched defined criterias""" return self._find_single( scopedef.scopedef_t._impl_matchers[ namespace_t.free_function ] Modified: pygccxml_dev/pygccxml/parser/linker.py =================================================================== --- pygccxml_dev/pygccxml/parser/linker.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/pygccxml/parser/linker.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -24,7 +24,7 @@ for d in self.__decls.itervalues(): self.__compiler = d.compiler break - + def _get_inst(self): return self.__inst def _set_inst(self, inst): @@ -43,6 +43,8 @@ base = declarated_t( declaration=self.__decls[ type_id ] ) self.__types[type_id] = base return base + elif '...' == type_id: + return ellipsis_t() else: return unknown_t() Modified: pygccxml_dev/pygccxml/parser/project_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/project_reader.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/pygccxml/parser/project_reader.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -465,7 +465,8 @@ types.extend( get_from_type( arg ) ) return types else: - assert isinstance( cpptype, pygccxml.declarations.unknown_t ) + assert isinstance( cpptype, ( pygccxml.declarations.unknown_t + , pygccxml.declarations.ellipsis_t ) ) return [] types = [] for decl in pygccxml.declarations.make_flatten( namespaces ): Modified: pygccxml_dev/pygccxml/parser/scanner.py =================================================================== --- pygccxml_dev/pygccxml/parser/scanner.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/pygccxml/parser/scanner.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -57,6 +57,7 @@ XML_NN_CONSTRUCTOR = "Constructor" XML_NN_CV_QUALIFIED_TYPE = "CvQualifiedType" XML_NN_DESTRUCTOR = "Destructor" +XML_NN_ELLIPSIS = "Ellipsis" XML_NN_ENUMERATION = "Enumeration" XML_NN_ENUMERATION_VALUE = "EnumValue" XML_NN_FIELD = "Field" @@ -113,6 +114,7 @@ , XML_NN_MEMBER_OPERATOR : self.__read_member_operator , XML_NN_METHOD : self.__read_method , XML_NN_GCC_XML : self.__read_version + , XML_NN_ELLIPSIS : self.__read_ellipsis } self.deep_declarations = [ XML_NN_CASTING_OPERATOR @@ -379,6 +381,13 @@ argument.default_value = None self.__inst.arguments.append( argument ) + def __read_ellipsis( self, attrs ): + if isinstance( self.__inst, calldef_type_t ): + self.__inst.arguments_types.append( '...' ) + else: + argument = argument_t( type='...' ) + self.__inst.arguments.append( argument ) + def __read_calldef( self, calldef, attrs, is_declaration ): #destructor for example doesn't have return type calldef.return_type = attrs.get( XML_AN_RETURNS, None ) Modified: pygccxml_dev/unittests/data/declarations_calldef.hpp =================================================================== --- pygccxml_dev/unittests/data/declarations_calldef.hpp 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/unittests/data/declarations_calldef.hpp 2008-02-17 19:49:54 UTC (rev 1243) @@ -1,65 +1,75 @@ -// Copyright 2004 Roman Yakovenko. -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef __declarations_calldef_hpp__ -#define __declarations_calldef_hpp__ - -namespace declarations{ namespace calldef{ - -class some_exception_t{}; - -class other_exception_t{}; - -void no_return_no_args(); - -int return_no_args(); - -void no_return_1_arg(int arg); - -int return_default_args( int arg=1, bool flag=false ); - -extern void static_call(); - -void calldef_with_throw() throw( some_exception_t, other_exception_t ); - -struct calldefs_t{ - calldefs_t(); - - calldefs_t(char); - - calldefs_t(int,double); - - calldefs_t(const calldefs_t&); - - virtual ~calldefs_t(); - - calldefs_t& operator=( const calldefs_t& ); - bool operator==( const calldefs_t& ); - operator char*() const; - virtual operator double(); - - static void static_call(); - - inline int member_inline_call(int i){ return i;} - - virtual void member_virtual_call(); - - virtual void member_pure_virtual_call() = 0; - - void member_const_call() const; - - calldefs_t* do_smth(const calldefs_t& other); -}; - -namespace std{ - class iostream; -} - -std::iostream& operator<<( std::iostream&, const calldefs_t& ); -std::iostream& operator>>( std::iostream&, calldefs_t& ); - -} } - -#endif//__declarations_calldef_hpp__ +// Copyright 2004 Roman Yakovenko. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef __declarations_calldef_hpp__ +#define __declarations_calldef_hpp__ + +namespace declarations{ namespace calldef{ + +class some_exception_t{}; + +class other_exception_t{}; + +void no_return_no_args(); + +int return_no_args(); + +void no_return_1_arg(int arg); + +int return_default_args( int arg=1, bool flag=false ); + +extern void static_call(); + +void calldef_with_throw() throw( some_exception_t, other_exception_t ); + +struct calldefs_t{ + calldefs_t(); + + calldefs_t(char); + + calldefs_t(int,double); + + calldefs_t(const calldefs_t&); + + virtual ~calldefs_t(); + + calldefs_t& operator=( const calldefs_t& ); + bool operator==( const calldefs_t& ); + operator char*() const; + virtual operator double(); + + static void static_call(); + + inline int member_inline_call(int i){ return i;} + + virtual void member_virtual_call(); + + virtual void member_pure_virtual_call() = 0; + + void member_const_call() const; + + calldefs_t* do_smth(const calldefs_t& other); +}; + +namespace std{ + class iostream; +} + +std::iostream& operator<<( std::iostream&, const calldefs_t& ); +std::iostream& operator>>( std::iostream&, calldefs_t& ); + +namespace ellipsis_tester{ + +struct ellipsis{ + void do_smth( int, ... ); +}; + +void do_smth_else( int, ... ); + +}//ellipsis_tester + +} } + +#endif//__declarations_calldef_hpp__ Modified: pygccxml_dev/unittests/data/plain_c.c =================================================================== --- pygccxml_dev/unittests/data/plain_c.c 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/unittests/data/plain_c.c 2008-02-17 19:49:54 UTC (rev 1243) @@ -9,8 +9,8 @@ void hello_print(const char *message); double hello_sum(double x, double y); +void do_smth( int, ... ); - #ifdef __cplusplus } #endif Modified: pygccxml_dev/unittests/decl_string_tester.py =================================================================== --- pygccxml_dev/unittests/decl_string_tester.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/unittests/decl_string_tester.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -40,6 +40,15 @@ return_default_args = self.global_ns.free_fun( 'return_default_args' ) decls = parser.parse_string( self.template % return_default_args.decl_string, self.config ) self.failUnless( decls, "Created decl_string for global function containes mistake" ) + + def test_all_mem_and_free_funs( self ): + ns = self.global_ns.ns( '::declarations::calldef' ) + for f in ns.mem_funs(): + decls = parser.parse_string( self.template % f.decl_string, self.config ) + self.failUnless( decls, "Created decl_string for member function containes mistake" ) + for f in ns.free_funs(): + decls = parser.parse_string( self.template % f.decl_string, self.config ) + self.failUnless( decls, "Created decl_string for member function containes mistake" ) def create_suite(): suite = unittest.TestSuite() Modified: pygccxml_dev/unittests/declarations_tester.py =================================================================== --- pygccxml_dev/unittests/declarations_tester.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/unittests/declarations_tester.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -160,6 +160,16 @@ else: self.failUnless( decl.return_type.decl_string in calldefs_cast_operators, "unable to find operator symbol for operator '%s'" % decl.decl_string ) + def test_ellipsis( self ): + ns = self.global_ns.ns( 'ellipsis_tester' ) + do_smth = ns.mem_fun( 'do_smth' ) + for a in do_smth.arguments: + print str(a) + self.failUnless( do_smth.has_ellipsis ) + do_smth_else = ns.free_fun( 'do_smth_else' ) + self.failUnless( do_smth_else.has_ellipsis ) + + class all_at_once_tester_t( declarations_t ): COMPILATION_MODE = COMPILATION_MODE.ALL_AT_ONCE def __init__(self, *args): Modified: pygccxml_dev/unittests/filters_tester.py =================================================================== --- pygccxml_dev/unittests/filters_tester.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/unittests/filters_tester.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -34,9 +34,9 @@ public_members = declarations.matcher.find( criteria, self.declarations ) if '0.9' in public_members[0].compiler: #2 empty classes, this compiler doesn't generate constructor and copy constructor - self.failUnless( 15 == len( public_members ) ) + self.failUnless( 16 == len( public_members ) ) else: - self.failUnless( 19 == len( public_members ) ) + self.failUnless( 20 == len( public_members ) ) def test_or_matcher( self ): criteria1 = declarations.regex_matcher_t( 'oper.*' Modified: pygccxml_dev/unittests/plain_c_tester.py =================================================================== --- pygccxml_dev/unittests/plain_c_tester.py 2008-02-17 18:07:39 UTC (rev 1242) +++ pygccxml_dev/unittests/plain_c_tester.py 2008-02-17 19:49:54 UTC (rev 1243) @@ -26,7 +26,11 @@ def test( self ): self.global_ns.free_fun( 'hello_sum' ) self.global_ns.free_fun( 'hello_print' ) - + declarations.print_declarations( self.global_ns ) + f = self.global_ns.free_fun( 'do_smth' ) + for arg in f.arguments: + print arg.type.decl_string + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |