From: <rom...@us...> - 2007-11-27 19:55:37
|
Revision: 1175 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1175&view=rev Author: roman_yakovenko Date: 2007-11-27 11:55:42 -0800 (Tue, 27 Nov 2007) Log Message: ----------- adding support for class partial name - name without default template arguments Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/algorithm.py pygccxml_dev/pygccxml/declarations/algorithms_cache.py pygccxml_dev/pygccxml/declarations/calldef.py pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/container_traits.py pygccxml_dev/pygccxml/declarations/cpptypes.py pygccxml_dev/pygccxml/declarations/declaration.py pygccxml_dev/pygccxml/declarations/matchers.py Modified: pygccxml_dev/pygccxml/declarations/algorithm.py =================================================================== --- pygccxml_dev/pygccxml/declarations/algorithm.py 2007-11-26 11:32:03 UTC (rev 1174) +++ pygccxml_dev/pygccxml/declarations/algorithm.py 2007-11-27 19:55:42 UTC (rev 1175) @@ -7,7 +7,7 @@ import types -def declaration_path( decl ): +def declaration_path( decl, with_defaults=True ): """ returns a list of parent declarations names @@ -17,9 +17,6 @@ @return: [names], where first item contains top parent name and last item contains decl name """ - #TODO: - #If parent declaration cache already has declaration_path, reuse it for - #calculation. if not decl: return [] if not decl.cache.declaration_path: @@ -39,6 +36,40 @@ else: return decl.cache.declaration_path +def partial_declaration_path( decl ): + """ + returns a list of parent declarations names without template arguments that + have default value + + @param decl: declaration for which declaration path should be calculated + @type decl: L{declaration_t} + + @return: [names], where first item contains top parent name and last item + contains decl name + """ + #TODO: + #If parent declaration cache already has declaration_path, reuse it for + #calculation. + if not decl: + return [] + if not decl.cache.partial_declaration_path: + result = [ decl.partial_name ] + parent = decl.parent + while parent: + if parent.cache.partial_declaration_path: + result.reverse() + decl.cache.partial_declaration_path \ + = parent.cache.partial_declaration_path + result + return decl.cache.partial_declaration_path + else: + result.append( parent.partial_name ) + parent = parent.parent + result.reverse() + decl.cache.partial_declaration_path = result + return result + else: + return decl.cache.partial_declaration_path + def full_name_from_declaration_path( dpath ): ##Here I have lack of knowledge: ##TODO: "What is the full name of declaration declared in unnamed namespace?" @@ -46,7 +77,7 @@ result = result[0] + '::'.join( result[1:] ) return result -def full_name( decl ): +def full_name( decl, with_defaults=True ): """ returns full name of the declaration @param decl: declaration for which full name should be calculated. If decl @@ -58,10 +89,16 @@ """ if None is decl: raise RuntimeError( "Unable to generate full name for None object!" ) - if not decl.cache.full_name: - decl.cache.full_name = full_name_from_declaration_path( declaration_path( decl ) ) - return decl.cache.full_name - + if with_defaults: + if not decl.cache.full_name: + decl.cache.full_name = full_name_from_declaration_path( declaration_path( decl ) ) + return decl.cache.full_name + else: + if not decl.cache.full_partial_name: + decl.cache.full_partial_name \ + = full_name_from_declaration_path( partial_declaration_path( decl ) ) + return decl.cache.full_partial_name + def make_flatten( decl_or_decls ): """ converts tree representation of declarations to flatten one. Modified: pygccxml_dev/pygccxml/declarations/algorithms_cache.py =================================================================== --- pygccxml_dev/pygccxml/declarations/algorithms_cache.py 2007-11-26 11:32:03 UTC (rev 1174) +++ pygccxml_dev/pygccxml/declarations/algorithms_cache.py 2007-11-27 19:55:42 UTC (rev 1175) @@ -13,9 +13,11 @@ object.__init__( self ) self._enabled = True self._full_name = None + self._full_partial_name = None self._access_type = None self._demangled_name = None self._declaration_path = None + self._partial_declaration_path = None def disable( self ): self._enabled = False @@ -37,6 +39,16 @@ full_name = property( _get_full_name, _set_full_name ) + def _get_full_partial_name( self ): + return self._full_partial_name + + def _set_full_partial_name( self, fname ): + if not self.enabled: + fname = None + self._full_partial_name = fname + + full_partial_name = property( _get_full_partial_name, _set_full_partial_name ) + def _get_access_type( self ): return self._access_type @@ -44,7 +56,6 @@ if not self.enabled: access_type = None self._access_type = access_type - access_type = property( _get_access_type, _set_access_type ) def _get_demangled_name( self ): @@ -64,19 +75,34 @@ if not self.enabled: declaration_path = None self._declaration_path = declaration_path - + declaration_path = property( _get_declaration_path, _set_declaration_path ) + def _get_partial_declaration_path( self ): + return self._partial_declaration_path + + def _set_partial_declaration_path( self, partial_declaration_path ): + if not self.enabled: + partial_declaration_path = None + self._partial_declaration_path = partial_declaration_path + + partial_declaration_path = property( _get_partial_declaration_path + , _set_partial_declaration_path ) + def reset( self ): self.full_name = None + self.full_partial_name = None self.access_type = None self.demangled_name = None self.declaration_path = None + self.partial_declaration_path = None def reset_name_based( self ): self.full_name = None + self.full_partial_name = None self.demangled_name = None self.declaration_path = None + self.partial_declaration_path = None def reset_access_type( self ): self.access_type = None Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2007-11-26 11:32:03 UTC (rev 1174) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2007-11-27 19:55:42 UTC (rev 1175) @@ -391,10 +391,13 @@ , arguments_types=[ arg.type for arg in self.arguments ] , has_const=self.has_const ) - def _create_decl_string(self): - return self.function_type().decl_string + def create_decl_string(self, with_defaults=True): + f_type = self.function_type() + if with_defaults: + return f_type.decl_string + else: + return f_type.partial_decl_string - class free_calldef_t( calldef_t ): """base class for "callable" declarations that defined within C++ namespace""" def __init__( self, *args, **keywords ): @@ -430,9 +433,14 @@ return cpptypes.free_function_type_t( return_type=self.return_type , arguments_types=[ arg.type for arg in self.arguments ] ) - def _create_decl_string(self): - return self.function_type().decl_string + def create_decl_string(self, with_defaults=True): + f_type = self.function_type() + if with_defaults: + return f_type.decl_string + else: + return f_type.partial_decl_string + class operator_t(object): """base class for "operator" declarations""" OPERATOR_WORD_LEN = len( 'operator' ) Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2007-11-26 11:32:03 UTC (rev 1174) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2007-11-27 19:55:42 UTC (rev 1175) @@ -107,6 +107,11 @@ self._container_traits = container_traits.find_container_traits( self ) return self._container_traits + def _get_partial_name_impl( self ): + if not self.container_traits: + return self.name + return self.container_traits.remove_defaults( self ) + class class_t( scopedef.scopedef_t ): """describes class definition""" @@ -406,5 +411,10 @@ return trivial[0] else: return None - + + def _get_partial_name_impl( self ): + if not self.container_traits: + return self.name + return self.container_traits.remove_defaults( self ) + class_types = ( class_t, class_declaration_t ) Modified: pygccxml_dev/pygccxml/declarations/container_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/container_traits.py 2007-11-26 11:32:03 UTC (rev 1174) +++ pygccxml_dev/pygccxml/declarations/container_traits.py 2007-11-27 19:55:42 UTC (rev 1175) @@ -145,18 +145,20 @@ return key_type = c_args[0] mapped_type = c_args[1] - tmpl = string.Template( "$container< $key_type, $mapped_type, $compare<$key_type>, $allocator< std::pair< const $key_type, $mapped_type> > >" ) - if key_type.startswith( 'const ' ) or key_type.endswith( ' const' ): - tmpl = string.Template( "$container< $key_type, $mapped_type, $compare<$key_type>, $allocator< std::pair< $key_type, $mapped_type> > >" ) - tmpl = tmpl.substitute( container=c_name - , key_type=key_type - , mapped_type=mapped_type - , compare=default_compare - , allocator=default_allocator ) - if defaults_eraser.normalize( cls_name ) == defaults_eraser.normalize( tmpl ): - return templates.join( c_name - , [ defaults_eraser.erase_recursive( key_type ) - , defaults_eraser.erase_recursive( mapped_type )] ) + tmpls = [ + string.Template( "$container< $key_type, $mapped_type, $compare<$key_type>, $allocator< std::pair< const $key_type, $mapped_type> > >" ) + , string.Template( "$container< $key_type, $mapped_type, $compare<$key_type>, $allocator< std::pair< $key_type const, $mapped_type> > >" ) + , string.Template( "$container< $key_type, $mapped_type, $compare<$key_type>, $allocator< std::pair< $key_type, $mapped_type> > >" )] + for tmpl in tmpls: + tmpl = tmpl.substitute( container=c_name + , key_type=key_type + , mapped_type=mapped_type + , compare=default_compare + , allocator=default_allocator ) + if defaults_eraser.normalize( cls_name ) == defaults_eraser.normalize( tmpl ): + return templates.join( c_name + , [ defaults_eraser.erase_recursive( key_type ) + , defaults_eraser.erase_recursive( mapped_type )] ) @staticmethod Modified: pygccxml_dev/pygccxml/declarations/cpptypes.py =================================================================== --- pygccxml_dev/pygccxml/declarations/cpptypes.py 2007-11-26 11:32:03 UTC (rev 1174) +++ pygccxml_dev/pygccxml/declarations/cpptypes.py 2007-11-27 19:55:42 UTC (rev 1175) @@ -34,12 +34,16 @@ return self.__class__.__name__ < other.__class__.__name__ return self.decl_string < other.decl_string - def _create_decl_string(self): + def build_decl_string(self, with_defaults=True): raise NotImplementedError() - def _get_decl_string( self ): - return self._create_decl_string() - decl_string = property( _get_decl_string ) + @property + def decl_string( self ): + return self.build_decl_string() + + @property + def partial_decl_string( self ): + return self.build_decl_string( False ) def _clone_impl( self ): raise NotImplementedError() @@ -63,7 +67,7 @@ type_t.__init__( self ) self._decl_string = decl_string - def _create_decl_string(self): + def build_decl_string(self, with_defaults=True): return self._decl_string def _clone_impl( self ): @@ -74,7 +78,7 @@ def __init__( self ): type_t.__init__( self ) - def _create_decl_string(self): + def build_decl_string(self, with_defaults=True): return '?unknown?' def _clone_impl( self ): @@ -89,7 +93,7 @@ type_t.__init__( self ) self._name = name - def _create_decl_string(self): + def build_decl_string(self, with_defaults=True): return self._name def _clone_impl( self ): @@ -336,8 +340,8 @@ def __init__( self, base ): compound_t.__init__( self, base) - def _create_decl_string(self): - return 'volatile ' + self.base.decl_string + def build_decl_string(self, with_defaults=True): + return 'volatile ' + self.base.build_decl_string(with_defaults) def _clone_impl( self ): return volatile_t( self.base.clone() ) @@ -357,8 +361,8 @@ def __init__( self, base ): compound_t.__init__( self, base) - def _create_decl_string(self): - return '__restrict__ ' + self.base.decl_string + def build_decl_string(self, with_defaults=True): + return '__restrict__ ' + self.base.build_decl_string( with_defaults ) def _clone_impl( self ): return restrict_t( self.base.clone() ) @@ -368,8 +372,8 @@ def __init__( self, base ): compound_t.__init__( self, base ) - def _create_decl_string(self): - return self.base.decl_string + ' const' + def build_decl_string(self, with_defaults=True): + return self.base.build_decl_string(with_defaults) + ' const' def _clone_impl( self ): return const_t( self.base.clone() ) @@ -379,8 +383,8 @@ def __init__( self, base ): compound_t.__init__( self, base ) - def _create_decl_string(self): - return self.base.decl_string + ' *' + def build_decl_string(self, with_defaults=True): + return self.base.build_decl_string( with_defaults ) + ' *' def _clone_impl( self ): return pointer_t( self.base.clone() ) @@ -390,8 +394,8 @@ def __init__( self, base ): compound_t.__init__( self, base) - def _create_decl_string(self): - return self.base.decl_string + ' &' + def build_decl_string(self, with_defaults=True): + return self.base.build_decl_string(with_defaults) + ' &' def _clone_impl( self ): return reference_t( self.base.clone() ) @@ -411,8 +415,8 @@ size = property( _get_size, _set_size, doc="returns array size" ) - def _create_decl_string(self): - return self.base.decl_string + '[%d]' % self.size + def build_decl_string(self, with_defaults=True): + return self.base.build_decl_string(with_defaults) + '[%d]' % self.size def _clone_impl( self ): return array_t( self.base.clone(), self.size ) @@ -449,7 +453,7 @@ calldef_type_t.__init__( self, return_type, arguments_types ) @staticmethod - def create_decl_string( return_type, arguments_types ): + def create_decl_string( return_type, arguments_types, with_defaults=True ): """ returns free function type @@ -461,11 +465,12 @@ @return: L{free_function_type_t} """ return free_function_type_t.NAME_TEMPLATE % { - 'return_type' : return_type.decl_string - , 'arguments' : ','.join( map( lambda x: x.decl_string, arguments_types ) ) } + 'return_type' : return_type.build_decl_string( with_defaults ) + , 'arguments' : ','.join( map( lambda x: x.build_decl_string( with_defaults ) + , arguments_types ) ) } - def _create_decl_string(self): - return self.create_decl_string( self.return_type, self.arguments_types ) + def build_decl_string(self, with_defaults=True): + return self.create_decl_string( self.return_type, self.arguments_types, with_defaults ) def _clone_impl( self ): rt_clone = None @@ -475,7 +480,7 @@ , [ arg.clone() for arg in self.arguments_types ] ) #TODO: create real typedef - def create_typedef( self, typedef_name, unused=None): + def create_typedef( self, typedef_name, unused=None, with_defaults=True): """returns string, that contains valid C++ code, that defines typedef to function type @param name: the desired name of typedef @@ -483,8 +488,9 @@ #unused argument simplifies user code return free_function_type_t.TYPEDEF_NAME_TEMPLATE % { 'typedef_name' : typedef_name - , 'return_type' : self.return_type.decl_string - , 'arguments' : ','.join( map( lambda x: x.decl_string, self.arguments_types ) ) } + , 'return_type' : self.return_type.build_decl_string( with_defaults ) + , 'arguments' : ','.join( map( lambda x: x.build_decl_string( with_defaults ) + , self.arguments_types ) ) } class member_function_type_t( type_t, calldef_type_t ): """describes member function type""" @@ -512,7 +518,7 @@ ,doc="reference to parent L{class<declaration_t>}" ) #TODO: create real typedef - def create_typedef( self, typedef_name, class_alias=None): + def create_typedef( self, typedef_name, class_alias=None, with_defaults=True): """creates typedef to the function type @param typedef_name: desired type name @@ -522,40 +528,46 @@ if self.has_const: has_const_str = 'const' if None is class_alias: - class_alias = self.class_inst.decl_string + if with_defaults: + class_alias = self.class_inst.decl_string + else: + class_alias = self.class_inst.partial_decl_string return member_function_type_t.TYPEDEF_NAME_TEMPLATE % { 'typedef_name' : typedef_name - , 'return_type' : self.return_type.decl_string + , 'return_type' : self.return_type.build_decl_string( with_defaults ) , 'class' : class_alias - , 'arguments' : ','.join( map( lambda x: x.decl_string, self.arguments_types ) ) + , 'arguments' : ','.join( map( lambda x: x.build_decl_string(with_defaults) + , self.arguments_types ) ) , 'has_const' : has_const_str } def create(self): - return self.create_decl_string( self.return_type + return self.build_decl_string( self.return_type , self.class_inst.decl_string , self.arguments_types , self.has_const ) @staticmethod - def create_decl_string(return_type, class_decl_string, arguments_types, has_const): + def create_decl_string(return_type, class_decl_string, arguments_types, has_const, with_defaults=True): has_const_str = '' if has_const: has_const_str = 'const' return_type_decl_string = '' if return_type: - return_type_decl_string = return_type.decl_string + return_type_decl_string = return_type.build_decl_string( with_defaults ) return member_function_type_t.NAME_TEMPLATE % { 'return_type' : return_type_decl_string , 'class' : class_decl_string - , 'arguments' : ','.join( map( lambda x: x.decl_string, arguments_types ) ) + , 'arguments' : ','.join( map( lambda x: x.build_decl_string(with_defaults) + , arguments_types ) ) , 'has_const' : has_const_str } - def _create_decl_string(self): + def build_decl_string(self, with_defaults=True): return self.create_decl_string( self.return_type , self.class_inst.decl_string , self.arguments_types - , self.has_const ) + , self.has_const + , with_defaults) def _clone_impl( self ): rt_clone = None @@ -582,8 +594,9 @@ variable_type = property( _get_variable_type, _set_variable_type , doc="describes member variable L{type<type_t>}") - def _create_decl_string(self): - return self.NAME_TEMPLATE % { 'type' : self.variable_type.decl_string, 'class' : self.base.decl_string } + def build_decl_string(self, with_defaults=True): + return self.NAME_TEMPLATE % { 'type' : self.variable_type.build_decl_string(with_defaults) + , 'class' : self.base.build_decl_string(with_defaults) } def _clone_impl( self ): return member_variable_type_t( class_inst=self.base @@ -606,8 +619,11 @@ declaration = property( _get_declaration, _set_declaration , doc="reference to L{declaration<declaration_t>}") - def _create_decl_string(self): - return self._declaration.decl_string + def build_decl_string(self, with_defaults=True): + if with_defaults: + return self._declaration.decl_string + else: + return self._declaration.partial_decl_string def _clone_impl( self ): return declarated_t( self._declaration ) Modified: pygccxml_dev/pygccxml/declarations/declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/declaration.py 2007-11-26 11:32:03 UTC (rev 1174) +++ pygccxml_dev/pygccxml/declarations/declaration.py 2007-11-27 19:55:42 UTC (rev 1175) @@ -67,6 +67,7 @@ self._parent = None self._cache = algorithms_cache.declaration_algs_cache_t() self._compiler = None + self._partial_name = None def __str__(self): """Default __str__ method. @@ -150,6 +151,7 @@ def _set_name( self, new_name ): previous_name = self._name self._name = new_name + self._partial_name = None self.cache.reset_name_based() if previous_name: #the was a rename and not initial "set" self._on_rename() @@ -159,6 +161,17 @@ @type: str """) + def _get_partial_name_impl( self ): + return self.name + + @property + def partial_name( self ): + """declaration name, without template default arguments + Right now std containers is the only classes that support this functionality""" + if None is self._partial_name: + self._partial_name = self._get_partial_name_impl() + return self._partial_name + def _get_parent(self): return self._parent def _set_parent(self, new_parent): @@ -229,17 +242,20 @@ @type: str """ ) + def create_decl_string(self, with_defaults=True): + return algorithm.full_name( self, with_defaults ) - def _create_decl_string(self): - return algorithm.full_name( self ) + @property + def decl_string(self): + """declaration full name""" + return self.create_decl_string() - def _decl_string(self): - return self._create_decl_string() - decl_string = property( _decl_string, - doc="""Full name of the declaration - @type: str - """ ) @property + def partial_decl_string(self): + """declaration full name""" + return self.create_decl_string(with_defaults=False) + + @property def cache( self ): """implementation details Modified: pygccxml_dev/pygccxml/declarations/matchers.py =================================================================== --- pygccxml_dev/pygccxml/declarations/matchers.py 2007-11-26 11:32:03 UTC (rev 1174) +++ pygccxml_dev/pygccxml/declarations/matchers.py 2007-11-27 19:55:42 UTC (rev 1175) @@ -223,20 +223,21 @@ def check_name( self, decl ): assert not None is self.name - if self.__opt_is_tmpl_inst: if not self.__opt_is_full_name: - if self.name != decl.name: + if self.name != decl.name and self.name != decl.partial_name: return False else: - if self.name != algorithm.full_name( decl ): + if self.name != algorithm.full_name( decl, with_defaults=True ) \ + and self.name != algorithm.full_name( decl, with_defaults=False ): return False else: if not self.__opt_is_full_name: - if decl.name != self.name: + if self.name != decl.name and self.name != decl.partial_name: return False else: - if self.name != algorithm.full_name( decl ): + if self.name != algorithm.full_name( decl, with_defaults=True ) \ + and self.name != algorithm.full_name( decl, with_defaults=False ): return False return True This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |