[pygccxml-commit] SF.net SVN: pygccxml: [887] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-01-30 12:08:53
|
Revision: 887 http://svn.sourceforge.net/pygccxml/?rev=887&view=rev Author: roman_yakovenko Date: 2007-01-30 04:08:48 -0800 (Tue, 30 Jan 2007) Log Message: ----------- expose operator= as "assign" function, with call policy "return_self" Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/data/operators_to_be_exported.hpp pyplusplus_dev/unittests/operators_tester.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2007-01-30 12:08:48 UTC (rev 887) @@ -316,7 +316,7 @@ @staticmethod def exportable( oper ): """returns True if Boost.Python or Py++ know how to export the operator""" - if isinstance( oper, declarations.member_operator_t ) and oper.symbol in ( '()', '[]' ): + if isinstance( oper, declarations.member_operator_t ) and oper.symbol in ( '()', '[]', '=' ): return '' if not operators_helper.is_supported( oper ): return messages.W1014 % oper.name @@ -335,6 +335,8 @@ alias = '__call__' elif self.symbol == '[]': alias = '__getitem__' + elif self.symbol == '=': + alias = 'assign' else: pass return alias Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2007-01-30 12:08:48 UTC (rev 887) @@ -18,6 +18,14 @@ ACCESS_TYPES = declarations.ACCESS_TYPES VIRTUALITY_TYPES = declarations.VIRTUALITY_TYPES +class impl_details: + class GAEUS_VALUES: #guess always expose using scope values + TRUE = 'true' + FALSE = 'false' + ALWAYS_TRUE = 'always true' + all = [ TRUE, FALSE, ALWAYS_TRUE ] + + always_expose_using_scope_documentation = \ """boolean, configures how Py++ should generate code for class. Py can generate code using IDL like syntax: @@ -49,7 +57,7 @@ """ def __init__(self): object.__init__( self ) - self._always_expose_using_scope = False + self._always_expose_using_scope = None self._indexing_suite = None self._equality_comparable = None self._less_than_comparable = None @@ -80,12 +88,24 @@ , doc="reference to indexing suite configuration class. " \ +"If the class is not STD container, returns None") - def _get_always_expose_using_scope( self ): - #I am almost sure this logic should be moved to code_creators + def guess_always_expose_using_scope_value( self ): if isinstance( self.indexing_suite, isuite2.indexing_suite2_t ) \ and ( self.indexing_suite.disable_methods or self.indexing_suite.disabled_methods_groups ): + return impl_details.GAEUS_VALUES.ALWAYS_TRUE + else: + return impl_details.GAEUS_VALUES.FALSE + + def _get_always_expose_using_scope( self ): + tmp = self.guess_always_expose_using_scope_value() + if tmp == impl_details.GAEUS_VALUES.ALWAYS_TRUE: return True + if None is self._always_expose_using_scope: + if impl_details.GAEUS_VALUES.TRUE == tmp: + self._always_expose_using_scope = True + else: + self._always_expose_using_scope = False return self._always_expose_using_scope + def _set_always_expose_using_scope( self, value ): self._always_expose_using_scope = value always_expose_using_scope = property( _get_always_expose_using_scope, _set_always_expose_using_scope @@ -328,17 +348,21 @@ vfunction_selector = lambda member: isinstance( member, declarations.member_function_t ) \ and member.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL members.extend( filter( vfunction_selector, self.private_members ) ) - #now lets filter out none public operators: Py++ does not support them right now - members = filter( lambda decl: not isinstance( decl, declarations.member_operator_t ) - or decl.access_type == declarations.ACCESS_TYPES.PUBLIC - , members ) + + def is_exportable( decl ): + #filter out non-public member operators - Py++ does not support them right now + if isinstance( decl, declarations.member_operator_t ) \ + and decl.access_type != declarations.ACCESS_TYPES.PUBLIC: + return False + #remove artificial constructors + if isinstance( decl, declarations.constructor_t ) and decl.is_artificial: + return False + if decl.ignore == True or decl.exportable == False: + return False + return True #-#if declarations.has_destructor( self ) \ #-# and not declarations.has_public_destructor( self ): - #remove artificial constructors - members = filter( lambda decl: not isinstance( decl, declarations.constructor_t ) - or not decl.is_artificial - , members ) - members = filter( lambda member: member.ignore == False and member.exportable, members ) + members = filter( is_exportable, members ) sorted_members = members if sort: sorted_members = sort( members ) @@ -484,3 +508,17 @@ def _readme_impl( self ): return self.is_wrapper_needed() + + def guess_always_expose_using_scope_value( self ): + def is_assign( oper ): + if oper.symbol != '=': + return False + if oper.is_artificial: + return False + if oper.access_type != ACCESS_TYPES.PUBLIC: + return False + return True + #MSVC 7.1 has problem with taking reference to operator= + if self.member_operators( is_assign, allow_empty=True, recursive=False ): + return impl_details.GAEUS_VALUES.ALWAYS_TRUE + return super(class_t, self).guess_always_expose_using_scope_value() Modified: pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2007-01-30 12:08:48 UTC (rev 887) @@ -115,6 +115,19 @@ else: return decl_wrappers.return_internal_reference() +class return_self_resolver_t( resolver_t ): + def __init__( self ): + resolver_t.__init__( self ) + + def __call__(self, calldef, hint=None): + if not isinstance( calldef, declarations.member_operator_t ): + return None + + if calldef.symbol != '=': + return None + + return decl_wrappers.return_self() + class variable_accessors_resolver_t( resolver_t ): def __init__( self ): resolver_t.__init__( self ) @@ -170,6 +183,7 @@ self.__resolvers.append( void_pointer_resolver_t() ) self.__resolvers.append( return_internal_reference_resolver_t() ) self.__resolvers.append( variable_accessors_resolver_t() ) + self.__resolvers.append( return_self_resolver_t() ) def __call__( self, calldef, hint=None ): for resolver in self.__resolvers: Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-01-30 12:08:48 UTC (rev 887) @@ -472,7 +472,7 @@ pass def visit_member_operator( self ): - if self.curr_decl.symbol in ( '()', '[]' ): + if self.curr_decl.symbol in ( '()', '[]', '=' ): self.visit_member_function() else: self.__types_db.update( self.curr_decl ) Modified: pyplusplus_dev/unittests/data/operators_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/operators_to_be_exported.hpp 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/unittests/data/operators_to_be_exported.hpp 2007-01-30 12:08:48 UTC (rev 887) @@ -1,29 +1,32 @@ -// 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 __operators_to_be_exported_hpp__ -#define __operators_to_be_exported_hpp__ - -#include "boost/rational.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 __operators_to_be_exported_hpp__ +#define __operators_to_be_exported_hpp__ + +#include "boost/rational.hpp" #include <iostream> - -namespace pyplusplus{ namespace rational{ - -typedef boost::rational< long int > pyrational; - -struct helper{ - - void instantiate(){ - sizeof( pyrational ); - boost::gcd<long int>( 1, 1); + +namespace pyplusplus{ namespace rational{ + +typedef boost::rational< long int > pyrational; + +struct helper{ + + void instantiate(){ + sizeof( pyrational ); + boost::gcd<long int>( 1, 1); boost::lcm<long int>( 1, 1); - std::cout << pyrational( 1,1); - } -}; - -} } - - -#endif//__operators_to_be_exported_hpp__ + std::cout << pyrational( 1,1); + pyrational x(1,1); + x = pyrational( 2, 3 ); + + } +}; + +} } + + +#endif//__operators_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/operators_tester.py =================================================================== --- pyplusplus_dev/unittests/operators_tester.py 2007-01-29 07:26:32 UTC (rev 886) +++ pyplusplus_dev/unittests/operators_tester.py 2007-01-30 12:08:48 UTC (rev 887) @@ -76,6 +76,9 @@ self.failUnless( 0 < r1 ) + r1 = pyrational( 5, 7 ) + self.failUnless( r1.assign( 17 ) == pyrational( 17, 1 ) ) + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) @@ -85,4 +88,4 @@ unittest.TextTestRunner(verbosity=2).run( create_suite() ) if __name__ == "__main__": - run_suite() \ No newline at end of file + run_suite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |