[pygccxml-commit] SF.net SVN: pygccxml: [478] pygccxml_dev/unittests/data
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-08-27 18:49:43
|
Revision: 478 Author: roman_yakovenko Date: 2006-08-27 11:49:18 -0700 (Sun, 27 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=478&view=rev Log Message: ----------- adding type_alg_cache_t class and remove_aliase optimization Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/algorithms_cache.py pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/cpptypes.py pygccxml_dev/pygccxml/declarations/namespace.py pygccxml_dev/pygccxml/declarations/type_traits.py pygccxml_dev/pygccxml/parser/project_reader.py pygccxml_dev/pygccxml/parser/source_reader.py pygccxml_dev/unittests/data/typedefs1.hpp pygccxml_dev/unittests/data/typedefs2.hpp pygccxml_dev/unittests/data/typedefs_base.hpp Modified: pygccxml_dev/pygccxml/declarations/algorithms_cache.py =================================================================== --- pygccxml_dev/pygccxml/declarations/algorithms_cache.py 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/pygccxml/declarations/algorithms_cache.py 2006-08-27 18:49:18 UTC (rev 478) @@ -7,10 +7,15 @@ defines class that will keep results of different calculations. """ -class algorithms_cache_t( object ): + +class declaration_algs_cache_t( object ): def __init__( self ): object.__init__( self ) self._enabled = True + self._full_name = None + self._access_type = None + self._demangled_name = None + self._declaration_path = None def disable( self ): self._enabled = False @@ -22,44 +27,44 @@ def enabled( self ): return self._enabled -class declaration_algs_cache_t( algorithms_cache_t ): - def __init__( self ): - algorithms_cache_t.__init__( self ) - self._full_name = None - self._access_type = None - self._demangled_name = None - self._declaration_path = None + def _get_full_name( self ): + return self._full_name - def _get_full_name( self ): - if self.enabled: - return self._full_name - return None def _set_full_name( self, fname ): + if not self.enabled: + fname = None self._full_name = fname + full_name = property( _get_full_name, _set_full_name ) def _get_access_type( self ): - if self.enabled: - return self._access_type - return None + return self._access_type + def _set_access_type( self, access_type ): + 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 ): - if self.enabled: - return self._demangled_name - return None + return self._demangled_name + def _set_demangled_name( self, demangled_name ): + if not self.enabled: + demangled_name = None self._demangled_name = demangled_name + demangled_name = property( _get_demangled_name, _set_demangled_name ) def _get_declaration_path( self ): - if self.enabled: - return self._declaration_path - return None + return self._declaration_path + def _set_declaration_path( self, declaration_path ): + if not self.enabled: + declaration_path = None self._declaration_path = declaration_path + declaration_path = property( _get_declaration_path, _set_declaration_path ) def reset( self ): @@ -76,17 +81,31 @@ def reset_access_type( self ): self.access_type = None -#Introducing next cache to the type broke unit test. I should find out why. -#~ class type_algs_cache_t( algorithms_cache_t ): - #~ def __init__( self ): - #~ algorithms_cache_t.__init__( self ) - #~ self._remove_alias = None +class type_algs_cache_t( object ): + enabled = True + + @staticmethod + def disable(): + type_algs_cache_t.enabled = False - #~ def _get_remove_alias( self ): - #~ if self.enabled: - #~ return self._remove_alias - #~ return None - #~ def _set_remove_alias( self, remove_alias ): - #~ self._remove_alias = remove_alias - #~ remove_alias = property( _get_remove_alias, _set_remove_alias ) + @staticmethod + def enable( self ): + type_algs_cache_t.enabled = True + def __init__( self ): + object.__init__( self ) + self._remove_alias = None + + def _get_remove_alias( self ): + return self._remove_alias + + def _set_remove_alias( self, remove_alias ): + if not type_algs_cache_t.enabled: + remove_alias = None + self._remove_alias = remove_alias + + remove_alias = property( _get_remove_alias, _set_remove_alias ) + + def reset(self): + self.remove_alias = None + \ No newline at end of file Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-27 18:49:18 UTC (rev 478) @@ -284,6 +284,7 @@ else: raise RuntimeError( "Invalid access type: %s." % access ) decl.parent = self + decl.cache.reset() decl.cache.access_type = access def remove_declaration( self, decl ): @@ -302,7 +303,7 @@ else: #decl.cache.access_type == ACCESS_TYPES.PRVATE container = self.private_members del container[ container.index( decl ) ] - decl.cache.reset_access_type() + decl.cache.reset() def find_out_member_access_type( self, member ): """ Modified: pygccxml_dev/pygccxml/declarations/cpptypes.py =================================================================== --- pygccxml_dev/pygccxml/declarations/cpptypes.py 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/pygccxml/declarations/cpptypes.py 2006-08-27 18:49:18 UTC (rev 478) @@ -7,11 +7,14 @@ defines classes, that describe C++ types """ +import algorithms_cache + class type_t(object): """base class for all types""" def __init__(self): object.__init__( self ) - + self.cache = algorithms_cache.type_algs_cache_t() + def __str__(self): res = self.decl_string if res[:2]=="::": @@ -44,7 +47,6 @@ def clone( self ): "returns new instance of the type" answer = self._clone_impl() - assert answer return answer #There are cases when GCC-XML reports something like this @@ -578,7 +580,7 @@ return self._declaration.decl_string def _clone_impl( self ): - return declarated_t( self.declaration ) + return declarated_t( self._declaration ) class type_qualifiers_t( object ): """contains additional information about type: mutable, static, extern""" Modified: pygccxml_dev/pygccxml/declarations/namespace.py =================================================================== --- pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-27 18:49:18 UTC (rev 478) @@ -51,6 +51,7 @@ def adopt_declaration( self, decl ): self.declarations.append( decl ) decl.parent = self + decl.cache.reset() def remove_declaration( self, decl ): """ @@ -60,6 +61,7 @@ @type decl: L{declaration_t} """ del self.declarations[ self.declarations.index( decl ) ] + decl.cache.reset() #add more comment about this. #if not keep_parent: # decl.parent=None Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2006-08-27 18:49:18 UTC (rev 478) @@ -41,12 +41,20 @@ def remove_alias(type_): """returns type without typedefs""" + type_ref = None if isinstance( type_, cpptypes.type_t ): - return __remove_alias( type_.clone() ) + type_ref = type_ elif isinstance( type_, typedef.typedef_t ): - return __remove_alias( type_.type.clone() ) + type_ref = type_.type else: + pass #not a valid input, just return it + if not type_ref: return type_ + if type_ref.cache.remove_alias: + return type_ref.cache.remove_alias + no_alias = __remove_alias( type_ref.clone() ) + type_ref.cache.remove_alias = no_alias + return no_alias def create_cv_types( base ): """implementation details""" Modified: pygccxml_dev/pygccxml/parser/project_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/project_reader.py 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/pygccxml/parser/project_reader.py 2006-08-27 18:49:18 UTC (rev 478) @@ -425,6 +425,9 @@ create_key = lambda decl:( decl.location.as_tuple() , tuple( pygccxml.declarations.declaration_path( decl ) ) ) for decl_wrapper_type in declarated_types: + #it is possible, that cache contains reference to dropped class + #We need to clear it + decl_wrapper_type.cache.reset() if isinstance( decl_wrapper_type.declaration, pygccxml.declarations.class_t ): key = create_key(decl_wrapper_type.declaration) if leaved_classes.has_key( key ): Modified: pygccxml_dev/pygccxml/parser/source_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/source_reader.py 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/pygccxml/parser/source_reader.py 2006-08-27 18:49:18 UTC (rev 478) @@ -29,9 +29,8 @@ @return: None """ visited = set() - for decl in decls: - if not isinstance( decl, typedef_t ): - continue + typedefs = filter( lambda decl: isinstance( decl, typedef_t ), decls ) + for decl in typedefs: type_ = remove_alias( decl.type ) if not isinstance( type_, declarated_t ): continue Modified: pygccxml_dev/unittests/data/typedefs1.hpp =================================================================== --- pygccxml_dev/unittests/data/typedefs1.hpp 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/unittests/data/typedefs1.hpp 2006-08-27 18:49:18 UTC (rev 478) @@ -1,17 +1,17 @@ -// 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) - -#ifndef __typedefs1_hpp__ -#define __typedefs1_hpp__ - -#include "typedefs_base.hpp" - -namespace typedefs{ - -typedef item_t Item1; - -} - +// 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) + +#ifndef __typedefs1_hpp__ +#define __typedefs1_hpp__ + +#include "typedefs_base.hpp" + +namespace typedefs{ + +typedef item_t Item1; + +} + #endif//__typedefs1_hpp__ \ No newline at end of file Modified: pygccxml_dev/unittests/data/typedefs2.hpp =================================================================== --- pygccxml_dev/unittests/data/typedefs2.hpp 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/unittests/data/typedefs2.hpp 2006-08-27 18:49:18 UTC (rev 478) @@ -1,17 +1,17 @@ -// 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) - -#ifndef __typedefs2_hpp__ -#define __typedefs2_hpp__ - -#include "typedefs_base.hpp" - -namespace typedefs{ - -typedef item_t Item2; - -} - +// 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) + +#ifndef __typedefs2_hpp__ +#define __typedefs2_hpp__ + +#include "typedefs_base.hpp" + +namespace typedefs{ + +typedef item_t Item2; + +} + #endif//__typedefs2_hpp__ \ No newline at end of file Modified: pygccxml_dev/unittests/data/typedefs_base.hpp =================================================================== --- pygccxml_dev/unittests/data/typedefs_base.hpp 2006-08-27 06:52:22 UTC (rev 477) +++ pygccxml_dev/unittests/data/typedefs_base.hpp 2006-08-27 18:49:18 UTC (rev 478) @@ -1,18 +1,17 @@ -// 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) - -#ifndef __typedefs_hpp__ -#define __typedefs_hpp__ - -namespace typedefs{ - -struct item_t{}; - -typedef item_t Item; - -} - -#endif//__typedefs_hpp__ - +// 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) + +#ifndef __typedefs_hpp__ +#define __typedefs_hpp__ + +namespace typedefs{ + +struct item_t{}; + +typedef item_t Item; + +} + +#endif//__typedefs_hpp__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |