pp_utilities.hpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef BOOST_PARSER_DETAIL_PP_UTILITIES_HPP_INCLUDED
  2. #define BOOST_PARSER_DETAIL_PP_UTILITIES_HPP_INCLUDED
  3. // Copyright 2021 Peter Dimov
  4. // Copyright 2023 T. Zachary Laine
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // https://www.boost.org/LICENSE_1_0.txt
  7. #define BOOST_PARSER_PP_EXPAND(x) x
  8. #define BOOST_PARSER_PP_CAT(x, y) BOOST_PARSER_PP_CAT_I(x, y)
  9. #define BOOST_PARSER_PP_CAT_I(x, ...) x ## __VA_ARGS__
  10. #if defined(_MSC_VER) && !defined(__clang__)
  11. #define BOOST_PARSER_PP_FIRST(x) BOOST_PARSER_PP_FIRST_I((x))
  12. #define BOOST_PARSER_PP_FIRST_I(x) BOOST_PARSER_PP_FIRST_II x
  13. #define BOOST_PARSER_PP_FIRST_II(x, ...) x
  14. #else
  15. #define BOOST_PARSER_PP_FIRST(x) BOOST_PARSER_PP_FIRST_I(x)
  16. #define BOOST_PARSER_PP_FIRST_I(x, ...) x
  17. #endif
  18. #define BOOST_PARSER_PP_IS_PAREN_I(x) BOOST_PARSER_PP_CAT(BOOST_PARSER_PP_IS_PAREN_I_, BOOST_PARSER_PP_IS_PAREN_II x)
  19. #define BOOST_PARSER_PP_IS_PAREN_II(...) 0
  20. #define BOOST_PARSER_PP_IS_PAREN_I_0 1,
  21. #define BOOST_PARSER_PP_IS_PAREN_I_BOOST_PARSER_PP_IS_PAREN_II 0,
  22. #define BOOST_PARSER_PP_IS_PAREN(x) BOOST_PARSER_PP_FIRST(BOOST_PARSER_PP_IS_PAREN_I(x))
  23. #define BOOST_PARSER_PP_EMPTY
  24. #define BOOST_PARSER_PP_IS_EMPTY(x) BOOST_PARSER_PP_IS_EMPTY_I(BOOST_PARSER_PP_IS_PAREN(x), BOOST_PARSER_PP_IS_PAREN(x BOOST_PARSER_PP_EMPTY ()))
  25. #define BOOST_PARSER_PP_IS_EMPTY_I(x, y) BOOST_PARSER_PP_IS_EMPTY_II(x, y)
  26. #define BOOST_PARSER_PP_IS_EMPTY_II(x, y) BOOST_PARSER_PP_IS_EMPTY_III(x, y)
  27. #define BOOST_PARSER_PP_IS_EMPTY_III(x, y) BOOST_PARSER_PP_IS_EMPTY_III_ ## x ## y
  28. #define BOOST_PARSER_PP_IS_EMPTY_III_00 0
  29. #define BOOST_PARSER_PP_IS_EMPTY_III_01 1
  30. #define BOOST_PARSER_PP_IS_EMPTY_III_10 0
  31. #define BOOST_PARSER_PP_IS_EMPTY_III_11 0
  32. #define BOOST_PARSER_PP_CALL(F, a, x) BOOST_PARSER_PP_CAT(BOOST_PARSER_PP_CALL_I_, BOOST_PARSER_PP_IS_EMPTY(x))(F, a, x)
  33. #define BOOST_PARSER_PP_CALL_I_0(F, a, x) F(a, x)
  34. #define BOOST_PARSER_PP_CALL_I_1(F, a, x)
  35. #define BOOST_PARSER_PP_PARSE(x) BOOST_PARSER_PP_CAT(BOOST_PARSER_PP_PARSE_I_, BOOST_PARSER_PP_PARSE_II x)
  36. #define BOOST_PARSER_PP_PARSE_II(...) 0, (__VA_ARGS__),
  37. #define BOOST_PARSER_PP_PARSE_I_BOOST_PARSER_PP_PARSE_II 0, ~,
  38. #define BOOST_PARSER_PP_PARSE_I_0 1
  39. #if defined(_MSC_VER) && !defined(__clang__)
  40. #define BOOST_PARSER_PP_NAME(x) BOOST_PARSER_PP_NAME_I(BOOST_PARSER_PP_PARSE(x))
  41. #define BOOST_PARSER_PP_NAME_I(x) BOOST_PARSER_PP_NAME_II((x))
  42. #define BOOST_PARSER_PP_NAME_II(x) BOOST_PARSER_PP_NAME_III x
  43. #define BOOST_PARSER_PP_NAME_III(x, y, z) #z
  44. #else
  45. #define BOOST_PARSER_PP_NAME(x) BOOST_PARSER_PP_NAME_I(BOOST_PARSER_PP_PARSE(x))
  46. #define BOOST_PARSER_PP_NAME_I(x) BOOST_PARSER_PP_NAME_II(x)
  47. #define BOOST_PARSER_PP_NAME_II(x, y, z) #z
  48. #endif
  49. // template<class C, class F> constexpr auto mfn( F C::* p ) { return p; }
  50. // template<class C, class F> constexpr auto mfn( F * p ) { return p; }
  51. #define BOOST_PARSER_PP_POINTER(C, x) BOOST_PARSER_PP_POINTER_I(C, BOOST_PARSER_PP_PARSE(x))
  52. #define BOOST_PARSER_PP_EXPAND_V(...) __VA_ARGS__
  53. #if defined(_MSC_VER) && !defined(__clang__)
  54. #define BOOST_PARSER_PP_POINTER_I(C, x) BOOST_PARSER_PP_POINTER_II((C, x))
  55. #define BOOST_PARSER_PP_POINTER_II(x) BOOST_PARSER_PP_POINTER_III x
  56. #define BOOST_PARSER_PP_POINTER_III(C, x, y, z) BOOST_PARSER_PP_POINTER_III_##x(C, y, z)
  57. #define BOOST_PARSER_PP_POINTER_III_0(C, y, z) &C::z
  58. #define BOOST_PARSER_PP_POINTER_III_1(C, y, z) ::boost::describe::detail::mfn<C, BOOST_PARSER_PP_EXPAND_V y>(&C::z)
  59. #else
  60. #define BOOST_PARSER_PP_POINTER_I(C, x) BOOST_PARSER_PP_POINTER_II(C, x)
  61. #define BOOST_PARSER_PP_POINTER_II(C, x, y, z) BOOST_PARSER_PP_POINTER_III_##x(C, y, z)
  62. #define BOOST_PARSER_PP_POINTER_III_0(C, y, z) &C::z
  63. #define BOOST_PARSER_PP_POINTER_III_1(C, y, z) ::boost::describe::detail::mfn<C, BOOST_PARSER_PP_EXPAND_V y>(&C::z)
  64. #endif
  65. #endif // #ifndef BOOST_PARSER_DETAIL_PP_UTILITIES_HPP_INCLUDED