[pygccxml-commit] SF.net SVN: pygccxml: [253] pygccxml_dev/pygccxml/declarations
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-06-27 08:23:58
|
Revision: 253 Author: roman_yakovenko Date: 2006-06-27 01:23:42 -0700 (Tue, 27 Jun 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=253&view=rev Log Message: ----------- preparing source code for indexing suite 2 Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/type_traits.py pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/pyplusplus/module_creator/types_database.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2006-06-27 05:51:08 UTC (rev 252) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2006-06-27 08:23:42 UTC (rev 253) @@ -110,6 +110,7 @@ from type_traits import is_void from type_traits import is_void_pointer from type_traits import is_class +from type_traits import is_class_declaration from type_traits import is_const from type_traits import base_type from type_traits import is_array @@ -138,6 +139,7 @@ from type_traits import remove_pointer from type_traits import remove_volatile from type_traits import remove_reference +from type_traits import remove_declarated from type_traits import has_destructor from type_traits import has_trivial_copy @@ -165,8 +167,25 @@ from container_traits import set_traits from container_traits import hash_set_traits from container_traits import multiset_traits -from container_traits import hash_multiset_traits +from container_traits import hash_multiset_traits +all_container_traits = [ + list_traits + , deque_traits + , queue_traits + , priority_queue + , vector_traits + , stack_traits + , map_traits + , multimap_traits + , hash_map_traits + , hash_multimap_traits + , set_traits + , hash_set_traits + , multiset_traits + , hash_multiset_traits +] + import templates import call_invocation @@ -256,7 +275,6 @@ impl_matchers[ scopedef.scopedef_t.typedef ] = declaration_matcher_t impl_decl_types[ scopedef.scopedef_t.typedef ] = typedef_t - impl_matchers[ namespace_t.namespace ] = namespace_matcher_t impl_matchers[ namespace_t.free_function ] = calldef_matcher_t Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2006-06-27 05:51:08 UTC (rev 252) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2006-06-27 08:23:42 UTC (rev 253) @@ -278,11 +278,17 @@ def is_class(type): """returns True if type represents C++ class""" nake_type = remove_alias( type ) - nake_type = remove_reference( nake_type ) nake_type = remove_cv( nake_type ) nake_type = remove_declarated( nake_type ) return isinstance( nake_type, class_declaration.class_t) +def is_class_declaration(type): + """returns True if type represents C++ class""" + nake_type = remove_alias( type ) + nake_type = remove_cv( nake_type ) + nake_type = remove_declarated( nake_type ) + return isinstance( nake_type, class_declaration.class_declaration_t) + def find_trivial_constructor( type ): """returns reference to trivial constructor or None""" assert isinstance( type, class_declaration.class_t ) Modified: pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-06-27 05:51:08 UTC (rev 252) +++ pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-06-27 08:23:42 UTC (rev 253) @@ -7,6 +7,7 @@ import types import algorithm import code_creator +import declaration_based from pygccxml import declarations class indexing_suite_t( code_creator.code_creator_t ): @@ -43,4 +44,22 @@ def _create_impl(self): return "def( %s() )" % self._create_suite_declaration() - \ No newline at end of file + + +#class indexing_suite2_t( code_creator.code_creator_t ): + #class value_traits_t( declaration_based_t ): + #def __init__( self, container_class, parent=None ): + #declaration_based_t.__init__( declaration=container_class, parent=parent ) + + #def _create_impl( self + + #def __init__(self, parent=None ): + #code_creator.code_creator_t.__init__( self, parent=parent ) + + #def _get_configuration( self ): + #return self.parent.declaration.indexing_suite + #configuration = property( _get_configuration ) + + #def _get_container( self ): + #return self.parent.declaration + #container = property( _get_container ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-06-27 05:51:08 UTC (rev 252) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-06-27 08:23:42 UTC (rev 253) @@ -10,25 +10,13 @@ import indexing_suite as container_suites -def guess_container_traits( class_ ): - if declarations.vector_traits.is_my_case( class_ ): - return declarations.vector_traits - elif declarations.list_traits.is_my_case( class_ ): - return declarations.list_traits - elif declarations.map_traits.is_my_case( class_ ): - return declarations.map_traits - elif declarations.hash_map_traits.is_my_case( class_ ): - declarations.hash_map_traits - else: - return None - -#this will only be exported if indexing suite is not None and only when needed -class class_declaration_t(decl_wrapper.decl_wrapper_t, declarations.class_declaration_t): - def __init__(self, *arguments, **keywords): - declarations.class_declaration_t.__init__(self, *arguments, **keywords ) - decl_wrapper.decl_wrapper_t.__init__( self ) +class class_common_impl_details_t( object ): + def __init__(self): + object.__init__( self ) self._always_expose_using_scope = False self._indexing_suite = None + self._equality_comparable = None + self._lessthan_comparable = None def _get_always_expose_using_scope( self ): return self._always_expose_using_scope @@ -38,25 +26,57 @@ def _get_indexing_suite( self ): if self._indexing_suite is None: - container_traits = guess_container_traits( self ) - if container_traits: - self._indexing_suite = container_suites.indexing_suite_t( self, container_traits ) + for container_traits in declarations.all_container_traits: + if container_traits.is_my_case( self ): + self._indexing_suite = container_suites.indexing_suite_t( self, container_traits ) + break return self._indexing_suite indexing_suite = property( _get_indexing_suite ) + + def _get_equality_comparable( self ): + if None is self._equality_comparable: + self._equality_comparable = declarations.has_public_equal( self ) + return self._equality_comparable + + def _set_equality_comparable( self, value ): + self._equality_comparable = value + + equality_comparable = property( _get_equality_comparable, _set_equality_comparable ) -class class_t(scopedef_wrapper.scopedef_t, declarations.class_t): + def _get_lessthan_comparable( self ): + if None is self._lessthan_comparable: + self._lessthan_comparable = declarations.has_public_less( self ) + return self._lessthan_comparable + + def _set_lessthan_comparable( self, value ): + self._lessthan_comparable = value + + lessthan_comparable = property( _get_lessthan_comparable, _set_lessthan_comparable ) + + +#this will only be exported if indexing suite is not None and only when needed +class class_declaration_t( class_common_impl_details_t + , decl_wrapper.decl_wrapper_t + , declarations.class_declaration_t ): def __init__(self, *arguments, **keywords): + class_common_impl_details_t.__init__( self ) + declarations.class_declaration_t.__init__(self, *arguments, **keywords ) + decl_wrapper.decl_wrapper_t.__init__( self ) + +class class_t( class_common_impl_details_t + , scopedef_wrapper.scopedef_t + , declarations.class_t): + def __init__(self, *arguments, **keywords): + class_common_impl_details_t.__init__( self ) declarations.class_t.__init__(self, *arguments, **keywords ) scopedef_wrapper.scopedef_t.__init__( self ) - self._always_expose_using_scope = False self._redefine_operators = False self._held_type = None self._noncopyable = None self._wrapper_alias = self._generate_valid_name() + "_wrapper" self._user_code = [] self._wrapper_user_code = [] - self._indexing_suite = None self._null_constructor_body = '' self._copy_constructor_body = '' @@ -113,15 +133,6 @@ def _set_wrapper_user_code( self, value ): self._wrapper_user_code = value wrapper_user_code = property( _get_wrapper_user_code, _set_wrapper_user_code ) - - def _get_indexing_suite( self ): - if self._indexing_suite is None: - container_traits = guess_container_traits( self ) - if container_traits: - self._indexing_suite \ - = container_suites.indexing_suite_t( self, container_traits ) - return self._indexing_suite - indexing_suite = property( _get_indexing_suite ) def _get_null_constructor_body(self): return self._null_constructor_body Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-06-27 05:51:08 UTC (rev 252) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-06-27 08:23:42 UTC (rev 253) @@ -369,22 +369,23 @@ if not self.__types_db.used_containers: return - map_header_was_used = False - vector_header_was_used = False - + #supported container : [ header file, is already used ] + isuite1 = { + 'vector<' : [ "boost/python/suite/indexing/vector_indexing_suite.hpp", False ] + , 'map<' : [ "boost/python/suite/indexing/map_indexing_suite.hpp", False ] + } + for cls in self.__types_db.used_containers: - if cls.name.startswith( 'vector' ): - if not vector_header_was_used: - vector_header_was_used = True - header = "boost/python/suite/indexing/vector_indexing_suite.hpp" - self.__extmodule.add_system_header( header ) - self.__extmodule.add_include( header=header ) - else: - if not map_header_was_used: - map_header_was_used = True - header = "boost/python/suite/indexing/map_indexing_suite.hpp" - self.__extmodule.add_system_header( header ) - self.__extmodule.add_include( header=header ) + container_name = cls.name.split( '<' )[0] + '<' + if not isuite1.has_key( container_name ): + continue #not supported + if not cls.name.startswith( 'vector<') and not cls.name.startswith( 'map<'): + continue + + if not isuite1[ container_name ][1]: + isuite1[ container_name ][1] = True + self.__extmodule.add_system_header( isuite1[ container_name ][0] ) + self.__extmodule.add_include( header=isuite1[ container_name ][0] ) cls_creator = create_cls_cc( cls ) value_type = cls.indexing_suite.value_type() Modified: pyplusplus_dev/pyplusplus/module_creator/types_database.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-06-27 05:51:08 UTC (rev 252) +++ pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-06-27 08:23:42 UTC (rev 253) @@ -54,30 +54,29 @@ type = declarations.remove_alias( type ) type = declarations.remove_pointer( type ) type = declarations.remove_reference( type ) + type = declarations.remove_cv( type ) + type = declarations.remove_declarated( type ) - traits = None - if declarations.vector_traits.is_my_case( type ): - traits = declarations.vector_traits - elif declarations.map_traits.is_my_case( type ): - traits = declarations.map_traits - elif declarations.hash_map_traits.is_my_case( type ): - traits = declarations.hash_map_traits - else: - pass - if None is traits: + if not declarations.is_class( type ) and not declarations.is_class_declaration( type ): return False - try: - cls = traits.class_declaration( type ) - traits.value_type( cls ) - self.__containers.add( cls ) - return True + + container_cls = type + if None is container_cls.indexing_suite: + return False + + try: + #checking whether value_type could be extracted + container_cls.indexing_suite.value_type() except RuntimeError, error: - msg = 'WARNING: pyplusplus found std::vector instantiation declaration, ' + msg = 'WARNING: pyplusplus found "%s" instantiation declaration, ' % container_cls.name msg = msg + 'but can not find out value type!' msg = msg + os.linesep + 'This class will not be exported!' - msg = msg + os.linesep + 'std::vector instantiation is: ' + vector.decl_string _logging_.logger.warn( msg ) - return False + return False + + self.__containers.add( container_cls ) + return True + def _update_db( self, db, type_ ): if self._update_containers_db( type_ ): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |