[pygccxml-commit] SF.net SVN: pygccxml: [907] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-02-16 10:01:38
|
Revision: 907 http://svn.sourceforge.net/pygccxml/?rev=907&view=rev Author: roman_yakovenko Date: 2007-02-16 02:01:39 -0800 (Fri, 16 Feb 2007) Log Message: ----------- fixing bug in is_convertible functionality: there is no implicit conversion between integral types and void* Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/type_traits.py pygccxml_dev/unittests/data/type_traits.hpp pygccxml_dev/unittests/type_traits_tester.py Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2007-02-16 09:36:27 UTC (rev 906) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2007-02-16 10:01:39 UTC (rev 907) @@ -555,7 +555,10 @@ if is_reference( target ) and is_const( target.base ) and is_same( source, target.base.base ): return True #X => const X& if is_same( target, cpptypes.pointer_t( cpptypes.void_t() ) ): - return True #X => void* + if is_integral( source ) or is_enum( source ): + return False + else: + return True #X => void* if is_pointer( source ) and is_pointer( target ): if is_const( target.base ) and is_same( source.base, target.base.base ): return True#X* => const X* @@ -763,31 +766,31 @@ and not is_void( target ): return True # enum could be converted to any integral type - assert isinstance( source.declaration, class_declaration.class_t ) - source_inst = source.declaration - #class instance could be convertible to something else if it has operator - casting_operators = algorithm.find_all_declarations( source_inst.declarations - , type=calldef.casting_operator_t - , recursive=False ) - if casting_operators: - for operator in casting_operators: - if is_convertible( operator.return_type, target ): - return True + if isinstance( source.declaration, class_declaration.class_t ): + source_inst = source.declaration + #class instance could be convertible to something else if it has operator + casting_operators = algorithm.find_all_declarations( source_inst.declarations + , type=calldef.casting_operator_t + , recursive=False ) + if casting_operators: + for operator in casting_operators: + if is_convertible( operator.return_type, target ): + return True #may be target is class too, so in this case we should check whether is #has constructor from source if isinstance( target, cpptypes.declarated_t ): - assert isinstance( target.declaration, class_declaration.class_t ) - constructors = algorithm.find_all_declarations( target.declaration.declarations - , type=calldef.constructor_t - , recursive=False ) - if constructors: - for constructor in constructors: - if 1 != len( constructor.arguments ): - continue - #TODO: add test to check explicitness - if is_convertible( source, constructor.arguments[0].type ): - return True + if isinstance( target.declaration, class_declaration.class_t ): + constructors = algorithm.find_all_declarations( target.declaration.declarations + , type=calldef.constructor_t + , recursive=False ) + if constructors: + for constructor in constructors: + if 1 != len( constructor.arguments ): + continue + #TODO: add test to check explicitness + if is_convertible( source, constructor.arguments[0].type ): + return True return False Modified: pygccxml_dev/unittests/data/type_traits.hpp =================================================================== --- pygccxml_dev/unittests/data/type_traits.hpp 2007-02-16 09:36:27 UTC (rev 906) +++ pygccxml_dev/unittests/data/type_traits.hpp 2007-02-16 10:01:39 UTC (rev 907) @@ -592,8 +592,8 @@ struct x70 : public tester_t< float, int&, false >{}; struct x71 : public tester_t< float, const int&, true >{}; struct x72 : public tester_t< other, void*, true >{}; -struct x73 : public tester_t< int, void*, true >{}; -struct x74 : public tester_t< fruit, void*, true >{}; +struct x73 : public tester_t< int, void*, false >{}; +struct x74 : public tester_t< fruit, void*, false >{}; struct x75 : public tester_t< other, int*, false >{}; struct x76 : public tester_t< other*, int*, false >{}; struct x77 : public tester_t< fruit, int, true >{}; Modified: pygccxml_dev/unittests/type_traits_tester.py =================================================================== --- pygccxml_dev/unittests/type_traits_tester.py 2007-02-16 09:36:27 UTC (rev 906) +++ pygccxml_dev/unittests/type_traits_tester.py 2007-02-16 10:01:39 UTC (rev 907) @@ -203,8 +203,6 @@ self.failUnless( declarations.is_binary_operator( operator_pe ), 'operator+= should be idenitified as binray operator' ) def __is_convertible_impl( self, decl ): - if decl.name == 'x81': - i = 0 defs = decl.bases[0].related_class.declarations source_type = declarations.find_declaration( defs, name='source_type' ) target_type = declarations.find_declaration( defs, name='target_type' ) @@ -212,8 +210,8 @@ , name='expected' , type=declarations.enumeration_t ) expected_value = bool( expected_type.get_name2value_dict()['value'] ) - if expected_value != declarations.is_convertible( source_type, target_type ): - print decl.name + self.failUnless( expected_value == declarations.is_convertible( source_type, target_type ) + , 'Check conversion failed for ' + decl.name ) def test_is_convertible( self ): ns_is_convertible = declarations.find_declaration( self.declarations This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |