Re: [pygccxml-development] USE_CALLDEF_ORGANIZER
Brought to you by:
mbaas,
roman_yakovenko
From: Berserker <ber...@ho...> - 2010-01-27 15:19:21
|
> It is not going to be too difficult. But, If I were you, I would not > go this way. I would drop "overloading" and gave the functions > different name. > > The interface exposed to the user is fragile and could be easily > broken with addition/deletion of a function. > > Let me know if you still want the change. In my option one or more params doesn't make any difference when someone choose to use USE_CALLDEF_ORGANIZER, but it's my opinion :) I managed to write a working solution in ugly python code :D class my_calldef_organizer_t(object): def __init__( self ): object.__init__( self ) #preserve order in which functions where defined self.__cmp_unrelated = lambda d1, d2: cmp( d1.location.line, d2.location.line ) def __build_groups( self, decls ): groups = { None: [] } for d in decls: # First patch here if not isinstance( d, declarations.calldef_t ) or len( d.required_args ) == 0: groups[ None ].append( d ) else: if not groups.has_key( d.name ): groups[ d.name ] = [] groups[ d.name ].append( d ) return groups def __cmp_types( self, t1, t2 ): return decl_wrappers.algorithm.registration_order.is_related( t1, t2 ) def __cmp( self, f1, f2 ): # Second patch here result = None args = len(f1.arguments) if args == len(f2.arguments): i = 0 while i < args and result is None: if not declarations.is_same(f1.arguments[i].type, f2.arguments[i].type): result = self.__cmp_types(f1.arguments[i].type, f2.arguments[i].type) i = i + 1 if result is None: result = self.__cmp_unrelated( f1, f2 ) return result def __sort_groups( self, groups ): for group in groups.keys(): if None is group: continue groups[ group ].sort( self.__cmp ) def __join_groups( self, groups ): decls = [] sorted_keys = groups.keys() sorted_keys.sort() for group in sorted_keys: decls.extend( groups[group] ) return decls def sort( self, decls ): groups = self.__build_groups( decls ) self.__sort_groups(groups) result = self.__join_groups(groups) return result def sort_calldefs_wrapper( decls ): return my_calldef_organizer_t().sort(decls) creators_factory.sort_algorithms.sort_calldefs = sort_calldefs_wrapper I think it would make sense to apply this patch in svn. Thank you as usual ;) Bye _________________________________________________________________ Sei bravo con le parole? Gioca su Typectionary http://typectionary.it.msn.com/ |