![]() |
PUMA Library Reference Manual
|
#include <Puma/Token.h>
Inheritance diagram for Puma::Token:Abstraction of a lexical token.
A token is created by a scanner (see Puma::CScanner). It is part a token chain (see Puma::Unit) and encapsulates a lexical unit of the scanned text.
The information provided about a lexical unit is:
Public Types | |
| enum | { ID_END_OF_FILE = -1 , ID_UNKNOWN = -2 , ID_ERROR = -3 , ID_WARNING = -4 } |
| Special token types. More... | |
Public Member Functions | |
| Token (int type=0, LanguageID lang=LanguageID(0), const char *text="") | |
| Constructor. | |
| Token (const Token ©) | |
| Copy-constructor. | |
| virtual | ~Token () |
| Destructor. | |
| void | print (std::ostream &os) const |
| Print the token text on the given stream. | |
| virtual ListElement * | duplicate () |
| Duplicate this token. | |
| Unit * | unit () const |
| Get the unit this token belongs to. | |
| void | reset (int type=0, const char *text=0, LanguageID lang=LanguageID(0)) |
| Reset the token object optionally providing new content. | |
| void | location (const Location &loc) |
| Set the location of the token (usually the line and column in a file). | |
| void | cont_lines (Array< int > *lines) |
| Set the continuous lines appeared in this token. | |
| int | line_breaks () const |
| Count the number of line breaks in the text of this token. | |
| void | macro_call (bool is_call=true) |
| Set the token to be a macro call. | |
| const char * | text () const |
| Get the token text. | |
| DString & | dtext () const |
| Get the token text from the global dictionary. | |
| char * | get_static_text () const |
| Get the static token text. | |
| int | type () const |
| Get the type of the token (see Puma::CTokens). | |
| const Location & | location () const |
| Get the location of the token (usually the line and column in a file). | |
| bool | is_macro_generated () const |
| Check if the token is macro generated. | |
| bool | is_macro_call () const |
| Check if the token is a macro call. | |
| bool | is_core () const |
| Check if this is a core language token. | |
| bool | is_identifier () const |
| Check if the token is an identifier. | |
| bool | is_keyword () const |
| Check if the token is a keyword. | |
| bool | is_comma () const |
| Check if this is a comma. | |
| bool | is_open () const |
| Check if this is a left parenthesis. | |
| bool | is_close () const |
| Check if this is a right parenthesis. | |
| bool | is_whitespace () const |
| Check if this is a white-space token. | |
| bool | is_comment () const |
| Check if this is a comment. | |
| bool | is_preprocessor () const |
| Check if this is a preprocessor token. | |
| bool | is_macro_op () const |
| Check if this is function-like macro operand. | |
| bool | is_directive () const |
| Check if this is a compiler directive token. | |
| bool | is_wildcard () const |
| Check if this is a wildcard token. | |
| void * | operator new (size_t size) |
| Overwrite operator new for better performance. | |
| void | operator delete (void *ptr) |
| Free the memory allowed with the Token's own operator new. | |
Public Member Functions inherited from Puma::ListElement | |
| ListElement () | |
| Constructor. | |
| virtual | ~ListElement () |
| Destructor. | |
| List * | belonging_to () const |
| Get the list this element belongs to. | |
Static Public Member Functions | |
| static char * | get_static_text (int token_type) |
| Get the static token text for the given token type. | |
Static Public Attributes | |
| static LanguageID | comment_id |
| Comment tokens. | |
| static LanguageID | pre_id |
| Preprocessor tokens. | |
| static LanguageID | dir_id |
| Compiler directives. | |
| static LanguageID | cpp_id |
| C/C++ core language tokens. | |
| static LanguageID | white_id |
| White-spaces. | |
| static LanguageID | wildcard_id |
| Wildcards. | |
| static LanguageID | keyword_id |
| Keywords. | |
| static LanguageID | open_id |
| Left parenthesis. | |
| static LanguageID | macro_op_id |
| Function-like macro operands. | |
| static LanguageID | identifier_id |
| Identifiers. | |
| static LanguageID | comma_id |
| Comma. | |
| static LanguageID | close_id |
| Right parenthesis. | |
| anonymous enum |
| Puma::Token::Token | ( | int | type = 0, |
| LanguageID | lang = LanguageID(0), | ||
| const char * | text = "" ) |
Constructor.
| type | The token type. |
| lang | The language of the token. |
| text | The optional token text (defaults to the empty string). |
| Puma::Token::Token | ( | const Token & | copy | ) |
Copy-constructor.
| copy | The token to copy. |
|
virtual |
Destructor.
Frees the token text.
|
inline |
Set the continuous lines appeared in this token.
| lines | The continuous line array. |
| DString & Puma::Token::dtext | ( | ) | const |
Get the token text from the global dictionary.
|
inlinevirtual |
Duplicate this token.
Implements Puma::ListElement.
| char * Puma::Token::get_static_text | ( | ) | const |
Get the static token text.
Only for keywords, operators, and other tokens with a constant token text.
|
static |
Get the static token text for the given token type.
Only for keywords, operators, and other tokens with a constant token text.
| token_type | The token type. |
|
inline |
Check if this is a right parenthesis.
Subset of core tokens.
|
inline |
Check if this is a comma.
Subset of core tokens.
|
inline |
Check if this is a comment.
|
inline |
Check if this is a core language token.
|
inline |
Check if this is a compiler directive token.
|
inline |
Check if the token is an identifier.
Subset of core tokens.
|
inline |
Check if the token is a keyword.
Subset of identifiers.
|
inline |
Check if the token is a macro call.
| bool Puma::Token::is_macro_generated | ( | ) | const |
Check if the token is macro generated.
|
inline |
Check if this is function-like macro operand.
|
inline |
Check if this is a left parenthesis.
Subset of core tokens.
|
inline |
Check if this is a preprocessor token.
|
inline |
Check if this is a white-space token.
|
inline |
Check if this is a wildcard token.
Subset of core tokens.
| int Puma::Token::line_breaks | ( | ) | const |
Count the number of line breaks in the text of this token.
|
inline |
Get the location of the token (usually the line and column in a file).
|
inline |
Set the location of the token (usually the line and column in a file).
| loc | The location. |
|
inline |
Set the token to be a macro call.
| is_call | Is a macro call or not. |
| void Puma::Token::operator delete | ( | void * | ptr | ) |
Free the memory allowed with the Token's own operator new.
The memory is not freed but kept back for reuse.
| ptr | A pointer to the memory to free. |
| void * Puma::Token::operator new | ( | size_t | size | ) |
Overwrite operator new for better performance.
Tokens are allocated very often. To reduce the overhead of allocating a lot of small portions of memory, this implementation reuses already allocated memory by using a constant size memory pool (see Puma::ConstSizeMemPool).
| size | The size of the memory to allocate in byte. |
| void Puma::Token::print | ( | std::ostream & | os | ) | const |
Print the token text on the given stream.
| os | The output stream. |
| void Puma::Token::reset | ( | int | type = 0, |
| const char * | text = 0, | ||
| LanguageID | lang = LanguageID(0) ) |
Reset the token object optionally providing new content.
| type | The new token type. |
| text | The new token text. |
| lang | The new token language. |
| const char * Puma::Token::text | ( | ) | const |
Get the token text.
|
inline |
Get the type of the token (see Puma::CTokens).
| Unit * Puma::Token::unit | ( | ) | const |
Get the unit this token belongs to.
|
static |
Right parenthesis.
|
static |
Comma.
|
static |
Comment tokens.
|
static |
C/C++ core language tokens.
|
static |
Compiler directives.
|
static |
Identifiers.
|
static |
Keywords.
|
static |
Function-like macro operands.
|
static |
Left parenthesis.
|
static |
Preprocessor tokens.
|
static |
White-spaces.
|
static |
Wildcards.