[pygccxml-commit] SF.net SVN: pygccxml: [745] pyplusplus_dev_ft
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2006-11-21 21:59:02
|
Revision: 745
http://svn.sourceforge.net/pygccxml/?rev=745&view=rev
Author: roman_yakovenko
Date: 2006-11-21 13:59:01 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
generated code now works as expected
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 20:48:45 UTC (rev 744)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 21:59:01 UTC (rev 745)
@@ -99,22 +99,35 @@
def create_body(self):
cntrl = self.ft.controller
- save_return_value_stmt = ''
- if not cntrl.save_return_value_stmt \
- and not declarations.is_void( self.declaration.return_type ):
- save_return_value_stmt = '%(type)s %(name)s = ' \
- % { 'type': cntrl.result_variable.type.decl_string
- , 'name' : cntrl.result_variable.name }
+
+ result_var_assign = ''
+ if not declarations.is_void( self.declaration.return_type ):
+ result_var_assign = '%(type)s %(name)s = ' \
+ % { 'type': cntrl.result_variable.type.decl_string
+ , 'name' : cntrl.result_variable.name }
+
+ return_stmt = ''
+ if cntrl.return_variables:
+ return_vars = cntrl.return_variables[:]
+ if not declarations.is_void( self.declaration.return_type ):
+ return_vars.insert( 0, cntrl.result_variable.name )
+ return_stmt = declarations.call_invocation.join( 'boost::python::make_tuple', return_vars )
+ 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 + ';'
- return cntrl.template.substitute(
- declare_variables=os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
- , pre_call=os.linesep.join( cntrl.pre_call )
- , post_call=os.linesep.join( cntrl.post_call )
- , save_return_value_stmt=save_return_value_stmt
- , function=self.__this_arg.name + '.' + self.declaration.name
- , arg_expressions=self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
- , return_stmt=''
- )
+ return cntrl.template.substitute({
+ 'declare_variables' : os.linesep.join( map( lambda var: var.declare_var_string(), cntrl.variables ) )
+ , 'pre_call' : os.linesep.join( cntrl.pre_call )
+ , 'post_call' : os.linesep.join( cntrl.post_call )
+ , 'save_result' : result_var_assign
+ , 'function' : self.__this_arg.name + '.' + self.declaration.name
+ , 'arg_expressions' : self.PARAM_SEPARATOR.join( cntrl.arg_expressions )
+ , 'return' : return_stmt
+ })
def _create_impl(self):
answer = ['// Transformed wrapper function for "%s"' % self.declaration ]
@@ -446,4 +459,4 @@
#~ self.declaration.arguments = self._subst_manager.wrapper_func.arg_list
#~ return answer
-
\ No newline at end of file
+
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 20:48:45 UTC (rev 744)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 21:59:01 UTC (rev 745)
@@ -68,7 +68,6 @@
def __init__( self, function ):
controller_base_t.__init__( self, function )
self.__wrapper_args = function.arguments[:]
- self.__wrapper_return_type = function.return_type
self.__result_var = variable_t( self.function.return_type
, self.register_variable_name( 'result' ) )
self.__return_variables = []
@@ -76,7 +75,6 @@
self.__post_call = []
self.__save_return_value_stmt = None
self.__arg_expressions = [ arg.name for arg in function.arguments ]
- self.__return_stmt = None
def apply( self, transformations ):
map( lambda t: t.configure_mem_fun( self ), transformations )
@@ -107,14 +105,13 @@
def modify_argument_expression( self, index, expression ):
self.arg_expressions[ index ] = expression
-
- def __get_wrapper_return_type( self ):
- return self.__wrapper_return_type
- def __set_wrapper_return_type( self, type_ ):
- if isinstane( type, types.StringTypes ):
- type_ = declarations.dummy_type_t( type_ )
- self.__wrapper_return_type = type_
- wrapper_return_type = property( __get_wrapper_return_type, __set_wrapper_return_type )
+
+ @property
+ def wrapper_return_type( self ):
+ if len( self.return_variables ):
+ return declarations.dummy_type_t( 'boost::python::tuple' )
+ else:
+ return self.function.return_type
@property
def return_variables( self ):
@@ -136,12 +133,6 @@
def add_post_call_code( self, code ):
self.__post_call.append( code )
-
- def __get_save_return_value_stmt( self ):
- return self.__save_return_value_stmt
- def __set_save_return_value_stmt( self, expr ):
- self.__save_return_value_stmt = expr
- save_return_value_stmt = property( __get_save_return_value_stmt, __set_save_return_value_stmt )
def set_input_param( self, index, var_name_or_expr ):
self.__input_params[ index ] = var_name_or_expr
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-21 20:48:45 UTC (rev 744)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/templates.py 2006-11-21 21:59:01 UTC (rev 745)
@@ -15,9 +15,9 @@
body = Template( os.linesep.join([
'$declare_variables'
, '$pre_call'
- , '$save_return_value_stmt$function($arg_expressions);'
+ , '$save_result$function($arg_expressions);'
, '$post_call'
- , '$return_stmt'
+ , '$return'
]))
class mem_fun_v:
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 20:48:45 UTC (rev 744)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 21:59:01 UTC (rev 745)
@@ -52,7 +52,9 @@
"""
####### Do the tests directly on the wrapper C++ class ########
-
+ calc = module.calculator_t()
+ self.failUnless( ( 0, 1, 2 ) == calc.assign_0_1_2() )
+ self.failUnless( ( 1, 2 ) == calc.assign_1_2() )
#~ img = module.image_t( 2, 6)
# Check a method that returns two values by reference
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|