[pygccxml-commit] SF.net SVN: pygccxml: [160] pyplusplus_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-05-24 12:36:37
|
Revision: 160 Author: roman_yakovenko Date: 2006-05-24 05:36:11 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=160&view=rev Log Message: ----------- implementing first draft of member variable references Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/member_variables_tester.py Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-24 12:36:11 UTC (rev 160) @@ -464,7 +464,7 @@ indent = declaration_based.declaration_based_t.indent GET_TEMPLATE = os.linesep.join([ - 'static %(type)s get_%(name)s(%(class_type)s& inst) {' + 'static %(type)s get_%(name)s( %(class_type)s& inst ) {' , indent( 'return inst.%(name)s;' ) , '}' , '' @@ -488,10 +488,18 @@ def _get_class_inst_type( self ): return declarations.declarated_t( self.declaration.parent ) + + def _get_exported_var_type( self ): + type_ = declarations.remove_reference( self.declaration.type ) + type_ = declarations.remove_const( type_ ) + if declarations.is_fundamental( type_ ) or declarations.is_enum( type_ ): + return type_ + else: + return self.declaration.type def _get_getter_type(self): return declarations.free_function_type_t( - return_type=self.declaration.type + return_type=self._get_exported_var_type() , arguments_types=[ self._get_class_inst_type() ] ) getter_type = property( _get_getter_type ) @@ -501,19 +509,26 @@ def _get_setter_type(self): return declarations.free_function_type_t( - return_type=self.declaration.type - , arguments_types=[ self._get_class_inst_type(), self.declaration.type ] ) + return_type=declarations.void_t() + , arguments_types=[ self._get_class_inst_type(), self._get_exported_var_type() ] ) setter_type = property( _get_setter_type ) - def _get_has_setter( self ): - return not declarations.is_const( self.declaration.type ) + def _get_has_setter( self ): + if declarations.is_fundamental( self._get_exported_var_type() ): + return True + elif declarations.is_enum( self._get_exported_var_type() ): + return True + elif declarations.is_const( declarations.remove_reference( self.declaration.type ) ): + return False + else: + return True has_setter = property( _get_has_setter ) def _create_impl(self): answer = [] cls_type = algorithm.create_identifier( self, self.declaration.parent.decl_string ) - substitutions = dict( type=self.declaration.type.decl_string + substitutions = dict( type=self._get_exported_var_type().decl_string , class_type=cls_type , name=self.declaration.name ) answer.append( self.GET_TEMPLATE % substitutions ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-05-24 12:36:11 UTC (rev 160) @@ -9,8 +9,26 @@ class variable_t(decl_wrapper.decl_wrapper_t, declarations.variable_t): def __init__(self, *arguments, **keywords): declarations.variable_t.__init__(self, *arguments, **keywords ) - decl_wrapper.decl_wrapper_t.__init__( self ) - + decl_wrapper.decl_wrapper_t.__init__( self ) + self._call_policies = None + + def _get_call_policies( self ): + return self._call_policies + def _set_call_policies( self, call_policies ): + self._call_policies = call_policies + + __call_policies_doc__ = \ + """There are usecase, when exporting member variable forces pyplusplus to + create accessors functions. Sometime, those functions requires call policies. + To be more specific: when you export member variable that has reference or + pointer type, you need to tell boost.python library how to manage object + life-time. In all cases, pyplusplus will give reasonable default value. I am + sure, that there are use cases, when you need to change it. You should use this + property to change it. + """ + call_policies = property( _get_call_policies, _set_call_policies + , doc=__call_policies_doc__ ) + def _exportable_impl( self ): if not isinstance( self.parent, declarations.class_t ): return '' Modified: pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2006-05-24 12:36:11 UTC (rev 160) @@ -11,7 +11,7 @@ def __init__( self ): object.__init__( self ) - def __call__(self, calldef): + def __call__(self, decl): raise NotImplementedError() class default_policy_resolver_t(resolver_t): @@ -31,7 +31,9 @@ return None def __call__(self, calldef): - assert isinstance( calldef, declarations.calldef_t ) + if not isinstance( calldef, declarations.calldef_t ): + return None + if not isinstance( calldef, declarations.constructor_t ): return self._resolve_by_type( calldef.return_type ) else: @@ -45,7 +47,9 @@ resolver_t.__init__( self ) def __call__( self, calldef ): - assert isinstance( calldef, declarations.calldef_t ) + if not isinstance( calldef, declarations.calldef_t ): + return None + if isinstance( calldef, declarations.constructor_t ): return None return_type = declarations.remove_alias( calldef.return_type ) @@ -63,7 +67,9 @@ = declarations.pointer_t( declarations.const_t( declarations.wchar_t() ) ) def __call__(self, calldef): - assert isinstance( calldef, declarations.calldef_t ) + if not isinstance( calldef, declarations.calldef_t ): + return None + if isinstance( calldef, declarations.constructor_t ): return None @@ -82,6 +88,9 @@ resolver_t.__init__( self ) def __call__(self, calldef): + if not isinstance( calldef, declarations.calldef_t ): + return None + if not isinstance( calldef, declarations.member_operator_t ): return None @@ -98,7 +107,29 @@ return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference ) else: return decl_wrappers.return_internal_reference() - + +class variable_accessors_resolver_t( resolver_t ): + def __init__( self ): + resolver_t.__init__( self ) + + def __init__( self, variable ): + if not isinstance( variable, declarations.variable_t ): + return None + + if not declarations.is_reference( variable.type ): + return None + + no_ref = declarations.remove_reference( self.declaration.type ) + base_type = declarations.remove_const( no_ref ) + if declarations.is_fundamental( base_type ) or declarations.is_enum( base_type ): + #the relevant code creator will generate code, that will return this member variable + #by value + return decl_wrappers.default_call_policies() + + + return self.declaration.type + + class built_in_resolver_t(resolver_t): def __init__( self, config=None): resolver_t.__init__( self ) Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-24 12:36:11 UTC (rev 160) @@ -251,8 +251,8 @@ return True if declarations.is_pointer( member.type ): return True - #if declarations.is_reference( member.type ): - #return True + if declarations.is_reference( member.type ): + return True if declarations.is_array( member.type ): return True if isinstance( member, declarations.class_t ): @@ -663,9 +663,9 @@ elif declarations.is_pointer( self.curr_decl.type ): wrapper = code_creators.member_variable_wrapper_t( variable=self.curr_decl ) maker = code_creators.member_variable_t( variable=self.curr_decl, wrapper=wrapper ) - #elif declarations.is_reference( self.curr_decl.type ): - #wrapper = code_creators.mem_var_ref_wrapper_t( variable=self.curr_decl ) - #maker = code_creators.mem_var_ref_t( variable=self.curr_decl, wrapper=wrapper ) + elif declarations.is_reference( self.curr_decl.type ): + wrapper = code_creators.mem_var_ref_wrapper_t( variable=self.curr_decl ) + maker = code_creators.mem_var_ref_t( variable=self.curr_decl, wrapper=wrapper ) else: maker = code_creators.member_variable_t( variable=self.curr_decl ) if wrapper: Modified: pyplusplus_dev/unittests/member_variables_tester.py =================================================================== --- pyplusplus_dev/unittests/member_variables_tester.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/unittests/member_variables_tester.py 2006-05-24 12:36:11 UTC (rev 160) @@ -18,7 +18,8 @@ , *args ) def customize(self, mb ): - mb.variable( 'prefered_color' ).alias = 'PreferedColor' + mb.variable( 'prefered_color' ).alias = 'PreferedColor' + mb.classes().always_expose_using_scope = True def change_default_color( self, module ): module.point.default_color = module.point.color.blue This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |