]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/wave/grammars/cpp_has_include_grammar.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / wave / grammars / cpp_has_include_grammar.hpp
1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
3
4 http://www.boost.org/
5
6 Copyright (c) 2020 Jeff Trull
7 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
8 Software License, Version 1.0. (See accompanying file
9 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 =============================================================================*/
11
12 #if !defined(BOOST_CPP_HAS_INCLUDE_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED)
13 #define BOOST_CPP_HAS_INCLUDE_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED
14
15 #include <boost/wave/wave_config.hpp>
16
17 #include <boost/assert.hpp>
18 #include <boost/spirit/include/classic_core.hpp>
19 #include <boost/spirit/include/classic_closure.hpp>
20 #include <boost/spirit/include/classic_assign_actor.hpp>
21 #include <boost/spirit/include/classic_push_back_actor.hpp>
22
23 #include <boost/wave/token_ids.hpp>
24 #include <boost/wave/util/pattern_parser.hpp>
25 #include <boost/wave/grammars/cpp_has_include_grammar_gen.hpp>
26
27 #if !defined(spirit_append_actor)
28 #define spirit_append_actor(actor) boost::spirit::classic::push_back_a(actor)
29 #endif // !has_include(spirit_append_actor)
30
31 // this must occur after all of the includes and before any code appears
32 #ifdef BOOST_HAS_ABI_HEADERS
33 #include BOOST_ABI_PREFIX
34 #endif
35
36 ///////////////////////////////////////////////////////////////////////////////
37 namespace boost {
38 namespace wave {
39 namespace grammars {
40
41 ///////////////////////////////////////////////////////////////////////////////
42 // define, whether the rule's should generate some debug output
43 #define TRACE_CPP_HAS_INCLUDE_GRAMMAR \
44 bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_HAS_INCLUDE_GRAMMAR) \
45 /**/
46
47 template <typename ContainerT>
48 struct has_include_grammar :
49 public boost::spirit::classic::grammar<has_include_grammar<ContainerT> >
50 {
51 has_include_grammar(ContainerT &tokens_seq_,
52 bool &is_quoted_filename_,
53 bool &is_system_)
54 : tokens_seq(tokens_seq_), is_quoted_filename(is_quoted_filename_),
55 is_system(is_system_), true_(true)
56 {
57 BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "has_include_grammar",
58 TRACE_CPP_HAS_INCLUDE_GRAMMAR);
59 is_quoted_filename = false;
60 is_system = false;
61 }
62
63 template <typename ScannerT>
64 struct definition
65 {
66 typedef boost::spirit::classic::rule<ScannerT> rule_t;
67
68 rule_t has_include_op;
69 rule_t system_include;
70 rule_t nonsystem_include;
71
72 rule_t nonparen;
73 rule_t parenthesized_exp;
74 rule_t computed_include;
75
76 definition(has_include_grammar const & self)
77 {
78 using namespace boost::spirit::classic;
79 using namespace boost::wave;
80 using namespace boost::wave::util;
81
82 has_include_op
83 = ch_p(T_IDENTIFIER) >> // token contains '__has_include'
84 ch_p(T_LEFTPAREN) >>
85 (system_include | nonsystem_include | computed_include) >>
86 ch_p(T_RIGHTPAREN)
87 ;
88
89 system_include
90 = ch_p(T_LESS)
91 [
92 spirit_append_actor(self.tokens_seq)
93 ]
94 >> * (~ch_p(T_GREATER))
95 [
96 spirit_append_actor(self.tokens_seq)
97 ]
98 >> ch_p(T_GREATER)
99 [
100 spirit_append_actor(self.tokens_seq)
101 ][
102 assign_a(self.is_quoted_filename, self.true_)
103 ][
104 assign_a(self.is_system, self.true_)
105 ]
106 ;
107
108 nonsystem_include = ch_p(T_STRINGLIT)
109 [
110 spirit_append_actor(self.tokens_seq)
111 ][
112 assign_a(self.is_quoted_filename, self.true_)
113 ]
114 ;
115
116 // an action to store a sequence of parsed tokens
117 auto append_seq = [&](typename ScannerT::iterator_t first,
118 typename ScannerT::iterator_t last) {
119 for (;first != last;++first) {
120 self.tokens_seq.push_back(*first);
121 };
122 };
123
124 // if neither of the above match we take everything between
125 // the parentheses and evaluate it ("computed include")
126 // supported expressions are "implementation defined" per the gcc manual
127 // we've tried to be fairly generous in Wave
128 // here we accept any set of non-whitespace characters with
129 // properly nested parentheses:
130 nonparen = (anychar_p - ch_p(T_LEFTPAREN) - ch_p(T_RIGHTPAREN)) [ append_seq ] ;
131
132 parenthesized_exp =
133 ch_p(T_LEFTPAREN)[ spirit_append_actor(self.tokens_seq) ] >>
134 computed_include >>
135 ch_p(T_RIGHTPAREN)[ spirit_append_actor(self.tokens_seq) ] ;
136 computed_include = * (nonparen | parenthesized_exp) ;
137
138
139 BOOST_SPIRIT_DEBUG_TRACE_RULE(has_include_op, TRACE_CPP_HAS_INCLUDE_GRAMMAR);
140 BOOST_SPIRIT_DEBUG_TRACE_RULE(system_include, TRACE_CPP_HAS_INCLUDE_GRAMMAR);
141 BOOST_SPIRIT_DEBUG_TRACE_RULE(nonsystem_include, TRACE_CPP_HAS_INCLUDE_GRAMMAR);
142 BOOST_SPIRIT_DEBUG_TRACE_RULE(computed_include, TRACE_CPP_HAS_INCLUDE_GRAMMAR);
143 BOOST_SPIRIT_DEBUG_TRACE_RULE(parenthesized_exp, TRACE_CPP_HAS_INCLUDE_GRAMMAR);
144 BOOST_SPIRIT_DEBUG_TRACE_RULE(nonparen, TRACE_CPP_HAS_INCLUDE_GRAMMAR);
145 }
146
147 // start rule of this grammar
148 rule_t const& start() const
149 { return has_include_op; }
150 };
151
152 ContainerT &tokens_seq;
153 bool &is_quoted_filename;
154 bool &is_system;
155 const bool true_; // Spirit Classic actors operate on references, not values
156 };
157
158 ///////////////////////////////////////////////////////////////////////////////
159 #undef TRACE_CPP_HAS_INCLUDE_GRAMMAR
160
161 ///////////////////////////////////////////////////////////////////////////////
162 //
163 // The following parse function is has_include here, to allow the separation of
164 // the compilation of the has_include_grammar from the function
165 // using it.
166 //
167 ///////////////////////////////////////////////////////////////////////////////
168
169 #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
170 #define BOOST_WAVE_HAS_INCLUDE_GRAMMAR_GEN_INLINE
171 #else
172 #define BOOST_WAVE_HAS_INCLUDE_GRAMMAR_GEN_INLINE inline
173 #endif
174
175 // The parse_operator_define function is instantiated manually twice to
176 // simplify the explicit specialization of this template. This way the user
177 // has only to specify one template parameter (the lexer type) to correctly
178 // formulate the required explicit specialization.
179 // This results in no code overhead, because otherwise the function would be
180 // generated by the compiler twice anyway.
181
182 template <typename LexIteratorT>
183 BOOST_WAVE_HAS_INCLUDE_GRAMMAR_GEN_INLINE
184 boost::spirit::classic::parse_info<
185 typename has_include_grammar_gen<LexIteratorT>::iterator1_type
186 >
187 has_include_grammar_gen<LexIteratorT>::parse_operator_has_include (
188 iterator1_type const &first, iterator1_type const &last,
189 token_sequence_type &tokens,
190 bool &is_quoted_filename, bool &is_system)
191 {
192 using namespace boost::spirit::classic;
193 using namespace boost::wave;
194
195 has_include_grammar<token_sequence_type>
196 g(tokens, is_quoted_filename, is_system);
197 return boost::spirit::classic::parse (
198 first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT));
199 }
200
201 template <typename LexIteratorT>
202 BOOST_WAVE_HAS_INCLUDE_GRAMMAR_GEN_INLINE
203 boost::spirit::classic::parse_info<
204 typename has_include_grammar_gen<LexIteratorT>::iterator2_type
205 >
206 has_include_grammar_gen<LexIteratorT>::parse_operator_has_include (
207 iterator2_type const &first, iterator2_type const &last,
208 token_sequence_type &found_qualified_name,
209 bool &is_quoted_filename, bool &is_system)
210 {
211 using namespace boost::spirit::classic;
212 using namespace boost::wave;
213
214 has_include_grammar<token_sequence_type>
215 g(found_qualified_name, is_quoted_filename, is_system);
216 return boost::spirit::classic::parse (
217 first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT));
218 }
219
220 #undef BOOST_WAVE_HAS_INCLUDE_GRAMMAR_GEN_INLINE
221
222 ///////////////////////////////////////////////////////////////////////////////
223 } // namespace grammars
224 } // namespace wave
225 } // namespace boost
226
227 // the suffix header occurs after all of the code
228 #ifdef BOOST_HAS_ABI_HEADERS
229 #include BOOST_ABI_SUFFIX
230 #endif
231
232 #endif // !defined(BOOST_CPP_HAS_INCLUDE_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED)