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_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED)
0012 #define BOOST_CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED
0013 
0014 #include <boost/spirit/include/classic_core.hpp>
0015 #include <boost/spirit/include/classic_parse_tree.hpp>
0016 #include <boost/spirit/include/classic_confix.hpp>
0017 #include <boost/spirit/include/classic_lists.hpp>
0018 
0019 #include <boost/wave/wave_config.hpp>
0020 #include <boost/wave/token_ids.hpp>
0021 #include <boost/wave/grammars/cpp_predef_macros_gen.hpp>
0022 #include <boost/wave/util/pattern_parser.hpp>
0023 
0024 // this must occur after all of the includes and before any code appears
0025 #ifdef BOOST_HAS_ABI_HEADERS
0026 #include BOOST_ABI_PREFIX
0027 #endif
0028 
0029 ///////////////////////////////////////////////////////////////////////////////
0030 namespace boost {
0031 namespace wave {
0032 namespace grammars {
0033 
0034 ///////////////////////////////////////////////////////////////////////////////
0035 //  define, whether the rule's should generate some debug output
0036 #define TRACE_PREDEF_MACROS_GRAMMAR \
0037     bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_PREDEF_MACROS_GRAMMAR) \
0038     /**/
0039 
0040 ///////////////////////////////////////////////////////////////////////////////
0041 // Encapsulation of the grammar for command line driven predefined macros.
0042 struct predefined_macros_grammar :
0043     public boost::spirit::classic::grammar<predefined_macros_grammar>
0044 {
0045     template <typename ScannerT>
0046     struct definition
0047     {
0048         // 'normal' (parse_tree generating) rule type
0049         typedef boost::spirit::classic::rule<
0050                 ScannerT, boost::spirit::classic::dynamic_parser_tag>
0051             rule_type;
0052 
0053         rule_type plain_define, macro_definition, macro_parameters;
0054 
0055         definition(predefined_macros_grammar const &/*self*/)
0056         {
0057             // import the spirit and cpplexer namespaces here
0058             using namespace boost::spirit::classic;
0059             using namespace boost::wave;
0060             using namespace boost::wave::util;
0061 
0062             // set the rule id's for later use
0063             plain_define.set_id(BOOST_WAVE_PLAIN_DEFINE_ID);
0064             macro_parameters.set_id(BOOST_WAVE_MACRO_PARAMETERS_ID);
0065             macro_definition.set_id(BOOST_WAVE_MACRO_DEFINITION_ID);
0066 
0067             // recognizes command line defined macro syntax, i.e.
0068             //  -DMACRO
0069             //  -DMACRO=
0070             //  -DMACRO=value
0071             //  -DMACRO(x)
0072             //  -DMACRO(x)=
0073             //  -DMACRO(x)=value
0074 
0075             // This grammar resembles the overall structure of the cpp_grammar to
0076             // make it possible to reuse the parse tree traversal code
0077             plain_define
0078                 =   (   ch_p(T_IDENTIFIER)
0079                     |   pattern_p(KeywordTokenType,
0080                             TokenTypeMask|PPTokenFlag)
0081                     |   pattern_p(OperatorTokenType|AltExtTokenType,
0082                             ExtTokenTypeMask|PPTokenFlag)   // and, bit_and etc.
0083                     |   pattern_p(BoolLiteralTokenType,
0084                             TokenTypeMask|PPTokenFlag)  // true/false
0085                     )
0086                     >>  !macro_parameters
0087                     >>  !macro_definition
0088                 ;
0089 
0090             // parameter list
0091             macro_parameters
0092                 =   confix_p(
0093                         no_node_d[ch_p(T_LEFTPAREN) >> *ch_p(T_SPACE)],
0094                        !list_p(
0095                             (   ch_p(T_IDENTIFIER)
0096                             |   pattern_p(KeywordTokenType,
0097                                     TokenTypeMask|PPTokenFlag)
0098                             |   pattern_p(OperatorTokenType|AltExtTokenType,
0099                                     ExtTokenTypeMask|PPTokenFlag)   // and, bit_and etc.
0100                             |   pattern_p(BoolLiteralTokenType,
0101                                     TokenTypeMask|PPTokenFlag)  // true/false
0102 
0103 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
0104                             |   ch_p(T_ELLIPSIS)
0105 #endif
0106                             ),
0107                             no_node_d
0108                             [
0109                                 *ch_p(T_SPACE) >> ch_p(T_COMMA) >> *ch_p(T_SPACE)
0110                             ]
0111                         ),
0112                         no_node_d[*ch_p(T_SPACE) >> ch_p(T_RIGHTPAREN)]
0113                     )
0114                 ;
0115 
0116             // macro body (anything left until eol)
0117             macro_definition
0118                 =   no_node_d[ch_p(T_ASSIGN)]
0119                     >> *anychar_p
0120                 ;
0121 
0122             BOOST_SPIRIT_DEBUG_TRACE_RULE(plain_define, TRACE_PREDEF_MACROS_GRAMMAR);
0123             BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_definition, TRACE_PREDEF_MACROS_GRAMMAR);
0124             BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_parameters, TRACE_PREDEF_MACROS_GRAMMAR);
0125         }
0126 
0127         // start rule of this grammar
0128         rule_type const& start() const
0129         { return plain_define; }
0130     };
0131 
0132     predefined_macros_grammar()
0133     {
0134         BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this,
0135             "predefined_macros_grammar", TRACE_PREDEF_MACROS_GRAMMAR);
0136     }
0137 
0138 };
0139 
0140 ///////////////////////////////////////////////////////////////////////////////
0141 #undef TRACE_PREDEF_MACROS_GRAMMAR
0142 
0143 ///////////////////////////////////////////////////////////////////////////////
0144 //
0145 //  The following parse function is defined here, to allow the separation of
0146 //  the compilation of the cpp_predefined_macros_grammar from the function
0147 //  using it.
0148 //
0149 ///////////////////////////////////////////////////////////////////////////////
0150 
0151 #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
0152 #define BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
0153 #else
0154 #define BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE inline
0155 #endif
0156 
0157 template <typename LexIteratorT>
0158 BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
0159 boost::spirit::classic::tree_parse_info<LexIteratorT>
0160 predefined_macros_grammar_gen<LexIteratorT>::parse_predefined_macro (
0161     LexIteratorT const &first, LexIteratorT const &last)
0162 {
0163     predefined_macros_grammar g;
0164     return boost::spirit::classic::pt_parse (first, last, g);
0165 }
0166 
0167 #undef BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
0168 
0169 ///////////////////////////////////////////////////////////////////////////////
0170 }   // namespace grammars
0171 }   // namespace wave
0172 }   // namespace boost
0173 
0174 // the suffix header occurs after all of the code
0175 #ifdef BOOST_HAS_ABI_HEADERS
0176 #include BOOST_ABI_SUFFIX
0177 #endif
0178 
0179 #endif // !defined(BOOST_CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED)