[pygccxml-commit] SF.net SVN: pygccxml: [1318] pyplusplus_dev/unittests/data
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-05-08 20:05:42
|
Revision: 1318 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1318&view=rev Author: roman_yakovenko Date: 2008-05-08 13:05:35 -0700 (Thu, 08 May 2008) Log Message: ----------- fixing covariant returns bug Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/function_traits.py pygccxml_dev/unittests/data/core_cache.hpp pygccxml_dev/unittests/test_all.py pyplusplus_dev/unittests/test_all.py Added Paths: ----------- pygccxml_dev/unittests/data/covariant_returns.hpp pygccxml_dev/unittests/function_traits_tester.py pyplusplus_dev/unittests/bug_covariant_returns_tester.py pyplusplus_dev/unittests/data/bug_covariant_returns_to_be_exported.hpp Modified: pygccxml_dev/pygccxml/declarations/function_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/function_traits.py 2008-05-04 20:45:00 UTC (rev 1317) +++ pygccxml_dev/pygccxml/declarations/function_traits.py 2008-05-08 20:05:35 UTC (rev 1318) @@ -9,7 +9,59 @@ import calldef import type_traits +import class_declaration +def is_same_return_type( f1, f2 ): + #covariant returns + #The return type of an overriding function shall be either identical to the + #return type of the overridden function or covariant with the classes of the + #functions. If a function D::f overrides a function B::f, the return types + #of the functions are covariant if they satisfy the following criteria: + + #* both are pointers to classes or references to classes + #* the class in the return type of B::f is the same class as the class in + # the return type of D::f or, is an unambiguous direct or indirect base + # class of the class in the return type of D::f and is accessible in D + #* both pointers or references have the same cv-qualification and the class + # type in the return type of D::f has the same cv-qualification as or less + # cv-qualification than the class type in the return type of B::f. + + if not f1.__class__ is f2.__class__: + return False #2 different calldef types + if not isinstance( f1, calldef.member_calldef_t ): + #for free functions we compare return types as usual + return type_traits.is_same( f1.return_type, f2.return_type) + if f1.virtuality == calldef.VIRTUALITY_TYPES.NOT_VIRTUAL \ + or f2.virtuality == calldef.VIRTUALITY_TYPES.NOT_VIRTUAL: + #for non-virtual member functions we compare types as usual + return type_traits.is_same( f1.return_type, f2.return_type) + rt1 = f1.return_type + rt2 = f2.return_type + if type_traits.is_pointer( rt1 ) and type_traits.is_pointer( rt2 ): + rt1 = type_traits.remove_pointer( rt1 ) + rt2 = type_traits.remove_pointer( rt2 ) + elif type_traits.is_reference( rt1 ) and type_traits.is_reference( rt2 ): + rt1 = type_traits.remove_reference( rt1 ) + rt2 = type_traits.remove_reference( rt2 ) + else: + return type_traits.is_same( f1.return_type, f2.return_type) + if ( type_traits.is_const( rt1 ) and type_traits.is_const( rt2 ) ) \ + or ( False == type_traits.is_const( rt1 ) and False == type_traits.is_const( rt2 ) ): + rt1 = type_traits.remove_const( rt1 ) + rt2 = type_traits.remove_const( rt2 ) + else: + return False + if not type_traits.is_class( rt1 ) or not type_traits.is_class( rt2 ): + return type_traits.is_same( rt1, rt2 ) + c1 = type_traits.class_traits.get_declaration( rt1 ) + c2 = type_traits.class_traits.get_declaration( rt2 ) + if c1.class_type == class_declaration.CLASS_TYPES.UNION \ + or c2.class_type == class_declaration.CLASS_TYPES.UNION: + return type_traits.is_same( rt1, rt2 ) + return type_traits.is_base_and_derived( c1, c2 ) \ + or type_traits.is_base_and_derived( c2, c1 ) + + def is_same_function( f1, f2 ): """returns true if f1 and f2 is same function @@ -25,7 +77,7 @@ return False if f1.name != f2.name: return False - if not type_traits.is_same( f1.return_type, f2.return_type): + if not is_same_return_type( f1, f2 ): return False if len( f1.arguments ) != len(f2.arguments): return False Modified: pygccxml_dev/unittests/data/core_cache.hpp =================================================================== --- pygccxml_dev/unittests/data/core_cache.hpp 2008-05-04 20:45:00 UTC (rev 1317) +++ pygccxml_dev/unittests/data/core_cache.hpp 2008-05-08 20:05:35 UTC (rev 1318) @@ -22,4 +22,4 @@ #endif//__core_cache_hpp__ -//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch \ No newline at end of file +//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch \ No newline at end of file Added: pygccxml_dev/unittests/data/covariant_returns.hpp =================================================================== --- pygccxml_dev/unittests/data/covariant_returns.hpp (rev 0) +++ pygccxml_dev/unittests/data/covariant_returns.hpp 2008-05-08 20:05:35 UTC (rev 1318) @@ -0,0 +1,36 @@ +// 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 __bug_virtual_functions_overload_to_be_exported_hpp__ +#define __bug_virtual_functions_overload_to_be_exported_hpp__ + +struct data_t { + int i; +}; + +struct more_data_t : public data_t{ +}; + +struct algorithm_t{ + algorithm_t(){}; + virtual data_t* f(){ + data_t* d = new data_t(); + d->i = 0; + return d; + } +}; + +class better_algorithm_t : public algorithm_t{ +public: + better_algorithm_t(){}; + virtual more_data_t* f(){ + more_data_t* d = new more_data_t(); + d->i = 1; + return d; + } + +}; + +#endif//__bug_virtual_functions_overload_to_be_exported_hpp__ Added: pygccxml_dev/unittests/function_traits_tester.py =================================================================== --- pygccxml_dev/unittests/function_traits_tester.py (rev 0) +++ pygccxml_dev/unittests/function_traits_tester.py 2008-05-08 20:05:35 UTC (rev 1318) @@ -0,0 +1,46 @@ +# 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 = 'covariant_returns.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_is_same_function( self ): + d = self.global_ns.class_( 'better_algorithm_t' ) + b = self.global_ns.class_( 'algorithm_t' ) + + df = d.mem_fun( 'f' ) + bf = b.mem_fun( 'f' ) + + self.failUnless( id(df) != id(bf) and declarations.is_same_function( df, bf ) ) + +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() Modified: pygccxml_dev/unittests/test_all.py =================================================================== --- pygccxml_dev/unittests/test_all.py 2008-05-04 20:45:00 UTC (rev 1317) +++ pygccxml_dev/unittests/test_all.py 2008-05-08 20:05:35 UTC (rev 1318) @@ -49,6 +49,7 @@ import type_as_exception_bug_tester import copy_constructor_tester import plain_c_tester +import function_traits_tester testers = [ decl_string_tester @@ -94,6 +95,7 @@ , type_as_exception_bug_tester , copy_constructor_tester , plain_c_tester + , function_traits_tester ] def create_suite(): Added: pyplusplus_dev/unittests/bug_covariant_returns_tester.py =================================================================== --- pyplusplus_dev/unittests/bug_covariant_returns_tester.py (rev 0) +++ pyplusplus_dev/unittests/bug_covariant_returns_tester.py 2008-05-08 20:05:35 UTC (rev 1318) @@ -0,0 +1,37 @@ +# 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 os +import sys +import unittest +import fundamental_tester_base +from pyplusplus import code_creators +from pyplusplus.module_builder.call_policies import * + +class tester_t(fundamental_tester_base.fundamental_tester_base_t): + EXTENSION_NAME = 'bug_covariant_returns' + + def __init__( self, *args ): + fundamental_tester_base.fundamental_tester_base_t.__init__( + self + , tester_t.EXTENSION_NAME + , *args ) + + def customize(self, mb ): + mb.mem_funs( 'f' ).call_policies = return_value_policy(manage_new_object) + + def run_tests( self, module): + pass + +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() Added: pyplusplus_dev/unittests/data/bug_covariant_returns_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/bug_covariant_returns_to_be_exported.hpp (rev 0) +++ pyplusplus_dev/unittests/data/bug_covariant_returns_to_be_exported.hpp 2008-05-08 20:05:35 UTC (rev 1318) @@ -0,0 +1,36 @@ +// 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 __bug_virtual_functions_overload_to_be_exported_hpp__ +#define __bug_virtual_functions_overload_to_be_exported_hpp__ + +struct data_t { + int i; +}; + +struct more_data_t : public data_t{ +}; + +struct algorithm_t{ + algorithm_t(){}; + virtual data_t* f(){ + data_t* d = new data_t(); + d->i = 0; + return d; + } +}; + +class better_algorithm_t : public algorithm_t{ +public: + better_algorithm_t(){}; + virtual more_data_t* f(){ + more_data_t* d = new more_data_t(); + d->i = 1; + return d; + } + +}; + +#endif//__bug_virtual_functions_overload_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/test_all.py =================================================================== --- pyplusplus_dev/unittests/test_all.py 2008-05-04 20:45:00 UTC (rev 1317) +++ pyplusplus_dev/unittests/test_all.py 2008-05-08 20:05:35 UTC (rev 1318) @@ -103,6 +103,7 @@ import ft_inout_tester import split_module_indexing_suite_bug_tester import inner_tmpl_class_tester +import bug_covariant_returns_tester testers = [ algorithms_tester @@ -193,6 +194,7 @@ , override_bug_tester , split_module_indexing_suite_bug_tester , inner_tmpl_class_tester + , bug_covariant_returns_tester ] class module_runner_t( object ): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |