tree_sitter_c2rust_core/
node.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}
52type C2RustUnnamed_3 = crate::util::ScannerStateWithLookahead;
53type C2RustUnnamed_4 = crate::util::LongShortData;
54type C2RustUnnamed_5 = crate::util::ScannerStateLookaheadMeta;
55type C2RustUnnamed_6 = crate::util::ScannerStateLookaheadFirstLeaf;
56#[derive(Copy, Clone)]
57#[repr(C)]
58pub struct TSNode {
59    pub context: [u32; 4],
60    pub id: *const os::raw::c_void,
61    pub tree: *const TSTree,
62}
63#[derive(Copy, Clone)]
64#[repr(C)]
65pub struct NodeChildIterator {
66    pub parent: Subtree,
67    pub tree: *const TSTree,
68    pub position: Length,
69    pub child_index: u32,
70    pub structural_child_index: u32,
71    pub alias_sequence: *const TSSymbol,
72}
73#[inline]
74unsafe extern "C" fn ts_subtree_symbol(mut self_0: Subtree) -> TSSymbol {
75    return (if (self_0.data).is_inline() as os::raw::c_int != 0 {
76        self_0.data.symbol as os::raw::c_int
77    } else {
78        (*self_0.ptr).symbol as os::raw::c_int
79    }) as TSSymbol;
80}
81#[inline]
82unsafe extern "C" fn ts_subtree_size(mut self_0: Subtree) -> Length {
83    if (self_0.data).is_inline() {
84        let mut result: Length = {
85            let mut init = Length {
86                bytes: self_0.data.size_bytes as u32,
87                extent: {
88                    let mut init = TSPoint {
89                        row: 0 as os::raw::c_int as u32,
90                        column: self_0.data.size_bytes as u32,
91                    };
92                    init
93                },
94            };
95            init
96        };
97        return result;
98    } else {
99        return (*self_0.ptr).size;
100    };
101}
102#[inline]
103unsafe extern "C" fn point_add(mut a: TSPoint, mut b: TSPoint) -> TSPoint {
104    if b.row > 0 as os::raw::c_int as os::raw::c_uint {
105        return point__new((a.row).wrapping_add(b.row), b.column);
106    } else {
107        return point__new(a.row, (a.column).wrapping_add(b.column));
108    };
109}
110#[inline]
111unsafe extern "C" fn point__new(mut row: os::raw::c_uint, mut column: os::raw::c_uint) -> TSPoint {
112    let mut result: TSPoint = {
113        let mut init = TSPoint {
114            row: row,
115            column: column,
116        };
117        init
118    };
119    return result;
120}
121#[inline]
122unsafe extern "C" fn ts_subtree_named(mut self_0: Subtree) -> bool {
123    return if (self_0.data).is_inline() as os::raw::c_int != 0 {
124        (self_0.data).named() as os::raw::c_int
125    } else {
126        (*self_0.ptr).named() as os::raw::c_int
127    } != 0;
128}
129#[inline]
130unsafe extern "C" fn ts_subtree_missing(mut self_0: Subtree) -> bool {
131    return if (self_0.data).is_inline() as os::raw::c_int != 0 {
132        (self_0.data).is_missing() as os::raw::c_int
133    } else {
134        (*self_0.ptr).is_missing() as os::raw::c_int
135    } != 0;
136}
137#[inline]
138unsafe extern "C" fn ts_subtree_extra(mut self_0: Subtree) -> bool {
139    return if (self_0.data).is_inline() as os::raw::c_int != 0 {
140        (self_0.data).extra() as os::raw::c_int
141    } else {
142        (*self_0.ptr).extra() as os::raw::c_int
143    } != 0;
144}
145#[inline]
146unsafe extern "C" fn ts_subtree_has_changes(mut self_0: Subtree) -> bool {
147    return if (self_0.data).is_inline() as os::raw::c_int != 0 {
148        (self_0.data).has_changes() as os::raw::c_int
149    } else {
150        (*self_0.ptr).has_changes() as os::raw::c_int
151    } != 0;
152}
153#[inline]
154unsafe extern "C" fn ts_subtree_error_cost(mut self_0: Subtree) -> u32 {
155    if ts_subtree_missing(self_0) {
156        return (110 as os::raw::c_int + 500 as os::raw::c_int) as u32;
157    } else {
158        return if (self_0.data).is_inline() as os::raw::c_int != 0 {
159            0 as os::raw::c_int as os::raw::c_uint
160        } else {
161            (*self_0.ptr).error_cost
162        };
163    };
164}
165#[inline]
166unsafe extern "C" fn ts_subtree_visible(mut self_0: Subtree) -> bool {
167    return if (self_0.data).is_inline() as os::raw::c_int != 0 {
168        (self_0.data).visible() as os::raw::c_int
169    } else {
170        (*self_0.ptr).visible() as os::raw::c_int
171    } != 0;
172}
173#[inline]
174unsafe extern "C" fn length_zero() -> Length {
175    let mut result: Length = {
176        let mut init = Length {
177            bytes: 0 as os::raw::c_int as u32,
178            extent: {
179                let mut init = TSPoint {
180                    row: 0 as os::raw::c_int as u32,
181                    column: 0 as os::raw::c_int as u32,
182                };
183                init
184            },
185        };
186        init
187    };
188    return result;
189}
190#[inline]
191unsafe extern "C" fn ts_subtree_child_count(mut self_0: Subtree) -> u32 {
192    return (if (self_0.data).is_inline() as os::raw::c_int != 0 {
193        0 as os::raw::c_int
194    } else {
195        (*self_0.ptr).child_count as os::raw::c_int
196    }) as u32;
197}
198#[inline]
199unsafe extern "C" fn length_add(mut len1: Length, mut len2: Length) -> Length {
200    let mut result: Length = Length {
201        bytes: 0,
202        extent: TSPoint { row: 0, column: 0 },
203    };
204    result.bytes = (len1.bytes).wrapping_add(len2.bytes);
205    result.extent = point_add(len1.extent, len2.extent);
206    return result;
207}
208#[inline]
209unsafe extern "C" fn ts_subtree_padding(mut self_0: Subtree) -> Length {
210    if (self_0.data).is_inline() {
211        let mut result: Length = {
212            let mut init = Length {
213                bytes: self_0.data.padding_bytes as u32,
214                extent: {
215                    let mut init = TSPoint {
216                        row: (self_0.data).padding_rows() as u32,
217                        column: self_0.data.padding_columns as u32,
218                    };
219                    init
220                },
221            };
222            init
223        };
224        return result;
225    } else {
226        return (*self_0.ptr).padding;
227    };
228}
229#[inline]
230unsafe extern "C" fn ts_subtree_total_bytes(mut self_0: Subtree) -> u32 {
231    return (ts_subtree_total_size(self_0)).bytes;
232}
233#[inline]
234unsafe extern "C" fn ts_subtree_total_size(mut self_0: Subtree) -> Length {
235    return length_add(ts_subtree_padding(self_0), ts_subtree_size(self_0));
236}
237#[inline]
238unsafe extern "C" fn point_lt(mut a: TSPoint, mut b: TSPoint) -> bool {
239    return a.row < b.row || a.row == b.row && a.column < b.column;
240}
241#[inline]
242unsafe extern "C" fn point_lte(mut a: TSPoint, mut b: TSPoint) -> bool {
243    return a.row < b.row || a.row == b.row && a.column <= b.column;
244}
245#[inline]
246unsafe extern "C" fn point_sub(mut a: TSPoint, mut b: TSPoint) -> TSPoint {
247    if a.row > b.row {
248        return point__new((a.row).wrapping_sub(b.row), a.column);
249    } else {
250        return point__new(
251            0 as os::raw::c_int as os::raw::c_uint,
252            (a.column).wrapping_sub(b.column),
253        );
254    };
255}
256#[inline]
257unsafe extern "C" fn ts_language_alias_sequence(
258    mut self_0: *const TSLanguage,
259    mut production_id: u32,
260) -> *const TSSymbol {
261    return if production_id != 0 {
262        &*((*self_0).alias_sequences).offset(
263            production_id.wrapping_mul((*self_0).max_alias_sequence_length as os::raw::c_uint)
264                as isize,
265        ) as *const TSSymbol
266    } else {
267        0 as *const TSSymbol
268    };
269}
270#[inline]
271unsafe extern "C" fn ts_language_field_map(
272    mut self_0: *const TSLanguage,
273    mut production_id: u32,
274    mut start: *mut *const TSFieldMapEntry,
275    mut end: *mut *const TSFieldMapEntry,
276) {
277    if (*self_0).field_count == 0 as os::raw::c_int as os::raw::c_uint {
278        *start = 0 as *const TSFieldMapEntry;
279        *end = 0 as *const TSFieldMapEntry;
280        return;
281    }
282    let mut slice: TSFieldMapSlice = *((*self_0).field_map_slices).offset(production_id as isize);
283    *start = &*((*self_0).field_map_entries).offset(slice.index as isize) as *const TSFieldMapEntry;
284    *end = (&*((*self_0).field_map_entries).offset(slice.index as isize) as *const TSFieldMapEntry)
285        .offset(slice.length as os::raw::c_int as isize);
286}
287#[no_mangle]
288pub unsafe extern "C" fn ts_node_new(
289    mut tree: *const TSTree,
290    mut subtree: *const Subtree,
291    mut position: Length,
292    mut alias: TSSymbol,
293) -> TSNode {
294    return {
295        let mut init = TSNode {
296            context: [
297                position.bytes,
298                position.extent.row,
299                position.extent.column,
300                alias as u32,
301            ],
302            id: subtree as *const os::raw::c_void,
303            tree: tree,
304        };
305        init
306    };
307}
308#[inline]
309unsafe extern "C" fn ts_node__null() -> TSNode {
310    return ts_node_new(
311        0 as *const TSTree,
312        0 as *const Subtree,
313        length_zero(),
314        0 as os::raw::c_int as TSSymbol,
315    );
316}
317#[no_mangle]
318pub unsafe extern "C" fn ts_node_start_byte(mut self_0: TSNode) -> u32 {
319    return self_0.context[0 as os::raw::c_int as usize];
320}
321#[no_mangle]
322pub unsafe extern "C" fn ts_node_start_point(mut self_0: TSNode) -> TSPoint {
323    return {
324        let mut init = TSPoint {
325            row: self_0.context[1 as os::raw::c_int as usize],
326            column: self_0.context[2 as os::raw::c_int as usize],
327        };
328        init
329    };
330}
331#[inline]
332unsafe extern "C" fn ts_node__alias(mut self_0: *const TSNode) -> u32 {
333    return (*self_0).context[3 as os::raw::c_int as usize];
334}
335#[inline]
336unsafe extern "C" fn ts_node__subtree(mut self_0: TSNode) -> Subtree {
337    return *(self_0.id as *const Subtree);
338}
339#[inline]
340unsafe extern "C" fn ts_node_iterate_children(mut node: *const TSNode) -> NodeChildIterator {
341    let mut subtree: Subtree = ts_node__subtree(*node);
342    if ts_subtree_child_count(subtree) == 0 as os::raw::c_int as os::raw::c_uint {
343        return {
344            let mut init = NodeChildIterator {
345                parent: Subtree {
346                    ptr: 0 as *const SubtreeHeapData,
347                },
348                tree: (*node).tree,
349                position: length_zero(),
350                child_index: 0 as os::raw::c_int as u32,
351                structural_child_index: 0 as os::raw::c_int as u32,
352                alias_sequence: 0 as *const TSSymbol,
353            };
354            init
355        };
356    }
357    let mut alias_sequence: *const TSSymbol = ts_language_alias_sequence(
358        (*(*node).tree).language,
359        (*subtree.ptr).c2rust_unnamed.c2rust_unnamed.production_id as u32,
360    );
361    return {
362        let mut init = NodeChildIterator {
363            parent: subtree,
364            tree: (*node).tree,
365            position: {
366                let mut init = Length {
367                    bytes: ts_node_start_byte(*node),
368                    extent: ts_node_start_point(*node),
369                };
370                init
371            },
372            child_index: 0 as os::raw::c_int as u32,
373            structural_child_index: 0 as os::raw::c_int as u32,
374            alias_sequence: alias_sequence,
375        };
376        init
377    };
378}
379#[inline]
380unsafe extern "C" fn ts_node_child_iterator_done(mut self_0: *mut NodeChildIterator) -> bool {
381    return (*self_0).child_index == (*(*self_0).parent.ptr).child_count as os::raw::c_uint;
382}
383#[inline]
384unsafe extern "C" fn ts_node_child_iterator_next(
385    mut self_0: *mut NodeChildIterator,
386    mut result: *mut TSNode,
387) -> bool {
388    if ((*self_0).parent.ptr).is_null()
389        || ts_node_child_iterator_done(self_0) as os::raw::c_int != 0
390    {
391        return false;
392    }
393    let mut child: *const Subtree =
394        &mut *if ((*self_0).parent.data).is_inline() as os::raw::c_int != 0 {
395            0 as *mut Subtree
396        } else {
397            ((*self_0).parent.ptr as *mut Subtree)
398                .offset(-((*(*self_0).parent.ptr).child_count as os::raw::c_int as isize))
399        }
400        .offset((*self_0).child_index as isize) as *mut Subtree;
401    let mut alias_symbol: TSSymbol = 0 as os::raw::c_int as TSSymbol;
402    if !ts_subtree_extra(*child) {
403        if !((*self_0).alias_sequence).is_null() {
404            alias_symbol =
405                *((*self_0).alias_sequence).offset((*self_0).structural_child_index as isize);
406        }
407        let ref mut fresh0 = (*self_0).structural_child_index;
408        *fresh0 = (*fresh0).wrapping_add(1);
409    }
410    if (*self_0).child_index > 0 as os::raw::c_int as os::raw::c_uint {
411        (*self_0).position = length_add((*self_0).position, ts_subtree_padding(*child));
412    }
413    *result = ts_node_new((*self_0).tree, child, (*self_0).position, alias_symbol);
414    (*self_0).position = length_add((*self_0).position, ts_subtree_size(*child));
415    let ref mut fresh1 = (*self_0).child_index;
416    *fresh1 = (*fresh1).wrapping_add(1);
417    return true;
418}
419#[inline]
420unsafe extern "C" fn ts_node__is_relevant(mut self_0: TSNode, mut include_anonymous: bool) -> bool {
421    let mut tree: Subtree = ts_node__subtree(self_0);
422    if include_anonymous {
423        return ts_subtree_visible(tree) as os::raw::c_int != 0 || ts_node__alias(&mut self_0) != 0;
424    } else {
425        let mut alias: TSSymbol = ts_node__alias(&mut self_0) as TSSymbol;
426        if alias != 0 {
427            return (ts_language_symbol_metadata((*self_0.tree).language, alias)).named;
428        } else {
429            return ts_subtree_visible(tree) as os::raw::c_int != 0
430                && ts_subtree_named(tree) as os::raw::c_int != 0;
431        }
432    };
433}
434#[inline]
435unsafe extern "C" fn ts_node__relevant_child_count(
436    mut self_0: TSNode,
437    mut include_anonymous: bool,
438) -> u32 {
439    let mut tree: Subtree = ts_node__subtree(self_0);
440    if ts_subtree_child_count(tree) > 0 as os::raw::c_int as os::raw::c_uint {
441        if include_anonymous {
442            return (*tree.ptr)
443                .c2rust_unnamed
444                .c2rust_unnamed
445                .visible_child_count;
446        } else {
447            return (*tree.ptr).c2rust_unnamed.c2rust_unnamed.named_child_count;
448        }
449    } else {
450        return 0 as os::raw::c_int as u32;
451    };
452}
453#[inline]
454unsafe extern "C" fn ts_node__child(
455    mut self_0: TSNode,
456    mut child_index: u32,
457    mut include_anonymous: bool,
458) -> TSNode {
459    let mut result: TSNode = self_0;
460    let mut did_descend: bool = true;
461    while did_descend {
462        did_descend = false;
463        let mut child: TSNode = TSNode {
464            context: [0; 4],
465            id: 0 as *const os::raw::c_void,
466            tree: 0 as *const TSTree,
467        };
468        let mut index: u32 = 0 as os::raw::c_int as u32;
469        let mut iterator: NodeChildIterator = ts_node_iterate_children(&mut result);
470        while ts_node_child_iterator_next(&mut iterator, &mut child) {
471            if ts_node__is_relevant(child, include_anonymous) {
472                if index == child_index {
473                    return child;
474                }
475                index = index.wrapping_add(1);
476            } else {
477                let mut grandchild_index: u32 = child_index.wrapping_sub(index);
478                let mut grandchild_count: u32 =
479                    ts_node__relevant_child_count(child, include_anonymous);
480                if grandchild_index < grandchild_count {
481                    did_descend = true;
482                    result = child;
483                    child_index = grandchild_index;
484                    break;
485                } else {
486                    index = (index as os::raw::c_uint).wrapping_add(grandchild_count) as u32 as u32;
487                }
488            }
489        }
490    }
491    return ts_node__null();
492}
493unsafe extern "C" fn ts_subtree_has_trailing_empty_descendant(
494    mut self_0: Subtree,
495    mut other: Subtree,
496) -> bool {
497    let mut i: os::raw::c_uint =
498        (ts_subtree_child_count(self_0)).wrapping_sub(1 as os::raw::c_int as os::raw::c_uint);
499    while i.wrapping_add(1 as os::raw::c_int as os::raw::c_uint)
500        > 0 as os::raw::c_int as os::raw::c_uint
501    {
502        let mut child: Subtree = *if (self_0.data).is_inline() as os::raw::c_int != 0 {
503            0 as *mut Subtree
504        } else {
505            (self_0.ptr as *mut Subtree)
506                .offset(-((*self_0.ptr).child_count as os::raw::c_int as isize))
507        }
508        .offset(i as isize);
509        if ts_subtree_total_bytes(child) > 0 as os::raw::c_int as os::raw::c_uint {
510            break;
511        }
512        if child.ptr == other.ptr
513            || ts_subtree_has_trailing_empty_descendant(child, other) as os::raw::c_int != 0
514        {
515            return true;
516        }
517        i = i.wrapping_sub(1);
518    }
519    return false;
520}
521#[inline]
522unsafe extern "C" fn ts_node__prev_sibling(
523    mut self_0: TSNode,
524    mut include_anonymous: bool,
525) -> TSNode {
526    let mut self_subtree: Subtree = ts_node__subtree(self_0);
527    let mut self_is_empty: bool =
528        ts_subtree_total_bytes(self_subtree) == 0 as os::raw::c_int as os::raw::c_uint;
529    let mut target_end_byte: u32 = ts_node_end_byte(self_0);
530    let mut node: TSNode = ts_node_parent(self_0);
531    let mut earlier_node: TSNode = ts_node__null();
532    let mut earlier_node_is_relevant: bool = false;
533    while !ts_node_is_null(node) {
534        let mut earlier_child: TSNode = ts_node__null();
535        let mut earlier_child_is_relevant: bool = false;
536        let mut found_child_containing_target: bool = false;
537        let mut child: TSNode = TSNode {
538            context: [0; 4],
539            id: 0 as *const os::raw::c_void,
540            tree: 0 as *const TSTree,
541        };
542        let mut iterator: NodeChildIterator = ts_node_iterate_children(&mut node);
543        while ts_node_child_iterator_next(&mut iterator, &mut child) {
544            if child.id == self_0.id {
545                break;
546            }
547            if iterator.position.bytes > target_end_byte {
548                found_child_containing_target = true;
549                break;
550            } else if iterator.position.bytes == target_end_byte
551                && (!self_is_empty
552                    || ts_subtree_has_trailing_empty_descendant(
553                        ts_node__subtree(child),
554                        self_subtree,
555                    ) as os::raw::c_int
556                        != 0)
557            {
558                found_child_containing_target = true;
559                break;
560            } else if ts_node__is_relevant(child, include_anonymous) {
561                earlier_child = child;
562                earlier_child_is_relevant = true;
563            } else if ts_node__relevant_child_count(child, include_anonymous)
564                > 0 as os::raw::c_int as os::raw::c_uint
565            {
566                earlier_child = child;
567                earlier_child_is_relevant = false;
568            }
569        }
570        if found_child_containing_target {
571            if !ts_node_is_null(earlier_child) {
572                earlier_node = earlier_child;
573                earlier_node_is_relevant = earlier_child_is_relevant;
574            }
575            node = child;
576        } else if earlier_child_is_relevant {
577            return earlier_child;
578        } else {
579            if !ts_node_is_null(earlier_child) {
580                node = earlier_child;
581            } else if earlier_node_is_relevant {
582                return earlier_node;
583            } else {
584                node = earlier_node;
585            }
586        }
587    }
588    return ts_node__null();
589}
590#[inline]
591unsafe extern "C" fn ts_node__next_sibling(
592    mut self_0: TSNode,
593    mut include_anonymous: bool,
594) -> TSNode {
595    let mut target_end_byte: u32 = ts_node_end_byte(self_0);
596    let mut node: TSNode = ts_node_parent(self_0);
597    let mut later_node: TSNode = ts_node__null();
598    let mut later_node_is_relevant: bool = false;
599    while !ts_node_is_null(node) {
600        let mut later_child: TSNode = ts_node__null();
601        let mut later_child_is_relevant: bool = false;
602        let mut child_containing_target: TSNode = ts_node__null();
603        let mut child: TSNode = TSNode {
604            context: [0; 4],
605            id: 0 as *const os::raw::c_void,
606            tree: 0 as *const TSTree,
607        };
608        let mut iterator: NodeChildIterator = ts_node_iterate_children(&mut node);
609        while ts_node_child_iterator_next(&mut iterator, &mut child) {
610            if iterator.position.bytes < target_end_byte {
611                continue;
612            }
613            if ts_node_start_byte(child) <= ts_node_start_byte(self_0) {
614                if (ts_node__subtree(child)).ptr != (ts_node__subtree(self_0)).ptr {
615                    child_containing_target = child;
616                }
617            } else if ts_node__is_relevant(child, include_anonymous) {
618                later_child = child;
619                later_child_is_relevant = true;
620                break;
621            } else {
622                if !(ts_node__relevant_child_count(child, include_anonymous)
623                    > 0 as os::raw::c_int as os::raw::c_uint)
624                {
625                    continue;
626                }
627                later_child = child;
628                later_child_is_relevant = false;
629                break;
630            }
631        }
632        if !ts_node_is_null(child_containing_target) {
633            if !ts_node_is_null(later_child) {
634                later_node = later_child;
635                later_node_is_relevant = later_child_is_relevant;
636            }
637            node = child_containing_target;
638        } else if later_child_is_relevant {
639            return later_child;
640        } else {
641            if !ts_node_is_null(later_child) {
642                node = later_child;
643            } else if later_node_is_relevant {
644                return later_node;
645            } else {
646                node = later_node;
647            }
648        }
649    }
650    return ts_node__null();
651}
652#[inline]
653unsafe extern "C" fn ts_node__first_child_for_byte(
654    mut self_0: TSNode,
655    mut goal: u32,
656    mut include_anonymous: bool,
657) -> TSNode {
658    let mut node: TSNode = self_0;
659    let mut did_descend: bool = true;
660    while did_descend {
661        did_descend = false;
662        let mut child: TSNode = TSNode {
663            context: [0; 4],
664            id: 0 as *const os::raw::c_void,
665            tree: 0 as *const TSTree,
666        };
667        let mut iterator: NodeChildIterator = ts_node_iterate_children(&mut node);
668        while ts_node_child_iterator_next(&mut iterator, &mut child) {
669            if !(ts_node_end_byte(child) > goal) {
670                continue;
671            }
672            if ts_node__is_relevant(child, include_anonymous) {
673                return child;
674            } else {
675                if !(ts_node_child_count(child) > 0 as os::raw::c_int as os::raw::c_uint) {
676                    continue;
677                }
678                did_descend = true;
679                node = child;
680                break;
681            }
682        }
683    }
684    return ts_node__null();
685}
686#[inline]
687unsafe extern "C" fn ts_node__descendant_for_byte_range(
688    mut self_0: TSNode,
689    mut range_start: u32,
690    mut range_end: u32,
691    mut include_anonymous: bool,
692) -> TSNode {
693    let mut node: TSNode = self_0;
694    let mut last_visible_node: TSNode = self_0;
695    let mut did_descend: bool = true;
696    while did_descend {
697        did_descend = false;
698        let mut child: TSNode = TSNode {
699            context: [0; 4],
700            id: 0 as *const os::raw::c_void,
701            tree: 0 as *const TSTree,
702        };
703        let mut iterator: NodeChildIterator = ts_node_iterate_children(&mut node);
704        while ts_node_child_iterator_next(&mut iterator, &mut child) {
705            let mut node_end: u32 = iterator.position.bytes;
706            if node_end < range_end {
707                continue;
708            }
709            if node_end <= range_start {
710                continue;
711            }
712            if range_start < ts_node_start_byte(child) {
713                break;
714            }
715            node = child;
716            if ts_node__is_relevant(node, include_anonymous) {
717                last_visible_node = node;
718            }
719            did_descend = true;
720            break;
721        }
722    }
723    return last_visible_node;
724}
725#[inline]
726unsafe extern "C" fn ts_node__descendant_for_point_range(
727    mut self_0: TSNode,
728    mut range_start: TSPoint,
729    mut range_end: TSPoint,
730    mut include_anonymous: bool,
731) -> TSNode {
732    let mut node: TSNode = self_0;
733    let mut last_visible_node: TSNode = self_0;
734    let mut did_descend: bool = true;
735    while did_descend {
736        did_descend = false;
737        let mut child: TSNode = TSNode {
738            context: [0; 4],
739            id: 0 as *const os::raw::c_void,
740            tree: 0 as *const TSTree,
741        };
742        let mut iterator: NodeChildIterator = ts_node_iterate_children(&mut node);
743        while ts_node_child_iterator_next(&mut iterator, &mut child) {
744            let mut node_end: TSPoint = iterator.position.extent;
745            if point_lt(node_end, range_end) {
746                continue;
747            }
748            if point_lte(node_end, range_start) {
749                continue;
750            }
751            if point_lt(range_start, ts_node_start_point(child)) {
752                break;
753            }
754            node = child;
755            if ts_node__is_relevant(node, include_anonymous) {
756                last_visible_node = node;
757            }
758            did_descend = true;
759            break;
760        }
761    }
762    return last_visible_node;
763}
764#[no_mangle]
765pub unsafe extern "C" fn ts_node_end_byte(mut self_0: TSNode) -> u32 {
766    return (ts_node_start_byte(self_0))
767        .wrapping_add((ts_subtree_size(ts_node__subtree(self_0))).bytes);
768}
769#[no_mangle]
770pub unsafe extern "C" fn ts_node_end_point(mut self_0: TSNode) -> TSPoint {
771    return point_add(
772        ts_node_start_point(self_0),
773        (ts_subtree_size(ts_node__subtree(self_0))).extent,
774    );
775}
776#[no_mangle]
777pub unsafe extern "C" fn ts_node_symbol(mut self_0: TSNode) -> TSSymbol {
778    let mut symbol: TSSymbol = ts_node__alias(&mut self_0) as TSSymbol;
779    if symbol == 0 {
780        symbol = ts_subtree_symbol(ts_node__subtree(self_0));
781    }
782    return ts_language_public_symbol((*self_0.tree).language, symbol);
783}
784#[no_mangle]
785pub unsafe extern "C" fn ts_node_type(mut self_0: TSNode) -> *const os::raw::c_char {
786    let mut symbol: TSSymbol = ts_node__alias(&mut self_0) as TSSymbol;
787    if symbol == 0 {
788        symbol = ts_subtree_symbol(ts_node__subtree(self_0));
789    }
790    return ts_language_symbol_name((*self_0.tree).language, symbol);
791}
792#[no_mangle]
793pub unsafe extern "C" fn ts_node_string(mut self_0: TSNode) -> *mut os::raw::c_char {
794    return ts_subtree_string(ts_node__subtree(self_0), (*self_0.tree).language, false);
795}
796#[no_mangle]
797pub unsafe extern "C" fn ts_node_eq(mut self_0: TSNode, mut other: TSNode) -> bool {
798    return self_0.tree == other.tree && self_0.id == other.id;
799}
800#[no_mangle]
801pub unsafe extern "C" fn ts_node_is_null(mut self_0: TSNode) -> bool {
802    return (self_0.id).is_null();
803}
804#[no_mangle]
805pub unsafe extern "C" fn ts_node_is_extra(mut self_0: TSNode) -> bool {
806    return ts_subtree_extra(ts_node__subtree(self_0));
807}
808#[no_mangle]
809pub unsafe extern "C" fn ts_node_is_named(mut self_0: TSNode) -> bool {
810    let mut alias: TSSymbol = ts_node__alias(&mut self_0) as TSSymbol;
811    return if alias as os::raw::c_int != 0 {
812        (ts_language_symbol_metadata((*self_0.tree).language, alias)).named as os::raw::c_int
813    } else {
814        ts_subtree_named(ts_node__subtree(self_0)) as os::raw::c_int
815    } != 0;
816}
817#[no_mangle]
818pub unsafe extern "C" fn ts_node_is_missing(mut self_0: TSNode) -> bool {
819    return ts_subtree_missing(ts_node__subtree(self_0));
820}
821#[no_mangle]
822pub unsafe extern "C" fn ts_node_has_changes(mut self_0: TSNode) -> bool {
823    return ts_subtree_has_changes(ts_node__subtree(self_0));
824}
825#[no_mangle]
826pub unsafe extern "C" fn ts_node_has_error(mut self_0: TSNode) -> bool {
827    return ts_subtree_error_cost(ts_node__subtree(self_0))
828        > 0 as os::raw::c_int as os::raw::c_uint;
829}
830#[no_mangle]
831pub unsafe extern "C" fn ts_node_parent(mut self_0: TSNode) -> TSNode {
832    let mut node: TSNode = ts_tree_root_node(self_0.tree);
833    let mut end_byte: u32 = ts_node_end_byte(self_0);
834    if node.id == self_0.id {
835        return ts_node__null();
836    }
837    let mut last_visible_node: TSNode = node;
838    let mut did_descend: bool = true;
839    while did_descend {
840        did_descend = false;
841        let mut child: TSNode = TSNode {
842            context: [0; 4],
843            id: 0 as *const os::raw::c_void,
844            tree: 0 as *const TSTree,
845        };
846        let mut iterator: NodeChildIterator = ts_node_iterate_children(&mut node);
847        while ts_node_child_iterator_next(&mut iterator, &mut child) {
848            if ts_node_start_byte(child) > ts_node_start_byte(self_0) || child.id == self_0.id {
849                break;
850            }
851            if !(iterator.position.bytes >= end_byte) {
852                continue;
853            }
854            node = child;
855            if ts_node__is_relevant(child, true) {
856                last_visible_node = node;
857            }
858            did_descend = true;
859            break;
860        }
861    }
862    return last_visible_node;
863}
864#[no_mangle]
865pub unsafe extern "C" fn ts_node_child(mut self_0: TSNode, mut child_index: u32) -> TSNode {
866    return ts_node__child(self_0, child_index, true);
867}
868#[no_mangle]
869pub unsafe extern "C" fn ts_node_named_child(mut self_0: TSNode, mut child_index: u32) -> TSNode {
870    return ts_node__child(self_0, child_index, false);
871}
872#[no_mangle]
873pub unsafe extern "C" fn ts_node_child_by_field_id(
874    mut self_0: TSNode,
875    mut field_id: TSFieldId,
876) -> TSNode {
877    let mut field_map: *const TSFieldMapEntry = 0 as *const TSFieldMapEntry;
878    let mut field_map_end: *const TSFieldMapEntry = 0 as *const TSFieldMapEntry;
879    let mut child: TSNode = TSNode {
880        context: [0; 4],
881        id: 0 as *const os::raw::c_void,
882        tree: 0 as *const TSTree,
883    };
884    let mut iterator: NodeChildIterator = NodeChildIterator {
885        parent: Subtree {
886            data: SubtreeInlineData {
887                is_inline_visible_named_extra_has_changes_is_missing_is_keyword: [0; 1],
888                symbol: 0,
889                parse_state: 0,
890                padding_columns: 0,
891                padding_rows_lookahead_bytes: [0; 1],
892                padding_bytes: 0,
893                size_bytes: 0,
894            },
895        },
896        tree: 0 as *const TSTree,
897        position: Length {
898            bytes: 0,
899            extent: TSPoint { row: 0, column: 0 },
900        },
901        child_index: 0,
902        structural_child_index: 0,
903        alias_sequence: 0 as *const TSSymbol,
904    };
905    'c_3795: loop {
906        if field_id == 0 || ts_node_child_count(self_0) == 0 as os::raw::c_int as os::raw::c_uint {
907            return ts_node__null();
908        }
909        field_map = 0 as *const TSFieldMapEntry;
910        field_map_end = 0 as *const TSFieldMapEntry;
911        ts_language_field_map(
912            (*self_0.tree).language,
913            (*(ts_node__subtree(self_0)).ptr)
914                .c2rust_unnamed
915                .c2rust_unnamed
916                .production_id as u32,
917            &mut field_map,
918            &mut field_map_end,
919        );
920        if field_map == field_map_end {
921            return ts_node__null();
922        }
923        while ((*field_map).field_id as os::raw::c_int) < field_id as os::raw::c_int {
924            field_map = field_map.offset(1);
925            if field_map == field_map_end {
926                return ts_node__null();
927            }
928        }
929        while (*field_map_end.offset(-(1 as os::raw::c_int) as isize)).field_id as os::raw::c_int
930            > field_id as os::raw::c_int
931        {
932            field_map_end = field_map_end.offset(-1);
933            if field_map == field_map_end {
934                return ts_node__null();
935            }
936        }
937        child = TSNode {
938            context: [0; 4],
939            id: 0 as *const os::raw::c_void,
940            tree: 0 as *const TSTree,
941        };
942        iterator = ts_node_iterate_children(&mut self_0);
943        loop {
944            if !ts_node_child_iterator_next(&mut iterator, &mut child) {
945                break 'c_3795;
946            }
947            if ts_subtree_extra(ts_node__subtree(child)) {
948                continue;
949            }
950            let mut index: u32 = (iterator.structural_child_index)
951                .wrapping_sub(1 as os::raw::c_int as os::raw::c_uint);
952            if index < (*field_map).child_index as os::raw::c_uint {
953                continue;
954            }
955            if (*field_map).inherited {
956                if field_map.offset(1 as os::raw::c_int as isize) == field_map_end {
957                    self_0 = child;
958                    break;
959                } else {
960                    let mut result: TSNode = ts_node_child_by_field_id(child, field_id);
961                    if !(result.id).is_null() {
962                        return result;
963                    }
964                    field_map = field_map.offset(1);
965                    if field_map == field_map_end {
966                        return ts_node__null();
967                    }
968                }
969            } else if ts_node__is_relevant(child, true) {
970                return child;
971            } else {
972                if ts_node_child_count(child) > 0 as os::raw::c_int as os::raw::c_uint {
973                    return ts_node_child(child, 0 as os::raw::c_int as u32);
974                } else {
975                    field_map = field_map.offset(1);
976                    if field_map == field_map_end {
977                        return ts_node__null();
978                    }
979                }
980            }
981        }
982    }
983    return ts_node__null();
984}
985#[no_mangle]
986pub unsafe extern "C" fn ts_node_field_name_for_child(
987    mut self_0: TSNode,
988    mut child_index: u32,
989) -> *const os::raw::c_char {
990    let mut field_map_start: *const TSFieldMapEntry = 0 as *const TSFieldMapEntry;
991    let mut field_map_end: *const TSFieldMapEntry = 0 as *const TSFieldMapEntry;
992    if ts_node_child_count(self_0) == 0 {
993        return 0 as *const os::raw::c_char;
994    }
995    ts_language_field_map(
996        (*self_0.tree).language,
997        (*(ts_node__subtree(self_0)).ptr)
998            .c2rust_unnamed
999            .c2rust_unnamed
1000            .production_id as u32,
1001        &mut field_map_start,
1002        &mut field_map_end,
1003    );
1004    let mut i: *const TSFieldMapEntry = field_map_start;
1005    while i < field_map_end {
1006        if (*i).child_index as os::raw::c_uint == child_index {
1007            return *((*(*self_0.tree).language).field_names).offset((*i).field_id as isize);
1008        }
1009        i = i.offset(1);
1010    }
1011    return 0 as *const os::raw::c_char;
1012}
1013#[no_mangle]
1014pub unsafe extern "C" fn ts_node_child_by_field_name(
1015    mut self_0: TSNode,
1016    mut name: *const os::raw::c_char,
1017    mut name_length: u32,
1018) -> TSNode {
1019    let mut field_id: TSFieldId =
1020        ts_language_field_id_for_name((*self_0.tree).language, name, name_length);
1021    return ts_node_child_by_field_id(self_0, field_id);
1022}
1023#[no_mangle]
1024pub unsafe extern "C" fn ts_node_child_count(mut self_0: TSNode) -> u32 {
1025    let mut tree: Subtree = ts_node__subtree(self_0);
1026    if ts_subtree_child_count(tree) > 0 as os::raw::c_int as os::raw::c_uint {
1027        return (*tree.ptr)
1028            .c2rust_unnamed
1029            .c2rust_unnamed
1030            .visible_child_count;
1031    } else {
1032        return 0 as os::raw::c_int as u32;
1033    };
1034}
1035#[no_mangle]
1036pub unsafe extern "C" fn ts_node_named_child_count(mut self_0: TSNode) -> u32 {
1037    let mut tree: Subtree = ts_node__subtree(self_0);
1038    if ts_subtree_child_count(tree) > 0 as os::raw::c_int as os::raw::c_uint {
1039        return (*tree.ptr).c2rust_unnamed.c2rust_unnamed.named_child_count;
1040    } else {
1041        return 0 as os::raw::c_int as u32;
1042    };
1043}
1044#[no_mangle]
1045pub unsafe extern "C" fn ts_node_next_sibling(mut self_0: TSNode) -> TSNode {
1046    return ts_node__next_sibling(self_0, true);
1047}
1048#[no_mangle]
1049pub unsafe extern "C" fn ts_node_next_named_sibling(mut self_0: TSNode) -> TSNode {
1050    return ts_node__next_sibling(self_0, false);
1051}
1052#[no_mangle]
1053pub unsafe extern "C" fn ts_node_prev_sibling(mut self_0: TSNode) -> TSNode {
1054    return ts_node__prev_sibling(self_0, true);
1055}
1056#[no_mangle]
1057pub unsafe extern "C" fn ts_node_prev_named_sibling(mut self_0: TSNode) -> TSNode {
1058    return ts_node__prev_sibling(self_0, false);
1059}
1060#[no_mangle]
1061pub unsafe extern "C" fn ts_node_first_child_for_byte(mut self_0: TSNode, mut byte: u32) -> TSNode {
1062    return ts_node__first_child_for_byte(self_0, byte, true);
1063}
1064#[no_mangle]
1065pub unsafe extern "C" fn ts_node_first_named_child_for_byte(
1066    mut self_0: TSNode,
1067    mut byte: u32,
1068) -> TSNode {
1069    return ts_node__first_child_for_byte(self_0, byte, false);
1070}
1071#[no_mangle]
1072pub unsafe extern "C" fn ts_node_descendant_for_byte_range(
1073    mut self_0: TSNode,
1074    mut start: u32,
1075    mut end: u32,
1076) -> TSNode {
1077    return ts_node__descendant_for_byte_range(self_0, start, end, true);
1078}
1079#[no_mangle]
1080pub unsafe extern "C" fn ts_node_named_descendant_for_byte_range(
1081    mut self_0: TSNode,
1082    mut start: u32,
1083    mut end: u32,
1084) -> TSNode {
1085    return ts_node__descendant_for_byte_range(self_0, start, end, false);
1086}
1087#[no_mangle]
1088pub unsafe extern "C" fn ts_node_descendant_for_point_range(
1089    mut self_0: TSNode,
1090    mut start: TSPoint,
1091    mut end: TSPoint,
1092) -> TSNode {
1093    return ts_node__descendant_for_point_range(self_0, start, end, true);
1094}
1095#[no_mangle]
1096pub unsafe extern "C" fn ts_node_named_descendant_for_point_range(
1097    mut self_0: TSNode,
1098    mut start: TSPoint,
1099    mut end: TSPoint,
1100) -> TSNode {
1101    return ts_node__descendant_for_point_range(self_0, start, end, false);
1102}
1103#[no_mangle]
1104pub unsafe extern "C" fn ts_node_edit(mut self_0: *mut TSNode, mut edit: *const TSInputEdit) {
1105    let mut start_byte: u32 = ts_node_start_byte(*self_0);
1106    let mut start_point: TSPoint = ts_node_start_point(*self_0);
1107    if start_byte >= (*edit).old_end_byte {
1108        start_byte =
1109            ((*edit).new_end_byte).wrapping_add(start_byte.wrapping_sub((*edit).old_end_byte));
1110        start_point = point_add(
1111            (*edit).new_end_point,
1112            point_sub(start_point, (*edit).old_end_point),
1113        );
1114    } else if start_byte > (*edit).start_byte {
1115        start_byte = (*edit).new_end_byte;
1116        start_point = (*edit).new_end_point;
1117    }
1118    (*self_0).context[0 as os::raw::c_int as usize] = start_byte;
1119    (*self_0).context[1 as os::raw::c_int as usize] = start_point.row;
1120    (*self_0).context[2 as os::raw::c_int as usize] = start_point.column;
1121}