1 | /*============================================================================= |
---|
2 | Boost.Wave: A Standard compliant C++ preprocessor library |
---|
3 | |
---|
4 | http://www.boost.org/ |
---|
5 | |
---|
6 | Copyright (c) 2001-2005 Hartmut Kaiser. Distributed under the Boost |
---|
7 | Software License, Version 1.0. (See accompanying file |
---|
8 | LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
9 | =============================================================================*/ |
---|
10 | |
---|
11 | #if !defined(CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED) |
---|
12 | #define CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED |
---|
13 | |
---|
14 | #include <boost/spirit/tree/parse_tree.hpp> |
---|
15 | |
---|
16 | #include <boost/wave/wave_config.hpp> |
---|
17 | #include <boost/wave/language_support.hpp> |
---|
18 | |
---|
19 | /////////////////////////////////////////////////////////////////////////////// |
---|
20 | namespace boost { |
---|
21 | namespace wave { |
---|
22 | namespace grammars { |
---|
23 | |
---|
24 | /////////////////////////////////////////////////////////////////////////////// |
---|
25 | // |
---|
26 | // store parser_id's of all rules of the cpp_grammar here for later access |
---|
27 | // |
---|
28 | /////////////////////////////////////////////////////////////////////////////// |
---|
29 | struct cpp_grammar_rule_ids { |
---|
30 | std::size_t pp_statement_id; |
---|
31 | std::size_t include_file_id; // #include "..." |
---|
32 | std::size_t sysinclude_file_id; // #include <...> |
---|
33 | std::size_t macroinclude_file_id; // #include ... |
---|
34 | std::size_t plain_define_id; // #define |
---|
35 | std::size_t macro_parameters_id; |
---|
36 | std::size_t macro_definition_id; |
---|
37 | std::size_t undefine_id; // #undef |
---|
38 | std::size_t ifdef_id; // #ifdef |
---|
39 | std::size_t ifndef_id; // #ifndef |
---|
40 | std::size_t if_id; // #if |
---|
41 | std::size_t elif_id; // #elif |
---|
42 | std::size_t else_id; // #else |
---|
43 | std::size_t endif_id; // #endif |
---|
44 | std::size_t line_id; // #line |
---|
45 | std::size_t error_id; // #error |
---|
46 | std::size_t warning_id; // #warning |
---|
47 | std::size_t pragma_id; // #pragma |
---|
48 | std::size_t illformed_id; |
---|
49 | std::size_t ppspace_id; |
---|
50 | std::size_t ppqualifiedname_id; |
---|
51 | #if BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0 |
---|
52 | std::size_t region_id; // #region |
---|
53 | std::size_t endregion_id; // #endregion |
---|
54 | #endif |
---|
55 | }; |
---|
56 | |
---|
57 | /////////////////////////////////////////////////////////////////////////////// |
---|
58 | // |
---|
59 | // cpp_grammar_gen template class |
---|
60 | // |
---|
61 | // This template helps separating the compilation of the cpp_grammar |
---|
62 | // class from the compilation of the main pp_iterator. This is done to |
---|
63 | // safe compilation time. |
---|
64 | // |
---|
65 | /////////////////////////////////////////////////////////////////////////////// |
---|
66 | |
---|
67 | template <typename LexIteratorT> |
---|
68 | struct cpp_grammar_gen |
---|
69 | { |
---|
70 | typedef LexIteratorT iterator_type; |
---|
71 | typedef typename LexIteratorT::token_type token_type; |
---|
72 | typedef typename token_type::position_type position_type; |
---|
73 | |
---|
74 | // the parser_id's of all rules of the cpp_grammar are stored here |
---|
75 | // note: these are valid only after the first call to parse_cpp_grammar |
---|
76 | static cpp_grammar_rule_ids rule_ids; |
---|
77 | |
---|
78 | // the actual position of the last matched T_NEWLINE is stored here into the |
---|
79 | // member 'pos_of_newline' |
---|
80 | static position_type pos_of_newline; |
---|
81 | |
---|
82 | // the found_eof flag is set to true during the parsing, if the directive |
---|
83 | // under inspection terminates with a T__EOF token |
---|
84 | static bool found_eof; |
---|
85 | |
---|
86 | // the found_directive contains the token_id of the recognized pp directive |
---|
87 | static boost::wave::token_id found_directive; |
---|
88 | |
---|
89 | // parse the cpp_grammar and return the resulting parse tree |
---|
90 | static boost::spirit::tree_parse_info<iterator_type> |
---|
91 | parse_cpp_grammar (iterator_type const &first, iterator_type const &last, |
---|
92 | bool &found_eof_, position_type const &act_pos); |
---|
93 | }; |
---|
94 | |
---|
95 | /////////////////////////////////////////////////////////////////////////////// |
---|
96 | // definitions of the static members |
---|
97 | template <typename LexIteratorT> |
---|
98 | cpp_grammar_rule_ids |
---|
99 | cpp_grammar_gen<LexIteratorT>::rule_ids; |
---|
100 | |
---|
101 | template <typename LexIteratorT> |
---|
102 | typename LexIteratorT::token_type::position_type |
---|
103 | cpp_grammar_gen<LexIteratorT>::pos_of_newline; |
---|
104 | |
---|
105 | template <typename LexIteratorT> |
---|
106 | bool cpp_grammar_gen<LexIteratorT>::found_eof = false; |
---|
107 | |
---|
108 | template <typename LexIteratorT> |
---|
109 | boost::wave::token_id cpp_grammar_gen<LexIteratorT>::found_directive = |
---|
110 | boost::wave::T_EOF; |
---|
111 | |
---|
112 | /////////////////////////////////////////////////////////////////////////////// |
---|
113 | } // namespace grammars |
---|
114 | } // namespace wave |
---|
115 | } // namespace boost |
---|
116 | |
---|
117 | #endif // !defined(CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED) |
---|