1 | /*============================================================================= |
---|
2 | Boost.Wave: A Standard compliant C++ preprocessor library |
---|
3 | |
---|
4 | http://www.boost.org/ |
---|
5 | |
---|
6 | Copyright (c) 2001-2007 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(MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED) |
---|
12 | #define MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED |
---|
13 | |
---|
14 | #include <vector> |
---|
15 | #include <list> |
---|
16 | |
---|
17 | #include <boost/wave/wave_config.hpp> |
---|
18 | #if BOOST_WAVE_SERIALIZATION != 0 |
---|
19 | #include <boost/serialization/serialization.hpp> |
---|
20 | #include <boost/serialization/list.hpp> |
---|
21 | #include <boost/serialization/vector.hpp> |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <boost/wave/token_ids.hpp> |
---|
25 | |
---|
26 | // this must occur after all of the includes and before any code appears |
---|
27 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
28 | #include BOOST_ABI_PREFIX |
---|
29 | #endif |
---|
30 | |
---|
31 | /////////////////////////////////////////////////////////////////////////////// |
---|
32 | namespace boost { |
---|
33 | namespace wave { |
---|
34 | namespace util { |
---|
35 | |
---|
36 | /////////////////////////////////////////////////////////////////////////////// |
---|
37 | // |
---|
38 | // macro_definition |
---|
39 | // |
---|
40 | // This class containes all infos for a defined macro. |
---|
41 | // |
---|
42 | /////////////////////////////////////////////////////////////////////////////// |
---|
43 | template <typename TokenT, typename ContainerT> |
---|
44 | struct macro_definition { |
---|
45 | |
---|
46 | typedef std::vector<TokenT> parameter_container_type; |
---|
47 | typedef ContainerT definition_container_type; |
---|
48 | |
---|
49 | typedef typename parameter_container_type::const_iterator |
---|
50 | const_parameter_iterator_t; |
---|
51 | typedef typename definition_container_type::const_iterator |
---|
52 | const_definition_iterator_t; |
---|
53 | |
---|
54 | macro_definition(TokenT const &token_, bool has_parameters, |
---|
55 | bool is_predefined_, long uid_) |
---|
56 | : macroname(token_), uid(uid_), is_functionlike(has_parameters), |
---|
57 | replaced_parameters(false), is_available_for_replacement(true), |
---|
58 | is_predefined(is_predefined_) |
---|
59 | #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 |
---|
60 | , has_ellipsis(false) |
---|
61 | #endif |
---|
62 | { |
---|
63 | } |
---|
64 | // generated copy constructor |
---|
65 | // generated destructor |
---|
66 | // generated assignment operator |
---|
67 | |
---|
68 | // Replace all occurrences of the parameters throughout the macrodefinition |
---|
69 | // with special parameter tokens to simplify later macro replacement. |
---|
70 | // Additionally mark all occurrences of the macro name itself throughout |
---|
71 | // the macro definition |
---|
72 | void replace_parameters() |
---|
73 | { |
---|
74 | using namespace boost::wave; |
---|
75 | |
---|
76 | if (!replaced_parameters) { |
---|
77 | typename definition_container_type::iterator end = macrodefinition.end(); |
---|
78 | typename definition_container_type::iterator it = macrodefinition.begin(); |
---|
79 | |
---|
80 | for (/**/; it != end; ++it) { |
---|
81 | token_id id = *it; |
---|
82 | |
---|
83 | if (T_IDENTIFIER == id || |
---|
84 | IS_CATEGORY(id, KeywordTokenType) || |
---|
85 | IS_EXTCATEGORY(id, OperatorTokenType|AltExtTokenType) || |
---|
86 | IS_CATEGORY(id, OperatorTokenType)) |
---|
87 | { |
---|
88 | // may be a parameter to replace |
---|
89 | const_parameter_iterator_t cend = macroparameters.end(); |
---|
90 | const_parameter_iterator_t cit = macroparameters.begin(); |
---|
91 | for (typename parameter_container_type::size_type i = 0; |
---|
92 | cit != cend; ++cit, ++i) |
---|
93 | { |
---|
94 | if ((*it).get_value() == (*cit).get_value()) { |
---|
95 | (*it).set_token_id(token_id(T_PARAMETERBASE+i)); |
---|
96 | break; |
---|
97 | } |
---|
98 | #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 |
---|
99 | else if (T_ELLIPSIS == token_id(*cit) && |
---|
100 | "__VA_ARGS__" == (*it).get_value()) |
---|
101 | { |
---|
102 | // __VA_ARGS__ requires special handling |
---|
103 | (*it).set_token_id(token_id(T_EXTPARAMETERBASE+i)); |
---|
104 | break; |
---|
105 | } |
---|
106 | #endif |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 |
---|
112 | // we need to know, if the last of the formal arguments is an ellipsis |
---|
113 | if (macroparameters.size() > 0 && |
---|
114 | T_ELLIPSIS == token_id(macroparameters.back())) |
---|
115 | { |
---|
116 | has_ellipsis = true; |
---|
117 | } |
---|
118 | #endif |
---|
119 | replaced_parameters = true; // do it only once |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | TokenT macroname; // macro name |
---|
124 | parameter_container_type macroparameters; // formal parameters |
---|
125 | definition_container_type macrodefinition; // macro definition token sequence |
---|
126 | long uid; // unique id of this macro |
---|
127 | bool is_functionlike; |
---|
128 | bool replaced_parameters; |
---|
129 | bool is_available_for_replacement; |
---|
130 | bool is_predefined; |
---|
131 | #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 |
---|
132 | bool has_ellipsis; |
---|
133 | #endif |
---|
134 | |
---|
135 | #if BOOST_WAVE_SERIALIZATION != 0 |
---|
136 | // default constructor is needed for serialization only |
---|
137 | macro_definition() |
---|
138 | : uid(0), is_functionlike(false), replaced_parameters(false), |
---|
139 | is_available_for_replacement(false), is_predefined(false) |
---|
140 | #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 |
---|
141 | , has_ellipsis(false) |
---|
142 | #endif |
---|
143 | {} |
---|
144 | |
---|
145 | private: |
---|
146 | friend class boost::serialization::access; |
---|
147 | template<typename Archive> |
---|
148 | void serialize(Archive &ar, const unsigned int version) |
---|
149 | { |
---|
150 | ar & macroname; |
---|
151 | ar & macroparameters; |
---|
152 | ar & macrodefinition; |
---|
153 | ar & uid; |
---|
154 | ar & is_functionlike; |
---|
155 | ar & replaced_parameters; |
---|
156 | ar & is_available_for_replacement; |
---|
157 | ar & is_predefined; |
---|
158 | #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 |
---|
159 | ar & has_ellipsis; |
---|
160 | #endif |
---|
161 | } |
---|
162 | #endif |
---|
163 | }; |
---|
164 | |
---|
165 | /////////////////////////////////////////////////////////////////////////////// |
---|
166 | } // namespace util |
---|
167 | } // namespace wave |
---|
168 | } // namespace boost |
---|
169 | |
---|
170 | // the suffix header occurs after all of the code |
---|
171 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
172 | #include BOOST_ABI_SUFFIX |
---|
173 | #endif |
---|
174 | |
---|
175 | #endif // !defined(MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED) |
---|