[pygccxml-commit] SF.net SVN: pygccxml:[1413] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-09-11 18:59:32
|
Revision: 1413 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1413&view=rev Author: roman_yakovenko Date: 2008-09-11 18:59:42 +0000 (Thu, 11 Sep 2008) Log Message: ----------- fix few bugs related to default\copy constructors Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/calldef.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/algorithms_tester.py Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2008-09-05 19:41:29 UTC (rev 1412) +++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2008-09-11 18:59:42 UTC (rev 1413) @@ -1010,18 +1010,22 @@ """ Creates wrapper class constructor from wrapped class instance. """ - def __init__( self, class_ ): + def __init__( self, constructor ): code_creator.code_creator_t.__init__( self ) - declaration_based.declaration_based_t.__init__( self, declaration=class_ ) + declaration_based.declaration_based_t.__init__( self, declaration=constructor ) + + @property + def parent_class( self ): + return self.declaration.parent def _create_declaration(self): result = [] - result.append( self.declaration.wrapper_alias ) + result.append( self.parent_class.wrapper_alias ) result.append( '(' ) if not self.target_configuration.boost_python_has_wrapper_held_type \ - or self.declaration.require_self_reference: + or self.parent_class.require_self_reference: result.append( 'PyObject* self, ' ) - declarated = declarations.declarated_t( self.declaration ) + declarated = declarations.declarated_t( self.parent_class ) const_decl = declarations.const_t( declarated ) const_ref_decl = declarations.reference_t( const_decl ) identifier = algorithm.create_identifier( self, const_ref_decl.decl_string ) @@ -1030,7 +1034,7 @@ return ''.join( result ) def _create_constructor_call( self ): - answer = [ algorithm.create_identifier( self, self.declaration.decl_string ) ] + answer = [ algorithm.create_identifier( self, self.parent_class.decl_string ) ] answer.append( '( arg )' ) return ''.join( answer ) @@ -1039,7 +1043,7 @@ answer.append( ': ' + self._create_constructor_call() ) answer.append( ' , ' + self.parent.boost_wrapper_identifier + '(){' ) answer.append( self.indent( '// copy constructor' ) ) - answer.append( self.indent( self.declaration.copy_constructor_body ) ) + answer.append( self.indent( self.declaration.body ) ) answer.append( '}' ) return os.linesep.join( answer ) @@ -1051,23 +1055,27 @@ """ Creates wrapper for compiler generated null constructor. """ - def __init__( self, class_ ): + def __init__( self, constructor ): code_creator.code_creator_t.__init__( self ) - declaration_based.declaration_based_t.__init__( self, declaration=class_ ) - + declaration_based.declaration_based_t.__init__( self, declaration=constructor ) + + @property + def parent_class( self ): + return self.declaration.parent + def _create_constructor_call( self ): - return algorithm.create_identifier( self, self.declaration.decl_string ) + '()' + return algorithm.create_identifier( self, self.parent_class.decl_string ) + '()' def _create_impl(self): - answer = [ self.declaration.wrapper_alias + '(' ] + answer = [ self.parent_class.wrapper_alias + '(' ] if not self.target_configuration.boost_python_has_wrapper_held_type \ - or self.declaration.require_self_reference: + or self.parent_class.require_self_reference: answer[0] = answer[0] + 'PyObject* self' answer[0] = answer[0] + ')' answer.append( ': ' + self._create_constructor_call() ) answer.append( ' , ' + self.parent.boost_wrapper_identifier + '(){' ) answer.append( self.indent( '// null constructor' ) ) - answer.append( self.indent( self.declaration.null_constructor_body ) ) + answer.append( self.indent( self.declaration.body ) ) answer.append( '}' ) return os.linesep.join( answer ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2008-09-05 19:41:29 UTC (rev 1412) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2008-09-11 18:59:42 UTC (rev 1413) @@ -185,8 +185,6 @@ self._registration_code_tail = [] self._declaration_code = [] self._wrapper_code = [] - self._null_constructor_body = '' - self._copy_constructor_body = '' self._destructor_code = [] self._exception_translation_code = None self._properties = [] @@ -298,16 +296,29 @@ return self._wrapper_code def _get_null_constructor_body(self): - return self._null_constructor_body + c = self.find_trivial_constructor() + if c: + return c.body + else: + return '' def _set_null_constructor_body(self, body): - self._null_constructor_body = body + c = self.find_trivial_constructor() + if c: + c.body = body null_constructor_body = property( _get_null_constructor_body, _set_null_constructor_body - , doc="null constructor code, that will be added as is to the null constructor of class-wrapper") + , doc="null constructor code, that will be added as is to the null constructor of class-wrapper" ) def _get_copy_constructor_body(self): - return self._copy_constructor_body + c = self.find_copy_constructor() + if c: + return c.body + else: + return '' + def _set_copy_constructor_body(self, body): - self._copy_constructor_body = body + c = self.find_copy_constructor() + if c: + c.body = body copy_constructor_body = property( _get_copy_constructor_body, _set_copy_constructor_body , doc="copy constructor code, that will be added as is to the copy constructor of class-wrapper") Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2008-09-05 19:41:29 UTC (rev 1412) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2008-09-11 18:59:42 UTC (rev 1413) @@ -594,12 +594,12 @@ copy_constr = self.curr_decl.find_copy_constructor() if not self.curr_decl.noncopyable and copy_constr and copy_constr.is_artificial: - cccc = code_creators.copy_constructor_wrapper_t( class_=self.curr_decl) + cccc = code_creators.copy_constructor_wrapper_t( constructor=copy_constr) wrapper.adopt_creator( cccc ) trivial_constr = self.curr_decl.find_trivial_constructor() if trivial_constr and trivial_constr.is_artificial and not noncopyable_vars: - tcons = code_creators.null_constructor_wrapper_t( class_=self.curr_decl ) + tcons = code_creators.null_constructor_wrapper_t( constructor=trivial_constr ) wrapper.adopt_creator( tcons ) exposed = self.expose_overloaded_mem_fun_using_macro( cls_decl, cls_cc ) Modified: pyplusplus_dev/unittests/algorithms_tester.py =================================================================== --- pyplusplus_dev/unittests/algorithms_tester.py 2008-09-05 19:41:29 UTC (rev 1412) +++ pyplusplus_dev/unittests/algorithms_tester.py 2008-09-11 18:59:42 UTC (rev 1413) @@ -268,7 +268,41 @@ self.failUnless( do_smth.exportable == False ) print do_smth.why_not_exportable() + +class constructors_code_tester_t( unittest.TestCase ): + def test(self): + code = """ + namespace xyz{ + struct Y; + + struct X{ + X(); + X( const X& ); + X( Y* ); + }; + } + """ + + mb = module_builder.module_builder_t( + [ module_builder.create_text_fc( code ) ] + , gccxml_path=autoconfig.gccxml.executable ) + + x = mb.class_( 'X' ) + x.include() + x.constructors().body = ' //all constructors body' + x.null_constructor_body = ' //null constructor body' + x.copy_constructor_body = ' //copy constructor body' + + mb.build_code_creator( 'XXX' ) + code = mb.code_creator.create() + tmp = code.split( x.null_constructor_body ) + self.failUnless( len( tmp ) == 2 ) + tmp = code.split( x.copy_constructor_body ) + self.failUnless( len( tmp ) == 2 ) + tmp = code.split( ' //all constructors body' ) + self.failUnless( len( tmp ) == 2 ) + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(doc_extractor_tester_t)) @@ -283,6 +317,7 @@ suite.addTest( unittest.makeSuite(exclude_erronious_tester_t)) suite.addTest( unittest.makeSuite(use_function_signature_bug_tester_t)) suite.addTest( unittest.makeSuite(exclude_ellipsis_tester_t)) + suite.addTest( unittest.makeSuite(constructors_code_tester_t)) return suite def run_suite(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |