From 1c02715e4990299d37dea1fb32bcca6f1e927cd4 Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Mon, 9 Feb 2015 00:04:07 -0200 Subject: [PATCH 01/15] Fix to bug 11001 According to reference, insert_range should work for any Extensible sequence or Extensible Associative sequence, but the default implementation of insert_range_impl assumes a front_inserter is defined for the given sequence, but neither Extensible nor every Extensible Associative sequences are required to also be a Front Extensible sequence. This fix rely only on insert, which is defined for every Extensible sequence. --- include/boost/mpl/aux_/insert_range_impl.hpp | 35 +++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/include/boost/mpl/aux_/insert_range_impl.hpp b/include/boost/mpl/aux_/insert_range_impl.hpp index baffb54..4595468 100644 --- a/include/boost/mpl/aux_/insert_range_impl.hpp +++ b/include/boost/mpl/aux_/insert_range_impl.hpp @@ -14,9 +14,10 @@ // $Date$ // $Revision$ -#include +#include +#include +#include #include -#include #include #include #include @@ -43,29 +44,31 @@ struct insert_range_impl > struct apply #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING) - : reverse_copy< - joint_view< + : fold< + joint_view< iterator_range::type,Pos> - , joint_view< + , joint_view< Range , iterator_range::type> > > - , front_inserter< typename clear::type > + , typename clear::type + , insert<_1, end<_1>, _2> > { #else { - typedef typename reverse_copy< - joint_view< - iterator_range::type,Pos> - , joint_view< - Range - , iterator_range::type> - > - > - , front_inserter< typename clear::type > - >::type type; + typedef typename fold< + joint_view< + iterator_range::type,Pos> + , joint_view< + Range + , iterator_range::type> + > + > + , typename clear::type + , insert<_1, end<_1>, _2> + >::type type; #endif }; }; From c7798600d67acb49d398ebe90e9d7e2fcfe5738c Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Mon, 9 Feb 2015 20:48:55 -0200 Subject: [PATCH 02/15] Inserting elements at the beginning of Sequence, rather than at the end This way we take advantage of the constant-time insertion and removal of elements at the beginning of Front Extensible sequences, such as list. This implementation is closer to the original. --- include/boost/mpl/aux_/insert_range_impl.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/mpl/aux_/insert_range_impl.hpp b/include/boost/mpl/aux_/insert_range_impl.hpp index 4595468..fa43315 100644 --- a/include/boost/mpl/aux_/insert_range_impl.hpp +++ b/include/boost/mpl/aux_/insert_range_impl.hpp @@ -44,7 +44,7 @@ struct insert_range_impl > struct apply #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING) - : fold< + : reverse_fold< joint_view< iterator_range::type,Pos> , joint_view< @@ -53,12 +53,12 @@ struct insert_range_impl > > , typename clear::type - , insert<_1, end<_1>, _2> + , insert<_1, begin<_1>, _2> > { #else { - typedef typename fold< + typedef typename reverse_fold< joint_view< iterator_range::type,Pos> , joint_view< @@ -67,7 +67,7 @@ struct insert_range_impl > > , typename clear::type - , insert<_1, end<_1>, _2> + , insert<_1, begin<_1>, _2> >::type type; #endif }; From fc18efc259d115c70631cca08a347d28e3fd0c03 Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Tue, 10 Feb 2015 20:59:54 -0200 Subject: [PATCH 03/15] Specializing insert_range for aux::map_tag Taking advantage of the fact that order of insertion doesn't really matter for associative sequences. Comparing to the default implementation, which at any rate does work for associative sequences, this specialization essencially avoids reinserting every element of Sequence into a new sequence, besides the fact no joint_view nor iterator_range needs to be instantiated. --- .../boost/mpl/map/aux_/insert_range_impl.hpp | 41 +++++++++++++++++++ include/boost/mpl/map/map0.hpp | 1 + 2 files changed, 42 insertions(+) create mode 100644 include/boost/mpl/map/aux_/insert_range_impl.hpp diff --git a/include/boost/mpl/map/aux_/insert_range_impl.hpp b/include/boost/mpl/map/aux_/insert_range_impl.hpp new file mode 100644 index 0000000..f1f0437 --- /dev/null +++ b/include/boost/mpl/map/aux_/insert_range_impl.hpp @@ -0,0 +1,41 @@ + +#ifndef BOOST_MPL_MAP_AUX_INSERT_RANGE_IMPL_HPP_INCLUDED +#define BOOST_MPL_MAP_AUX_INSERT_RANGE_IMPL_HPP_INCLUDED + +// Copyright Bruno Dutra 2015 +// +// 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/mpl for documentation. + +// $Id$ +// $Date$ +// $Revision$ + +#include +#include +#include +#include +#include + +namespace boost { namespace mpl { + +template<> +struct insert_range_impl< aux::map_tag > +{ + template< + typename Sequence + , typename /*Pos*/ + , typename Range + > + struct apply + : fold > + { + }; +}; + +}} + +#endif // BOOST_MPL_MAP_AUX_INSERT_RANGE_IMPL_HPP_INCLUDED diff --git a/include/boost/mpl/map/map0.hpp b/include/boost/mpl/map/map0.hpp index e1ea897..88ed4b7 100644 --- a/include/boost/mpl/map/map0.hpp +++ b/include/boost/mpl/map/map0.hpp @@ -19,6 +19,7 @@ #include //#include #include +#include #include #include #include From f807edab2e1c3c2255b765b34fb97a4c9fa5fc5d Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Sat, 21 Feb 2015 19:42:38 -0200 Subject: [PATCH 04/15] Specializing insert_range for aux::set_tag as well Follows the same rationale as for maps. --- .../boost/mpl/set/aux_/insert_range_impl.hpp | 41 +++++++++++++++++++ include/boost/mpl/set/set0.hpp | 1 + 2 files changed, 42 insertions(+) create mode 100644 include/boost/mpl/set/aux_/insert_range_impl.hpp diff --git a/include/boost/mpl/set/aux_/insert_range_impl.hpp b/include/boost/mpl/set/aux_/insert_range_impl.hpp new file mode 100644 index 0000000..f7150a8 --- /dev/null +++ b/include/boost/mpl/set/aux_/insert_range_impl.hpp @@ -0,0 +1,41 @@ + +#ifndef BOOST_MPL_SET_AUX_INSERT_RANGE_IMPL_HPP_INCLUDED +#define BOOST_MPL_SET_AUX_INSERT_RANGE_IMPL_HPP_INCLUDED + +// Copyright Bruno Dutra 2015 +// +// 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/mpl for documentation. + +// $Id$ +// $Date$ +// $Revision$ + +#include +#include +#include +#include +#include + +namespace boost { namespace mpl { + +template<> +struct insert_range_impl< aux::set_tag > +{ + template< + typename Sequence + , typename /*Pos*/ + , typename Range + > + struct apply + : fold > + { + }; +}; + +}} + +#endif // BOOST_MPL_SET_AUX_INSERT_RANGE_IMPL_HPP_INCLUDED diff --git a/include/boost/mpl/set/set0.hpp b/include/boost/mpl/set/set0.hpp index 8403731..1c424e4 100644 --- a/include/boost/mpl/set/set0.hpp +++ b/include/boost/mpl/set/set0.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include From 77cda02d859adfba217b581076314daddda365e6 Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Sat, 21 Feb 2015 19:44:20 -0200 Subject: [PATCH 05/15] Adding a new test case for insert_range. Tests whether insert_range works with set, set_c and map as it should. --- test/insert_range.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/insert_range.cpp b/test/insert_range.cpp index 65e16fa..865017b 100644 --- a/test/insert_range.cpp +++ b/test/insert_range.cpp @@ -15,9 +15,17 @@ #include #include #include +#include +#include +#include #include #include #include +#include +#include +#include +#include +#include #include @@ -33,3 +41,33 @@ MPL_TEST_CASE() typedef insert_range< list0<>,end< list0<> >::type,list1 >::type result2; MPL_ASSERT_RELATION( size::value, ==, 1 ); } + +template +void test_associative() +{ + typedef typename insert_range< A,typename end< A >::type,B >::type C; + + MPL_ASSERT_RELATION( size::value, <=, (size::value + size::value) ); + MPL_ASSERT(( fold< joint_view< A,B >,true_,and_< _1,contains< C,_2 > > > )); +} + +MPL_TEST_CASE() +{ + typedef set3< short,int,long > signed_integers; + typedef set3< unsigned short,unsigned int,unsigned long > unsigned_integers; + test_associative(); + + typedef set_c< int,1,3,5,7,9 > odds; + typedef set_c< int,0,2,4,6,8 > evens; + test_associative(); + + typedef map2< + pair< void,void* > + , pair< int,int* > + > pointers; + typedef map2< + pair< void const,void const* > + , pair< int const,int const* > + > pointers_to_const; + test_associative(); +} From c8fe35643da67a56d1e4408055e8cb9a52757c8d Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Sun, 22 Feb 2015 20:59:59 -0300 Subject: [PATCH 06/15] Fix to Tickets #7975 and #8749 Originally Tickets 7975 and 8749 referred only to insertion of keys into maps, but the very same bug can be reproduced for sets as well. Moreover, the removal of keys from both also suffers of the same bug. --- include/boost/mpl/map/aux_/item.hpp | 3 +++ include/boost/mpl/set/aux_/item.hpp | 2 ++ test/map.cpp | 16 ++++++++++++++++ test/set.cpp | 16 ++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/include/boost/mpl/map/aux_/item.hpp b/include/boost/mpl/map/aux_/item.hpp index d0df522..a0a98ca 100644 --- a/include/boost/mpl/map/aux_/item.hpp +++ b/include/boost/mpl/map/aux_/item.hpp @@ -40,6 +40,7 @@ struct m_item typedef Key key_; typedef pair item; typedef Base base; + typedef m_item type; typedef typename next< typename Base::size >::type size; typedef typename next< typename Base::order >::type order; @@ -62,6 +63,7 @@ struct m_mask { typedef void_ key_; typedef Base base; + typedef m_mask type; typedef typename prior< typename Base::size >::type size; typedef typename x_order_impl::type key_order_; @@ -123,6 +125,7 @@ struct m_mask { typedef void_ key_; typedef Base base; + typedef m_mask type; typedef typename prior< typename Base::size >::type size; typedef typename x_order_impl::type key_order_; diff --git a/include/boost/mpl/set/aux_/item.hpp b/include/boost/mpl/set/aux_/item.hpp index e90e490..bd5bc95 100644 --- a/include/boost/mpl/set/aux_/item.hpp +++ b/include/boost/mpl/set/aux_/item.hpp @@ -33,6 +33,7 @@ struct s_item typedef void_ last_masked_; typedef T item_type_; typedef typename Base::item_ base; + typedef s_item type; typedef typename next< typename Base::size >::type size; typedef typename next< typename Base::order >::type order; @@ -57,6 +58,7 @@ struct s_mask typedef void_ item_type_; typedef typename Base::item_ base; typedef typename prior< typename Base::size >::type size; + typedef s_mask type; BOOST_MPL_AUX_SET_OVERLOAD( aux::yes_tag, IS_MASKED, s_mask, aux::type_wrapper* ); }; diff --git a/test/map.cpp b/test/map.cpp index 17ad99d..f39b85d 100644 --- a/test/map.cpp +++ b/test/map.cpp @@ -217,3 +217,19 @@ MPL_TEST_CASE() > )); } + +MPL_TEST_CASE() +{ + typedef insert< map<>, pair >::type little_map; + + MPL_ASSERT_RELATION(size::value, ==, 1); + MPL_ASSERT_RELATION(size::value, ==, 1); +} + +MPL_TEST_CASE() +{ + typedef erase_key< map< pair, pair >, float >::type little_map; + + MPL_ASSERT_RELATION(size::value, ==, 1); + MPL_ASSERT_RELATION(size::value, ==, 1); +} diff --git a/test/set.cpp b/test/set.cpp index ab291d9..0710b41 100644 --- a/test/set.cpp +++ b/test/set.cpp @@ -329,3 +329,19 @@ MPL_TEST_CASE() find_test(); find_test(); } + +MPL_TEST_CASE() +{ + typedef insert< set<>, int >::type little_set; + + MPL_ASSERT_RELATION(size::value, ==, 1); + MPL_ASSERT_RELATION(size::value, ==, 1); +} + +MPL_TEST_CASE() +{ + typedef erase_key< set< float, int >, float >::type little_set; + + MPL_ASSERT_RELATION(size::value, ==, 1); + MPL_ASSERT_RELATION(size::value, ==, 1); +} From eaa3f26c9c566fe462ac272fe26da82a492024c7 Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Sat, 21 Mar 2015 22:04:52 -0300 Subject: [PATCH 07/15] fixing the issue for empty_sequence's as well --- include/boost/mpl/empty_sequence.hpp | 3 ++- test/empty_sequence.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/boost/mpl/empty_sequence.hpp b/include/boost/mpl/empty_sequence.hpp index 94f5f5a..f32cc6e 100644 --- a/include/boost/mpl/empty_sequence.hpp +++ b/include/boost/mpl/empty_sequence.hpp @@ -23,7 +23,8 @@ namespace boost { namespace mpl { struct empty_sequence { - struct tag; + struct tag; + typedef empty_sequence type; struct begin { typedef random_access_iterator_tag category; }; typedef begin end; }; diff --git a/test/empty_sequence.cpp b/test/empty_sequence.cpp index a9501cc..2fa989f 100644 --- a/test/empty_sequence.cpp +++ b/test/empty_sequence.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -33,4 +34,6 @@ MPL_TEST_CASE() typedef advance_c::type advanced; MPL_ASSERT(( is_same )); + + MPL_ASSERT(( equal< empty_sequence, empty_sequence::type > )); } From 0f5451623c0c88db5db625b47865fc40e020ebfe Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Sat, 21 Mar 2015 22:19:56 -0300 Subject: [PATCH 08/15] adding tests to attest other views don't suffer of it either --- test/filter_view.cpp | 5 +++++ test/joint_view.cpp | 1 + test/single_view.cpp | 3 +++ test/transform_view.cpp | 12 +++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/test/filter_view.cpp b/test/filter_view.cpp index 35210a5..2ae5754 100644 --- a/test/filter_view.cpp +++ b/test/filter_view.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -26,6 +27,10 @@ MPL_TEST_CASE() { typedef mpl::list types; + typedef mpl::list floats; + + MPL_ASSERT(( equal< mpl::filter_view< types,boost::is_float<_> >::type,floats > )); + typedef mpl::max_element< mpl::transform_view< mpl::filter_view< types,boost::is_float<_> > diff --git a/test/joint_view.cpp b/test/joint_view.cpp index f71958a..17f824c 100644 --- a/test/joint_view.cpp +++ b/test/joint_view.cpp @@ -30,6 +30,7 @@ MPL_TEST_CASE() typedef range_c answer; MPL_ASSERT(( equal )); + MPL_ASSERT(( equal )); MPL_ASSERT_RELATION( size::value, ==, 15 ); } diff --git a/test/single_view.cpp b/test/single_view.cpp index c46096e..18169d3 100644 --- a/test/single_view.cpp +++ b/test/single_view.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include MPL_TEST_CASE() @@ -37,4 +38,6 @@ MPL_TEST_CASE() MPL_ASSERT_RELATION( (mpl::distance::value), ==, 0 ); MPL_ASSERT_RELATION( size::value, ==, 1 ); + + MPL_ASSERT(( equal< view, view::type > )); } diff --git a/test/transform_view.cpp b/test/transform_view.cpp index bc1fbcf..ff8fe6b 100644 --- a/test/transform_view.cpp +++ b/test/transform_view.cpp @@ -16,12 +16,22 @@ #include #include #include +#include #include - MPL_TEST_CASE() { typedef list types; + typedef list< + sizeof_::type, + sizeof_::type, + sizeof_::type, + sizeof_::type, + sizeof_::type + > sizes; + + MPL_ASSERT(( equal< transform_view< types, sizeof_<_> >::type,sizes > )); + typedef max_element< transform_view< types, sizeof_<_> > >::type iter; From 90951ea9e4f788d5d8c63031af74876d985a5345 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Thu, 2 Apr 2015 07:54:36 -0400 Subject: [PATCH 09/15] Remove reliance on deprecated type_traits headers. Fixed apply test. --- include/boost/mpl/empty_base.hpp | 15 +++++++++------ test/apply.cpp | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/boost/mpl/empty_base.hpp b/include/boost/mpl/empty_base.hpp index a5841cf..69630a5 100644 --- a/include/boost/mpl/empty_base.hpp +++ b/include/boost/mpl/empty_base.hpp @@ -17,12 +17,10 @@ #include #include #include +#include #include -// should be always the last #include directive -#include - namespace boost { namespace mpl { // empty base class, guaranteed to have no members; inheritance from @@ -51,9 +49,14 @@ struct is_empty_base }} namespace boost { -BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_empty, mpl::empty_base, true) + +template<> struct is_empty< mpl::empty_base > + : public ::boost::integral_constant +{ +public: + BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(1,is_empty,(mpl::empty_base)) +}; + } -#include - #endif // BOOST_MPL_EMPTY_BASE_HPP_INCLUDED diff --git a/test/apply.cpp b/test/apply.cpp index 6ee8e78..71bcbf9 100644 --- a/test/apply.cpp +++ b/test/apply.cpp @@ -76,7 +76,7 @@ MPL_TEST_CASE() typedef apply1< _1, std_vector<_1> >::type v_lambda; typedef apply1::type v_int; - MPL_ASSERT(( is_same< v,std_vector > )); + MPL_ASSERT(( is_same< v_int,std_vector > )); } MPL_TEST_CASE() @@ -86,7 +86,7 @@ MPL_TEST_CASE() typedef apply1< lambda<_1>, std_vector<_1> >::type make_vector; typedef apply_wrap1< make_vector,int >::type v_int; - MPL_ASSERT(( is_same< v,std_vector > )); + MPL_ASSERT(( is_same< v_int,std_vector > )); } MPL_TEST_CASE() From 2531010a0a5b9380aea4d42bbbb2831171471658 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Thu, 2 Apr 2015 08:00:13 -0400 Subject: [PATCH 10/15] Added include for integral constant. --- include/boost/mpl/empty_base.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/mpl/empty_base.hpp b/include/boost/mpl/empty_base.hpp index 69630a5..cb56ef6 100644 --- a/include/boost/mpl/empty_base.hpp +++ b/include/boost/mpl/empty_base.hpp @@ -19,6 +19,7 @@ #include #include +#include #include namespace boost { namespace mpl { From d5dcd7abb1b7e23d6e74e3c6bed05b04f510f07b Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Tue, 21 Apr 2015 15:40:24 +0200 Subject: [PATCH 11/15] Removed references to non-supported compilers. Signed-off-by: Deniz Bahadir --- preprocessed/include/msvc60/user.hpp | 26 -------------------------- preprocessed/include/msvc70/user.hpp | 21 --------------------- preprocessed/include/no_ctps/user.hpp | 15 --------------- preprocessed/preprocess.py | 2 +- preprocessed/preprocess_map.py | 2 +- preprocessed/preprocess_vector.py | 2 +- 6 files changed, 3 insertions(+), 65 deletions(-) delete mode 100644 preprocessed/include/msvc60/user.hpp delete mode 100644 preprocessed/include/msvc70/user.hpp delete mode 100644 preprocessed/include/no_ctps/user.hpp diff --git a/preprocessed/include/msvc60/user.hpp b/preprocessed/include/msvc60/user.hpp deleted file mode 100644 index 06774f2..0000000 --- a/preprocessed/include/msvc60/user.hpp +++ /dev/null @@ -1,26 +0,0 @@ - -// Copyright Aleksey Gurtovoy 2003-2004 -// -// 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/mpl for documentation. - -// $Id$ -// $Date$ -// $Revision$ - -#define BOOST_NO_CONFIG -#define BOOST_MSVC 1200 -#define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -#define BOOST_NO_INCLASS_MEMBER_INITIALIZATION -#define BOOST_NO_TEMPLATE_TEMPLATES -#define BOOST_NO_CV_VOID_SPECIALIZATIONS -#define BOOST_NO_INTRINSIC_WCHAR_T -#define BOOST_NO_STD_ALLOCATOR -#define BOOST_MPL_CFG_NO_BIND_TEMPLATE -#define BOOST_MPL_CFG_NO_APPLY_TEMPLATE -#define BOOST_MPL_CFG_MSVC_60_ETI_BUG -#define BOOST_MPL_CFG_MSVC_ETI_BUG -#define BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC diff --git a/preprocessed/include/msvc70/user.hpp b/preprocessed/include/msvc70/user.hpp deleted file mode 100644 index 19d8acf..0000000 --- a/preprocessed/include/msvc70/user.hpp +++ /dev/null @@ -1,21 +0,0 @@ - -// Copyright Aleksey Gurtovoy 2003-2004 -// -// 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/mpl for documentation. - -// $Id$ -// $Date$ -// $Revision$ - -#define BOOST_NO_CONFIG -#define BOOST_MSVC 1300 -#define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -#define BOOST_NO_INCLASS_MEMBER_INITIALIZATION -#define BOOST_MPL_CFG_NO_BIND_TEMPLATE -#define BOOST_MPL_CFG_NO_APPLY_TEMPLATE -#define BOOST_MPL_CFG_MSVC_ETI_BUG -#define BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC diff --git a/preprocessed/include/no_ctps/user.hpp b/preprocessed/include/no_ctps/user.hpp deleted file mode 100644 index f213849..0000000 --- a/preprocessed/include/no_ctps/user.hpp +++ /dev/null @@ -1,15 +0,0 @@ - -// Copyright Aleksey Gurtovoy 2003-2004 -// -// 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/mpl for documentation. - -// $Id$ -// $Date$ -// $Revision$ - -#define BOOST_NO_CONFIG -#define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION diff --git a/preprocessed/preprocess.py b/preprocessed/preprocess.py index 31a1df4..0c38eb0 100644 --- a/preprocessed/preprocess.py +++ b/preprocessed/preprocess.py @@ -82,7 +82,7 @@ def main( all_modes, src_dir, dst_dir ): if __name__ == '__main__': main( - ["bcc", "bcc551", "gcc", "msvc60", "msvc70", "mwcw", "dmc", "no_ctps", "no_ttp", "plain"] + ["bcc", "bcc551", "gcc", "mwcw", "dmc", "no_ttp", "plain"] , "src" , os.path.join( "boost", "mpl", "aux_", "preprocessed" ) ) diff --git a/preprocessed/preprocess_map.py b/preprocessed/preprocess_map.py index a791128..9f4fa9c 100644 --- a/preprocessed/preprocess_map.py +++ b/preprocessed/preprocess_map.py @@ -15,7 +15,7 @@ import preprocess import os.path preprocess.main( - [ "plain", "typeof_based", "no_ctps" ] + [ "plain", "typeof_based" ] , "map" , os.path.join( "boost", "mpl", "map", "aux_", "preprocessed" ) ) diff --git a/preprocessed/preprocess_vector.py b/preprocessed/preprocess_vector.py index 3de89d1..26c65b6 100644 --- a/preprocessed/preprocess_vector.py +++ b/preprocessed/preprocess_vector.py @@ -15,7 +15,7 @@ import preprocess import os.path preprocess.main( - [ "no_ctps", "plain", "typeof_based" ] + [ "plain", "typeof_based" ] , "vector" , os.path.join( "boost", "mpl", "vector", "aux_", "preprocessed" ) ) From 95f79d95a559faf7f323f7ccc35c815189c2822f Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Wed, 22 Apr 2015 13:47:06 +0200 Subject: [PATCH 12/15] Fix / Workaround for issue #11224. Python-script "fix_boost_mpl_preprocess.py" fixes the header-problems described in issue #11224. Python-script "boost_mpl_preprocess.py" simplifies the pre-processing of MPL-containers. Signed-off-by: Deniz Bahadir --- preprocessed/README.txt | 48 ++++++ preprocessed/boost_mpl_preprocess.py | 207 +++++++++++++++++++++++ preprocessed/fix_boost_mpl_preprocess.py | 114 +++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 preprocessed/README.txt create mode 100755 preprocessed/boost_mpl_preprocess.py create mode 100755 preprocessed/fix_boost_mpl_preprocess.py diff --git a/preprocessed/README.txt b/preprocessed/README.txt new file mode 100644 index 0000000..602bcfc --- /dev/null +++ b/preprocessed/README.txt @@ -0,0 +1,48 @@ +Pre-processing of MPL-containers +-------------------------------- + +Pre-processing of MPL-containers can be accomplished using the script +"boost_mpl_preprocess.py". In the simplest case call it with a single +argument which is the path to the source-directory of Boost. + + python boost_mpl_preprocess.py + +This will pre-process all four MPL-container types (vector, list, set, +map) and makes them able to hold up to 100 elements. They can be used +either in their 'numbered' or their 'variadic' form. + +Additionally, the script also allows more fine-grained pre-processing. +The maximal number of elements an MPL-container type is able to hold can +be different from the one of other MPL-container types and it can also +differ between its 'numbered' and 'variadic' form. +To see all options, call the script like this: + + python boost_mpl_preprocess.py --help + + +Fixing pre-processing of MPL-containers +--------------------------------------- + +Sadly, pre-processing of MPL-containers might fail, if the source-files +used as input are missing some header-comments required during the pre- +processing step. +In such a case call the script "fix_boost_mpl_preprocess.py" like this: + + python fix_boost_mpl_preprocess.py + +This will fix the header-comments of all the source-files needed during +pre-processing. Calling "boost_mpl_preprocess.py" afterwards should then +successfully pre-process the MPL-containers. + +Note: +If pre-processing failed can be checked by examining at least one of the +following directories in which automatically generated files will be put +during pre-processing. If at least one file in these directories (or sub- +directories therein) has a size of zero bytes, the fix is needed. + + /boost/mpl/vector/aux_/preprocessed/ + /boost/mpl/list/aux_/preprocessed/ + /boost/mpl/set/aux_/preprocessed/ + /boost/mpl/map/aux_/preprocessed/ + /boost/mpl/aux_/preprocessed/ + diff --git a/preprocessed/boost_mpl_preprocess.py b/preprocessed/boost_mpl_preprocess.py new file mode 100755 index 0000000..a51e3f9 --- /dev/null +++ b/preprocessed/boost_mpl_preprocess.py @@ -0,0 +1,207 @@ +# Copyright Deniz Bahadir 2015 +# +# 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/mpl for documentation. +# See http://stackoverflow.com/a/20660264/3115457 for further information. +# See http://stackoverflow.com/a/29627158/3115457 for further information. + +import argparse +import sys +import os +import os.path +import re +import fileinput +import shutil + + +def create_more_container_files(sourceDir, suffix, maxElements, containers, containers2): + """Creates additional files for the individual MPL-containers.""" + + # Create files for each MPL-container with 20 to 'maxElements' elements + # which will be used during generation. + for container in containers: + for i in range(20, maxElements, 10): + # Create copy of "template"-file. + newFile = os.path.join( sourceDir, container, container + str(i+10) + suffix ) + shutil.copyfile( os.path.join( sourceDir, container, container + "20" + suffix ), newFile ) + # Adjust copy of "template"-file accordingly. + for line in fileinput.input( newFile, inplace=1, mode="rU" ): + line = re.sub(r'20', re.escape(str(i+10)), line.rstrip()) + line = re.sub(r'11', re.escape(str(i + 1)), line.rstrip()) + line = re.sub(r'10', re.escape(str(i)), line.rstrip()) + print(line) + for container in containers2: + for i in range(20, maxElements, 10): + # Create copy of "template"-file. + newFile = os.path.join( sourceDir, container, container + str(i+10) + "_c" + suffix ) + shutil.copyfile( os.path.join( sourceDir, container, container + "20_c" + suffix ), newFile ) + # Adjust copy of "template"-file accordingly. + for line in fileinput.input( newFile, inplace=1, mode="rU" ): + line = re.sub(r'20', re.escape(str(i+10)), line.rstrip()) + line = re.sub(r'11', re.escape(str(i + 1)), line.rstrip()) + line = re.sub(r'10', re.escape(str(i)), line.rstrip()) + print(line) + + +def create_input_for_numbered_sequences(headerDir, sourceDir, containers, maxElements): + """Creates additional source- and header-files for the numbered sequence MPL-containers.""" + # Create additional container-list without "map". + containersWithoutMap = containers[:] + try: + containersWithoutMap.remove('map') + except ValueError: + # We can safely ignore if "map" is not contained in 'containers'! + pass + # Create header/source-files. + create_more_container_files(headerDir, ".hpp", maxElements, containers, containersWithoutMap) + create_more_container_files(sourceDir, ".cpp", maxElements, containers, containersWithoutMap) + + +def adjust_container_limits_for_variadic_sequences(headerDir, containers, maxElements): + """Adjusts the limits of variadic sequence MPL-containers.""" + for container in containers: + headerFile = os.path.join( headerDir, "limits", container + ".hpp" ) + regexMatch = r'(define\s+BOOST_MPL_LIMIT_' + container.upper() + r'_SIZE\s+)[0-9]+' + regexReplace = r'\g<1>' + re.escape( str(maxElements) ) + for line in fileinput.input( headerFile, inplace=1, mode="rU" ): + line = re.sub(regexMatch, regexReplace, line.rstrip()) + print(line) + + +def to_positive_multiple_of_10(string): + """Converts a string into its encoded positive integer (greater zero) or throws an exception.""" + try: + value = int(string) + except ValueError: + msg = '"%r" is not a positive multiple of 10 (greater zero).' % string + raise argparse.ArgumentTypeError(msg) + if value <= 0 or value % 10 != 0: + msg = '"%r" is not a positive multiple of 10 (greater zero).' % string + raise argparse.ArgumentTypeError(msg) + return value + + +def to_existing_absolute_path(string): + """Converts a path into its absolute path and verifies that it exists or throws an exception.""" + value = os.path.abspath(string) + if not os.path.exists( value ) or not os.path.isdir( value ): + msg = '"%r" is not a valid path to a directory.' % string + raise argparse.ArgumentTypeError(msg) + return value + + +def main(): + """The main function.""" + + # Prepare and run cmdline-parser. + cmdlineParser = argparse.ArgumentParser(description="A generator-script for pre-processed Boost.MPL headers.") + cmdlineParser.add_argument("-v", "--verbose", dest='verbose', action='store_true', + help="Be a little bit more verbose.") + cmdlineParser.add_argument("-s", "--sequence-type", dest='seqType', choices=['variadic', 'numbered', 'both'], + default='both', + help="Only update pre-processed headers for the selected sequence types, " + "either 'numbered' sequences, 'variadic' sequences or 'both' sequence " + "types. (Default=both)") + cmdlineParser.add_argument("--no-vector", dest='want_vector', action='store_false', + help="Do not update pre-processed headers for Boost.MPL Vector.") + cmdlineParser.add_argument("--no-list", dest='want_list', action='store_false', + help="Do not update pre-processed headers for Boost.MPL List.") + cmdlineParser.add_argument("--no-set", dest='want_set', action='store_false', + help="Do not update pre-processed headers for Boost.MPL Set.") + cmdlineParser.add_argument("--no-map", dest='want_map', action='store_false', + help="Do not update pre-processed headers for Boost.MPL Map.") + cmdlineParser.add_argument("--num-elements", dest='numElements', metavar="", + type=to_positive_multiple_of_10, default=100, + help="The maximal number of elements per container sequence. (Default=100)") + cmdlineParser.add_argument(dest='sourceDir', metavar="", + type=to_existing_absolute_path, + help="The source-directory of Boost.") + args = cmdlineParser.parse_args() + + # Some verbose debug output. + if args.verbose: + print "Arguments extracted from command-line:" + print " verbose = ", args.verbose + print " source directory = ", args.sourceDir + print " num elements = ", args.numElements + print " sequence type = ", args.seqType + print " want: vector = ", args.want_vector + print " want: list = ", args.want_list + print " want: set = ", args.want_set + print " want: map = ", args.want_map + + # The directories for header- and source files of Boost.MPL. + # NOTE: Assuming 'args.sourceDir' is the source-directory of the entire boost project. + headerDir = os.path.join( args.sourceDir, "boost", "mpl" ) + sourceDir = os.path.join( args.sourceDir, "libs", "mpl", "preprocessed" ) + # Check that the header/source-directories exist. + if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ): + # Maybe 'args.sourceDir' is not the source-directory of the entire boost project + # but instead of the Boost.MPL git-directory, only? + headerDir = os.path.join( args.sourceDir, "include", "boost", "mpl" ) + sourceDir = os.path.join( args.sourceDir, "preprocessed" ) + if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ): + cmdlineParser.print_usage() + print "error: Cannot find Boost.MPL header/source files in given Boost source-directory!" + sys.exit(0) + + # Some verbose debug output. + if args.verbose: + print "Chosen header-directory: ", headerDir + print "Chosen source-directory: ", sourceDir + + # Create list of containers for which files shall be pre-processed. + containers = [] + if args.want_vector: + containers.append('vector') + if args.want_list: + containers.append('list') + if args.want_set: + containers.append('set') + if args.want_map: + containers.append('map') + if containers == []: + print "Nothing to do. (Why did you prevent generating pre-processed headers for all Boost.MPL container types?" + sys.exit(0) + + # Some verbose debug output. + if args.verbose: + print "Containers for which to pre-process headers: ", containers + + # Create (additional) input files for generating pre-processed headers of numbered sequence MPL containers. + if args.seqType == "both" or args.seqType == "numbered": + create_input_for_numbered_sequences(headerDir, sourceDir, containers, args.numElements) + # Modify settings for generating pre-processed headers of variadic sequence MPL containers. + if args.seqType == "both" or args.seqType == "variadic": + adjust_container_limits_for_variadic_sequences(headerDir, containers, args.numElements) + + # Generate MPL-preprocessed files. + os.chdir( sourceDir ) + if args.seqType == "both" or args.seqType == "numbered": + if args.want_vector: + if args.verbose: + print "Pre-process headers for Boost.MPL numbered vectors." + os.system( "python " + os.path.join( sourceDir, "preprocess_vector.py" ) + " all " + args.sourceDir ) + if args.want_list: + if args.verbose: + print "Pre-process headers for Boost.MPL numbered lists." + os.system( "python " + os.path.join( sourceDir, "preprocess_list.py" ) + " all " + args.sourceDir ) + if args.want_set: + if args.verbose: + print "Pre-process headers for Boost.MPL numbered sets." + os.system( "python " + os.path.join( sourceDir, "preprocess_set.py" ) + " all " + args.sourceDir ) + if args.want_map: + if args.verbose: + print "Pre-process headers for Boost.MPL numbered maps." + os.system( "python " + os.path.join( sourceDir, "preprocess_map.py" ) + " all " + args.sourceDir ) + if args.seqType == "both" or args.seqType == "variadic": + if args.verbose: + print "Pre-process headers for Boost.MPL variadic containers." + os.system( "python " + os.path.join( sourceDir, "preprocess.py" ) + " all " + args.sourceDir ) + + +if __name__ == '__main__': + main() diff --git a/preprocessed/fix_boost_mpl_preprocess.py b/preprocessed/fix_boost_mpl_preprocess.py new file mode 100755 index 0000000..1f613ef --- /dev/null +++ b/preprocessed/fix_boost_mpl_preprocess.py @@ -0,0 +1,114 @@ +# Copyright Deniz Bahadir 2015 +# +# 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/mpl for documentation. +# See http://stackoverflow.com/a/29627158/3115457 for further information. + +import argparse +import sys +import os.path +import re +import fileinput +import datetime +import glob + + +def fix_header_comment(filename, timestamp): + """Fixes the header-comment of the given file.""" + # Fix input file. + name = os.path.basename( filename ) + for line in fileinput.input( filename, inplace=1, mode="rU" ): + # If header-comment already contains anything for '$Id$', remove it. + line = re.sub(r'\$Id:[^$]+\$', r'$Id$', line.rstrip()) + # Replace '$Id$' by a string containing the file's name (and a timestamp)! + line = re.sub(re.escape(r'$Id$'), r'$Id: ' + name + r' ' + timestamp.isoformat() + r' $', line.rstrip()) + print(line) + + +def fix_input_files_for_variadic_seq(sourceDir, timestamp): + """Fixes files used as input when pre-processing MPL-containers in their variadic form.""" + files = glob.glob( os.path.join( sourceDir, "src", "*" ) ) + for currentFile in sorted( files ): + fix_header_comment( currentFile, timestamp ) + + +def fix_input_files_for_numbered_seq(sourceDir, suffix, timestamp, containers): + """Fixes files used as input when pre-processing MPL-containers in their numbered form.""" + # Fix input files for each MPL-container type. + for container in containers: + files = glob.glob( os.path.join( sourceDir, container, container + '*' + suffix ) ) + for currentFile in sorted( files ): + fix_header_comment( currentFile, timestamp ) + + +def fix_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set', 'map'], verbose='false'): + """Fixes source- and header-files used as input when pre-processing MPL-containers.""" + # The new modification time. + timestamp = datetime.datetime.now(); + # Fix the input files. + if verbose: + print "Fix input files for pre-processing Boost.MPL variadic containers." + fix_input_files_for_variadic_seq(sourceDir, timestamp) + if verbose: + print "Fix input files for pre-processing Boost.MPL numbered containers." + fix_input_files_for_numbered_seq(headerDir, ".hpp", timestamp, containers) + fix_input_files_for_numbered_seq(sourceDir, ".cpp", timestamp, containers) + + +def to_existing_absolute_path(string): + """Converts a path into its absolute path and verifies that it exists or throws an exception.""" + value = os.path.abspath(string) + if not os.path.exists( value ) or not os.path.isdir( value ): + msg = '"%r" is not a valid path to a directory.' % string + raise argparse.ArgumentTypeError(msg) + return value + + +def main(): + """The main function.""" + + # Prepare and run cmdline-parser. + cmdlineParser = argparse.ArgumentParser( + description="Fixes the input files used for pre-processing of Boost.MPL headers.") + cmdlineParser.add_argument("-v", "--verbose", dest='verbose', action='store_true', + help="Be a little bit more verbose.") + cmdlineParser.add_argument(dest='sourceDir', metavar="", + type=to_existing_absolute_path, + help="The source-directory of Boost.") + args = cmdlineParser.parse_args() + + # Some verbose debug output. + if args.verbose: + print "Arguments extracted from command-line:" + print " verbose = ", args.verbose + print " source directory = ", args.sourceDir + + # The directories for header- and source files of Boost.MPL. + # NOTE: Assuming 'args.sourceDir' is the source-directory of the entire boost project. + headerDir = os.path.join( args.sourceDir, "boost", "mpl" ) + sourceDir = os.path.join( args.sourceDir, "libs", "mpl", "preprocessed" ) + # Check that the header/source-directories exist. + if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ): + # Maybe 'args.sourceDir' is not the source-directory of the entire boost project + # but instead of the Boost.MPL git-directory, only? + headerDir = os.path.join( args.sourceDir, "include", "boost", "mpl" ) + sourceDir = os.path.join( args.sourceDir, "preprocessed" ) + if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ): + cmdlineParser.print_usage() + print "error: Cannot find Boost.MPL header/source files in given Boost source-directory!" + sys.exit(0) + + # Some verbose debug output. + if args.verbose: + print "Chosen header-directory: ", headerDir + print "Chosen source-directory: ", sourceDir + + # Fix input file for generating pre-processed headers. + fix_input_files(headerDir, sourceDir, verbose = args.verbose) + + +if __name__ == '__main__': + main() From 7cd0559ce812a70854a31e7ba6fa8ba7298e95b5 Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Fri, 1 May 2015 17:02:00 +0200 Subject: [PATCH 13/15] Fix / Workaround for issue #11224. (cont.) * Corrected a small error in a regex of "boost_mpl_preprocess.py" which did match too much and therefore resulted in wrong substitution in some cases. * Added some more directories with files that need fixing to script "fix_boost_mpl_preprocess.py". Signed-off-by: Deniz Bahadir --- preprocessed/boost_mpl_preprocess.py | 4 ++-- preprocessed/fix_boost_mpl_preprocess.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/preprocessed/boost_mpl_preprocess.py b/preprocessed/boost_mpl_preprocess.py index a51e3f9..ff26599 100755 --- a/preprocessed/boost_mpl_preprocess.py +++ b/preprocessed/boost_mpl_preprocess.py @@ -31,7 +31,7 @@ def create_more_container_files(sourceDir, suffix, maxElements, containers, cont for line in fileinput.input( newFile, inplace=1, mode="rU" ): line = re.sub(r'20', re.escape(str(i+10)), line.rstrip()) line = re.sub(r'11', re.escape(str(i + 1)), line.rstrip()) - line = re.sub(r'10', re.escape(str(i)), line.rstrip()) + line = re.sub(r'10(?![0-9])', re.escape(str(i)), line.rstrip()) print(line) for container in containers2: for i in range(20, maxElements, 10): @@ -42,7 +42,7 @@ def create_more_container_files(sourceDir, suffix, maxElements, containers, cont for line in fileinput.input( newFile, inplace=1, mode="rU" ): line = re.sub(r'20', re.escape(str(i+10)), line.rstrip()) line = re.sub(r'11', re.escape(str(i + 1)), line.rstrip()) - line = re.sub(r'10', re.escape(str(i)), line.rstrip()) + line = re.sub(r'10(?![0-9])', re.escape(str(i)), line.rstrip()) print(line) diff --git a/preprocessed/fix_boost_mpl_preprocess.py b/preprocessed/fix_boost_mpl_preprocess.py index 1f613ef..0dffd07 100755 --- a/preprocessed/fix_boost_mpl_preprocess.py +++ b/preprocessed/fix_boost_mpl_preprocess.py @@ -28,9 +28,12 @@ def fix_header_comment(filename, timestamp): print(line) -def fix_input_files_for_variadic_seq(sourceDir, timestamp): +def fix_input_files_for_variadic_seq(headerDir, sourceDir, timestamp): """Fixes files used as input when pre-processing MPL-containers in their variadic form.""" - files = glob.glob( os.path.join( sourceDir, "src", "*" ) ) + # Fix files in include/source-directories. + files = glob.glob( os.path.join( headerDir, "*.hpp" ) ) + files += glob.glob( os.path.join( headerDir, "aux_", "*.hpp" ) ) + files += glob.glob( os.path.join( sourceDir, "src", "*" ) ) for currentFile in sorted( files ): fix_header_comment( currentFile, timestamp ) @@ -51,7 +54,7 @@ def fix_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set', ' # Fix the input files. if verbose: print "Fix input files for pre-processing Boost.MPL variadic containers." - fix_input_files_for_variadic_seq(sourceDir, timestamp) + fix_input_files_for_variadic_seq(headerDir, sourceDir, timestamp) if verbose: print "Fix input files for pre-processing Boost.MPL numbered containers." fix_input_files_for_numbered_seq(headerDir, ".hpp", timestamp, containers) From 0e262c22a04ee93f3e5556e0008fe554da653c51 Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Fri, 1 May 2015 17:46:59 +0200 Subject: [PATCH 14/15] Fix / Workaround for issue #11224. (cont.) * Extended script "boost_mpl_preprocess.py" to automatically call script "fix_boost_mpl_preprocess.py" prior to pre-processing and thereby automatically fix issue #11224. * Extended script "fix_boost_mpl_preprocess.py" to just allow checking if the selected Boost source-directory requires fixing because of issue #11224. * Adjusted the "README.txt" accordingly. Signed-off-by: Deniz Bahadir --- preprocessed/README.txt | 25 +++++- preprocessed/boost_mpl_preprocess.py | 14 ++- preprocessed/fix_boost_mpl_preprocess.py | 110 ++++++++++++++++++++--- 3 files changed, 133 insertions(+), 16 deletions(-) diff --git a/preprocessed/README.txt b/preprocessed/README.txt index 602bcfc..caa8691 100644 --- a/preprocessed/README.txt +++ b/preprocessed/README.txt @@ -26,19 +26,36 @@ Fixing pre-processing of MPL-containers Sadly, pre-processing of MPL-containers might fail, if the source-files used as input are missing some header-comments required during the pre- processing step. -In such a case call the script "fix_boost_mpl_preprocess.py" like this: +However, the script "boost_mpl_preprocess.py" makes sure to patch these +input source-files prior to pre-processing (by implicitly calling script +"fix_boost_mpl_preprocess.py" with the chosen settings). It only patches +the source-files needed for pre-processing the selected MPL-container +types and their selected form ('numbered' or 'variadic'). +If calling it with a single argument (as in the former section) all input +source-files will be patched automatically. + +Instead of fixing the input-files implicitly during pre-processing one +can also fix them explicitly by calling "fix_boost_mpl_preprocess.py" +directly. +If you just want to test if any fixing is needed call it like this: + + python fix_boost_mpl_preprocess.py --check-only + +This will tell you if any fixing is needed. In such a case call the script +"fix_boost_mpl_preprocess.py" like this: python fix_boost_mpl_preprocess.py This will fix the header-comments of all the source-files needed during pre-processing. Calling "boost_mpl_preprocess.py" afterwards should then -successfully pre-process the MPL-containers. +successfully pre-process the MPL-containers (without the need of implicitly +fixing any files again). Note: -If pre-processing failed can be checked by examining at least one of the +Failure of pre-processing can be checked by examining at least one of the following directories in which automatically generated files will be put during pre-processing. If at least one file in these directories (or sub- -directories therein) has a size of zero bytes, the fix is needed. +directories therein) has a size of zero bytes, fixing is needed. /boost/mpl/vector/aux_/preprocessed/ /boost/mpl/list/aux_/preprocessed/ diff --git a/preprocessed/boost_mpl_preprocess.py b/preprocessed/boost_mpl_preprocess.py index ff26599..1724c32 100755 --- a/preprocessed/boost_mpl_preprocess.py +++ b/preprocessed/boost_mpl_preprocess.py @@ -8,6 +8,7 @@ # See http://stackoverflow.com/a/20660264/3115457 for further information. # See http://stackoverflow.com/a/29627158/3115457 for further information. +import fix_boost_mpl_preprocess as fixmpl import argparse import sys import os @@ -164,9 +165,20 @@ def main(): if args.want_map: containers.append('map') if containers == []: - print "Nothing to do. (Why did you prevent generating pre-processed headers for all Boost.MPL container types?" + print "Nothing to do." + print "(Why did you prevent generating pre-processed headers for all Boost.MPL container types?)" sys.exit(0) + # Possibly fix the header-comments of input-files needed for pre-processing. + if args.verbose: + print "Checking if prior to pre-processing some input-files need fixing." + needFixing = fixmpl.check_input_files(headerDir, sourceDir, containers, args.seqType, args.verbose) + if needFixing: + if args.verbose: + print "Fixing of some input-files prior to pre-processing is needed." + print "Will fix them now!" + fixmpl.fix_input_files(headerDir, sourceDir, containers, args.seqType, args.verbose) + # Some verbose debug output. if args.verbose: print "Containers for which to pre-process headers: ", containers diff --git a/preprocessed/fix_boost_mpl_preprocess.py b/preprocessed/fix_boost_mpl_preprocess.py index 0dffd07..3b92d25 100755 --- a/preprocessed/fix_boost_mpl_preprocess.py +++ b/preprocessed/fix_boost_mpl_preprocess.py @@ -16,6 +16,79 @@ import datetime import glob +def check_header_comment(filename): + """Checks if the header-comment of the given file needs fixing.""" + # Check input file. + name = os.path.basename( filename ) + # Read content of input file. + sourcefile = open( filename, "rU" ) + content = sourcefile.read() + sourcefile.close() + # Search content for '$Id$'. + match = re.search(r'\$Id\$', content) + if match == None: + # Make sure that the correct value for '$Id$' was already set. + match = re.search(r'\$Id: ' + name + r'\s+[^$]+\$', content) + if match != None: + # The given file needs no fixing. + return False + # The given file needs fixing. + return True + + +def check_input_files_for_variadic_seq(headerDir, sourceDir): + """Checks if files, used as input when pre-processing MPL-containers in their variadic form, need fixing.""" + # Check input files in include/source-directories. + files = glob.glob( os.path.join( headerDir, "*.hpp" ) ) + files += glob.glob( os.path.join( headerDir, "aux_", "*.hpp" ) ) + files += glob.glob( os.path.join( sourceDir, "src", "*" ) ) + for currentFile in sorted( files ): + if check_header_comment( currentFile ): + return True + return False + + +def check_input_files_for_numbered_seq(sourceDir, suffix, containers): + """Check if files, used as input when pre-processing MPL-containers in their numbered form, need fixing.""" + # Check input files for each MPL-container type. + for container in containers: + files = glob.glob( os.path.join( sourceDir, container, container + '*' + suffix ) ) + for currentFile in sorted( files ): + if check_header_comment( currentFile ): + return True + return False + + +def check_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set', 'map'], + seqType='both', verbose=False): + """Checks if source- and header-files, used as input when pre-processing MPL-containers, need fixing.""" + # Check the input files for containers in their variadic form. + result1 = False + if seqType == "both" or seqType == "variadic": + if verbose: + print "Check if input files for pre-processing Boost.MPL variadic containers need fixing." + result1 = check_input_files_for_variadic_seq(headerDir, sourceDir) + if verbose: + if result1: + print " At least one input file needs fixing!" + else: + print " No input file needs fixing!" + # Check the input files for containers in their numbered form. + result2 = False + result3 = False + if seqType == "both" or seqType == "numbered": + if verbose: + print "Check input files for pre-processing Boost.MPL numbered containers." + result2 = check_input_files_for_numbered_seq(headerDir, ".hpp", containers) + result3 = check_input_files_for_numbered_seq(sourceDir, ".cpp", containers) + if verbose: + if result2 or result3: + print " At least one input file needs fixing!" + else: + print " No input file needs fixing!" + # Return result. + return result1 or result2 or result3 + def fix_header_comment(filename, timestamp): """Fixes the header-comment of the given file.""" # Fix input file. @@ -47,18 +120,22 @@ def fix_input_files_for_numbered_seq(sourceDir, suffix, timestamp, containers): fix_header_comment( currentFile, timestamp ) -def fix_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set', 'map'], verbose='false'): +def fix_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set', 'map'], + seqType='both', verbose=False): """Fixes source- and header-files used as input when pre-processing MPL-containers.""" # The new modification time. timestamp = datetime.datetime.now(); - # Fix the input files. - if verbose: - print "Fix input files for pre-processing Boost.MPL variadic containers." - fix_input_files_for_variadic_seq(headerDir, sourceDir, timestamp) - if verbose: - print "Fix input files for pre-processing Boost.MPL numbered containers." - fix_input_files_for_numbered_seq(headerDir, ".hpp", timestamp, containers) - fix_input_files_for_numbered_seq(sourceDir, ".cpp", timestamp, containers) + # Fix the input files for containers in their variadic form. + if seqType == "both" or seqType == "variadic": + if verbose: + print "Fix input files for pre-processing Boost.MPL variadic containers." + fix_input_files_for_variadic_seq(headerDir, sourceDir, timestamp) + # Fix the input files for containers in their numbered form. + if seqType == "both" or seqType == "numbered": + if verbose: + print "Fix input files for pre-processing Boost.MPL numbered containers." + fix_input_files_for_numbered_seq(headerDir, ".hpp", timestamp, containers) + fix_input_files_for_numbered_seq(sourceDir, ".cpp", timestamp, containers) def to_existing_absolute_path(string): @@ -78,6 +155,8 @@ def main(): description="Fixes the input files used for pre-processing of Boost.MPL headers.") cmdlineParser.add_argument("-v", "--verbose", dest='verbose', action='store_true', help="Be a little bit more verbose.") + cmdlineParser.add_argument("--check-only", dest='checkonly', action='store_true', + help="Only checks if fixing is required.") cmdlineParser.add_argument(dest='sourceDir', metavar="", type=to_existing_absolute_path, help="The source-directory of Boost.") @@ -87,6 +166,7 @@ def main(): if args.verbose: print "Arguments extracted from command-line:" print " verbose = ", args.verbose + print " check-only = ", args.checkonly print " source directory = ", args.sourceDir # The directories for header- and source files of Boost.MPL. @@ -109,8 +189,16 @@ def main(): print "Chosen header-directory: ", headerDir print "Chosen source-directory: ", sourceDir - # Fix input file for generating pre-processed headers. - fix_input_files(headerDir, sourceDir, verbose = args.verbose) + if args.checkonly: + # Check input files for generating pre-processed headers. + result = check_input_files(headerDir, sourceDir, verbose = args.verbose) + if result: + print "Fixing the input-files used for pre-processing of Boost.MPL headers IS required." + else: + print "Fixing the input-files used for pre-processing of Boost.MPL headers is NOT required." + else: + # Fix input files for generating pre-processed headers. + fix_input_files(headerDir, sourceDir, verbose = args.verbose) if __name__ == '__main__': From 7c9701ee5c09994816e6fcdf0689c0521a58db3d Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Tue, 19 May 2015 12:11:44 +0200 Subject: [PATCH 15/15] Addition to fix / workaround for issue #11224. * Added default-value for cmdline-option which expects the Boost source-directory. It points to the Boost source-directory in which the script "boost_mpl_preprocess.py" is located. * Adjusted "README.txt" file to reflect these changes. Signed-off-by: Deniz Bahadir --- preprocessed/README.txt | 17 +++++++++----- preprocessed/boost_mpl_preprocess.py | 33 ++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/preprocessed/README.txt b/preprocessed/README.txt index caa8691..75ae37f 100644 --- a/preprocessed/README.txt +++ b/preprocessed/README.txt @@ -2,14 +2,19 @@ Pre-processing of MPL-containers -------------------------------- Pre-processing of MPL-containers can be accomplished using the script -"boost_mpl_preprocess.py". In the simplest case call it with a single +"boost_mpl_preprocess.py". In the simple case call it with a single argument which is the path to the source-directory of Boost. python boost_mpl_preprocess.py -This will pre-process all four MPL-container types (vector, list, set, -map) and makes them able to hold up to 100 elements. They can be used -either in their 'numbered' or their 'variadic' form. +If the Boost source-directory is the one this script resides in, you +can just call it without any arguments. + + python boost_mpl_preprocess.py + +Either way, this will pre-process all four MPL-container types (vector, +list, set, map) and makes them able to hold up to 100 elements. They can +be used either in their 'numbered' or their 'variadic' form. Additionally, the script also allows more fine-grained pre-processing. The maximal number of elements an MPL-container type is able to hold can @@ -31,8 +36,8 @@ input source-files prior to pre-processing (by implicitly calling script "fix_boost_mpl_preprocess.py" with the chosen settings). It only patches the source-files needed for pre-processing the selected MPL-container types and their selected form ('numbered' or 'variadic'). -If calling it with a single argument (as in the former section) all input -source-files will be patched automatically. +If calling it with a single (or no) argument (as in the former section) +all input source-files will be patched automatically. Instead of fixing the input-files implicitly during pre-processing one can also fix them explicitly by calling "fix_boost_mpl_preprocess.py" diff --git a/preprocessed/boost_mpl_preprocess.py b/preprocessed/boost_mpl_preprocess.py index 1724c32..72a18ab 100755 --- a/preprocessed/boost_mpl_preprocess.py +++ b/preprocessed/boost_mpl_preprocess.py @@ -72,6 +72,21 @@ def adjust_container_limits_for_variadic_sequences(headerDir, containers, maxEle print(line) +def current_boost_dir(): + """Returns the (relative) path to the Boost source-directory this file is located in (if any).""" + # Path to directory containing this script. + path = os.path.dirname( os.path.realpath(__file__) ) + # Making sure it is located in "${boost-dir}/libs/mpl/preprocessed". + for directory in reversed( ["libs", "mpl", "preprocessed"] ): + (head, tail) = os.path.split(path) + if tail == directory: + path = head + else: + return None + return os.path.relpath( path ) + + + def to_positive_multiple_of_10(string): """Converts a string into its encoded positive integer (greater zero) or throws an exception.""" try: @@ -96,7 +111,12 @@ def to_existing_absolute_path(string): def main(): """The main function.""" - + + # Find the current Boost source-directory in which this script is located. + sourceDir = current_boost_dir() + if sourceDir == None: + sourceDir = "" + # Prepare and run cmdline-parser. cmdlineParser = argparse.ArgumentParser(description="A generator-script for pre-processed Boost.MPL headers.") cmdlineParser.add_argument("-v", "--verbose", dest='verbose', action='store_true', @@ -117,9 +137,9 @@ def main(): cmdlineParser.add_argument("--num-elements", dest='numElements', metavar="", type=to_positive_multiple_of_10, default=100, help="The maximal number of elements per container sequence. (Default=100)") - cmdlineParser.add_argument(dest='sourceDir', metavar="", + cmdlineParser.add_argument(dest='sourceDir', metavar="", default=current_boost_dir(), nargs='?', type=to_existing_absolute_path, - help="The source-directory of Boost.") + help="The source-directory of Boost. (Default=\"" + sourceDir + "\")") args = cmdlineParser.parse_args() # Some verbose debug output. @@ -134,7 +154,12 @@ def main(): print " want: set = ", args.want_set print " want: map = ", args.want_map - # The directories for header- and source files of Boost.MPL. + # Verify that we received any source-directory. + if args.sourceDir == None: + print "You should specify a valid path to the Boost source-directory." + sys.exit(0) + + # The directories for header- and source files of Boost.MPL. # NOTE: Assuming 'args.sourceDir' is the source-directory of the entire boost project. headerDir = os.path.join( args.sourceDir, "boost", "mpl" ) sourceDir = os.path.join( args.sourceDir, "libs", "mpl", "preprocessed" )