tree_sitter_c2rust/core_wrapper/core/
stack.rs

1use crate::core_transpiled::util::*;
2use crate::core_transpiled::*;
3use :: c2rust_bitfields;
4use std::os;
5pub type __uint8_t = libc::c_uchar;
6pub type __int16_t = libc::c_short;
7pub type __uint16_t = libc::c_ushort;
8pub type __int32_t = libc::c_int;
9pub type __uint32_t = libc::c_uint;
10pub type __off_t = libc::c_long;
11pub type __off64_t = libc::c_long;
12pub type _IO_lock_t = ();
13use crate::core_transpiled::util::libc::{dup, fclose, fdopen, fputc, fputs, FILE};
14pub type int16_t = __int16_t;
15pub type int32_t = __int32_t;
16pub type uint8_t = __uint8_t;
17pub type uint16_t = __uint16_t;
18pub type uint32_t = __uint32_t;
19pub type TSStateId = uint16_t;
20pub type TSFieldId = uint16_t;
21#[derive(Copy, Clone)]
22#[repr(C)]
23pub struct C2RustUnnamed {
24    pub states: *const bool,
25    pub symbol_map: *const TSSymbol,
26    pub create: Option<unsafe extern "C" fn() -> *mut libc::c_void>,
27    pub destroy: Option<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
28    pub scan: Option<unsafe extern "C" fn(*mut libc::c_void, *mut TSLexer, *const bool) -> bool>,
29    pub serialize:
30        Option<unsafe extern "C" fn(*mut libc::c_void, *mut libc::c_char) -> libc::c_uint>,
31    pub deserialize:
32        Option<unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, libc::c_uint) -> ()>,
33}
34#[derive(Copy, Clone)]
35#[repr(C)]
36pub struct C2RustUnnamed_0 {
37    pub count: uint8_t,
38    pub reusable: bool,
39}
40#[derive(Copy, Clone)]
41#[repr(C)]
42pub struct C2RustUnnamed_1 {
43    pub type_: uint8_t,
44    pub child_count: uint8_t,
45    pub symbol: TSSymbol,
46    pub dynamic_precedence: int16_t,
47    pub production_id: uint16_t,
48}
49#[derive(Copy, Clone)]
50#[repr(C)]
51pub struct C2RustUnnamed_2 {
52    pub type_: uint8_t,
53    pub state: TSStateId,
54    pub extra: bool,
55    pub repetition: bool,
56}
57#[derive(Copy, Clone)]
58#[repr(C)]
59pub struct Array {
60    pub contents: *mut libc::c_void,
61    pub size: uint32_t,
62    pub capacity: uint32_t,
63}
64type C2RustUnnamed_3 = crate::core_transpiled::util::LongShortData;
65type C2RustUnnamed_4 = crate::core_transpiled::util::ScannerStateWithLookahead;
66type C2RustUnnamed_5 = crate::core_transpiled::util::ScannerStateLookaheadMeta;
67type C2RustUnnamed_6 = crate::core_transpiled::util::ScannerStateLookaheadFirstLeaf;
68#[derive(Copy, Clone)]
69#[repr(C)]
70pub struct Stack {
71    pub heads: C2RustUnnamed_8,
72    pub slices: StackSliceArray,
73    pub iterators: C2RustUnnamed_7,
74    pub node_pool: StackNodeArray,
75    pub base_node: *mut StackNode,
76    pub subtree_pool: *mut SubtreePool,
77}
78#[derive(Copy, Clone)]
79#[repr(C)]
80pub struct StackNode {
81    pub state: TSStateId,
82    pub position: Length,
83    pub links: [StackLink; 8],
84    pub link_count: libc::c_ushort,
85    pub ref_count: uint32_t,
86    pub error_cost: libc::c_uint,
87    pub node_count: libc::c_uint,
88    pub dynamic_precedence: libc::c_int,
89}
90#[derive(Copy, Clone)]
91#[repr(C)]
92pub struct StackLink {
93    pub node: *mut StackNode,
94    pub subtree: Subtree,
95    pub is_pending: bool,
96}
97#[derive(Copy, Clone)]
98#[repr(C)]
99pub struct StackNodeArray {
100    pub contents: *mut *mut StackNode,
101    pub size: uint32_t,
102    pub capacity: uint32_t,
103}
104type C2RustUnnamed_7 = crate::core_transpiled::util::StackElement<*mut StackIterator>;
105#[derive(Copy, Clone)]
106#[repr(C)]
107pub struct StackIterator {
108    pub node: *mut StackNode,
109    pub subtrees: SubtreeArray,
110    pub subtree_count: uint32_t,
111    pub is_pending: bool,
112}
113#[derive(Copy, Clone)]
114#[repr(C)]
115pub struct StackSliceArray {
116    pub contents: *mut StackSlice,
117    pub size: uint32_t,
118    pub capacity: uint32_t,
119}
120#[derive(Copy, Clone)]
121#[repr(C)]
122pub struct StackSlice {
123    pub subtrees: SubtreeArray,
124    pub version: StackVersion,
125}
126pub type StackVersion = libc::c_uint;
127type C2RustUnnamed_8 = crate::core_transpiled::util::StackElement<*mut StackHead>;
128#[derive(Copy, Clone)]
129#[repr(C)]
130pub struct StackHead {
131    pub node: *mut StackNode,
132    pub summary: *mut StackSummary,
133    pub node_count_at_last_error: libc::c_uint,
134    pub last_external_token: Subtree,
135    pub lookahead_when_paused: Subtree,
136    pub status: StackStatus,
137}
138pub type StackStatus = libc::c_uint;
139pub const StackStatusHalted: StackStatus = 2;
140pub const StackStatusPaused: StackStatus = 1;
141pub const StackStatusActive: StackStatus = 0;
142#[derive(Copy, Clone)]
143#[repr(C)]
144pub struct StackSummary {
145    pub contents: *mut StackSummaryEntry,
146    pub size: uint32_t,
147    pub capacity: uint32_t,
148}
149#[derive(Copy, Clone)]
150#[repr(C)]
151pub struct StackSummaryEntry {
152    pub position: Length,
153    pub depth: libc::c_uint,
154    pub state: TSStateId,
155}
156pub type StackAction = libc::c_uint;
157pub const StackActionNone: C2RustUnnamed_10 = 0;
158pub const StackActionStop: C2RustUnnamed_10 = 1;
159pub const StackActionPop: C2RustUnnamed_10 = 2;
160pub type StackCallback =
161    Option<unsafe extern "C" fn(*mut libc::c_void, *const StackIterator) -> StackAction>;
162#[derive(Copy, Clone)]
163#[repr(C)]
164pub struct SummarizeStackSession {
165    pub summary: *mut StackSummary,
166    pub max_depth: libc::c_uint,
167}
168type C2RustUnnamed_9 = crate::core_transpiled::util::StackElement<*mut *mut StackNode>;
169pub type C2RustUnnamed_10 = libc::c_uint;
170#[inline]
171unsafe extern "C" fn point__new(mut row: libc::c_uint, mut column: libc::c_uint) -> TSPoint {
172    let mut result: TSPoint = {
173        let mut init = TSPoint {
174            row: row,
175            column: column,
176        };
177        init
178    };
179    return result;
180}
181#[inline]
182unsafe extern "C" fn point_add(mut a: TSPoint, mut b: TSPoint) -> TSPoint {
183    if b.row > 0 as libc::c_int as libc::c_uint {
184        return point__new((a.row).wrapping_add(b.row), b.column);
185    } else {
186        return point__new(a.row, (a.column).wrapping_add(b.column));
187    };
188}
189#[inline]
190unsafe extern "C" fn length_add(mut len1: Length, mut len2: Length) -> Length {
191    let mut result: Length = Length {
192        bytes: 0,
193        extent: TSPoint { row: 0, column: 0 },
194    };
195    result.bytes = (len1.bytes).wrapping_add(len2.bytes);
196    result.extent = point_add(len1.extent, len2.extent);
197    return result;
198}
199#[inline]
200unsafe extern "C" fn length_zero() -> Length {
201    let mut result: Length = {
202        let mut init = Length {
203            bytes: 0 as libc::c_int as uint32_t,
204            extent: {
205                let mut init = TSPoint {
206                    row: 0 as libc::c_int as uint32_t,
207                    column: 0 as libc::c_int as uint32_t,
208                };
209                init
210            },
211        };
212        init
213    };
214    return result;
215}
216#[inline]
217unsafe extern "C" fn _array__delete(mut self_0: *mut Array) {
218    if !((*self_0).contents).is_null() {
219        crate::core_transpiled::alloc::ts_free((*self_0).contents);
220        (*self_0).contents = 0 as *mut libc::c_void;
221        (*self_0).size = 0 as libc::c_int as uint32_t;
222        (*self_0).capacity = 0 as libc::c_int as uint32_t;
223    }
224}
225#[inline]
226unsafe extern "C" fn _array__erase(
227    mut self_0: *mut Array,
228    mut element_size: size_t,
229    mut index: uint32_t,
230) {
231    if index < (*self_0).size {
232    } else {
233        panic!();
234    }
235    let mut contents: *mut libc::c_char = (*self_0).contents as *mut libc::c_char;
236    std::ptr::copy(
237        contents.offset(
238            (index.wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong)
239                .wrapping_mul(element_size) as isize,
240        ) as *const libc::c_void,
241        contents.offset((index as libc::c_ulong).wrapping_mul(element_size) as isize)
242            as *mut libc::c_void,
243        ((((*self_0).size)
244            .wrapping_sub(index)
245            .wrapping_sub(1 as libc::c_int as libc::c_uint) as libc::c_ulong)
246            .wrapping_mul(element_size)) as usize,
247    );
248    (*self_0).size = ((*self_0).size).wrapping_sub(1);
249}
250#[inline]
251unsafe extern "C" fn _array__reserve(
252    mut self_0: *mut Array,
253    mut element_size: size_t,
254    mut new_capacity: uint32_t,
255) {
256    if new_capacity > (*self_0).capacity {
257        if !((*self_0).contents).is_null() {
258            (*self_0).contents = crate::core_transpiled::alloc::ts_realloc(
259                (*self_0).contents,
260                (new_capacity as libc::c_ulong).wrapping_mul(element_size),
261            );
262        } else {
263            (*self_0).contents = crate::core_transpiled::alloc::ts_malloc(
264                (new_capacity as libc::c_ulong).wrapping_mul(element_size),
265            );
266        }
267        (*self_0).capacity = new_capacity;
268    }
269}
270#[inline]
271unsafe extern "C" fn _array__grow(
272    mut self_0: *mut Array,
273    mut count: uint32_t,
274    mut element_size: size_t,
275) {
276    let mut new_size: uint32_t = ((*self_0).size).wrapping_add(count);
277    if new_size > (*self_0).capacity {
278        let mut new_capacity: uint32_t =
279            ((*self_0).capacity).wrapping_mul(2 as libc::c_int as libc::c_uint);
280        if new_capacity < 8 as libc::c_int as libc::c_uint {
281            new_capacity = 8 as libc::c_int as uint32_t;
282        }
283        if new_capacity < new_size {
284            new_capacity = new_size;
285        }
286        _array__reserve(self_0, element_size, new_capacity);
287    }
288}
289#[inline]
290unsafe extern "C" fn _array__splice(
291    mut self_0: *mut Array,
292    mut element_size: size_t,
293    mut index: uint32_t,
294    mut old_count: uint32_t,
295    mut new_count: uint32_t,
296    mut elements: *const libc::c_void,
297) {
298    let mut new_size: uint32_t = ((*self_0).size)
299        .wrapping_add(new_count)
300        .wrapping_sub(old_count);
301    let mut old_end: uint32_t = index.wrapping_add(old_count);
302    let mut new_end: uint32_t = index.wrapping_add(new_count);
303    if old_end <= (*self_0).size {
304    } else {
305        panic!();
306    }
307    _array__reserve(self_0, element_size, new_size);
308    let mut contents: *mut libc::c_char = (*self_0).contents as *mut libc::c_char;
309    if (*self_0).size > old_end {
310        std::ptr::copy(
311            contents.offset((old_end as libc::c_ulong).wrapping_mul(element_size) as isize)
312                as *const libc::c_void,
313            contents.offset((new_end as libc::c_ulong).wrapping_mul(element_size) as isize)
314                as *mut libc::c_void,
315            ((((*self_0).size).wrapping_sub(old_end) as libc::c_ulong).wrapping_mul(element_size))
316                as usize,
317        );
318    }
319    if new_count > 0 as libc::c_int as libc::c_uint {
320        if !elements.is_null() {
321            std::ptr::copy_nonoverlapping(
322                elements,
323                contents.offset((index as libc::c_ulong).wrapping_mul(element_size) as isize)
324                    as *mut libc::c_void,
325                (new_count as libc::c_ulong).wrapping_mul(element_size),
326            );
327        } else {
328            std::ptr::write_bytes(
329                contents.offset((index as libc::c_ulong).wrapping_mul(element_size) as isize)
330                    as *mut libc::c_void,
331                (0 as libc::c_int) as u8,
332                ((new_count as libc::c_ulong).wrapping_mul(element_size)) as usize,
333            );
334        }
335    }
336    (*self_0).size = ((*self_0).size as libc::c_uint)
337        .wrapping_add(new_count.wrapping_sub(old_count)) as uint32_t
338        as uint32_t;
339}
340#[inline]
341unsafe extern "C" fn ts_subtree_symbol(mut self_0: Subtree) -> TSSymbol {
342    return (if (self_0.data).is_inline() as libc::c_int != 0 {
343        self_0.data.symbol as libc::c_int
344    } else {
345        (*self_0.ptr).symbol as libc::c_int
346    }) as TSSymbol;
347}
348#[inline]
349unsafe extern "C" fn ts_subtree_visible(mut self_0: Subtree) -> bool {
350    return if (self_0.data).is_inline() as libc::c_int != 0 {
351        (self_0.data).visible() as libc::c_int
352    } else {
353        (*self_0.ptr).visible() as libc::c_int
354    } != 0;
355}
356#[inline]
357unsafe extern "C" fn ts_subtree_named(mut self_0: Subtree) -> bool {
358    return if (self_0.data).is_inline() as libc::c_int != 0 {
359        (self_0.data).named() as libc::c_int
360    } else {
361        (*self_0.ptr).named() as libc::c_int
362    } != 0;
363}
364#[inline]
365unsafe extern "C" fn ts_subtree_extra(mut self_0: Subtree) -> bool {
366    return if (self_0.data).is_inline() as libc::c_int != 0 {
367        (self_0.data).extra() as libc::c_int
368    } else {
369        (*self_0.ptr).extra() as libc::c_int
370    } != 0;
371}
372#[inline]
373unsafe extern "C" fn ts_subtree_missing(mut self_0: Subtree) -> bool {
374    return if (self_0.data).is_inline() as libc::c_int != 0 {
375        (self_0.data).is_missing() as libc::c_int
376    } else {
377        (*self_0.ptr).is_missing() as libc::c_int
378    } != 0;
379}
380#[inline]
381unsafe extern "C" fn ts_subtree_alloc_size(mut child_count: uint32_t) -> size_t {
382    return (child_count as libc::c_ulong)
383        .wrapping_mul(::core::mem::size_of::<Subtree>() as libc::c_ulong)
384        .wrapping_add(::core::mem::size_of::<SubtreeHeapData>() as libc::c_ulong);
385}
386#[inline]
387unsafe extern "C" fn ts_subtree_padding(mut self_0: Subtree) -> Length {
388    if (self_0.data).is_inline() {
389        let mut result: Length = {
390            let mut init = Length {
391                bytes: self_0.data.padding_bytes as uint32_t,
392                extent: {
393                    let mut init = TSPoint {
394                        row: (self_0.data).padding_rows() as uint32_t,
395                        column: self_0.data.padding_columns as uint32_t,
396                    };
397                    init
398                },
399            };
400            init
401        };
402        return result;
403    } else {
404        return (*self_0.ptr).padding;
405    };
406}
407#[inline]
408unsafe extern "C" fn ts_subtree_size(mut self_0: Subtree) -> Length {
409    if (self_0.data).is_inline() {
410        let mut result: Length = {
411            let mut init = Length {
412                bytes: self_0.data.size_bytes as uint32_t,
413                extent: {
414                    let mut init = TSPoint {
415                        row: 0 as libc::c_int as uint32_t,
416                        column: self_0.data.size_bytes as uint32_t,
417                    };
418                    init
419                },
420            };
421            init
422        };
423        return result;
424    } else {
425        return (*self_0.ptr).size;
426    };
427}
428#[inline]
429unsafe extern "C" fn ts_subtree_total_size(mut self_0: Subtree) -> Length {
430    return length_add(ts_subtree_padding(self_0), ts_subtree_size(self_0));
431}
432#[inline]
433unsafe extern "C" fn ts_subtree_total_bytes(mut self_0: Subtree) -> uint32_t {
434    return (ts_subtree_total_size(self_0)).bytes;
435}
436#[inline]
437unsafe extern "C" fn ts_subtree_child_count(mut self_0: Subtree) -> uint32_t {
438    return if (self_0.data).is_inline() as libc::c_int != 0 {
439        0 as libc::c_int as libc::c_uint
440    } else {
441        (*self_0.ptr).child_count
442    };
443}
444#[inline]
445unsafe extern "C" fn ts_subtree_visible_descendant_count(mut self_0: Subtree) -> uint32_t {
446    return if (self_0.data).is_inline() as libc::c_int != 0
447        || (*self_0.ptr).child_count == 0 as libc::c_int as libc::c_uint
448    {
449        0 as libc::c_int as libc::c_uint
450    } else {
451        (*self_0.ptr)
452            .c2rust_unnamed
453            .c2rust_unnamed
454            .visible_descendant_count
455    };
456}
457#[inline]
458unsafe extern "C" fn ts_subtree_error_cost(mut self_0: Subtree) -> uint32_t {
459    if ts_subtree_missing(self_0) {
460        return (110 as libc::c_int + 500 as libc::c_int) as uint32_t;
461    } else {
462        return if (self_0.data).is_inline() as libc::c_int != 0 {
463            0 as libc::c_int as libc::c_uint
464        } else {
465            (*self_0.ptr).error_cost
466        };
467    };
468}
469#[inline]
470unsafe extern "C" fn ts_subtree_dynamic_precedence(mut self_0: Subtree) -> int32_t {
471    return if (self_0.data).is_inline() as libc::c_int != 0
472        || (*self_0.ptr).child_count == 0 as libc::c_int as libc::c_uint
473    {
474        0 as libc::c_int
475    } else {
476        (*self_0.ptr)
477            .c2rust_unnamed
478            .c2rust_unnamed
479            .dynamic_precedence
480    };
481}
482#[inline]
483unsafe extern "C" fn ts_subtree_is_error(mut self_0: Subtree) -> bool {
484    return ts_subtree_symbol(self_0) as libc::c_int
485        == -(1 as libc::c_int) as TSSymbol as libc::c_int;
486}
487#[inline]
488unsafe extern "C" fn ts_language_write_symbol_as_dot_string(
489    mut self_0: *const TSLanguage,
490    mut f: *mut FILE,
491    mut symbol: TSSymbol,
492) {
493    let mut name: *const libc::c_char = ts_language_symbol_name(self_0, symbol);
494    let mut chr: *const libc::c_char = name;
495    while *chr != 0 {
496        match *chr as libc::c_int {
497            34 | 92 => {
498                fputc('\\' as i32, f);
499                fputc(*chr as libc::c_int, f);
500            }
501            10 => {
502                fputs(b"\\n\0" as *const u8 as *const libc::c_char, f);
503            }
504            9 => {
505                fputs(b"\\t\0" as *const u8 as *const libc::c_char, f);
506            }
507            _ => {
508                fputc(*chr as libc::c_int, f);
509            }
510        }
511        chr = chr.offset(1);
512    }
513}
514unsafe extern "C" fn stack_node_retain(mut self_0: *mut StackNode) {
515    if self_0.is_null() {
516        return;
517    }
518    if (*self_0).ref_count > 0 as libc::c_int as libc::c_uint {
519    } else {
520        panic!();
521    }
522    (*self_0).ref_count = ((*self_0).ref_count).wrapping_add(1);
523    if (*self_0).ref_count != 0 as libc::c_int as libc::c_uint {
524    } else {
525        panic!();
526    };
527}
528unsafe extern "C" fn stack_node_release(
529    mut self_0: *mut StackNode,
530    mut pool: *mut StackNodeArray,
531    mut subtree_pool: *mut SubtreePool,
532) {
533    loop {
534        if (*self_0).ref_count != 0 as libc::c_int as libc::c_uint {
535        } else {
536            panic!();
537        }
538        (*self_0).ref_count = ((*self_0).ref_count).wrapping_sub(1);
539        if (*self_0).ref_count > 0 as libc::c_int as libc::c_uint {
540            return;
541        }
542        let mut first_predecessor: *mut StackNode = 0 as *mut StackNode;
543        if (*self_0).link_count as libc::c_int > 0 as libc::c_int {
544            let mut i: libc::c_uint =
545                ((*self_0).link_count as libc::c_int - 1 as libc::c_int) as libc::c_uint;
546            while i > 0 as libc::c_int as libc::c_uint {
547                let mut link: StackLink = (*self_0).links[i as usize];
548                if !(link.subtree.ptr).is_null() {
549                    ts_subtree_release(subtree_pool, link.subtree);
550                }
551                stack_node_release(link.node, pool, subtree_pool);
552                i = i.wrapping_sub(1);
553            }
554            let mut link_0: StackLink = (*self_0).links[0 as libc::c_int as usize];
555            if !(link_0.subtree.ptr).is_null() {
556                ts_subtree_release(subtree_pool, link_0.subtree);
557            }
558            first_predecessor = (*self_0).links[0 as libc::c_int as usize].node;
559        }
560        if (*pool).size < 50 as libc::c_int as libc::c_uint {
561            _array__grow(
562                pool as *mut Array,
563                1 as libc::c_int as uint32_t,
564                ::core::mem::size_of::<*mut StackNode>() as libc::c_ulong,
565            );
566            let fresh0 = (*pool).size;
567            (*pool).size = ((*pool).size).wrapping_add(1);
568            let ref mut fresh1 = *((*pool).contents).offset(fresh0 as isize);
569            *fresh1 = self_0;
570        } else {
571            crate::core_transpiled::alloc::ts_free(self_0 as *mut libc::c_void);
572        }
573        if first_predecessor.is_null() {
574            break;
575        }
576        self_0 = first_predecessor;
577    }
578}
579unsafe extern "C" fn stack__subtree_node_count(mut subtree: Subtree) -> uint32_t {
580    let mut count: uint32_t = ts_subtree_visible_descendant_count(subtree);
581    if ts_subtree_visible(subtree) {
582        count = count.wrapping_add(1);
583    }
584    if ts_subtree_symbol(subtree) as libc::c_int
585        == -(1 as libc::c_int) as TSSymbol as libc::c_int - 1 as libc::c_int
586    {
587        count = count.wrapping_add(1);
588    }
589    return count;
590}
591unsafe extern "C" fn stack_node_new(
592    mut previous_node: *mut StackNode,
593    mut subtree: Subtree,
594    mut is_pending: bool,
595    mut state: TSStateId,
596    mut pool: *mut StackNodeArray,
597) -> *mut StackNode {
598    let mut node: *mut StackNode = (if (*pool).size > 0 as libc::c_int as libc::c_uint {
599        (*pool).size = ((*pool).size).wrapping_sub(1);
600        *((*pool).contents).offset((*pool).size as isize) as *mut libc::c_void
601    } else {
602        crate::core_transpiled::alloc::ts_malloc(
603            ::core::mem::size_of::<StackNode>() as libc::c_ulong
604        )
605    }) as *mut StackNode;
606    *node = {
607        let mut init = StackNode {
608            state: state,
609            position: Length {
610                bytes: 0,
611                extent: TSPoint { row: 0, column: 0 },
612            },
613            links: [StackLink {
614                node: 0 as *mut StackNode,
615                subtree: Subtree {
616                    data: SubtreeInlineData {
617                        is_inline_visible_named_extra_has_changes_is_missing_is_keyword: [0; 1],
618                        symbol: 0,
619                        parse_state: 0,
620                        padding_columns: 0,
621                        padding_rows_lookahead_bytes: [0; 1],
622                        padding_bytes: 0,
623                        size_bytes: 0,
624                    },
625                },
626                is_pending: false,
627            }; 8],
628            link_count: 0 as libc::c_int as libc::c_ushort,
629            ref_count: 1 as libc::c_int as uint32_t,
630            error_cost: 0,
631            node_count: 0,
632            dynamic_precedence: 0,
633        };
634        init
635    };
636    if !previous_node.is_null() {
637        (*node).link_count = 1 as libc::c_int as libc::c_ushort;
638        (*node).links[0 as libc::c_int as usize] = {
639            let mut init = StackLink {
640                node: previous_node,
641                subtree: subtree,
642                is_pending: is_pending,
643            };
644            init
645        };
646        (*node).position = (*previous_node).position;
647        (*node).error_cost = (*previous_node).error_cost;
648        (*node).dynamic_precedence = (*previous_node).dynamic_precedence;
649        (*node).node_count = (*previous_node).node_count;
650        if !(subtree.ptr).is_null() {
651            (*node).error_cost = ((*node).error_cost).wrapping_add(ts_subtree_error_cost(subtree));
652            (*node).position = length_add((*node).position, ts_subtree_total_size(subtree));
653            (*node).node_count =
654                ((*node).node_count).wrapping_add(stack__subtree_node_count(subtree));
655            (*node).dynamic_precedence += ts_subtree_dynamic_precedence(subtree);
656        }
657    } else {
658        (*node).position = length_zero();
659        (*node).error_cost = 0 as libc::c_int as libc::c_uint;
660    }
661    return node;
662}
663unsafe extern "C" fn stack__subtree_is_equivalent(mut left: Subtree, mut right: Subtree) -> bool {
664    if left.ptr == right.ptr {
665        return 1 as libc::c_int != 0;
666    }
667    if (left.ptr).is_null() || (right.ptr).is_null() {
668        return 0 as libc::c_int != 0;
669    }
670    if ts_subtree_symbol(left) as libc::c_int != ts_subtree_symbol(right) as libc::c_int {
671        return 0 as libc::c_int != 0;
672    }
673    if ts_subtree_error_cost(left) > 0 as libc::c_int as libc::c_uint
674        && ts_subtree_error_cost(right) > 0 as libc::c_int as libc::c_uint
675    {
676        return 1 as libc::c_int != 0;
677    }
678    return (ts_subtree_padding(left)).bytes == (ts_subtree_padding(right)).bytes
679        && (ts_subtree_size(left)).bytes == (ts_subtree_size(right)).bytes
680        && ts_subtree_child_count(left) == ts_subtree_child_count(right)
681        && ts_subtree_extra(left) as libc::c_int == ts_subtree_extra(right) as libc::c_int
682        && ts_subtree_external_scanner_state_eq(left, right) as libc::c_int != 0;
683}
684unsafe extern "C" fn stack_node_add_link(
685    mut self_0: *mut StackNode,
686    mut link: StackLink,
687    mut subtree_pool: *mut SubtreePool,
688) {
689    if link.node == self_0 {
690        return;
691    }
692    let mut i: libc::c_int = 0 as libc::c_int;
693    while i < (*self_0).link_count as libc::c_int {
694        let mut existing_link: *mut StackLink =
695            &mut *((*self_0).links).as_mut_ptr().offset(i as isize) as *mut StackLink;
696        if stack__subtree_is_equivalent((*existing_link).subtree, link.subtree) {
697            if (*existing_link).node == link.node {
698                if ts_subtree_dynamic_precedence(link.subtree)
699                    > ts_subtree_dynamic_precedence((*existing_link).subtree)
700                {
701                    ts_subtree_retain(link.subtree);
702                    ts_subtree_release(subtree_pool, (*existing_link).subtree);
703                    (*existing_link).subtree = link.subtree;
704                    (*self_0).dynamic_precedence = (*link.node).dynamic_precedence
705                        + ts_subtree_dynamic_precedence(link.subtree);
706                }
707                return;
708            }
709            if (*(*existing_link).node).state as libc::c_int == (*link.node).state as libc::c_int
710                && (*(*existing_link).node).position.bytes == (*link.node).position.bytes
711                && (*(*existing_link).node).error_cost == (*link.node).error_cost
712            {
713                let mut j: libc::c_int = 0 as libc::c_int;
714                while j < (*link.node).link_count as libc::c_int {
715                    stack_node_add_link(
716                        (*existing_link).node,
717                        (*link.node).links[j as usize],
718                        subtree_pool,
719                    );
720                    j += 1;
721                }
722                let mut dynamic_precedence: int32_t = (*link.node).dynamic_precedence;
723                if !(link.subtree.ptr).is_null() {
724                    dynamic_precedence += ts_subtree_dynamic_precedence(link.subtree);
725                }
726                if dynamic_precedence > (*self_0).dynamic_precedence {
727                    (*self_0).dynamic_precedence = dynamic_precedence;
728                }
729                return;
730            }
731        }
732        i += 1;
733    }
734    if (*self_0).link_count as libc::c_int == 8 as libc::c_int {
735        return;
736    }
737    stack_node_retain(link.node);
738    let mut node_count: libc::c_uint = (*link.node).node_count;
739    let mut dynamic_precedence_0: libc::c_int = (*link.node).dynamic_precedence;
740    let fresh2 = (*self_0).link_count;
741    (*self_0).link_count = ((*self_0).link_count).wrapping_add(1);
742    (*self_0).links[fresh2 as usize] = link;
743    if !(link.subtree.ptr).is_null() {
744        ts_subtree_retain(link.subtree);
745        node_count = node_count.wrapping_add(stack__subtree_node_count(link.subtree));
746        dynamic_precedence_0 += ts_subtree_dynamic_precedence(link.subtree);
747    }
748    if node_count > (*self_0).node_count {
749        (*self_0).node_count = node_count;
750    }
751    if dynamic_precedence_0 > (*self_0).dynamic_precedence {
752        (*self_0).dynamic_precedence = dynamic_precedence_0;
753    }
754}
755unsafe extern "C" fn stack_head_delete(
756    mut self_0: *mut StackHead,
757    mut pool: *mut StackNodeArray,
758    mut subtree_pool: *mut SubtreePool,
759) {
760    if !((*self_0).node).is_null() {
761        if !((*self_0).last_external_token.ptr).is_null() {
762            ts_subtree_release(subtree_pool, (*self_0).last_external_token);
763        }
764        if !((*self_0).lookahead_when_paused.ptr).is_null() {
765            ts_subtree_release(subtree_pool, (*self_0).lookahead_when_paused);
766        }
767        if !((*self_0).summary).is_null() {
768            _array__delete((*self_0).summary as *mut Array);
769            crate::core_transpiled::alloc::ts_free((*self_0).summary as *mut libc::c_void);
770        }
771        stack_node_release((*self_0).node, pool, subtree_pool);
772    }
773}
774unsafe extern "C" fn ts_stack__add_version(
775    mut self_0: *mut Stack,
776    mut original_version: StackVersion,
777    mut node: *mut StackNode,
778) -> StackVersion {
779    let mut head: StackHead = {
780        let mut init = StackHead {
781            node: node,
782            summary: 0 as *mut StackSummary,
783            node_count_at_last_error: (*((*self_0).heads.contents)
784                .offset(original_version as isize))
785            .node_count_at_last_error,
786            last_external_token: (*((*self_0).heads.contents).offset(original_version as isize))
787                .last_external_token,
788            lookahead_when_paused: Subtree {
789                ptr: 0 as *const SubtreeHeapData,
790            },
791            status: StackStatusActive,
792        };
793        init
794    };
795    _array__grow(
796        &mut (*self_0).heads as *mut C2RustUnnamed_8 as *mut Array,
797        1 as libc::c_int as uint32_t,
798        ::core::mem::size_of::<StackHead>() as libc::c_ulong,
799    );
800    let fresh3 = (*self_0).heads.size;
801    (*self_0).heads.size = ((*self_0).heads.size).wrapping_add(1);
802    *((*self_0).heads.contents).offset(fresh3 as isize) = head;
803    stack_node_retain(node);
804    if !(head.last_external_token.ptr).is_null() {
805        ts_subtree_retain(head.last_external_token);
806    }
807    return ((*self_0).heads.size).wrapping_sub(1 as libc::c_int as libc::c_uint);
808}
809unsafe extern "C" fn ts_stack__add_slice(
810    mut self_0: *mut Stack,
811    mut original_version: StackVersion,
812    mut node: *mut StackNode,
813    mut subtrees: *mut SubtreeArray,
814) {
815    let mut i: uint32_t = ((*self_0).slices.size).wrapping_sub(1 as libc::c_int as libc::c_uint);
816    while i.wrapping_add(1 as libc::c_int as libc::c_uint) > 0 as libc::c_int as libc::c_uint {
817        let mut version: StackVersion = (*((*self_0).slices.contents).offset(i as isize)).version;
818        if (*((*self_0).heads.contents).offset(version as isize)).node == node {
819            let mut slice: StackSlice = {
820                let mut init = StackSlice {
821                    subtrees: *subtrees,
822                    version: version,
823                };
824                init
825            };
826            _array__splice(
827                &mut (*self_0).slices as *mut StackSliceArray as *mut Array,
828                ::core::mem::size_of::<StackSlice>() as libc::c_ulong,
829                i.wrapping_add(1 as libc::c_int as libc::c_uint),
830                0 as libc::c_int as uint32_t,
831                1 as libc::c_int as uint32_t,
832                &mut slice as *mut StackSlice as *const libc::c_void,
833            );
834            return;
835        }
836        i = i.wrapping_sub(1);
837    }
838    let mut version_0: StackVersion = ts_stack__add_version(self_0, original_version, node);
839    let mut slice_0: StackSlice = {
840        let mut init = StackSlice {
841            subtrees: *subtrees,
842            version: version_0,
843        };
844        init
845    };
846    _array__grow(
847        &mut (*self_0).slices as *mut StackSliceArray as *mut Array,
848        1 as libc::c_int as uint32_t,
849        ::core::mem::size_of::<StackSlice>() as libc::c_ulong,
850    );
851    let fresh4 = (*self_0).slices.size;
852    (*self_0).slices.size = ((*self_0).slices.size).wrapping_add(1);
853    *((*self_0).slices.contents).offset(fresh4 as isize) = slice_0;
854}
855unsafe extern "C" fn stack__iter(
856    mut self_0: *mut Stack,
857    mut version: StackVersion,
858    mut callback: StackCallback,
859    mut payload: *mut libc::c_void,
860    mut goal_subtree_count: libc::c_int,
861) -> StackSliceArray {
862    (*self_0).slices.size = 0 as libc::c_int as uint32_t;
863    (*self_0).iterators.size = 0 as libc::c_int as uint32_t;
864    if version < (*self_0).heads.size {
865    } else {
866        panic!();
867    }
868    let mut head: *mut StackHead =
869        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
870    let mut new_iterator: StackIterator = {
871        let mut init = StackIterator {
872            node: (*head).node,
873            subtrees: {
874                let mut init = SubtreeArray {
875                    contents: 0 as *mut Subtree,
876                    size: 0 as libc::c_int as uint32_t,
877                    capacity: 0 as libc::c_int as uint32_t,
878                };
879                init
880            },
881            subtree_count: 0 as libc::c_int as uint32_t,
882            is_pending: 1 as libc::c_int != 0,
883        };
884        init
885    };
886    let mut include_subtrees: bool = 0 as libc::c_int != 0;
887    if goal_subtree_count >= 0 as libc::c_int {
888        include_subtrees = 1 as libc::c_int != 0;
889        _array__reserve(
890            &mut new_iterator.subtrees as *mut SubtreeArray as *mut Array,
891            ::core::mem::size_of::<Subtree>() as libc::c_ulong,
892            (ts_subtree_alloc_size(goal_subtree_count as uint32_t) as uint32_t as libc::c_ulong)
893                .wrapping_div(::core::mem::size_of::<Subtree>() as libc::c_ulong)
894                as uint32_t,
895        );
896    }
897    _array__grow(
898        &mut (*self_0).iterators as *mut C2RustUnnamed_7 as *mut Array,
899        1 as libc::c_int as uint32_t,
900        ::core::mem::size_of::<StackIterator>() as libc::c_ulong,
901    );
902    let fresh5 = (*self_0).iterators.size;
903    (*self_0).iterators.size = ((*self_0).iterators.size).wrapping_add(1);
904    *((*self_0).iterators.contents).offset(fresh5 as isize) = new_iterator;
905    while (*self_0).iterators.size > 0 as libc::c_int as libc::c_uint {
906        let mut i: uint32_t = 0 as libc::c_int as uint32_t;
907        let mut size: uint32_t = (*self_0).iterators.size;
908        while i < size {
909            let mut iterator: *mut StackIterator =
910                &mut *((*self_0).iterators.contents).offset(i as isize) as *mut StackIterator;
911            let mut node: *mut StackNode = (*iterator).node;
912            let mut action: StackAction =
913                callback.expect("non-null function pointer")(payload, iterator);
914            let mut should_pop: bool = action & StackActionPop as libc::c_int as libc::c_uint != 0;
915            let mut should_stop: bool = action & StackActionStop as libc::c_int as libc::c_uint
916                != 0
917                || (*node).link_count as libc::c_int == 0 as libc::c_int;
918            if should_pop {
919                let mut subtrees: SubtreeArray = (*iterator).subtrees;
920                if !should_stop {
921                    ts_subtree_array_copy(subtrees, &mut subtrees);
922                }
923                ts_subtree_array_reverse(&mut subtrees);
924                ts_stack__add_slice(self_0, version, node, &mut subtrees);
925            }
926            if should_stop {
927                if !should_pop {
928                    ts_subtree_array_delete((*self_0).subtree_pool, &mut (*iterator).subtrees);
929                }
930                _array__erase(
931                    &mut (*self_0).iterators as *mut C2RustUnnamed_7 as *mut Array,
932                    ::core::mem::size_of::<StackIterator>() as libc::c_ulong,
933                    i,
934                );
935                i = i.wrapping_sub(1);
936                size = size.wrapping_sub(1);
937            } else {
938                let mut current_block_41: u64;
939                let mut j: uint32_t = 1 as libc::c_int as uint32_t;
940                while j <= (*node).link_count as libc::c_uint {
941                    let mut next_iterator: *mut StackIterator = 0 as *mut StackIterator;
942                    let mut link: StackLink = StackLink {
943                        node: 0 as *mut StackNode,
944                        subtree: Subtree {
945                            data: SubtreeInlineData {
946                                is_inline_visible_named_extra_has_changes_is_missing_is_keyword: [0;
947                                    1],
948                                symbol: 0,
949                                parse_state: 0,
950                                padding_columns: 0,
951                                padding_rows_lookahead_bytes: [0; 1],
952                                padding_bytes: 0,
953                                size_bytes: 0,
954                            },
955                        },
956                        is_pending: false,
957                    };
958                    if j == (*node).link_count as libc::c_uint {
959                        link = (*node).links[0 as libc::c_int as usize];
960                        next_iterator = &mut *((*self_0).iterators.contents).offset(i as isize)
961                            as *mut StackIterator;
962                        current_block_41 = 11459959175219260272;
963                    } else if (*self_0).iterators.size >= 64 as libc::c_int as libc::c_uint {
964                        current_block_41 = 5783071609795492627;
965                    } else {
966                        link = (*node).links[j as usize];
967                        let mut current_iterator: StackIterator =
968                            *((*self_0).iterators.contents).offset(i as isize);
969                        _array__grow(
970                            &mut (*self_0).iterators as *mut C2RustUnnamed_7 as *mut Array,
971                            1 as libc::c_int as uint32_t,
972                            ::core::mem::size_of::<StackIterator>() as libc::c_ulong,
973                        );
974                        let fresh6 = (*self_0).iterators.size;
975                        (*self_0).iterators.size = ((*self_0).iterators.size).wrapping_add(1);
976                        *((*self_0).iterators.contents).offset(fresh6 as isize) = current_iterator;
977                        if ((*self_0).iterators.size).wrapping_sub(1 as libc::c_int as libc::c_uint)
978                            < (*self_0).iterators.size
979                        {
980                        } else {
981                            panic!();
982                        }
983                        next_iterator = &mut *((*self_0).iterators.contents).offset(
984                            ((*self_0).iterators.size)
985                                .wrapping_sub(1 as libc::c_int as libc::c_uint)
986                                as isize,
987                        ) as *mut StackIterator;
988                        ts_subtree_array_copy(
989                            (*next_iterator).subtrees,
990                            &mut (*next_iterator).subtrees,
991                        );
992                        current_block_41 = 11459959175219260272;
993                    }
994                    match current_block_41 {
995                        11459959175219260272 => {
996                            (*next_iterator).node = link.node;
997                            if !(link.subtree.ptr).is_null() {
998                                if include_subtrees {
999                                    _array__grow(
1000                                        &mut (*next_iterator).subtrees as *mut SubtreeArray
1001                                            as *mut Array,
1002                                        1 as libc::c_int as uint32_t,
1003                                        ::core::mem::size_of::<Subtree>() as libc::c_ulong,
1004                                    );
1005                                    let fresh7 = (*next_iterator).subtrees.size;
1006                                    (*next_iterator).subtrees.size =
1007                                        ((*next_iterator).subtrees.size).wrapping_add(1);
1008                                    *((*next_iterator).subtrees.contents).offset(fresh7 as isize) =
1009                                        link.subtree;
1010                                    ts_subtree_retain(link.subtree);
1011                                }
1012                                if !ts_subtree_extra(link.subtree) {
1013                                    (*next_iterator).subtree_count =
1014                                        ((*next_iterator).subtree_count).wrapping_add(1);
1015                                    if !link.is_pending {
1016                                        (*next_iterator).is_pending = 0 as libc::c_int != 0;
1017                                    }
1018                                }
1019                            } else {
1020                                (*next_iterator).subtree_count =
1021                                    ((*next_iterator).subtree_count).wrapping_add(1);
1022                                (*next_iterator).is_pending = 0 as libc::c_int != 0;
1023                            }
1024                        }
1025                        _ => {}
1026                    }
1027                    j = j.wrapping_add(1);
1028                }
1029            }
1030            i = i.wrapping_add(1);
1031        }
1032    }
1033    return (*self_0).slices;
1034}
1035#[no_mangle]
1036pub unsafe extern "C" fn ts_stack_new(mut subtree_pool: *mut SubtreePool) -> *mut Stack {
1037    let mut self_0: *mut Stack = crate::core_transpiled::alloc::ts_calloc(
1038        1 as libc::c_int as size_t,
1039        ::core::mem::size_of::<Stack>() as libc::c_ulong,
1040    ) as *mut Stack;
1041    (*self_0).heads.size = 0 as libc::c_int as uint32_t;
1042    (*self_0).heads.capacity = 0 as libc::c_int as uint32_t;
1043    (*self_0).heads.contents = 0 as *mut StackHead;
1044    (*self_0).slices.size = 0 as libc::c_int as uint32_t;
1045    (*self_0).slices.capacity = 0 as libc::c_int as uint32_t;
1046    (*self_0).slices.contents = 0 as *mut StackSlice;
1047    (*self_0).iterators.size = 0 as libc::c_int as uint32_t;
1048    (*self_0).iterators.capacity = 0 as libc::c_int as uint32_t;
1049    (*self_0).iterators.contents = 0 as *mut StackIterator;
1050    (*self_0).node_pool.size = 0 as libc::c_int as uint32_t;
1051    (*self_0).node_pool.capacity = 0 as libc::c_int as uint32_t;
1052    (*self_0).node_pool.contents = 0 as *mut *mut StackNode;
1053    _array__reserve(
1054        &mut (*self_0).heads as *mut C2RustUnnamed_8 as *mut Array,
1055        ::core::mem::size_of::<StackHead>() as libc::c_ulong,
1056        4 as libc::c_int as uint32_t,
1057    );
1058    _array__reserve(
1059        &mut (*self_0).slices as *mut StackSliceArray as *mut Array,
1060        ::core::mem::size_of::<StackSlice>() as libc::c_ulong,
1061        4 as libc::c_int as uint32_t,
1062    );
1063    _array__reserve(
1064        &mut (*self_0).iterators as *mut C2RustUnnamed_7 as *mut Array,
1065        ::core::mem::size_of::<StackIterator>() as libc::c_ulong,
1066        4 as libc::c_int as uint32_t,
1067    );
1068    _array__reserve(
1069        &mut (*self_0).node_pool as *mut StackNodeArray as *mut Array,
1070        ::core::mem::size_of::<*mut StackNode>() as libc::c_ulong,
1071        50 as libc::c_int as uint32_t,
1072    );
1073    (*self_0).subtree_pool = subtree_pool;
1074    (*self_0).base_node = stack_node_new(
1075        0 as *mut StackNode,
1076        Subtree {
1077            ptr: 0 as *const SubtreeHeapData,
1078        },
1079        0 as libc::c_int != 0,
1080        1 as libc::c_int as TSStateId,
1081        &mut (*self_0).node_pool,
1082    );
1083    ts_stack_clear(self_0);
1084    return self_0;
1085}
1086#[no_mangle]
1087pub unsafe extern "C" fn ts_stack_delete(mut self_0: *mut Stack) {
1088    if !((*self_0).slices.contents).is_null() {
1089        _array__delete(&mut (*self_0).slices as *mut StackSliceArray as *mut Array);
1090    }
1091    if !((*self_0).iterators.contents).is_null() {
1092        _array__delete(&mut (*self_0).iterators as *mut C2RustUnnamed_7 as *mut Array);
1093    }
1094    stack_node_release(
1095        (*self_0).base_node,
1096        &mut (*self_0).node_pool,
1097        (*self_0).subtree_pool,
1098    );
1099    let mut i: uint32_t = 0 as libc::c_int as uint32_t;
1100    while i < (*self_0).heads.size {
1101        stack_head_delete(
1102            &mut *((*self_0).heads.contents).offset(i as isize),
1103            &mut (*self_0).node_pool,
1104            (*self_0).subtree_pool,
1105        );
1106        i = i.wrapping_add(1);
1107    }
1108    (*self_0).heads.size = 0 as libc::c_int as uint32_t;
1109    if !((*self_0).node_pool.contents).is_null() {
1110        let mut i_0: uint32_t = 0 as libc::c_int as uint32_t;
1111        while i_0 < (*self_0).node_pool.size {
1112            crate::core_transpiled::alloc::ts_free(
1113                *((*self_0).node_pool.contents).offset(i_0 as isize) as *mut libc::c_void,
1114            );
1115            i_0 = i_0.wrapping_add(1);
1116        }
1117        _array__delete(&mut (*self_0).node_pool as *mut StackNodeArray as *mut Array);
1118    }
1119    _array__delete(&mut (*self_0).heads as *mut C2RustUnnamed_8 as *mut Array);
1120    crate::core_transpiled::alloc::ts_free(self_0 as *mut libc::c_void);
1121}
1122#[no_mangle]
1123pub unsafe extern "C" fn ts_stack_version_count(mut self_0: *const Stack) -> uint32_t {
1124    return (*self_0).heads.size;
1125}
1126#[no_mangle]
1127pub unsafe extern "C" fn ts_stack_state(
1128    mut self_0: *const Stack,
1129    mut version: StackVersion,
1130) -> TSStateId {
1131    if version < (*self_0).heads.size {
1132    } else {
1133        panic!();
1134    }
1135    return (*(*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead))
1136        .node)
1137        .state;
1138}
1139#[no_mangle]
1140pub unsafe extern "C" fn ts_stack_position(
1141    mut self_0: *const Stack,
1142    mut version: StackVersion,
1143) -> Length {
1144    if version < (*self_0).heads.size {
1145    } else {
1146        panic!();
1147    }
1148    return (*(*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead))
1149        .node)
1150        .position;
1151}
1152#[no_mangle]
1153pub unsafe extern "C" fn ts_stack_last_external_token(
1154    mut self_0: *const Stack,
1155    mut version: StackVersion,
1156) -> Subtree {
1157    if version < (*self_0).heads.size {
1158    } else {
1159        panic!();
1160    }
1161    return (*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead))
1162        .last_external_token;
1163}
1164#[no_mangle]
1165pub unsafe extern "C" fn ts_stack_set_last_external_token(
1166    mut self_0: *mut Stack,
1167    mut version: StackVersion,
1168    mut token: Subtree,
1169) {
1170    if version < (*self_0).heads.size {
1171    } else {
1172        panic!();
1173    }
1174    let mut head: *mut StackHead =
1175        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
1176    if !(token.ptr).is_null() {
1177        ts_subtree_retain(token);
1178    }
1179    if !((*head).last_external_token.ptr).is_null() {
1180        ts_subtree_release((*self_0).subtree_pool, (*head).last_external_token);
1181    }
1182    (*head).last_external_token = token;
1183}
1184#[no_mangle]
1185pub unsafe extern "C" fn ts_stack_error_cost(
1186    mut self_0: *const Stack,
1187    mut version: StackVersion,
1188) -> libc::c_uint {
1189    if version < (*self_0).heads.size {
1190    } else {
1191        panic!();
1192    }
1193    let mut head: *mut StackHead =
1194        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
1195    let mut result: libc::c_uint = (*(*head).node).error_cost;
1196    if (*head).status as libc::c_uint == StackStatusPaused as libc::c_int as libc::c_uint
1197        || (*(*head).node).state as libc::c_int == 0 as libc::c_int
1198            && ((*(*head).node).links[0 as libc::c_int as usize].subtree.ptr).is_null()
1199    {
1200        result = result.wrapping_add(500 as libc::c_int as libc::c_uint);
1201    }
1202    return result;
1203}
1204#[no_mangle]
1205pub unsafe extern "C" fn ts_stack_node_count_since_error(
1206    mut self_0: *const Stack,
1207    mut version: StackVersion,
1208) -> libc::c_uint {
1209    if version < (*self_0).heads.size {
1210    } else {
1211        panic!();
1212    }
1213    let mut head: *mut StackHead =
1214        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
1215    if (*(*head).node).node_count < (*head).node_count_at_last_error {
1216        (*head).node_count_at_last_error = (*(*head).node).node_count;
1217    }
1218    return ((*(*head).node).node_count).wrapping_sub((*head).node_count_at_last_error);
1219}
1220#[no_mangle]
1221pub unsafe extern "C" fn ts_stack_push(
1222    mut self_0: *mut Stack,
1223    mut version: StackVersion,
1224    mut subtree: Subtree,
1225    mut pending: bool,
1226    mut state: TSStateId,
1227) {
1228    if version < (*self_0).heads.size {
1229    } else {
1230        panic!();
1231    }
1232    let mut head: *mut StackHead =
1233        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
1234    let mut new_node: *mut StackNode = stack_node_new(
1235        (*head).node,
1236        subtree,
1237        pending,
1238        state,
1239        &mut (*self_0).node_pool,
1240    );
1241    if (subtree.ptr).is_null() {
1242        (*head).node_count_at_last_error = (*new_node).node_count;
1243    }
1244    (*head).node = new_node;
1245}
1246#[inline(always)]
1247unsafe extern "C" fn pop_count_callback(
1248    mut payload: *mut libc::c_void,
1249    mut iterator: *const StackIterator,
1250) -> StackAction {
1251    let mut goal_subtree_count: *mut libc::c_uint = payload as *mut libc::c_uint;
1252    if (*iterator).subtree_count == *goal_subtree_count {
1253        return (StackActionPop as libc::c_int | StackActionStop as libc::c_int) as StackAction;
1254    } else {
1255        return StackActionNone as libc::c_int as StackAction;
1256    };
1257}
1258#[no_mangle]
1259pub unsafe extern "C" fn ts_stack_pop_count(
1260    mut self_0: *mut Stack,
1261    mut version: StackVersion,
1262    mut count: uint32_t,
1263) -> StackSliceArray {
1264    return stack__iter(
1265        self_0,
1266        version,
1267        Some(
1268            pop_count_callback
1269                as unsafe extern "C" fn(*mut libc::c_void, *const StackIterator) -> StackAction,
1270        ),
1271        &mut count as *mut uint32_t as *mut libc::c_void,
1272        count as libc::c_int,
1273    );
1274}
1275#[inline(always)]
1276unsafe extern "C" fn pop_pending_callback(
1277    mut payload: *mut libc::c_void,
1278    mut iterator: *const StackIterator,
1279) -> StackAction {
1280    if (*iterator).subtree_count >= 1 as libc::c_int as libc::c_uint {
1281        if (*iterator).is_pending {
1282            return (StackActionPop as libc::c_int | StackActionStop as libc::c_int) as StackAction;
1283        } else {
1284            return StackActionStop as libc::c_int as StackAction;
1285        }
1286    } else {
1287        return StackActionNone as libc::c_int as StackAction;
1288    };
1289}
1290#[no_mangle]
1291pub unsafe extern "C" fn ts_stack_pop_pending(
1292    mut self_0: *mut Stack,
1293    mut version: StackVersion,
1294) -> StackSliceArray {
1295    let mut pop: StackSliceArray = stack__iter(
1296        self_0,
1297        version,
1298        Some(
1299            pop_pending_callback
1300                as unsafe extern "C" fn(*mut libc::c_void, *const StackIterator) -> StackAction,
1301        ),
1302        0 as *mut libc::c_void,
1303        0 as libc::c_int,
1304    );
1305    if pop.size > 0 as libc::c_int as libc::c_uint {
1306        ts_stack_renumber_version(
1307            self_0,
1308            (*(pop.contents).offset(0 as libc::c_int as isize)).version,
1309            version,
1310        );
1311        (*(pop.contents).offset(0 as libc::c_int as isize)).version = version;
1312    }
1313    return pop;
1314}
1315#[inline(always)]
1316unsafe extern "C" fn pop_error_callback(
1317    mut payload: *mut libc::c_void,
1318    mut iterator: *const StackIterator,
1319) -> StackAction {
1320    if (*iterator).subtrees.size > 0 as libc::c_int as libc::c_uint {
1321        let mut found_error: *mut bool = payload as *mut bool;
1322        if !*found_error
1323            && ts_subtree_is_error(
1324                *((*iterator).subtrees.contents).offset(0 as libc::c_int as isize),
1325            ) as libc::c_int
1326                != 0
1327        {
1328            *found_error = 1 as libc::c_int != 0;
1329            return (StackActionPop as libc::c_int | StackActionStop as libc::c_int) as StackAction;
1330        } else {
1331            return StackActionStop as libc::c_int as StackAction;
1332        }
1333    } else {
1334        return StackActionNone as libc::c_int as StackAction;
1335    };
1336}
1337#[no_mangle]
1338pub unsafe extern "C" fn ts_stack_pop_error(
1339    mut self_0: *mut Stack,
1340    mut version: StackVersion,
1341) -> SubtreeArray {
1342    if version < (*self_0).heads.size {
1343    } else {
1344        panic!();
1345    }
1346    let mut node: *mut StackNode =
1347        (*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead)).node;
1348    let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1349    while i < (*node).link_count as libc::c_uint {
1350        if !((*node).links[i as usize].subtree.ptr).is_null()
1351            && ts_subtree_is_error((*node).links[i as usize].subtree) as libc::c_int != 0
1352        {
1353            let mut found_error: bool = 0 as libc::c_int != 0;
1354            let mut pop: StackSliceArray = stack__iter(
1355                self_0,
1356                version,
1357                Some(
1358                    pop_error_callback
1359                        as unsafe extern "C" fn(
1360                            *mut libc::c_void,
1361                            *const StackIterator,
1362                        ) -> StackAction,
1363                ),
1364                &mut found_error as *mut bool as *mut libc::c_void,
1365                1 as libc::c_int,
1366            );
1367            if pop.size > 0 as libc::c_int as libc::c_uint {
1368                if pop.size == 1 as libc::c_int as libc::c_uint {
1369                } else {
1370                    panic!();
1371                }
1372                ts_stack_renumber_version(
1373                    self_0,
1374                    (*(pop.contents).offset(0 as libc::c_int as isize)).version,
1375                    version,
1376                );
1377                return (*(pop.contents).offset(0 as libc::c_int as isize)).subtrees;
1378            }
1379            break;
1380        } else {
1381            i = i.wrapping_add(1);
1382        }
1383    }
1384    return {
1385        let mut init = SubtreeArray {
1386            contents: 0 as *mut Subtree,
1387            size: 0 as libc::c_int as uint32_t,
1388            capacity: 0,
1389        };
1390        init
1391    };
1392}
1393#[inline(always)]
1394unsafe extern "C" fn pop_all_callback(
1395    mut payload: *mut libc::c_void,
1396    mut iterator: *const StackIterator,
1397) -> StackAction {
1398    return (if (*(*iterator).node).link_count as libc::c_int == 0 as libc::c_int {
1399        StackActionPop as libc::c_int
1400    } else {
1401        StackActionNone as libc::c_int
1402    }) as StackAction;
1403}
1404#[no_mangle]
1405pub unsafe extern "C" fn ts_stack_pop_all(
1406    mut self_0: *mut Stack,
1407    mut version: StackVersion,
1408) -> StackSliceArray {
1409    return stack__iter(
1410        self_0,
1411        version,
1412        Some(
1413            pop_all_callback
1414                as unsafe extern "C" fn(*mut libc::c_void, *const StackIterator) -> StackAction,
1415        ),
1416        0 as *mut libc::c_void,
1417        0 as libc::c_int,
1418    );
1419}
1420#[inline(always)]
1421unsafe extern "C" fn summarize_stack_callback(
1422    mut payload: *mut libc::c_void,
1423    mut iterator: *const StackIterator,
1424) -> StackAction {
1425    let mut session: *mut SummarizeStackSession = payload as *mut SummarizeStackSession;
1426    let mut state: TSStateId = (*(*iterator).node).state;
1427    let mut depth: libc::c_uint = (*iterator).subtree_count;
1428    if depth > (*session).max_depth {
1429        return StackActionStop as libc::c_int as StackAction;
1430    }
1431    let mut i: libc::c_uint =
1432        ((*(*session).summary).size).wrapping_sub(1 as libc::c_int as libc::c_uint);
1433    while i.wrapping_add(1 as libc::c_int as libc::c_uint) > 0 as libc::c_int as libc::c_uint {
1434        let mut entry: StackSummaryEntry = *((*(*session).summary).contents).offset(i as isize);
1435        if entry.depth < depth {
1436            break;
1437        }
1438        if entry.depth == depth && entry.state as libc::c_int == state as libc::c_int {
1439            return StackActionNone as libc::c_int as StackAction;
1440        }
1441        i = i.wrapping_sub(1);
1442    }
1443    _array__grow(
1444        (*session).summary as *mut Array,
1445        1 as libc::c_int as uint32_t,
1446        ::core::mem::size_of::<StackSummaryEntry>() as libc::c_ulong,
1447    );
1448    let fresh8 = (*(*session).summary).size;
1449    (*(*session).summary).size = ((*(*session).summary).size).wrapping_add(1);
1450    *((*(*session).summary).contents).offset(fresh8 as isize) = {
1451        let mut init = StackSummaryEntry {
1452            position: (*(*iterator).node).position,
1453            depth: depth,
1454            state: state,
1455        };
1456        init
1457    };
1458    return StackActionNone as libc::c_int as StackAction;
1459}
1460#[no_mangle]
1461pub unsafe extern "C" fn ts_stack_record_summary(
1462    mut self_0: *mut Stack,
1463    mut version: StackVersion,
1464    mut max_depth: libc::c_uint,
1465) {
1466    let mut session: SummarizeStackSession = {
1467        let mut init = SummarizeStackSession {
1468            summary: crate::core_transpiled::alloc::ts_malloc(
1469                ::core::mem::size_of::<StackSummary>() as libc::c_ulong,
1470            ) as *mut StackSummary,
1471            max_depth: max_depth,
1472        };
1473        init
1474    };
1475    (*session.summary).size = 0 as libc::c_int as uint32_t;
1476    (*session.summary).capacity = 0 as libc::c_int as uint32_t;
1477    (*session.summary).contents = 0 as *mut StackSummaryEntry;
1478    stack__iter(
1479        self_0,
1480        version,
1481        Some(
1482            summarize_stack_callback
1483                as unsafe extern "C" fn(*mut libc::c_void, *const StackIterator) -> StackAction,
1484        ),
1485        &mut session as *mut SummarizeStackSession as *mut libc::c_void,
1486        -(1 as libc::c_int),
1487    );
1488    let mut head: *mut StackHead =
1489        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
1490    if !((*head).summary).is_null() {
1491        _array__delete((*head).summary as *mut Array);
1492        crate::core_transpiled::alloc::ts_free((*head).summary as *mut libc::c_void);
1493    }
1494    (*head).summary = session.summary;
1495}
1496#[no_mangle]
1497pub unsafe extern "C" fn ts_stack_get_summary(
1498    mut self_0: *mut Stack,
1499    mut version: StackVersion,
1500) -> *mut StackSummary {
1501    if version < (*self_0).heads.size {
1502    } else {
1503        panic!();
1504    }
1505    return (*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead))
1506        .summary;
1507}
1508#[no_mangle]
1509pub unsafe extern "C" fn ts_stack_dynamic_precedence(
1510    mut self_0: *mut Stack,
1511    mut version: StackVersion,
1512) -> libc::c_int {
1513    if version < (*self_0).heads.size {
1514    } else {
1515        panic!();
1516    }
1517    return (*(*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead))
1518        .node)
1519        .dynamic_precedence;
1520}
1521#[no_mangle]
1522pub unsafe extern "C" fn ts_stack_has_advanced_since_error(
1523    mut self_0: *const Stack,
1524    mut version: StackVersion,
1525) -> bool {
1526    if version < (*self_0).heads.size {
1527    } else {
1528        panic!();
1529    }
1530    let mut head: *const StackHead =
1531        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
1532    let mut node: *const StackNode = (*head).node;
1533    if (*node).error_cost == 0 as libc::c_int as libc::c_uint {
1534        return 1 as libc::c_int != 0;
1535    }
1536    while !node.is_null() {
1537        if !((*node).link_count as libc::c_int > 0 as libc::c_int) {
1538            break;
1539        }
1540        let mut subtree: Subtree = (*node).links[0 as libc::c_int as usize].subtree;
1541        if (subtree.ptr).is_null() {
1542            break;
1543        }
1544        if ts_subtree_total_bytes(subtree) > 0 as libc::c_int as libc::c_uint {
1545            return 1 as libc::c_int != 0;
1546        } else {
1547            if !((*node).node_count > (*head).node_count_at_last_error
1548                && ts_subtree_error_cost(subtree) == 0 as libc::c_int as libc::c_uint)
1549            {
1550                break;
1551            }
1552            node = (*node).links[0 as libc::c_int as usize].node;
1553        }
1554    }
1555    return 0 as libc::c_int != 0;
1556}
1557#[no_mangle]
1558pub unsafe extern "C" fn ts_stack_remove_version(
1559    mut self_0: *mut Stack,
1560    mut version: StackVersion,
1561) {
1562    if version < (*self_0).heads.size {
1563    } else {
1564        panic!();
1565    }
1566    stack_head_delete(
1567        &mut *((*self_0).heads.contents).offset(version as isize),
1568        &mut (*self_0).node_pool,
1569        (*self_0).subtree_pool,
1570    );
1571    _array__erase(
1572        &mut (*self_0).heads as *mut C2RustUnnamed_8 as *mut Array,
1573        ::core::mem::size_of::<StackHead>() as libc::c_ulong,
1574        version,
1575    );
1576}
1577#[no_mangle]
1578pub unsafe extern "C" fn ts_stack_renumber_version(
1579    mut self_0: *mut Stack,
1580    mut v1: StackVersion,
1581    mut v2: StackVersion,
1582) {
1583    if v1 == v2 {
1584        return;
1585    }
1586    if v2 < v1 {
1587    } else {
1588        panic!();
1589    }
1590    if v1 < (*self_0).heads.size {
1591    } else {
1592        panic!();
1593    }
1594    let mut source_head: *mut StackHead =
1595        &mut *((*self_0).heads.contents).offset(v1 as isize) as *mut StackHead;
1596    let mut target_head: *mut StackHead =
1597        &mut *((*self_0).heads.contents).offset(v2 as isize) as *mut StackHead;
1598    if !((*target_head).summary).is_null() && ((*source_head).summary).is_null() {
1599        (*source_head).summary = (*target_head).summary;
1600        (*target_head).summary = 0 as *mut StackSummary;
1601    }
1602    stack_head_delete(
1603        target_head,
1604        &mut (*self_0).node_pool,
1605        (*self_0).subtree_pool,
1606    );
1607    *target_head = *source_head;
1608    _array__erase(
1609        &mut (*self_0).heads as *mut C2RustUnnamed_8 as *mut Array,
1610        ::core::mem::size_of::<StackHead>() as libc::c_ulong,
1611        v1,
1612    );
1613}
1614#[no_mangle]
1615pub unsafe extern "C" fn ts_stack_swap_versions(
1616    mut self_0: *mut Stack,
1617    mut v1: StackVersion,
1618    mut v2: StackVersion,
1619) {
1620    let mut temporary_head: StackHead = *((*self_0).heads.contents).offset(v1 as isize);
1621    *((*self_0).heads.contents).offset(v1 as isize) =
1622        *((*self_0).heads.contents).offset(v2 as isize);
1623    *((*self_0).heads.contents).offset(v2 as isize) = temporary_head;
1624}
1625#[no_mangle]
1626pub unsafe extern "C" fn ts_stack_copy_version(
1627    mut self_0: *mut Stack,
1628    mut version: StackVersion,
1629) -> StackVersion {
1630    if version < (*self_0).heads.size {
1631    } else {
1632        panic!();
1633    }
1634    _array__grow(
1635        &mut (*self_0).heads as *mut C2RustUnnamed_8 as *mut Array,
1636        1 as libc::c_int as uint32_t,
1637        ::core::mem::size_of::<StackHead>() as libc::c_ulong,
1638    );
1639    let fresh9 = (*self_0).heads.size;
1640    (*self_0).heads.size = ((*self_0).heads.size).wrapping_add(1);
1641    *((*self_0).heads.contents).offset(fresh9 as isize) =
1642        *((*self_0).heads.contents).offset(version as isize);
1643    if ((*self_0).heads.size).wrapping_sub(1 as libc::c_int as libc::c_uint) < (*self_0).heads.size
1644    {
1645    } else {
1646        panic!();
1647    }
1648    let mut head: *mut StackHead = &mut *((*self_0).heads.contents)
1649        .offset(((*self_0).heads.size).wrapping_sub(1 as libc::c_int as libc::c_uint) as isize)
1650        as *mut StackHead;
1651    stack_node_retain((*head).node);
1652    if !((*head).last_external_token.ptr).is_null() {
1653        ts_subtree_retain((*head).last_external_token);
1654    }
1655    (*head).summary = 0 as *mut StackSummary;
1656    return ((*self_0).heads.size).wrapping_sub(1 as libc::c_int as libc::c_uint);
1657}
1658#[no_mangle]
1659pub unsafe extern "C" fn ts_stack_merge(
1660    mut self_0: *mut Stack,
1661    mut version1: StackVersion,
1662    mut version2: StackVersion,
1663) -> bool {
1664    if !ts_stack_can_merge(self_0, version1, version2) {
1665        return 0 as libc::c_int != 0;
1666    }
1667    let mut head1: *mut StackHead =
1668        &mut *((*self_0).heads.contents).offset(version1 as isize) as *mut StackHead;
1669    let mut head2: *mut StackHead =
1670        &mut *((*self_0).heads.contents).offset(version2 as isize) as *mut StackHead;
1671    let mut i: uint32_t = 0 as libc::c_int as uint32_t;
1672    while i < (*(*head2).node).link_count as libc::c_uint {
1673        stack_node_add_link(
1674            (*head1).node,
1675            (*(*head2).node).links[i as usize],
1676            (*self_0).subtree_pool,
1677        );
1678        i = i.wrapping_add(1);
1679    }
1680    if (*(*head1).node).state as libc::c_int == 0 as libc::c_int {
1681        (*head1).node_count_at_last_error = (*(*head1).node).node_count;
1682    }
1683    ts_stack_remove_version(self_0, version2);
1684    return 1 as libc::c_int != 0;
1685}
1686#[no_mangle]
1687pub unsafe extern "C" fn ts_stack_can_merge(
1688    mut self_0: *mut Stack,
1689    mut version1: StackVersion,
1690    mut version2: StackVersion,
1691) -> bool {
1692    let mut head1: *mut StackHead =
1693        &mut *((*self_0).heads.contents).offset(version1 as isize) as *mut StackHead;
1694    let mut head2: *mut StackHead =
1695        &mut *((*self_0).heads.contents).offset(version2 as isize) as *mut StackHead;
1696    return (*head1).status as libc::c_uint == StackStatusActive as libc::c_int as libc::c_uint
1697        && (*head2).status as libc::c_uint == StackStatusActive as libc::c_int as libc::c_uint
1698        && (*(*head1).node).state as libc::c_int == (*(*head2).node).state as libc::c_int
1699        && (*(*head1).node).position.bytes == (*(*head2).node).position.bytes
1700        && (*(*head1).node).error_cost == (*(*head2).node).error_cost
1701        && ts_subtree_external_scanner_state_eq(
1702            (*head1).last_external_token,
1703            (*head2).last_external_token,
1704        ) as libc::c_int
1705            != 0;
1706}
1707#[no_mangle]
1708pub unsafe extern "C" fn ts_stack_halt(mut self_0: *mut Stack, mut version: StackVersion) {
1709    if version < (*self_0).heads.size {
1710    } else {
1711        panic!();
1712    }
1713    (*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead)).status =
1714        StackStatusHalted;
1715}
1716#[no_mangle]
1717pub unsafe extern "C" fn ts_stack_pause(
1718    mut self_0: *mut Stack,
1719    mut version: StackVersion,
1720    mut lookahead: Subtree,
1721) {
1722    if version < (*self_0).heads.size {
1723    } else {
1724        panic!();
1725    }
1726    let mut head: *mut StackHead =
1727        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
1728    (*head).status = StackStatusPaused;
1729    (*head).lookahead_when_paused = lookahead;
1730    (*head).node_count_at_last_error = (*(*head).node).node_count;
1731}
1732#[no_mangle]
1733pub unsafe extern "C" fn ts_stack_is_active(
1734    mut self_0: *const Stack,
1735    mut version: StackVersion,
1736) -> bool {
1737    if version < (*self_0).heads.size {
1738    } else {
1739        panic!();
1740    }
1741    return (*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead)).status
1742        as libc::c_uint
1743        == StackStatusActive as libc::c_int as libc::c_uint;
1744}
1745#[no_mangle]
1746pub unsafe extern "C" fn ts_stack_is_halted(
1747    mut self_0: *const Stack,
1748    mut version: StackVersion,
1749) -> bool {
1750    if version < (*self_0).heads.size {
1751    } else {
1752        panic!();
1753    }
1754    return (*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead)).status
1755        as libc::c_uint
1756        == StackStatusHalted as libc::c_int as libc::c_uint;
1757}
1758#[no_mangle]
1759pub unsafe extern "C" fn ts_stack_is_paused(
1760    mut self_0: *const Stack,
1761    mut version: StackVersion,
1762) -> bool {
1763    if version < (*self_0).heads.size {
1764    } else {
1765        panic!();
1766    }
1767    return (*(&mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead)).status
1768        as libc::c_uint
1769        == StackStatusPaused as libc::c_int as libc::c_uint;
1770}
1771#[no_mangle]
1772pub unsafe extern "C" fn ts_stack_resume(
1773    mut self_0: *mut Stack,
1774    mut version: StackVersion,
1775) -> Subtree {
1776    if version < (*self_0).heads.size {
1777    } else {
1778        panic!();
1779    }
1780    let mut head: *mut StackHead =
1781        &mut *((*self_0).heads.contents).offset(version as isize) as *mut StackHead;
1782    if (*head).status as libc::c_uint == StackStatusPaused as libc::c_int as libc::c_uint {
1783    } else {
1784        panic!();
1785    }
1786    let mut result: Subtree = (*head).lookahead_when_paused;
1787    (*head).status = StackStatusActive;
1788    (*head).lookahead_when_paused = Subtree {
1789        ptr: 0 as *const SubtreeHeapData,
1790    };
1791    return result;
1792}
1793#[no_mangle]
1794pub unsafe extern "C" fn ts_stack_clear(mut self_0: *mut Stack) {
1795    stack_node_retain((*self_0).base_node);
1796    let mut i: uint32_t = 0 as libc::c_int as uint32_t;
1797    while i < (*self_0).heads.size {
1798        stack_head_delete(
1799            &mut *((*self_0).heads.contents).offset(i as isize),
1800            &mut (*self_0).node_pool,
1801            (*self_0).subtree_pool,
1802        );
1803        i = i.wrapping_add(1);
1804    }
1805    (*self_0).heads.size = 0 as libc::c_int as uint32_t;
1806    _array__grow(
1807        &mut (*self_0).heads as *mut C2RustUnnamed_8 as *mut Array,
1808        1 as libc::c_int as uint32_t,
1809        ::core::mem::size_of::<StackHead>() as libc::c_ulong,
1810    );
1811    let fresh10 = (*self_0).heads.size;
1812    (*self_0).heads.size = ((*self_0).heads.size).wrapping_add(1);
1813    *((*self_0).heads.contents).offset(fresh10 as isize) = {
1814        let mut init = StackHead {
1815            node: (*self_0).base_node,
1816            summary: 0 as *mut StackSummary,
1817            node_count_at_last_error: 0,
1818            last_external_token: Subtree {
1819                ptr: 0 as *const SubtreeHeapData,
1820            },
1821            lookahead_when_paused: Subtree {
1822                ptr: 0 as *const SubtreeHeapData,
1823            },
1824            status: StackStatusActive,
1825        };
1826        init
1827    };
1828}
1829#[no_mangle]
1830pub unsafe extern "C" fn ts_stack_print_dot_graph(
1831    mut self_0: *mut Stack,
1832    mut language: *const TSLanguage,
1833    mut f: *mut FILE,
1834) -> bool {
1835    _array__reserve(
1836        &mut (*self_0).iterators as *mut C2RustUnnamed_7 as *mut Array,
1837        ::core::mem::size_of::<StackIterator>() as libc::c_ulong,
1838        32 as libc::c_int as uint32_t,
1839    );
1840    if f.is_null() {
1841        f = core::ptr::null_mut();
1842    }
1843    fwrite!(f, "digraph stack {{\n",).unwrap_or(usize::MAX) as os::raw::c_int;
1844    fwrite!(f, "rankdir=\"RL\";\n",).unwrap_or(usize::MAX) as os::raw::c_int;
1845    fwrite!(f, "edge [arrowhead=none]\n",).unwrap_or(usize::MAX) as os::raw::c_int;
1846    let mut visited_nodes: C2RustUnnamed_9 = {
1847        let mut init = C2RustUnnamed_9 {
1848            contents: 0 as *mut *mut StackNode,
1849            size: 0 as libc::c_int as uint32_t,
1850            capacity: 0 as libc::c_int as uint32_t,
1851        };
1852        init
1853    };
1854    (*self_0).iterators.size = 0 as libc::c_int as uint32_t;
1855    let mut i: uint32_t = 0 as libc::c_int as uint32_t;
1856    while i < (*self_0).heads.size {
1857        let mut head: *mut StackHead =
1858            &mut *((*self_0).heads.contents).offset(i as isize) as *mut StackHead;
1859        if !((*head).status as libc::c_uint == StackStatusHalted as libc::c_int as libc::c_uint) {
1860            fwrite!(f, "node_head_{} [shape=none, label=\"\"]\n", i).unwrap_or(usize::MAX)
1861                as os::raw::c_int;
1862            fwrite!(
1863                f,
1864                "node_head_{} -> node_{:p} [",
1865                i,
1866                (*head).node as *mut libc::c_void as *const os::raw::c_int
1867            )
1868            .unwrap_or(usize::MAX) as os::raw::c_int;
1869            if (*head).status as libc::c_uint == StackStatusPaused as libc::c_int as libc::c_uint {
1870                fwrite!(f, "color=red ",).unwrap_or(usize::MAX) as os::raw::c_int;
1871            }
1872            fwrite ! (f , "label={}, fontcolor=blue, weight=10000, labeltooltip=\"node_count: {}\nerror_cost: {}" , i , ts_stack_node_count_since_error (self_0 , i) , ts_stack_error_cost (self_0 , i)) . unwrap_or (usize :: MAX) as os :: raw :: c_int ;
1873            if !((*head).summary).is_null() {
1874                fwrite!(f, "\nsummary:",).unwrap_or(usize::MAX) as os::raw::c_int;
1875                let mut j: uint32_t = 0 as libc::c_int as uint32_t;
1876                while j < (*(*head).summary).size {
1877                    fwrite!(
1878                        f,
1879                        " {}",
1880                        (*((*(*head).summary).contents).offset(j as isize)).state as libc::c_int
1881                    )
1882                    .unwrap_or(usize::MAX) as os::raw::c_int;
1883                    j = j.wrapping_add(1);
1884                }
1885            }
1886            if !((*head).last_external_token.ptr).is_null() {
1887                let mut state: *const ExternalScannerState = &(*(*head).last_external_token.ptr)
1888                    .c2rust_unnamed
1889                    .external_scanner_state;
1890                let mut data: *const libc::c_char = ts_external_scanner_state_data(state);
1891                fwrite!(f, "\nexternal_scanner_state:",).unwrap_or(usize::MAX) as os::raw::c_int;
1892                let mut j_0: uint32_t = 0 as libc::c_int as uint32_t;
1893                while j_0 < (*state).length {
1894                    fwrite!(f, " {:02X}", *data.offset(j_0 as isize) as libc::c_int)
1895                        .unwrap_or(usize::MAX) as os::raw::c_int;
1896                    j_0 = j_0.wrapping_add(1);
1897                }
1898            }
1899            fwrite!(f, "\"]\n",).unwrap_or(usize::MAX) as os::raw::c_int;
1900            _array__grow(
1901                &mut (*self_0).iterators as *mut C2RustUnnamed_7 as *mut Array,
1902                1 as libc::c_int as uint32_t,
1903                ::core::mem::size_of::<StackIterator>() as libc::c_ulong,
1904            );
1905            let fresh11 = (*self_0).iterators.size;
1906            (*self_0).iterators.size = ((*self_0).iterators.size).wrapping_add(1);
1907            *((*self_0).iterators.contents).offset(fresh11 as isize) = {
1908                let mut init = StackIterator {
1909                    node: (*head).node,
1910                    subtrees: SubtreeArray {
1911                        contents: 0 as *mut Subtree,
1912                        size: 0,
1913                        capacity: 0,
1914                    },
1915                    subtree_count: 0,
1916                    is_pending: false,
1917                };
1918                init
1919            };
1920        }
1921        i = i.wrapping_add(1);
1922    }
1923    let mut all_iterators_done: bool = 0 as libc::c_int != 0;
1924    while !all_iterators_done {
1925        all_iterators_done = 1 as libc::c_int != 0;
1926        let mut i_0: uint32_t = 0 as libc::c_int as uint32_t;
1927        while i_0 < (*self_0).iterators.size {
1928            let mut iterator: StackIterator = *((*self_0).iterators.contents).offset(i_0 as isize);
1929            let mut node: *mut StackNode = iterator.node;
1930            let mut j_1: uint32_t = 0 as libc::c_int as uint32_t;
1931            while j_1 < visited_nodes.size {
1932                if *(visited_nodes.contents).offset(j_1 as isize) == node {
1933                    node = 0 as *mut StackNode;
1934                    break;
1935                } else {
1936                    j_1 = j_1.wrapping_add(1);
1937                }
1938            }
1939            if !node.is_null() {
1940                all_iterators_done = 0 as libc::c_int != 0;
1941                fwrite!(
1942                    f,
1943                    "node_{:p} [",
1944                    node as *mut libc::c_void as *const os::raw::c_int
1945                )
1946                .unwrap_or(usize::MAX) as os::raw::c_int;
1947                if (*node).state as libc::c_int == 0 as libc::c_int {
1948                    fwrite!(f, "label=\"?\"",).unwrap_or(usize::MAX) as os::raw::c_int;
1949                } else if (*node).link_count as libc::c_int == 1 as libc::c_int
1950                    && !((*node).links[0 as libc::c_int as usize].subtree.ptr).is_null()
1951                    && ts_subtree_extra((*node).links[0 as libc::c_int as usize].subtree)
1952                        as libc::c_int
1953                        != 0
1954                {
1955                    fwrite!(f, "shape=point margin=0 label=\"\"",).unwrap_or(usize::MAX)
1956                        as os::raw::c_int;
1957                } else {
1958                    fwrite!(f, "label=\"{}\"", (*node).state as libc::c_int).unwrap_or(usize::MAX)
1959                        as os::raw::c_int;
1960                }
1961                fwrite ! (f , " tooltip=\"position: {},{}\nnode_count:{}\nerror_cost: {}\ndynamic_precedence: {}\"];\n" , ((* node) . position . extent . row) . wrapping_add (1 as libc :: c_int as libc :: c_uint) , (* node) . position . extent . column , (* node) . node_count , (* node) . error_cost , (* node) . dynamic_precedence) . unwrap_or (usize :: MAX) as os :: raw :: c_int ;
1962                let mut j_2: libc::c_int = 0 as libc::c_int;
1963                while j_2 < (*node).link_count as libc::c_int {
1964                    let mut link: StackLink = (*node).links[j_2 as usize];
1965                    fwrite!(
1966                        f,
1967                        "node_{:p} -> node_{:p} [",
1968                        node as *mut libc::c_void as *const os::raw::c_int,
1969                        link.node as *mut libc::c_void as *const os::raw::c_int
1970                    )
1971                    .unwrap_or(usize::MAX) as os::raw::c_int;
1972                    if link.is_pending {
1973                        fwrite!(f, "style=dashed ",).unwrap_or(usize::MAX) as os::raw::c_int;
1974                    }
1975                    if !(link.subtree.ptr).is_null()
1976                        && ts_subtree_extra(link.subtree) as libc::c_int != 0
1977                    {
1978                        fwrite!(f, "fontcolor=gray ",).unwrap_or(usize::MAX) as os::raw::c_int;
1979                    }
1980                    if (link.subtree.ptr).is_null() {
1981                        fwrite!(f, "color=red",).unwrap_or(usize::MAX) as os::raw::c_int;
1982                    } else {
1983                        fwrite!(f, "label=\"",).unwrap_or(usize::MAX) as os::raw::c_int;
1984                        let mut quoted: bool = ts_subtree_visible(link.subtree) as libc::c_int != 0
1985                            && !ts_subtree_named(link.subtree);
1986                        if quoted {
1987                            fwrite!(f, "'",).unwrap_or(usize::MAX) as os::raw::c_int;
1988                        }
1989                        ts_language_write_symbol_as_dot_string(
1990                            language,
1991                            f,
1992                            ts_subtree_symbol(link.subtree),
1993                        );
1994                        if quoted {
1995                            fwrite!(f, "'",).unwrap_or(usize::MAX) as os::raw::c_int;
1996                        }
1997                        fwrite!(f, "\"",).unwrap_or(usize::MAX) as os::raw::c_int;
1998                        fwrite!(
1999                            f,
2000                            "labeltooltip=\"error_cost: {}\ndynamic_precedence: {}\"",
2001                            ts_subtree_error_cost(link.subtree),
2002                            ts_subtree_dynamic_precedence(link.subtree)
2003                        )
2004                        .unwrap_or(usize::MAX) as os::raw::c_int;
2005                    }
2006                    fwrite!(f, "];\n",).unwrap_or(usize::MAX) as os::raw::c_int;
2007                    let mut next_iterator: *mut StackIterator = 0 as *mut StackIterator;
2008                    if j_2 == 0 as libc::c_int {
2009                        next_iterator = &mut *((*self_0).iterators.contents).offset(i_0 as isize)
2010                            as *mut StackIterator;
2011                    } else {
2012                        _array__grow(
2013                            &mut (*self_0).iterators as *mut C2RustUnnamed_7 as *mut Array,
2014                            1 as libc::c_int as uint32_t,
2015                            ::core::mem::size_of::<StackIterator>() as libc::c_ulong,
2016                        );
2017                        let fresh12 = (*self_0).iterators.size;
2018                        (*self_0).iterators.size = ((*self_0).iterators.size).wrapping_add(1);
2019                        *((*self_0).iterators.contents).offset(fresh12 as isize) = iterator;
2020                        if ((*self_0).iterators.size).wrapping_sub(1 as libc::c_int as libc::c_uint)
2021                            < (*self_0).iterators.size
2022                        {
2023                        } else {
2024                            panic!();
2025                        }
2026                        next_iterator = &mut *((*self_0).iterators.contents).offset(
2027                            ((*self_0).iterators.size)
2028                                .wrapping_sub(1 as libc::c_int as libc::c_uint)
2029                                as isize,
2030                        ) as *mut StackIterator;
2031                    }
2032                    (*next_iterator).node = link.node;
2033                    j_2 += 1;
2034                }
2035                _array__grow(
2036                    &mut visited_nodes as *mut C2RustUnnamed_9 as *mut Array,
2037                    1 as libc::c_int as uint32_t,
2038                    ::core::mem::size_of::<*mut StackNode>() as libc::c_ulong,
2039                );
2040                let fresh13 = visited_nodes.size;
2041                visited_nodes.size = (visited_nodes.size).wrapping_add(1);
2042                let ref mut fresh14 = *(visited_nodes.contents).offset(fresh13 as isize);
2043                *fresh14 = node;
2044            }
2045            i_0 = i_0.wrapping_add(1);
2046        }
2047    }
2048    fwrite!(f, "}}\n",).unwrap_or(usize::MAX) as os::raw::c_int;
2049    _array__delete(&mut visited_nodes as *mut C2RustUnnamed_9 as *mut Array);
2050    return 1 as libc::c_int != 0;
2051}
2052pub const StackStatus_StackStatusHalted: StackStatus = StackStatusHalted;
2053pub const StackStatus_StackStatusPaused: StackStatus = StackStatusPaused;
2054pub const StackStatus_StackStatusActive: StackStatus = StackStatusActive;