File indexing completed on 2025-01-30 10:02:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #if !defined(BOOST_DETECT_INCLUDE_GUARDS_HK060304_INCLUDED)
0030 #define BOOST_DETECT_INCLUDE_GUARDS_HK060304_INCLUDED
0031
0032 #include <boost/wave/wave_config.hpp>
0033 #include <boost/wave/token_ids.hpp>
0034
0035
0036 #ifdef BOOST_HAS_ABI_HEADERS
0037 #include BOOST_ABI_PREFIX
0038 #endif
0039
0040
0041 namespace boost {
0042 namespace wave {
0043 namespace cpplexer {
0044
0045 template <typename Token>
0046 class include_guards
0047 {
0048 public:
0049 include_guards()
0050 : state(&include_guards::state_0), detected_guards(false),
0051 current_state(true), if_depth(0)
0052 {}
0053
0054 Token& detect_guard(Token& t)
0055 { return current_state ? (this->*state)(t) : t; }
0056 bool detected(std::string& guard_name_) const
0057 {
0058 if (detected_guards) {
0059 guard_name_ = guard_name.c_str();
0060 return true;
0061 }
0062 return false;
0063 }
0064
0065 private:
0066 typedef Token& state_type(Token& t);
0067 state_type include_guards::* state;
0068
0069 bool detected_guards;
0070 bool current_state;
0071 typename Token::string_type guard_name;
0072 int if_depth;
0073
0074 state_type state_0, state_1, state_2, state_3, state_4, state_5;
0075 state_type state_1a, state_1b, state_1c, state_1d, state_1e;
0076
0077 bool is_skippable(token_id id) const
0078 {
0079 return (T_POUND == BASE_TOKEN(id) ||
0080 IS_CATEGORY(id, WhiteSpaceTokenType) ||
0081 IS_CATEGORY(id, EOLTokenType));
0082 }
0083 };
0084
0085
0086
0087 template <typename Token>
0088 inline Token&
0089 include_guards<Token>::state_0(Token& t)
0090 {
0091 token_id id = token_id(t);
0092 if (T_PP_IFNDEF == id)
0093 state = &include_guards::state_1;
0094 else if (T_PP_IF == id)
0095 state = &include_guards::state_1a;
0096 else if (!is_skippable(id))
0097 current_state = false;
0098 return t;
0099 }
0100
0101
0102
0103 template <typename Token>
0104 inline Token&
0105 include_guards<Token>::state_1(Token& t)
0106 {
0107 token_id id = token_id(t);
0108 if (T_IDENTIFIER == id) {
0109 guard_name = t.get_value();
0110 state = &include_guards::state_2;
0111 }
0112 else if (!is_skippable(id))
0113 current_state = false;
0114 return t;
0115 }
0116
0117
0118
0119 template <typename Token>
0120 inline Token&
0121 include_guards<Token>::state_1a(Token& t)
0122 {
0123 token_id id = token_id(t);
0124 if (T_NOT == BASE_TOKEN(id))
0125 state = &include_guards::state_1b;
0126 else if (!is_skippable(id))
0127 current_state = false;
0128 return t;
0129 }
0130
0131
0132
0133 template <typename Token>
0134 inline Token&
0135 include_guards<Token>::state_1b(Token& t)
0136 {
0137 token_id id = token_id(t);
0138 if (T_IDENTIFIER == id && t.get_value() == "defined")
0139 state = &include_guards::state_1c;
0140 else if (!is_skippable(id))
0141 current_state = false;
0142 return t;
0143 }
0144
0145
0146
0147 template <typename Token>
0148 inline Token&
0149 include_guards<Token>::state_1c(Token& t)
0150 {
0151 token_id id = token_id(t);
0152 if (T_LEFTPAREN == id)
0153 state = &include_guards::state_1d;
0154 else if (T_IDENTIFIER == id) {
0155 guard_name = t.get_value();
0156 state = &include_guards::state_2;
0157 }
0158 else if (!is_skippable(id))
0159 current_state = false;
0160 return t;
0161 }
0162
0163
0164
0165 template <typename Token>
0166 inline Token&
0167 include_guards<Token>::state_1d(Token& t)
0168 {
0169 token_id id = token_id(t);
0170 if (T_IDENTIFIER == id) {
0171 guard_name = t.get_value();
0172 state = &include_guards::state_1e;
0173 }
0174 else if (!is_skippable(id))
0175 current_state = false;
0176 return t;
0177 }
0178
0179
0180
0181 template <typename Token>
0182 inline Token&
0183 include_guards<Token>::state_1e(Token& t)
0184 {
0185 token_id id = token_id(t);
0186 if (T_RIGHTPAREN == id)
0187 state = &include_guards::state_2;
0188 else if (!is_skippable(id))
0189 current_state = false;
0190 return t;
0191 }
0192
0193
0194
0195 template <typename Token>
0196 inline Token&
0197 include_guards<Token>::state_2(Token& t)
0198 {
0199 token_id id = token_id(t);
0200 if (T_PP_DEFINE == id)
0201 state = &include_guards::state_3;
0202 else if (!is_skippable(id))
0203 current_state = false;
0204 return t;
0205 }
0206
0207
0208
0209 template <typename Token>
0210 inline Token&
0211 include_guards<Token>::state_3(Token& t)
0212 {
0213 token_id id = token_id(t);
0214 if (T_IDENTIFIER == id && t.get_value() == guard_name)
0215 state = &include_guards::state_4;
0216 else if (!is_skippable(id))
0217 current_state = false;
0218 return t;
0219 }
0220
0221
0222
0223 template <typename Token>
0224 inline Token&
0225 include_guards<Token>::state_4(Token& t)
0226 {
0227 token_id id = token_id(t);
0228 if (T_PP_IF == id || T_PP_IFDEF == id || T_PP_IFNDEF == id)
0229 ++if_depth;
0230 else if (T_PP_ENDIF == id) {
0231 if (if_depth > 0)
0232 --if_depth;
0233 else
0234 state = &include_guards::state_5;
0235 }
0236 return t;
0237 }
0238
0239
0240
0241 template <typename Token>
0242 inline Token&
0243 include_guards<Token>::state_5(Token& t)
0244 {
0245 token_id id = token_id(t);
0246 if (T_EOF == id)
0247 detected_guards = current_state;
0248 else if (!is_skippable(id))
0249 current_state = false;
0250 return t;
0251 }
0252
0253
0254 }
0255 }
0256 }
0257
0258
0259 #ifdef BOOST_HAS_ABI_HEADERS
0260 #include BOOST_ABI_SUFFIX
0261 #endif
0262
0263 #endif