[pygccxml-commit] SF.net SVN: pygccxml: [1163] pyplusplus_dev/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-11-20 21:29:54
|
Revision: 1163 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1163&view=rev Author: roman_yakovenko Date: 2007-11-20 13:29:57 -0800 (Tue, 20 Nov 2007) Log Message: ----------- switching to new and better implementation of "already exposed" database and algorithms Modified Paths: -------------- pyplusplus_dev/pyplusplus/file_writers/writer.py pyplusplus_dev/pyplusplus/module_builder/builder.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py pyplusplus_dev/pyplusplus/utils/__init__.py Modified: pyplusplus_dev/pyplusplus/file_writers/writer.py =================================================================== --- pyplusplus_dev/pyplusplus/file_writers/writer.py 2007-11-20 21:25:57 UTC (rev 1162) +++ pyplusplus_dev/pyplusplus/file_writers/writer.py 2007-11-20 21:29:57 UTC (rev 1163) @@ -32,7 +32,7 @@ if None is files_sum_repository: self.__files_sum_repository = md5sum_repository.dummy_repository_t() self.__exposed_decls_db = utils.exposed_decls_db_t() - self.__extmodule.register_exposed( self.__exposed_decls_db ) + self.__exposed_decls_db.register_decls( extmodule.global_ns ) @property def encoding( self ): @@ -143,4 +143,4 @@ def save_exposed_decls_db( self, file_path ): self.__exposed_decls_db.save( file_path ) - \ No newline at end of file + Modified: pyplusplus_dev/pyplusplus/module_builder/builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/builder.py 2007-11-20 21:25:57 UTC (rev 1162) +++ pyplusplus_dev/pyplusplus/module_builder/builder.py 2007-11-20 21:29:57 UTC (rev 1163) @@ -97,7 +97,6 @@ self.__registrations_code_head = [] self.__registrations_code_tail = [] - self.__already_exposed_modules = [] @property def global_ns( self ): @@ -109,7 +108,9 @@ return self.__encoding def register_module_dependency( self, other_module_generate_code_dir ): - self.__already_exposed_modules.append( other_module_generate_code_dir ) + db = utils.exposed_decls_db_t() + db.load( other_module_generate_code_dir ) + db.update_decls( self.global_ns ) def run_query_optimizer(self): """ @@ -255,8 +256,7 @@ , types_db , target_configuration , enable_indexing_suite - , doc_extractor - , self.__already_exposed_modules) + , doc_extractor) self.__code_creator = creator.create() self.__code_creator.replace_included_headers(self.__parsed_files) #I think I should ask users, what they expect @@ -266,11 +266,12 @@ return self.__code_creator - def _get_module( self ): + @property + def code_creator( self ): + "reference to L{code_creators.module_t} instance" if not self.__code_creator: raise RuntimeError( "self.module is equal to None. Did you forget to call build_code_creator function?" ) return self.__code_creator - code_creator = property( _get_module, doc="reference to L{code_creators.module_t} instance" ) def has_code_creator( self ): """ Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-11-20 21:25:57 UTC (rev 1162) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-11-20 21:29:57 UTC (rev 1163) @@ -52,8 +52,7 @@ , types_db=None , target_configuration=None , enable_indexing_suite=True - , doc_extractor=None - , already_exposed_dbs=None): + , doc_extractor=None ): """Constructor. @param decls: Declarations that should be exposed in the final module. @@ -91,7 +90,7 @@ if not self.__types_db: self.__types_db = types_database.types_database_t() - self.__extmodule = code_creators.module_t() + self.__extmodule = code_creators.module_t( declarations.get_global_namespace(decls) ) if boost_python_ns_name: bp_ns_alias = code_creators.namespace_alias_t( alias=boost_python_ns_name , full_namespace_name='::boost::python' ) @@ -102,7 +101,7 @@ self.__extmodule.adopt_creator( self.__module_body ) self.__opaque_types_manager = opaque_types_manager.manager_t( self.__extmodule ) - self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger, already_exposed_dbs) + self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger) prepared_decls = self._prepare_decls( decls, doc_extractor ) self.__decls = sort_algorithms.sort( prepared_decls ) @@ -141,9 +140,8 @@ self.__print_readme( decl ) continue - if self.__dependencies_manager.is_already_exposed( decl ): + if decl.already_exposed: #check wether this is already exposed in other module - decl.already_exposed = True continue if isinstance( decl.parent, declarations.namespace_t ): @@ -286,8 +284,7 @@ for cls in used_containers: self.__print_readme( cls ) - if self.__dependencies_manager.is_already_exposed( cls ): - cls.already_exposed = True + if cls.already_exposed: continue cls_creator = create_cls_cc( cls ) Modified: pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py 2007-11-20 21:25:57 UTC (rev 1162) +++ pyplusplus_dev/pyplusplus/module_creator/dependencies_manager.py 2007-11-20 21:29:57 UTC (rev 1163) @@ -13,20 +13,14 @@ class manager_t( object ): - def __init__( self, logger, already_exposed=None ): + def __init__( self, logger ): object.__init__( self ) self.__exported_decls = [] self.__logger = logger - self.__already_exposed_db = utils.exposed_decls_db_t() - if already_exposed: - map( self.__already_exposed_db.load, already_exposed ) def add_exported( self, decl ): self.__exported_decls.append( decl ) - def is_already_exposed( self, decl ): - return decl.already_exposed or self.__already_exposed_db.is_exposed( decl ) - def __select_duplicate_aliases( self, decls ): duplicated = {} for decl in decls: @@ -79,7 +73,7 @@ if self.__is_std_decl( decl ): #TODO add element_type to the list of dependencies return [] #std declarations should be exported by Py++! - if self.is_already_exposed( decl ): + if decl.already_exposed: return [] dependencies = decl.i_depend_on_them(recursive=False) if isinstance( decl, declarations.class_t ): Modified: pyplusplus_dev/pyplusplus/utils/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/utils/__init__.py 2007-11-20 21:25:57 UTC (rev 1162) +++ pyplusplus_dev/pyplusplus/utils/__init__.py 2007-11-20 21:29:57 UTC (rev 1163) @@ -55,96 +55,113 @@ class exposed_decls_db_t( object ): DEFAULT_FILE_NAME = 'exposed_decl.pypp.txt' - class row_creator_t( declarations.decl_visitor_t ): - def __init__( self, field_delimiter ): - self.__decl = None - self.__formatted = None - self.__field_delimiter = field_delimiter + class row_t( declarations.decl_visitor_t ): + FIELD_DELIMITER = '@' + EXPOSED_DECL_SIGN = '+' + UNEXPOSED_DECL_SIGN = '~' + CALLDEF_SIGNATURE_DELIMITER = '#' + + def __init__( self, decl_or_string ): + self.key = '' + self.signature = '' + self.exposed_sign = '' + self.normalized_name = '' + if isinstance( decl_or_string, declarations.declaration_t ): + self.__init_from_decl( decl_or_string ) + else: + self.__init_from_str( decl_or_string ) - def get_full_name(self): - return declarations.full_name( self.__decl ) + def find_out_normalized_name( self, decl ): + if decl.name: + return decl.name + else:#unnamed enums, classes, unions + return str( decl.location.as_tuple() ) - def __call__( self, decl ): - self.__decl = decl - self.__formatted = None - try: - declarations.apply_visitor( self, decl ) - except NotImplementedError: - pass - return self.__formatted + def __init_from_str( self, row ): + self.exposed_sign, self.key, self.normalized_name, self.signature \ + = row.split( self.FIELD_DELIMITER ) - def visit_free_function( self ): - self.__formatted = '%s%s%s' % ( self.get_full_name() - , self.__field_delimiter - , self.__decl.function_type().decl_string ) - - def visit_class_declaration(self ): - self.__formatted = self.get_full_name() + def __init_from_decl( self, decl ): + if decl.ignore: + self.exposed_sign = self.UNEXPOSED_DECL_SIGN + else: + self.exposed_sign = self.EXPOSED_DECL_SIGN + self.key = decl.__class__.__name__ + self.signature = decl.decl_string + if isinstance( decl, declarations.calldef_t ): + self.signature = self.signature + decl.function_type().decl_string + self.normalized_name = self.find_out_normalized_name( decl ) - def visit_class(self ): - self.__formatted = self.get_full_name() - - def visit_enumeration(self ): - self.__formatted = self.get_full_name() - - def visit_variable(self ): - self.__formatted = self.get_full_name() + def __str__( self ): + return self.FIELD_DELIMITER.join([ self.exposed_sign + , self.key + , self.normalized_name + , self.signature]) + def does_refer_same_decl( self, other ): + return self.key == other.key \ + and self.signature == other.signature \ + and self.normalized_name == other.normalized_name + def __init__( self ): - self.__exposed = {} - self.__row_creator = self.row_creator_t(field_delimiter='@') - self.__key_delimiter = '?' + self.__registry = {} # key : { name : set(row) } self.__row_delimiter = os.linesep def save( self, fpath ): if os.path.isdir( fpath ): fpath = os.path.join( fpath, self.DEFAULT_FILE_NAME ) f = file( fpath, 'w+b' ) - for key, items in self.__exposed.iteritems(): - for item in items: - f.write( '%s%s%s%s' % ( key, self.__key_delimiter, item, self.__row_delimiter ) ) + for name2rows in self.__registry.itervalues(): + for rows in name2rows.itervalues(): + for row in rows: + f.write( '%s%s' % ( str(row), self.__row_delimiter ) ) f.close() - + def load( self, fpath ): if os.path.isdir( fpath ): fpath = os.path.join( fpath, self.DEFAULT_FILE_NAME ) f = file( fpath, 'r+b' ) for line in f: - key, row = line.split( self.__key_delimiter) - row = row.replace( self.__row_delimiter, '' ) - if not self.__exposed.has_key( key ): - self.__exposed[ key ] = set() - self.__exposed[ key ].add( row ) - - def __create_key( self, decl ): - return decl.__class__.__name__ + row = self.row_t( line.replace( self.__row_delimiter, '' ) ) + self.__update_registry( row ) - def expose( self, decl ): - if not isinstance( decl.parent, declarations.namespace_t ): - return None #we don't want to dump class internal declarations - row = self.__row_creator( decl ) - if row is None: + def __update_registry( self, row ): + if not self.__registry.has_key( row.key ): + self.__registry[ row.key ] = { row.normalized_name : [row] } + else: + if not self.__registry[ row.key ].has_key( row.normalized_name ): + self.__registry[ row.key ][row.normalized_name] = [row] + else: + self.__registry[ row.key ][row.normalized_name].append(row) + + def __find_in_registry( self, decl ): + row = self.row_t( decl ) + try: + decls = filter( lambda rrow: rrow.does_refer_same_decl( row ) + , self.__registry[ row.key ][ row.normalized_name ] ) + if decls: + return decls[0] + else: + return None + except KeyError: return None - key = self.__create_key( decl ) - if not self.__exposed.has_key( key ): - self.__exposed[ key ] = set() - self.__exposed[ key ].add( row ) - - def __get_under_ns_decl( self, decl ): - while True: - if isinstance( decl.parent, declarations.namespace_t ): - return decl + + def is_exposed( self, decl ): + row = self.__find_in_registry( decl) + return row and self.row_t.EXPOSED_DECL_SIGN == row.exposed_sign + + def update_decls( self, global_ns ): + for decl in global_ns.decls(): + row = self.__find_in_registry( decl ) + if not row: + continue + if self.row_t.EXPOSED_DECL_SIGN == row.exposed_sign: + decl.ignore = False + decl.already_exposed = True else: - decl = decl.parent + decl.ignore = True + decl.already_exposed = False - def is_exposed( self, decl_ ): - if isinstance( decl_, declarations.namespace_t ): - return False#namespaces are always exposed - decl = self.__get_under_ns_decl( decl_ ) - key = self.__create_key( decl ) - if not self.__exposed.has_key( key ): - return False - row = self.__row_creator( decl ) - return row in self.__exposed[ key ] - - + def register_decls( self, global_ns ): + for decl in global_ns.decls(): + self.__update_registry( self.row_t( decl ) ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |