[pygccxml-commit] SF.net SVN: pygccxml: [822] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2006-12-31 08:18:38
|
Revision: 822
http://svn.sourceforge.net/pygccxml/?rev=822&view=rev
Author: roman_yakovenko
Date: 2006-12-31 00:18:38 -0800 (Sun, 31 Dec 2006)
Log Message:
-----------
adding new trasnformer - type_modifier
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/function_transformers/__init__.py
pyplusplus_dev/pyplusplus/function_transformers/transformers.py
pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp
pyplusplus_dev/unittests/function_transformations_tester.py
Modified: pyplusplus_dev/pyplusplus/function_transformers/__init__.py
===================================================================
--- pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2006-12-29 19:07:42 UTC (rev 821)
+++ pyplusplus_dev/pyplusplus/function_transformers/__init__.py 2006-12-31 08:18:38 UTC (rev 822)
@@ -44,3 +44,8 @@
def creator( function ):
return transformers.output_static_array_t( function, *args, **keywd )
return creator
+
+def modify_type( *args, **keywd ):
+ def creator( function ):
+ return transformers.type_modifier_t( function, *args, **keywd )
+ return creator
Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py
===================================================================
--- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-12-29 19:07:42 UTC (rev 821)
+++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-12-31 08:18:38 UTC (rev 822)
@@ -66,7 +66,7 @@
% ( function, self.arg_ref.name, arg.type)
def __str__(self):
- return "output(%d)"%(self.arg_index)
+ return "output(%d)"%(self.arg.name)
def required_headers( self ):
"""Returns list of header files that transformer generated code depends on."""
@@ -103,39 +103,31 @@
def configure_virtual_mem_fun( self, controller ):
self.__configure_v_mem_fun_default( controller.default_controller )
self.__configure_v_mem_fun_override( controller.override_controller )
-
-
+
# input_t
-class input_t(transformer.transformer_t):
- """Handles a single input variable.
-
- The reference on the specified variable is removed.
-
- void setValue(int& v) -> setValue(v)
+class type_modifier_t(transformer.transformer_t):
+ """Change/modify type of the argument.
+
+ Right now compiler should be able to use implicit conversion
"""
- def __init__(self, function, arg_ref):
+ def __init__(self, function, arg_ref, modifier):
"""Constructor.
- The specified argument must be a reference or a pointer.
-
- @param idx: Index of the argument that is an output value (the first arg has index 1).
- @type idx: int
+ modifier is callable, which take the type of the argument and should return
+ new type
"""
transformer.transformer_t.__init__( self, function )
self.arg = self.get_argument( arg_ref )
self.arg_index = self.function.arguments.index( self.arg )
+ self.modifier = modifier
- if not is_ref_or_ptr( self.arg.type ):
- raise ValueError( '%s\nin order to use "input" transformation, argument %s type must be a reference or a pointer (got %s).' ) \
- % ( function, self.arg_ref.name, arg.type)
-
def __str__(self):
- return "input(%d)"%(self.idx)
+ return "type_modifier(%s)" % self.arg.name
def __configure_sealed( self, controller ):
w_arg = controller.find_wrapper_arg( self.arg.name )
- w_arg.type = remove_ref_or_ptr( self.arg.type )
+ w_arg.type = self.modifier( self.arg.type )
def __configure_v_mem_fun_default( self, controller ):
self.__configure_sealed( controller )
@@ -147,8 +139,35 @@
self.__configure_sealed( controller )
def configure_virtual_mem_fun( self, controller ):
- self.__configure_v_mem_fun_default( controller.default_controller )
+ self.__configure_v_mem_fun_default( controller.default_controller )
+
+# input_t
+class input_t(type_modifier_t):
+ """Handles a single input variable.
+
+ The reference on the specified variable is removed.
+
+ void setValue(int& v) -> setValue(v)
+ """
+
+ def __init__(self, function, arg_ref):
+ """Constructor.
+
+ The specified argument must be a reference or a pointer.
+
+ @param idx: Index of the argument that is an output value (the first arg has index 1).
+ @type idx: int
+ """
+ type_modifier_t.__init__( self, function, arg_ref, remove_ref_or_ptr )
+
+ if not is_ref_or_ptr( self.arg.type ):
+ raise ValueError( '%s\nin order to use "input" transformation, argument %s type must be a reference or a pointer (got %s).' ) \
+ % ( function, self.arg_ref.name, arg.type)
+
+ def __str__(self):
+ return "input(%s)"%(self.arg.name)
+
# inout_t
class inout_t(transformer.transformer_t):
"""Handles a single input/output variable.
@@ -173,7 +192,7 @@
% ( function, self.arg_ref.name, arg.type)
def __str__(self):
- return "inout(%d)"%(self.arg_index)
+ return "inout(%s)"%(self.arg.name)
def __configure_sealed(self, controller):
w_arg = controller.find_wrapper_arg( self.arg.name )
@@ -230,7 +249,7 @@
if not is_ptr_or_array( self.arg.type ):
raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
- % ( function, self.arg_ref.name, arg.type)
+ % ( function, self.arg.name, self.arg.type)
self.array_size = size
self.array_item_type = declarations.array_item_type( self.arg.type )
@@ -308,7 +327,7 @@
if not is_ptr_or_array( self.arg.type ):
raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
- % ( function, self.arg_ref.name, arg.type)
+ % ( function, self.arg.name, self.arg.type)
self.array_size = size
self.array_item_type = declarations.array_item_type( self.arg.type )
Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp
===================================================================
--- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-12-29 19:07:42 UTC (rev 821)
+++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-12-31 08:18:38 UTC (rev 822)
@@ -208,6 +208,12 @@
}
};
+struct modify_type_tester_t{
+ int do_nothing( int& v ){
+ return v;
+ }
+};
+
}
#endif//__function_transformations_to_be_exported_hpp__
Modified: pyplusplus_dev/unittests/function_transformations_tester.py
===================================================================
--- pyplusplus_dev/unittests/function_transformations_tester.py 2006-12-29 19:07:42 UTC (rev 821)
+++ pyplusplus_dev/unittests/function_transformations_tester.py 2006-12-31 08:18:38 UTC (rev 822)
@@ -8,6 +8,7 @@
import math
import unittest
import fundamental_tester_base
+from pygccxml import declarations
from pyplusplus import function_transformers as ft
from pyplusplus.module_builder import call_policies
@@ -69,6 +70,10 @@
cls = mb.class_("bug_render_target_t")
cls.mem_fun("get_statistics", arg_types=['float &']*2).add_transformation( ft.output(0), ft.output(1) )
+
+ cls = mb.class_( 'modify_type_tester_t' )
+ do_nothing = cls.mem_fun( 'do_nothing' )
+ do_nothing.add_transformation( ft.modify_type(0, declarations.remove_reference ) )
def run_tests(self, module):
"""Run the actual unit tests.
@@ -214,6 +219,9 @@
tmp.get_statistics()
self.failUnless( 2.0 + 3.0 == module.bug_render_target_t.get_static_statistics( tmp ) )
+ tmp = module.modify_type_tester_t()
+ self.failUnless( 123 == tmp.do_nothing(123) )
+
def create_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(tester_t))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|