[pygccxml-commit] SF.net SVN: pygccxml: [1148] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-11-13 20:57:24
|
Revision: 1148 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1148&view=rev Author: roman_yakovenko Date: 2007-11-13 12:57:25 -0800 (Tue, 13 Nov 2007) Log Message: ----------- fixing noncopyable bug Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/type_traits.py pygccxml_dev/unittests/data/type_traits.hpp Added Paths: ----------- pygccxml_dev/unittests/data/noncopyable.hpp Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2007-11-13 07:24:34 UTC (rev 1147) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2007-11-13 20:57:25 UTC (rev 1148) @@ -393,4 +393,18 @@ self._container_traits = container_traits.find_container_traits( self ) return self._container_traits + def find_copy_constructor( self ): + copy_ = self.constructors( lambda x: x.is_copy_constructor, recursive=False, allow_empty=True ) + if copy_: + return copy_[0] + else: + return None + + def find_trivial_constructor( self ): + trivial = self.constructors( lambda x: x.is_trivial_constructor, recursive=False, allow_empty=True ) + if trivial: + return trivial[0] + else: + return None + class_types = ( class_t, class_declaration_t ) Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2007-11-13 07:24:34 UTC (rev 1147) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2007-11-13 20:57:25 UTC (rev 1148) @@ -402,11 +402,9 @@ """returns True, if class has public copy constructor, False otherwise""" assert isinstance( type, class_declaration.class_t ) if '0.9' in type.compiler: - copy_ = type.constructors( lambda x: x.is_copy_constructor - , recursive=False - , allow_empty=True ) + copy_ = type.find_copy_constructor() if copy_: - if copy_[0].access_type == 'public': + if copy_.access_type == 'public': return True else: return False @@ -900,8 +898,18 @@ if class_.class_type == class_declaration.CLASS_TYPES.UNION: return False + + if class_.is_abstract: + return True + + #if class has public, user defined copy constructor, than this class is + #copyable + copy_ = class_.find_copy_constructor() + if copy_ and copy_.access_type == 'public' and not copy_.is_artificial: + return False + for base_desc in class_.recursive_bases: - assert isinstance( base_desc, class_declaration.hierarchy_info_t ) + assert isinstance( base_desc, class_declaration.hierarchy_info_t ) if base_desc.related_class.decl_string in ('::boost::noncopyable', '::boost::noncopyable_::noncopyable' ): return True if not has_trivial_copy( base_desc.related_class ): @@ -910,28 +918,11 @@ , base_desc.related_class.protected_members ) if not protected_ctrs: return True - if __is_noncopyable_single( base_desc.related_class ): return True - - if class_.is_abstract: + + if not has_trivial_copy( class_ ): return True - #~ if '0.9' in class_.compiler: - #~ #class will be mark as noncopyable if it has private operator assign and - #~ #copy constructor - #~ #select all non-public members that are copy constructor and operator assign - #~ is_noncopyable_query = \ - #~ matchers.not_matcher_t( matchers.access_type_matcher_t( 'public' ) )\ - #~ & \ - #~ ( matchers.custom_matcher_t( lambda decl: isinstance( decl, calldef.constructor_t ) \ - #~ and decl.is_copy_constructor ) - #~ | matchers.operator_matcher_t( symbol='=' ) ) - #~ result = class_.decls( is_noncopyable_query, recursive=False, allow_empty=True ) - #~ if result: - #~ return True - #~ else: - elif not has_trivial_copy( class_ ): - return True elif not has_public_constructor( class_ ): return True elif has_destructor( class_ ) and not has_public_destructor( class_ ): @@ -939,7 +930,6 @@ else: return __is_noncopyable_single( class_ ) - def is_defined_in_xxx( xxx, cls ): """small helper function, that checks whether class ( C{cls} ) is defined under C{::xxx} namespace""" Added: pygccxml_dev/unittests/data/noncopyable.hpp =================================================================== --- pygccxml_dev/unittests/data/noncopyable.hpp (rev 0) +++ pygccxml_dev/unittests/data/noncopyable.hpp 2007-11-13 20:57:25 UTC (rev 1148) @@ -0,0 +1,36 @@ +// Boost noncopyable.hpp header file --------------------------------------// + +// (C) Copyright Beman Dawes 1999-2003. 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) + +// See http://www.boost.org/libs/utility for documentation. + +#ifndef BOOST_NONCOPYABLE_HPP_INCLUDED +#define BOOST_NONCOPYABLE_HPP_INCLUDED + +namespace boost { + +// Private copy constructor and copy assignment ensure classes derived from +// class noncopyable cannot be copied. + +// Contributed by Dave Abrahams + +namespace noncopyable_ // protection from unintended ADL +{ + class noncopyable + { + protected: + noncopyable() {} + ~noncopyable() {} + private: // emphasize the following members are private + noncopyable( const noncopyable& ); + const noncopyable& operator=( const noncopyable& ); + }; +} + +typedef noncopyable_::noncopyable noncopyable; + +} // namespace boost + +#endif // BOOST_NONCOPYABLE_HPP_INCLUDED Modified: pygccxml_dev/unittests/data/type_traits.hpp =================================================================== --- pygccxml_dev/unittests/data/type_traits.hpp 2007-11-13 07:24:34 UTC (rev 1147) +++ pygccxml_dev/unittests/data/type_traits.hpp 2007-11-13 20:57:25 UTC (rev 1148) @@ -9,6 +9,8 @@ #include <string> #include <iostream> +#include <vector> +#include "noncopyable.hpp" #define TYPE_PERMUTATION( BASE, NAME ) \ typedef BASE NAME##_t; \ @@ -76,14 +78,93 @@ static const y_type zero; }; + + struct instantiate_vector{ + instantiate_vector() + : v() + {} + + std::vector< int > v; + }; + + + class a_t{ + public: + + static char get_a(){ return 'a'; } + + private: + a_t(){}; + ~a_t(){}; + }; + + class b_t{ + ~b_t(){} + public: + + static char get_b(){ return 'b'; } + + }; + + class c_t : public boost::noncopyable{ + public: + static char get_c(){ return 'c'; } + + }; + + class d_t{ + private: + d_t( const d_t& ); + public: + d_t(){} + ~d_t(){} + static char get_d(){ return 'd'; } + + }; + + class dd_t : public d_t{ + public: + dd_t(){} + ~dd_t(){} + static char get_dd(){ return 'D'; } + }; + + struct e_t{ + virtual void do_smth() = 0; + private: + c_t c; + }; + + struct f_t{ + f_t() : i(0){} + virtual void do_smth() = 0; + private: + const int i; + }; + + struct g_t{ + enum E{e}; + g_t() : e_(e){} + virtual void do_smth() = 0; + private: + const E e_; + }; } namespace yes{ typedef detail::x x; + typedef detail::a_t a_t; + typedef detail::b_t b_t; + typedef detail::c_t c_t; + typedef detail::d_t d_t; + typedef detail::dd_t dd_t; + typedef detail::f_t f_t; + typedef detail::g_t g_t; } namespace no{ typedef std::string string_type; typedef detail::y_type y_type; + typedef std::vector< int > vector_of_int_type; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |