diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a3e1e28e..64d20df71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -194,7 +194,6 @@ jobs: libs/core \ libs/describe \ libs/detail \ - libs/endian \ libs/function \ libs/function_types \ libs/functional \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 50eeafe47..59596d722 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,10 +181,6 @@ list(APPEND boost_spirit_x4_boost_deps mp11) list(APPEND boost_spirit_x4_boost_deps predef) list(APPEND boost_spirit_x4_boost_deps io) -# Everything required by `endian` (manually confirmed) -list(APPEND boost_spirit_x4_boost_deps endian) # used in binary parsers -list(APPEND boost_spirit_x4_boost_deps config) - # Everything required by `preprocessor` (manually confirmed) list(APPEND boost_spirit_x4_boost_deps preprocessor) diff --git a/README.md b/README.md index 0285c2be4..c0cd39bf4 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ We're trying hard to reduce these dependencies. We aim to remove these entirely ```console git submodule update --init --depth 1 --recursive -- \ tools/build tools/boost_install libs/assert libs/bind libs/config \ - libs/container_hash libs/core libs/describe libs/detail libs/endian \ + libs/container_hash libs/core libs/describe libs/detail \ libs/function libs/function_types libs/functional libs/fusion \ libs/integer libs/io libs/mp11 libs/mpl libs/predef libs/preprocessor \ libs/static_assert libs/throw_exception libs/tuple libs/type_index \ diff --git a/include/boost/spirit/x4/binary.hpp b/include/boost/spirit/x4/binary.hpp deleted file mode 100644 index 956ac1f30..000000000 --- a/include/boost/spirit/x4/binary.hpp +++ /dev/null @@ -1,192 +0,0 @@ -#ifndef BOOST_SPIRIT_X4_BINARY_HPP -#define BOOST_SPIRIT_X4_BINARY_HPP - -/*============================================================================= - Copyright (c) 2001-2011 Hartmut Kaiser - Copyright (c) 2001-2011 Joel de Guzman - Copyright (c) 2025 Nana Sakisaka - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -==============================================================================*/ - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include - -namespace boost::spirit::x4 { - -template -struct binary_lit_parser : parser> -{ - using attribute_type = unused_type; - - template - requires - (!std::is_same_v, binary_lit_parser>) && - std::is_constructible_v - constexpr explicit binary_lit_parser(U&& n) - noexcept(std::is_nothrow_constructible_v) - : n_(std::forward(n)) - {} - - template Se, class Context, X4Attribute Attr> - [[nodiscard]] constexpr bool - parse(It& first, Se const& last, Context const& ctx, Attr& attr_param) const - // TODO: noexcept - { - x4::skip_over(first, last, ctx); - - unsigned char const* bytes = n_.data(); - - It it = first; - for (unsigned int i = 0; i < sizeof(n_); ++i) { - if (it == last || *bytes++ != static_cast(*it++)) { - return false; - } - } - - first = it; - x4::move_to(n_, attr_param); - return true; - } - -private: - boost::endian::endian_arithmetic n_; -}; - -template -struct any_binary_parser : parser> -{ - static_assert(std::is_trivially_copyable_v); - - using attribute_type = T; - - template Se, class Context, X4Attribute Attr> - [[nodiscard]] constexpr bool - parse(It& first, Se const& last, Context const& ctx, Attr& attr_param) const - // TODO: noexcept - { - x4::skip_over(first, last, ctx); - - // Properly align the buffer for performance reasons - alignas(T) unsigned char buf[sizeof(T)]; - unsigned char* bytes = buf; - - It it = first; - for (unsigned int i = 0; i < sizeof(T); ++i) { - if (it == last) return false; - *bytes++ = *it++; - } - - first = it; - - static_assert(bits % CHAR_BIT == 0, "Boost.Endian supports only multiples of CHAR_BIT"); - x4::move_to( - endian::endian_load(buf), - attr_param - ); - return true; - } - - [[nodiscard]] static constexpr binary_lit_parser, endian, bits> - operator()(T&& n) - noexcept(std::is_nothrow_constructible_v, endian, bits>, T>) - { - return binary_lit_parser, endian, bits>{std::forward(n)}; - } -}; - - -#define BOOST_SPIRIT_X4_BINARY_PARSER(name, endiantype, attrtype, bits) \ - namespace parsers { \ - [[maybe_unused]] inline constexpr any_binary_parser name{}; \ - } /* parsers */ \ - using parsers::name; - -BOOST_SPIRIT_X4_BINARY_PARSER(byte_, native, uint_least8_t, 8) -BOOST_SPIRIT_X4_BINARY_PARSER(word, native, uint_least16_t, 16) -BOOST_SPIRIT_X4_BINARY_PARSER(big_word, big, uint_least16_t, 16) -BOOST_SPIRIT_X4_BINARY_PARSER(little_word, little, uint_least16_t, 16) -BOOST_SPIRIT_X4_BINARY_PARSER(dword, native, uint_least32_t, 32) -BOOST_SPIRIT_X4_BINARY_PARSER(big_dword, big, uint_least32_t, 32) -BOOST_SPIRIT_X4_BINARY_PARSER(little_dword, little, uint_least32_t, 32) - -#ifdef BOOST_HAS_LONG_LONG -BOOST_SPIRIT_X4_BINARY_PARSER(qword, native, uint_least64_t, 64) -BOOST_SPIRIT_X4_BINARY_PARSER(big_qword, big, uint_least64_t, 64) -BOOST_SPIRIT_X4_BINARY_PARSER(little_qword, little, uint_least64_t, 64) -#endif - -BOOST_SPIRIT_X4_BINARY_PARSER(bin_float, native, float, sizeof(float) * CHAR_BIT) -BOOST_SPIRIT_X4_BINARY_PARSER(big_bin_float, big, float, sizeof(float) * CHAR_BIT) -BOOST_SPIRIT_X4_BINARY_PARSER(little_bin_float, little, float, sizeof(float) * CHAR_BIT) -BOOST_SPIRIT_X4_BINARY_PARSER(bin_double, native, double, sizeof(double) * CHAR_BIT) -BOOST_SPIRIT_X4_BINARY_PARSER(big_bin_double, big, double, sizeof(double) * CHAR_BIT) -BOOST_SPIRIT_X4_BINARY_PARSER(little_bin_double, little, double, sizeof(double) * CHAR_BIT) - -#undef BOOST_SPIRIT_X4_BINARY_PARSER - - -template -struct get_info> -{ - using result_type = std::string; - - [[nodiscard]] constexpr std::string - operator()(any_binary_parser const&) const - { - return "little-endian binary"; - } -}; - -template -struct get_info> -{ - using result_type = std::string; - - [[nodiscard]] constexpr std::string - operator()(any_binary_parser const&) const - { - return "big-endian binary"; - } -}; - -template -struct get_info> -{ - using result_type = std::string; - - [[nodiscard]] constexpr std::string - operator()(binary_lit_parser const&) const - { - return "little-endian binary"; - } -}; - -template -struct get_info> -{ - using result_type = std::string; - - [[nodiscard]] constexpr - std::string operator()(binary_lit_parser const&) const - { - return "big-endian binary"; - } -}; - -} // boost::spirit::x4 - -#endif diff --git a/test/x4/CMakeLists.txt b/test/x4/CMakeLists.txt index dac31a2f4..6fc4d9af8 100644 --- a/test/x4/CMakeLists.txt +++ b/test/x4/CMakeLists.txt @@ -56,7 +56,6 @@ x4_define_tests( attr attribute attribute_type_check - binary bool char char_class diff --git a/test/x4/Jamfile b/test/x4/Jamfile index 79c548437..876fcbdc4 100644 --- a/test/x4/Jamfile +++ b/test/x4/Jamfile @@ -67,7 +67,6 @@ run actions.cpp catch2 ; run alternative.cpp catch2 ; run and_predicate.cpp catch2 ; run attr.cpp catch2 ; -run binary.cpp catch2 ; run bool.cpp catch2 ; run char.cpp catch2 ; run char_class.cpp catch2 ; diff --git a/test/x4/binary.cpp b/test/x4/binary.cpp deleted file mode 100644 index 50fb850eb..000000000 --- a/test/x4/binary.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2011 Hartmut Kaiser - Copyright (c) 2025 Nana Sakisaka - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -==============================================================================*/ - -#include "test.hpp" - -#include - -#include - -#include - -namespace { - -template -constexpr auto binary_test(char const (&binstr)[N], Args&&... args) -{ - return spirit_test::parse(std::string_view{binstr, N - 1}, std::forward(args)...); -} - -} // anonymous - -TEST_CASE("binary") -{ - using x4::byte_; - using x4::word; - using x4::dword; - using x4::big_word; - using x4::big_dword; - using x4::little_word; - using x4::little_dword; - - using x4::qword; - using x4::big_qword; - using x4::little_qword; - - using x4::bin_float; - using x4::big_bin_float; - using x4::little_bin_float; - using x4::bin_double; - using x4::big_bin_double; - using x4::little_bin_double; - - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(byte_); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(word); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(dword); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_word); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_dword); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_word); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_dword); - - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(qword); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_qword); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_qword); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(bin_float); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_bin_float); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_bin_float); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(bin_double); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_bin_double); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_bin_double); - -// TODO: boost::endian::endian_arithmetic value constructor is not constexpr -#if 0 - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(byte_(1)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(word(1)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(dword(1)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_word(1)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_dword(1)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_word(1)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_dword(1)); - - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(qword(1)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_qword(1)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_qword(1)); - - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(bin_float(1.0f)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_bin_float(1.0f)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_bin_float(1.0f)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(bin_double(1.0)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(big_bin_double(1.0)); - BOOST_SPIRIT_X4_ASSERT_CONSTEXPR_CTORS(little_bin_double(1.0)); -#endif - - if constexpr (std::endian::native == std::endian::little) - { - { - std::uint8_t uc = 0; - REQUIRE(parse("\x01", byte_, uc)); - CHECK(uc == 0x01); - } - { - std::uint16_t us = 0; - REQUIRE(parse("\x01\x02", word, us)); - CHECK(us == 0x0201); - } - { - std::uint32_t ui = 0; - REQUIRE(parse("\x01\x02\x03\x04", dword, ui)); - CHECK(ui == 0x04030201); - } - { - std::uint64_t ul = 0; - REQUIRE(parse("\x01\x02\x03\x04\x05\x06\x07\x08", qword, ul)); - CHECK(ul == 0x0807060504030201LL); - } - { - float f = 0; - REQUIRE(binary_test("\x00\x00\x80\x3f", bin_float, f)); - CHECK(f == 1.0f); - } - { - double d = 0; - REQUIRE(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", bin_double, d)); - CHECK(d == 1.0); - } - } - else // big endian - { - { - std::uint8_t uc = 0; - REQUIRE(parse("\x01", byte_, uc)); - CHECK(uc == 0x01); - } - { - std::uint16_t us = 0; - REQUIRE(parse("\x01\x02", word, us)); - CHECK(us == 0x0102); - } - { - std::uint32_t ui = 0; - REQUIRE(parse("\x01\x02\x03\x04", dword, ui)); - CHECK(ui == 0x01020304); - } - { - std::uint64_t ul = 0; - REQUIRE(parse("\x01\x02\x03\x04\x05\x06\x07\x08", qword, ul)); - CHECK(ul == 0x0102030405060708LL); - } - { - float f = 0; - REQUIRE(binary_test("\x3f\x80\x00\x00", bin_float, f)); - CHECK(f == 1.0f); - } - { - double d = 0; - REQUIRE(binary_test("\x3f\xf0\x00\x00\x00\x00\x00\x00", bin_double, d)); - CHECK(d == 1.0); - } - } - - if constexpr (std::endian::native == std::endian::little) - { - CHECK(parse("\x01", byte_(0x01))); - CHECK(parse("\x01\x02", word(0x0201))); - CHECK(parse("\x01\x02\x03\x04", dword(0x04030201))); - - CHECK(parse("\x01\x02\x03\x04\x05\x06\x07\x08", qword(0x0807060504030201LL))); - - CHECK(binary_test("\x00\x00\x80\x3f", bin_float(1.0f))); - CHECK(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", bin_double(1.0))); - } - else // big endian - { - CHECK(parse("\x01", byte_(0x01))); - CHECK(parse("\x01\x02", word(0x0102))); - CHECK(parse("\x01\x02\x03\x04", dword(0x01020304))); - - CHECK(parse("\x01\x02\x03\x04\x05\x06\x07\x08", qword(0x0102030405060708LL))); - - CHECK(binary_test("\x3f\x80\x00\x00", bin_float(1.0f))); - CHECK(binary_test("\x3f\xf0\x00\x00\x00\x00\x00\x00", bin_double(1.0))); - } - - { - // big endian binaries - { - std::uint16_t us = 0; - REQUIRE(parse("\x01\x02", big_word, us)); - CHECK(us == 0x0102); - } - { - std::uint32_t ui = 0; - REQUIRE(parse("\x01\x02\x03\x04", big_dword, ui)); - CHECK(ui == 0x01020304); - } - { - std::uint64_t ul = 0; - REQUIRE(parse("\x01\x02\x03\x04\x05\x06\x07\x08", big_qword, ul)); - CHECK(ul == 0x0102030405060708LL); - } - { - float f = 0; - REQUIRE(binary_test("\x3f\x80\x00\x00", big_bin_float, f)); - CHECK(f == 1.0f); - } - { - double d = 0; - REQUIRE(binary_test("\x3f\xf0\x00\x00\x00\x00\x00\x00", big_bin_double, d)); - CHECK(d == 1.0); - } - } - - { - CHECK(parse("\x01\x02", big_word(0x0102))); - CHECK(parse("\x01\x02\x03\x04", big_dword(0x01020304))); - - CHECK(parse("\x01\x02\x03\x04\x05\x06\x07\x08", big_qword(0x0102030405060708LL))); - - CHECK(binary_test("\x3f\x80\x00\x00", big_bin_float(1.0f))); - CHECK(binary_test("\x3f\xf0\x00\x00\x00\x00\x00\x00", big_bin_double(1.0))); - } - - { - // little endian binaries - { - std::uint16_t us = 0; - REQUIRE(parse("\x01\x02", little_word, us)); - CHECK(us == 0x0201); - } - { - std::uint32_t ui = 0; - REQUIRE(parse("\x01\x02\x03\x04", little_dword, ui)); - CHECK(ui == 0x04030201); - } - - { - std::uint64_t ul = 0; - REQUIRE(parse("\x01\x02\x03\x04\x05\x06\x07\x08", little_qword, ul)); - CHECK(ul == 0x0807060504030201LL); - } - - { - float f = 0; - REQUIRE(binary_test("\x00\x00\x80\x3f", little_bin_float, f)); - CHECK(f == 1.0f); - } - { - double d = 0; - REQUIRE(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", little_bin_double, d)); - CHECK(d == 1.0); - } - } - - { - CHECK(parse("\x01\x02", little_word(0x0201))); - CHECK(parse("\x01\x02\x03\x04", little_dword(0x04030201))); - - CHECK(parse("\x01\x02\x03\x04\x05\x06\x07\x08", little_qword(0x0807060504030201LL))); - - CHECK(binary_test("\x00\x00\x80\x3f", little_bin_float(1.0f))); - CHECK(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", little_bin_double(1.0))); - } -} diff --git a/test/x4/expect.cpp b/test/x4/expect.cpp index 26c20fa42..7eefe542a 100644 --- a/test/x4/expect.cpp +++ b/test/x4/expect.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -309,7 +308,6 @@ TEST_CASE("expect") using x4::eoi; using x4::eol; //using x4::attr; - using x4::dword; using x4::int_; using x4::shared_symbols; using x4::with; @@ -533,15 +531,11 @@ TEST_CASE("expect") CHECK(n == 12); } - // binary, numeric, char, string parsers + // numeric, char, string parsers { - TEST_SUCCESS_PASS("12abcd", +digit > dword); TEST_SUCCESS_PASS("abc12", +alpha > int_); TEST_SUCCESS_PASS("12a", +digit > lit('a')); - TEST_FAILURE("12abc", +digit > dword, { - CHECK(where == "abc"sv); - }); TEST_FAILURE("abc", +alpha > int_, { CHECK(where == ""sv); }); diff --git a/test/x4/iterator.cpp b/test/x4/iterator.cpp index 9e434cac1..44636dc8d 100644 --- a/test/x4/iterator.cpp +++ b/test/x4/iterator.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include