[pygccxml-commit] SF.net SVN: pygccxml:[1383] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-08-06 13:00:18
|
Revision: 1383 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1383&view=rev Author: roman_yakovenko Date: 2008-08-06 13:00:27 +0000 (Wed, 06 Aug 2008) Log Message: ----------- implement better algorithm for searching template instantiatd classes Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/matchers.py pygccxml_dev/pygccxml/declarations/pattern_parser.py pygccxml_dev/pygccxml/declarations/scopedef.py pygccxml_dev/pygccxml/declarations/templates.py pygccxml_dev/unittests/test_all.py Added Paths: ----------- pygccxml_dev/unittests/better_templates_matcher_tester.py pygccxml_dev/unittests/data/better_templates_matcher_tester.hpp Modified: pygccxml_dev/pygccxml/declarations/matchers.py =================================================================== --- pygccxml_dev/pygccxml/declarations/matchers.py 2008-08-05 15:40:28 UTC (rev 1382) +++ pygccxml_dev/pygccxml/declarations/matchers.py 2008-08-06 13:00:27 UTC (rev 1383) @@ -177,6 +177,7 @@ else: self.__opt_is_full_name = False self.__decl_name_only = self.__opt_tmpl_name + self.__name = templates.normalize( name ) else: if '::' in self.__name: self.__opt_is_full_name = True @@ -225,11 +226,12 @@ assert not None is self.name if self.__opt_is_tmpl_inst: if not self.__opt_is_full_name: - if self.name != decl.name and self.name != decl.partial_name: + if self.name != templates.normalize( decl.name ) \ + and self.name != templates.normalize( decl.partial_name ): return False - else: - if self.name != algorithm.full_name( decl, with_defaults=True ) \ - and self.name != algorithm.full_name( decl, with_defaults=False ): + else: + if self.name != templates.normalize( algorithm.full_name( decl, with_defaults=True ) ) \ + and self.name != templates.normalize( algorithm.full_name( decl, with_defaults=False ) ): return False else: if not self.__opt_is_full_name: Modified: pygccxml_dev/pygccxml/declarations/pattern_parser.py =================================================================== --- pygccxml_dev/pygccxml/declarations/pattern_parser.py 2008-08-05 15:40:28 UTC (rev 1382) +++ pygccxml_dev/pygccxml/declarations/pattern_parser.py 2008-08-06 13:00:27 UTC (rev 1383) @@ -24,7 +24,7 @@ def has_pattern( self, decl_string ): """implementation details""" last_part = decl_string.split( '::' )[-1] - return -1 != last_part.find( self.__end ) + return -1 != decl_string.find( self.__begin ) and -1 != last_part.find( self.__end ) def name( self, decl_string ): """implementation details""" @@ -127,3 +127,14 @@ return ''.join( [ name, self.__begin, args_str, self.__end ] ) + def normalize( self, decl_string, arg_separator=None ): + """implementation details""" + if not self.has_pattern( decl_string ): + return decl_string + name, args = self.split( decl_string ) + for i, arg in enumerate( args ): + args[i] = self.normalize( arg ) + return self.join( name, args, arg_separator ) + + + Modified: pygccxml_dev/pygccxml/declarations/scopedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/scopedef.py 2008-08-05 15:40:28 UTC (rev 1382) +++ pygccxml_dev/pygccxml/declarations/scopedef.py 2008-08-06 13:00:27 UTC (rev 1383) @@ -10,6 +10,7 @@ import time import algorithm import filtering +import templates import declaration import mdecl_wrapper from pygccxml import utils @@ -301,8 +302,15 @@ decls = self.declarations if recursive: decls = algorithm.make_flatten( self.declarations ) + if decl_type: + decls = filter( lambda d: isinstance( d, decl_type ), decls ) return decls + if name and templates.is_instantiation( name ): + #templates has tricky mode to compare them, so lets check the whole + #range + name = None + if name and decl_type: matcher = scopedef_t._impl_matchers[ scopedef_t.decl ]( name=name ) if matcher.is_full_name(): Modified: pygccxml_dev/pygccxml/declarations/templates.py =================================================================== --- pygccxml_dev/pygccxml/declarations/templates.py 2008-08-05 15:40:28 UTC (rev 1382) +++ pygccxml_dev/pygccxml/declarations/templates.py 2008-08-06 13:00:27 UTC (rev 1383) @@ -64,4 +64,13 @@ def join( name, args ): """returns name< argument_1, argument_2, ..., argument_n >""" global __THE_PARSER - return __THE_PARSER.join( name, args ) \ No newline at end of file + return __THE_PARSER.join( name, args ) + +def normalize( decl_string ): + """returns decl_string, which contains "normalized" spaces + + this functionality allows to implement comparison of 2 different string + which are actually same: x::y< z > and x::y<z> + """ + global __THE_PARSER + return __THE_PARSER.normalize( decl_string ) Added: pygccxml_dev/unittests/better_templates_matcher_tester.py =================================================================== --- pygccxml_dev/unittests/better_templates_matcher_tester.py (rev 0) +++ pygccxml_dev/unittests/better_templates_matcher_tester.py 2008-08-06 13:00:27 UTC (rev 1383) @@ -0,0 +1,44 @@ +# 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) + +import unittest +import autoconfig +import parser_test_case + +from pygccxml import utils +from pygccxml import parser +from pygccxml import declarations + +class tester_t( parser_test_case.parser_test_case_t ): + + global_ns = None + + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.header = 'better_templates_matcher_tester.hpp' + + def setUp(self): + if not tester_t.global_ns: + decls = parser.parse( [self.header], self.config ) + tester_t.global_ns = declarations.get_global_namespace( decls ) + tester_t.global_ns.init_optimizer() + + def test( self ): + classes = [ '::std::vector<Ogre::PlaneBoundedVolume,std::allocator<Ogre::PlaneBoundedVolume>>' + , '::std::vector<Ogre::Plane, std::allocator<Ogre::Plane>>' + , '::Ogre::Singleton< Ogre::PCZoneFactoryManager>' ] + for i in classes: + c = self.global_ns.class_( i ) + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(tester_t)) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() \ No newline at end of file Added: pygccxml_dev/unittests/data/better_templates_matcher_tester.hpp =================================================================== --- pygccxml_dev/unittests/data/better_templates_matcher_tester.hpp (rev 0) +++ pygccxml_dev/unittests/data/better_templates_matcher_tester.hpp 2008-08-06 13:00:27 UTC (rev 1383) @@ -0,0 +1,31 @@ +// 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) + +#include <vector> +#include <map> + +namespace Ogre{ + struct PlaneBoundedVolume{}; + + struct Plane{}; + + std::vector<PlaneBoundedVolume> do_smth(){ + return std::vector<PlaneBoundedVolume>(); + } + + std::vector<Plane> do_smth2(){ + return std::vector<Plane>(); + } + + template< class X > + struct Singleton{ + }; + + struct PCZoneFactoryManager{}; + + Singleton<PCZoneFactoryManager> do_smth3(){ + return Singleton<PCZoneFactoryManager>(); + } +} Modified: pygccxml_dev/unittests/test_all.py =================================================================== --- pygccxml_dev/unittests/test_all.py 2008-08-05 15:40:28 UTC (rev 1382) +++ pygccxml_dev/unittests/test_all.py 2008-08-06 13:00:27 UTC (rev 1383) @@ -50,6 +50,7 @@ import copy_constructor_tester import plain_c_tester import function_traits_tester +import better_templates_matcher_tester testers = [ decl_string_tester @@ -96,6 +97,7 @@ , copy_constructor_tester , plain_c_tester , function_traits_tester + , better_templates_matcher_tester ] def create_suite(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |