[pygccxml-commit] SF.net SVN: pygccxml:[1397] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2008-08-18 18:58:54
|
Revision: 1397
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1397&view=rev
Author: roman_yakovenko
Date: 2008-08-18 18:58:51 +0000 (Mon, 18 Aug 2008)
Log Message:
-----------
improving "make_constructor" functionality
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py
pyplusplus_dev/pyplusplus/messages/warnings_.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
pyplusplus_dev/unittests/data/free_functions_to_be_exported.hpp
pyplusplus_dev/unittests/data/make_constructor_to_be_exported.hpp
pyplusplus_dev/unittests/make_constructor_tester.py
Added Paths:
-----------
pyplusplus_dev/pyplusplus/module_creator/fake_constructors_manager.py
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2008-08-14 18:49:06 UTC (rev 1396)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2008-08-18 18:58:51 UTC (rev 1397)
@@ -169,6 +169,9 @@
WRAPPER = 'wrapper'
ALL = ( DECLARED, WRAPPER )
+ FAKE_CONSTRUCTOR_TYPES = ( declarations.member_function_t, declarations.free_function_t )
+ FAKE_CONSTRUCTOR_TYPE_NAMES = 'member and free functions'
+
def __init__(self, *arguments, **keywords):
class_common_details_t.__init__( self )
declarations.class_t.__init__(self, *arguments, **keywords )
@@ -193,17 +196,17 @@
self._expose_this = None
self._expose_sizeof = None
self._fake_constructors = []
-
+
@property
def fake_constructors(self):
"""list of fake constructors"""
return self._fake_constructors
-
+
def add_fake_constructors( self, f ):
"""f - reference to a calldef_t object or list of them
-
+
boost::python::make_constructor allows to register a C++ function, as a
- class constructor.
+ class constructor.
"""
if isinstance( f, declarations.calldef_t ):
self._fake_constructors.add( f )
@@ -624,7 +627,16 @@
return explanation
def _readme_impl( self ):
- return self.is_wrapper_needed()
+ explanation = self.is_wrapper_needed()
+ for fc in self.fake_constructors:
+ if fc.ignore:
+ explanation.append( messages.W1062 % ( str( self ), str( fc ) ) )
+ if not fc.exportable:
+ explanation.append( messages.W1063 % ( str( self ), str( fc ) ) )
+ if not isinstance( fc, self.FAKE_CONSTRUCTOR_TYPES ):
+ explanation.append( messages.W1064
+ % ( str( fc ), str( self ), self.FAKE_CONSTRUCTOR_TYPE_NAMES ) )
+ return explanation
def guess_always_expose_using_scope_value( self ):
def is_assign( oper ):
Modified: pyplusplus_dev/pyplusplus/messages/warnings_.py
===================================================================
--- pyplusplus_dev/pyplusplus/messages/warnings_.py 2008-08-14 18:49:06 UTC (rev 1396)
+++ pyplusplus_dev/pyplusplus/messages/warnings_.py 2008-08-18 18:58:51 UTC (rev 1397)
@@ -237,6 +237,15 @@
W1061 = compilation_error( 'Py++ can not expose "%s" - its type is "%s".'
' This could be changed in future.')
+W1062 = compilation_error( '"%s" contains "fake constructor" "%s", that was excluded.'
+ ' Py++ will not generate "__init__" method, based on that function.')
+
+W1063 = compilation_error( '"%s" contains "fake constructor" "%s", that is exportable.'
+ ' Py++ will not generate "__init__" method, based on that function.')
+
+W1064 = compilation_error( 'Py++ can not expose "%s" as "fake constructor" of "%s".'
+ ' Only the following function types supported: %s' )
+
warnings = globals()
all_warning_msgs = []
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2008-08-14 18:49:06 UTC (rev 1396)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2008-08-18 18:58:51 UTC (rev 1397)
@@ -9,6 +9,7 @@
import dependencies_manager
import opaque_types_manager
import call_policies_resolver
+import fake_constructors_manager
from pygccxml import declarations
from pyplusplus import decl_wrappers
@@ -78,7 +79,7 @@
self.__types_db = types_db
if not self.__types_db:
self.__types_db = types_database.types_database_t()
-
+
global_ns = declarations.get_global_namespace(decls)
self.__extmodule = code_creators.module_t( global_ns )
if boost_python_ns_name:
@@ -101,9 +102,7 @@
self.__array_1_registered = set() #(type.decl_string,size)
self.__free_operators = []
self.__exposed_free_fun_overloads = set()
- self.__fake_constructors = set()
- for cls in global_ns.classes(recursive=True, allow_empty=True):
- self.__fake_constructors.update( cls.fake_constructors )
+ self.__fc_manager = fake_constructors_manager.manager_t( global_ns )
def __print_readme( self, decl ):
readme = decl.readme()
@@ -353,9 +352,9 @@
self.__types_db.update( self.curr_decl )
self.__dependencies_manager.add_exported( self.curr_decl )
- if self.curr_decl in self.__fake_constructors:
+ if self.__fc_manager.is_fake_constructor( self.curr_decl ):
return
-
+
fwrapper = None
if None is self.curr_decl.call_policies:
self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl )
@@ -460,12 +459,12 @@
def visit_free_function( self ):
if self.curr_decl in self.__exposed_free_fun_overloads:
return
-
- if self.curr_decl in self.__fake_constructors:
+
+ if self.__fc_manager.is_fake_constructor( self.curr_decl ):
self.__types_db.update( self.curr_decl )
self.__dependencies_manager.add_exported( self.curr_decl )
return
-
+
elif self.curr_decl.use_overload_macro:
parent_decl = self.curr_decl.parent
names = set( map( lambda decl: decl.name
@@ -608,9 +607,6 @@
if cls_decl.expose_sizeof:
cls_cc.adopt_creator( code_creators.expose_sizeof_t( cls_decl ) )
- for fc in cls_decl.fake_constructors:
- cls_cc.adopt_creator( code_creators.make_constructor_t( fc ) )
-
for decl in exportable_members:
if decl in exposed:
continue
@@ -646,6 +642,10 @@
destructor = code_creators.destructor_wrapper_t( class_=cls_decl )
wrapper.adopt_creator( destructor )
+ for fc in cls_decl.fake_constructors:
+ if self.__fc_manager.should_generate_code( fc ):
+ cls_cc.adopt_creator( code_creators.make_constructor_t( fc ) )
+
self.curr_decl = cls_decl
self.curr_code_creator = cls_parent_cc
Added: pyplusplus_dev/pyplusplus/module_creator/fake_constructors_manager.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/fake_constructors_manager.py (rev 0)
+++ pyplusplus_dev/pyplusplus/module_creator/fake_constructors_manager.py 2008-08-18 18:58:51 UTC (rev 1397)
@@ -0,0 +1,29 @@
+# Copyright 2004 Roman Yakovenko.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+"""defines class, which manages "fake constructors" """
+
+class manager_t( object ):
+ def __init__( self, global_ns ):
+ self.__global_ns = global_ns
+ self.__fc_all = set()
+ self.__fc_exposed = set()
+
+ for cls in global_ns.classes(recursive=True, allow_empty=True):
+ for fc in cls.fake_constructors:
+ self.__fc_all.add( fc )
+ if fc.ignore:
+ continue
+ if not fc.exportable:
+ continue
+ if not isinstance( fc, cls.FAKE_CONSTRUCTOR_TYPES ):
+ continue
+ self.__fc_exposed.add( fc )
+
+ def is_fake_constructor( self, fc ):
+ return fc in self.__fc_all
+
+ def should_generate_code( self, fc ):
+ return fc in self.__fc_exposed
Modified: pyplusplus_dev/unittests/data/free_functions_to_be_exported.hpp
===================================================================
--- pyplusplus_dev/unittests/data/free_functions_to_be_exported.hpp 2008-08-14 18:49:06 UTC (rev 1396)
+++ pyplusplus_dev/unittests/data/free_functions_to_be_exported.hpp 2008-08-18 18:58:51 UTC (rev 1397)
@@ -6,6 +6,8 @@
#ifndef __free_functions_to_be_exported_hpp__
#define __free_functions_to_be_exported_hpp__
+#include <stddef.h>
+
namespace free_functions{
inline int one(){
@@ -16,7 +18,10 @@
return a+b;
}
+inline void do_smth( size_t , int ){
}
+}
+
#endif//__free_functions_to_be_exported_hpp__
Modified: pyplusplus_dev/unittests/data/make_constructor_to_be_exported.hpp
===================================================================
--- pyplusplus_dev/unittests/data/make_constructor_to_be_exported.hpp 2008-08-14 18:49:06 UTC (rev 1396)
+++ pyplusplus_dev/unittests/data/make_constructor_to_be_exported.hpp 2008-08-18 18:58:51 UTC (rev 1397)
@@ -9,21 +9,21 @@
#include <memory>
namespace mc{
-
+
struct numbers_t{
numbers_t()
: x( 0 )
, y( 0 )
{}
~numbers_t(){}
-
+
static std::auto_ptr<numbers_t> create( int i, int j, int k, int m ){
std::auto_ptr<numbers_t> n( new numbers_t() );
n->x = i + j;
n->y = k + m;
return n;
}
-
+
int x;
int y;
};
@@ -35,6 +35,11 @@
return n;
}
+inline std::auto_ptr<numbers_t> create( double, double, double, double, double){
+ return std::auto_ptr<numbers_t>();
}
+
+}
+
#endif//__make_constructor_to_be_exported_hpp__
Modified: pyplusplus_dev/unittests/make_constructor_tester.py
===================================================================
--- pyplusplus_dev/unittests/make_constructor_tester.py 2008-08-14 18:49:06 UTC (rev 1396)
+++ pyplusplus_dev/unittests/make_constructor_tester.py 2008-08-18 18:58:51 UTC (rev 1397)
@@ -10,27 +10,28 @@
class tester_t(fundamental_tester_base.fundamental_tester_base_t):
EXTENSION_NAME = 'make_constructor'
-
+
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 ):
mc = mb.namespace( 'mc' )
numbers = mc.class_( 'numbers_t' )
numbers.add_fake_constructors( mc.calldefs( 'create' ) )
-
-
- def run_tests(self, module):
+ numbers.add_fake_constructors( mc.calldefs(lambda d: d.name.startswith('~') ) )
+ mc.calldef( 'create', arg_types=[None]*5 ).exclude()
+
+ def run_tests(self, module):
n = module.numbers_t( 1,2,3,4)
self.failUnless( n.x == 1+2 and n.y == 3+4)
n = module.numbers_t( 10, 18)
self.failUnless( n.x == 10 and n.y == 18)
-
+
def create_suite():
- suite = unittest.TestSuite()
+ suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(tester_t))
return suite
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|