[pygccxml-commit] SF.net SVN: pygccxml: [770] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-11-30 13:56:26
|
Revision: 770 http://svn.sourceforge.net/pygccxml/?rev=770&view=rev Author: roman_yakovenko Date: 2006-11-30 05:56:21 -0800 (Thu, 30 Nov 2006) Log Message: ----------- adding dependencies manager Modified Paths: -------------- pyplusplus_dev/pyplusplus/module_creator/creator.py Added Paths: ----------- pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py Property Changed: ---------------- pyplusplus_dev/unittests/ Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-11-30 13:47:13 UTC (rev 769) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-11-30 13:56:21 UTC (rev 770) @@ -6,6 +6,7 @@ import types_database import creators_wizard import sort_algorithms +import dependencies_manager import opaque_types_manager import call_policies_resolver from pygccxml import declarations @@ -127,7 +128,9 @@ self.__exposed_free_fun_overloads = set() self.__opaque_types_manager = opaque_types_manager.manager_t( self.__extmodule ) self.__return_pointee_value_exists = False - + + self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger) + def _prepare_decls( self, decls, doc_extractor ): decls = declarations.make_flatten( decls ) @@ -181,6 +184,7 @@ and operator is creator.declaration , creator.creators ): #expose operator only once + self.__dependencies_manager.add_exported( operator ) creator.adopt_creator( code_creators.operator_t( operator=operator ) ) elif not creator: pass @@ -302,6 +306,7 @@ used_headers.add( isuite[ container_name ] ) cls_creator = create_cls_cc( cls ) + self.__dependencies_manager.add_exported( cls ) creators.append( cls_creator ) try: element_type = cls.indexing_suite.element_type @@ -370,6 +375,7 @@ creator.target_configuration = self.__target_configuration #last action. self._append_user_code() + self.__dependencies_manager.inform_user() return self.__extmodule def _create_includes(self): @@ -380,6 +386,7 @@ def visit_member_function( self ): fwrapper = None self.__types_db.update( self.curr_decl ) + self.__dependencies_manager.add_exported( self.curr_decl ) if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) self.__on_demand_include_call_policies( self.curr_decl.call_policies ) @@ -436,6 +443,7 @@ if self.curr_decl.is_copy_constructor: return self.__types_db.update( self.curr_decl ) + self.__dependencies_manager.add_exported( self.curr_decl ) if self.curr_decl.allow_implicit_conversion: maker = code_creators.casting_constructor_t( constructor=self.curr_decl ) self.__module_body.adopt_creator( maker ) @@ -461,8 +469,10 @@ self.__types_db.update( self.curr_decl ) maker = code_creators.operator_t( operator=self.curr_decl ) self.curr_code_creator.adopt_creator( maker ) + self.__dependencies_manager.add_exported( self.curr_decl ) def visit_casting_operator( self ): + self.__dependencies_manager.add_exported( self.curr_decl ) if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) self.__on_demand_include_call_policies( self.curr_decl.call_policies ) @@ -494,6 +504,7 @@ self.__exposed_free_fun_overloads.update( overloads ) for f in overloads: self.__types_db.update( f ) + self.__dependencies_manager.add_exported( f ) if None is f.call_policies: f.call_policies = self.__call_policies_resolver( f ) self.__on_demand_include_call_policies( f.call_policies ) @@ -514,6 +525,7 @@ overloads_reg.associated_decl_creators.extend( uc_creators ) else: self.__types_db.update( self.curr_decl ) + self.__dependencies_manager.add_exported( self.curr_decl ) if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) self.__on_demand_include_call_policies( self.curr_decl.call_policies ) @@ -557,6 +569,7 @@ for f in overloads: self.__types_db.update( f ) + self.__dependencies_manager.add_exported( f ) if None is f.call_policies: f.call_policies = self.__call_policies_resolver( f ) self.__on_demand_include_call_policies( f.call_policies ) @@ -572,7 +585,7 @@ return exposed def visit_class(self ): - assert isinstance( self.curr_decl, declarations.class_t ) + self.__dependencies_manager.add_exported( self.curr_decl ) cls_decl = self.curr_decl cls_parent_cc = self.curr_code_creator exportable_members = self.curr_decl.get_exportable_members(sort_algorithms.sort) @@ -643,7 +656,7 @@ def visit_enumeration(self): - assert isinstance( self.curr_decl, declarations.enumeration_t ) + self.__dependencies_manager.add_exported( self.curr_decl ) maker = None if self.curr_decl.name: maker = code_creators.enum_t( enum=self.curr_decl ) @@ -667,7 +680,8 @@ def visit_variable(self): self.__types_db.update( self.curr_decl ) - + self.__dependencies_manager.add_exported( self.curr_decl ) + if declarations.is_array( self.curr_decl.type ): if not self.__cr_array_1_included: self.__extmodule.add_system_header( code_repository.array_1.file_name ) Added: pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py (rev 0) +++ pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py 2006-11-30 13:56:21 UTC (rev 770) @@ -0,0 +1,76 @@ +# 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) + +from pygccxml import declarations +from pyplusplus import decl_wrappers + +class manager_t( object ): + def __init__( self, logger ): + object.__init__( self ) + self.__exported_decls = [] + self.__logger = logger + + def add_exported( self, decl ): + self.__exported_decls.append( decl ) + + def __is_std_decl( self, decl ): + if not decl.parent: + return False + + if not isinstance( decl.parent, declarations.namespace_t ): + return False + + if 'std' != decl.parent.name: + return False + + ns_std = decl.parent + if not ns_std.parent: + return False + + if not isinstance( ns_std.parent, declarations.namespace_t ): + return False + + if '::' != ns_std.parent.name: + return False + + global_ns = ns_std.parent + if global_ns.parent: + return False + + if decl.name.startswith( 'pair<' ): + #special case + return False + return True + + def __build_dependencies( self, decl ): + if self.__is_std_decl( decl ): + return [] #std declarations should be exported by Py++! + return decl.i_depend_on_them() + + def __find_out_used_but_not_exported( self ): + used_not_exported = [] + exported_ids = set( map( lambda d: id( d ), self.__exported_decls ) ) + for decl in self.__exported_decls: + for dependency in self.__build_dependencies( decl ): + depend_on_decl = dependency.find_out_depend_on_declaration() + if None is depend_on_decl: + continue + if self.__is_std_decl( depend_on_decl ): + continue + if isinstance( depend_on_decl, declarations.class_types ) and depend_on_decl.opaque: + continue + if id( depend_on_decl ) not in exported_ids: + used_not_exported.append( dependency ) + return used_not_exported + + def __create_msg( self, dependency ): + reason = 'The declaration depends on unexposed declaration "%s".' \ + % dependency.find_out_depend_on_declaration() + return "%s;%s" % ( dependency.declaration, reason ) + + def inform_user( self ): + used_not_exported_decls = self.__find_out_used_but_not_exported() + for used_not_exported in used_not_exported_decls: + self.__logger.warn( self.__create_msg( used_not_exported ) ) Property changes on: pyplusplus_dev/unittests ___________________________________________________________________ Name: svn:ignore + *.pyc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |