Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:37

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 //  Copyright (c) 2001-2011 Joel de Guzman
0003 // 
0004 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #if !defined(BOOST_SPIRIT_KARMA_SIMPLE_TRACE_APR_21_2010_0155PM)
0008 #define BOOST_SPIRIT_KARMA_SIMPLE_TRACE_APR_21_2010_0155PM
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/spirit/home/support/unused.hpp>
0015 #include <boost/spirit/home/karma/nonterminal/debug_handler_state.hpp>
0016 #include <boost/fusion/include/out.hpp>
0017 #include <iostream>
0018 
0019 //  The stream to use for debug output
0020 #if !defined(BOOST_SPIRIT_DEBUG_OUT)
0021 #define BOOST_SPIRIT_DEBUG_OUT std::cerr
0022 #endif
0023 
0024 //  number of tokens to print while debugging
0025 #if !defined(BOOST_SPIRIT_DEBUG_PRINT_SOME)
0026 #define BOOST_SPIRIT_DEBUG_PRINT_SOME 20
0027 #endif
0028 
0029 //  number of spaces to indent
0030 #if !defined(BOOST_SPIRIT_DEBUG_INDENT)
0031 #define BOOST_SPIRIT_DEBUG_INDENT 2
0032 #endif
0033 
0034 namespace boost { namespace spirit { namespace karma
0035 {
0036     struct simple_trace
0037     {
0038         int& get_indent() const
0039         {
0040             static int indent = 0;
0041             return indent;
0042         }
0043 
0044         void print_indent() const
0045         {
0046             int n = get_indent();
0047             n *= BOOST_SPIRIT_DEBUG_INDENT;
0048             for (int i = 0; i != n; ++i)
0049                 BOOST_SPIRIT_DEBUG_OUT << ' ';
0050         }
0051 
0052         template <typename Buffer>
0053         void print_some(char const* tag, Buffer const& buffer) const
0054         {
0055             print_indent();
0056             BOOST_SPIRIT_DEBUG_OUT << '<' << tag << '>' << std::flush;
0057             {
0058                 std::ostreambuf_iterator<char> out(BOOST_SPIRIT_DEBUG_OUT);
0059                 buffer.buffer_copy_to(out, BOOST_SPIRIT_DEBUG_PRINT_SOME);
0060             }
0061             BOOST_SPIRIT_DEBUG_OUT << "</" << tag << '>' << std::endl;
0062         }
0063 
0064         template <typename OutputIterator, typename Context, typename State
0065           , typename Buffer>
0066         void operator()(
0067             OutputIterator&, Context const& context
0068           , State state, std::string const& rule_name
0069           , Buffer const& buffer) const
0070         {
0071             switch (state)
0072             {
0073                 case pre_generate:
0074                     print_indent();
0075                     ++get_indent();
0076                     BOOST_SPIRIT_DEBUG_OUT
0077                         << '<' << rule_name << '>' << std::endl;
0078                     print_indent();
0079                     ++get_indent();
0080                     BOOST_SPIRIT_DEBUG_OUT << "<try>" << std::endl;;
0081                     print_indent();
0082                     BOOST_SPIRIT_DEBUG_OUT << "<attributes>";
0083                     traits::print_attribute(
0084                         BOOST_SPIRIT_DEBUG_OUT,
0085                         context.attributes
0086                     );
0087                     BOOST_SPIRIT_DEBUG_OUT << "</attributes>" << std::endl;
0088                     if (!fusion::empty(context.locals))
0089                     {
0090                         print_indent();
0091                         BOOST_SPIRIT_DEBUG_OUT
0092                             << "<locals>" << context.locals << "</locals>"
0093                             << std::endl;
0094                     }
0095                     --get_indent();
0096                     print_indent();
0097                     BOOST_SPIRIT_DEBUG_OUT << "</try>" << std::endl;;
0098                     break;
0099 
0100                 case successful_generate:
0101                     print_indent();
0102                     ++get_indent();
0103                     BOOST_SPIRIT_DEBUG_OUT << "<success>" << std::endl;
0104                     print_some("result", buffer);
0105                     if (!fusion::empty(context.locals))
0106                     {
0107                         print_indent();
0108                         BOOST_SPIRIT_DEBUG_OUT
0109                             << "<locals>" << context.locals << "</locals>"
0110                             << std::endl;
0111                     }
0112                     --get_indent();
0113                     print_indent();
0114                     BOOST_SPIRIT_DEBUG_OUT << "</success>" << std::endl;
0115                     --get_indent();
0116                     print_indent();
0117                     BOOST_SPIRIT_DEBUG_OUT 
0118                         << "</" << rule_name << '>' << std::endl;
0119                     break;
0120 
0121                 case failed_generate:
0122                     print_indent();
0123                     BOOST_SPIRIT_DEBUG_OUT << "<fail/>" << std::endl;
0124                     --get_indent();
0125                     print_indent();
0126                     BOOST_SPIRIT_DEBUG_OUT 
0127                         << "</" << rule_name << '>' << std::endl;
0128                     break;
0129             }
0130         }
0131     };
0132 }}}
0133 
0134 #endif