[pygccxml-commit] SF.net SVN: pygccxml:[1856]
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2011-03-17 20:25:38
|
Revision: 1856 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1856&view=rev Author: roman_yakovenko Date: 2011-03-17 20:25:25 +0000 (Thu, 17 Mar 2011) Log Message: ----------- improving bit fields related generated code - thanks to Scott Sturdivant for the bug report Modified Paths: -------------- pyplusplus_dev/docs/history/history.rest pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp pyplusplus_dev/unittests/member_variables_tester.py sphinx/conf.py Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2011-03-07 21:02:46 UTC (rev 1855) +++ pyplusplus_dev/docs/history/history.rest 2011-03-17 20:25:25 UTC (rev 1856) @@ -80,6 +80,9 @@ 13. Thanks to Aron Xu, for pointing out that it is better to use "os.name", instead of "sys.platform" for platform specific logic +14. Thanks to Scott Sturdivant, for reporting the bug, related to bit fields code generation. + The bug was fixed. + ----------- Version 1.0 ----------- Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2011-03-07 21:02:46 UTC (rev 1855) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2011-03-17 20:25:25 UTC (rev 1856) @@ -281,27 +281,28 @@ member_variable_base_t.__init__( self, variable=variable, wrapper=wrapper ) def _create_impl( self ): - doc = '' - if self.declaration.type_qualifiers.has_static: - add_property = 'add_static_property' - else: - if self.documentation: - doc = self.documentation - add_property = 'add_property' - answer = [ add_property ] + answer = [ 'add_property' ] answer.append( '( ' ) answer.append('"%s"' % self.alias) answer.append( self.PARAM_SEPARATOR ) - answer.append( '(%s)(&%s)' - % ( self.wrapper.getter_type, self.wrapper.getter_full_name ) ) + make_function = algorithm.create_identifier( self, '::boost::python::make_function' ) + + answer.append( '%(mk_func)s( (%(getter_type)s)(&%(wfname)s) )' + % { 'mk_func' : make_function + , 'getter_type' : self.wrapper.getter_type + , 'wfname' : self.wrapper.getter_full_name } ) + if self.wrapper.has_setter: answer.append( self.PARAM_SEPARATOR ) - answer.append( '(%s)(&%s)' - % ( self.wrapper.setter_type, self.wrapper.setter_full_name ) ) - if doc: + answer.append( '%(mk_func)s( (%(setter_type)s)(&%(wfname)s) )' + % { 'mk_func' : make_function + , 'setter_type' : self.wrapper.setter_type + , 'wfname' : self.wrapper.setter_full_name } ) + + if self.documentation: answer.append( self.PARAM_SEPARATOR ) - answer.append( doc ) + answer.append( self.documentation ) answer.append( ' ) ' ) code = ''.join( answer ) @@ -318,18 +319,17 @@ """ creates get/set accessors for bit fields """ - indent = code_creator.code_creator_t.indent - BF_GET_TEMPLATE = os.linesep.join([ - '%(type)s get_%(name)s() const {' - , indent( 'return %(name)s;' ) + GET_TEMPLATE =os.linesep.join([ + 'static %(type)s get_%(name)s(%(cls_type)s inst ){' + , indent( 'return inst.%(name)s;' ) , '}' , '' ]) - BF_SET_TEMPLATE = os.linesep.join([ - 'void set_%(name)s( %(type)s new_value ){ ' - , indent( '%(name)s = new_value;' ) + SET_TEMPLATE = os.linesep.join([ + 'static void set_%(name)s( %(cls_type)s inst, %(type)s new_value ){ ' + , indent( 'inst.%(name)s = new_value;' ) , '}' , '' ]) @@ -342,12 +342,17 @@ return self.parent.full_name + '::' + 'get_' + self.declaration.name getter_full_name = property( _get_getter_full_name ) + def inst_arg_type( self, has_const ): + inst_arg_type = declarations.declarated_t( self.declaration.parent ) + if has_const: + inst_arg_type = declarations.const_t(inst_arg_type) + inst_arg_type = declarations.reference_t(inst_arg_type) + return inst_arg_type + def _get_getter_type(self): - return declarations.member_function_type_t.create_decl_string( + return declarations.free_function_type_t.create_decl_string( return_type=self.declaration.type - , class_decl_string=self.parent.full_name - , arguments_types=[] - , has_const=True + , arguments_types=[ self.inst_arg_type(True) ] , with_defaults=False) getter_type = property( _get_getter_type ) @@ -356,11 +361,9 @@ setter_full_name = property(_get_setter_full_name) def _get_setter_type(self): - return declarations.member_function_type_t.create_decl_string( + return declarations.free_function_type_t.create_decl_string( return_type=declarations.void_t() - , class_decl_string=self.parent.full_name - , arguments_types=[self.declaration.type] - , has_const=False + , arguments_types=[ self.inst_arg_type(False), self.declaration.type ] , with_defaults=False) setter_type = property( _get_setter_type ) @@ -370,11 +373,15 @@ def _create_impl(self): answer = [] - substitutions = dict( type=self.declaration.type.decl_string - , name=self.declaration.name ) - answer.append( self.BF_GET_TEMPLATE % substitutions ) + answer.append( self.GET_TEMPLATE % { + 'type' : self.declaration.type.decl_string + , 'name' : self.declaration.name + , 'cls_type' : self.inst_arg_type( has_const=True ) }) if self.has_setter: - answer.append( self.BF_SET_TEMPLATE % substitutions ) + answer.append( self.SET_TEMPLATE % { + 'type' : self.declaration.type.decl_string + , 'name' : self.declaration.name + , 'cls_type' : self.inst_arg_type( has_const=False ) }) return os.linesep.join( answer ) def _get_system_files_impl( self ): Modified: pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2011-03-07 21:02:46 UTC (rev 1855) +++ pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2011-03-17 20:25:25 UTC (rev 1856) @@ -48,6 +48,19 @@ void set_a( bit_fields_t& inst, unsigned int new_value ); unsigned int get_b(const bit_fields_t& inst); +struct status_bits_t{ + int bcr : 3; + int status : 3; +}; + +struct status_bits_keeper_t{ + + int get_sb_bcr(){ return status_bits.bcr; } + int get_sb_status(){ return status_bits.status; } + + status_bits_t status_bits; +}; + struct array_t{ array_t() { @@ -165,11 +178,11 @@ static int* none_image; }; - + class Andy{ protected: Andy() : userData(NULL) {} - + virtual ~Andy() {} public: Modified: pyplusplus_dev/unittests/member_variables_tester.py =================================================================== --- pyplusplus_dev/unittests/member_variables_tester.py 2011-03-07 21:02:46 UTC (rev 1855) +++ pyplusplus_dev/unittests/member_variables_tester.py 2011-03-17 20:25:25 UTC (rev 1856) @@ -37,6 +37,11 @@ bf.b = value def run_tests(self, module): + sbk = module.status_bits_keeper_t() + sb = sbk.status_bits + sb.bcr = 2 + self.failUnless( sbk.get_sb_bcr() == 2 ) + self.failIfRaisesAny( module.point ) xypoint = module.point() self.failUnless( module.point.instance_count == 1) @@ -78,7 +83,7 @@ data = data_type.from_address( image.data ) for j in range(5): self.failUnless( j == data[j] ) - + int_array = ctypes.c_int * 5 array = int_array() for i in range( 5 ): @@ -87,7 +92,7 @@ data = data_type.from_address( image.data ) for j in range(5): self.failUnless( j*2 == data[j] ) - + data_type = ctypes.POINTER( ctypes.c_int ) data = data_type.from_address( module.image_t.none_image ) self.failUnless( 1997 == data.contents.value ) Modified: sphinx/conf.py =================================================================== --- sphinx/conf.py 2011-03-07 21:02:46 UTC (rev 1855) +++ sphinx/conf.py 2011-03-17 20:25:25 UTC (rev 1856) @@ -107,9 +107,9 @@ # built documents. # # The short X.Y version. -version = 'SVN - Mar 7 2011' +version = 'ersion( SVN - Mar 17 2011 )' # The full version, including alpha/beta/rc tags. -release = 'SVN - Mar 7 2011' +release = 'ersion( SVN - Mar 17 2011 )' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |