Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:40

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003 
0004     http://www.boost.org/
0005 
0006     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0007     Software License, Version 1.0. (See accompanying file
0008     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 
0011 #if !defined(BOOST_CPP_INTLIT_GRAMMAR_HPP_2E1E70B1_F15C_4132_8554_10A231B0D91C_INCLUDED)
0012 #define BOOST_CPP_INTLIT_GRAMMAR_HPP_2E1E70B1_F15C_4132_8554_10A231B0D91C_INCLUDED
0013 
0014 #include <boost/wave/wave_config.hpp>
0015 
0016 #include <boost/spirit/include/classic_core.hpp>
0017 #include <boost/spirit/include/classic_closure.hpp>
0018 #include <boost/spirit/include/classic_assign_actor.hpp>
0019 #include <boost/spirit/include/classic_push_back_actor.hpp>
0020 
0021 #include <boost/spirit/include/phoenix1_operators.hpp>
0022 #include <boost/spirit/include/phoenix1_primitives.hpp>
0023 #include <boost/spirit/include/phoenix1_statements.hpp>
0024 
0025 #include <boost/wave/cpp_exceptions.hpp>
0026 #include <boost/wave/grammars/cpp_literal_grammar_gen.hpp>
0027 
0028 #if !defined(spirit_append_actor)
0029 #define spirit_append_actor(actor) boost::spirit::classic::push_back_a(actor)
0030 #define spirit_assign_actor(actor) boost::spirit::classic::assign_a(actor)
0031 #endif // !defined(spirit_append_actor)
0032 
0033 // this must occur after all of the includes and before any code appears
0034 #ifdef BOOST_HAS_ABI_HEADERS
0035 #include BOOST_ABI_PREFIX
0036 #endif
0037 
0038 ///////////////////////////////////////////////////////////////////////////////
0039 //
0040 //  Reusable grammar for parsing of C++ style integer literals
0041 //
0042 ///////////////////////////////////////////////////////////////////////////////
0043 namespace boost {
0044 namespace wave {
0045 namespace grammars {
0046 
0047 ///////////////////////////////////////////////////////////////////////////////
0048 namespace closures {
0049 
0050     struct intlit_closure
0051     :   boost::spirit::classic::closure<intlit_closure, uint_literal_type>
0052     {
0053         member1 val;
0054     };
0055 }
0056 
0057 ///////////////////////////////////////////////////////////////////////////////
0058 //  define, whether the rule's should generate some debug output
0059 #define TRACE_INTLIT_GRAMMAR \
0060     bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_INTLIT_GRAMMAR) \
0061     /**/
0062 
0063 struct intlit_grammar :
0064     boost::spirit::classic::grammar<intlit_grammar, closures::intlit_closure::context_t>
0065 {
0066     intlit_grammar(bool &is_unsigned_) : is_unsigned(is_unsigned_)
0067     {
0068         BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "intlit_grammar",
0069             TRACE_INTLIT_GRAMMAR);
0070     }
0071 
0072     template <typename ScannerT>
0073     struct definition
0074     {
0075         typedef boost::spirit::classic::rule<ScannerT> rule_t;
0076 
0077         rule_t int_lit;
0078         boost::spirit::classic::subrule<0> sub_int_lit;
0079         boost::spirit::classic::subrule<1> oct_lit;
0080         boost::spirit::classic::subrule<2> hex_lit;
0081         boost::spirit::classic::subrule<3> dec_lit;
0082 
0083         definition(intlit_grammar const &self)
0084         {
0085             using namespace boost::spirit::classic;
0086             namespace phx = phoenix;
0087 
0088 
0089             int_lit = (
0090                     sub_int_lit =
0091                         (   ch_p('0')[self.val = 0] >> (hex_lit | oct_lit)
0092                         |   dec_lit
0093                         )
0094                         >> !as_lower_d[
0095                                 (ch_p('u')[phx::var(self.is_unsigned) = true] || ch_p('l'))
0096                             |   (ch_p('l') || ch_p('u')[phx::var(self.is_unsigned) = true])
0097                             ]
0098                     ,
0099 
0100                     hex_lit =
0101                             (ch_p('X') | ch_p('x'))
0102                         >>  uint_parser<uint_literal_type, 16>()
0103                             [
0104                                 (self.val = phx::arg1,
0105                                  phx::var(self.is_unsigned) = true)
0106                             ]
0107                     ,
0108 
0109                     oct_lit =
0110                        !uint_parser<uint_literal_type, 8>()
0111                         [
0112                             (self.val = phx::arg1,
0113                              phx::var(self.is_unsigned) = true)
0114                         ]
0115                     ,
0116 
0117                     dec_lit =
0118                         uint_parser<uint_literal_type, 10>()
0119                         [
0120                             self.val = phx::arg1
0121                         ]
0122                     )
0123                 ;
0124 
0125             BOOST_SPIRIT_DEBUG_TRACE_RULE(int_lit, TRACE_INTLIT_GRAMMAR);
0126             BOOST_SPIRIT_DEBUG_TRACE_RULE(sub_int_lit, TRACE_INTLIT_GRAMMAR);
0127             BOOST_SPIRIT_DEBUG_TRACE_RULE(hex_lit, TRACE_INTLIT_GRAMMAR);
0128             BOOST_SPIRIT_DEBUG_TRACE_RULE(oct_lit, TRACE_INTLIT_GRAMMAR);
0129             BOOST_SPIRIT_DEBUG_TRACE_RULE(dec_lit, TRACE_INTLIT_GRAMMAR);
0130         }
0131 
0132         // start rule of this grammar
0133         rule_t const& start() const
0134         { return int_lit; }
0135     };
0136 
0137     bool &is_unsigned;
0138 };
0139 
0140 #undef TRACE_INTLIT_GRAMMAR
0141 
0142 ///////////////////////////////////////////////////////////////////////////////
0143 //
0144 //  The following function is defined here, to allow the separation of
0145 //  the compilation of the intlit_grammar from the function using it.
0146 //
0147 ///////////////////////////////////////////////////////////////////////////////
0148 
0149 #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
0150 #define BOOST_WAVE_INTLITGRAMMAR_GEN_INLINE
0151 #else
0152 #define BOOST_WAVE_INTLITGRAMMAR_GEN_INLINE inline
0153 #endif
0154 
0155 template <typename TokenT>
0156 BOOST_WAVE_INTLITGRAMMAR_GEN_INLINE
0157 uint_literal_type
0158 intlit_grammar_gen<TokenT>::evaluate(TokenT const &token,
0159     bool &is_unsigned)
0160 {
0161     intlit_grammar g(is_unsigned);
0162     uint_literal_type result = 0;
0163     typename TokenT::string_type const &token_val = token.get_value();
0164     using boost::spirit::classic::parse_info;
0165     parse_info<typename TokenT::string_type::const_iterator> hit =
0166         parse(token_val.begin(), token_val.end(), g[spirit_assign_actor(result)]);
0167 
0168     if (!hit.hit) {
0169         BOOST_WAVE_THROW(preprocess_exception, ill_formed_integer_literal,
0170             token_val.c_str(), token.get_position());
0171     }
0172     return result;
0173 }
0174 
0175 #undef BOOST_WAVE_INTLITGRAMMAR_GEN_INLINE
0176 
0177 ///////////////////////////////////////////////////////////////////////////////
0178 }   // namespace grammars
0179 }   // namespace wave
0180 }   // namespace boost
0181 
0182 // the suffix header occurs after all of the code
0183 #ifdef BOOST_HAS_ABI_HEADERS
0184 #include BOOST_ABI_SUFFIX
0185 #endif
0186 
0187 #endif // !defined(BOOST_CPP_INTLIT_GRAMMAR_HPP_2E1E70B1_F15C_4132_8554_10A231B0D91C_INCLUDED)