[pygccxml-commit] SF.net SVN: pygccxml: [756] pyplusplus_dev_ft/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2006-11-27 09:03:30
|
Revision: 756
http://svn.sourceforge.net/pygccxml/?rev=756&view=rev
Author: roman_yakovenko
Date: 2006-11-27 01:03:29 -0800 (Mon, 27 Nov 2006)
Log Message:
-----------
small refactoring - moving return statement logic out of code creators
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py
pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-26 20:15:57 UTC (rev 755)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-27 09:03:29 UTC (rev 756)
@@ -94,37 +94,14 @@
% { 'type': cntrl.result_variable.type.decl_string
, 'name' : cntrl.result_variable.name }
- post_call = os.linesep.join( cntrl.post_call )
+ return_stmt_creator = calldef_utils.return_stmt_creator_t( self
+ , self.controller
+ , self.controller.result_variable
+ , self.controller.return_variables )
- return_stmt = ''
- if cntrl.return_variables:
- return_vars = cntrl.return_variables[:]
- if not declarations.is_void( self.declaration.return_type ):
- if self.declaration.call_policies.is_default():
- return_vars.insert( 0, cntrl.result_variable.name )
- else:
- c_p_alias = cntrl.register_variable_name( 'call_policies_t' )
- c_p_typedef = 'typedef %s %s;' \
- % ( self.declaration.call_policies.create_template_arg( self )
- , c_p_alias )
- post_call = os.linesep.join( [post_call, c_p_typedef] )
- return_vars.insert( 0
- , declarations.call_invocation.join(
- declarations.templates.join( make_object, [c_p_alias] )
- , [cntrl.result_variable.name] ) )
-
- return_stmt = declarations.call_invocation.join( make_tuple, return_vars )
- if self.LINE_LENGTH < len( return_stmt ):
- return_stmt = declarations.call_invocation.join(
- make_tuple
- , return_vars
- , os.linesep + self.indent( self.PARAM_SEPARATOR, 6 ) )
- elif not declarations.is_void( self.declaration.return_type ):
- return_stmt = cntrl.result_variable.name
- else:
- pass
- if return_stmt:
- return_stmt = 'return ' + return_stmt + ';'
+ post_call = os.linesep.join( cntrl.post_call )
+ if return_stmt_creator.pre_return_code:
+ post_call = os.linesep.join( [post_call, return_stmt_creator.pre_return_code] )
return cntrl.template.substitute({
'declare_variables' : os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
@@ -133,7 +110,7 @@
, 'save_result' : result_var_assign
, 'function' : self.resolve_function_ref()
, 'arg_expressions' : self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
- , 'return' : return_stmt
+ , 'return' : return_stmt_creator.statement
})
def _create_impl(self):
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py 2006-11-26 20:15:57 UTC (rev 755)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py 2006-11-27 09:03:29 UTC (rev 756)
@@ -3,6 +3,8 @@
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
+import os
+import algorithm
import code_creator
from pygccxml import declarations
from pyplusplus import decl_wrappers
@@ -91,5 +93,60 @@
params.append( decl_wrappers.python_traits.call_traits( arg.type ) % self.argument_name( index ) )
return ', '.join( params )
+class return_stmt_creator_t( object ):
+ def __init__( self, creator, controller, result_var, return_vars ):
+ object.__init__( self )
+ self.__creator = creator
+ self.__controller = controller
+ self.__function = controller.function
+ self.__return_vars = return_vars[:]
+ self.__pre_return_code = None
+ self.__return_stmt = None
+ self.__result_var = result_var
+ self.__call_policy_alias = controller.register_variable_name( 'call_policies_t' )
+
+ @property
+ def pre_return_code( self ):
+ if None is self.__pre_return_code:
+ if not self.__controller.return_variables \
+ or self.__function.call_policies.is_default() \
+ or declarations.is_void( self.__function.return_type ):
+ self.__pre_return_code = ''
+ else:
+ c_p_typedef = 'typedef %s %s;' \
+ % ( self.__function.call_policies.create_template_arg( self.__creator )
+ , self.__call_policy_alias )
+ self.__pre_return_code = c_p_typedef
+ return self.__pre_return_code
+ @property
+ def statement( self ):
+ if None is self.__return_stmt:
+ stmt = ''
+ make_tuple = algorithm.create_identifier( self.__creator, 'boost::python::make_tuple' )
+ make_object = algorithm.create_identifier( self.__creator, 'pyplusplus::call_policies::make_object' )
+ if self.__return_vars:
+ if not declarations.is_void( self.__function.return_type ):
+ if self.__function.call_policies.is_default():
+ self.__return_vars.insert( 0, self.__result_var.name )
+ else:
+ self.__return_vars.insert( 0
+ , declarations.call_invocation.join(
+ declarations.templates.join( make_object, [self.__call_policy_alias] )
+ , [self.__result_var.name] ) )
+
+ stmt = declarations.call_invocation.join( make_tuple, self.__return_vars )
+ if self.__creator.LINE_LENGTH < len( stmt ):
+ stmt = declarations.call_invocation.join(
+ make_tuple
+ , self.__return_vars
+ , os.linesep + self.__creator.indent( self.__creator.PARAM_SEPARATOR, 6 ) )
+ elif not declarations.is_void( self.__function.return_type ):
+ stmt = self.__result_var.name
+ else:
+ pass
+ if stmt:
+ stmt = 'return ' + stmt + ';'
+ self.__return_stmt = stmt
+ return self.__return_stmt
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-26 20:15:57 UTC (rev 755)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-27 09:03:29 UTC (rev 756)
@@ -47,19 +47,19 @@
default_body = Template( os.linesep.join([
'$declare_variables'
, '$pre_call'
- , '$declare_wrapped_class_inst'
- , 'if( dynamic_cast< $wrapped_class* >( boost::addressof( $wrapped_class_inst_var_name ) ) ){'
- # The following call is done on an instance created in Python i.e. a
- # wrapper instance. this call might invoke python code.
- , ' $save_return_value_stmt$wrapped_class_inst_var_name->$wrapped_class::$function_name($input_params);'
+ , 'if( $wrapper_class $py_wrapper_var = dynamic_cast< $wrapper_class >( boost::addressof( $wrapped_inst ) ) ){'
+ , ' // The following call is done on an instance created in Python i.e.'
+ , ' // a wrapper instance. this call might invoke python code.'
+ , ' // a wrapper instance. this call might invoke python code.'
+ , ' $py_save_result$wrapped_inst->$wrapped_class::$function_name($py_arg_expressions);'
, '}'
, 'else{'
- # The following call is done on an instance created in C++, so it won't
- # invoke python code.
- , ' $save_return_value_stmt$function_name($input_params);'
+ , " // The following call is done on an instance created in C++, so it won't "
+ , ' // invoke python code.'
+ , ' $cpp_save_result$wrapped_inst.$function_name($cpp_arg_expressions);'
, '}'
, '$post_call'
- , '$return_stmt'
+ , '$return'
]))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|