[pygccxml-commit] SF.net SVN: pygccxml: [516] pyplusplus_dev/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2006-09-04 06:49:44
|
Revision: 516
http://svn.sourceforge.net/pygccxml/?rev=516&view=rev
Author: roman_yakovenko
Date: 2006-09-03 23:49:35 -0700 (Sun, 03 Sep 2006)
Log Message:
-----------
small refactoring before introducing
"function transformation" functionality
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/__init__.py
pyplusplus_dev/pyplusplus/code_creators/calldef.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2006-09-04 06:17:49 UTC (rev 515)
+++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2006-09-04 06:49:35 UTC (rev 516)
@@ -74,6 +74,9 @@
from calldef import copy_constructor_wrapper_t
from calldef import null_constructor_wrapper_t
+from calldef import mem_fun_v_transformed_t
+from calldef import mem_fun_v_transformed_wrapper_t
+
from global_variable import global_variable_base_t
from global_variable import global_variable_t
from global_variable import array_gv_t
@@ -116,3 +119,49 @@
from exception_translator import exception_translator_t
from exception_translator import exception_translator_register_t
+from pygccxml import declarations
+
+ACCESS_TYPES = declarations.ACCESS_TYPES
+VIRTUALITY_TYPES = declarations.VIRTUALITY_TYPES
+
+
+def guess_mem_fun_creator_classes( decl ):
+ """return tuple of ( registration, declaration ) code creator classes"""
+ maker_cls = None
+ fwrapper_cls = None
+ access_level = decl.parent.find_out_member_access_type( decl )
+ if access_level == ACCESS_TYPES.PUBLIC:
+ if decl.virtuality == VIRTUALITY_TYPES.NOT_VIRTUAL:
+ maker_cls = mem_fun_t
+ elif decl.virtuality == VIRTUALITY_TYPES.PURE_VIRTUAL:
+ fwrapper_cls = mem_fun_pv_wrapper_t
+ maker_cls = mem_fun_pv_t
+ else:
+ if decl.overridable:
+ fwrapper_cls = mem_fun_v_wrapper_t
+ maker_cls = mem_fun_v_t
+ elif access_level == ACCESS_TYPES.PROTECTED:
+ if decl.virtuality == VIRTUALITY_TYPES.NOT_VIRTUAL:
+ if decl.has_static:
+ fwrapper_cls = mem_fun_protected_s_wrapper_t
+ maker_cls = mem_fun_protected_s_t
+ else:
+ fwrapper_cls = mem_fun_protected_wrapper_t
+ maker_cls = mem_fun_protected_t
+ elif decl.virtuality == VIRTUALITY_TYPES.VIRTUAL:
+ if decl.overridable:
+ fwrapper_cls = mem_fun_protected_v_wrapper_t
+ maker_cls = mem_fun_protected_v_t
+ else:
+ fwrapper_cls = mem_fun_protected_pv_wrapper_t
+ maker_cls = mem_fun_protected_pv_t
+ else: #private
+ if decl.virtuality == VIRTUALITY_TYPES.NOT_VIRTUAL:
+ pass#in general we should not come here
+ elif decl.virtuality == VIRTUALITY_TYPES.PURE_VIRTUAL:
+ fwrapper_cls = mem_fun_private_pv_wrapper_t
+ else:
+ if decl.overridable:
+ fwrapper_cls = mem_fun_v_wrapper_t
+ maker_cls = mem_fun_v_t
+ return ( maker_cls, fwrapper_cls )
Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-09-04 06:17:49 UTC (rev 515)
+++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-09-04 06:49:35 UTC (rev 516)
@@ -439,7 +439,130 @@
answer.append( self.create_default_function() )
return os.linesep.join( answer )
+class mem_fun_v_transformed_t( calldef_t ):
+ def __init__( self, function, wrapper=None ):
+ calldef_t.__init__( self, function=function, wrapper=wrapper )
+ self.default_function_type_alias = 'default_' + self.function_type_alias
+ def create_function_type_alias_code( self, exported_class_alias=None ):
+ result = []
+
+ ftype = self.declaration.function_type()
+ result.append( 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) )
+ if self.wrapper:
+ result.append( os.linesep )
+ ftype = self.wrapper.function_type()
+ result.append( 'typedef %s;' % ftype.create_typedef( self.default_function_type_alias ) )
+ return ''.join( result )
+
+ def create_doc(self):
+ return None
+
+ def create_function_ref_code(self, use_function_alias=False):
+ result = []
+ if use_function_alias:
+ result.append( '%s(&%s)'
+ % ( self.function_type_alias, declarations.full_name( self.declaration ) ) )
+ if self.wrapper:
+ result.append( self.param_sep() )
+ result.append( '%s(&%s)'
+ % ( self.default_function_type_alias, self.wrapper.default_full_name() ) )
+ elif self.declaration.create_with_signature:
+ result.append( '(%s)(&%s)'
+ % ( self.declaration.function_type().decl_string
+ , declarations.full_name( self.declaration ) ) )
+ if self.wrapper:
+ result.append( self.param_sep() )
+ result.append( '(%s)(&%s)'
+ % ( self.wrapper.function_type().decl_string, self.wrapper.default_full_name() ) )
+ else:
+ result.append( '&%s'% declarations.full_name( self.declaration ) )
+ if self.wrapper:
+ result.append( self.param_sep() )
+ result.append( '&%s' % self.wrapper.default_full_name() )
+ return ''.join( result )
+
+class mem_fun_v_transformed_wrapper_t( calldef_wrapper_t ):
+ def __init__( self, function ):
+ calldef_wrapper_t.__init__( self, function=function )
+
+ def default_full_name(self):
+ return self.parent.full_name + '::default_' + self.declaration.alias
+
+ def function_type(self):
+ return declarations.member_function_type_t(
+ return_type=self.declaration.return_type
+ , class_inst=declarations.dummy_type_t( self.parent.full_name )
+ , arguments_types=map( lambda arg: arg.type, self.declaration.arguments )
+ , has_const=self.declaration.has_const )
+
+ def create_declaration(self, name, has_virtual=True):
+ template = '%(virtual)s%(return_type)s %(name)s( %(args)s )%(constness)s %(throw)s'
+
+ virtual = 'virtual '
+ if not has_virtual:
+ virtual = ''
+
+ constness = ''
+ if self.declaration.has_const:
+ constness = ' const '
+
+ return template % {
+ 'virtual' : virtual
+ , 'return_type' : self.declaration.return_type.decl_string
+ , 'name' : name
+ , 'args' : self.args_declaration()
+ , 'constness' : constness
+ , 'throw' : self.throw_specifier_code()
+ }
+
+ def create_virtual_body(self):
+ template = []
+ template.append( 'if( %(override)s func_%(alias)s = this->get_override( "%(alias)s" ) )' )
+ template.append( self.indent('%(return_)sfunc_%(alias)s( %(args)s );') )
+ template.append( 'else' )
+ template.append( self.indent('%(return_)s%(wrapped_class)s::%(name)s( %(args)s );') )
+ template = os.linesep.join( template )
+
+ return_ = ''
+ if not declarations.is_void( self.declaration.return_type ):
+ return_ = 'return '
+
+ return template % {
+ 'override' : self.override_identifier()
+ , 'name' : self.declaration.name
+ , 'alias' : self.declaration.alias
+ , 'return_' : return_
+ , 'args' : self.function_call_args()
+ , 'wrapped_class' : self.wrapped_class_identifier()
+ }
+
+ def create_default_body(self):
+ function_call = declarations.call_invocation.join( self.declaration.name
+ , [ self.function_call_args() ] )
+ body = self.wrapped_class_identifier() + '::' + function_call + ';'
+ if not declarations.is_void( self.declaration.return_type ):
+ body = 'return ' + body
+ return body
+
+ def create_function(self):
+ answer = [ self.create_declaration(self.declaration.name) + '{' ]
+ answer.append( self.indent( self.create_virtual_body() ) )
+ answer.append( '}' )
+ return os.linesep.join( answer )
+
+ def create_default_function( self ):
+ answer = [ self.create_declaration('default_' + self.declaration.alias, False) + '{' ]
+ answer.append( self.indent( self.create_default_body() ) )
+ answer.append( '}' )
+ return os.linesep.join( answer )
+
+ def _create_impl(self):
+ answer = [ self.create_function() ]
+ answer.append( os.linesep )
+ answer.append( self.create_default_function() )
+ return os.linesep.join( answer )
+
class mem_fun_protected_t( calldef_t ):
def __init__( self, function, wrapper ):
calldef_t.__init__( self, function=function, wrapper=wrapper )
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-09-04 06:17:49 UTC (rev 515)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-09-04 06:49:35 UTC (rev 516)
@@ -568,53 +568,13 @@
include = code_creators.include_t( header=fn )
self.__extmodule.adopt_include(include)
- def guess_functions_code_creators( self ):
- maker_cls = None
- fwrapper_cls = None
- access_level = self.curr_decl.parent.find_out_member_access_type( self.curr_decl )
- if access_level == ACCESS_TYPES.PUBLIC:
- if self.curr_decl.virtuality == VIRTUALITY_TYPES.NOT_VIRTUAL:
- maker_cls = code_creators.mem_fun_t
- elif self.curr_decl.virtuality == VIRTUALITY_TYPES.PURE_VIRTUAL:
- fwrapper_cls = code_creators.mem_fun_pv_wrapper_t
- maker_cls = code_creators.mem_fun_pv_t
- else:
- if self.curr_decl.overridable:
- fwrapper_cls = code_creators.mem_fun_v_wrapper_t
- maker_cls = code_creators.mem_fun_v_t
- elif access_level == ACCESS_TYPES.PROTECTED:
- if self.curr_decl.virtuality == VIRTUALITY_TYPES.NOT_VIRTUAL:
- if self.curr_decl.has_static:
- fwrapper_cls = code_creators.mem_fun_protected_s_wrapper_t
- maker_cls = code_creators.mem_fun_protected_s_t
- else:
- fwrapper_cls = code_creators.mem_fun_protected_wrapper_t
- maker_cls = code_creators.mem_fun_protected_t
- elif self.curr_decl.virtuality == VIRTUALITY_TYPES.VIRTUAL:
- if self.curr_decl.overridable:
- fwrapper_cls = code_creators.mem_fun_protected_v_wrapper_t
- maker_cls = code_creators.mem_fun_protected_v_t
- else:
- fwrapper_cls = code_creators.mem_fun_protected_pv_wrapper_t
- maker_cls = code_creators.mem_fun_protected_pv_t
- else: #private
- if self.curr_decl.virtuality == VIRTUALITY_TYPES.NOT_VIRTUAL:
- pass#in general we should not come here
- elif self.curr_decl.virtuality == VIRTUALITY_TYPES.PURE_VIRTUAL:
- fwrapper_cls = code_creators.mem_fun_private_pv_wrapper_t
- else:
- if self.curr_decl.overridable:
- fwrapper_cls = code_creators.mem_fun_v_wrapper_t
- maker_cls = code_creators.mem_fun_v_t
- return ( maker_cls, fwrapper_cls )
-
def visit_member_function( self ):
fwrapper = None
self.__types_db.update( self.curr_decl )
if None is self.curr_decl.call_policies:
self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl )
- maker_cls, fwrapper_cls = self.guess_functions_code_creators()
+ maker_cls, fwrapper_cls = code_creators.guess_mem_fun_creator_classes( self.curr_decl )
maker = None
fwrapper = None
@@ -678,7 +638,7 @@
and not self.curr_decl.has_const:
#TODO: move this code to decl_wrappers
return #only const casting operators can generate implicitly_convertible
-
+
if None is self.curr_decl.call_policies:
self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|