Revision: 319
Author: roman_yakovenko
Date: 2006-07-19 22:19:45 -0700 (Wed, 19 Jul 2006)
ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=319&view=rev
Log Message:
-----------
adding declaration/registration helpers
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/module.py
pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py
pyplusplus_dev/pyplusplus/module_builder/builder.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
Modified: pyplusplus_dev/pyplusplus/code_creators/module.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/module.py 2006-07-20 05:04:20 UTC (rev 318)
+++ pyplusplus_dev/pyplusplus/code_creators/module.py 2006-07-20 05:19:45 UTC (rev 319)
@@ -4,9 +4,10 @@
# http://www.boost.org/LICENSE_1_0.txt)
import os
-import types
+import types
+import custom
import license
-import include
+import include
import namespace
import compound
import algorithm
@@ -180,6 +181,13 @@
alias=alias
, full_namespace_name=full_namespace_name )
, self.last_include_index() + 1 )
+
+ def adopt_declaration_creator( self, creator ):
+ self.adopt_creator( creator, self.creators.index( self.body ) )
+
+ def add_declaration_code( self, code, position ):
+ creator = custom.custom_text_t( code )
+ self.adopt_creator( creator, min( position, self.creators.index( self.body ) ) )
@@ -189,6 +197,4 @@
-
-
\ No newline at end of file
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-07-20 05:04:20 UTC (rev 318)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-07-20 05:19:45 UTC (rev 319)
@@ -97,14 +97,6 @@
return ''
def _exportable_impl( self ):
- #TODO: functions that takes as argument pointer to pointer to smth, could not be exported
- #see http://www.boost.org/libs/python/doc/v2/faq.html#funcptr
- if len( self.arguments ) > calldef_t.BOOST_PYTHON_MAX_ARITY:
- msg = "Function '%s' has more than %d arguments ( %d ). "
- msg = msg + " You should adjust BOOST_PYTHON_MAX_ARITY."
- msg = msg + " For more information see: http://mail.python.org/pipermail/c++-sig/2002-June/001554.html"
- self.logger.warning( msg % ( self.decl_string, calldef_t.BOOST_PYTHON_MAX_ARITY, len( self.arguments ) ) )
-
all_types = [ arg.type for arg in self.arguments ]
all_types.append( self.return_type )
for some_type in all_types:
@@ -128,26 +120,35 @@
return "pyplusplus can not expose fuction that takes as argument/returns C++ arrays. This will be changed in near future."
return self._exportable_impl_derived()
- def _readme_impl( self ):
+ def _readme_impl( self ):
def suspicious_type( type_ ):
if not declarations.is_reference( self.return_type ):
return False
type_no_ref = declarations.remove_reference( type_ )
return not declarations.is_const( type_no_ref ) \
and declarations.is_fundamental( type_no_ref )
- msg = []
+ msgs = []
+ #TODO: functions that takes as argument pointer to pointer to smth, could not be exported
+ #see http://www.boost.org/libs/python/doc/v2/faq.html#funcptr
+ if len( self.arguments ) > calldef_t.BOOST_PYTHON_MAX_ARITY:
+ tmp = [ "Function '%s' has more than %d arguments ( %d ). " ]
+ tmp.append( os.linesep + "\tYou should adjust BOOST_PYTHON_MAX_ARITY." )
+ tmp.append( os.linesep + "\tFor more information see: http://mail.python.org/pipermail/c++-sig/2002-June/001554.html" )
+ tmp = ''.join( tmp )
+ msgs.append( tmp % ( self.decl_string, calldef_t.BOOST_PYTHON_MAX_ARITY, len( self.arguments ) ) )
+
if suspicious_type( self.return_type ) and None is self.call_policies:
- msg.append( 'WARNING: Function "%s" returns non-const reference to C++ fundamental type - value can not be modified from Python.' % str( self ) )
+ msgs.append( 'Function "%s" returns non-const reference to C++ fundamental type - value can not be modified from Python.' % str( self ) )
for index, arg in enumerate( self.arguments ):
if suspicious_type( arg.type ):
- tmpl = 'WARNING: Function "%s" takes as argument (name=%s, pos=%d ) ' \
+ tmpl = 'Function "%s" takes as argument (name=%s, pos=%d ) ' \
+ 'non-const reference to C++ fundamental type - ' \
+ 'function could not be called from Python.'
- msg.append( tmpl % ( str( self ), arg.name, index ) )
+ msgs.append( tmpl % ( str( self ), arg.name, index ) )
if False == self.overridable:
- msg.append( self.get_overridable.__doc__ )
- return msg
+ msgs.append( self.get_overridable.__doc__ )
+ return msgs
class member_function_t( declarations.member_function_t, calldef_t ):
def __init__(self, *arguments, **keywords):
Modified: pyplusplus_dev/pyplusplus/module_builder/builder.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-07-20 05:04:20 UTC (rev 318)
+++ pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-07-20 05:19:45 UTC (rev 319)
@@ -6,14 +6,18 @@
import os
import sys
import time
-import types
+import types
+
from sets import Set as set
+
from pygccxml import parser
-from pygccxml import declarations as decls_package
+from pygccxml import declarations as decls_package
+
+from pyplusplus import _logging_
from pyplusplus import decl_wrappers
-from pyplusplus import module_creator as mcreator_package
-from pyplusplus import file_writers
-from pyplusplus import _logging_
+from pyplusplus import file_writers
+from pyplusplus import code_creators
+from pyplusplus import module_creator as mcreator_package
class module_builder_t(object):
"""
@@ -494,4 +498,18 @@
return decl_wrappers.calldef_t.BOOST_PYTHON_MAX_ARITY
def _set_BOOST_PYTHON_MAX_ARITY( self, value ):
decl_wrappers.calldef_t.BOOST_PYTHON_MAX_ARITY = value
- BOOST_PYTHON_MAX_ARITY = property( _get_BOOST_PYTHON_MAX_ARITY, _set_BOOST_PYTHON_MAX_ARITY )
\ No newline at end of file
+ BOOST_PYTHON_MAX_ARITY = property( _get_BOOST_PYTHON_MAX_ARITY, _set_BOOST_PYTHON_MAX_ARITY )
+
+ def add_declaration_code( self, code, tail=True ):
+ position = 0
+ if tail:
+ position = -1
+ self.code_creator.add_declaration_code( code, position )
+
+ def add_registration_code( self, code, tail=True ):
+ position = 0
+ if tail:
+ position = -1
+ creator = code_creators.custom_text_t( code )
+ self.code_creator.body.adopt_creator( creator, position )
+
\ No newline at end of file
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-07-20 05:04:20 UTC (rev 318)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-07-20 05:19:45 UTC (rev 319)
@@ -488,7 +488,7 @@
and class_traits.is_my_case( element_type ):
value_cls = class_traits.get_declaration( element_type )
element_type_cc = code_creators.value_traits_t( value_cls )
- self.__extmodule.adopt_creator( element_type_cc, self.__extmodule.creators.index( self.__module_body ) )
+ self.__extmodule.adopt_declaration_creator( element_type_cc )
cls_creator.adopt_creator( code_creators.indexing_suite2_t(cls) )
if INDEXING_SUITE_2_MAIN_HEADER in used_headers:
@@ -701,7 +701,7 @@
#we deal with internal class
self.curr_code_creator.wrapper.adopt_creator( wrapper )
else:
- self.__extmodule.adopt_creator( wrapper, self.__extmodule.creators.index( self.__module_body ) )
+ self.__extmodule.adopt_declaration_creator( wrapper )
if declarations.has_trivial_copy( self.curr_decl ):
#I don't know but sometimes boost.python requieres
#to construct wrapper from wrapped classe
@@ -782,8 +782,7 @@
else:
maker = code_creators.global_variable_t( variable=self.curr_decl )
if wrapper:
- self.__extmodule.adopt_creator( wrapper
- , self.__extmodule.creators.index( self.__module_body ) )
+ self.__extmodule.adopt_declaration_creator( wrapper )
else:
maker = None
wrapper = None
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|