[pygccxml-commit] SF.net SVN: pygccxml: [1009] pygccxml_dev/pygccxml/parser
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-04-19 21:50:47
|
Revision: 1009 http://svn.sourceforge.net/pygccxml/?rev=1009&view=rev Author: roman_yakovenko Date: 2007-04-19 14:50:46 -0700 (Thu, 19 Apr 2007) Log Message: ----------- another performance optimization - on file 31Mb the number of functions calls was reduced from 15815730 to 10073090 and it is not the limit Modified Paths: -------------- pygccxml_dev/pygccxml/parser/patcher.py pygccxml_dev/pygccxml/parser/source_reader.py Modified: pygccxml_dev/pygccxml/parser/patcher.py =================================================================== --- pygccxml_dev/pygccxml/parser/patcher.py 2007-04-19 21:13:19 UTC (rev 1008) +++ pygccxml_dev/pygccxml/parser/patcher.py 2007-04-19 21:50:46 UTC (rev 1009) @@ -6,33 +6,19 @@ from pygccxml import utils from pygccxml import declarations -class patcher_base_t(object): - def __init__( self, decls ): + +class default_argument_patcher_t( object ): + def __init__( self ): object.__init__( self ) - self.__decls = decls + + def __call__(self, decl): + for arg in decl.arguments: + if not arg.default_value: + continue + fixer = self.__find_fixer( decl, arg ) + if fixer: + arg.default_value = fixer( decl, arg ) - def _get_decls(self): - return self.__decls - decls = property( _get_decls ) - - def patch_it(self): - raise NotImplementedError() - -class default_argument_patcher_t( patcher_base_t ): - def __init__( self, decls ): - patcher_base_t.__init__( self, decls ) - - def patch_it(self): - for decl in declarations.make_flatten( self.decls ): - if not isinstance( decl, declarations.calldef_t ): - continue - for arg in decl.arguments: - if not arg.default_value: - continue - fixer = self.__find_fixer( decl, arg ) - if fixer: - arg.default_value = fixer( decl, arg ) - def __find_fixer(self, func, arg): if not arg.default_value: return False @@ -116,11 +102,10 @@ #this algorithm could be improved: it could take into account #1. unnamed namespaced #2. location within files - enums = filter( lambda decl: isinstance( decl, declarations.enumeration_t ) - , scope.declarations ) - for enum_decl in enums: - if enum_decl.has_value_name( default_value ): - return enum_decl + enumeration_t = declarations.enumeration_t + for decl in scope.declarations: + if isinstance( decl, enumeration_t ) and decl.has_value_name( default_value ): + return decl return None def __is_double_call( self, func, arg ): @@ -182,20 +167,21 @@ return call_invocation.join( f_q_name, args ) -class fix_casting_operator_name_patcher_t( patcher_base_t ): - def __init__( self, decls ): - patcher_base_t.__init__( self, decls ) +class casting_operator_patcher_t( object ): + def __init__( self ): + object.__init__( self ) - def patch_it(self): - for decl in declarations.make_flatten( self.decls ): - if not isinstance( decl, declarations.casting_operator_t): - continue - decl.name = 'operator ' + decl.return_type.decl_string + def __call__(self, decl): + decl.name = 'operator ' + decl.return_type.decl_string -def patch_it(decls): - patcher = default_argument_patcher_t( decls ) - patcher.patch_it() - patcher2 = fix_casting_operator_name_patcher_t( decls ) - patcher2.patch_it() - return patcher.decls +_default_arg_patcher_ = default_argument_patcher_t() +_casting_oper_patcher_ = casting_operator_patcher_t() + +def fix_decls(decls): + #decls should be flat list of all declarations, you want to apply patch on + for decl in decls: + if isinstance( decl, declarations.calldef_t ): + _default_arg_patcher_( decl ) + if isinstance( decl, declarations.casting_operator_t): + _casting_oper_patcher_( decl ) Modified: pygccxml_dev/pygccxml/parser/source_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/source_reader.py 2007-04-19 21:13:19 UTC (rev 1008) +++ pygccxml_dev/pygccxml/parser/source_reader.py 2007-04-19 21:50:46 UTC (rev 1009) @@ -318,14 +318,14 @@ decls = scanner_.declarations() types = scanner_.types() files = {} - for file_id, file_path in scanner_.files().items(): + for file_id, file_path in scanner_.files().iteritems(): files[file_id] = self.__produce_full_file(file_path) linker_ = linker.linker_t( decls=decls , types=types , access=scanner_.access() , membership=scanner_.members() , files=files ) - for type_ in list( types.itervalues() ): + for type_ in types.values(): #I need this copy because internaly linker change types collection linker_.instance = type_ apply_visitor( linker_, type_ ) @@ -333,16 +333,13 @@ linker_.instance = decl apply_visitor( linker_, decl ) bind_aliases( decls.itervalues() ) - decls = filter( lambda inst: isinstance(inst, declaration_t) and not inst.parent, decls.itervalues() ) #some times gccxml report typedefs defined in no namespace #it happens for example in next situation #template< typename X> - #void ddd(){ typedef typename X::Y YY;} + #void ddd(){ typedef typename X::Y YY;} + decls = filter( lambda inst: isinstance(inst, declaration_t) and not inst.parent + , decls.itervalues() ) + patcher.fix_decls( make_flatten( decls ) ) decls = filter( lambda inst: isinstance( inst, namespace_t ), decls ) - decls = patcher.patch_it( decls ) - decls_all = make_flatten( decls ) - for decl in decls_all: - if decl.location: - decl.location.file_name = self.__produce_full_file( decl.location.file_name ) return ( decls, files.values() ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |