[pygccxml-commit] SF.net SVN: pygccxml: [475] pygccxml_dev/pygccxml/parser
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-08-26 17:26:25
|
Revision: 475 Author: roman_yakovenko Date: 2006-08-26 10:26:11 -0700 (Sat, 26 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=475&view=rev Log Message: ----------- adding declarations and type algorirthms result cache Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/algorithm.py pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/declaration.py pygccxml_dev/pygccxml/declarations/namespace.py pygccxml_dev/pygccxml/declarations/scopedef.py pygccxml_dev/pygccxml/parser/linker.py Added Paths: ----------- pygccxml_dev/pygccxml/declarations/algorithms_cache.py Modified: pygccxml_dev/pygccxml/declarations/algorithm.py =================================================================== --- pygccxml_dev/pygccxml/declarations/algorithm.py 2006-08-26 12:14:17 UTC (rev 474) +++ pygccxml_dev/pygccxml/declarations/algorithm.py 2006-08-26 17:26:11 UTC (rev 475) @@ -19,18 +19,15 @@ """ if not decl: return [] - cached_decl_path = getattr(decl, "cached_decl_path", None) - if cached_decl_path: - return cached_decl_path - else: + if not decl.cache.declaration_path: result = [ decl.name ] parent = decl.parent while parent: result.append( parent.name ) parent = parent.parent result.reverse() - setattr(decl, "cached_decl_path", result) - return result + decl.cache.declaration_path = result + return decl.cache.declaration_path def full_name( decl ): """ @@ -44,11 +41,13 @@ """ if None is decl: raise RuntimeError( "Unable to generate full name for None object!" ) - decl_path = declaration_path( decl ) - ##Here I have lack of knowledge: - ##TODO: "What is the full name of declaration declared in unnamed namespace?" - result = filter( None, decl_path ) - return result[0] + '::'.join( result[1:] ) + if not decl.cache.full_name: + decl_path = declaration_path( decl ) + ##Here I have lack of knowledge: + ##TODO: "What is the full name of declaration declared in unnamed namespace?" + result = filter( None, decl_path ) + decl.cache.full_name = result[0] + '::'.join( result[1:] ) + return decl.cache.full_name def make_flatten( decl_or_decls ): Added: pygccxml_dev/pygccxml/declarations/algorithms_cache.py =================================================================== --- pygccxml_dev/pygccxml/declarations/algorithms_cache.py (rev 0) +++ pygccxml_dev/pygccxml/declarations/algorithms_cache.py 2006-08-26 17:26:11 UTC (rev 475) @@ -0,0 +1,33 @@ +# 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) + +""" +defines class that will keep results of different calculations. +""" + +class algorithms_cache_t( object ): + def __init__( self ): + object.__init__( self ) + self.full_name = None + self.access_type = None + self.declaration_path = None + + def reset( self ): + self.full_name = None + self.access_type = None + self.declaration_path = None + + def reset_name_based( self ): + self.full_name = None + self.declaration_path = None + + def reset_access_type( self ): + self.access_type = None + +class type_traits_cache_t( object ): + def __init__( self ): + object.__init__( self ) + self.remove_alias = None + Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-26 12:14:17 UTC (rev 474) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-26 17:26:11 UTC (rev 475) @@ -107,9 +107,7 @@ if not self._name: #class with empty name return self._name elif class_t.USE_DEMANGLED_AS_NAME and self.demangled: - if self.__cached_demangled_name: - return self.__cached_demangled_name - else: + if not self.__cached_demangled_name: fname = algorithm.full_name( self.parent ) if fname.startswith( '::' ) and not self.demangled.startswith( '::' ): fname = fname[2:] @@ -120,7 +118,7 @@ self.__cached_demangled_name = tmp else: self.__cached_demangled_name = self._name - return self.__cached_demangled_name + return self.__cached_demangled_name else: return self._name @@ -246,6 +244,8 @@ returns list of members according to access type If access equals to None, then returned list will contain all members. + You should not modify the list content, otherwise different optimization + data will stop work and may to give you wrong results. @param access: describes desired members @type access: L{ACCESS_TYPES} @@ -265,25 +265,24 @@ all_members.extend( self.private_members ) return all_members - def set_members( self, access, new_members ): - """ - set list of members according to access type + def adopt_declaration( self, decl, access ): + """adds new declaration to the class - @param access: describes desired members - @type access: L{ACCESS_TYPES} + @param decl: reference to a L{declaration<declaration_t>} - @param new_members: list of new members - @type new_members: [ L{member<declaration_t>} ] + @param access: member access type + @type access: L{ACCESS_TYPES} """ - assert( access in ACCESS_TYPES.ALL ) if access == ACCESS_TYPES.PUBLIC: - self.public_members = new_members + self.public_members.append( decl ) elif access == ACCESS_TYPES.PROTECTED: - self.protected_members = new_members + self.protected_members.append( decl ) + elif access == ACCESS_TYPES.PRIVATE: + self.private_members.append( decl ) else: - self.private_members = new_members - for member in new_members: - member.parent = self + raise RuntimeError( "Invalid access type: %s." % access ) + decl.parent = self + decl.cache.access_type = access def remove_declaration( self, decl ): """ @@ -293,19 +292,16 @@ @type decl: L{declaration_t} """ container = None - if decl in self.public_members: + access_type = self.find_out_member_access_type( decl ) + if access_type == ACCESS_TYPES.PUBLIC: container = self.public_members - elif decl in self.protected_members: + elif access_type == ACCESS_TYPES.PROTECTED: container = self.protected_members - elif decl in self.private_members: + else: #decl.cache.access_type == ACCESS_TYPES.PRVATE container = self.private_members - else: - raise ValueError() del container[ container.index( decl ) ] - #add more comment about this. - #if not keep_parent: - # decl.parent=None - + decl.cache.reset_access_type() + def find_out_member_access_type( self, member ): """ returns member access type @@ -316,19 +312,15 @@ @return: L{ACCESS_TYPES} """ assert member.parent is self - cached_access_type = getattr(member, "_cached_access_type", None) - if cached_access_type: - return cached_access_type - else: + if not member.cache.access_type: access_type = None if member in self.public_members: - access_type = ACCESS_TYPES.PUBLIC + member.cache.access_type = ACCESS_TYPES.PUBLIC elif member in self.protected_members: - access_type = ACCESS_TYPES.PROTECTED + member.cache.access_type = ACCESS_TYPES.PROTECTED elif member in self.private_members: - access_type = ACCESS_TYPES.PRIVATE + member.cache.access_type = ACCESS_TYPES.PRIVATE else: raise RuntimeError( "Unable to find member within internal members list." ) - setattr(member, "_cached_access_type", access_type) - return access_type + return member.cache.access_type Modified: pygccxml_dev/pygccxml/declarations/declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/declaration.py 2006-08-26 12:14:17 UTC (rev 474) +++ pygccxml_dev/pygccxml/declarations/declaration.py 2006-08-26 17:26:11 UTC (rev 475) @@ -12,8 +12,8 @@ import algorithm import templates +import algorithms_cache - class location_t(object): """provides information about the location of the declaration within the source file. @@ -75,8 +75,7 @@ self._mangled = mangled self._demangled = demangled self._parent = None - - #self._cached_name = None + self._cache = algorithms_cache.algorithms_cache_t() def __str__(self): """Default __str__ method. @@ -159,8 +158,15 @@ # return self._cached_name return self._get_name_impl() + def _on_rename( self ): + pass + def _set_name( self, new_name ): + previous_name = self._name self._name = new_name + if previous_name: #the was a rename and not initial "set" + self._on_rename() + name = property( _get_name, _set_name , doc="""Declaration name @type: str @@ -236,3 +242,10 @@ doc="""Full name of the declaration @type: str """ ) + @property + def cache( self ): + """implementation details + + reference to instance of L{algorithms_cache.algorithms_cache_t} class. + """ + return self._cache \ No newline at end of file Modified: pygccxml_dev/pygccxml/declarations/namespace.py =================================================================== --- pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-26 12:14:17 UTC (rev 474) +++ pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-26 17:26:11 UTC (rev 475) @@ -48,6 +48,10 @@ self.declarations.append( decl ) inst.declarations = [] + def adopt_declaration( self, decl ): + self.declarations.append( decl ) + decl.parent = self + def remove_declaration( self, decl ): """ removes decl from members list Modified: pygccxml_dev/pygccxml/declarations/scopedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/scopedef.py 2006-08-26 12:14:17 UTC (rev 474) +++ pygccxml_dev/pygccxml/declarations/scopedef.py 2006-08-26 17:26:11 UTC (rev 475) @@ -205,6 +205,15 @@ return add_operator( symbol ) return name #both name and symbol are None + def _on_rename( self ): + for decl in self.decls(allow_empty=True): + decl.cache.reset_name_based() + #I am not sure whether to introduce this or not? + #It could be very time consuming operation + it changes optimize query + #data structures. + #if self.parent: + # if self.parent._optimized: + # self.parent.init_optimizer() def __normalize_args( self, **keywds ): """implementation details""" Modified: pygccxml_dev/pygccxml/parser/linker.py =================================================================== --- pygccxml_dev/pygccxml/parser/linker.py 2006-08-26 12:14:17 UTC (rev 474) +++ pygccxml_dev/pygccxml/parser/linker.py 2006-08-26 17:26:11 UTC (rev 475) @@ -54,10 +54,9 @@ continue decl = self.__decls[member] if isinstance( self.__inst, class_t ): - self.__inst.get_members( access ).append( decl ) + self.__inst.adopt_declaration( decl, access ) else: - self.__inst.declarations.append( decl ) - decl.parent = self.__inst + self.__inst.adopt_declaration( decl ) def __link_calldef(self): self.__inst.return_type = self.__link_type( self.__inst.return_type ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |