Rizin
unix-like reverse engineering framework and cli tools
|
#include <stdio.h>
#include <rz_types.h>
#include <rz_list.h>
#include <rz_util/rz_file.h>
#include <rz_type.h>
#include <tree_sitter/api.h>
#include <types_parser.h>
Go to the source code of this file.
Classes | |
struct | rz_type_parser_t |
Macros | |
#define | TS_START_END(node, start, end) |
Functions | |
static char * | ts_node_sub_string (TSNode node, const char *cstr) |
TSLanguage * | tree_sitter_c () |
CParserState * | c_parser_state_new (HtPP *base_types, HtPP *callable_types) |
void | c_parser_state_free (CParserState *state) |
void | c_parser_state_free_keep_ht (CParserState *state) |
void | c_parser_state_reset_keep_ht (CParserState *state) |
RZ_API RZ_OWN RzTypeParser * | rz_type_parser_new () |
Creates a new instance of the C type parser. More... | |
RZ_API RZ_OWN RzTypeParser * | rz_type_parser_init (HtPP *types, HtPP *callables) |
Creates a new instance of the C type parser. More... | |
RZ_API void | rz_type_parser_free (RZ_NONNULL RzTypeParser *parser) |
Frees the instance of the C type parser without destroying hashtables. More... | |
RZ_API void | rz_type_parser_free_purge (RZ_NONNULL RzTypeParser *parser) |
Frees the instance of the C type parser and destroy the hashtables. More... | |
static int | type_parse_string (CParserState *state, const char *code, char **error_msg) |
RZ_API int | rz_type_parse_string_stateless (RzTypeParser *parser, const char *code, char **error_msg) |
Parses the C type string reusing the existing parser state. More... | |
RZ_API int | rz_type_parse_file_stateless (RzTypeParser *parser, const char *path, const char *dir, char **error_msg) |
Parses the C types file reusing the existing parser state. More... | |
RZ_API int | rz_type_parse_file (RzTypeDB *typedb, const char *path, const char *dir, char **error_msg) |
Parses the C types file creating the new parser state. More... | |
RZ_API int | rz_type_parse_string (RzTypeDB *typedb, const char *code, char **error_msg) |
Parses the C type string creating the new parser state. More... | |
RZ_API void | rz_type_parse_reset (RzTypeDB *typedb) |
Reset the C parser state. More... | |
RZ_API RZ_OWN RzType * | rz_type_parse_string_single (RzTypeParser *parser, const char *code, char **error_msg) |
Parses the single C type definition. More... | |
RZ_API RZ_OWN RzType * | rz_type_parse_string_declaration_single (RzTypeParser *parser, const char *code, char **error_msg) |
Parses the single C type declaration. More... | |
Definition at line 13 of file c_cpp_parser.c.
void c_parser_state_free | ( | CParserState * | state | ) |
Definition at line 55 of file c_cpp_parser.c.
References free(), and rz_strbuf_free().
Referenced by rz_type_parser_free_purge().
void c_parser_state_free_keep_ht | ( | CParserState * | state | ) |
Definition at line 66 of file c_cpp_parser.c.
References free(), and rz_strbuf_free().
Referenced by rz_type_parser_free().
CParserState* c_parser_state_new | ( | HtPP * | base_types, |
HtPP * | callable_types | ||
) |
Definition at line 33 of file c_cpp_parser.c.
References RZ_NEW0, and rz_strbuf_new().
Referenced by rz_type_parse_string(), rz_type_parser_init(), and rz_type_parser_new().
void c_parser_state_reset_keep_ht | ( | CParserState * | state | ) |
Definition at line 75 of file c_cpp_parser.c.
References rz_strbuf_free(), and rz_strbuf_new().
Referenced by rz_type_parse_string_declaration_single(), and rz_type_parse_string_single().
RZ_API int rz_type_parse_file | ( | RzTypeDB * | typedb, |
const char * | path, | ||
const char * | dir, | ||
char ** | error_msg | ||
) |
Parses the C types file creating the new parser state.
typedb | RzTypeDB instance |
path | The path to the C file to parse |
dir | The directory where the C file is located |
error_msg | A pointer where all error messages will be stored |
Definition at line 260 of file c_cpp_parser.c.
References free(), path, PFMT64d, rz_file_size(), rz_file_slurp(), RZ_LOG_DEBUG, and rz_type_parse_string().
Referenced by cmd_print_format(), and rz_core_run_script().
RZ_API int rz_type_parse_file_stateless | ( | RzTypeParser * | parser, |
const char * | path, | ||
const char * | dir, | ||
char ** | error_msg | ||
) |
Parses the C types file reusing the existing parser state.
parser | RzTypeParser instance |
path | The path to the C file to parse |
dir | The directory where the C file is located |
error_msg | A pointer where all error messages will be stored |
Definition at line 239 of file c_cpp_parser.c.
References free(), cmd_descs_generate::parser, path, PFMT64d, rz_file_size(), rz_file_slurp(), RZ_LOG_DEBUG, and rz_type_parse_string_stateless().
Referenced by rz_types_open_file().
Reset the C parser state.
typedb | RzTypeDB instance |
Definition at line 297 of file c_cpp_parser.c.
References rz_type_db_t::parser, rz_type_parser_free(), and rz_type_parser_new().
Referenced by rz_type_del_all_handler().
Parses the C type string creating the new parser state.
typedb | RzTypeDB instance |
code | The C type itself |
error_msg | A pointer where all error messages will be stored |
Definition at line 280 of file c_cpp_parser.c.
References c_parser_state_new(), rz_type_db_t::callables, eprintf, type_parse_string(), rz_type_db_t::types, and verbose.
Referenced by rz_type_parse_file().
RZ_API RZ_OWN RzType* rz_type_parse_string_declaration_single | ( | RzTypeParser * | parser, |
const char * | code, | ||
char ** | error_msg | ||
) |
Parses the single C type declaration.
parser | RzTypeParser parser instance |
code | The C type itself |
error_msg | A pointer where all error messages will be stored |
Definition at line 411 of file c_cpp_parser.c.
References c_parser_state_reset_keep_ht(), free(), i, NULL, parse_declaration_node(), cmd_descs_generate::parser, parser_debug(), parser_warning(), RZ_LOG_DEBUG, rz_strbuf_drain_nofree(), strdup(), tree_sitter_c(), ts_node_named_child(), ts_node_named_child_count(), ts_node_string(), ts_node_type(), ts_parser_delete(), ts_parser_new(), ts_parser_parse_string(), ts_parser_set_language(), ts_tree_delete(), ts_tree_root_node(), and ParserTypePair::type.
Referenced by rz_analysis_function_set_type_str().
RZ_API RZ_OWN RzType* rz_type_parse_string_single | ( | RzTypeParser * | parser, |
const char * | code, | ||
char ** | error_msg | ||
) |
Parses the single C type definition.
parser | RzTypeParser parser instance |
code | The C type itself |
error_msg | A pointer where all error messages will be stored |
Definition at line 309 of file c_cpp_parser.c.
References c_parser_state_reset_keep_ht(), free(), i, NULL, parse_type_descriptor_single(), cmd_descs_generate::parser, parser_debug(), parser_warning(), RZ_LOG_DEBUG, rz_return_val_if_fail, rz_str_newf(), rz_strbuf_drain_nofree(), strdup(), tree_sitter_c(), ts_node_named_child(), ts_node_named_child_count(), ts_node_string(), ts_node_type(), ts_parser_delete(), ts_parser_new(), ts_parser_parse_string(), ts_parser_set_language(), ts_tree_delete(), ts_tree_root_node(), and ParserTypePair::type.
Referenced by get_struct_type(), get_typedef_type(), get_union_type(), parse_enum_type(), parse_struct_member(), parse_type(), parse_type_string_cached(), parse_typedef(), rz_analysis_dwarf_integrate_functions(), rz_analysis_function_signature_type_handler(), rz_analysis_function_vars_bp_handler(), rz_analysis_function_vars_regs_handler(), rz_analysis_function_vars_sp_handler(), rz_analysis_function_vars_type_handler(), rz_analysis_global_variable_add_handler(), rz_analysis_global_variable_retype_handler(), rz_core_types_link(), type_match(), typelinks_load_sdb(), types_xrefs(), var_type_clone_or_default_type(), var_type_set_str(), and variable_set_type().
RZ_API int rz_type_parse_string_stateless | ( | RzTypeParser * | parser, |
const char * | code, | ||
char ** | error_msg | ||
) |
Parses the C type string reusing the existing parser state.
parser | RzTypeParser instance |
code | The C type itself |
error_msg | A pointer where all error messages will be stored |
Definition at line 227 of file c_cpp_parser.c.
References cmd_descs_generate::parser, and type_parse_string().
Referenced by rz_core_bin_export_info(), rz_type_db_edit_base_type(), rz_type_parse_file_stateless(), rz_types_define(), and rz_types_open_file().
RZ_API void rz_type_parser_free | ( | RZ_NONNULL RzTypeParser * | parser | ) |
Frees the instance of the C type parser without destroying hashtables.
Definition at line 127 of file c_cpp_parser.c.
References c_parser_state_free_keep_ht(), free(), and cmd_descs_generate::parser.
Referenced by rz_type_db_free(), rz_type_db_purge(), and rz_type_parse_reset().
RZ_API void rz_type_parser_free_purge | ( | RZ_NONNULL RzTypeParser * | parser | ) |
Frees the instance of the C type parser and destroy the hashtables.
Definition at line 136 of file c_cpp_parser.c.
References c_parser_state_free(), free(), and cmd_descs_generate::parser.
RZ_API RZ_OWN RzTypeParser* rz_type_parser_init | ( | HtPP * | types, |
HtPP * | callables | ||
) |
Creates a new instance of the C type parser.
Creates the new instance of the C types parser preloaded hashtables for RzBaseTypes and RzCallable types. It will use provided hashtables for storing the parsed types as well.
type | RzBaseTypes hashtable to preload into the parser state |
type | RzCallable hashtable to preload into the parser state |
Definition at line 115 of file c_cpp_parser.c.
References c_parser_state_new(), NULL, cmd_descs_generate::parser, RZ_NEW0, and types.
Referenced by rz_type_db_new(), and rz_type_db_purge().
RZ_API RZ_OWN RzTypeParser* rz_type_parser_new | ( | ) |
Creates a new instance of the C type parser.
Creates the new instance of the C types parser with empty hashtables for RzBaseTypes and RzCallable types.
Definition at line 96 of file c_cpp_parser.c.
References c_parser_state_new(), NULL, cmd_descs_generate::parser, and RZ_NEW0.
Referenced by rz_type_parse_reset().
TSLanguage* tree_sitter_c | ( | ) |
Definition at line 79645 of file parser.c.
References ALIAS_COUNT, EXTERNAL_TOKEN_COUNT, FIELD_COUNT, LANGUAGE_VERSION, LARGE_STATE_COUNT, MAX_ALIAS_SEQUENCE_LENGTH, PRODUCTION_ID_COUNT, STATE_COUNT, sym_identifier, SYMBOL_COUNT, TOKEN_COUNT, ts_alias_sequences, ts_field_map_entries, ts_field_map_slices, ts_field_names, ts_lex(), ts_lex_keywords(), ts_lex_modes, ts_non_terminal_alias_map, ts_parse_actions, ts_parse_table, ts_small_parse_table, ts_small_parse_table_map, ts_symbol_map, ts_symbol_metadata, ts_symbol_names, and TSLanguage::version.
Referenced by rz_type_parse_string_declaration_single(), rz_type_parse_string_single(), and type_parse_string().
Definition at line 19 of file c_cpp_parser.c.
References test_evm::end, rz_str_newf(), start, and TS_START_END.
Referenced by type_parse_string().
|
static |
Definition at line 141 of file c_cpp_parser.c.
References free(), i, NULL, parse_type_nodes_save(), cmd_descs_generate::parser, parser_debug(), parser_warning(), RZ_LOG_DEBUG, rz_strbuf_drain_nofree(), strdup(), tree_sitter_c(), ts_node_named_child(), ts_node_named_child_count(), ts_node_string(), ts_node_sub_string(), ts_node_type(), ts_parser_delete(), ts_parser_new(), ts_parser_parse_string(), ts_parser_set_language(), ts_tree_delete(), and ts_tree_root_node().
Referenced by rz_type_parse_string(), and rz_type_parse_string_stateless().