Rizin
unix-like reverse engineering framework and cli tools
|
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include "./length.h"
#include "./array.h"
#include "./error_costs.h"
#include "./host.h"
#include "tree_sitter/api.h"
#include "tree_sitter/parser.h"
Go to the source code of this file.
Classes | |
struct | ExternalScannerState |
struct | SubtreeInlineData |
struct | SubtreeHeapData |
union | Subtree |
union | MutableSubtree |
struct | SubtreePool |
Macros | |
#define | TS_TREE_STATE_NONE USHRT_MAX |
#define | NULL_SUBTREE ((Subtree) {.ptr = NULL}) |
#define | SUBTREE_BITS |
#define | SUBTREE_SIZE |
#define | SUBTREE_GET(self, name) (self.data.is_inline ? self.data.name : self.ptr->name) |
#define | ts_subtree_children(self) ((self).data.is_inline ? NULL : (Subtree *)((self).ptr) - (self).ptr->child_count) |
Typedefs | |
typedef struct SubtreeInlineData | SubtreeInlineData |
#define SUBTREE_BITS |
#define SUBTREE_GET | ( | self, | |
name | |||
) | (self.data.is_inline ? self.data.name : self.ptr->name) |
#define SUBTREE_SIZE |
typedef struct SubtreeInlineData SubtreeInlineData |
typedef Array | ( | MutableSubtree | ) |
typedef Array | ( | Subtree | ) |
const char* ts_external_scanner_state_data | ( | const ExternalScannerState * | self | ) |
Definition at line 53 of file subtree.c.
Referenced by ts_external_scanner_state_eq(), ts_parser__restore_external_scanner(), and ts_stack_print_dot_graph().
void ts_external_scanner_state_init | ( | ExternalScannerState * | self, |
const char * | data, | ||
unsigned | length | ||
) |
Definition at line 28 of file subtree.c.
References length, memcpy(), and ts_malloc.
Referenced by ts_parser__lex().
Definition at line 227 of file subtree.h.
Referenced by stack__iter(), ts_subtree_clone(), and ts_subtree_new_node().
void ts_subtree_array_clear | ( | SubtreePool * | pool, |
SubtreeArray * | self | ||
) |
Definition at line 83 of file subtree.c.
References array_clear, i, and ts_subtree_release().
Referenced by ts_parser__reduce(), and ts_subtree_array_delete().
void ts_subtree_array_copy | ( | SubtreeArray | self, |
SubtreeArray * | dest | ||
) |
Definition at line 70 of file subtree.c.
References dest, i, memcpy(), ts_calloc, and ts_subtree_retain().
Referenced by stack__iter().
void ts_subtree_array_delete | ( | SubtreePool * | pool, |
SubtreeArray * | self | ||
) |
Definition at line 90 of file subtree.c.
References array_delete, and ts_subtree_array_clear().
Referenced by stack__iter(), ts_parser__recover(), ts_parser__recover_to_state(), and ts_parser__reduce().
void ts_subtree_array_remove_trailing_extras | ( | SubtreeArray * | self, |
SubtreeArray * | destination | ||
) |
Definition at line 95 of file subtree.c.
References array_clear, array_push, ts_subtree_array_reverse(), and ts_subtree_extra().
Referenced by ts_parser__recover_to_state(), and ts_parser__reduce().
void ts_subtree_array_reverse | ( | SubtreeArray * | self | ) |
Definition at line 112 of file subtree.c.
References i, limit, and swap.
Referenced by stack__iter(), and ts_subtree_array_remove_trailing_extras().
void ts_subtree_balance | ( | Subtree | self, |
SubtreePool * | pool, | ||
const TSLanguage * | language | ||
) |
Definition at line 338 of file subtree.c.
References array_clear, array_pop, array_push, SubtreeHeapData::child_count, i, long, n, Subtree::ptr, MutableSubtree::ptr, SubtreeHeapData::ref_count, SubtreeHeapData::repeat_depth, SubtreePool::tree_stack, ts_subtree__compress(), ts_subtree_child_count(), ts_subtree_children, ts_subtree_repeat_depth(), and ts_subtree_to_mut_unsafe().
Referenced by ts_parser_parse().
Definition at line 282 of file subtree.h.
Referenced by iterator_advance(), iterator_descend(), reusable_node_advance(), reusable_node_descend(), stack__subtree_is_equivalent(), ts_node__relevant_child_count(), ts_node_child_count(), ts_node_iterate_children(), ts_node_named_child_count(), ts_parser__accept(), ts_parser__advance(), ts_parser__breakdown_lookahead(), ts_parser__breakdown_top_of_stack(), ts_parser__handle_error(), ts_parser__recover_to_state(), ts_parser__shift(), ts_subtree__print_dot_graph(), ts_subtree__write_to_string(), ts_subtree_balance(), ts_subtree_compare(), ts_subtree_edit(), ts_subtree_has_trailing_empty_descendant(), ts_subtree_production_id(), ts_subtree_summarize_children(), ts_subtree_visible_child_count(), and ts_tree_cursor_iterate_children().
Definition at line 615 of file subtree.c.
References i, n, ts_subtree_child_count(), ts_subtree_children, and ts_subtree_symbol().
Referenced by ts_parser__select_tree().
Definition at line 334 of file subtree.h.
References false.
Referenced by ts_subtree__print_dot_graph(), ts_subtree_edit(), and ts_subtree_summarize_children().
Definition at line 310 of file subtree.h.
Referenced by stack_node_add_link(), stack_node_new(), ts_parser__select_tree(), ts_stack_print_dot_graph(), and ts_subtree_summarize_children().
Subtree ts_subtree_edit | ( | Subtree | self, |
const TSInputEdit * | edit, | ||
SubtreePool * | pool | ||
) |
Definition at line 640 of file subtree.c.
References Array, array_delete, array_new, array_pop, array_push, Length::bytes, SubtreeHeapData::child_count, TSPoint::column, MutableSubtree::data, SubtreeHeapData::depends_on_column, SubtreeHeapData::error_cost, Length::extent, SubtreeHeapData::extra, SubtreeHeapData::fragile_left, SubtreeHeapData::fragile_right, SubtreeHeapData::has_changes, SubtreeHeapData::has_external_tokens, i, SubtreeInlineData::is_inline, SubtreeHeapData::is_keyword, SubtreeHeapData::is_missing, length_add(), length_sub(), length_zero(), SubtreeHeapData::lookahead_bytes, n, SubtreeHeapData::named, Edit::new_end, TSInputEdit::new_end_byte, TSInputEdit::new_end_point, Edit::old_end, TSInputEdit::old_end_byte, TSInputEdit::old_end_point, SubtreeHeapData::padding, SubtreeInlineData::parse_state, SubtreeHeapData::parse_state, MutableSubtree::ptr, SubtreeHeapData::ref_count, TSPoint::row, SubtreeHeapData::size, Edit::start, TSInputEdit::start_byte, TSInputEdit::start_point, SubtreeInlineData::symbol, SubtreeHeapData::symbol, ts_subtree_can_inline(), ts_subtree_child_count(), ts_subtree_children, ts_subtree_depends_on_column(), ts_subtree_from_mut(), ts_subtree_lookahead_bytes(), ts_subtree_make_mut(), ts_subtree_padding(), ts_subtree_pool_allocate(), ts_subtree_set_has_changes(), ts_subtree_size(), ts_subtree_total_size(), and SubtreeHeapData::visible.
Referenced by ts_tree_edit().
Definition at line 302 of file subtree.h.
References ERROR_COST_PER_MISSING_TREE, ERROR_COST_PER_RECOVERY, and ts_subtree_missing().
Referenced by stack__subtree_is_equivalent(), stack_node_new(), ts_node_has_error(), ts_parser__better_version_exists(), ts_parser__select_tree(), ts_parser_parse(), ts_stack_has_advanced_since_error(), ts_stack_print_dot_graph(), ts_subtree__print_dot_graph(), and ts_subtree_summarize_children().
Definition at line 1027 of file subtree.c.
References SubtreeHeapData::child_count, empty_state, SubtreeHeapData::external_scanner_state, Subtree::ptr, ts_external_scanner_state_eq(), and ts_subtree_has_external_tokens().
Referenced by stack__subtree_is_equivalent(), ts_parser__get_cached_token(), ts_parser__reuse_node(), and ts_stack_can_merge().
Definition at line 216 of file subtree.h.
References SUBTREE_GET.
Referenced by iterator_advance(), iterator_descend(), stack__iter(), stack__subtree_is_equivalent(), ts_node_child_by_field_id(), ts_node_child_iterator_next(), ts_node_is_extra(), ts_parser__accept(), ts_parser__breakdown_top_of_stack(), ts_parser__shift(), ts_stack_print_dot_graph(), ts_subtree__print_dot_graph(), ts_subtree__write_to_string(), ts_subtree_array_remove_trailing_extras(), ts_subtree_summarize_children(), ts_tree_cursor_child_iterator_next(), ts_tree_cursor_current_field_id(), ts_tree_cursor_current_node(), ts_tree_cursor_current_status(), and ts_tree_cursor_goto_parent().
Definition at line 322 of file subtree.h.
References false.
Referenced by ts_subtree_summarize_children().
Definition at line 326 of file subtree.h.
References false.
Referenced by ts_subtree_summarize_children().
|
inlinestatic |
Definition at line 350 of file subtree.h.
References Subtree::data.
Referenced by ts_parser__accept(), ts_parser__advance(), ts_parser__recover(), ts_parser__reduce(), ts_parser__select_children(), ts_parser__shift(), ts_subtree__compress(), ts_subtree_edit(), and ts_subtree_new_error_node().
Definition at line 217 of file subtree.h.
References SUBTREE_GET.
Referenced by iterator_compare(), ts_node_has_changes(), ts_parser__reuse_node(), and ts_subtree__print_dot_graph().
Definition at line 330 of file subtree.h.
References false.
Referenced by reusable_node_advance(), ts_parser__recover(), ts_parser__shift(), ts_subtree_external_scanner_state_eq(), ts_subtree_last_external_token(), and ts_subtree_summarize_children().
Definition at line 346 of file subtree.h.
References ts_builtin_sym_end, and ts_subtree_symbol().
Referenced by ts_parser__accept(), ts_parser__recover(), and ts_parser__reuse_node().
Definition at line 342 of file subtree.h.
References ts_builtin_sym_error, and ts_subtree_symbol().
Referenced by pop_error_callback(), ts_parser__breakdown_top_of_stack(), ts_parser__recover(), ts_parser__reuse_node(), ts_stack_pop_error(), ts_subtree__print_dot_graph(), ts_subtree__write_to_string(), and ts_subtree_summarize_children().
Definition at line 219 of file subtree.h.
References SUBTREE_GET.
Referenced by ts_parser__advance(), and ts_parser__can_reuse_first_leaf().
Definition at line 802 of file subtree.c.
References SubtreeHeapData::child_count, i, NULL_SUBTREE, Subtree::ptr, ts_subtree_children, and ts_subtree_has_external_tokens().
Referenced by reusable_node_advance(), ts_parser__recover(), and ts_parser__shift().
Definition at line 250 of file subtree.h.
Referenced by ts_parser__can_reuse_first_leaf(), and ts_subtree_summarize_children().
Definition at line 244 of file subtree.h.
Referenced by ts_parser__advance(), ts_parser__can_reuse_first_leaf(), ts_parser__handle_error(), ts_parser__reuse_node(), and ts_subtree_summarize_children().
Definition at line 221 of file subtree.h.
References SUBTREE_GET.
Referenced by ts_parser__handle_error(), ts_subtree__print_dot_graph(), ts_subtree_edit(), and ts_subtree_summarize_children().
MutableSubtree ts_subtree_make_mut | ( | SubtreePool * | pool, |
Subtree | self | ||
) |
Definition at line 284 of file subtree.c.
References MutableSubtree::data, ts_subtree_clone(), ts_subtree_release(), and ts_subtree_to_mut_unsafe().
Referenced by ts_parser__advance(), ts_parser__recover(), ts_parser__shift(), and ts_subtree_edit().
Definition at line 218 of file subtree.h.
References SUBTREE_GET.
Referenced by ts_node_is_missing(), ts_parser__reuse_node(), ts_subtree__write_to_string(), and ts_subtree_error_cost().
Definition at line 215 of file subtree.h.
References SUBTREE_GET.
Referenced by ts_node__is_relevant(), ts_node_is_named(), ts_stack_print_dot_graph(), ts_subtree__write_to_string(), and ts_subtree_summarize_children().
Subtree ts_subtree_new_error | ( | SubtreePool * | pool, |
int32_t | lookahead_char, | ||
Length | padding, | ||
Length | size, | ||
uint32_t | bytes_scanned, | ||
TSStateId | parse_state, | ||
const TSLanguage * | language | ||
) |
Definition at line 244 of file subtree.c.
References SubtreeHeapData::fragile_left, SubtreeHeapData::fragile_right, SubtreeHeapData::lookahead_char, Subtree::ptr, ts_builtin_sym_error, and ts_subtree_new_leaf().
Referenced by ts_parser__lex().
Subtree ts_subtree_new_error_node | ( | SubtreeArray * | children, |
bool | extra, | ||
const TSLanguage * | language | ||
) |
Definition at line 542 of file subtree.c.
References SubtreeHeapData::extra, MutableSubtree::ptr, ts_builtin_sym_error, ts_subtree_from_mut(), and ts_subtree_new_node().
Referenced by ts_parser__recover(), and ts_parser__recover_to_state().
Subtree ts_subtree_new_leaf | ( | SubtreePool * | pool, |
TSSymbol | symbol, | ||
Length | padding, | ||
Length | size, | ||
uint32_t | lookahead_bytes, | ||
TSStateId | parse_state, | ||
bool | has_external_tokens, | ||
bool | depends_on_column, | ||
bool | is_keyword, | ||
const TSLanguage * | language | ||
) |
Definition at line 167 of file subtree.c.
References Length::bytes, TSPoint::column, Length::extent, TSSymbolMetadata::named, SubtreeHeapData::ref_count, TSPoint::row, ts_builtin_sym_end, ts_language_symbol_metadata(), ts_subtree_can_inline(), ts_subtree_pool_allocate(), UINT8_MAX, and TSSymbolMetadata::visible.
Referenced by ts_parser__lex(), ts_subtree_new_error(), and ts_subtree_new_missing_leaf().
Subtree ts_subtree_new_missing_leaf | ( | SubtreePool * | pool, |
TSSymbol | symbol, | ||
Length | padding, | ||
uint32_t | lookahead_bytes, | ||
const TSLanguage * | language | ||
) |
Definition at line 558 of file subtree.c.
References Subtree::data, SubtreeInlineData::is_inline, length_zero(), Subtree::ptr, and ts_subtree_new_leaf().
Referenced by ts_parser__handle_error().
MutableSubtree ts_subtree_new_node | ( | TSSymbol | symbol, |
SubtreeArray * | children, | ||
unsigned | production_id, | ||
const TSLanguage * | language | ||
) |
Definition at line 500 of file subtree.c.
References TSSymbolMetadata::named, MutableSubtree::ptr, SubtreeHeapData::ref_count, ts_builtin_sym_error, ts_builtin_sym_error_repeat, ts_language_symbol_metadata(), ts_realloc, ts_subtree_alloc_size(), ts_subtree_summarize_children(), and TSSymbolMetadata::visible.
Referenced by ts_parser__accept(), ts_parser__recover(), ts_parser__reduce(), ts_parser__select_children(), and ts_subtree_new_error_node().
Definition at line 290 of file subtree.h.
Referenced by stack_node_add_link(), stack_node_new(), and ts_subtree_summarize_children().
Definition at line 256 of file subtree.h.
Referenced by iterator_advance(), iterator_descend(), iterator_end_position(), iterator_start_position(), stack__subtree_is_equivalent(), ts_node_child_iterator_next(), ts_subtree_edit(), ts_subtree_summarize_children(), ts_subtree_total_size(), ts_tree_cursor_child_iterator_next(), and ts_tree_root_node().
Definition at line 220 of file subtree.h.
References SUBTREE_GET.
Referenced by iterator_compare(), ts_parser__breakdown_lookahead(), ts_parser__can_reuse_first_leaf(), and ts_subtree__print_dot_graph().
void ts_subtree_pool_delete | ( | SubtreePool * | self | ) |
Definition at line 129 of file subtree.c.
References array_delete, i, and ts_free.
Referenced by ts_parser_delete(), ts_tree_delete(), and ts_tree_edit().
SubtreePool ts_subtree_pool_new | ( | uint32_t | capacity | ) |
Definition at line 123 of file subtree.c.
References array_new, and array_reserve.
Referenced by ts_parser_new(), ts_tree_delete(), and ts_tree_edit().
void ts_subtree_print_dot_graph | ( | Subtree | self, |
const TSLanguage * | language, | ||
FILE * | f | ||
) |
Definition at line 1020 of file subtree.c.
References f, and ts_subtree__print_dot_graph().
Referenced by ts_tree_print_dot_graph().
Definition at line 314 of file subtree.h.
References ts_subtree_child_count().
Referenced by ts_subtree__print_dot_graph().
void ts_subtree_release | ( | SubtreePool * | pool, |
Subtree | self | ||
) |
Definition at line 584 of file subtree.c.
References array_clear, array_pop, array_push, assert(), atomic_dec(), SubtreeHeapData::child_count, Subtree::data, SubtreeHeapData::external_scanner_state, SubtreeHeapData::has_external_tokens, i, SubtreeInlineData::is_inline, Subtree::ptr, MutableSubtree::ptr, SubtreeHeapData::ref_count, SubtreePool::tree_stack, ts_external_scanner_state_delete(), ts_free, ts_subtree_children, ts_subtree_pool_free(), and ts_subtree_to_mut_unsafe().
Referenced by stack_head_delete(), stack_node_add_link(), stack_node_release(), ts_parser__accept(), ts_parser__advance(), ts_parser__breakdown_lookahead(), ts_parser__breakdown_top_of_stack(), ts_parser__recover(), ts_parser__reduce(), ts_parser__set_cached_token(), ts_parser_delete(), ts_parser_reset(), ts_stack_set_last_external_token(), ts_subtree_array_clear(), ts_subtree_make_mut(), and ts_tree_delete().
Definition at line 286 of file subtree.h.
Referenced by ts_subtree__print_dot_graph(), ts_subtree_balance(), and ts_subtree_summarize_children().
void ts_subtree_retain | ( | Subtree | self | ) |
Definition at line 577 of file subtree.c.
References assert(), and atomic_inc().
Referenced by stack__iter(), stack_node_add_link(), ts_parser__accept(), ts_parser__breakdown_lookahead(), ts_parser__breakdown_top_of_stack(), ts_parser__get_cached_token(), ts_parser__recover_to_state(), ts_parser__reuse_node(), ts_parser__set_cached_token(), ts_parser_parse(), ts_stack__add_version(), ts_stack_copy_version(), ts_stack_set_last_external_token(), ts_subtree_array_copy(), ts_subtree_clone(), and ts_tree_copy().
|
inlinestatic |
Definition at line 236 of file subtree.h.
Referenced by ts_parser__recover(), and ts_parser__shift().
void ts_subtree_set_symbol | ( | MutableSubtree * | self, |
TSSymbol | symbol, | ||
const TSLanguage * | language | ||
) |
Definition at line 226 of file subtree.c.
References assert(), TSSymbolMetadata::named, ts_language_symbol_metadata(), UINT8_MAX, and TSSymbolMetadata::visible.
Referenced by ts_parser__advance().
Definition at line 265 of file subtree.h.
Referenced by iterator_compare(), iterator_descend(), iterator_end_position(), stack__subtree_is_equivalent(), ts_node_child_iterator_next(), ts_node_end_byte(), ts_node_end_point(), ts_parser__can_reuse_first_leaf(), ts_subtree_edit(), ts_subtree_summarize_children(), ts_subtree_total_size(), ts_tree_cursor_child_iterator_next(), ts_tree_cursor_goto_first_child_for_byte(), and ts_tree_cursor_goto_first_child_for_point().
char* ts_subtree_string | ( | Subtree | self, |
const TSLanguage * | language, | ||
bool | include_all | ||
) |
Definition at line 947 of file subtree.c.
References ROOT_FIELD, ts_malloc, and ts_subtree__write_to_string().
Referenced by ts_node_string().
void ts_subtree_summarize | ( | MutableSubtree | , |
const Subtree * | , | ||
uint32_t | , | ||
const TSLanguage * | |||
) |
void ts_subtree_summarize_children | ( | MutableSubtree | self, |
const TSLanguage * | language | ||
) |
Definition at line 371 of file subtree.c.
References assert(), SubtreeHeapData::depends_on_column, ERROR_COST_PER_RECOVERY, ERROR_COST_PER_SKIPPED_CHAR, ERROR_COST_PER_SKIPPED_LINE, ERROR_COST_PER_SKIPPED_TREE, SubtreeHeapData::first_leaf, i, length_add(), SubtreeHeapData::named_child_count, Subtree::ptr, ts_builtin_sym_error, ts_builtin_sym_error_repeat, ts_language_alias_sequence(), ts_language_symbol_metadata(), ts_subtree_child_count(), ts_subtree_children, ts_subtree_depends_on_column(), ts_subtree_dynamic_precedence(), ts_subtree_error_cost(), ts_subtree_extra(), ts_subtree_fragile_left(), ts_subtree_fragile_right(), ts_subtree_has_external_tokens(), ts_subtree_is_error(), ts_subtree_leaf_parse_state(), ts_subtree_leaf_symbol(), ts_subtree_lookahead_bytes(), ts_subtree_named(), ts_subtree_node_count(), ts_subtree_padding(), ts_subtree_repeat_depth(), ts_subtree_size(), ts_subtree_symbol(), ts_subtree_total_size(), ts_subtree_visible(), TS_TREE_STATE_NONE, and SubtreeHeapData::visible_child_count.
Referenced by ts_subtree__compress(), and ts_subtree_new_node().
Definition at line 213 of file subtree.h.
References SUBTREE_GET.
Referenced by iterator_compare(), stack__subtree_is_equivalent(), ts_node_symbol(), ts_node_type(), ts_parser__accept(), ts_parser__advance(), ts_parser__breakdown_top_of_stack(), ts_parser__get_cached_token(), ts_parser__lex(), ts_parser__recover(), ts_parser__select_children(), ts_stack_print_dot_graph(), ts_subtree__print_dot_graph(), ts_subtree__write_to_string(), ts_subtree_compare(), ts_subtree_is_eof(), ts_subtree_is_error(), and ts_subtree_summarize_children().
|
inlinestatic |
Definition at line 356 of file subtree.h.
References MutableSubtree::data.
Referenced by ts_subtree__compress(), ts_subtree_balance(), ts_subtree_make_mut(), and ts_subtree_release().
Definition at line 278 of file subtree.h.
References Length::bytes, and ts_subtree_total_size().
Referenced by reusable_node_advance(), ts_node__prev_sibling(), ts_parser__handle_error(), ts_parser__recover(), ts_parser__reuse_node(), ts_stack_has_advanced_since_error(), ts_subtree__print_dot_graph(), and ts_subtree_has_trailing_empty_descendant().
Definition at line 274 of file subtree.h.
References length_add(), ts_subtree_padding(), and ts_subtree_size().
Referenced by iterator_advance(), stack_node_new(), ts_parser__lex(), ts_parser__recover(), ts_subtree_edit(), ts_subtree_get_changed_ranges(), ts_subtree_summarize_children(), and ts_subtree_total_bytes().
Definition at line 214 of file subtree.h.
References SUBTREE_GET.
Referenced by iterator_get_visible_state(), iterator_tree_is_visible(), ts_node__is_relevant(), ts_stack_print_dot_graph(), ts_subtree__write_to_string(), ts_subtree_summarize_children(), ts_tree_cursor_child_iterator_next(), ts_tree_cursor_current_field_id(), ts_tree_cursor_goto_parent(), and ts_tree_cursor_parent_node().
Definition at line 294 of file subtree.h.
References ts_subtree_child_count().
Referenced by ts_tree_cursor_current_status(), ts_tree_cursor_goto_first_child(), ts_tree_cursor_goto_first_child_for_byte(), ts_tree_cursor_goto_first_child_for_point(), and ts_tree_cursor_goto_next_sibling().