[pygccxml-commit] SF.net SVN: pygccxml: [537] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2006-09-13 09:24:50
|
Revision: 537
http://svn.sourceforge.net/pygccxml/?rev=537&view=rev
Author: roman_yakovenko
Date: 2006-09-13 02:24:37 -0700 (Wed, 13 Sep 2006)
Log Message:
-----------
fixing "create_castinig_constructor" functionality.
As it was suggested by David Abrahams, by default they will be not generated.
Previous behavior is preserved.
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py
pyplusplus_dev/pyplusplus/module_builder/builder.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
pyplusplus_dev/unittests/casting_tester.py
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-09-13 07:32:06 UTC (rev 536)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-09-13 09:24:37 UTC (rev 537)
@@ -216,6 +216,7 @@
declarations.constructor_t.__init__( self, *arguments, **keywords )
calldef_t.__init__( self )
self._body = ''
+ self._allow_implicit_conversion = False
def _get_body(self):
return self._body
@@ -229,6 +230,33 @@
return 'Py++ does not exports compiler generated constructors'
return ''
+ def does_define_implicit_conversion( self ):
+ """ returns true if the constructor can take part in implicit conversions.
+
+ For more information see:
+
+ * http://boost.org/libs/python/doc/v2/implicit.html#implicitly_convertible-spec
+
+ * http://msdn2.microsoft.com/en-us/library/h1y7x448.aspx
+ """
+ if self.parent.is_abstract: #user is not able to create an instance of the class
+ return False
+ if self.is_copy_constructor:
+ return False
+ if 1 != len( self.arguments ):
+ return False
+ if self.parent.find_out_member_access_type( self ) != declarations.ACCESS_TYPES.PUBLIC:
+ return False
+ return True
+
+ def _get_allow_implicit_conversion(self):
+ return self._allow_implicit_conversion and self.does_define_implicit_conversion()
+ def _set_allow_implicit_conversion(self, allow_implicit_conversion):
+ self._allow_implicit_conversion = allow_implicit_conversion
+ allow_implicit_conversion = property( _get_allow_implicit_conversion, _set_allow_implicit_conversion
+ , doc="boolean, indicates whether Py++ should generate implicitly_convertible code or not" \
+ "Default value is calculated from the constructor type" )
+
class destructor_t( declarations.destructor_t, calldef_t ):
"""you may ignore this class for he time being.
Modified: pyplusplus_dev/pyplusplus/module_builder/builder.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-09-13 07:32:06 UTC (rev 536)
+++ pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-09-13 09:24:37 UTC (rev 537)
@@ -7,6 +7,8 @@
import sys
import time
+import warnings
+
from pygccxml import parser
from pygccxml import declarations as decls_package
@@ -201,7 +203,7 @@
def build_code_creator( self
, module_name
, boost_python_ns_name='bp'
- , create_castinig_constructor=True
+ , create_castinig_constructor=False
, call_policies_resolver_=None
, types_db=None
, target_configuration=None
@@ -224,10 +226,18 @@
and returns documentation string
@type doc_extractor: callable or None
"""
+ if create_castinig_constructor:
+ msg = os.linesep.join([
+ "create_castinig_constructor argument is deprecated and should not be used."
+ , "If you still want Py++ to generate implicitly_convertible code, consider to use allow_implicit_conversion constructor property"
+ , "mb = module_builder_t(...)"
+ , "mb.constructors().allow_implicit_conversion = True"])
+ warnings.warn(msg, DeprecationWarning, stacklevel=2)
+ self.global_ns.constructors().allow_implicit_conversion = True
+
creator = mcreator_package.creator_t( self.global_ns
, module_name
, boost_python_ns_name
- , create_castinig_constructor
, call_policies_resolver_
, types_db
, target_configuration
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-09-13 07:32:06 UTC (rev 536)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-09-13 09:24:37 UTC (rev 537)
@@ -64,7 +64,6 @@
, decls
, module_name
, boost_python_ns_name='bp'
- , create_castinig_constructor=False
, call_policies_resolver_=None
, types_db=None
, target_configuration=None
@@ -75,7 +74,6 @@
@param decls: Declarations that should be exposed in the final module.
@param module_name: The name of the final module.
@param boost_python_ns_name: The alias for the boost::python namespace.
- @param create_castinig_constructor: ...todo...
@param call_policies_resolver_: Callable that takes one declaration (calldef_t) as input and returns a call policy object which should be used for this declaration.
@param types_db: ...todo...
@param target_configuration: A target configuration object can be used to customize the generated source code to a particular compiler or a particular version of Boost.Python.
@@ -83,7 +81,6 @@
@type decls: list of declaration_t
@type module_name: str
@type boost_python_ns_name: str
- @type create_castinig_constructor: bool
@type call_policies_resolver_: callable
@type types_db: L{types_database_t<types_database.types_database_t>}
@type target_configuration: L{target_configuration_t<code_creators.target_configuration_t>}
@@ -110,7 +107,6 @@
self.__extmodule = code_creators.module_t()
self.__extmodule.add_system_header( "boost/python.hpp" )
self.__extmodule.adopt_creator( code_creators.include_t( header="boost/python.hpp" ) )
- self.__create_castinig_constructor = create_castinig_constructor
if boost_python_ns_name:
bp_ns_alias = code_creators.namespace_alias_t( alias=boost_python_ns_name
, full_namespace_name='::boost::python' )
@@ -251,10 +247,6 @@
def _does_class_have_smth_to_export(self, exportable_members ):
return bool( self._filter_decls( exportable_members ) )
- def _is_constructor_of_abstract_class( self, decl ):
- assert isinstance( decl, declarations.constructor_t )
- return decl.parent.is_abstract
-
def _filter_decls( self, decls ):
# Filter out artificial (compiler created) types unless they are classes
# See: http://public.kitware.com/pipermail/gccxml/2004-October/000486.html
@@ -604,10 +596,7 @@
if self.curr_decl.is_copy_constructor:
return
self.__types_db.update( self.curr_decl )
- if not self._is_constructor_of_abstract_class( self.curr_decl ) \
- and 1 == len( self.curr_decl.arguments ) \
- and self.__create_castinig_constructor \
- and self.curr_decl.access_type == ACCESS_TYPES.PUBLIC:
+ if self.curr_decl.allow_implicit_conversion:
maker = code_creators.casting_constructor_t( constructor=self.curr_decl )
self.__module_body.adopt_creator( maker )
Modified: pyplusplus_dev/unittests/casting_tester.py
===================================================================
--- pyplusplus_dev/unittests/casting_tester.py 2006-09-13 07:32:06 UTC (rev 536)
+++ pyplusplus_dev/unittests/casting_tester.py 2006-09-13 09:24:37 UTC (rev 537)
@@ -10,13 +10,16 @@
class tester_t(fundamental_tester_base.fundamental_tester_base_t):
EXTENSION_NAME = 'casting'
-
+
def __init__( self, *args ):
- fundamental_tester_base.fundamental_tester_base_t.__init__(
+ fundamental_tester_base.fundamental_tester_base_t.__init__(
self
, tester_t.EXTENSION_NAME
, *args )
-
+
+ def customize( self, mb ):
+ mb.constructors().allow_implicit_conversion = True
+
def run_tests( self, module):
x_inst = module.x()
x_inst.value = 25
@@ -26,7 +29,7 @@
self.failUnless( 0 == module.x_value(False) )
def create_suite():
- suite = unittest.TestSuite()
+ suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(tester_t))
return suite
@@ -34,4 +37,4 @@
unittest.TextTestRunner(verbosity=2).run( create_suite() )
if __name__ == "__main__":
- run_suite()
\ No newline at end of file
+ run_suite()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|