tree_sitter_c2rust_core/
get_changed_ranges.rs

1use crate::util::*;
2use crate::*;
3use c2rust_bitfields;
4use std::os;
5pub type __u8 = os::raw::c_uchar;
6pub type __int16_t = os::raw::c_short;
7pub type __u16 = os::raw::c_ushort;
8pub type __int32_t = os::raw::c_int;
9pub type __u32 = os::raw::c_uint;
10pub type int16_t = __int16_t;
11pub type int32_t = __int32_t;
12pub type TSSymbol = u16;
13pub type TSFieldId = u16;
14pub type TSStateId = u16;
15#[derive(Copy, Clone)]
16#[repr(C)]
17pub struct C2RustUnnamed {
18    pub states: *const bool,
19    pub symbol_map: *const TSSymbol,
20    pub create: Option<unsafe extern "C" fn() -> *mut os::raw::c_void>,
21    pub destroy: Option<unsafe extern "C" fn(*mut os::raw::c_void) -> ()>,
22    pub scan: Option<unsafe extern "C" fn(*mut os::raw::c_void, *mut TSLexer, *const bool) -> bool>,
23    pub serialize:
24        Option<unsafe extern "C" fn(*mut os::raw::c_void, *mut os::raw::c_char) -> os::raw::c_uint>,
25    pub deserialize: Option<
26        unsafe extern "C" fn(*mut os::raw::c_void, *const os::raw::c_char, os::raw::c_uint) -> (),
27    >,
28}
29#[derive(Copy, Clone)]
30#[repr(C)]
31pub struct C2RustUnnamed_0 {
32    pub count: u8,
33    pub reusable: bool,
34}
35#[derive(Copy, Clone)]
36#[repr(C)]
37pub struct C2RustUnnamed_1 {
38    pub type_: u8,
39    pub child_count: u8,
40    pub symbol: TSSymbol,
41    pub dynamic_precedence: int16_t,
42    pub production_id: u16,
43}
44#[derive(Copy, Clone)]
45#[repr(C)]
46pub struct C2RustUnnamed_2 {
47    pub type_: u8,
48    pub state: TSStateId,
49    pub extra: bool,
50    pub repetition: bool,
51}
52#[derive(Copy, Clone)]
53#[repr(C)]
54pub struct VoidArray {
55    pub contents: *mut os::raw::c_void,
56    pub size: u32,
57    pub capacity: u32,
58}
59type C2RustUnnamed_3 = crate::util::LongShortData;
60type C2RustUnnamed_4 = crate::util::ScannerStateWithLookahead;
61type C2RustUnnamed_5 = crate::util::ScannerStateLookaheadMeta;
62type C2RustUnnamed_6 = crate::util::ScannerStateLookaheadFirstLeaf;
63type C2RustUnnamed_7 = crate::util::StackElement<*mut TreeCursorEntry>;
64#[derive(Copy, Clone)]
65#[repr(C)]
66pub struct TSRangeArray {
67    pub contents: *mut TSRange,
68    pub size: u32,
69    pub capacity: u32,
70}
71#[derive(Copy, Clone)]
72#[repr(C)]
73pub struct Iterator_0 {
74    pub cursor: TreeCursor,
75    pub language: *const TSLanguage,
76    pub visible_depth: os::raw::c_uint,
77    pub in_padding: bool,
78}
79pub const IteratorDiffers: IteratorComparison = 0;
80pub const IteratorMayDiffer: IteratorComparison = 1;
81pub const IteratorMatches: IteratorComparison = 2;
82pub type IteratorComparison = os::raw::c_uint;
83#[inline]
84unsafe extern "C" fn point__new(mut row: os::raw::c_uint, mut column: os::raw::c_uint) -> TSPoint {
85    let mut result: TSPoint = {
86        let mut init = TSPoint {
87            row: row,
88            column: column,
89        };
90        init
91    };
92    return result;
93}
94#[inline]
95unsafe extern "C" fn point_add(mut a: TSPoint, mut b: TSPoint) -> TSPoint {
96    if b.row > 0 as os::raw::c_int as os::raw::c_uint {
97        return point__new((a.row).wrapping_add(b.row), b.column);
98    } else {
99        return point__new(a.row, (a.column).wrapping_add(b.column));
100    };
101}
102static mut LENGTH_MAX: Length = {
103    let mut init = Length {
104        bytes: 4294967295 as os::raw::c_uint,
105        extent: {
106            let mut init = TSPoint {
107                row: 4294967295 as os::raw::c_uint,
108                column: 4294967295 as os::raw::c_uint,
109            };
110            init
111        },
112    };
113    init
114};
115#[inline]
116unsafe extern "C" fn length_min(mut len1: Length, mut len2: Length) -> Length {
117    return if len1.bytes < len2.bytes { len1 } else { len2 };
118}
119#[inline]
120unsafe extern "C" fn length_add(mut len1: Length, mut len2: Length) -> Length {
121    let mut result: Length = Length {
122        bytes: 0,
123        extent: TSPoint { row: 0, column: 0 },
124    };
125    result.bytes = (len1.bytes).wrapping_add(len2.bytes);
126    result.extent = point_add(len1.extent, len2.extent);
127    return result;
128}
129#[inline]
130unsafe extern "C" fn length_zero() -> Length {
131    let mut result: Length = {
132        let mut init = Length {
133            bytes: 0 as os::raw::c_int as u32,
134            extent: {
135                let mut init = TSPoint {
136                    row: 0 as os::raw::c_int as u32,
137                    column: 0 as os::raw::c_int as u32,
138                };
139                init
140            },
141        };
142        init
143    };
144    return result;
145}
146#[inline]
147unsafe extern "C" fn array__reserve(
148    mut self_0: *mut VoidArray,
149    mut element_size: size_t,
150    mut new_capacity: u32,
151) {
152    if new_capacity > (*self_0).capacity {
153        if !((*self_0).contents).is_null() {
154            let ref mut fresh0 = (*self_0).contents;
155            *fresh0 = crate::alloc::ts_realloc(
156                (*self_0).contents,
157                (new_capacity as usize).wrapping_mul(element_size),
158            );
159        } else {
160            let ref mut fresh1 = (*self_0).contents;
161            *fresh1 = crate::alloc::ts_malloc((new_capacity as usize).wrapping_mul(element_size));
162        }
163        (*self_0).capacity = new_capacity;
164    }
165}
166#[inline]
167unsafe extern "C" fn array__grow(
168    mut self_0: *mut VoidArray,
169    mut count: size_t,
170    mut element_size: size_t,
171) {
172    let mut new_size: size_t = ((*self_0).size as usize).wrapping_add(count);
173    if new_size > (*self_0).capacity as usize {
174        let mut new_capacity: size_t =
175            ((*self_0).capacity).wrapping_mul(2 as os::raw::c_int as os::raw::c_uint) as size_t;
176        if new_capacity < 8 as os::raw::c_int as usize {
177            new_capacity = 8 as os::raw::c_int as size_t;
178        }
179        if new_capacity < new_size {
180            new_capacity = new_size;
181        }
182        array__reserve(self_0, element_size, new_capacity as u32);
183    }
184}
185#[inline]
186unsafe extern "C" fn ts_subtree_symbol(mut self_0: Subtree) -> TSSymbol {
187    return (if (self_0.data).is_inline() as os::raw::c_int != 0 {
188        self_0.data.symbol as os::raw::c_int
189    } else {
190        (*self_0.ptr).symbol as os::raw::c_int
191    }) as TSSymbol;
192}
193#[inline]
194unsafe extern "C" fn ts_subtree_visible(mut self_0: Subtree) -> bool {
195    return if (self_0.data).is_inline() as os::raw::c_int != 0 {
196        (self_0.data).visible() as os::raw::c_int
197    } else {
198        (*self_0.ptr).visible() as os::raw::c_int
199    } != 0;
200}
201#[inline]
202unsafe extern "C" fn ts_subtree_extra(mut self_0: Subtree) -> bool {
203    return if (self_0.data).is_inline() as os::raw::c_int != 0 {
204        (self_0.data).extra() as os::raw::c_int
205    } else {
206        (*self_0.ptr).extra() as os::raw::c_int
207    } != 0;
208}
209#[inline]
210unsafe extern "C" fn ts_subtree_has_changes(mut self_0: Subtree) -> bool {
211    return if (self_0.data).is_inline() as os::raw::c_int != 0 {
212        (self_0.data).has_changes() as os::raw::c_int
213    } else {
214        (*self_0.ptr).has_changes() as os::raw::c_int
215    } != 0;
216}
217#[inline]
218unsafe extern "C" fn ts_subtree_parse_state(mut self_0: Subtree) -> TSStateId {
219    return (if (self_0.data).is_inline() as os::raw::c_int != 0 {
220        self_0.data.parse_state as os::raw::c_int
221    } else {
222        (*self_0.ptr).parse_state as os::raw::c_int
223    }) as TSStateId;
224}
225#[inline]
226unsafe extern "C" fn ts_subtree_padding(mut self_0: Subtree) -> Length {
227    if (self_0.data).is_inline() {
228        let mut result: Length = {
229            let mut init = Length {
230                bytes: self_0.data.padding_bytes as u32,
231                extent: {
232                    let mut init = TSPoint {
233                        row: (self_0.data).padding_rows() as u32,
234                        column: self_0.data.padding_columns as u32,
235                    };
236                    init
237                },
238            };
239            init
240        };
241        return result;
242    } else {
243        return (*self_0.ptr).padding;
244    };
245}
246#[inline]
247unsafe extern "C" fn ts_subtree_size(mut self_0: Subtree) -> Length {
248    if (self_0.data).is_inline() {
249        let mut result: Length = {
250            let mut init = Length {
251                bytes: self_0.data.size_bytes as u32,
252                extent: {
253                    let mut init = TSPoint {
254                        row: 0 as os::raw::c_int as u32,
255                        column: self_0.data.size_bytes as u32,
256                    };
257                    init
258                },
259            };
260            init
261        };
262        return result;
263    } else {
264        return (*self_0.ptr).size;
265    };
266}
267#[inline]
268unsafe extern "C" fn ts_subtree_total_size(mut self_0: Subtree) -> Length {
269    return length_add(ts_subtree_padding(self_0), ts_subtree_size(self_0));
270}
271#[inline]
272unsafe extern "C" fn ts_subtree_child_count(mut self_0: Subtree) -> u32 {
273    return (if (self_0.data).is_inline() as os::raw::c_int != 0 {
274        0 as os::raw::c_int
275    } else {
276        (*self_0.ptr).child_count as os::raw::c_int
277    }) as u32;
278}
279#[inline]
280unsafe extern "C" fn ts_language_alias_at(
281    mut self_0: *const TSLanguage,
282    mut production_id: u32,
283    mut child_index: u32,
284) -> TSSymbol {
285    return (if production_id != 0 {
286        *((*self_0).alias_sequences).offset(
287            production_id
288                .wrapping_mul((*self_0).max_alias_sequence_length as os::raw::c_uint)
289                .wrapping_add(child_index) as isize,
290        ) as os::raw::c_int
291    } else {
292        0 as os::raw::c_int
293    }) as TSSymbol;
294}
295unsafe extern "C" fn ts_range_array_add(
296    mut self_0: *mut TSRangeArray,
297    mut start: Length,
298    mut end: Length,
299) {
300    if (*self_0).size > 0 as os::raw::c_int as os::raw::c_uint {
301        if ((*self_0).size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint) < (*self_0).size {
302        } else {
303            panic!();
304        }
305        let mut last_range: *mut TSRange = &mut *((*self_0).contents)
306            .offset(((*self_0).size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint) as isize)
307            as *mut TSRange;
308        if start.bytes <= (*last_range).end_byte {
309            (*last_range).end_byte = end.bytes;
310            (*last_range).end_point = end.extent;
311            return;
312        }
313    }
314    if start.bytes < end.bytes {
315        let mut range: TSRange = {
316            let mut init = TSRange {
317                start_point: start.extent,
318                end_point: end.extent,
319                start_byte: start.bytes,
320                end_byte: end.bytes,
321            };
322            init
323        };
324        array__grow(
325            self_0 as *mut VoidArray,
326            1 as os::raw::c_int as size_t,
327            ::std::mem::size_of::<TSRange>() as usize,
328        );
329        let ref mut fresh2 = (*self_0).size;
330        let fresh3 = *fresh2;
331        *fresh2 = (*fresh2).wrapping_add(1);
332        *((*self_0).contents).offset(fresh3 as isize) = range;
333    }
334}
335#[no_mangle]
336pub unsafe extern "C" fn ts_range_array_intersects(
337    mut self_0: *const TSRangeArray,
338    mut start_index: os::raw::c_uint,
339    mut start_byte: u32,
340    mut end_byte: u32,
341) -> bool {
342    let mut i: os::raw::c_uint = start_index;
343    while i < (*self_0).size {
344        let mut range: *mut TSRange = &mut *((*self_0).contents).offset(i as isize) as *mut TSRange;
345        if (*range).end_byte > start_byte {
346            if (*range).start_byte >= end_byte {
347                break;
348            }
349            return true;
350        } else {
351            i = i.wrapping_add(1);
352        }
353    }
354    return false;
355}
356#[no_mangle]
357pub unsafe extern "C" fn ts_range_array_get_changed_ranges(
358    mut old_ranges: *const TSRange,
359    mut old_range_count: os::raw::c_uint,
360    mut new_ranges: *const TSRange,
361    mut new_range_count: os::raw::c_uint,
362    mut differences: *mut TSRangeArray,
363) {
364    let mut new_index: os::raw::c_uint = 0 as os::raw::c_int as os::raw::c_uint;
365    let mut old_index: os::raw::c_uint = 0 as os::raw::c_int as os::raw::c_uint;
366    let mut current_position: Length = length_zero();
367    let mut in_old_range: bool = false;
368    let mut in_new_range: bool = false;
369    while old_index < old_range_count || new_index < new_range_count {
370        let mut old_range: *const TSRange =
371            &*old_ranges.offset(old_index as isize) as *const TSRange;
372        let mut new_range: *const TSRange =
373            &*new_ranges.offset(new_index as isize) as *const TSRange;
374        let mut next_old_position: Length = Length {
375            bytes: 0,
376            extent: TSPoint { row: 0, column: 0 },
377        };
378        if in_old_range {
379            next_old_position = {
380                let mut init = Length {
381                    bytes: (*old_range).end_byte,
382                    extent: (*old_range).end_point,
383                };
384                init
385            };
386        } else if old_index < old_range_count {
387            next_old_position = {
388                let mut init = Length {
389                    bytes: (*old_range).start_byte,
390                    extent: (*old_range).start_point,
391                };
392                init
393            };
394        } else {
395            next_old_position = LENGTH_MAX;
396        }
397        let mut next_new_position: Length = Length {
398            bytes: 0,
399            extent: TSPoint { row: 0, column: 0 },
400        };
401        if in_new_range {
402            next_new_position = {
403                let mut init = Length {
404                    bytes: (*new_range).end_byte,
405                    extent: (*new_range).end_point,
406                };
407                init
408            };
409        } else if new_index < new_range_count {
410            next_new_position = {
411                let mut init = Length {
412                    bytes: (*new_range).start_byte,
413                    extent: (*new_range).start_point,
414                };
415                init
416            };
417        } else {
418            next_new_position = LENGTH_MAX;
419        }
420        if next_old_position.bytes < next_new_position.bytes {
421            if in_old_range as os::raw::c_int != in_new_range as os::raw::c_int {
422                ts_range_array_add(differences, current_position, next_old_position);
423            }
424            if in_old_range {
425                old_index = old_index.wrapping_add(1);
426            }
427            current_position = next_old_position;
428            in_old_range = !in_old_range;
429        } else if next_new_position.bytes < next_old_position.bytes {
430            if in_old_range as os::raw::c_int != in_new_range as os::raw::c_int {
431                ts_range_array_add(differences, current_position, next_new_position);
432            }
433            if in_new_range {
434                new_index = new_index.wrapping_add(1);
435            }
436            current_position = next_new_position;
437            in_new_range = !in_new_range;
438        } else {
439            if in_old_range as os::raw::c_int != in_new_range as os::raw::c_int {
440                ts_range_array_add(differences, current_position, next_new_position);
441            }
442            if in_old_range {
443                old_index = old_index.wrapping_add(1);
444            }
445            if in_new_range {
446                new_index = new_index.wrapping_add(1);
447            }
448            in_old_range = !in_old_range;
449            in_new_range = !in_new_range;
450            current_position = next_new_position;
451        }
452    }
453}
454unsafe extern "C" fn iterator_new(
455    mut cursor: *mut TreeCursor,
456    mut tree: *const Subtree,
457    mut language: *const TSLanguage,
458) -> Iterator_0 {
459    (*cursor).stack.size = 0 as os::raw::c_int as u32;
460    array__grow(
461        &mut (*cursor).stack as *mut C2RustUnnamed_7 as *mut VoidArray,
462        1 as os::raw::c_int as size_t,
463        ::std::mem::size_of::<TreeCursorEntry>() as usize,
464    );
465    let ref mut fresh4 = (*cursor).stack.size;
466    let fresh5 = *fresh4;
467    *fresh4 = (*fresh4).wrapping_add(1);
468    *((*cursor).stack.contents).offset(fresh5 as isize) = {
469        let mut init = TreeCursorEntry {
470            subtree: tree,
471            position: length_zero(),
472            child_index: 0 as os::raw::c_int as u32,
473            structural_child_index: 0 as os::raw::c_int as u32,
474        };
475        init
476    };
477    return {
478        let mut init = Iterator_0 {
479            cursor: *cursor,
480            language: language,
481            visible_depth: 1 as os::raw::c_int as os::raw::c_uint,
482            in_padding: false,
483        };
484        init
485    };
486}
487unsafe extern "C" fn iterator_done(mut self_0: *mut Iterator_0) -> bool {
488    return (*self_0).cursor.stack.size == 0 as os::raw::c_int as os::raw::c_uint;
489}
490unsafe extern "C" fn iterator_start_position(mut self_0: *mut Iterator_0) -> Length {
491    if ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint)
492        < (*self_0).cursor.stack.size
493    {
494    } else {
495        panic!();
496    }
497    let mut entry: TreeCursorEntry = *(&mut *((*self_0).cursor.stack.contents).offset(
498        ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint) as isize,
499    ) as *mut TreeCursorEntry);
500    if (*self_0).in_padding {
501        return entry.position;
502    } else {
503        return length_add(entry.position, ts_subtree_padding(*entry.subtree));
504    };
505}
506unsafe extern "C" fn iterator_end_position(mut self_0: *mut Iterator_0) -> Length {
507    if ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint)
508        < (*self_0).cursor.stack.size
509    {
510    } else {
511        panic!();
512    }
513    let mut entry: TreeCursorEntry = *(&mut *((*self_0).cursor.stack.contents).offset(
514        ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint) as isize,
515    ) as *mut TreeCursorEntry);
516    let mut result: Length = length_add(entry.position, ts_subtree_padding(*entry.subtree));
517    if (*self_0).in_padding {
518        return result;
519    } else {
520        return length_add(result, ts_subtree_size(*entry.subtree));
521    };
522}
523unsafe extern "C" fn iterator_tree_is_visible(mut self_0: *const Iterator_0) -> bool {
524    if ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint)
525        < (*self_0).cursor.stack.size
526    {
527    } else {
528        panic!();
529    }
530    let mut entry: TreeCursorEntry = *(&mut *((*self_0).cursor.stack.contents).offset(
531        ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint) as isize,
532    ) as *mut TreeCursorEntry);
533    if ts_subtree_visible(*entry.subtree) {
534        return true;
535    }
536    if (*self_0).cursor.stack.size > 1 as os::raw::c_int as os::raw::c_uint {
537        let mut parent: Subtree = *(*((*self_0).cursor.stack.contents).offset(
538            ((*self_0).cursor.stack.size).wrapping_sub(2 as os::raw::c_int as os::raw::c_uint)
539                as isize,
540        ))
541        .subtree;
542        return ts_language_alias_at(
543            (*self_0).language,
544            (*parent.ptr).c2rust_unnamed.c2rust_unnamed.production_id as u32,
545            entry.structural_child_index,
546        ) as os::raw::c_int
547            != 0 as os::raw::c_int;
548    }
549    return false;
550}
551unsafe extern "C" fn iterator_get_visible_state(
552    mut self_0: *const Iterator_0,
553    mut tree: *mut Subtree,
554    mut alias_symbol: *mut TSSymbol,
555    mut start_byte: *mut u32,
556) {
557    let mut i: u32 =
558        ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint);
559    if (*self_0).in_padding {
560        if i == 0 as os::raw::c_int as os::raw::c_uint {
561            return;
562        }
563        i = i.wrapping_sub(1);
564    }
565    while i.wrapping_add(1 as os::raw::c_int as os::raw::c_uint)
566        > 0 as os::raw::c_int as os::raw::c_uint
567    {
568        let mut entry: TreeCursorEntry = *((*self_0).cursor.stack.contents).offset(i as isize);
569        if i > 0 as os::raw::c_int as os::raw::c_uint {
570            let mut parent: *const Subtree = (*((*self_0).cursor.stack.contents)
571                .offset(i.wrapping_sub(1 as os::raw::c_int as os::raw::c_uint) as isize))
572            .subtree;
573            *alias_symbol = ts_language_alias_at(
574                (*self_0).language,
575                (*(*parent).ptr).c2rust_unnamed.c2rust_unnamed.production_id as u32,
576                entry.structural_child_index,
577            );
578        }
579        if ts_subtree_visible(*entry.subtree) as os::raw::c_int != 0
580            || *alias_symbol as os::raw::c_int != 0
581        {
582            *tree = *entry.subtree;
583            *start_byte = entry.position.bytes;
584            break;
585        } else {
586            i = i.wrapping_sub(1);
587        }
588    }
589}
590unsafe extern "C" fn iterator_ascend(mut self_0: *mut Iterator_0) {
591    if iterator_done(self_0) {
592        return;
593    }
594    if iterator_tree_is_visible(self_0) as os::raw::c_int != 0 && !(*self_0).in_padding {
595        let ref mut fresh6 = (*self_0).visible_depth;
596        *fresh6 = (*fresh6).wrapping_sub(1);
597    }
598    if ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint)
599        < (*self_0).cursor.stack.size
600    {
601    } else {
602        panic!();
603    }
604    if (*(&mut *((*self_0).cursor.stack.contents).offset(
605        ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint) as isize,
606    ) as *mut TreeCursorEntry))
607        .child_index
608        > 0 as os::raw::c_int as os::raw::c_uint
609    {
610        (*self_0).in_padding = false;
611    }
612    let ref mut fresh7 = (*self_0).cursor.stack.size;
613    *fresh7 = (*fresh7).wrapping_sub(1);
614}
615unsafe extern "C" fn iterator_descend(mut self_0: *mut Iterator_0, mut goal_position: u32) -> bool {
616    if (*self_0).in_padding {
617        return false;
618    }
619    let mut did_descend: bool = false;
620    loop {
621        did_descend = false;
622        if ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint)
623            < (*self_0).cursor.stack.size
624        {
625        } else {
626            panic!();
627        }
628        let mut entry: TreeCursorEntry = *(&mut *((*self_0).cursor.stack.contents).offset(
629            ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint)
630                as isize,
631        ) as *mut TreeCursorEntry);
632        let mut position: Length = entry.position;
633        let mut structural_child_index: u32 = 0 as os::raw::c_int as u32;
634        let mut i: u32 = 0 as os::raw::c_int as u32;
635        let mut n: u32 = ts_subtree_child_count(*entry.subtree);
636        while i < n {
637            let mut child: *const Subtree =
638                &mut *if ((*entry.subtree).data).is_inline() as os::raw::c_int != 0 {
639                    0 as *mut Subtree
640                } else {
641                    ((*entry.subtree).ptr as *mut Subtree)
642                        .offset(-((*(*entry.subtree).ptr).child_count as os::raw::c_int as isize))
643                }
644                .offset(i as isize) as *mut Subtree;
645            let mut child_left: Length = length_add(position, ts_subtree_padding(*child));
646            let mut child_right: Length = length_add(child_left, ts_subtree_size(*child));
647            if child_right.bytes > goal_position {
648                array__grow(
649                    &mut (*self_0).cursor.stack as *mut C2RustUnnamed_7 as *mut VoidArray,
650                    1 as os::raw::c_int as size_t,
651                    ::std::mem::size_of::<TreeCursorEntry>() as usize,
652                );
653                let ref mut fresh8 = (*self_0).cursor.stack.size;
654                let fresh9 = *fresh8;
655                *fresh8 = (*fresh8).wrapping_add(1);
656                *((*self_0).cursor.stack.contents).offset(fresh9 as isize) = {
657                    let mut init = TreeCursorEntry {
658                        subtree: child,
659                        position: position,
660                        child_index: i,
661                        structural_child_index: structural_child_index,
662                    };
663                    init
664                };
665                if iterator_tree_is_visible(self_0) {
666                    if child_left.bytes > goal_position {
667                        (*self_0).in_padding = true;
668                    } else {
669                        let ref mut fresh10 = (*self_0).visible_depth;
670                        *fresh10 = (*fresh10).wrapping_add(1);
671                    }
672                    return true;
673                }
674                did_descend = true;
675                break;
676            } else {
677                position = child_right;
678                if !ts_subtree_extra(*child) {
679                    structural_child_index = structural_child_index.wrapping_add(1);
680                }
681                i = i.wrapping_add(1);
682            }
683        }
684        if !did_descend {
685            break;
686        }
687    }
688    return false;
689}
690unsafe extern "C" fn iterator_advance(mut self_0: *mut Iterator_0) {
691    if (*self_0).in_padding {
692        (*self_0).in_padding = false;
693        if iterator_tree_is_visible(self_0) {
694            let ref mut fresh11 = (*self_0).visible_depth;
695            *fresh11 = (*fresh11).wrapping_add(1);
696        } else {
697            iterator_descend(self_0, 0 as os::raw::c_int as u32);
698        }
699        return;
700    }
701    loop {
702        if iterator_tree_is_visible(self_0) {
703            let ref mut fresh12 = (*self_0).visible_depth;
704            *fresh12 = (*fresh12).wrapping_sub(1);
705        }
706        let ref mut fresh13 = (*self_0).cursor.stack.size;
707        *fresh13 = (*fresh13).wrapping_sub(1);
708        let mut entry: TreeCursorEntry =
709            *((*self_0).cursor.stack.contents).offset(*fresh13 as isize);
710        if iterator_done(self_0) {
711            return;
712        }
713        if ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint)
714            < (*self_0).cursor.stack.size
715        {
716        } else {
717            panic!();
718        }
719        let mut parent: *const Subtree = (*(&mut *((*self_0).cursor.stack.contents).offset(
720            ((*self_0).cursor.stack.size).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint)
721                as isize,
722        ) as *mut TreeCursorEntry))
723            .subtree;
724        let mut child_index: u32 =
725            (entry.child_index).wrapping_add(1 as os::raw::c_int as os::raw::c_uint);
726        if !(ts_subtree_child_count(*parent) > child_index) {
727            continue;
728        }
729        let mut position: Length =
730            length_add(entry.position, ts_subtree_total_size(*entry.subtree));
731        let mut structural_child_index: u32 = entry.structural_child_index;
732        if !ts_subtree_extra(*entry.subtree) {
733            structural_child_index = structural_child_index.wrapping_add(1);
734        }
735        let mut next_child: *const Subtree =
736            &mut *if ((*parent).data).is_inline() as os::raw::c_int != 0 {
737                0 as *mut Subtree
738            } else {
739                ((*parent).ptr as *mut Subtree)
740                    .offset(-((*(*parent).ptr).child_count as os::raw::c_int as isize))
741            }
742            .offset(child_index as isize) as *mut Subtree;
743        array__grow(
744            &mut (*self_0).cursor.stack as *mut C2RustUnnamed_7 as *mut VoidArray,
745            1 as os::raw::c_int as size_t,
746            ::std::mem::size_of::<TreeCursorEntry>() as usize,
747        );
748        let ref mut fresh14 = (*self_0).cursor.stack.size;
749        let fresh15 = *fresh14;
750        *fresh14 = (*fresh14).wrapping_add(1);
751        *((*self_0).cursor.stack.contents).offset(fresh15 as isize) = {
752            let mut init = TreeCursorEntry {
753                subtree: next_child,
754                position: position,
755                child_index: child_index,
756                structural_child_index: structural_child_index,
757            };
758            init
759        };
760        if iterator_tree_is_visible(self_0) {
761            if (ts_subtree_padding(*next_child)).bytes > 0 as os::raw::c_int as os::raw::c_uint {
762                (*self_0).in_padding = true;
763            } else {
764                let ref mut fresh16 = (*self_0).visible_depth;
765                *fresh16 = (*fresh16).wrapping_add(1);
766            }
767        } else {
768            iterator_descend(self_0, 0 as os::raw::c_int as u32);
769        }
770        break;
771    }
772}
773unsafe extern "C" fn iterator_compare(
774    mut old_iter: *const Iterator_0,
775    mut new_iter: *const Iterator_0,
776) -> IteratorComparison {
777    let mut old_tree: Subtree = Subtree {
778        ptr: 0 as *const SubtreeHeapData,
779    };
780    let mut new_tree: Subtree = Subtree {
781        ptr: 0 as *const SubtreeHeapData,
782    };
783    let mut old_start: u32 = 0 as os::raw::c_int as u32;
784    let mut new_start: u32 = 0 as os::raw::c_int as u32;
785    let mut old_alias_symbol: TSSymbol = 0 as os::raw::c_int as TSSymbol;
786    let mut new_alias_symbol: TSSymbol = 0 as os::raw::c_int as TSSymbol;
787    iterator_get_visible_state(
788        old_iter,
789        &mut old_tree,
790        &mut old_alias_symbol,
791        &mut old_start,
792    );
793    iterator_get_visible_state(
794        new_iter,
795        &mut new_tree,
796        &mut new_alias_symbol,
797        &mut new_start,
798    );
799    if (old_tree.ptr).is_null() && (new_tree.ptr).is_null() {
800        return IteratorMatches;
801    }
802    if (old_tree.ptr).is_null() || (new_tree.ptr).is_null() {
803        return IteratorDiffers;
804    }
805    if old_alias_symbol as os::raw::c_int == new_alias_symbol as os::raw::c_int
806        && ts_subtree_symbol(old_tree) as os::raw::c_int
807            == ts_subtree_symbol(new_tree) as os::raw::c_int
808    {
809        if old_start == new_start
810            && !ts_subtree_has_changes(old_tree)
811            && ts_subtree_symbol(old_tree) as os::raw::c_int
812                != -(1 as os::raw::c_int) as TSSymbol as os::raw::c_int
813            && (ts_subtree_size(old_tree)).bytes == (ts_subtree_size(new_tree)).bytes
814            && ts_subtree_parse_state(old_tree) as os::raw::c_int
815                != 32767 as os::raw::c_int * 2 as os::raw::c_int + 1 as os::raw::c_int
816            && ts_subtree_parse_state(new_tree) as os::raw::c_int
817                != 32767 as os::raw::c_int * 2 as os::raw::c_int + 1 as os::raw::c_int
818            && (ts_subtree_parse_state(old_tree) as os::raw::c_int == 0 as os::raw::c_int)
819                as os::raw::c_int
820                == (ts_subtree_parse_state(new_tree) as os::raw::c_int == 0 as os::raw::c_int)
821                    as os::raw::c_int
822        {
823            return IteratorMatches;
824        } else {
825            return IteratorMayDiffer;
826        }
827    }
828    return IteratorDiffers;
829}
830#[no_mangle]
831pub unsafe extern "C" fn ts_subtree_get_changed_ranges(
832    mut old_tree: *const Subtree,
833    mut new_tree: *const Subtree,
834    mut cursor1: *mut TreeCursor,
835    mut cursor2: *mut TreeCursor,
836    mut language: *const TSLanguage,
837    mut included_range_differences: *const TSRangeArray,
838    mut ranges: *mut *mut TSRange,
839) -> os::raw::c_uint {
840    let mut results: TSRangeArray = {
841        let mut init = TSRangeArray {
842            contents: 0 as *mut TSRange,
843            size: 0 as os::raw::c_int as u32,
844            capacity: 0 as os::raw::c_int as u32,
845        };
846        init
847    };
848    let mut old_iter: Iterator_0 = iterator_new(cursor1, old_tree, language);
849    let mut new_iter: Iterator_0 = iterator_new(cursor2, new_tree, language);
850    let mut included_range_difference_index: os::raw::c_uint =
851        0 as os::raw::c_int as os::raw::c_uint;
852    let mut position: Length = iterator_start_position(&mut old_iter);
853    let mut next_position: Length = iterator_start_position(&mut new_iter);
854    if position.bytes < next_position.bytes {
855        ts_range_array_add(&mut results, position, next_position);
856        position = next_position;
857    } else if position.bytes > next_position.bytes {
858        ts_range_array_add(&mut results, next_position, position);
859        next_position = position;
860    }
861    loop {
862        let mut comparison: IteratorComparison = iterator_compare(&mut old_iter, &mut new_iter);
863        if comparison as os::raw::c_uint == IteratorMatches as os::raw::c_int as os::raw::c_uint
864            && ts_range_array_intersects(
865                included_range_differences,
866                included_range_difference_index,
867                position.bytes,
868                (iterator_end_position(&mut old_iter)).bytes,
869            ) as os::raw::c_int
870                != 0
871        {
872            comparison = IteratorMayDiffer;
873        }
874        let mut is_changed: bool = false;
875        match comparison as os::raw::c_uint {
876            2 => {
877                next_position = iterator_end_position(&mut old_iter);
878            }
879            1 => {
880                if iterator_descend(&mut old_iter, position.bytes) {
881                    if !iterator_descend(&mut new_iter, position.bytes) {
882                        is_changed = true;
883                        next_position = iterator_end_position(&mut old_iter);
884                    }
885                } else if iterator_descend(&mut new_iter, position.bytes) {
886                    is_changed = true;
887                    next_position = iterator_end_position(&mut new_iter);
888                } else {
889                    next_position = length_min(
890                        iterator_end_position(&mut old_iter),
891                        iterator_end_position(&mut new_iter),
892                    );
893                }
894            }
895            0 => {
896                is_changed = true;
897                next_position = length_min(
898                    iterator_end_position(&mut old_iter),
899                    iterator_end_position(&mut new_iter),
900                );
901            }
902            _ => {}
903        }
904        while !iterator_done(&mut old_iter)
905            && (iterator_end_position(&mut old_iter)).bytes <= next_position.bytes
906        {
907            iterator_advance(&mut old_iter);
908        }
909        while !iterator_done(&mut new_iter)
910            && (iterator_end_position(&mut new_iter)).bytes <= next_position.bytes
911        {
912            iterator_advance(&mut new_iter);
913        }
914        while old_iter.visible_depth > new_iter.visible_depth {
915            iterator_ascend(&mut old_iter);
916        }
917        while new_iter.visible_depth > old_iter.visible_depth {
918            iterator_ascend(&mut new_iter);
919        }
920        if is_changed {
921            ts_range_array_add(&mut results, position, next_position);
922        }
923        position = next_position;
924        while included_range_difference_index < (*included_range_differences).size {
925            let mut range: *const TSRange = &mut *((*included_range_differences).contents)
926                .offset(included_range_difference_index as isize)
927                as *mut TSRange;
928            if !((*range).end_byte <= position.bytes) {
929                break;
930            }
931            included_range_difference_index = included_range_difference_index.wrapping_add(1);
932        }
933        if !(!iterator_done(&mut old_iter) && !iterator_done(&mut new_iter)) {
934            break;
935        }
936    }
937    let mut old_size: Length = ts_subtree_total_size(*old_tree);
938    let mut new_size: Length = ts_subtree_total_size(*new_tree);
939    if old_size.bytes < new_size.bytes {
940        ts_range_array_add(&mut results, old_size, new_size);
941    } else if new_size.bytes < old_size.bytes {
942        ts_range_array_add(&mut results, new_size, old_size);
943    }
944    *cursor1 = old_iter.cursor;
945    *cursor2 = new_iter.cursor;
946    *ranges = results.contents;
947    return results.size;
948}