[pygccxml-commit] SF.net SVN: pygccxml: [281] pygccxml_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-07-08 20:28:45
|
Revision: 281 Author: roman_yakovenko Date: 2006-07-08 13:28:29 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=281&view=rev Log Message: ----------- integrating has_public_equal and has_public_less with indexing suite 2. Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/type_traits.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py Added Paths: ----------- pygccxml_dev/unittests/data/has_public_binary_operator_traits.hpp pygccxml_dev/unittests/has_binary_operator_traits_tester.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2006-07-08 18:48:46 UTC (rev 280) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2006-07-08 20:28:29 UTC (rev 281) @@ -147,6 +147,7 @@ from type_traits import remove_declarated from type_traits import has_destructor +from type_traits import has_public_less from type_traits import has_trivial_copy from type_traits import has_public_equal from type_traits import has_public_assign @@ -154,8 +155,8 @@ from type_traits import has_public_constructor from type_traits import has_trivial_constructor from type_traits import find_trivial_constructor +from type_traits import has_public_binary_operator from type_traits import has_any_non_copyconstructor - from type_traits import smart_pointer_traits Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2006-07-08 18:48:46 UTC (rev 280) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2006-07-08 20:28:29 UTC (rev 281) @@ -365,32 +365,40 @@ , type.public_members ) return bool( constructors ) -def has_public_equal( type ): - """returns True if class has public operator==, otherwise False""" +def has_public_binary_operator( type, operator_symbol ): + symbol = operator_symbol not_artificial = lambda decl: decl.is_artificial == False type = remove_alias( type ) type = remove_cv( type ) type = remove_declarated( type ) assert isinstance( type, class_declaration.class_t ) - equals = type.member_operators( function=not_artificial, symbol='==', allow_empty=True, recursive=False ) + equals = type.member_operators( function=not_artificial, symbol=symbol, allow_empty=True, recursive=False ) if equals: return True t = cpptypes.declarated_t( type ) t = cpptypes.const_t( t ) t = cpptypes.reference_t( t ) - equals = type.parent.operators( function=not_artificial, symbol='==', arg_types=[t, None], allow_empty=True, recursive=False ) + equals = type.parent.operators( function=not_artificial, symbol=symbol, arg_types=[t, None], allow_empty=True, recursive=False ) if equals: return True for bi in type.recursive_bases: assert isinstance( bi, class_declaration.hierarchy_info_t ) if bi.access_type != class_declaration.ACCESS_TYPES.PUBLIC: continue - equals = bi.related_class.member_operators( function=not_artificial, symbol='==', allow_empty=True, recursive=False ) + equals = bi.related_class.member_operators( function=not_artificial, symbol=symbol, allow_empty=True, recursive=False ) if equals: return True return False - + +def has_public_equal( type ): + """returns True if class has public operator==, otherwise False""" + return has_public_binary_operator( type, '==' ) + +def has_public_less( type ): + """returns True if class has public operator<, otherwise False""" + return has_public_binary_operator( type, '<' ) + def is_unary_operator( oper ): """returns True if operator is unary operator, otherwise False""" #~ definition: Added: pygccxml_dev/unittests/data/has_public_binary_operator_traits.hpp =================================================================== --- pygccxml_dev/unittests/data/has_public_binary_operator_traits.hpp (rev 0) +++ pygccxml_dev/unittests/data/has_public_binary_operator_traits.hpp 2006-07-08 20:28:29 UTC (rev 281) @@ -0,0 +1,39 @@ +// 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 <string> +#include <vector> + +namespace binary_operator{ +namespace yes{ + typedef std::string yes1; + + inline bool instantiate_templ(){ + return std::string( "1" ) == std::string( "2" ); + } + + struct trivial{ + bool operator==(const trivial& other); + }; + + typedef trivial yes2; + + struct external{ + }; + + bool operator==( const external& left, const external& right ); + + typedef external yes3; +} +namespace no{ + + struct x1{ + private: + bool operator==( const x1& other ); + }; + + typedef x1 no1; +} +} \ No newline at end of file Added: pygccxml_dev/unittests/has_binary_operator_traits_tester.py =================================================================== --- pygccxml_dev/unittests/has_binary_operator_traits_tester.py (rev 0) +++ pygccxml_dev/unittests/has_binary_operator_traits_tester.py 2006-07-08 20:28:29 UTC (rev 281) @@ -0,0 +1,49 @@ +# 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 ): + COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE + global_ns = None + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.header = 'has_public_binary_operator_traits.hpp' + self.global_ns = None + + 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 ) + self.global_ns = tester_t.global_ns + + def test_yes( self ): + yes_ns = self.global_ns.namespace( 'yes' ) + for typedef in yes_ns.typedefs(): + self.failUnless( declarations.has_public_equal( typedef ) + , "Class '%s' should have public operator==" % typedef.decl_string ) + + def test_no( self ): + no_ns = self.global_ns.namespace( 'no' ) + for typedef in no_ns.typedefs(): + self.failUnless( not declarations.has_public_equal( typedef ) + , "Class '%s' should not have public operator==" % typedef.decl_string ) + +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 Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-07-08 18:48:46 UTC (rev 280) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-07-08 20:28:29 UTC (rev 281) @@ -49,7 +49,6 @@ indexing_suite = property( _get_indexing_suite ) def _get_equality_comparable( self ): - return False if None is self._equality_comparable: self._equality_comparable = declarations.has_public_equal( self ) return self._equality_comparable @@ -60,7 +59,6 @@ equality_comparable = property( _get_equality_comparable, _set_equality_comparable ) def _get_less_than_comparable( self ): - return False if None is self._less_than_comparable: self._less_than_comparable = declarations.has_public_less( self ) return self._less_than_comparable This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |