31 const TSRangeArray *
self,
36 for (
unsigned i = start_index;
i <
self->size;
i++) {
38 if (
range->end_byte > start_byte) {
39 if (
range->start_byte >= end_byte)
break;
47 const TSRange *old_ranges,
unsigned old_range_count,
48 const TSRange *new_ranges,
unsigned new_range_count,
49 TSRangeArray *differences
51 unsigned new_index = 0;
52 unsigned old_index = 0;
54 bool in_old_range =
false;
55 bool in_new_range =
false;
57 while (old_index < old_range_count || new_index < new_range_count) {
58 const TSRange *old_range = &old_ranges[old_index];
59 const TSRange *new_range = &new_ranges[new_index];
64 }
else if (old_index < old_range_count) {
73 }
else if (new_index < new_range_count) {
79 if (next_old_position.
bytes < next_new_position.
bytes) {
80 if (in_old_range != in_new_range) {
83 if (in_old_range) old_index++;
84 current_position = next_old_position;
85 in_old_range = !in_old_range;
86 }
else if (next_new_position.
bytes < next_old_position.
bytes) {
87 if (in_old_range != in_new_range) {
90 if (in_new_range) new_index++;
91 current_position = next_new_position;
92 in_new_range = !in_new_range;
94 if (in_old_range != in_new_range) {
97 if (in_old_range) old_index++;
98 if (in_new_range) new_index++;
99 in_old_range = !in_old_range;
100 in_new_range = !in_new_range;
101 current_position = next_new_position;
121 .position = length_zero(),
123 .structural_child_index = 0,
127 .language = language,
134 return self->cursor.stack.size == 0;
139 if (self->in_padding) {
140 return entry.position;
149 if (self->in_padding) {
159 if (self->cursor.stack.size > 1) {
160 Subtree parent = *
self->cursor.stack.contents[
self->cursor.stack.size - 2].subtree;
164 entry.structural_child_index
176 uint32_t i =
self->cursor.stack.size - 1;
178 if (self->in_padding) {
183 for (;
i + 1 > 0;
i--) {
187 const Subtree *parent =
self->cursor.stack.contents[
i - 1].subtree;
191 entry.structural_child_index
196 *tree = *
entry.subtree;
197 *start_byte =
entry.position.bytes;
206 if (
array_back(&self->cursor.stack)->child_index > 0)
self->in_padding =
false;
207 self->cursor.stack.size--;
211 if (self->in_padding)
return false;
218 uint32_t structural_child_index = 0;
224 if (child_right.
bytes > goal_position) {
227 .position = position,
229 .structural_child_index = structural_child_index,
233 if (child_left.
bytes > goal_position) {
234 self->in_padding =
true;
236 self->visible_depth++;
245 position = child_right;
248 }
while (did_descend);
254 if (self->in_padding) {
255 self->in_padding =
false;
257 self->visible_depth++;
273 uint32_t structural_child_index =
entry.structural_child_index;
278 .subtree = next_child,
279 .position = position,
280 .child_index = child_index,
281 .structural_child_index = structural_child_index,
286 self->in_padding =
true;
288 self->visible_depth++;
321 old_alias_symbol == new_alias_symbol &&
324 if (old_start == new_start &&
341 #ifdef DEBUG_GET_CHANGED_RANGES
342 static inline void iterator_print_state(
Iterator *
self) {
348 "(%-25s %s\t depth:%u [%u, %u] - [%u, %u])",
349 name, self->in_padding ?
"(p)" :
" ",
361 const TSRangeArray *included_range_differences,
369 unsigned included_range_difference_index = 0;
375 position = next_position;
376 }
else if (position.
bytes > next_position.
bytes) {
378 next_position = position;
382 #ifdef DEBUG_GET_CHANGED_RANGES
384 iterator_print_state(&old_iter);
386 iterator_print_state(&new_iter);
397 included_range_differences,
398 included_range_difference_index,
405 bool is_changed =
false;
406 switch (comparison) {
462 #ifdef DEBUG_GET_CHANGED_RANGES
464 " change: [[%u, %u] - [%u, %u]]\n",
473 position = next_position;
477 while (included_range_difference_index < included_range_differences->
size) {
478 const TSRange *
range = &included_range_differences->contents[
479 included_range_difference_index
482 included_range_difference_index++;
497 *cursor1 = old_iter.
cursor;
498 *cursor2 = new_iter.
cursor;
499 *ranges = results.contents;
const char * ts_language_symbol_name(const TSLanguage *, TSSymbol)
#define array_push(self, element)
#define array_clear(self)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
static void iterator_ascend(Iterator *self)
static void ts_range_array_add(TSRangeArray *self, Length start, Length end)
static IteratorComparison iterator_compare(const Iterator *old_iter, const Iterator *new_iter)
static bool iterator_done(Iterator *self)
static void iterator_advance(Iterator *self)
static bool iterator_tree_is_visible(const Iterator *self)
static bool iterator_descend(Iterator *self, uint32_t goal_position)
static void iterator_get_visible_state(const Iterator *self, Subtree *tree, TSSymbol *alias_symbol, uint32_t *start_byte)
static Length iterator_end_position(Iterator *self)
void ts_range_array_get_changed_ranges(const TSRange *old_ranges, unsigned old_range_count, const TSRange *new_ranges, unsigned new_range_count, TSRangeArray *differences)
static Iterator iterator_new(TreeCursor *cursor, const Subtree *tree, const TSLanguage *language)
static Length iterator_start_position(Iterator *self)
bool ts_range_array_intersects(const TSRangeArray *self, unsigned start_index, uint32_t start_byte, uint32_t end_byte)
unsigned ts_subtree_get_changed_ranges(const Subtree *old_tree, const Subtree *new_tree, TreeCursor *cursor1, TreeCursor *cursor2, const TSLanguage *language, const TSRangeArray *included_range_differences, TSRange **ranges)
static TSSymbol ts_language_alias_at(const TSLanguage *self, uint32_t production_id, uint32_t child_index)
static Length length_zero(void)
static Length length_add(Length len1, Length len2)
static Length length_min(Length len1, Length len2)
static const Length LENGTH_MAX
#define ts_builtin_sym_error
const TSLanguage * language
#define ts_subtree_children(self)
static bool ts_subtree_visible(Subtree self)
static Length ts_subtree_total_size(Subtree self)
#define TS_TREE_STATE_NONE
static bool ts_subtree_extra(Subtree self)
static bool ts_subtree_has_changes(Subtree self)
static Length ts_subtree_size(Subtree self)
static TSStateId ts_subtree_parse_state(Subtree self)
static uint32_t ts_subtree_child_count(Subtree self)
static Length ts_subtree_padding(Subtree self)
static TSSymbol ts_subtree_symbol(Subtree self)
const SubtreeHeapData * ptr