Rizin
unix-like reverse engineering framework and cli tools
types_parser.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 Anton Kochkov <anton.kochkov@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 typedef struct {
5  size_t unions;
6  size_t structs;
7  size_t enums;
8  size_t callables;
10 
11 typedef struct {
12  bool verbose;
13  HtPP *types;
14  HtPP *callables;
15  HtPP *forward;
20 } CParserState;
21 
22 typedef struct {
26 
27 CParserState *c_parser_state_new(HtPP *base_types, HtPP *callable_types);
29 
30 int parse_type_nodes_save(CParserState *state, TSNode node, const char *text);
31 int parse_type_node_single(CParserState *state, TSNode node, const char *text, ParserTypePair **tpair, bool is_const);
32 int parse_declaration_node(CParserState *state, TSNode node, const char *text, ParserTypePair **tpair);
34 int parse_type_declarator_node(CParserState *state, TSNode node, const char *text, ParserTypePair **tpair, char **identifier);
36 
37 void parser_debug(CParserState *state, const char *fmt, ...);
38 void parser_error(CParserState *state, const char *fmt, ...);
39 void parser_warning(CParserState *state, const char *fmt, ...);
40 
41 // Types storage API
42 
49 
53 
55 
58 
63 
65 RZ_OWN ParserTypePair *c_parser_new_union_type(CParserState *state, RZ_NONNULL const char *name, size_t members_count);
68 
73 
76 
80 
81 // ParserTypePair wrapper helpers
86 
87 // Generators of the anonymous type names
voidpf void uLong size
Definition: ioapi.h:138
int type
Definition: mipsasm.c:17
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
CParserAnonymousTypesState anon
Definition: types_parser.h:19
RzStrBuf * debug
Definition: types_parser.h:18
HtPP * callables
Definition: types_parser.h:14
RzStrBuf * warnings
Definition: types_parser.h:17
HtPP * forward
Definition: types_parser.h:15
HtPP * types
Definition: types_parser.h:13
RzStrBuf * errors
Definition: types_parser.h:16
RzType * type
Definition: types_parser.h:24
RzBaseType * btype
Definition: types_parser.h:23
Definition: api.h:92
Definition: z80asm.h:102
Definition: dis.h:43
RZ_OWN ParserTypePair * c_parser_new_union_naked_type(CParserState *state, RZ_NONNULL const char *name)
Creates new union naked type (without base type) based on the name.
bool c_parser_pointer_set_subtype(CParserState *state, RZ_BORROW ParserTypePair *tpair, RZ_OWN ParserTypePair *subpair)
RzBaseType * c_parser_base_type_find(CParserState *state, RZ_NONNULL const char *name)
Definition: types_storage.c:17
int parse_declaration_node(CParserState *state, TSNode node, const char *text, ParserTypePair **tpair)
bool c_parser_base_type_exists(CParserState *state, RZ_NONNULL const char *name)
Definition: types_storage.c:32
int parse_type_node_single(CParserState *state, TSNode node, const char *text, ParserTypePair **tpair, bool is_const)
bool c_parser_forward_definition_remove(CParserState *state, RZ_NONNULL const char *name)
Definition: types_storage.c:70
bool c_parser_base_type_is_forward_definition(CParserState *state, RZ_NONNULL const char *name)
Definition: types_storage.c:26
RZ_OWN ParserTypePair * c_parser_new_unspecified_naked_type(CParserState *state, RZ_NONNULL const char *name, bool is_const)
Creates new unspecified naked type (without base type) based on the name.
bool c_parser_array_set_subtype(CParserState *state, RZ_BORROW ParserTypePair *tpair, RZ_OWN ParserTypePair *subpair)
int parse_type_nodes_save(CParserState *state, TSNode node, const char *text)
int parse_type_descriptor_single(CParserState *state, TSNode node, const char *text, ParserTypePair **tpair)
RZ_OWN ParserTypePair * c_parser_new_enum_type(CParserState *state, RZ_NONNULL const char *name, size_t cases_count)
Creates new enumeration type based on the name.
bool c_parser_base_type_store(CParserState *state, RZ_NONNULL const char *name, ParserTypePair *tpair)
Definition: types_storage.c:36
RZ_OWN ParserTypePair * c_parser_new_structure_type(CParserState *state, RZ_NONNULL const char *name, size_t members_count)
Creates new structure "type + base type" pair based on the name.
RZ_OWN ParserTypePair * c_parser_get_structure_type(CParserState *state, RZ_NONNULL const char *name)
Returns the structure type if matching in the types hashtable.
RZ_OWN ParserTypePair * c_parser_new_primitive_type(CParserState *state, RZ_NONNULL const char *name, bool is_const)
Creates new primitive type based on the name.
RZ_OWN RzType * c_parser_new_callable(CParserState *state, RZ_NONNULL const char *name)
Creates new callable based on the name.
RZ_OWN ParserTypePair * c_parser_new_typedef(CParserState *state, RZ_NONNULL const char *name, RZ_NONNULL const char *base)
Creates new type alias based on the name.
bool c_parser_forward_definition_store(CParserState *state, RZ_NONNULL const char *name)
Definition: types_storage.c:50
RZ_OWN ParserTypePair * c_parser_type_wrap_to_array(CParserState *state, ParserTypePair *tpair, size_t size)
RZ_OWN char * c_parser_new_anonymous_callable_name(CParserState *state)
RZ_OWN ParserTypePair * c_parser_new_enum_naked_type(CParserState *state, RZ_NONNULL const char *name)
Creates new enum naked type (without base type) based on the name.
int parse_type_declarator_node(CParserState *state, TSNode node, const char *text, ParserTypePair **tpair, char **identifier)
RZ_OWN ParserTypePair * c_parser_new_structure_naked_type(CParserState *state, RZ_NONNULL const char *name)
Creates new structure naked type (without base type) based on the name.
void parser_debug(CParserState *state, const char *fmt,...)
Definition: types_parser.c:37
RZ_OWN char * c_parser_new_anonymous_enum_name(CParserState *state)
int parse_type_abstract_declarator_node(CParserState *state, TSNode node, const char *text, ParserTypePair **tpair)
RZ_OWN ParserTypePair * c_parser_get_typedef(CParserState *state, RZ_NONNULL const char *name)
Returns the type if matching in the types hashtable.
RZ_OWN ParserTypePair * c_parser_new_enum_forward_definition(CParserState *state, RZ_NONNULL const char *name)
Creates new enum forward definition.
RZ_OWN char * c_parser_new_anonymous_structure_name(CParserState *state)
bool c_parser_new_callable_argument(CParserState *state, RZ_NONNULL RzCallable *callable, RZ_NONNULL const char *name, RZ_OWN RZ_NONNULL RzType *type)
Adds a new argument to the callable.
CParserState * c_parser_state_new(HtPP *base_types, HtPP *callable_types)
Definition: c_cpp_parser.c:33
RZ_OWN ParserTypePair * c_parser_get_enum_type(CParserState *state, RZ_NONNULL const char *name)
Returns the enum type if matching in the types hashtable.
RZ_OWN char * c_parser_new_anonymous_union_name(CParserState *state)
bool c_parser_callable_type_exists(CParserState *state, RZ_NONNULL const char *name)
Definition: types_storage.c:94
RzCallable * c_parser_callable_type_find(CParserState *state, RZ_NONNULL const char *name)
Definition: types_storage.c:85
void parser_error(CParserState *state, const char *fmt,...)
Definition: types_parser.c:47
RZ_OWN ParserTypePair * c_parser_get_union_type(CParserState *state, RZ_NONNULL const char *name)
Returns the union type if matching in the types hashtable.
RZ_OWN ParserTypePair * c_parser_get_primitive_type(CParserState *state, RZ_NONNULL const char *name, bool is_const)
Returns the primitive type if matching in the types hashtable.
RZ_OWN ParserTypePair * c_parser_new_union_type(CParserState *state, RZ_NONNULL const char *name, size_t members_count)
Creates new union "type + base type" pair based on the name.
RZ_OWN ParserTypePair * c_parser_new_union_forward_definition(CParserState *state, RZ_NONNULL const char *name)
Creates new union forward definition.
void parser_warning(CParserState *state, const char *fmt,...)
Definition: types_parser.c:55
RZ_OWN ParserTypePair * c_parser_type_wrap_to_pointer(CParserState *state, ParserTypePair *tpair, bool is_const)
void c_parser_state_free(CParserState *state)
Definition: c_cpp_parser.c:55
RZ_OWN RzType * c_parser_new_naked_callable(CParserState *state)
Creates new naked callable without storing it.
RZ_OWN ParserTypePair * c_parser_new_structure_forward_definition(CParserState *state, RZ_NONNULL const char *name)
Creates new structure forward definition.
bool c_parser_callable_type_store(CParserState *state, RZ_NONNULL const char *name, RZ_NONNULL RzType *type)
Definition: types_storage.c:98