debug.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*=============================================================================
  2. Copyright (c) 2001-2003 Joel de Guzman
  3. Copyright (c) 2002-2003 Hartmut Kaiser
  4. http://spirit.sourceforge.net/
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_SPIRIT_DEBUG_MAIN_HPP)
  9. #define BOOST_SPIRIT_DEBUG_MAIN_HPP
  10. ///////////////////////////////////////////////////////////////////////////
  11. #if defined(BOOST_SPIRIT_DEBUG)
  12. #include <boost/spirit/home/classic/version.hpp>
  13. ///////////////////////////////////////////////////////////////////////////////
  14. //
  15. // Spirit.Debug includes and defines
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <iostream>
  19. ///////////////////////////////////////////////////////////////////////////
  20. //
  21. // The BOOST_SPIRIT_DEBUG_OUT defines the stream object, which should be used
  22. // for debug diagnostics. This defaults to std::cout.
  23. //
  24. ///////////////////////////////////////////////////////////////////////////
  25. #if !defined(BOOST_SPIRIT_DEBUG_OUT)
  26. #define BOOST_SPIRIT_DEBUG_OUT std::cout
  27. #endif
  28. ///////////////////////////////////////////////////////////////////////////
  29. //
  30. // The BOOST_SPIRIT_DEBUG_PRINT_SOME constant defines the number of characters
  31. // from the stream to be printed for diagnosis. This defaults to the first
  32. // 20 characters.
  33. //
  34. ///////////////////////////////////////////////////////////////////////////
  35. #if !defined(BOOST_SPIRIT_DEBUG_PRINT_SOME)
  36. #define BOOST_SPIRIT_DEBUG_PRINT_SOME 20
  37. #endif
  38. ///////////////////////////////////////////////////////////////////////////
  39. //
  40. // Additional BOOST_SPIRIT_DEBUG_FLAGS control the level of diagnostics printed
  41. // Basic constants are defined in debug/minimal.hpp.
  42. //
  43. ///////////////////////////////////////////////////////////////////////////
  44. #define BOOST_SPIRIT_DEBUG_FLAGS_NODES 0x0001 // node diagnostics
  45. #define BOOST_SPIRIT_DEBUG_FLAGS_ESCAPE_CHAR 0x0002 // escape_char_parse diagnostics
  46. #define BOOST_SPIRIT_DEBUG_FLAGS_TREES 0x0004 // parse tree/ast diagnostics
  47. #define BOOST_SPIRIT_DEBUG_FLAGS_CLOSURES 0x0008 // closure diagnostics
  48. #define BOOST_SPIRIT_DEBUG_FLAGS_SLEX 0x8000 // slex diagnostics
  49. #define BOOST_SPIRIT_DEBUG_FLAGS_MAX 0xFFFF // print maximal diagnostics
  50. #if !defined(BOOST_SPIRIT_DEBUG_FLAGS)
  51. #define BOOST_SPIRIT_DEBUG_FLAGS BOOST_SPIRIT_DEBUG_FLAGS_MAX
  52. #endif
  53. ///////////////////////////////////////////////////////////////////////////
  54. //
  55. // By default all nodes are traced (even those, not registered with
  56. // BOOST_SPIRIT_DEBUG_RULE et.al. - see below). The following constant may be
  57. // used to redefine this default.
  58. //
  59. ///////////////////////////////////////////////////////////////////////////
  60. #if !defined(BOOST_SPIRIT_DEBUG_TRACENODE)
  61. #define BOOST_SPIRIT_DEBUG_TRACENODE (true)
  62. #endif // !defined(BOOST_SPIRIT_DEBUG_TRACENODE)
  63. ///////////////////////////////////////////////////////////////////////////
  64. //
  65. // Helper macros for giving rules and subrules a name accessible through
  66. // parser_name() functions (see parser_names.hpp).
  67. //
  68. // Additionally, the macros BOOST_SPIRIT_DEBUG_RULE, SPIRIT_DEBUG_NODE and
  69. // BOOST_SPIRIT_DEBUG_GRAMMAR enable/disable the tracing of the
  70. // correspondingnode accordingly to the PP constant
  71. // BOOST_SPIRIT_DEBUG_TRACENODE.
  72. //
  73. // The macros BOOST_SPIRIT_DEBUG_TRACE_RULE, BOOST_SPIRIT_DEBUG_TRACE_NODE
  74. // and BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR allow to specify a flag to define,
  75. // whether the corresponding node is to be traced or not.
  76. //
  77. ///////////////////////////////////////////////////////////////////////////
  78. #if !defined(BOOST_SPIRIT_DEBUG_RULE)
  79. #define BOOST_SPIRIT_DEBUG_RULE(r) \
  80. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  81. register_node(&r, #r, BOOST_SPIRIT_DEBUG_TRACENODE)
  82. #endif // !defined(BOOST_SPIRIT_DEBUG_RULE)
  83. #if !defined(BOOST_SPIRIT_DEBUG_NODE)
  84. #define BOOST_SPIRIT_DEBUG_NODE(r) \
  85. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  86. register_node(&r, #r, BOOST_SPIRIT_DEBUG_TRACENODE)
  87. #endif // !defined(BOOST_SPIRIT_DEBUG_NODE)
  88. #if !defined(BOOST_SPIRIT_DEBUG_GRAMMAR)
  89. #define BOOST_SPIRIT_DEBUG_GRAMMAR(r) \
  90. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  91. register_node(&r, #r, BOOST_SPIRIT_DEBUG_TRACENODE)
  92. #endif // !defined(BOOST_SPIRIT_DEBUG_GRAMMAR)
  93. #if !defined(BOOST_SPIRIT_DEBUG_TRACE_RULE)
  94. #define BOOST_SPIRIT_DEBUG_TRACE_RULE(r, t) \
  95. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  96. register_node(&r, #r, (t))
  97. #endif // !defined(BOOST_SPIRIT_TRACE_RULE)
  98. #if !defined(BOOST_SPIRIT_DEBUG_TRACE_NODE)
  99. #define BOOST_SPIRIT_DEBUG_TRACE_NODE(r, t) \
  100. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  101. register_node(&r, #r, (t))
  102. #endif // !defined(BOOST_SPIRIT_DEBUG_TRACE_NODE)
  103. #if !defined(BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR)
  104. #define BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR(r, t) \
  105. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  106. register_node(&r, #r, (t))
  107. #endif // !defined(BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR)
  108. #if !defined(BOOST_SPIRIT_DEBUG_TRACE_RULE_NAME)
  109. #define BOOST_SPIRIT_DEBUG_TRACE_RULE_NAME(r, n, t) \
  110. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  111. register_node(&r, (n), (t))
  112. #endif // !defined(BOOST_SPIRIT_DEBUG_TRACE_RULE_NAME)
  113. #if !defined(BOOST_SPIRIT_DEBUG_TRACE_NODE_NAME)
  114. #define BOOST_SPIRIT_DEBUG_TRACE_NODE_NAME(r, n, t) \
  115. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  116. register_node(&r, (n), (t))
  117. #endif // !defined(BOOST_SPIRIT_DEBUG_TRACE_NODE_NAME)
  118. #if !defined(BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME)
  119. #define BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(r, n, t) \
  120. ::BOOST_SPIRIT_CLASSIC_NS::impl::get_node_registry(). \
  121. register_node(&r, (n), (t))
  122. #endif // !defined(BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME)
  123. //////////////////////////////////
  124. #include <boost/spirit/home/classic/debug/debug_node.hpp>
  125. #else
  126. //////////////////////////////////
  127. #include <boost/spirit/home/classic/debug/minimal.hpp>
  128. #endif // BOOST_SPIRIT_DEBUG
  129. #endif