[pygccxml-commit] SF.net SVN: pygccxml: [743] pyplusplus_dev_ft
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2006-11-21 20:48:01
|
Revision: 743
http://svn.sourceforge.net/pygccxml/?rev=743&view=rev
Author: roman_yakovenko
Date: 2006-11-21 12:47:59 -0800 (Tue, 21 Nov 2006)
Log Message:
-----------
the generated code could be compiled
Modified Paths:
--------------
pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py
pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
pyplusplus_dev_ft/pyplusplus/module_builder/builder.py
pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
pyplusplus_dev_ft/unittests/function_transformations_tester.py
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -93,8 +93,10 @@
result.append( self.create_function_ref_code( not self.works_on_instance ) )
if self.declaration.use_keywords:
- result.append( self.param_sep() )
- result.append( self.keywords_args() )
+ keywd_args = self.keywords_args()
+ if keywd_args:
+ result.append( self.param_sep() )
+ result.append( keywd_args )
if self.declaration.call_policies:
if not self.declaration.call_policies.is_default():
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_transformed.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -21,7 +21,8 @@
def __init__( self, function, wrapper=None ):
calldef_t.__init__( self, function=function, wrapper=wrapper )
-
+ #map( lambda transformer: transformer.configure_mem_fun
+
@property
def ft( self ): #function transformation
return self.declaration.transformations[0]
@@ -98,16 +99,18 @@
def create_body(self):
cntrl = self.ft.controller
- arg_utils = calldef_utils.argument_utils_t(
- self.declaration
- , algorithm.make_id_creator( self )
- , cntrl.wrapper_args )
-
+ 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 }
+
return cntrl.template.substitute(
- declare_variables=map( lambda var: var.declare_var_string(), cntrl.variables )
+ 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=cntrl.save_return_value_stmt
+ , 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=''
@@ -443,4 +446,4 @@
#~ self.declaration.arguments = self._subst_manager.wrapper_func.arg_list
#~ return answer
-
+
\ No newline at end of file
Modified: pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/code_creators/calldef_utils.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -39,6 +39,8 @@
return False
def keywords_args(self):
+ if not self.__args:
+ return ''
boost_arg = self.__id_creator( '::boost::python::arg' )
boost_obj = self.__id_creator( '::boost::python::object' )
result = ['( ']
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/controllers.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -3,7 +3,7 @@
from pygccxml import declarations
class variable_t( object ):
- def __init__( self, name, type, initialize_expr='' ):
+ def __init__( self, type, name, initialize_expr='' ):
self.__name = name
self.__type = type
self.__initialize_expr = initialize_expr
@@ -30,7 +30,7 @@
def __init__( self, function ):
object.__init__( self )
self.__function = function
- self.__variables = {} #name : variable
+ self.__variables = [] #variables
self.__names_in_use = set( map( lambda arg: arg.name, self.function.arguments ) )
@property
@@ -43,7 +43,8 @@
def declare_variable( self, type, name, initialize_expr='' ):
unique_name = self.__create_unique_var_name( name )
- self.__variables[ unique_name ] = variable_t( type, unique_name, initialize_expr )
+ self.__variables.append( variable_t( type, unique_name, initialize_expr ) )
+ return unique_name
def register_variable_name( self, name ):
return self.__create_unique_var_name( name )
@@ -53,19 +54,23 @@
unique_name = name
while 1:
if unique_name in self.__names_in_use:
- unique_name = "%s_%d" % ( name, n )
+ unique_name = "%s%d" % ( name, n )
n += 1
else:
self.__names_in_use.add( unique_name )
return unique_name
+ def apply( self, transformations ):
+ raise NotImplementedError()
+
class mem_fun_controller_t( controller_base_t ):
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 = []
self.__pre_call = []
self.__post_call = []
@@ -73,6 +78,12 @@
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 )
+
+ @property
+ def result_variable( self ):
+ return self.__result_var
@property
def template( self ):
@@ -110,7 +121,7 @@
return self.__return_variables
def return_variable( self, variable_name ):
- self.__return_variables.append( name )
+ self.__return_variables.append( variable_name )
@property
def pre_call( self ):
@@ -142,3 +153,4 @@
def set_return_stmt( self, stmt ):
self.__return_stmt = stmt
+
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/function_transformation.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -15,6 +15,7 @@
self.__controller = controllers.mem_fun_controller_t( function )
self.__transformers = map( lambda tr_creator: tr_creator( function ), transformer_creator )
self.__thread_safe = keywd.get( 'thread_safe', False )
+ self.__controller.apply( self.__transformers )
@property
def transformers( self ):
Modified: pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/function_transformers/transformers.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -77,4 +77,3 @@
controller.modify_argument_expression( self.arg_index, var_name )
#adding the variable to return variables list
controller.return_variable( var_name )
-
Modified: pyplusplus_dev_ft/pyplusplus/module_builder/builder.py
===================================================================
--- pyplusplus_dev_ft/pyplusplus/module_builder/builder.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/pyplusplus/module_builder/builder.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -378,7 +378,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive)
-
+ var = variable
+
def variables( self, name=None, function=None, type=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.scopedef_t} class documentation"""
return self.global_ns.variables( name=name
@@ -387,7 +388,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive)
-
+ vars = variables
+
def calldef( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.scopedef_t} class documentation"""
return self.global_ns.calldef( name=name
@@ -441,6 +443,7 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive )
+ mem_fun = member_function
def member_functions( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.scopedef_t} class documentation"""
@@ -452,6 +455,8 @@
, header_file=header_file
, recursive=recursive)
+ mem_funs = member_functions
+
def constructor( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.scopedef_t} class documentation"""
return self.global_ns.constructor( name=name
@@ -554,7 +559,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive )
-
+ free_fun = free_function
+
def free_functions( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.namespace_t} class documentation"""
return self.global_ns.free_functions( name=name
@@ -564,7 +570,8 @@
, header_dir=header_dir
, header_file=header_file
, recursive=recursive)
-
+ free_funs = free_functions
+
def free_operator( self, name=None, function=None, symbol=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
"""Please see L{decl_wrappers.namespace_t} class documentation"""
return self.global_ns.free_operator( name=name
Modified: pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/unittests/data/function_transformations_to_be_exported.hpp 2006-11-21 20:47:59 UTC (rev 743)
@@ -6,98 +6,116 @@
#ifndef __function_transformations_to_be_exported_hpp__
#define __function_transformations_to_be_exported_hpp__
-namespace ft{
+namespace ft2{
+
+struct calculator_t{
+
+ int assign_0_1_2( int& one, int& two ){
+ one = 1;
+ two = 2;
+ return 0;
+ }
+
+ void assign_1_2( int& one, int& two ){
+ assign_0_1_2( one, two );
+ }
+
+};
-struct image_t{
+}
- image_t( unsigned int h, unsigned int w )
- : m_height( h )
- , m_width( w )
- {}
+//~ namespace ft{
- // Made the method 'virtual' for now because func transformers
- // are currently only taken into account on virtual functions.
- void get_size( unsigned int& h, unsigned int& w ){
- h = m_height;
- w = m_width;
- }
+//~ struct image_t{
- // Return only one value
- virtual void get_one_value(unsigned int& h) {
- h = m_height;
- }
+ //~ image_t( unsigned int h, unsigned int w )
+ //~ : m_height( h )
+ //~ , m_width( w )
+ //~ {}
- // Like get_size() but with a return type and an additional argument
- // that has to be kept in the signature
- virtual int get_size2( unsigned int& h, unsigned int& w, int noref=0 ){
- h = m_height;
- w = m_width;
- return noref;
- }
+ //~ // Made the method 'virtual' for now because func transformers
+ //~ // are currently only taken into account on virtual functions.
+ //~ void get_size( unsigned int& h, unsigned int& w ){
+ //~ h = m_height;
+ //~ w = m_width;
+ //~ }
- // A method with an input argument
- virtual int input_arg(int& in){
- return in;
- }
+ //~ // Return only one value
+ //~ virtual void get_one_value(unsigned int& h) {
+ //~ h = m_height;
+ //~ }
- // A method taking an input array of fixed size
- virtual int fixed_input_array(int v[3]) {
- return v[0]+v[1]+v[2];
- }
+ //~ // Like get_size() but with a return type and an additional argument
+ //~ // that has to be kept in the signature
+ //~ virtual int get_size2( unsigned int& h, unsigned int& w, int noref=0 ){
+ //~ h = m_height;
+ //~ w = m_width;
+ //~ return noref;
+ //~ }
- // A method with a output array of fixed size
- virtual void fixed_output_array(int v[3]) {
- v[0] = 1;
- v[1] = 2;
- v[2] = 3;
- }
+ //~ // A method with an input argument
+ //~ virtual int input_arg(int& in){
+ //~ return in;
+ //~ }
- unsigned int m_width;
- unsigned int m_height;
+ //~ // A method taking an input array of fixed size
+ //~ virtual int fixed_input_array(int v[3]) {
+ //~ return v[0]+v[1]+v[2];
+ //~ }
-};
+ //~ // A method with a output array of fixed size
+ //~ virtual void fixed_output_array(int v[3]) {
+ //~ v[0] = 1;
+ //~ v[1] = 2;
+ //~ v[2] = 3;
+ //~ }
-// Provide an instance created in C++ (i.e. this is not a wrapper instance)
-image_t cpp_instance(12,13);
-image_t& get_cpp_instance() {
- return cpp_instance;
-}
+ //~ unsigned int m_width;
+ //~ unsigned int m_height;
-inline void
-get_image_size( image_t& img, unsigned int& h, unsigned int& w ){
- img.get_size( h, w );
-}
+//~ };
-// This is used for calling img.get_one_value() on an instance passed
-// in by Python.
-unsigned int get_image_one_value( image_t& img ) {
- unsigned int v;
- img.get_one_value(v);
- return v;
-}
+//~ // Provide an instance created in C++ (i.e. this is not a wrapper instance)
+//~ image_t cpp_instance(12,13);
+//~ image_t& get_cpp_instance() {
+ //~ return cpp_instance;
+//~ }
-// This is used for calling img.fixed_output_array() on an instance passed
-// in by Python.
-int image_fixed_output_array( image_t& img) {
- int v[3];
- img.fixed_output_array(v);
- return v[0]+v[1]+v[2];
-}
+//~ inline void
+//~ get_image_size( image_t& img, unsigned int& h, unsigned int& w ){
+ //~ img.get_size( h, w );
+//~ }
-//////////////////////////////////////////////////////////////////////
+//~ // This is used for calling img.get_one_value() on an instance passed
+//~ // in by Python.
+//~ unsigned int get_image_one_value( image_t& img ) {
+ //~ unsigned int v;
+ //~ img.get_one_value(v);
+ //~ return v;
+//~ }
-// A class without any virtual members
-struct no_virtual_members_t
-{
- bool member(int& v) { v=17; return true; }
-};
+//~ // This is used for calling img.fixed_output_array() on an instance passed
+//~ // in by Python.
+//~ int image_fixed_output_array( image_t& img) {
+ //~ int v[3];
+ //~ img.fixed_output_array(v);
+ //~ return v[0]+v[1]+v[2];
+//~ }
-struct ft_private_destructor_t{
- static void get_value( int& x ){ x = 21; }
-private:
- ~ft_private_destructor_t(){}
-};
+//~ //////////////////////////////////////////////////////////////////////
-}
+//~ // A class without any virtual members
+//~ struct no_virtual_members_t
+//~ {
+ //~ bool member(int& v) { v=17; return true; }
+//~ };
+//~ struct ft_private_destructor_t{
+ //~ static void get_value( int& x ){ x = 21; }
+//~ private:
+ //~ ~ft_private_destructor_t(){}
+//~ };
+
+//~ }
+
#endif//__function_transformations_to_be_exported_hpp__
Modified: pyplusplus_dev_ft/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 13:00:32 UTC (rev 742)
+++ pyplusplus_dev_ft/unittests/function_transformations_tester.py 2006-11-21 20:47:59 UTC (rev 743)
@@ -19,13 +19,17 @@
, *args )
def customize( self, mb ):
- mb.namespace( 'ft' ).exclude()
- image = mb.class_( "image_t" )
- image.include()
- image.add_wrapper_code( '' )
- image.member_functions().exclude()
- image.member_function( "get_size" ).include()
- image.member_function( "get_size" ).add_transformation( ft.output(0), ft.output(1) )
+ calc = mb.class_('calculator_t' )
+ calc.add_wrapper_code( '' )
+ assign_funs = calc.mem_funs( lambda decl: decl.name.startswith( 'assign' ) )
+ assign_funs.add_transformation( ft.output(0), ft.output(1) )
+
+ #~ image = mb.class_( "image_t" )
+ #~ image.include()
+ #~ image.add_wrapper_code( '' )
+ #~ image.member_functions().exclude()
+ #~ image.member_function( "get_size" ).include()
+ #~ image.member_function( "get_size" ).add_transformation( ft.output(0), ft.output(1) )
#~ image.member_function( "get_one_value" ).add_transformation( ft.output(0) )
#~ image.member_function( "get_size2" ).add_transformation( ft.output(0), ft.output(1) )
#~ image.member_function( "input_arg" ).add_transformation( ft.input(0) )
@@ -49,10 +53,10 @@
####### Do the tests directly on the wrapper C++ class ########
- img = module.image_t( 2, 6)
+ #~ img = module.image_t( 2, 6)
# Check a method that returns two values by reference
- self.assertEqual(img.get_size(), (2,6))
+ #~ self.assertEqual(img.get_size(), (2,6))
#~ # Check a method that only returns one value by reference
#~ self.assertEqual(img.get_one_value(), 2)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|