config.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright (C) 2020 T. Zachary Laine
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_PARSER_CONFIG_HPP
  7. #define BOOST_PARSER_CONFIG_HPP
  8. #include <boost/parser/detail/debug_assert.hpp>
  9. // Included for definition of __cpp_lib_concepts.
  10. #include <iterator>
  11. #ifdef BOOST_PARSER_DOXYGEN
  12. /** Boost.Parser uses assertions (`BOOST_ASSERT()`) in several places to
  13. indicate that your use of the library has an error in it. All of those
  14. places could have instead been ill-formed code, caught at compile time.
  15. It is far quicker and easier to determine exactly where in your code such
  16. an error is located if this is a runtime failure; you can just look at the
  17. stack in your favorite debugger. However, if you want to make these kinds
  18. of errors always ill-formed code, define this macro. */
  19. # define BOOST_PARSER_NO_RUNTIME_ASSERTIONS
  20. /** Asserts that the given condition is true. If
  21. `BOOST_PARSER_NO_RUNTIME_ASSERTIONS` macro is defined by the user,
  22. `BOOST_PARSER_ASSERT` expands to a compile-time `static_assert()`.
  23. Otherwise, it expands to a run-time `BOOST_ASSERT()`. Note that defining
  24. `BOOST_DISABLE_ASSERTS` disables the use of C `assert`, even when
  25. `BOOST_ASSERT` is unavailable. */
  26. # define BOOST_PARSER_ASSERT(condition)
  27. /** Boost.Parser will automatically use concepts to constrain templates when
  28. building in C++20 mode, if the compiler defines `__cpp_lib_concepts`. To
  29. disable the use of concepts, define this macro. */
  30. # define BOOST_PARSER_DISABLE_CONCEPTS
  31. /** Define this macro to use `boost::hana::tuple` instead of `std::tuple`
  32. throughout Boost.Parser. */
  33. # define BOOST_PARSER_USE_HANA_TUPLE
  34. /** Boost.Parser automatically treats aggregate structs as if they were
  35. tuples. It uses some metaprogramming to do this. The technique used has
  36. a hard limit on the number of data members a struct can have. Re-define
  37. this macro to change the hard limit. Note that large values may increase
  38. compile times. */
  39. # define BOOST_PARSER_MAX_AGGREGATE_SIZE 25
  40. /** The subrange template that is used throughout Boost.Parser. This will be
  41. `boost::parser::subrange` in C++17 builds, and `std::ranges::subrange` in
  42. all other builds. */
  43. # define BOOST_PARSER_SUBRANGE
  44. /** If you are using Visual Studio to run your program, and don't have a
  45. terminal in which to observe the output when parsing with `trace::on`,
  46. define this macro and you'll see the trace output in the Visual Studio
  47. debugger's output panel. This macro has no effect when `_MSC_VER` is not
  48. also defined. */
  49. # define BOOST_PARSER_TRACE_TO_VS_OUTPUT
  50. #else
  51. # ifdef BOOST_PARSER_NO_RUNTIME_ASSERTIONS
  52. # define BOOST_PARSER_ASSERT(condition) static_assert(condition)
  53. # elif defined(BOOST_PARSER_HAVE_BOOST_ASSERT)
  54. # define BOOST_PARSER_ASSERT(condition) BOOST_ASSERT(condition)
  55. # elif BOOST_DISABLE_ASSERTS
  56. # define BOOST_PARSER_ASSERT(condition) ((void)0)
  57. # else
  58. # define BOOST_PARSER_ASSERT(condition) assert(condition)
  59. # endif
  60. #endif
  61. // Follows logic in boost/config/detail/select_compiler_config.hpp.
  62. #if defined(__clang__) && !defined(__ibmxl__) && !defined(__CODEGEARC__)
  63. #elif defined(__GNUC__) && !defined(__ibmxl__)
  64. #define BOOST_PARSER_GCC
  65. #endif
  66. #if defined(__cpp_lib_constexpr_algorithms)
  67. # define BOOST_PARSER_ALGO_CONSTEXPR constexpr
  68. #else
  69. # define BOOST_PARSER_ALGO_CONSTEXPR
  70. #endif
  71. #if defined(__cpp_lib_concepts) && !defined(BOOST_PARSER_DISABLE_CONCEPTS) && \
  72. (!defined(__clang_major__) || 16 <= __clang_major__)
  73. # define BOOST_PARSER_USE_CONCEPTS 1
  74. #else
  75. # define BOOST_PARSER_USE_CONCEPTS 0
  76. #endif
  77. #if defined(__cpp_lib_ranges) && BOOST_PARSER_USE_CONCEPTS
  78. # define BOOST_PARSER_SUBRANGE std::ranges::subrange
  79. #else
  80. # include <boost/parser/subrange.hpp>
  81. # define BOOST_PARSER_SUBRANGE boost::parser::subrange
  82. #endif
  83. #if defined(BOOST_PARSER_USE_HANA_TUPLE)
  84. # define BOOST_PARSER_USE_STD_TUPLE 0
  85. #else
  86. # define BOOST_PARSER_USE_STD_TUPLE 1
  87. #endif
  88. #if !defined(BOOST_PARSER_MAX_AGGREGATE_SIZE)
  89. # define BOOST_PARSER_MAX_AGGREGATE_SIZE 25
  90. #endif
  91. // VS2019 and VS2017 need conditional constexpr in some places, even in C++17 mode.
  92. #if !defined(_MSC_VER) || 1930 <= _MSC_VER
  93. # define BOOST_PARSER_CONSTEXPR constexpr
  94. #else
  95. # define BOOST_PARSER_CONSTEXPR
  96. #endif
  97. #if defined(_MSC_VER) && defined(BOOST_PARSER_TRACE_TO_VS_OUTPUT)
  98. # define BOOST_PARSER_TRACE_OSTREAM boost::parser::detail::vs_cout
  99. #else
  100. # define BOOST_PARSER_TRACE_OSTREAM std::cout
  101. #endif
  102. #endif