IDA C++ SDK 9.2
|
Tools for parsing C-like input. More...
Go to the source code of this file.
Classes | |
struct | token_t |
Parser token. More... | |
struct | lex_value_t |
Typedefs | |
typedef ushort | lxtype |
see Parser token types | |
typedef error_t | lx_resolver_t(lexer_t *lx, void *ud, token_t *curtok, sval_t *res) |
Preprocessor callback for unknown tokens. | |
typedef int idaapi | lx_preprocessor_cb(void *ud, const char *fname, int nl, const char *line) |
Preprocessor callback. | |
typedef int idaapi | lx_pragma_cb(void *ud, const char *line) |
Callback for #pragma directives. | |
typedef int idaapi | lx_warning_cb(void *ud, const char *line) |
Callback for #warning directives. | |
typedef int idaapi | lx_macro_cb(void *ud, const char *name, const char *body, int nargs, bool isfunc, bool is_new_macro) |
Callback for #define directives. | |
typedef int idaapi | lx_undef_cb(void *ud, const char *name) |
Callback for #undef directives. |
Functions | |
DECLARE_TYPE_AS_MOVABLE (token_t) | |
MSC_DIAG_OFF (4826) struct cast_t | |
Preprocessor cast. | |
MSC_DIAG_ON (4826) typedef error_t lx_parse_cast_t(lexer_t *lx | |
Preprocessor callbacks for casts. | |
idaman lexer_t *ida_export | create_lexer (const char *const *keys, size_t size, void *ud=nullptr, uint32 macro_flags=0) |
Create new lexical analyzer and set its keyword table. | |
idaman void ida_export | destroy_lexer (lexer_t *lx) |
Destroy a lexical analyzer. | |
idaman error_t ida_export | lex_define_macro (lexer_t *lx, const char *macro, const char *body, int nargs=0, bool isfunc=false) |
Define a macro. | |
idaman void ida_export | lex_undefine_macro (lexer_t *lx, const char *macro) |
Undefine a macro. | |
idaman int ida_export | lex_set_options (lexer_t *lx, int options) |
Set lexer options. | |
idaman error_t ida_export | lex_get_token (lexer_t *lx, token_t *t, int32 *p_lnnum=nullptr) |
Get next token. | |
idaman int ida_export | lex_enum_macros (const lexer_t *lx, int idaapi cb(const char *name, const char *body, int nargs, bool isfunc, void *ud), void *ud=nullptr) |
Enumerate all macros. | |
idaman const char *ida_export | lex_print_token (qstring *buf, const token_t *t) |
Debug: get text representation of token. | |
idaman bool ida_export | is_c_keyword (const char *name) |
is NAME a valid C keyword (exclude 'this') | |
String oriented functions | |
idaman error_t ida_export | lex_init_string (lexer_t *lx, const char *line, void *macros=nullptr) |
Set the input line and the macro table. | |
File oriented functions | |
idaman error_t ida_export | lex_init_file (lexer_t *lx, const char *file) |
Initialization: file may be nullptr. | |
idaman const char *ida_export | lex_get_file_line (lexer_t *lx, int32 *linenum, const char **lineptr, int level=0) |
Error handling. | |
idaman void ida_export | lex_term_file (lexer_t *lx, bool del_macros) |
Termination: also see lex_init_file() |
Variables | |
const lxtype | lx_end = 1 |
no more tokens | |
const lxtype | lx_ident = 2 |
ident | |
const lxtype | lx_number = 3 |
long constant | |
const lxtype | lx_string = 4 |
string constant (token_t.chr != 0 => unicode string) | |
const lxtype | lx_char = 5 |
char constant | |
const lxtype | lx_typename = 6 |
user-defined type | |
const lxtype | lx_float = 7 |
IEEE floating point constant. | |
const lxtype | lx_int64 = 8 |
int64 constant | |
const lxtype | lx_callcnv = 9 |
custom calling convention | |
const lxtype | lx_key = 128 |
keywords start. | |
cast_t * | cast |
cast_t token_t * | ct |
Token stack | |
typedef qstack< token_t > | tokenstack_t |
see get_token(), unget_token() | |
bool | get_token (token_t *t, lexer_t *lx, tokenstack_t &buf) |
Retrieve token from a stack or lexer. | |
void | unget_token (const token_t &t, tokenstack_t &buf) |
Push a token back onto the token stack. |
Tools for parsing C-like input.
Functions in this file use objects of opaque type lexer_t. To create a lexer_t instance, use create_lexer().
Preprocessor callback for unknown tokens.
Will be called when preprocessor calculates the value of #if expression.
typedef int idaapi lx_preprocessor_cb(void *ud, const char *fname, int nl, const char *line) |
Preprocessor callback.
It will be called for each input line.
typedef int idaapi lx_pragma_cb(void *ud, const char *line) |
Callback for #pragma directives.
typedef int idaapi lx_warning_cb(void *ud, const char *line) |
Callback for #warning directives.
typedef int idaapi lx_macro_cb(void *ud, const char *name, const char *body, int nargs, bool isfunc, bool is_new_macro) |
Callback for #define directives.
typedef int idaapi lx_undef_cb(void *ud, const char *name) |
Callback for #undef directives.
typedef qstack<token_t> tokenstack_t |
see get_token(), unget_token()
DECLARE_TYPE_AS_MOVABLE | ( | token_t | ) |
MSC_DIAG_OFF | ( | 4826 | ) |
Preprocessor cast.
MSC_DIAG_ON | ( | 4826 | ) |
Preprocessor callbacks for casts.
Will be called when preprocessor calculates the value of #if expression.
idaman lexer_t *ida_export create_lexer | ( | const char *const * | keys, |
size_t | size, | ||
void * | ud = nullptr, | ||
uint32 | macro_flags = 0 ) |
Create new lexical analyzer and set its keyword table.
If keys==nullptr, then set the default C keyword table
idaman void ida_export destroy_lexer | ( | lexer_t * | lx | ) |
Destroy a lexical analyzer.
idaman error_t ida_export lex_define_macro | ( | lexer_t * | lx, |
const char * | macro, | ||
const char * | body, | ||
int | nargs = 0, | ||
bool | isfunc = false ) |
Define a macro.
idaman void ida_export lex_undefine_macro | ( | lexer_t * | lx, |
const char * | macro ) |
Undefine a macro.
lx | the lexer object |
macro | macro to undefine |
idaman int ida_export lex_set_options | ( | lexer_t * | lx, |
int | options ) |
Get next token.
lx | the lexer object |
t | the output buffer for the token |
p_lnnum | the line number where the token starts |
idaman int ida_export lex_enum_macros | ( | const lexer_t * | lx, |
int idaapi | cbconst char *name, const char *body, int nargs, bool isfunc, void *ud, | ||
void * | ud = nullptr ) |
Enumerate all macros.
Do so until 'cb' returns non-zero.
Debug: get text representation of token.
idaman error_t ida_export lex_init_string | ( | lexer_t * | lx, |
const char * | line, | ||
void * | macros = nullptr ) |
Set the input line and the macro table.
if macros==nullptr, the macro table will not be changed.
idaman error_t ida_export lex_init_file | ( | lexer_t * | lx, |
const char * | file ) |
Initialization: file may be nullptr.
Also see lex_term_file().
idaman const char *ida_export lex_get_file_line | ( | lexer_t * | lx, |
int32 * | linenum, | ||
const char ** | lineptr, | ||
int | level = 0 ) |
Error handling.
if level > 0, then return information about the enclosing file which included the current one.
Termination: also see lex_init_file()
|
inline |
Retrieve token from a stack or lexer.
If buf is not empty then get the token on top of the stack. If buf is empty then gen the next token from the lexer.
|
inline |
Push a token back onto the token stack.
idaman bool ida_export is_c_keyword | ( | const char * | name | ) |
is NAME a valid C keyword (exclude 'this')
cast_t* cast |
cast_t token_t* ct |