diff options
Diffstat (limited to 'boost/spirit/home/x3')
17 files changed, 231 insertions, 514 deletions
diff --git a/boost/spirit/home/x3/auxiliary/attr.hpp b/boost/spirit/home/x3/auxiliary/attr.hpp index 6471bd90df..0459e55255 100644 --- a/boost/spirit/home/x3/auxiliary/attr.hpp +++ b/boost/spirit/home/x3/auxiliary/attr.hpp @@ -50,9 +50,8 @@ namespace boost { namespace spirit { namespace x3 Value value_; - private: // silence MSVC warning C4512: assignment operator could not be generated - attr_parser& operator= (attr_parser const&); + attr_parser& operator= (attr_parser const&) = delete; }; template <typename Value, std::size_t N> @@ -86,9 +85,8 @@ namespace boost { namespace spirit { namespace x3 Value value_[N]; - private: // silence MSVC warning C4512: assignment operator could not be generated - attr_parser& operator= (attr_parser const&); + attr_parser& operator= (attr_parser const&) = delete; }; template <typename Value> diff --git a/boost/spirit/home/x3/char/char_set.hpp b/boost/spirit/home/x3/char/char_set.hpp index 26e15478dc..082f6ce191 100644 --- a/boost/spirit/home/x3/char/char_set.hpp +++ b/boost/spirit/home/x3/char/char_set.hpp @@ -67,18 +67,11 @@ namespace boost { namespace spirit { namespace x3 { using spirit::x3::detail::cast_char; - typedef typename - remove_const< - typename traits::char_type_of<String>::type - >::type - in_type; - - in_type const* definition = - (in_type const*)traits::get_c_string(str); - in_type ch = *definition++; + auto* definition = traits::get_c_string(str); + auto ch = *definition++; while (ch) { - in_type next = *definition++; + auto next = *definition++; if (next == '-') { next = *definition++; diff --git a/boost/spirit/home/x3/char/unicode.hpp b/boost/spirit/home/x3/char/unicode.hpp index 290c7a4adc..a7bcbfb205 100644 --- a/boost/spirit/home/x3/char/unicode.hpp +++ b/boost/spirit/home/x3/char/unicode.hpp @@ -197,26 +197,26 @@ namespace boost { namespace spirit { namespace x3 typedef char_encoding::unicode encoding; typedef char_encoding::unicode::char_type char_type; -#define BOOST_SPIRIT_X3_BASIC_CLASSIFY(name) \ - template <typename Char> \ - static bool \ - is(name##_tag, Char ch) \ - { \ - return encoding::is ##name \ - BOOST_PREVENT_MACRO_SUBSTITUTION \ - (detail::cast_char<char_type>(ch)); \ - } \ +#define BOOST_SPIRIT_X3_BASIC_CLASSIFY(name) \ + template <typename Char> \ + static bool \ + is(name##_tag, Char ch) \ + { \ + return encoding::is ##name \ + BOOST_PREVENT_MACRO_SUBSTITUTION \ + (detail::cast_char<char_type>(ch)); \ + } \ /***/ -#define BOOST_SPIRIT_X3_CLASSIFY(name) \ - template <typename Char> \ - static bool \ - is(name##_tag, Char ch) \ - { \ - return encoding::is_##name \ - BOOST_PREVENT_MACRO_SUBSTITUTION \ - (detail::cast_char<char_type>(ch)); \ - } \ +#define BOOST_SPIRIT_X3_CLASSIFY(name) \ + template <typename Char> \ + static bool \ + is(name##_tag, Char ch) \ + { \ + return encoding::is_##name \ + BOOST_PREVENT_MACRO_SUBSTITUTION \ + (detail::cast_char<char_type>(ch)); \ + } \ /***/ @@ -419,9 +419,9 @@ namespace boost { namespace spirit { namespace x3 } }; -#define BOOST_SPIRIT_X3_CHAR_CLASS(name) \ - typedef unicode_char_class<name##_tag> name##_type; \ - name##_type const name = name##_type(); \ +#define BOOST_SPIRIT_X3_CHAR_CLASS(name) \ + typedef unicode_char_class<name##_tag> name##_type; \ + name##_type const name = name##_type(); \ /***/ namespace unicode diff --git a/boost/spirit/home/x3/core/detail/parse_into_container.hpp b/boost/spirit/home/x3/core/detail/parse_into_container.hpp index 979238cff3..b58add3b28 100644 --- a/boost/spirit/home/x3/core/detail/parse_into_container.hpp +++ b/boost/spirit/home/x3/core/detail/parse_into_container.hpp @@ -12,6 +12,7 @@ #include <boost/spirit/home/x3/support/traits/container_traits.hpp> #include <boost/spirit/home/x3/support/traits/value_traits.hpp> #include <boost/spirit/home/x3/support/traits/attribute_of.hpp> +#include <boost/spirit/home/x3/support/traits/pseudo_attribute.hpp> #include <boost/spirit/home/x3/support/traits/handles_container.hpp> #include <boost/spirit/home/x3/support/traits/has_attribute.hpp> #include <boost/spirit/home/x3/support/traits/is_substitute.hpp> @@ -91,10 +92,10 @@ namespace boost { namespace spirit { namespace x3 { namespace detail , Context const& context, RContext& rcontext, Attribute& attr, mpl::false_) { // synthesized attribute needs to be value initialized - typedef typename - traits::container_value<Attribute>::type - value_type; - value_type val = traits::value_initialize<value_type>::call(); + using value_type = typename traits::container_value<Attribute>::type; + using pseudo = traits::pseudo_attribute<Context, value_type, Iterator>; + typename pseudo::type val = pseudo::call( + first, last, traits::value_initialize<value_type>::call()); if (!parser.parse(first, last, context, rcontext, val)) return false; @@ -221,10 +222,14 @@ namespace boost { namespace spirit { namespace x3 { namespace detail template <typename Parser, typename Context, typename RContext, typename Enable = void> struct parse_into_container_impl : parse_into_container_base_impl<Parser> {}; - template <typename Parser, typename Container, typename Context> + template <typename Parser, typename Iterator, typename Container, typename Context> struct parser_attr_is_substitute_for_container_value : traits::is_substitute< - typename traits::attribute_of<Parser, Context>::type + typename traits::pseudo_attribute< + Context + , typename traits::attribute_of<Parser, Context>::type + , Iterator + >::type , typename traits::container_value<Container>::type > {}; @@ -278,7 +283,7 @@ namespace boost { namespace spirit { namespace x3 { namespace detail parser_accepts_container; typedef parser_attr_is_substitute_for_container_value< - Parser, Attribute, Context> + Parser, Iterator, Attribute, Context> parser_attr_is_substitute_for_container_value; typedef mpl::or_< diff --git a/boost/spirit/home/x3/directive/raw.hpp b/boost/spirit/home/x3/directive/raw.hpp index 8432e13888..2f82362544 100644 --- a/boost/spirit/home/x3/directive/raw.hpp +++ b/boost/spirit/home/x3/directive/raw.hpp @@ -10,6 +10,7 @@ #include <boost/spirit/home/x3/core/skip_over.hpp> #include <boost/spirit/home/x3/core/parser.hpp> #include <boost/spirit/home/x3/support/traits/move_to.hpp> +#include <boost/spirit/home/x3/support/traits/pseudo_attribute.hpp> #include <boost/range/iterator_range.hpp> namespace boost { namespace spirit { namespace x3 @@ -65,6 +66,21 @@ namespace boost { namespace spirit { namespace x3 }; auto const raw = raw_gen{}; + + namespace traits + { + template <typename Context, typename Iterator> + struct pseudo_attribute<Context, raw_attribute_type, Iterator> + { + using attribute_type = raw_attribute_type; + using type = boost::iterator_range<Iterator>; + + static type call(Iterator& first, Iterator const& last, attribute_type) + { + return { first, last }; + } + }; + } }}} #endif diff --git a/boost/spirit/home/x3/nonterminal/rule.hpp b/boost/spirit/home/x3/nonterminal/rule.hpp index 2aee90f551..73f4ec6436 100644 --- a/boost/spirit/home/x3/nonterminal/rule.hpp +++ b/boost/spirit/home/x3/nonterminal/rule.hpp @@ -131,9 +131,6 @@ namespace boost { namespace spirit { namespace x3 bool parse(Iterator& first, Iterator const& last , Context const& context, unused_type, unused_type) const { - static_assert(!has_attribute, - "The rule requires an input attribute. Check your parser."); - // make sure we pass exactly the rule attribute type attribute_type no_attr; return parse_rule(*this, first, last, context, no_attr); diff --git a/boost/spirit/home/x3/numeric/real.hpp b/boost/spirit/home/x3/numeric/real.hpp index a7a9573058..a90543fc69 100644 --- a/boost/spirit/home/x3/numeric/real.hpp +++ b/boost/spirit/home/x3/numeric/real.hpp @@ -57,6 +57,9 @@ namespace boost { namespace spirit { namespace x3 typedef real_parser<double> double_type; double_type const double_ = {}; + typedef real_parser<long double> long_double_type; + long_double_type const long_double = {}; + }}} #endif diff --git a/boost/spirit/home/x3/operator/detail/alternative.hpp b/boost/spirit/home/x3/operator/detail/alternative.hpp index 2c87fa0376..e66a76e3be 100644 --- a/boost/spirit/home/x3/operator/detail/alternative.hpp +++ b/boost/spirit/home/x3/operator/detail/alternative.hpp @@ -8,6 +8,7 @@ #define BOOST_SPIRIT_X3_ALTERNATIVE_DETAIL_JAN_07_2013_1245PM #include <boost/spirit/home/x3/support/traits/attribute_of.hpp> +#include <boost/spirit/home/x3/support/traits/pseudo_attribute.hpp> #include <boost/spirit/home/x3/support/traits/is_variant.hpp> #include <boost/spirit/home/x3/support/traits/tuple_traits.hpp> #include <boost/spirit/home/x3/support/traits/move_to.hpp> @@ -244,9 +245,11 @@ namespace boost { namespace spirit { namespace x3 { namespace detail bool parse_alternative(Parser const& p, Iterator& first, Iterator const& last , Context const& context, RContext& rcontext, Attribute& attr) { - typedef detail::pass_variant_attribute<Parser, Attribute, Context> pass; + using pass = detail::pass_variant_attribute<Parser, Attribute, Context>; + using pseudo = traits::pseudo_attribute<Context, typename pass::type, Iterator>; + + typename pseudo::type attr_ = pseudo::call(first, last, pass::call(attr)); - typename pass::type attr_ = pass::call(attr); if (p.parse(first, last, context, rcontext, attr_)) { move_if_not_alternative<typename pass::is_alternative>::call(attr_, attr); @@ -255,7 +258,6 @@ namespace boost { namespace spirit { namespace x3 { namespace detail return false; } - template <typename Left, typename Right, typename Context, typename RContext> struct parse_into_container_impl<alternative<Left, Right>, Context, RContext> { diff --git a/boost/spirit/home/x3/operator/detail/sequence.hpp b/boost/spirit/home/x3/operator/detail/sequence.hpp index 9d3fe5c992..3ac21b61c9 100644 --- a/boost/spirit/home/x3/operator/detail/sequence.hpp +++ b/boost/spirit/home/x3/operator/detail/sequence.hpp @@ -304,11 +304,11 @@ namespace boost { namespace spirit { namespace x3 { namespace detail , Context const& context, RContext& rcontext, Attribute& attr , AttributeCategory) { - typedef typename Parser::left_type Left; - typedef typename Parser::right_type Right; - typedef partition_attribute<Left, Right, Attribute, Context> partition; - typedef typename partition::l_pass l_pass; - typedef typename partition::r_pass r_pass; + using Left = typename Parser::left_type; + using Right = typename Parser::right_type; + using partition = partition_attribute<Left, Right, Attribute, Context>; + using l_pass = typename partition::l_pass; + using r_pass = typename partition::r_pass; typename partition::l_part l_part = partition::left(attr); typename partition::r_part r_part = partition::right(attr); diff --git a/boost/spirit/home/x3/string/literal_string.hpp b/boost/spirit/home/x3/string/literal_string.hpp index 486dc807b3..55ed567368 100644 --- a/boost/spirit/home/x3/string/literal_string.hpp +++ b/boost/spirit/home/x3/string/literal_string.hpp @@ -106,6 +106,35 @@ namespace boost { namespace spirit { namespace x3 } #endif +#if defined(BOOST_SPIRIT_X3_UNICODE) + namespace unicode + { + inline literal_string<char32_t const*, char_encoding::unicode> + string(char32_t const* s) + { + return { s }; + } + + inline literal_string<std::basic_string<char32_t>, char_encoding::unicode> + string(std::basic_string<char32_t> const& s) + { + return { s }; + } + + inline literal_string<char32_t const*, char_encoding::unicode, unused_type> + lit(char32_t const* s) + { + return { s }; + } + + inline literal_string<std::basic_string<char32_t>, char_encoding::unicode, unused_type> + lit(std::basic_string<char32_t> const& s) + { + return { s }; + } + } +#endif + namespace ascii { inline literal_string<wchar_t const*, char_encoding::ascii> diff --git a/boost/spirit/home/x3/support/numeric_utils/extract_real.hpp b/boost/spirit/home/x3/support/numeric_utils/extract_real.hpp index fb5cd4d069..91b71e9829 100644 --- a/boost/spirit/home/x3/support/numeric_utils/extract_real.hpp +++ b/boost/spirit/home/x3/support/numeric_utils/extract_real.hpp @@ -29,47 +29,61 @@ namespace boost { namespace spirit { namespace x3 { namespace extension using x3::traits::pow10; template <typename T> - inline void + inline bool scale(int exp, T& n) { + constexpr auto max_exp = std::numeric_limits<T>::max_exponent10; + constexpr auto min_exp = std::numeric_limits<T>::min_exponent10; + if (exp >= 0) { - // $$$ Why is this failing for boost.math.concepts ? $$$ - //~ int nn = std::numeric_limits<T>::max_exponent10; - //~ BOOST_ASSERT(exp <= std::numeric_limits<T>::max_exponent10); + // return false if exp exceeds the max_exp + // do this check only for primitive types! + if (is_floating_point<T>() && exp > max_exp) + return false; n *= pow10<T>(exp); } else { - if (exp < std::numeric_limits<T>::min_exponent10) + if (exp < min_exp) { - n /= pow10<T>(-std::numeric_limits<T>::min_exponent10); - n /= pow10<T>(-exp + std::numeric_limits<T>::min_exponent10); + n /= pow10<T>(-min_exp); + + // return false if exp still exceeds the min_exp + // do this check only for primitive types! + exp += -min_exp; + if (is_floating_point<T>() && exp < min_exp) + return false; + + n /= pow10<T>(-exp); } else { n /= pow10<T>(-exp); } } + return true; } - inline void + inline bool scale(int /*exp*/, unused_type /*n*/) { // no-op for unused_type + return true; } template <typename T> - inline void + inline bool scale(int exp, int frac, T& n) { - scale(exp - frac, n); + return scale(exp - frac, n); } - inline void + inline bool scale(int /*exp*/, int /*frac*/, unused_type /*n*/) { // no-op for unused_type + return true; } inline float @@ -150,6 +164,7 @@ namespace boost { namespace spirit { namespace x3 } bool e_hit = false; + Iterator e_pos; int frac_digits = 0; // Try to parse the dot ('.' decimal point) @@ -178,6 +193,7 @@ namespace boost { namespace spirit { namespace x3 } // Now, let's see if we can parse the exponent prefix + e_pos = first; e_hit = p.parse_exp(first, last); } else @@ -191,6 +207,7 @@ namespace boost { namespace spirit { namespace x3 // If we must expect a dot and we didn't see an exponent // prefix, return no-match. + e_pos = first; e_hit = p.parse_exp(first, last); if (p.expect_dot && !e_hit) { @@ -208,19 +225,25 @@ namespace boost { namespace spirit { namespace x3 { // Got the exponent value. Scale the number by // exp-frac_digits. - extension::scale(exp, frac_digits, n); + if (!extension::scale(exp, frac_digits, n)) + return false; } else { - // Oops, no exponent, return no-match. - first = save; - return false; + // If there is no number, disregard the exponent altogether. + // by resetting 'first' prior to the exponent prefix (e|E) + first = e_pos; + + // Scale the number by -frac_digits. + if (!extension::scale(-frac_digits, n)) + return false; } } else if (frac_digits) { // No exponent found. Scale the number by -frac_digits. - extension::scale(-frac_digits, n); + if (!extension::scale(-frac_digits, n)) + return false; } // If we got a negative sign, negate the number diff --git a/boost/spirit/home/x3/support/numeric_utils/pow10.hpp b/boost/spirit/home/x3/support/numeric_utils/pow10.hpp index 1ff3a077a1..3a220d44d2 100644 --- a/boost/spirit/home/x3/support/numeric_utils/pow10.hpp +++ b/boost/spirit/home/x3/support/numeric_utils/pow10.hpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (c) 2001-2014 Joel de Guzman + Copyright (c) 2001-2019 Joel de Guzman Copyright (c) 2001-2011 Hartmut Kaiser http://spirit.sourceforge.net/ @@ -42,7 +42,11 @@ namespace boost { namespace spirit { namespace x3 { namespace traits } }; -#if (DBL_MAX_10_EXP == 308) // for IEEE-754 +#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) +#pragma message("Spirit X3 requires full c++14 support.") +#pragma message("Support for VS2015 will cease in the next Boost release.") +#pragma message("This code branch will be removed.") + template <> struct pow10_helper<double> { @@ -95,7 +99,46 @@ namespace boost { namespace spirit { namespace x3 { namespace traits return pow10_helper<double>::call(dim); } }; -#endif // for IEEE-754 +#else + template <typename T> + struct pow10_table + { + constexpr static std::size_t size = + std::numeric_limits<T>::max_exponent10; + + constexpr pow10_table() + : exponents() + { + exponents[0] = T(1); + for (auto i = 1; i != size; ++i) + exponents[i] = exponents[i-1] * T(10); + } + + T exponents[size]; + }; + + template <typename T> + struct native_pow10_helper + { + static T call(unsigned dim) + { + constexpr auto table = pow10_table<T>(); + return table.exponents[dim]; + } + }; + + template <> + struct pow10_helper<float> + : native_pow10_helper<float> {}; + + template <> + struct pow10_helper<double> + : native_pow10_helper<double> {}; + + template <> + struct pow10_helper<long double> + : native_pow10_helper<long double> {}; +#endif } template <typename T> diff --git a/boost/spirit/home/x3/support/traits/attribute_of.hpp b/boost/spirit/home/x3/support/traits/attribute_of.hpp index 93ee79b57b..1a6d760035 100644 --- a/boost/spirit/home/x3/support/traits/attribute_of.hpp +++ b/boost/spirit/home/x3/support/traits/attribute_of.hpp @@ -16,8 +16,8 @@ namespace boost { namespace spirit { namespace x3 { namespace traits { /////////////////////////////////////////////////////////////////////////// - // Get the attribute type of a component. By default, this gets the - // Component's attribute_type typedef or instantiates a nested attribute + // Get the attribute type of a component. By default, this gets the + // Component's attribute_type typedef or instantiates a nested attribute // metafunction. Components may specialize this if such an attribute_type // is not readily available (e.g. expensive to compute at compile time). /////////////////////////////////////////////////////////////////////////// @@ -28,28 +28,27 @@ namespace boost { namespace spirit { namespace x3 { namespace traits { template <typename Component, typename Context, typename Enable = void> struct default_attribute_of; - + template <typename Component, typename Context> - struct default_attribute_of<Component, Context, + struct default_attribute_of<Component, Context, typename disable_if_substitution_failure< typename Component::attribute_type>::type> : mpl::identity<typename Component::attribute_type> {}; - + template <typename Component, typename Context> - struct default_attribute_of<Component, Context, + struct default_attribute_of<Component, Context, typename disable_if_substitution_failure< typename Component::template attribute<Context>::type>::type> : Component::template attribute<Context> {}; - + template <typename Component, typename Context> struct default_attribute_of<Component, Context, typename enable_if_c<Component::is_pass_through_unary>::type> : attribute_of<typename Component::subject_type, Context>{}; } - + template <typename Component, typename Context, typename Enable> struct attribute_of : detail::default_attribute_of<Component, Context> {}; - }}}} #endif diff --git a/boost/spirit/home/x3/support/traits/pseudo_attribute.hpp b/boost/spirit/home/x3/support/traits/pseudo_attribute.hpp new file mode 100644 index 0000000000..4bfae46736 --- /dev/null +++ b/boost/spirit/home/x3/support/traits/pseudo_attribute.hpp @@ -0,0 +1,34 @@ +/*============================================================================= + Copyright (c) 2019 Joel de Guzman + + 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) +=============================================================================*/ +#if !defined(BOOST_SPIRIT_X3_PSEUDO_ATTRIBUTE_OF_MAY_15_2019_1012PM) +#define BOOST_SPIRIT_X3_PSEUDO_ATTRIBUTE_OF_MAY_15_2019_1012PM + +#include <utility> + +namespace boost { namespace spirit { namespace x3 { namespace traits +{ + /////////////////////////////////////////////////////////////////////////// + // Pseudo attributes are placeholders for parsers that can only know + // its actual attribute at parse time. This trait customization point + // provides a mechanism to convert the trait to the actual trait at + // parse time. + /////////////////////////////////////////////////////////////////////////// + template <typename Context, typename Attribute, typename Iterator + , typename Enable = void> + struct pseudo_attribute + { + using attribute_type = Attribute; + using type = Attribute; + + static type&& call(Iterator&, Iterator const&, attribute_type&& attr) + { + return std::forward<type>(attr); + } + }; +}}}} + +#endif diff --git a/boost/spirit/home/x3/support/traits/string_traits.hpp b/boost/spirit/home/x3/support/traits/string_traits.hpp index 44c8d144a8..acbc4346cf 100644 --- a/boost/spirit/home/x3/support/traits/string_traits.hpp +++ b/boost/spirit/home/x3/support/traits/string_traits.hpp @@ -11,129 +11,10 @@ #include <string> #include <boost/mpl/bool.hpp> -#include <boost/mpl/identity.hpp> namespace boost { namespace spirit { namespace x3 { namespace traits { /////////////////////////////////////////////////////////////////////////// - // Determine if T is a character type - /////////////////////////////////////////////////////////////////////////// - template <typename T> - struct is_char : mpl::false_ {}; - - template <typename T> - struct is_char<T const> : is_char<T> {}; - - template <> - struct is_char<char> : mpl::true_ {}; - - template <> - struct is_char<wchar_t> : mpl::true_ {}; - - /////////////////////////////////////////////////////////////////////////// - // Determine if T is a string - /////////////////////////////////////////////////////////////////////////// - template <typename T> - struct is_string : mpl::false_ {}; - - template <typename T> - struct is_string<T const> : is_string<T> {}; - - template <> - struct is_string<char const*> : mpl::true_ {}; - - template <> - struct is_string<wchar_t const*> : mpl::true_ {}; - - template <> - struct is_string<char*> : mpl::true_ {}; - - template <> - struct is_string<wchar_t*> : mpl::true_ {}; - - template <std::size_t N> - struct is_string<char[N]> : mpl::true_ {}; - - template <std::size_t N> - struct is_string<wchar_t[N]> : mpl::true_ {}; - - template <std::size_t N> - struct is_string<char const[N]> : mpl::true_ {}; - - template <std::size_t N> - struct is_string<wchar_t const[N]> : mpl::true_ {}; - - template <std::size_t N> - struct is_string<char(&)[N]> : mpl::true_ {}; - - template <std::size_t N> - struct is_string<wchar_t(&)[N]> : mpl::true_ {}; - - template <std::size_t N> - struct is_string<char const(&)[N]> : mpl::true_ {}; - - template <std::size_t N> - struct is_string<wchar_t const(&)[N]> : mpl::true_ {}; - - template <typename T, typename Traits, typename Allocator> - struct is_string<std::basic_string<T, Traits, Allocator> > : mpl::true_ {}; - - /////////////////////////////////////////////////////////////////////////// - // Get the underlying char type of a string - /////////////////////////////////////////////////////////////////////////// - template <typename T> - struct char_type_of; - - template <typename T> - struct char_type_of<T const> : char_type_of<T> {}; - - template <> - struct char_type_of<char> : mpl::identity<char> {}; - - template <> - struct char_type_of<wchar_t> : mpl::identity<wchar_t> {}; - - template <> - struct char_type_of<char const*> : mpl::identity<char const> {}; - - template <> - struct char_type_of<wchar_t const*> : mpl::identity<wchar_t const> {}; - - template <> - struct char_type_of<char*> : mpl::identity<char> {}; - - template <> - struct char_type_of<wchar_t*> : mpl::identity<wchar_t> {}; - - template <std::size_t N> - struct char_type_of<char[N]> : mpl::identity<char> {}; - - template <std::size_t N> - struct char_type_of<wchar_t[N]> : mpl::identity<wchar_t> {}; - - template <std::size_t N> - struct char_type_of<char const[N]> : mpl::identity<char const> {}; - - template <std::size_t N> - struct char_type_of<wchar_t const[N]> : mpl::identity<wchar_t const> {}; - - template <std::size_t N> - struct char_type_of<char(&)[N]> : mpl::identity<char> {}; - - template <std::size_t N> - struct char_type_of<wchar_t(&)[N]> : mpl::identity<wchar_t> {}; - - template <std::size_t N> - struct char_type_of<char const(&)[N]> : mpl::identity<char const> {}; - - template <std::size_t N> - struct char_type_of<wchar_t const(&)[N]> : mpl::identity<wchar_t const> {}; - - template <typename T, typename Traits, typename Allocator> - struct char_type_of<std::basic_string<T, Traits, Allocator> > - : mpl::identity<T> {}; - - /////////////////////////////////////////////////////////////////////////// // Get the C string from a string /////////////////////////////////////////////////////////////////////////// template <typename String> @@ -142,8 +23,6 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename String> struct extract_c_string { - typedef typename char_type_of<String>::type char_type; - template <typename T> static T const* call (T* str) { @@ -161,9 +40,7 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename T> struct extract_c_string<T const> { - typedef typename extract_c_string<T>::char_type char_type; - - static typename extract_c_string<T>::char_type const* call (T const str) + static decltype(auto) call(T const str) { return extract_c_string<T>::call(str); } @@ -173,9 +50,7 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename T> struct extract_c_string<T&> { - typedef typename extract_c_string<T>::char_type char_type; - - static typename extract_c_string<T>::char_type const* call (T& str) + static decltype(auto) call(T& str) { return extract_c_string<T>::call(str); } @@ -185,9 +60,7 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename T> struct extract_c_string<T const&> { - typedef typename extract_c_string<T>::char_type char_type; - - static typename extract_c_string<T>::char_type const* call (T const& str) + static decltype(auto) call(T const& str) { return extract_c_string<T>::call(str); } @@ -196,8 +69,6 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename T, typename Traits, typename Allocator> struct extract_c_string<std::basic_string<T, Traits, Allocator> > { - typedef T char_type; - typedef std::basic_string<T, Traits, Allocator> string; static T const* call (string const& str) @@ -207,29 +78,25 @@ namespace boost { namespace spirit { namespace x3 { namespace traits }; template <typename T> - typename extract_c_string<T*>::char_type const* - get_c_string(T* str) + decltype(auto) get_c_string(T* str) { return extract_c_string<T*>::call(str); } template <typename T> - typename extract_c_string<T const*>::char_type const* - get_c_string(T const* str) + decltype(auto) get_c_string(T const* str) { return extract_c_string<T const*>::call(str); } template <typename String> - typename extract_c_string<String>::char_type const* - get_c_string(String& str) + decltype(auto) get_c_string(String& str) { return extract_c_string<String>::call(str); } template <typename String> - typename extract_c_string<String>::char_type const* - get_c_string(String const& str) + decltype(auto) get_c_string(String const& str) { return extract_c_string<String>::call(str); } diff --git a/boost/spirit/home/x3/support/unused.hpp b/boost/spirit/home/x3/support/unused.hpp index 0486df3090..91471307a6 100644 --- a/boost/spirit/home/x3/support/unused.hpp +++ b/boost/spirit/home/x3/support/unused.hpp @@ -10,19 +10,12 @@ #include <iosfwd> -#if defined(BOOST_MSVC) -# pragma warning(push) -# pragma warning(disable: 4522) // multiple assignment operators specified warning -#endif - /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace x3 { struct unused_type { - unused_type() - { - } + unused_type() = default; template <typename T> unused_type(T const&) @@ -43,18 +36,6 @@ namespace boost { namespace spirit { namespace x3 return *this; } - unused_type const& - operator=(unused_type const&) const - { - return *this; - } - - unused_type& - operator=(unused_type const&) - { - return *this; - } - // unused_type can also masquerade as an empty context (see context.hpp) template <typename ID> @@ -77,8 +58,4 @@ namespace boost { namespace spirit { namespace x3 } }}} -#if defined(BOOST_MSVC) -# pragma warning(pop) -#endif - #endif diff --git a/boost/spirit/home/x3/support/utility/testing.hpp b/boost/spirit/home/x3/support/utility/testing.hpp deleted file mode 100644 index eb99f69204..0000000000 --- a/boost/spirit/home/x3/support/utility/testing.hpp +++ /dev/null @@ -1,269 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2015 Joel de Guzman - - 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) -=============================================================================*/ -#if !defined(BOOST_SPIRIT_X3_TEST_UTILITIES) -#define BOOST_SPIRIT_X3_TEST_UTILITIES - -#include <boost/regex.hpp> -#include <boost/filesystem.hpp> -#include <boost/filesystem/fstream.hpp> - -namespace boost { namespace spirit { namespace x3 { namespace testing -{ - namespace fs = boost::filesystem; - - //////////////////////////////////////////////////////////////////////////// - // compare - // - // Compares the contents of in with the template tem. The template - // may include embedded regular expressions marked up within re_prefix - // and re_suffix tags. For example, given the default RE markup, this - // template <%[0-9]+%> will match any integer in in. The function - // will return the first non-matching position. The flag full_match - // indicates a full match. It is possible for returned pos to be - // at the end of in (in.end()) while still returning full_match == - // false. In that case, we have a partial match. - //////////////////////////////////////////////////////////////////////////// - - template <typename Iterator> - struct compare_result - { - compare_result( - Iterator pos - , bool full_match - ) : pos(pos), full_match(full_match) {} - - Iterator pos; - bool full_match; - }; - - template <typename Range> - compare_result<typename Range::const_iterator> - compare( - Range const& in - , Range const& tem - , char const* re_prefix = "<%" - , char const* re_suffix = "%>" - ); - - //////////////////////////////////////////////////////////////////////////// - // compare - // - // 1) Call f, given the contents of input_path loaded in a string. - // The result of calling f is the output string. - // 2) Compare the result of calling f with expected template - // file (expect_path) using the low-level compare utility - // abive - //////////////////////////////////////////////////////////////////////////// - template <typename F> - bool compare( - fs::path input_path, fs::path expect_path - , F f - , char const* re_prefix = "<%" - , char const* re_suffix = "%>" - ); - - //////////////////////////////////////////////////////////////////////////// - // for_each_file - // - // For each *.input and *.expect file in a given directory, - // call the function f, passing in the *.input and *.expect paths. - //////////////////////////////////////////////////////////////////////////// - template <typename F> - int for_each_file(fs::path p, F f); - - //////////////////////////////////////////////////////////////////////////// - // load_file - // - // Load file into a string. - //////////////////////////////////////////////////////////////////////////// - std::string load(fs::path p); - - //////////////////////////////////////////////////////////////////////////// - // Implementation - //////////////////////////////////////////////////////////////////////////// - - template <typename Iterator> - inline bool is_regex( - Iterator& first - , Iterator last - , std::string& re - , char const* re_prefix - , char const* re_suffix - ) - { - boost::regex e(re_prefix + std::string("(.*?)") + re_suffix); - boost::match_results<Iterator> what; - if (boost::regex_search( - first, last, what, e - , boost::match_default | boost::match_continuous)) - { - re = what[1].str(); - first = what[0].second; - return true; - } - return false; - } - - template <typename Range> - inline compare_result<typename Range::const_iterator> - compare( - Range const& in - , Range const& tem - , char const* re_prefix - , char const* re_suffix - ) - { - typedef typename Range::const_iterator iter_t; - typedef compare_result<iter_t> compare_result_t; - - iter_t in_first = in.begin(); - iter_t in_last = in.end(); - iter_t tem_first = tem.begin(); - iter_t tem_last = tem.end(); - std::string re; - - while (in_first != in_last && tem_first != tem_last) - { - if (is_regex(tem_first, tem_last, re, re_prefix, re_suffix)) - { - boost::match_results<iter_t> what; - boost::regex e(re); - if (!boost::regex_search( - in_first, in_last, what, e - , boost::match_default | boost::match_continuous)) - { - // RE mismatch: exit now. - return compare_result_t(in_first, false); - } - else - { - // RE match: gobble the matching string. - in_first = what[0].second; - } - } - else - { - // Char by char comparison. Exit if we have a mismatch. - if (*in_first++ != *tem_first++) - return compare_result_t(in_first, false); - } - } - - // Ignore trailing spaces in template - bool has_trailing_nonspaces = false; - while (tem_first != tem_last) - { - if (!std::isspace(*tem_first++)) - { - has_trailing_nonspaces = true; - break; - } - } - while (in_first != in_last) - { - if (!std::isspace(*in_first++)) - { - has_trailing_nonspaces = true; - break; - } - } - // return a full match only if the template is fully matched and if there - // are no more characters to match in the source - return compare_result_t(in_first, !has_trailing_nonspaces); - } - - template <typename F> - inline int for_each_file(fs::path p, F f) - { - try - { - if (fs::exists(p) && fs::is_directory(p)) - { - for (auto i = fs::directory_iterator(p); i != fs::directory_iterator(); ++i) - { - auto ext = fs::extension(i->path()); - if (ext == ".input") - { - auto input_path = i->path(); - auto expect_path = input_path; - expect_path.replace_extension(".expect"); - f(input_path, expect_path); - } - } - } - else - { - std::cerr << "Directory: " << fs::absolute(p) << " does not exist." << std::endl; - return 1; - } - } - - catch (const fs::filesystem_error& ex) - { - std::cerr << ex.what() << '\n'; - return 1; - } - return 0; - } - - inline std::string load(fs::path p) - { - boost::filesystem::ifstream file(p); - if (!file) - return ""; - std::string contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); - return contents; - } - - template <typename F> - inline bool compare( - fs::path input_path, fs::path expect_path - , F f - , char const* re_prefix - , char const* re_suffix - ) - { - std::string output = f(load(input_path), input_path); - std::string expected = load(expect_path); - - auto result = compare(output, expected, re_prefix, re_suffix); - if (!result.full_match) - { - std::cout << "=============================================" << std::endl; - std::cout << "==== Mismatch Found:" << std::endl; - int line = 1; - int col = 1; - for (auto i = output.begin(); i != result.pos; ++i) - { - if (*i == '\n') - { - line++; - col = 0; - } - ++col; - } - - std::cerr - << "==== File: " << expect_path - << ", Line: " << line - << ", Column: " << col - << std::endl; - std::cerr << "=============================================" << std::endl; - - // Print output - std::cerr << output; - std::cerr << "=============================================" << std::endl; - std::cerr << "==== End" << std::endl; - std::cerr << "=============================================" << std::endl; - return false; - } - return true; - } - -}}}} - -#endif |