#include <pp_token.hh>
Inheritance diagram for lestes::lang::cplus::lex::pp_token:

Public Types | |
| enum | token_types { TOK_FILE_END, TOK_TERMINATOR, TOK_LEFT_BRACKET, TOK_RIGHT_BRACKET, TOK_LEFT_BRACE, TOK_RIGHT_BRACE, TOK_LEFT_PAR, TOK_RIGHT_PAR, TOK_SEMICOLON, TOK_COLON, TOK_QMARK, TOK_DOT, TOK_PLUS, TOK_STAR, TOK_PERCENT, TOK_SLASH, TOK_HAT, TOK_AMP, TOK_VBAR, TOK_TILDE, TOK_EMARK, TOK_EQ, TOK_LT, TOK_GT, TOK_COMMA, TOK_MINUS, TOK_DOT_DOT_DOT, TOK_COLON_COLON, TOK_DOT_STAR, TOK_PLUS_EQ, TOK_MINUS_EQ, TOK_STAR_EQ, TOK_SLASH_EQ, TOK_PERCENT_EQ, TOK_HAT_EQ, TOK_AMP_EQ, TOK_VBAR_EQ, TOK_LT_LT, TOK_GT_GT, TOK_LT_LT_EQ, TOK_GT_GT_EQ, TOK_EQ_EQ, TOK_EMARK_EQ, TOK_LT_EQ, TOK_GT_EQ, TOK_AMP_AMP, TOK_VBAR_VBAR, TOK_PLUS_PLUS, TOK_MINUS_MINUS, TOK_MINUS_GT_STAR, TOK_MINUS_GT, TOK_ASM, TOK_AUTO, TOK_BOOL, TOK_BREAK, TOK_CASE, TOK_CATCH, TOK_CHAR, TOK_CLASS, TOK_CONST, TOK_CONST_CAST, TOK_CONTINUE, TOK_DEFAULT, TOK_DELETE, TOK_DO, TOK_DOUBLE, TOK_DYNAMIC_CAST, TOK_ELSE, TOK_ENUM, TOK_EXPLICIT, TOK_EXPORT, TOK_EXTERN, TOK_FLOAT, TOK_FOR, TOK_FRIEND, TOK_GOTO, TOK_IF, TOK_INLINE, TOK_INT, TOK_LONG, TOK_MUTABLE, TOK_NAMESPACE, TOK_NEW, TOK_OPERATOR, TOK_PRIVATE, TOK_PROTECTED, TOK_PUBLIC, TOK_REGISTER, TOK_REINTERPRET_CAST, TOK_RETURN, TOK_SHORT, TOK_SIGNED, TOK_SIZEOF, TOK_STATIC, TOK_STATIC_CAST, TOK_STRUCT, TOK_SWITCH, TOK_TEMPLATE, TOK_THIS, TOK_THROW, TOK_TRY, TOK_TYPEDEF, TOK_TYPEID, TOK_TYPENAME, TOK_UNION, TOK_UNSIGNED, TOK_USING, TOK_VIRTUAL, TOK_VOID, TOK_VOLATILE, TOK_WCHAR, TOK_WHILE, TOK_BOOL_LIT, TOK_CHAR_LIT, TOK_WCHAR_LIT, TOK_STRING_LIT, TOK_WSTRING_LIT, TOK_NUMBER_LIT, TOK_IDENT, TOK_HASH, TOK_HASH_HASH, TOK_BLANK, TOK_LINE_END, TOK_OTHER, TOK_INCLUDE, TOK_DEFINE, TOK_UNDEF, TOK_LINE, TOK_PRAGMA, TOK_ERROR, TOK_DEFINED, TOK_IFDEF, TOK_IFNDEF, TOK_ELIF, TOK_ENDIF, TOK_INCL_HCHAR, TOK_INCL_QCHAR, TOK_INCL_SIG, TOK_LAST, TOK_AVOID_WARNING } |
| Token type constants. More... | |
| enum | { TOKEN_TYPE_COUNT = TOK_AVOID_WARNING } |
Public Member Functions | |
| bool | is_name (void) const |
| Token can be macro name. | |
| bool | is_alternative (void) const |
| Token has alternative spelling. | |
| bool | is_valued (void) const |
| Token has value. | |
| bool | equals (const ptr< pp_token > &other) const |
| Tests equality. | |
| bool | congruent (const ptr< pp_token > &other) const |
| Tests congruence. | |
| lstring | description_get (void) const |
| Returns description. | |
| ucn_string | spelling_get (void) const |
| Returns token spelling. | |
| ptr< taboo_macros > | taboo_get (void) const |
| Returns taboo macros. | |
| ptr< pp_token > | clone (const location_type &a_location) const |
| Returns copy of token with different location. | |
| ptr< pp_token > | clone (const ptr< taboo_macros > &a_taboo) const |
| Returns copy of token with different taboo macros. | |
Static Public Member Functions | |
| static ptr< pp_token > | create (const location_type &a_location, const type_type &a_type) |
| Returns new token, initializes with location and type. | |
| static ptr< pp_token > | create_alternative (const location_type &a_location, const type_type &a_type) |
| Returns new alternative token, initializes with location and type. | |
| static ptr< pp_token > | create (const location_type &a_location, const type_type &a_type, const value_type &a_value) |
| Returns new token, initializes with location, type and value. | |
| static ptr< pp_token > | terminator (void) |
| Returns the terminator token. | |
Protected Member Functions | |
| pp_token (const location_type &a_location, const type_type &a_type, const value_type &a_value, bool a_alternative, const ptr< taboo_macros > &a_taboo) | |
| Creates new token, initializes with appropriate values. | |
| virtual void | gc_mark (void) |
| Marks the object. | |
Private Types | |
| enum | pp_token_flags { FLG_NONE = 0x0, FLG_INTERNAL = 0x1, FLG_EXTERNAL = 0x2, FLG_NAME = 0x4, FLG_VARIANT = 0x08 } |
| Token flags. More... | |
| typedef lc_host_uint_least16 | flags_type |
| Type of flags. | |
Private Member Functions | |
| pp_token (const pp_token &) | |
| Hides copy constructor. | |
| pp_token & | operator= (const pp_token &) |
| Hides assignment operator. | |
Static Private Member Functions | |
| static void | initialize (void) |
| Initializes static structures. | |
Private Attributes | |
| bool | alternative |
| Token has alternative spelling. | |
| srp< taboo_macros > | taboo |
| Taboo macros for token. | |
Static Private Attributes | |
| static bool | initialized |
| Initialization flag. | |
| static lstring | the_description [TOKEN_TYPE_COUNT] |
| Descriptions of tokens. | |
| static ucn_string | the_spelling [2][TOKEN_TYPE_COUNT] |
| Spelling of tokens. | |
| static ptr< token_value > | the_value [TOKEN_TYPE_COUNT] |
| Values of tokens. | |
| static flags_type | the_flags [TOKEN_TYPE_COUNT] |
| Flags of tokens. | |
| static ptr< pp_token > | terminator_instance = terminator_instance |
| The terminator token instance. | |
Represents preprocessor token. Each token has type and location, literals and names also have value. Token type properties are represented by internal flags.
Definition at line 212 of file pp_token.hh.
typedef lc_host_uint_least16 lestes::lang::cplus::lex::pp_token::flags_type [private] |
Token type constants.
Definition at line 247 of file pp_token.hh.
00247 { 00248 PP_TOKENS_LIST 00249 TOK_AVOID_WARNING 00250 };
| anonymous enum |
Definition at line 253 of file pp_token.hh.
00253 { 00254 //! Number of token types. 00255 TOKEN_TYPE_COUNT = TOK_AVOID_WARNING 00256 };
enum lestes::lang::cplus::lex::pp_token::pp_token_flags [private] |
Token flags.
Definition at line 269 of file pp_token.hh.
00269 { 00270 //! Empty flags. 00271 FLG_NONE = 0x0, 00272 //! Token has internally initialized value. 00273 FLG_INTERNAL = 0x1, 00274 //! Token has externally initialized value. 00275 FLG_EXTERNAL = 0x2, 00276 //! Token is a name. 00277 FLG_NAME = 0x4, 00278 //! Token has two variants of spelling. 00279 FLG_VARIANT = 0x08 00280 };
| lestes::lang::cplus::lex::pp_token::pp_token | ( | const location_type & | a_location, | |
| const type_type & | a_type, | |||
| const value_type & | a_value, | |||
| bool | a_alternative, | |||
| const ptr< taboo_macros > & | a_taboo | |||
| ) | [protected] |
Creates new token, initializes with appropriate values.
Creates new token, initializes with location, token type, token value and flags.
is_equal(type_get(),a_type)
is_equal(value_get(),a_value)
| a_location | The initial location. | |
| a_type | The type. | |
| a_value | The value. | |
| a_alternative | The alternative spelling flag. | |
| a_taboo | The taboo. |
Definition at line 64 of file pp_token.cc.
Referenced by clone(), create(), and create_alternative().
00065 : 00066 basic_pp_token(a_location,a_type,a_value), 00067 alternative(a_alternative), 00068 taboo(checked(a_taboo)) 00069 { 00070 }
| lestes::lang::cplus::lex::pp_token::pp_token | ( | const pp_token & | ) | [private] |
Hides copy constructor.
| bool lestes::lang::cplus::lex::pp_token::is_name | ( | void | ) | const |
Token can be macro name.
Tests if token is name, that is identifier, keyword, true or false.
Definition at line 76 of file pp_token.cc.
References FLG_NAME, the_flags, and lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::type_get().
Referenced by clone().
| bool lestes::lang::cplus::lex::pp_token::is_alternative | ( | void | ) | const |
Token has alternative spelling.
Tests if token has alternative spelling.
Definition at line 85 of file pp_token.cc.
References alternative.
Referenced by clone(), congruent(), equals(), and spelling_get().
00086 { 00087 return alternative; 00088 }
| bool lestes::lang::cplus::lex::pp_token::is_valued | ( | void | ) | const |
Token has value.
Tests if token has value.
Definition at line 94 of file pp_token.cc.
References FLG_EXTERNAL, FLG_INTERNAL, the_flags, and lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::type_get().
Referenced by spelling_get().
00095 { 00096 return the_flags[type_get()] & (FLG_EXTERNAL | FLG_INTERNAL); 00097 }
| bool lestes::lang::cplus::lex::pp_token::equals | ( | const ptr< pp_token > & | other | ) | const |
Tests equality.
Tests equality of the token.
| other | The token to compare with. |
Definition at line 193 of file pp_token.cc.
References is_alternative(), lestes::is_equal(), lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::location_get(), lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::type_get(), and lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::value_get().
00194 { 00195 // TODO pt taboo 00196 return other && 00197 is_equal(type_get(),other->type_get()) && 00198 is_equal(is_alternative(),other->is_alternative()) && 00199 is_equal(location_get(),other->location_get()) && 00200 is_equal(value_get(),other->value_get()); 00201 }
| bool lestes::lang::cplus::lex::pp_token::congruent | ( | const ptr< pp_token > & | other | ) | const |
Tests congruence.
Tests congruence of the token, that is equivalence considering only type, value and spelling.
| other | The token to compare with. |
Definition at line 180 of file pp_token.cc.
References is_alternative(), lestes::is_equal(), lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::type_get(), and lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::value_get().
00181 { 00182 return other && 00183 is_equal(type_get(),other->type_get()) && 00184 is_equal(is_alternative(),other->is_alternative()) && 00185 is_equal(value_get(),other->value_get()); 00186 }
| lstring lestes::lang::cplus::lex::pp_token::description_get | ( | void | ) | const |
Returns description.
Returns internal token description dependent on token type, for debugging.
Definition at line 103 of file pp_token.cc.
References the_description, and lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::type_get().
00104 { 00105 return the_description[type_get()]; 00106 }
| ucn_string lestes::lang::cplus::lex::pp_token::spelling_get | ( | void | ) | const |
Returns token spelling.
Returns token spelling, reflecting the source.
Definition at line 112 of file pp_token.cc.
References is_alternative(), is_valued(), the_spelling, TOK_CHAR_LIT, TOK_STRING_LIT, TOK_WCHAR_LIT, TOK_WSTRING_LIT, lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::type_get(), and lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::value_get().
00113 { 00114 pp_token_type ptt = type_get(); 00115 00116 switch (ptt) { 00117 case pp_token::TOK_STRING_LIT: 00118 { 00119 ucn_string us = "\""; 00120 us += value_get()->content_get(); 00121 us += character::create_from_host('"'); 00122 return us; 00123 } 00124 case pp_token::TOK_CHAR_LIT: 00125 { 00126 ucn_string us = "'"; 00127 us += value_get()->content_get(); 00128 us += character::create_from_host('\''); 00129 return us; 00130 } 00131 case pp_token::TOK_WSTRING_LIT: 00132 { 00133 ucn_string us = "L\""; 00134 us += value_get()->content_get(); 00135 us += character::create_from_host('"'); 00136 return us; 00137 } 00138 case pp_token::TOK_WCHAR_LIT: 00139 { 00140 ucn_string us = "L'"; 00141 us += value_get()->content_get(); 00142 us += character::create_from_host('\''); 00143 return us; 00144 } 00145 default: 00146 break; 00147 } 00148 00149 if (is_valued()) { 00150 /* TODO pt remove 00151 if (is_name()) { 00152 ucn_string u; 00153 u += value_get()->content_get(); 00154 u += taboo_get()->names_get(); 00155 return u; 00156 } 00157 */ 00158 00159 return value_get()->content_get(); 00160 } 00161 00162 return the_spelling[is_alternative()][ptt]; 00163 }
| ptr< taboo_macros > lestes::lang::cplus::lex::pp_token::taboo_get | ( | void | ) | const |
Returns taboo macros.
Returns taboo macros for the token.
Definition at line 169 of file pp_token.cc.
References taboo.
Referenced by clone().
00170 { 00171 return taboo; 00172 }
| ptr< pp_token > lestes::lang::cplus::lex::pp_token::clone | ( | const location_type & | a_location | ) | const |
Returns copy of token with different location.
Returns copy of this token, with different location.
| a_location | The new location |
Definition at line 209 of file pp_token.cc.
References is_alternative(), lassert, pp_token(), taboo_get(), lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::type_get(), and lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::value_get().
00210 { 00211 lassert(a_location); 00212 return new pp_token(a_location,type_get(),value_get(),is_alternative(),taboo_get()); 00213 }
| ptr< pp_token > lestes::lang::cplus::lex::pp_token::clone | ( | const ptr< taboo_macros > & | a_taboo | ) | const |
Returns copy of token with different taboo macros.
Returns copy of this token, with different taboo macros.
The token is name.
| a_taboo | The new taboo macros. |
Definition at line 222 of file pp_token.cc.
References is_alternative(), is_name(), lassert, lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::location_get(), pp_token(), lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::type_get(), and lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::value_get().
00223 { 00224 lassert(a_taboo); 00225 lassert(is_name()); 00226 return new pp_token(location_get(),type_get(),value_get(),is_alternative(),a_taboo); 00227 }
| ptr< pp_token > lestes::lang::cplus::lex::pp_token::create | ( | const location_type & | a_location, | |
| const type_type & | a_type | |||
| ) | [static] |
Returns new token, initializes with location and type.
Returns new token, initializes with location, token type.
is_equal(type_get(),a_type)
| a_location | The location. | |
| a_type | The token type. |
Definition at line 238 of file pp_token.cc.
References lestes::lang::cplus::lex::taboo_macros::create(), FLG_EXTERNAL, initialize(), lassert, pp_token(), the_flags, and the_value.
Referenced by lestes::lang::cplus::lex::string_joiner::join_sequence(), lestes::lang::cplus::lex::macro_argument::parse(), lestes::lang::cplus::lex::evaluator::parse_include(), lestes::lang::cplus::lex::stringifier::process(), lestes::lang::cplus::lex::string_translator::read(), lestes::lang::cplus::lex::evaluator::read(), and terminator().
00239 { 00240 initialize(); 00241 lassert(!(the_flags[a_type] & FLG_EXTERNAL)); 00242 return new pp_token(a_location,a_type,the_value[a_type],false,taboo_macros::create()); 00243 }
| ptr< pp_token > lestes::lang::cplus::lex::pp_token::create_alternative | ( | const location_type & | a_location, | |
| const type_type & | a_type | |||
| ) | [static] |
Returns new alternative token, initializes with location and type.
Returns new token with alternative spelling, initializes with location and token type.
Alternative spelling is used only when available.
is_equal(type_get(),a_type)
| a_location | The location. | |
| a_type | The token type. |
Definition at line 255 of file pp_token.cc.
References lestes::lang::cplus::lex::taboo_macros::create(), FLG_EXTERNAL, FLG_VARIANT, initialize(), lassert, pp_token(), the_flags, and the_value.
00256 { 00257 initialize(); 00258 lassert(!(the_flags[a_type] & FLG_EXTERNAL)); 00259 lassert(the_flags[a_type] & FLG_VARIANT); 00260 return new pp_token(a_location,a_type,the_value[a_type],true,taboo_macros::create()); 00261 }
| ptr< pp_token > lestes::lang::cplus::lex::pp_token::create | ( | const location_type & | a_location, | |
| const type_type & | a_type, | |||
| const value_type & | a_value | |||
| ) | [static] |
Returns new token, initializes with location, type and value.
Returns new token, initializes with location, token type and token value.
is_equal(type_get(),a_type)
is_equal(value_get(),a_value)
| a_location | The initial location. | |
| a_type | The initial token type. | |
| a_value | The initial token value. |
Definition at line 274 of file pp_token.cc.
References lestes::lang::cplus::lex::taboo_macros::create(), FLG_EXTERNAL, initialize(), lassert, pp_token(), and the_flags.
00276 { 00277 initialize(); 00278 lassert(the_flags[a_type] & FLG_EXTERNAL); 00279 return new pp_token(a_location,a_type,a_value,false,taboo_macros::create()); 00280 }
| ptr< pp_token > lestes::lang::cplus::lex::pp_token::terminator | ( | void | ) | [static] |
Returns the terminator token.
Definition at line 282 of file pp_token.cc.
References create(), terminator_instance, and TOK_TERMINATOR.
Referenced by lestes::lang::cplus::lex::token_sequence::peek_back(), lestes::lang::cplus::lex::token_stream::peek_front(), lestes::lang::cplus::lex::token_sequence::peek_front(), lestes::lang::cplus::lex::token_stream::read(), lestes::lang::cplus::lex::token_sequence::read(), lestes::lang::cplus::lex::token_sequence::read_back(), lestes::lang::cplus::lex::token_sequence::read_back_skip_ws(), lestes::lang::cplus::lex::token_stream::read_front(), lestes::lang::cplus::lex::token_sequence::read_front(), lestes::lang::cplus::lex::token_stream::read_front_skip_ws(), and lestes::lang::cplus::lex::token_sequence::read_front_skip_ws().
00283 { 00284 if (!terminator_instance) { 00285 terminator_instance = pp_token::create(source_location::zero(),pp_token::TOK_TERMINATOR); 00286 } 00287 return terminator_instance; 00288 }
| void lestes::lang::cplus::lex::pp_token::gc_mark | ( | void | ) | [protected, virtual] |
Marks the object.
Marks the object.
Reimplemented from lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >.
Definition at line 293 of file pp_token.cc.
References lestes::lang::cplus::lex::basic_token< lc_host_uint_least16, ptr< source_location >, ptr< token_value > >::gc_mark(), and taboo.
00294 { 00295 taboo.gc_mark(); 00296 basic_pp_token::gc_mark(); 00297 }
Hides assignment operator.
| void lestes::lang::cplus::lex::pp_token::initialize | ( | void | ) | [static, private] |
Initializes static structures.
Initializes helper static structures containing properties of existing token types. The initialization is invoked automatically prior to use of any instance.
Definition at line 303 of file pp_token.cc.
References initialized, and PP_TOKENS_LIST.
Referenced by create(), and create_alternative().
00304 { 00305 if (initialized) return; 00306 00307 ulint i; 00308 00309 i = 0; 00310 #undef DEF_PP_TOKEN 00311 #define DEF_PP_TOKEN(x,y,z,w) \ 00312 the_description[i++] = #x; 00313 PP_TOKENS_LIST 00314 00315 i = 0; 00316 #undef DEF_PP_TOKEN 00317 #define DEF_PP_TOKEN(x,y,z,w) \ 00318 the_spelling[0][i] = y; the_spelling[1][i++] = z; 00319 PP_TOKENS_LIST 00320 00321 i = 0; 00322 #undef DEF_PP_TOKEN 00323 #define DEF_PP_TOKEN(x,y,z,w) \ 00324 the_value[i++] = ((w) & FLG_INTERNAL) ? token_value::create(ucn_string(y)) : ptr<token_value>(NULL); 00325 PP_TOKENS_LIST 00326 00327 i = 0; 00328 #undef DEF_PP_TOKEN 00329 #define DEF_PP_TOKEN(x,y,z,w) \ 00330 the_flags[i++] = w; 00331 PP_TOKENS_LIST 00332 00333 initialized = true; 00334 }
bool lestes::lang::cplus::lex::pp_token::alternative [private] |
Token has alternative spelling.
Definition at line 282 of file pp_token.hh.
Referenced by is_alternative().
srp<taboo_macros> lestes::lang::cplus::lex::pp_token::taboo [private] |
Taboo macros for token.
Definition at line 284 of file pp_token.hh.
Referenced by gc_mark(), and taboo_get().
bool lestes::lang::cplus::lex::pp_token::initialized [static, private] |
Initialization flag.
Multiple initialization guard.
Definition at line 292 of file pp_token.hh.
Referenced by initialize().
lstring lestes::lang::cplus::lex::pp_token::the_description [static, private] |
Descriptions of tokens.
List of token descriptions.
Definition at line 294 of file pp_token.hh.
Referenced by description_get().
ucn_string lestes::lang::cplus::lex::pp_token::the_spelling [static, private] |
Spelling of tokens.
List of token spellings.
Definition at line 296 of file pp_token.hh.
Referenced by spelling_get().
ptr< token_value > lestes::lang::cplus::lex::pp_token::the_value [static, private] |
Values of tokens.
List of token internally initialized values.
Definition at line 298 of file pp_token.hh.
Referenced by create(), and create_alternative().
pp_token::flags_type lestes::lang::cplus::lex::pp_token::the_flags [static, private] |
Flags of tokens.
List of token flags.
Definition at line 300 of file pp_token.hh.
Referenced by create(), create_alternative(), is_name(), and is_valued().
ptr< pp_token > lestes::lang::cplus::lex::pp_token::terminator_instance = terminator_instance [static, private] |
The terminator token instance.
Terminator token instance.
Definition at line 302 of file pp_token.hh.
Referenced by terminator().
1.5.1-20070107