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 __uint64_t = libc::c_ulong;
11pub type __time_t = libc::c_long;
12pub type __clockid_t = libc::c_int;
13pub type __syscall_slong_t = libc::c_long;
14pub type clockid_t = __clockid_t;
15pub type int16_t = __int16_t;
16pub type int32_t = __int32_t;
17pub type uint8_t = __uint8_t;
18pub type uint16_t = __uint16_t;
19pub type uint32_t = __uint32_t;
20pub type TSStateId = uint16_t;
21pub type TSFieldId = uint16_t;
22#[derive(Copy, Clone)]
23#[repr(C)]
24pub struct C2RustUnnamed {
25 pub states: *const bool,
26 pub symbol_map: *const TSSymbol,
27 pub create: Option<unsafe extern "C" fn() -> *mut libc::c_void>,
28 pub destroy: Option<unsafe extern "C" fn(*mut libc::c_void) -> ()>,
29 pub scan: Option<unsafe extern "C" fn(*mut libc::c_void, *mut TSLexer, *const bool) -> bool>,
30 pub serialize:
31 Option<unsafe extern "C" fn(*mut libc::c_void, *mut libc::c_char) -> libc::c_uint>,
32 pub deserialize:
33 Option<unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, libc::c_uint) -> ()>,
34}
35#[derive(Copy, Clone)]
36#[repr(C)]
37pub struct C2RustUnnamed_0 {
38 pub count: uint8_t,
39 pub reusable: bool,
40}
41#[derive(Copy, Clone)]
42#[repr(C)]
43pub struct C2RustUnnamed_1 {
44 pub type_: uint8_t,
45 pub child_count: uint8_t,
46 pub symbol: TSSymbol,
47 pub dynamic_precedence: int16_t,
48 pub production_id: uint16_t,
49}
50#[derive(Copy, Clone)]
51#[repr(C)]
52pub struct C2RustUnnamed_2 {
53 pub type_: uint8_t,
54 pub state: TSStateId,
55 pub extra: bool,
56 pub repetition: bool,
57}
58#[derive(Copy, Clone)]
59#[repr(C)]
60pub struct TSQuery {
61 pub captures: SymbolTable,
62 pub predicate_values: SymbolTable,
63 pub capture_quantifiers: C2RustUnnamed_11,
64 pub steps: C2RustUnnamed_10,
65 pub pattern_map: C2RustUnnamed_9,
66 pub predicate_steps: C2RustUnnamed_8,
67 pub patterns: C2RustUnnamed_7,
68 pub step_offsets: C2RustUnnamed_6,
69 pub negated_fields: C2RustUnnamed_5,
70 pub string_buffer: C2RustUnnamed_4,
71 pub repeat_symbols_with_rootless_patterns: C2RustUnnamed_3,
72 pub language: *const TSLanguage,
73 pub wildcard_root_pattern_count: uint16_t,
74}
75type C2RustUnnamed_3 = crate::core_transpiled::util::StackElement<*mut TSSymbol>;
76type C2RustUnnamed_4 = crate::core_transpiled::util::StackElement<*mut libc::c_char>;
77type C2RustUnnamed_5 = crate::core_transpiled::util::StackElement<*mut TSFieldId>;
78type C2RustUnnamed_6 = crate::core_transpiled::util::StackElement<*mut StepOffset>;
79#[derive(Copy, Clone)]
80#[repr(C)]
81pub struct StepOffset {
82 pub byte_offset: uint32_t,
83 pub step_index: uint16_t,
84}
85type C2RustUnnamed_7 = crate::core_transpiled::util::StackElement<*mut QueryPattern>;
86#[derive(Copy, Clone)]
87#[repr(C)]
88pub struct QueryPattern {
89 pub steps: Slice,
90 pub predicate_steps: Slice,
91 pub start_byte: uint32_t,
92 pub end_byte: uint32_t,
93 pub is_non_local: bool,
94}
95#[derive(Copy, Clone)]
96#[repr(C)]
97pub struct Slice {
98 pub offset: uint32_t,
99 pub length: uint32_t,
100}
101type C2RustUnnamed_8 = crate::core_transpiled::util::StackElement<*mut TSQueryPredicateStep>;
102#[derive(Copy, Clone)]
103#[repr(C)]
104pub struct TSQueryPredicateStep {
105 pub type_: TSQueryPredicateStepType,
106 pub value_id: uint32_t,
107}
108type C2RustUnnamed_9 = crate::core_transpiled::util::StackElement<*mut PatternEntry>;
109#[derive(Copy, Clone)]
110#[repr(C)]
111pub struct PatternEntry {
112 pub step_index: uint16_t,
113 pub pattern_index: uint16_t,
114 pub is_rooted: bool,
115}
116type C2RustUnnamed_10 = crate::core_transpiled::util::StackElement<*mut QueryStep>;
117#[derive(Copy, Clone, BitfieldStruct)]
118#[repr(C)]
119pub struct QueryStep {
120 pub symbol: TSSymbol,
121 pub supertype_symbol: TSSymbol,
122 pub field: TSFieldId,
123 pub capture_ids: [uint16_t; 3],
124 pub depth: uint16_t,
125 pub alternative_index: uint16_t,
126 pub negated_field_list_id: uint16_t,
127 #[bitfield(name = "is_named", ty = "bool", bits = "0..=0")]
128 #[bitfield(name = "is_immediate", ty = "bool", bits = "1..=1")]
129 #[bitfield(name = "is_last_child", ty = "bool", bits = "2..=2")]
130 #[bitfield(name = "is_pass_through", ty = "bool", bits = "3..=3")]
131 #[bitfield(name = "is_dead_end", ty = "bool", bits = "4..=4")]
132 #[bitfield(name = "alternative_is_immediate", ty = "bool", bits = "5..=5")]
133 #[bitfield(name = "contains_captures", ty = "bool", bits = "6..=6")]
134 #[bitfield(name = "root_pattern_guaranteed", ty = "bool", bits = "7..=7")]
135 #[bitfield(name = "parent_pattern_guaranteed", ty = "bool", bits = "8..=8")]
136 pub is_named_is_immediate_is_last_child_is_pass_through_is_dead_end_alternative_is_immediate_contains_captures_root_pattern_guaranteed_parent_pattern_guaranteed:
137 [u8; 2],
138}
139type C2RustUnnamed_11 = crate::core_transpiled::util::StackElement<*mut CaptureQuantifiers>;
140#[derive(Copy, Clone)]
141#[repr(C)]
142pub struct CaptureQuantifiers {
143 pub contents: *mut uint8_t,
144 pub size: uint32_t,
145 pub capacity: uint32_t,
146}
147#[derive(Copy, Clone)]
148#[repr(C)]
149pub struct SymbolTable {
150 pub characters: C2RustUnnamed_13,
151 pub slices: C2RustUnnamed_12,
152}
153type C2RustUnnamed_12 = crate::core_transpiled::util::StackElement<*mut Slice>;
154type C2RustUnnamed_13 = crate::core_transpiled::util::StackElement<*mut libc::c_char>;
155#[derive(Copy, Clone)]
156#[repr(C)]
157pub struct TSQueryCursor {
158 pub query: *const TSQuery,
159 pub cursor: TSTreeCursor,
160 pub states: C2RustUnnamed_16,
161 pub finished_states: C2RustUnnamed_15,
162 pub capture_list_pool: CaptureListPool,
163 pub depth: uint32_t,
164 pub max_start_depth: uint32_t,
165 pub start_byte: uint32_t,
166 pub end_byte: uint32_t,
167 pub start_point: TSPoint,
168 pub end_point: TSPoint,
169 pub next_state_id: uint32_t,
170 pub end_clock: TSClock,
171 pub timeout_duration: TSDuration,
172 pub operation_count: libc::c_uint,
173 pub on_visible_node: bool,
174 pub ascending: bool,
175 pub halted: bool,
176 pub did_exceed_match_limit: bool,
177}
178pub type TSDuration = uint64_t;
179#[derive(Copy, Clone)]
180#[repr(C)]
181pub struct CaptureListPool {
182 pub list: C2RustUnnamed_14,
183 pub empty_list: CaptureList,
184 pub max_capture_list_count: uint32_t,
185 pub free_capture_list_count: uint32_t,
186}
187#[derive(Copy, Clone)]
188#[repr(C)]
189pub struct CaptureList {
190 pub contents: *mut TSQueryCapture,
191 pub size: uint32_t,
192 pub capacity: uint32_t,
193}
194#[derive(Copy, Clone)]
195#[repr(C)]
196pub struct TSQueryCapture {
197 pub node: TSNode,
198 pub index: uint32_t,
199}
200type C2RustUnnamed_14 = crate::core_transpiled::util::StackElement<*mut CaptureList>;
201type C2RustUnnamed_15 = crate::core_transpiled::util::StackElement<*mut QueryState>;
202#[derive(Copy, Clone, BitfieldStruct)]
203#[repr(C)]
204pub struct QueryState {
205 pub id: uint32_t,
206 pub capture_list_id: uint32_t,
207 pub start_depth: uint16_t,
208 pub step_index: uint16_t,
209 pub pattern_index: uint16_t,
210 #[bitfield(name = "consumed_capture_count", ty = "uint16_t", bits = "0..=11")]
211 #[bitfield(name = "seeking_immediate_match", ty = "bool", bits = "12..=12")]
212 #[bitfield(name = "has_in_progress_alternatives", ty = "bool", bits = "13..=13")]
213 #[bitfield(name = "dead", ty = "bool", bits = "14..=14")]
214 #[bitfield(name = "needs_parent", ty = "bool", bits = "15..=15")]
215 pub consumed_capture_count_seeking_immediate_match_has_in_progress_alternatives_dead_needs_parent:
216 [u8; 2],
217}
218type C2RustUnnamed_16 = crate::core_transpiled::util::StackElement<*mut QueryState>;
219#[derive(Copy, Clone)]
220#[repr(C)]
221pub struct TSQueryMatch {
222 pub id: uint32_t,
223 pub pattern_index: uint16_t,
224 pub capture_count: uint16_t,
225 pub captures: *const TSQueryCapture,
226}
227#[derive(Copy, Clone)]
228#[repr(C)]
229pub struct Array {
230 pub contents: *mut libc::c_void,
231 pub size: uint32_t,
232 pub capacity: uint32_t,
233}
234#[derive(Copy, Clone)]
235#[repr(C)]
236pub struct StatePredecessorMap {
237 pub contents: *mut TSStateId,
238}
239type C2RustUnnamed_17 = crate::core_transpiled::util::StackElement<*mut uint16_t>;
240type C2RustUnnamed_18 = crate::core_transpiled::util::StackElement<*mut uint32_t>;
241type C2RustUnnamed_19 = crate::core_transpiled::util::StackElement<*mut uint16_t>;
242type C2RustUnnamed_20 = crate::core_transpiled::util::StackElement<*mut AnalysisSubgraphNode>;
243#[derive(Copy, Clone, BitfieldStruct)]
244#[repr(C)]
245pub struct AnalysisSubgraphNode {
246 pub state: TSStateId,
247 pub production_id: uint16_t,
248 #[bitfield(name = "child_index", ty = "uint8_t", bits = "0..=6")]
249 #[bitfield(name = "done", ty = "bool", bits = "7..=7")]
250 pub child_index_done: [u8; 1],
251 #[bitfield(padding)]
252 pub c2rust_padding: [u8; 1],
253}
254#[derive(Copy, Clone)]
255#[repr(C)]
256pub struct QueryAnalysis {
257 pub states: AnalysisStateSet,
258 pub next_states: AnalysisStateSet,
259 pub deeper_states: AnalysisStateSet,
260 pub state_pool: AnalysisStateSet,
261 pub final_step_indices: C2RustUnnamed_22,
262 pub finished_parent_symbols: C2RustUnnamed_21,
263 pub did_abort: bool,
264}
265type C2RustUnnamed_21 = crate::core_transpiled::util::StackElement<*mut TSSymbol>;
266type C2RustUnnamed_22 = crate::core_transpiled::util::StackElement<*mut uint16_t>;
267#[derive(Copy, Clone)]
268#[repr(C)]
269pub struct AnalysisStateSet {
270 pub contents: *mut *mut AnalysisState,
271 pub size: uint32_t,
272 pub capacity: uint32_t,
273}
274#[derive(Copy, Clone)]
275#[repr(C)]
276pub struct AnalysisState {
277 pub stack: [AnalysisStateEntry; 8],
278 pub depth: uint16_t,
279 pub step_index: uint16_t,
280 pub root_symbol: TSSymbol,
281}
282#[derive(Copy, Clone, BitfieldStruct)]
283#[repr(C)]
284pub struct AnalysisStateEntry {
285 pub parse_state: TSStateId,
286 pub parent_symbol: TSSymbol,
287 pub child_index: uint16_t,
288 #[bitfield(name = "field_id", ty = "TSFieldId", bits = "0..=14")]
289 #[bitfield(name = "done", ty = "bool", bits = "15..=15")]
290 pub field_id_done: [u8; 2],
291}
292#[derive(Copy, Clone)]
293#[repr(C)]
294pub struct AnalysisSubgraphArray {
295 pub contents: *mut AnalysisSubgraph,
296 pub size: uint32_t,
297 pub capacity: uint32_t,
298}
299#[derive(Copy, Clone)]
300#[repr(C)]
301pub struct AnalysisSubgraph {
302 pub symbol: TSSymbol,
303 pub start_states: C2RustUnnamed_24,
304 pub nodes: C2RustUnnamed_23,
305}
306type C2RustUnnamed_23 = crate::core_transpiled::util::StackElement<*mut AnalysisSubgraphNode>;
307type C2RustUnnamed_24 = crate::core_transpiled::util::StackElement<*mut TSStateId>;
308pub const TSParseActionTypeShift: C2RustUnnamed_31 = 0;
309pub const TSParseActionTypeReduce: C2RustUnnamed_31 = 1;
310#[derive(Copy, Clone)]
311#[repr(C)]
312pub struct Stream {
313 pub input: *const libc::c_char,
314 pub start: *const libc::c_char,
315 pub end: *const libc::c_char,
316 pub next: int32_t,
317 pub next_size: uint8_t,
318}
319pub type wint_t = libc::c_uint;
320type C2RustUnnamed_25 = crate::core_transpiled::util::StackElement<*mut uint32_t>;
321pub const TreeCursorStepHidden: TreeCursorStep = 1;
322pub const TreeCursorStepVisible: TreeCursorStep = 2;
323pub type TreeCursorStep = libc::c_uint;
324pub const TreeCursorStepNone: TreeCursorStep = 0;
325type C2RustUnnamed_26 = crate::core_transpiled::util::ScannerStateWithLookahead;
326type C2RustUnnamed_27 = crate::core_transpiled::util::LongShortData;
327type C2RustUnnamed_28 = crate::core_transpiled::util::ScannerStateLookaheadMeta;
328type C2RustUnnamed_29 = crate::core_transpiled::util::ScannerStateLookaheadFirstLeaf;
329type C2RustUnnamed_30 = crate::core_transpiled::util::StackElement<*mut TreeCursorEntry>;
330pub type C2RustUnnamed_31 = libc::c_uint;
331pub const TSParseActionTypeRecover: C2RustUnnamed_31 = 3;
332pub const TSParseActionTypeAccept: C2RustUnnamed_31 = 2;
333#[inline]
334unsafe extern "C" fn _array__delete(mut self_0: *mut Array) {
335 if !((*self_0).contents).is_null() {
336 crate::core_transpiled::alloc::ts_free((*self_0).contents);
337 (*self_0).contents = 0 as *mut libc::c_void;
338 (*self_0).size = 0 as libc::c_int as uint32_t;
339 (*self_0).capacity = 0 as libc::c_int as uint32_t;
340 }
341}
342#[inline]
343unsafe extern "C" fn _array__splice(
344 mut self_0: *mut Array,
345 mut element_size: size_t,
346 mut index: uint32_t,
347 mut old_count: uint32_t,
348 mut new_count: uint32_t,
349 mut elements: *const libc::c_void,
350) {
351 let mut new_size: uint32_t = ((*self_0).size)
352 .wrapping_add(new_count)
353 .wrapping_sub(old_count);
354 let mut old_end: uint32_t = index.wrapping_add(old_count);
355 let mut new_end: uint32_t = index.wrapping_add(new_count);
356 if old_end <= (*self_0).size {
357 } else {
358 panic!();
359 }
360 _array__reserve(self_0, element_size, new_size);
361 let mut contents: *mut libc::c_char = (*self_0).contents as *mut libc::c_char;
362 if (*self_0).size > old_end {
363 std::ptr::copy(
364 contents.offset((old_end as libc::c_ulong).wrapping_mul(element_size) as isize)
365 as *const libc::c_void,
366 contents.offset((new_end as libc::c_ulong).wrapping_mul(element_size) as isize)
367 as *mut libc::c_void,
368 ((((*self_0).size).wrapping_sub(old_end) as libc::c_ulong).wrapping_mul(element_size))
369 as usize,
370 );
371 }
372 if new_count > 0 as libc::c_int as libc::c_uint {
373 if !elements.is_null() {
374 std::ptr::copy_nonoverlapping(
375 elements,
376 contents.offset((index as libc::c_ulong).wrapping_mul(element_size) as isize)
377 as *mut libc::c_void,
378 (new_count as libc::c_ulong).wrapping_mul(element_size),
379 );
380 } else {
381 std::ptr::write_bytes(
382 contents.offset((index as libc::c_ulong).wrapping_mul(element_size) as isize)
383 as *mut libc::c_void,
384 (0 as libc::c_int) as u8,
385 ((new_count as libc::c_ulong).wrapping_mul(element_size)) as usize,
386 );
387 }
388 }
389 (*self_0).size = ((*self_0).size as libc::c_uint)
390 .wrapping_add(new_count.wrapping_sub(old_count)) as uint32_t
391 as uint32_t;
392}
393#[inline]
394unsafe extern "C" fn _array__reserve(
395 mut self_0: *mut Array,
396 mut element_size: size_t,
397 mut new_capacity: uint32_t,
398) {
399 if new_capacity > (*self_0).capacity {
400 if !((*self_0).contents).is_null() {
401 (*self_0).contents = crate::core_transpiled::alloc::ts_realloc(
402 (*self_0).contents,
403 (new_capacity as libc::c_ulong).wrapping_mul(element_size),
404 );
405 } else {
406 (*self_0).contents = crate::core_transpiled::alloc::ts_malloc(
407 (new_capacity as libc::c_ulong).wrapping_mul(element_size),
408 );
409 }
410 (*self_0).capacity = new_capacity;
411 }
412}
413#[inline]
414unsafe extern "C" fn _array__grow(
415 mut self_0: *mut Array,
416 mut count: uint32_t,
417 mut element_size: size_t,
418) {
419 let mut new_size: uint32_t = ((*self_0).size).wrapping_add(count);
420 if new_size > (*self_0).capacity {
421 let mut new_capacity: uint32_t =
422 ((*self_0).capacity).wrapping_mul(2 as libc::c_int as libc::c_uint);
423 if new_capacity < 8 as libc::c_int as libc::c_uint {
424 new_capacity = 8 as libc::c_int as uint32_t;
425 }
426 if new_capacity < new_size {
427 new_capacity = new_size;
428 }
429 _array__reserve(self_0, element_size, new_capacity);
430 }
431}
432#[inline]
433unsafe extern "C" fn _array__assign(
434 mut self_0: *mut Array,
435 mut other: *const Array,
436 mut element_size: size_t,
437) {
438 _array__reserve(self_0, element_size, (*other).size);
439 (*self_0).size = (*other).size;
440 std::ptr::copy_nonoverlapping(
441 (*other).contents,
442 (*self_0).contents,
443 ((*self_0).size as libc::c_ulong).wrapping_mul(element_size),
444 );
445}
446#[inline]
447unsafe extern "C" fn _array__erase(
448 mut self_0: *mut Array,
449 mut element_size: size_t,
450 mut index: uint32_t,
451) {
452 if index < (*self_0).size {
453 } else {
454 panic!();
455 }
456 let mut contents: *mut libc::c_char = (*self_0).contents as *mut libc::c_char;
457 std::ptr::copy(
458 contents.offset(
459 (index.wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong)
460 .wrapping_mul(element_size) as isize,
461 ) as *const libc::c_void,
462 contents.offset((index as libc::c_ulong).wrapping_mul(element_size) as isize)
463 as *mut libc::c_void,
464 ((((*self_0).size)
465 .wrapping_sub(index)
466 .wrapping_sub(1 as libc::c_int as libc::c_uint) as libc::c_ulong)
467 .wrapping_mul(element_size)) as usize,
468 );
469 (*self_0).size = ((*self_0).size).wrapping_sub(1);
470}
471#[inline]
472unsafe extern "C" fn duration_from_micros(mut micros: uint64_t) -> TSDuration {
473 return micros;
474}
475#[inline]
476unsafe extern "C" fn duration_to_micros(mut self_0: TSDuration) -> uint64_t {
477 return self_0;
478}
479#[inline]
480unsafe extern "C" fn clock_null() -> TSClock {
481 return {
482 let mut init = timespec {
483 tv_sec: 0 as libc::c_int as __time_t,
484 tv_nsec: 0 as libc::c_int as __syscall_slong_t,
485 };
486 init
487 };
488}
489#[inline]
490unsafe extern "C" fn clock_after(mut base: TSClock, mut duration: TSDuration) -> TSClock {
491 let mut result: TSClock = base;
492 result.tv_sec = (result.tv_sec as libc::c_ulong)
493 .wrapping_add((duration as usize).wrapping_div(1000000 as libc::c_int as libc::c_ulong))
494 as __time_t as __time_t;
495 result.tv_nsec = (result.tv_nsec as libc::c_ulong).wrapping_add(
496 (duration as usize)
497 .wrapping_rem(1000000 as libc::c_int as libc::c_ulong)
498 .wrapping_mul(1000 as libc::c_int as libc::c_ulong),
499 ) as __syscall_slong_t as __syscall_slong_t;
500 if result.tv_nsec >= 1000000000 as libc::c_int as libc::c_long {
501 result.tv_nsec -= 1000000000 as libc::c_int as libc::c_long;
502 result.tv_sec += 1;
503 }
504 return result;
505}
506#[inline]
507unsafe extern "C" fn clock_is_null(mut self_0: TSClock) -> bool {
508 return self_0.tv_sec == 0 && self_0.tv_nsec == 0;
509}
510#[inline]
511unsafe extern "C" fn clock_is_gt(mut self_0: TSClock, mut other: TSClock) -> bool {
512 if self_0.tv_sec > other.tv_sec {
513 return 1 as libc::c_int != 0;
514 }
515 if self_0.tv_sec < other.tv_sec {
516 return 0 as libc::c_int != 0;
517 }
518 return self_0.tv_nsec > other.tv_nsec;
519}
520#[inline]
521unsafe extern "C" fn ts_subtree_symbol(mut self_0: Subtree) -> TSSymbol {
522 return (if (self_0.data).is_inline() as libc::c_int != 0 {
523 self_0.data.symbol as libc::c_int
524 } else {
525 (*self_0.ptr).symbol as libc::c_int
526 }) as TSSymbol;
527}
528#[inline]
529unsafe extern "C" fn ts_language_aliases_for_symbol(
530 mut self_0: *const TSLanguage,
531 mut original_symbol: TSSymbol,
532 mut start: *mut *const TSSymbol,
533 mut end: *mut *const TSSymbol,
534) {
535 *start = &*((*self_0).public_symbol_map).offset(original_symbol as isize) as *const TSSymbol;
536 *end = (*start).offset(1 as libc::c_int as isize);
537 let mut idx: libc::c_uint = 0 as libc::c_int as libc::c_uint;
538 loop {
539 let fresh0 = idx;
540 idx = idx.wrapping_add(1);
541 let mut symbol: TSSymbol = *((*self_0).alias_map).offset(fresh0 as isize);
542 if symbol as libc::c_int == 0 as libc::c_int
543 || symbol as libc::c_int > original_symbol as libc::c_int
544 {
545 break;
546 }
547 let fresh1 = idx;
548 idx = idx.wrapping_add(1);
549 let mut count: uint16_t = *((*self_0).alias_map).offset(fresh1 as isize);
550 if symbol as libc::c_int == original_symbol as libc::c_int {
551 *start = &*((*self_0).alias_map).offset(idx as isize) as *const uint16_t;
552 *end = &*((*self_0).alias_map).offset(idx.wrapping_add(count as libc::c_uint) as isize)
553 as *const uint16_t;
554 break;
555 } else {
556 idx = idx.wrapping_add(count as libc::c_uint);
557 }
558 }
559}
560#[inline]
561unsafe extern "C" fn ts_language_state_is_primary(
562 mut self_0: *const TSLanguage,
563 mut state: TSStateId,
564) -> bool {
565 if (*self_0).version >= 14 as libc::c_int as libc::c_uint {
566 return state as libc::c_int
567 == *((*self_0).primary_state_ids).offset(state as isize) as libc::c_int;
568 } else {
569 return 1 as libc::c_int != 0;
570 };
571}
572#[inline]
573unsafe extern "C" fn ts_lookahead_iterator__next(mut self_0: *mut LookaheadIterator) -> bool {
574 if (*self_0).is_small_state {
575 (*self_0).data = ((*self_0).data).offset(1);
576 if (*self_0).data == (*self_0).group_end {
577 if (*self_0).group_count as libc::c_int == 0 as libc::c_int {
578 return 0 as libc::c_int != 0;
579 }
580 (*self_0).group_count = ((*self_0).group_count).wrapping_sub(1);
581 let fresh2 = (*self_0).data;
582 (*self_0).data = ((*self_0).data).offset(1);
583 (*self_0).table_value = *fresh2;
584 let fresh3 = (*self_0).data;
585 (*self_0).data = ((*self_0).data).offset(1);
586 let mut symbol_count: libc::c_uint = *fresh3 as libc::c_uint;
587 (*self_0).group_end = ((*self_0).data).offset(symbol_count as isize);
588 (*self_0).symbol = *(*self_0).data;
589 } else {
590 (*self_0).symbol = *(*self_0).data;
591 return 1 as libc::c_int != 0;
592 }
593 } else {
594 loop {
595 (*self_0).data = ((*self_0).data).offset(1);
596 (*self_0).symbol = ((*self_0).symbol).wrapping_add(1);
597 if (*self_0).symbol as libc::c_uint >= (*(*self_0).language).symbol_count {
598 return 0 as libc::c_int != 0;
599 }
600 (*self_0).table_value = *(*self_0).data;
601 if !((*self_0).table_value == 0) {
602 break;
603 }
604 }
605 }
606 if ((*self_0).symbol as libc::c_uint) < (*(*self_0).language).token_count {
607 let mut entry: *const TSParseActionEntry = &*((*(*self_0).language).parse_actions)
608 .offset((*self_0).table_value as isize)
609 as *const TSParseActionEntry;
610 (*self_0).action_count = (*entry).entry.count as uint16_t;
611 (*self_0).actions = entry.offset(1 as libc::c_int as isize) as *const TSParseAction;
612 (*self_0).next_state = 0 as libc::c_int as TSStateId;
613 } else {
614 (*self_0).action_count = 0 as libc::c_int as uint16_t;
615 (*self_0).next_state = (*self_0).table_value;
616 }
617 return 1 as libc::c_int != 0;
618}
619#[inline]
620unsafe extern "C" fn ts_language_field_map(
621 mut self_0: *const TSLanguage,
622 mut production_id: uint32_t,
623 mut start: *mut *const TSFieldMapEntry,
624 mut end: *mut *const TSFieldMapEntry,
625) {
626 if (*self_0).field_count == 0 as libc::c_int as libc::c_uint {
627 *start = 0 as *const TSFieldMapEntry;
628 *end = 0 as *const TSFieldMapEntry;
629 return;
630 }
631 let mut slice: TSFieldMapSlice = *((*self_0).field_map_slices).offset(production_id as isize);
632 *start = &*((*self_0).field_map_entries).offset(slice.index as isize) as *const TSFieldMapEntry;
633 *end = (&*((*self_0).field_map_entries).offset(slice.index as isize) as *const TSFieldMapEntry)
634 .offset(slice.length as libc::c_int as isize);
635}
636#[inline]
637unsafe extern "C" fn ts_language_alias_at(
638 mut self_0: *const TSLanguage,
639 mut production_id: uint32_t,
640 mut child_index: uint32_t,
641) -> TSSymbol {
642 return (if production_id != 0 {
643 *((*self_0).alias_sequences).offset(
644 production_id
645 .wrapping_mul((*self_0).max_alias_sequence_length as libc::c_uint)
646 .wrapping_add(child_index) as isize,
647 ) as libc::c_int
648 } else {
649 0 as libc::c_int
650 }) as TSSymbol;
651}
652#[inline]
653unsafe extern "C" fn ts_language_lookaheads(
654 mut self_0: *const TSLanguage,
655 mut state: TSStateId,
656) -> LookaheadIterator {
657 let mut is_small_state: bool = state as libc::c_uint >= (*self_0).large_state_count;
658 let mut data: *const uint16_t = 0 as *const uint16_t;
659 let mut group_end: *const uint16_t = 0 as *const uint16_t;
660 let mut group_count: uint16_t = 0 as libc::c_int as uint16_t;
661 if is_small_state {
662 let mut index: uint32_t = *((*self_0).small_parse_table_map)
663 .offset((state as libc::c_uint).wrapping_sub((*self_0).large_state_count) as isize);
664 data = &*((*self_0).small_parse_table).offset(index as isize) as *const uint16_t;
665 group_end = data.offset(1 as libc::c_int as isize);
666 group_count = *data;
667 } else {
668 data = (&*((*self_0).parse_table)
669 .offset((state as libc::c_uint).wrapping_mul((*self_0).symbol_count) as isize)
670 as *const uint16_t)
671 .offset(-(1 as libc::c_int as isize));
672 }
673 return {
674 let mut init = LookaheadIterator {
675 language: self_0,
676 data: data,
677 group_end: group_end,
678 state: 0,
679 table_value: 0,
680 section_index: 0,
681 group_count: group_count,
682 is_small_state: is_small_state,
683 actions: 0 as *const TSParseAction,
684 symbol: 65535 as libc::c_int as TSSymbol,
685 next_state: 0 as libc::c_int as TSStateId,
686 action_count: 0,
687 };
688 init
689 };
690}
691#[inline]
692unsafe extern "C" fn ts_subtree_is_repetition(mut self_0: Subtree) -> uint32_t {
693 return (if (self_0.data).is_inline() as libc::c_int != 0 {
694 0 as libc::c_int
695 } else {
696 (!(*self_0.ptr).named()
697 && !(*self_0.ptr).visible()
698 && (*self_0.ptr).child_count != 0 as libc::c_int as libc::c_uint) as libc::c_int
699 }) as uint32_t;
700}
701#[inline]
702unsafe extern "C" fn point_lte(mut a: TSPoint, mut b: TSPoint) -> bool {
703 return a.row < b.row || a.row == b.row && a.column <= b.column;
704}
705#[inline]
706unsafe extern "C" fn point_lt(mut a: TSPoint, mut b: TSPoint) -> bool {
707 return a.row < b.row || a.row == b.row && a.column < b.column;
708}
709#[inline]
710unsafe extern "C" fn point_eq(mut a: TSPoint, mut b: TSPoint) -> bool {
711 return a.row == b.row && a.column == b.column;
712}
713#[inline]
714unsafe extern "C" fn point_gte(mut a: TSPoint, mut b: TSPoint) -> bool {
715 return a.row > b.row || a.row == b.row && a.column >= b.column;
716}
717#[inline]
718unsafe extern "C" fn ts_tree_cursor_current_subtree(mut _self: *const TSTreeCursor) -> Subtree {
719 let mut self_0: *const TreeCursor = _self as *const TreeCursor;
720 if ((*self_0).stack.size).wrapping_sub(1 as libc::c_int as libc::c_uint) < (*self_0).stack.size
721 {
722 } else {
723 panic!();
724 }
725 let mut last_entry: *mut TreeCursorEntry = &mut *((*self_0).stack.contents)
726 .offset(((*self_0).stack.size).wrapping_sub(1 as libc::c_int as libc::c_uint) as isize)
727 as *mut TreeCursorEntry;
728 return *(*last_entry).subtree;
729}
730#[inline]
731unsafe extern "C" fn ts_decode_utf8(
732 mut string: *const uint8_t,
733 mut length: uint32_t,
734 mut code_point: *mut int32_t,
735) -> uint32_t {
736 let mut i: uint32_t = 0 as libc::c_int as uint32_t;
737 let fresh4 = i;
738 i = i.wrapping_add(1);
739 *code_point = *string.offset(fresh4 as isize) as int32_t;
740 if !(*code_point & 0x80 as libc::c_int == 0 as libc::c_int) {
741 let mut __t: uint8_t = 0 as libc::c_int as uint8_t;
742 if !(i != length
743 && (if *code_point >= 0xe0 as libc::c_int {
744 ((if *code_point < 0xf0 as libc::c_int {
745 *code_point &= 0xf as libc::c_int;
746 __t = *string.offset(i as isize);
747 ((*::core::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(
748 b" 000000000000\x1000\0",
749 ))[*code_point as usize] as libc::c_int
750 & (1 as libc::c_int) << (__t as libc::c_int >> 5 as libc::c_int)
751 != 0
752 && {
753 __t = (__t as libc::c_int & 0x3f as libc::c_int) as uint8_t;
754 1 as libc::c_int != 0
755 }) as libc::c_int
756 } else {
757 *code_point -= 0xf0 as libc::c_int;
758 (*code_point <= 4 as libc::c_int
759 && {
760 __t = *string.offset(i as isize);
761 (*::core::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(
762 b"\0\0\0\0\0\0\0\0\x1E\x0F\x0F\x0F\0\0\0\0\0",
763 ))[(__t as libc::c_int >> 4 as libc::c_int) as usize]
764 as libc::c_int
765 & (1 as libc::c_int) << *code_point
766 != 0
767 }
768 && {
769 *code_point = *code_point << 6 as libc::c_int
770 | __t as libc::c_int & 0x3f as libc::c_int;
771 i = i.wrapping_add(1);
772 i != length
773 }
774 && {
775 __t = (*string.offset(i as isize) as libc::c_int - 0x80 as libc::c_int)
776 as uint8_t;
777 __t as libc::c_int <= 0x3f as libc::c_int
778 }) as libc::c_int
779 }) != 0
780 && {
781 *code_point = *code_point << 6 as libc::c_int | __t as libc::c_int;
782 i = i.wrapping_add(1);
783 i != length
784 }) as libc::c_int
785 } else {
786 (*code_point >= 0xc2 as libc::c_int && {
787 *code_point &= 0x1f as libc::c_int;
788 1 as libc::c_int != 0
789 }) as libc::c_int
790 }) != 0
791 && {
792 __t = (*string.offset(i as isize) as libc::c_int - 0x80 as libc::c_int) as uint8_t;
793 __t as libc::c_int <= 0x3f as libc::c_int
794 }
795 && {
796 *code_point = *code_point << 6 as libc::c_int | __t as libc::c_int;
797 i = i.wrapping_add(1);
798 1 as libc::c_int != 0
799 })
800 {
801 *code_point = -(1 as libc::c_int);
802 }
803 }
804 return i;
805}
806static mut PARENT_DONE: TSQueryError = 4294967295 as TSQueryError;
807static mut PATTERN_DONE_MARKER: uint16_t = 65535 as libc::c_int as uint16_t;
808static mut NONE: uint16_t = 65535 as libc::c_int as uint16_t;
809static mut WILDCARD_SYMBOL: TSSymbol = 0 as libc::c_int as TSSymbol;
810static mut OP_COUNT_PER_QUERY_TIMEOUT_CHECK: libc::c_uint = 100 as libc::c_int as libc::c_uint;
811unsafe extern "C" fn stream_advance(mut self_0: *mut Stream) -> bool {
812 (*self_0).input = ((*self_0).input).offset((*self_0).next_size as libc::c_int as isize);
813 if (*self_0).input < (*self_0).end {
814 let mut size: uint32_t = ts_decode_utf8(
815 (*self_0).input as *const uint8_t,
816 ((*self_0).end).offset_from((*self_0).input) as libc::c_long as uint32_t,
817 &mut (*self_0).next,
818 );
819 if size > 0 as libc::c_int as libc::c_uint {
820 (*self_0).next_size = size as uint8_t;
821 return 1 as libc::c_int != 0;
822 }
823 } else {
824 (*self_0).next_size = 0 as libc::c_int as uint8_t;
825 (*self_0).next = '\0' as i32;
826 }
827 return 0 as libc::c_int != 0;
828}
829unsafe extern "C" fn stream_reset(mut self_0: *mut Stream, mut input: *const libc::c_char) {
830 (*self_0).input = input;
831 (*self_0).next_size = 0 as libc::c_int as uint8_t;
832 stream_advance(self_0);
833}
834unsafe extern "C" fn stream_new(mut string: *const libc::c_char, mut length: uint32_t) -> Stream {
835 let mut self_0: Stream = {
836 let mut init = Stream {
837 input: string,
838 start: string,
839 end: string.offset(length as isize),
840 next: 0 as libc::c_int,
841 next_size: 0,
842 };
843 init
844 };
845 stream_advance(&mut self_0);
846 return self_0;
847}
848unsafe extern "C" fn stream_skip_whitespace(mut self_0: *mut Stream) {
849 loop {
850 if iswspace((*self_0).next as wint_t) != 0 {
851 stream_advance(self_0);
852 } else {
853 if !((*self_0).next == ';' as i32) {
854 break;
855 }
856 stream_advance(self_0);
857 while (*self_0).next != 0 && (*self_0).next != '\n' as i32 {
858 if !stream_advance(self_0) {
859 break;
860 }
861 }
862 }
863 }
864}
865unsafe extern "C" fn stream_is_ident_start(mut self_0: *mut Stream) -> bool {
866 return iswalnum((*self_0).next as wint_t) != 0
867 || (*self_0).next == '_' as i32
868 || (*self_0).next == '-' as i32;
869}
870unsafe extern "C" fn stream_scan_identifier(mut stream: *mut Stream) {
871 loop {
872 stream_advance(stream);
873 if !(iswalnum((*stream).next as wint_t) != 0
874 || (*stream).next == '_' as i32
875 || (*stream).next == '-' as i32
876 || (*stream).next == '.' as i32
877 || (*stream).next == '?' as i32
878 || (*stream).next == '!' as i32)
879 {
880 break;
881 }
882 }
883}
884unsafe extern "C" fn stream_offset(mut self_0: *mut Stream) -> uint32_t {
885 return ((*self_0).input).offset_from((*self_0).start) as libc::c_long as uint32_t;
886}
887unsafe extern "C" fn capture_list_pool_new() -> CaptureListPool {
888 return {
889 let mut init = CaptureListPool {
890 list: {
891 let mut init = C2RustUnnamed_14 {
892 contents: 0 as *mut CaptureList,
893 size: 0 as libc::c_int as uint32_t,
894 capacity: 0 as libc::c_int as uint32_t,
895 };
896 init
897 },
898 empty_list: {
899 let mut init = CaptureList {
900 contents: 0 as *mut TSQueryCapture,
901 size: 0 as libc::c_int as uint32_t,
902 capacity: 0 as libc::c_int as uint32_t,
903 };
904 init
905 },
906 max_capture_list_count: 4294967295 as libc::c_uint,
907 free_capture_list_count: 0 as libc::c_int as uint32_t,
908 };
909 init
910 };
911}
912unsafe extern "C" fn capture_list_pool_reset(mut self_0: *mut CaptureListPool) {
913 let mut i: uint16_t = 0 as libc::c_int as uint16_t;
914 while (i as libc::c_int) < (*self_0).list.size as uint16_t as libc::c_int {
915 (*((*self_0).list.contents).offset(i as isize)).size = 4294967295 as libc::c_uint;
916 i = i.wrapping_add(1);
917 }
918 (*self_0).free_capture_list_count = (*self_0).list.size;
919}
920unsafe extern "C" fn capture_list_pool_delete(mut self_0: *mut CaptureListPool) {
921 let mut i: uint16_t = 0 as libc::c_int as uint16_t;
922 while (i as libc::c_int) < (*self_0).list.size as uint16_t as libc::c_int {
923 _array__delete(
924 &mut *((*self_0).list.contents).offset(i as isize) as *mut CaptureList as *mut Array,
925 );
926 i = i.wrapping_add(1);
927 }
928 _array__delete(&mut (*self_0).list as *mut C2RustUnnamed_14 as *mut Array);
929}
930unsafe extern "C" fn capture_list_pool_get(
931 mut self_0: *const CaptureListPool,
932 mut id: uint16_t,
933) -> *const CaptureList {
934 if id as libc::c_uint >= (*self_0).list.size {
935 return &(*self_0).empty_list;
936 }
937 return &mut *((*self_0).list.contents).offset(id as isize) as *mut CaptureList;
938}
939unsafe extern "C" fn capture_list_pool_get_mut(
940 mut self_0: *mut CaptureListPool,
941 mut id: uint16_t,
942) -> *mut CaptureList {
943 if (id as libc::c_uint) < (*self_0).list.size {
944 } else {
945 panic!();
946 }
947 return &mut *((*self_0).list.contents).offset(id as isize) as *mut CaptureList;
948}
949unsafe extern "C" fn capture_list_pool_is_empty(mut self_0: *const CaptureListPool) -> bool {
950 return (*self_0).free_capture_list_count == 0 as libc::c_int as libc::c_uint
951 && (*self_0).list.size >= (*self_0).max_capture_list_count;
952}
953unsafe extern "C" fn capture_list_pool_acquire(mut self_0: *mut CaptureListPool) -> uint16_t {
954 if (*self_0).free_capture_list_count > 0 as libc::c_int as libc::c_uint {
955 let mut i: uint16_t = 0 as libc::c_int as uint16_t;
956 while (i as libc::c_int) < (*self_0).list.size as uint16_t as libc::c_int {
957 if (*((*self_0).list.contents).offset(i as isize)).size == 4294967295 as libc::c_uint {
958 (*((*self_0).list.contents).offset(i as isize)).size = 0 as libc::c_int as uint32_t;
959 (*self_0).free_capture_list_count =
960 ((*self_0).free_capture_list_count).wrapping_sub(1);
961 return i;
962 }
963 i = i.wrapping_add(1);
964 }
965 }
966 let mut i_0: uint32_t = (*self_0).list.size;
967 if i_0 >= (*self_0).max_capture_list_count {
968 return NONE;
969 }
970 let mut list: CaptureList = CaptureList {
971 contents: 0 as *mut TSQueryCapture,
972 size: 0,
973 capacity: 0,
974 };
975 list.size = 0 as libc::c_int as uint32_t;
976 list.capacity = 0 as libc::c_int as uint32_t;
977 list.contents = 0 as *mut TSQueryCapture;
978 _array__grow(
979 &mut (*self_0).list as *mut C2RustUnnamed_14 as *mut Array,
980 1 as libc::c_int as uint32_t,
981 ::core::mem::size_of::<CaptureList>() as libc::c_ulong,
982 );
983 let fresh5 = (*self_0).list.size;
984 (*self_0).list.size = ((*self_0).list.size).wrapping_add(1);
985 *((*self_0).list.contents).offset(fresh5 as isize) = list;
986 return i_0 as uint16_t;
987}
988unsafe extern "C" fn capture_list_pool_release(mut self_0: *mut CaptureListPool, mut id: uint16_t) {
989 if id as libc::c_uint >= (*self_0).list.size {
990 return;
991 }
992 (*((*self_0).list.contents).offset(id as isize)).size = 4294967295 as libc::c_uint;
993 (*self_0).free_capture_list_count = ((*self_0).free_capture_list_count).wrapping_add(1);
994}
995unsafe extern "C" fn quantifier_mul(
996 mut left: TSQuantifier,
997 mut right: TSQuantifier,
998) -> TSQuantifier {
999 match left as libc::c_uint {
1000 0 => return TSQuantifierZero,
1001 1 => match right as libc::c_uint {
1002 0 => return TSQuantifierZero,
1003 1 | 3 => return TSQuantifierZeroOrOne,
1004 2 | 4 => return TSQuantifierZeroOrMore,
1005 _ => {}
1006 },
1007 2 => match right as libc::c_uint {
1008 0 => return TSQuantifierZero,
1009 1 | 2 | 3 | 4 => return TSQuantifierZeroOrMore,
1010 _ => {}
1011 },
1012 3 => return right,
1013 4 => match right as libc::c_uint {
1014 0 => return TSQuantifierZero,
1015 1 | 2 => return TSQuantifierZeroOrMore,
1016 3 | 4 => return TSQuantifierOneOrMore,
1017 _ => {}
1018 },
1019 _ => {}
1020 }
1021 return TSQuantifierZero;
1022}
1023unsafe extern "C" fn quantifier_join(
1024 mut left: TSQuantifier,
1025 mut right: TSQuantifier,
1026) -> TSQuantifier {
1027 match left as libc::c_uint {
1028 0 => match right as libc::c_uint {
1029 0 => return TSQuantifierZero,
1030 1 | 3 => return TSQuantifierZeroOrOne,
1031 2 | 4 => return TSQuantifierZeroOrMore,
1032 _ => {}
1033 },
1034 1 => match right as libc::c_uint {
1035 0 | 1 | 3 => return TSQuantifierZeroOrOne,
1036 2 | 4 => return TSQuantifierZeroOrMore,
1037 _ => {}
1038 },
1039 2 => return TSQuantifierZeroOrMore,
1040 3 => match right as libc::c_uint {
1041 0 | 1 => return TSQuantifierZeroOrOne,
1042 2 => return TSQuantifierZeroOrMore,
1043 3 => return TSQuantifierOne,
1044 4 => return TSQuantifierOneOrMore,
1045 _ => {}
1046 },
1047 4 => match right as libc::c_uint {
1048 0 | 1 | 2 => return TSQuantifierZeroOrMore,
1049 3 | 4 => return TSQuantifierOneOrMore,
1050 _ => {}
1051 },
1052 _ => {}
1053 }
1054 return TSQuantifierZero;
1055}
1056unsafe extern "C" fn quantifier_add(
1057 mut left: TSQuantifier,
1058 mut right: TSQuantifier,
1059) -> TSQuantifier {
1060 match left as libc::c_uint {
1061 0 => return right,
1062 1 => match right as libc::c_uint {
1063 0 => return TSQuantifierZeroOrOne,
1064 1 | 2 => return TSQuantifierZeroOrMore,
1065 3 | 4 => return TSQuantifierOneOrMore,
1066 _ => {}
1067 },
1068 2 => match right as libc::c_uint {
1069 0 => return TSQuantifierZeroOrMore,
1070 1 | 2 => return TSQuantifierZeroOrMore,
1071 3 | 4 => return TSQuantifierOneOrMore,
1072 _ => {}
1073 },
1074 3 => match right as libc::c_uint {
1075 0 => return TSQuantifierOne,
1076 1 | 2 | 3 | 4 => return TSQuantifierOneOrMore,
1077 _ => {}
1078 },
1079 4 => return TSQuantifierOneOrMore,
1080 _ => {}
1081 }
1082 return TSQuantifierZero;
1083}
1084unsafe extern "C" fn capture_quantifiers_new() -> CaptureQuantifiers {
1085 return {
1086 let mut init = CaptureQuantifiers {
1087 contents: 0 as *mut uint8_t,
1088 size: 0 as libc::c_int as uint32_t,
1089 capacity: 0 as libc::c_int as uint32_t,
1090 };
1091 init
1092 };
1093}
1094unsafe extern "C" fn capture_quantifiers_delete(mut self_0: *mut CaptureQuantifiers) {
1095 _array__delete(self_0 as *mut Array);
1096}
1097unsafe extern "C" fn capture_quantifiers_clear(mut self_0: *mut CaptureQuantifiers) {
1098 (*self_0).size = 0 as libc::c_int as uint32_t;
1099}
1100unsafe extern "C" fn capture_quantifiers_replace(
1101 mut self_0: *mut CaptureQuantifiers,
1102 mut quantifiers: *mut CaptureQuantifiers,
1103) {
1104 (*self_0).size = 0 as libc::c_int as uint32_t;
1105 _array__splice(
1106 self_0 as *mut Array,
1107 ::core::mem::size_of::<uint8_t>() as libc::c_ulong,
1108 (*self_0).size,
1109 0 as libc::c_int as uint32_t,
1110 (*quantifiers).size,
1111 (*quantifiers).contents as *const libc::c_void,
1112 );
1113}
1114unsafe extern "C" fn capture_quantifier_for_id(
1115 mut self_0: *const CaptureQuantifiers,
1116 mut id: uint16_t,
1117) -> TSQuantifier {
1118 return (if (*self_0).size <= id as libc::c_uint {
1119 TSQuantifierZero as libc::c_int as libc::c_uint
1120 } else {
1121 if (id as uint32_t) < (*self_0).size {
1122 } else {
1123 panic!();
1124 }
1125 *(&mut *((*self_0).contents).offset(id as isize) as *mut uint8_t) as TSQuantifier
1126 as libc::c_uint
1127 }) as TSQuantifier;
1128}
1129unsafe extern "C" fn capture_quantifiers_add_for_id(
1130 mut self_0: *mut CaptureQuantifiers,
1131 mut id: uint16_t,
1132 mut quantifier: TSQuantifier,
1133) {
1134 if (*self_0).size <= id as libc::c_uint {
1135 if !(((id as libc::c_int + 1 as libc::c_int) as libc::c_uint).wrapping_sub((*self_0).size)
1136 == 0 as libc::c_int as libc::c_uint)
1137 {
1138 _array__grow(
1139 self_0 as *mut Array,
1140 ((id as libc::c_int + 1 as libc::c_int) as libc::c_uint)
1141 .wrapping_sub((*self_0).size),
1142 ::core::mem::size_of::<uint8_t>() as libc::c_ulong,
1143 );
1144 std::ptr::write_bytes(
1145 ((*self_0).contents).offset((*self_0).size as isize) as *mut libc::c_void,
1146 (0 as libc::c_int) as u8,
1147 ((((id as libc::c_int + 1 as libc::c_int) as libc::c_uint)
1148 .wrapping_sub((*self_0).size) as libc::c_ulong)
1149 .wrapping_mul(::core::mem::size_of::<uint8_t>() as libc::c_ulong))
1150 as usize,
1151 );
1152 (*self_0).size = ((*self_0).size as libc::c_uint).wrapping_add(
1153 ((id as libc::c_int + 1 as libc::c_int) as libc::c_uint)
1154 .wrapping_sub((*self_0).size),
1155 ) as uint32_t as uint32_t;
1156 }
1157 }
1158 if (id as uint32_t) < (*self_0).size {
1159 } else {
1160 panic!();
1161 }
1162 let mut own_quantifier: *mut uint8_t =
1163 &mut *((*self_0).contents).offset(id as isize) as *mut uint8_t;
1164 *own_quantifier = quantifier_add(*own_quantifier as TSQuantifier, quantifier) as uint8_t;
1165}
1166unsafe extern "C" fn capture_quantifiers_add_all(
1167 mut self_0: *mut CaptureQuantifiers,
1168 mut quantifiers: *mut CaptureQuantifiers,
1169) {
1170 if (*self_0).size < (*quantifiers).size {
1171 if !(((*quantifiers).size).wrapping_sub((*self_0).size) == 0 as libc::c_int as libc::c_uint)
1172 {
1173 _array__grow(
1174 self_0 as *mut Array,
1175 ((*quantifiers).size).wrapping_sub((*self_0).size),
1176 ::core::mem::size_of::<uint8_t>() as libc::c_ulong,
1177 );
1178 std::ptr::write_bytes(
1179 ((*self_0).contents).offset((*self_0).size as isize) as *mut libc::c_void,
1180 (0 as libc::c_int) as u8,
1181 ((((*quantifiers).size).wrapping_sub((*self_0).size) as libc::c_ulong)
1182 .wrapping_mul(::core::mem::size_of::<uint8_t>() as libc::c_ulong))
1183 as usize,
1184 );
1185 (*self_0).size = ((*self_0).size as libc::c_uint)
1186 .wrapping_add(((*quantifiers).size).wrapping_sub((*self_0).size))
1187 as uint32_t as uint32_t;
1188 }
1189 }
1190 let mut id: uint16_t = 0 as libc::c_int as uint16_t;
1191 while (id as libc::c_int) < (*quantifiers).size as uint16_t as libc::c_int {
1192 if (id as uint32_t) < (*quantifiers).size {
1193 } else {
1194 panic!();
1195 }
1196 let mut quantifier: *mut uint8_t =
1197 &mut *((*quantifiers).contents).offset(id as isize) as *mut uint8_t;
1198 if (id as uint32_t) < (*self_0).size {
1199 } else {
1200 panic!();
1201 }
1202 let mut own_quantifier: *mut uint8_t =
1203 &mut *((*self_0).contents).offset(id as isize) as *mut uint8_t;
1204 *own_quantifier =
1205 quantifier_add(*own_quantifier as TSQuantifier, *quantifier as TSQuantifier) as uint8_t;
1206 id = id.wrapping_add(1);
1207 }
1208}
1209unsafe extern "C" fn capture_quantifiers_mul(
1210 mut self_0: *mut CaptureQuantifiers,
1211 mut quantifier: TSQuantifier,
1212) {
1213 let mut id: uint16_t = 0 as libc::c_int as uint16_t;
1214 while (id as libc::c_int) < (*self_0).size as uint16_t as libc::c_int {
1215 if (id as uint32_t) < (*self_0).size {
1216 } else {
1217 panic!();
1218 }
1219 let mut own_quantifier: *mut uint8_t =
1220 &mut *((*self_0).contents).offset(id as isize) as *mut uint8_t;
1221 *own_quantifier = quantifier_mul(*own_quantifier as TSQuantifier, quantifier) as uint8_t;
1222 id = id.wrapping_add(1);
1223 }
1224}
1225unsafe extern "C" fn capture_quantifiers_join_all(
1226 mut self_0: *mut CaptureQuantifiers,
1227 mut quantifiers: *mut CaptureQuantifiers,
1228) {
1229 if (*self_0).size < (*quantifiers).size {
1230 if !(((*quantifiers).size).wrapping_sub((*self_0).size) == 0 as libc::c_int as libc::c_uint)
1231 {
1232 _array__grow(
1233 self_0 as *mut Array,
1234 ((*quantifiers).size).wrapping_sub((*self_0).size),
1235 ::core::mem::size_of::<uint8_t>() as libc::c_ulong,
1236 );
1237 std::ptr::write_bytes(
1238 ((*self_0).contents).offset((*self_0).size as isize) as *mut libc::c_void,
1239 (0 as libc::c_int) as u8,
1240 ((((*quantifiers).size).wrapping_sub((*self_0).size) as libc::c_ulong)
1241 .wrapping_mul(::core::mem::size_of::<uint8_t>() as libc::c_ulong))
1242 as usize,
1243 );
1244 (*self_0).size = ((*self_0).size as libc::c_uint)
1245 .wrapping_add(((*quantifiers).size).wrapping_sub((*self_0).size))
1246 as uint32_t as uint32_t;
1247 }
1248 }
1249 let mut id: uint32_t = 0 as libc::c_int as uint32_t;
1250 while id < (*quantifiers).size {
1251 if id < (*quantifiers).size {
1252 } else {
1253 panic!();
1254 }
1255 let mut quantifier: *mut uint8_t =
1256 &mut *((*quantifiers).contents).offset(id as isize) as *mut uint8_t;
1257 if id < (*self_0).size {
1258 } else {
1259 panic!();
1260 }
1261 let mut own_quantifier: *mut uint8_t =
1262 &mut *((*self_0).contents).offset(id as isize) as *mut uint8_t;
1263 *own_quantifier =
1264 quantifier_join(*own_quantifier as TSQuantifier, *quantifier as TSQuantifier)
1265 as uint8_t;
1266 id = id.wrapping_add(1);
1267 }
1268 let mut id_0: uint32_t = (*quantifiers).size;
1269 while id_0 < (*self_0).size {
1270 if id_0 < (*self_0).size {
1271 } else {
1272 panic!();
1273 }
1274 let mut own_quantifier_0: *mut uint8_t =
1275 &mut *((*self_0).contents).offset(id_0 as isize) as *mut uint8_t;
1276 *own_quantifier_0 =
1277 quantifier_join(*own_quantifier_0 as TSQuantifier, TSQuantifierZero) as uint8_t;
1278 id_0 = id_0.wrapping_add(1);
1279 }
1280}
1281unsafe extern "C" fn symbol_table_new() -> SymbolTable {
1282 return {
1283 let mut init = SymbolTable {
1284 characters: {
1285 let mut init = C2RustUnnamed_13 {
1286 contents: 0 as *mut libc::c_char,
1287 size: 0 as libc::c_int as uint32_t,
1288 capacity: 0 as libc::c_int as uint32_t,
1289 };
1290 init
1291 },
1292 slices: {
1293 let mut init = C2RustUnnamed_12 {
1294 contents: 0 as *mut Slice,
1295 size: 0 as libc::c_int as uint32_t,
1296 capacity: 0 as libc::c_int as uint32_t,
1297 };
1298 init
1299 },
1300 };
1301 init
1302 };
1303}
1304unsafe extern "C" fn symbol_table_delete(mut self_0: *mut SymbolTable) {
1305 _array__delete(&mut (*self_0).characters as *mut C2RustUnnamed_13 as *mut Array);
1306 _array__delete(&mut (*self_0).slices as *mut C2RustUnnamed_12 as *mut Array);
1307}
1308unsafe extern "C" fn symbol_table_id_for_name(
1309 mut self_0: *const SymbolTable,
1310 mut name: *const libc::c_char,
1311 mut length: uint32_t,
1312) -> libc::c_int {
1313 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1314 while i < (*self_0).slices.size {
1315 let mut slice: Slice = *((*self_0).slices.contents).offset(i as isize);
1316 if slice.length == length
1317 && strncmp(
1318 &mut *((*self_0).characters.contents).offset(slice.offset as isize),
1319 name,
1320 length as libc::c_ulong,
1321 ) == 0
1322 {
1323 return i as libc::c_int;
1324 }
1325 i = i.wrapping_add(1);
1326 }
1327 return -(1 as libc::c_int);
1328}
1329unsafe extern "C" fn symbol_table_name_for_id(
1330 mut self_0: *const SymbolTable,
1331 mut id: uint16_t,
1332 mut length: *mut uint32_t,
1333) -> *const libc::c_char {
1334 let mut slice: Slice = *((*self_0).slices.contents).offset(id as isize);
1335 *length = slice.length;
1336 return &mut *((*self_0).characters.contents).offset(slice.offset as isize)
1337 as *mut libc::c_char;
1338}
1339unsafe extern "C" fn symbol_table_insert_name(
1340 mut self_0: *mut SymbolTable,
1341 mut name: *const libc::c_char,
1342 mut length: uint32_t,
1343) -> uint16_t {
1344 let mut id: libc::c_int = symbol_table_id_for_name(self_0, name, length);
1345 if id >= 0 as libc::c_int {
1346 return id as uint16_t;
1347 }
1348 let mut slice: Slice = {
1349 let mut init = Slice {
1350 offset: (*self_0).characters.size,
1351 length: length,
1352 };
1353 init
1354 };
1355 if !(length.wrapping_add(1 as libc::c_int as libc::c_uint) == 0 as libc::c_int as libc::c_uint)
1356 {
1357 _array__grow(
1358 &mut (*self_0).characters as *mut C2RustUnnamed_13 as *mut Array,
1359 length.wrapping_add(1 as libc::c_int as libc::c_uint),
1360 ::core::mem::size_of::<libc::c_char>() as libc::c_ulong,
1361 );
1362 std::ptr::write_bytes(
1363 ((*self_0).characters.contents).offset((*self_0).characters.size as isize)
1364 as *mut libc::c_void,
1365 (0 as libc::c_int) as u8,
1366 ((length.wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong)
1367 .wrapping_mul(::core::mem::size_of::<libc::c_char>() as libc::c_ulong))
1368 as usize,
1369 );
1370 (*self_0).characters.size = ((*self_0).characters.size as libc::c_uint)
1371 .wrapping_add(length.wrapping_add(1 as libc::c_int as libc::c_uint))
1372 as uint32_t as uint32_t;
1373 }
1374 std::ptr::copy_nonoverlapping(
1375 name as *const libc::c_void,
1376 &mut *((*self_0).characters.contents).offset(slice.offset as isize) as *mut libc::c_char
1377 as *mut libc::c_void,
1378 length as libc::c_ulong,
1379 );
1380 *((*self_0).characters.contents).offset(
1381 ((*self_0).characters.size).wrapping_sub(1 as libc::c_int as libc::c_uint) as isize,
1382 ) = 0 as libc::c_int as libc::c_char;
1383 _array__grow(
1384 &mut (*self_0).slices as *mut C2RustUnnamed_12 as *mut Array,
1385 1 as libc::c_int as uint32_t,
1386 ::core::mem::size_of::<Slice>() as libc::c_ulong,
1387 );
1388 let fresh6 = (*self_0).slices.size;
1389 (*self_0).slices.size = ((*self_0).slices.size).wrapping_add(1);
1390 *((*self_0).slices.contents).offset(fresh6 as isize) = slice;
1391 return ((*self_0).slices.size).wrapping_sub(1 as libc::c_int as libc::c_uint) as uint16_t;
1392}
1393unsafe extern "C" fn query_step__new(
1394 mut symbol: TSSymbol,
1395 mut depth: uint16_t,
1396 mut is_immediate: bool,
1397) -> QueryStep {
1398 let mut step: QueryStep = {
1399 let mut init = QueryStep { is_named_is_immediate_is_last_child_is_pass_through_is_dead_end_alternative_is_immediate_contains_captures_root_pattern_guaranteed_parent_pattern_guaranteed : [0 ; 2] , symbol : symbol , supertype_symbol : 0 , field : 0 as libc :: c_int as TSFieldId , capture_ids : [0 ; 3] , depth : depth , alternative_index : NONE , negated_field_list_id : 0 as libc :: c_int as uint16_t , } ;
1400 init.set_is_named(0 as libc::c_int != 0);
1401 init.set_is_immediate(is_immediate);
1402 init.set_is_last_child(0 as libc::c_int != 0);
1403 init.set_is_pass_through(0 as libc::c_int != 0);
1404 init.set_is_dead_end(0 as libc::c_int != 0);
1405 init.set_alternative_is_immediate(0 as libc::c_int != 0);
1406 init.set_contains_captures(0 as libc::c_int != 0);
1407 init.set_root_pattern_guaranteed(0 as libc::c_int != 0);
1408 init.set_parent_pattern_guaranteed(false);
1409 init
1410 };
1411 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1412 while i < 3 as libc::c_int as libc::c_uint {
1413 step.capture_ids[i as usize] = NONE;
1414 i = i.wrapping_add(1);
1415 }
1416 return step;
1417}
1418unsafe extern "C" fn query_step__add_capture(mut self_0: *mut QueryStep, mut capture_id: uint16_t) {
1419 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1420 while i < 3 as libc::c_int as libc::c_uint {
1421 if (*self_0).capture_ids[i as usize] as libc::c_int == NONE as libc::c_int {
1422 (*self_0).capture_ids[i as usize] = capture_id;
1423 break;
1424 } else {
1425 i = i.wrapping_add(1);
1426 }
1427 }
1428}
1429unsafe extern "C" fn query_step__remove_capture(
1430 mut self_0: *mut QueryStep,
1431 mut capture_id: uint16_t,
1432) {
1433 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1434 while i < 3 as libc::c_int as libc::c_uint {
1435 if (*self_0).capture_ids[i as usize] as libc::c_int == capture_id as libc::c_int {
1436 (*self_0).capture_ids[i as usize] = NONE;
1437 while i.wrapping_add(1 as libc::c_int as libc::c_uint)
1438 < 3 as libc::c_int as libc::c_uint
1439 {
1440 if (*self_0).capture_ids[i.wrapping_add(1 as libc::c_int as libc::c_uint) as usize]
1441 as libc::c_int
1442 == NONE as libc::c_int
1443 {
1444 break;
1445 }
1446 (*self_0).capture_ids[i as usize] = (*self_0).capture_ids
1447 [i.wrapping_add(1 as libc::c_int as libc::c_uint) as usize];
1448 (*self_0).capture_ids[i.wrapping_add(1 as libc::c_int as libc::c_uint) as usize] =
1449 NONE;
1450 i = i.wrapping_add(1);
1451 }
1452 break;
1453 } else {
1454 i = i.wrapping_add(1);
1455 }
1456 }
1457}
1458#[inline]
1459unsafe extern "C" fn state_predecessor_map_new(
1460 mut language: *const TSLanguage,
1461) -> StatePredecessorMap {
1462 return {
1463 let mut init = StatePredecessorMap {
1464 contents: crate::core_transpiled::alloc::ts_calloc(
1465 ((*language).state_count as size_t)
1466 .wrapping_mul((256 as libc::c_int + 1 as libc::c_int) as libc::c_ulong),
1467 ::core::mem::size_of::<TSStateId>() as libc::c_ulong,
1468 ) as *mut TSStateId,
1469 };
1470 init
1471 };
1472}
1473#[inline]
1474unsafe extern "C" fn state_predecessor_map_delete(mut self_0: *mut StatePredecessorMap) {
1475 crate::core_transpiled::alloc::ts_free((*self_0).contents as *mut libc::c_void);
1476}
1477#[inline]
1478unsafe extern "C" fn state_predecessor_map_add(
1479 mut self_0: *mut StatePredecessorMap,
1480 mut state: TSStateId,
1481 mut predecessor: TSStateId,
1482) {
1483 let mut index: size_t =
1484 (state as size_t).wrapping_mul((256 as libc::c_int + 1 as libc::c_int) as libc::c_ulong);
1485 let mut count: *mut TSStateId =
1486 &mut *((*self_0).contents).offset(index as isize) as *mut TSStateId;
1487 if *count as libc::c_int == 0 as libc::c_int
1488 || (*count as libc::c_int) < 256 as libc::c_int
1489 && *((*self_0).contents).offset(index.wrapping_add(*count as libc::c_ulong) as isize)
1490 as libc::c_int
1491 != predecessor as libc::c_int
1492 {
1493 *count = (*count).wrapping_add(1);
1494 *((*self_0).contents).offset(index.wrapping_add(*count as libc::c_ulong) as isize) =
1495 predecessor;
1496 }
1497}
1498#[inline]
1499unsafe extern "C" fn state_predecessor_map_get(
1500 mut self_0: *const StatePredecessorMap,
1501 mut state: TSStateId,
1502 mut count: *mut libc::c_uint,
1503) -> *const TSStateId {
1504 let mut index: size_t =
1505 (state as size_t).wrapping_mul((256 as libc::c_int + 1 as libc::c_int) as libc::c_ulong);
1506 *count = *((*self_0).contents).offset(index as isize) as libc::c_uint;
1507 return &mut *((*self_0).contents)
1508 .offset(index.wrapping_add(1 as libc::c_int as libc::c_ulong) as isize)
1509 as *mut TSStateId;
1510}
1511unsafe extern "C" fn analysis_state__recursion_depth(
1512 mut self_0: *const AnalysisState,
1513) -> libc::c_uint {
1514 let mut result: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1515 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1516 while i < (*self_0).depth as libc::c_uint {
1517 let mut symbol: TSSymbol = (*self_0).stack[i as usize].parent_symbol;
1518 let mut j: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1519 while j < i {
1520 if (*self_0).stack[j as usize].parent_symbol as libc::c_int == symbol as libc::c_int {
1521 result = result.wrapping_add(1);
1522 break;
1523 } else {
1524 j = j.wrapping_add(1);
1525 }
1526 }
1527 i = i.wrapping_add(1);
1528 }
1529 return result;
1530}
1531#[inline]
1532unsafe extern "C" fn analysis_state__compare_position(
1533 mut self_0: *const *mut AnalysisState,
1534 mut other: *const *mut AnalysisState,
1535) -> libc::c_int {
1536 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1537 while i < (**self_0).depth as libc::c_uint {
1538 if i >= (**other).depth as libc::c_uint {
1539 return -(1 as libc::c_int);
1540 }
1541 if ((**self_0).stack[i as usize].child_index as libc::c_int)
1542 < (**other).stack[i as usize].child_index as libc::c_int
1543 {
1544 return -(1 as libc::c_int);
1545 }
1546 if (**self_0).stack[i as usize].child_index as libc::c_int
1547 > (**other).stack[i as usize].child_index as libc::c_int
1548 {
1549 return 1 as libc::c_int;
1550 }
1551 i = i.wrapping_add(1);
1552 }
1553 if ((**self_0).depth as libc::c_int) < (**other).depth as libc::c_int {
1554 return 1 as libc::c_int;
1555 }
1556 if ((**self_0).step_index as libc::c_int) < (**other).step_index as libc::c_int {
1557 return -(1 as libc::c_int);
1558 }
1559 if (**self_0).step_index as libc::c_int > (**other).step_index as libc::c_int {
1560 return 1 as libc::c_int;
1561 }
1562 return 0 as libc::c_int;
1563}
1564#[inline]
1565unsafe extern "C" fn analysis_state__compare(
1566 mut self_0: *const *mut AnalysisState,
1567 mut other: *const *mut AnalysisState,
1568) -> libc::c_int {
1569 let mut result: libc::c_int = analysis_state__compare_position(self_0, other);
1570 if result != 0 as libc::c_int {
1571 return result;
1572 }
1573 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1574 while i < (**self_0).depth as libc::c_uint {
1575 if ((**self_0).stack[i as usize].parent_symbol as libc::c_int)
1576 < (**other).stack[i as usize].parent_symbol as libc::c_int
1577 {
1578 return -(1 as libc::c_int);
1579 }
1580 if (**self_0).stack[i as usize].parent_symbol as libc::c_int
1581 > (**other).stack[i as usize].parent_symbol as libc::c_int
1582 {
1583 return 1 as libc::c_int;
1584 }
1585 if ((**self_0).stack[i as usize].parse_state as libc::c_int)
1586 < (**other).stack[i as usize].parse_state as libc::c_int
1587 {
1588 return -(1 as libc::c_int);
1589 }
1590 if (**self_0).stack[i as usize].parse_state as libc::c_int
1591 > (**other).stack[i as usize].parse_state as libc::c_int
1592 {
1593 return 1 as libc::c_int;
1594 }
1595 if (((**self_0).stack[i as usize]).field_id() as libc::c_int)
1596 < ((**other).stack[i as usize]).field_id() as libc::c_int
1597 {
1598 return -(1 as libc::c_int);
1599 }
1600 if ((**self_0).stack[i as usize]).field_id() as libc::c_int
1601 > ((**other).stack[i as usize]).field_id() as libc::c_int
1602 {
1603 return 1 as libc::c_int;
1604 }
1605 i = i.wrapping_add(1);
1606 }
1607 return 0 as libc::c_int;
1608}
1609#[inline]
1610unsafe extern "C" fn analysis_state__top(
1611 mut self_0: *mut AnalysisState,
1612) -> *mut AnalysisStateEntry {
1613 if (*self_0).depth as libc::c_int == 0 as libc::c_int {
1614 return &mut *((*self_0).stack)
1615 .as_mut_ptr()
1616 .offset(0 as libc::c_int as isize) as *mut AnalysisStateEntry;
1617 }
1618 return &mut *((*self_0).stack)
1619 .as_mut_ptr()
1620 .offset(((*self_0).depth as libc::c_int - 1 as libc::c_int) as isize)
1621 as *mut AnalysisStateEntry;
1622}
1623#[inline]
1624unsafe extern "C" fn analysis_state__has_supertype(
1625 mut self_0: *mut AnalysisState,
1626 mut symbol: TSSymbol,
1627) -> bool {
1628 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1629 while i < (*self_0).depth as libc::c_uint {
1630 if (*self_0).stack[i as usize].parent_symbol as libc::c_int == symbol as libc::c_int {
1631 return 1 as libc::c_int != 0;
1632 }
1633 i = i.wrapping_add(1);
1634 }
1635 return 0 as libc::c_int != 0;
1636}
1637#[inline]
1638unsafe extern "C" fn analysis_state_pool__clone_or_reuse(
1639 mut self_0: *mut AnalysisStateSet,
1640 mut borrowed_item: *mut AnalysisState,
1641) -> *mut AnalysisState {
1642 let mut new_item: *mut AnalysisState = 0 as *mut AnalysisState;
1643 if (*self_0).size != 0 {
1644 (*self_0).size = ((*self_0).size).wrapping_sub(1);
1645 new_item = *((*self_0).contents).offset((*self_0).size as isize);
1646 } else {
1647 new_item = crate::core_transpiled::alloc::ts_malloc(
1648 ::core::mem::size_of::<AnalysisState>() as libc::c_ulong
1649 ) as *mut AnalysisState;
1650 }
1651 *new_item = *borrowed_item;
1652 return new_item;
1653}
1654#[inline]
1655unsafe extern "C" fn analysis_state_set__insert_sorted(
1656 mut self_0: *mut AnalysisStateSet,
1657 mut pool: *mut AnalysisStateSet,
1658 mut borrowed_item: *mut AnalysisState,
1659) {
1660 let mut index: libc::c_uint = 0;
1661 let mut exists: libc::c_uint = 0;
1662 index = 0 as libc::c_int as libc::c_uint;
1663 exists = 0 as libc::c_int as libc::c_uint;
1664 let mut size: uint32_t = ((*self_0).size).wrapping_sub(index);
1665 if !(size == 0 as libc::c_int as libc::c_uint) {
1666 let mut comparison: libc::c_int = 0;
1667 while size > 1 as libc::c_int as libc::c_uint {
1668 let mut half_size: uint32_t = size.wrapping_div(2 as libc::c_int as libc::c_uint);
1669 let mut mid_index: uint32_t = index.wrapping_add(half_size);
1670 comparison = analysis_state__compare(
1671 &mut *((*self_0).contents).offset(mid_index as isize),
1672 &mut borrowed_item,
1673 );
1674 if comparison <= 0 as libc::c_int {
1675 index = mid_index;
1676 }
1677 size = (size as libc::c_uint).wrapping_sub(half_size) as uint32_t as uint32_t;
1678 }
1679 comparison = analysis_state__compare(
1680 &mut *((*self_0).contents).offset(index as isize),
1681 &mut borrowed_item,
1682 );
1683 if comparison == 0 as libc::c_int {
1684 exists = 1 as libc::c_int as libc::c_uint;
1685 } else if comparison < 0 as libc::c_int {
1686 index = index.wrapping_add(1 as libc::c_int as libc::c_uint);
1687 }
1688 }
1689 if exists == 0 {
1690 let mut new_item: *mut AnalysisState =
1691 analysis_state_pool__clone_or_reuse(pool, borrowed_item);
1692 _array__splice(
1693 self_0 as *mut Array,
1694 ::core::mem::size_of::<*mut AnalysisState>() as libc::c_ulong,
1695 index,
1696 0 as libc::c_int as uint32_t,
1697 1 as libc::c_int as uint32_t,
1698 &mut new_item as *mut *mut AnalysisState as *const libc::c_void,
1699 );
1700 }
1701}
1702#[inline]
1703unsafe extern "C" fn analysis_state_set__push(
1704 mut self_0: *mut AnalysisStateSet,
1705 mut pool: *mut AnalysisStateSet,
1706 mut borrowed_item: *mut AnalysisState,
1707) {
1708 let mut new_item: *mut AnalysisState = analysis_state_pool__clone_or_reuse(pool, borrowed_item);
1709 _array__grow(
1710 self_0 as *mut Array,
1711 1 as libc::c_int as uint32_t,
1712 ::core::mem::size_of::<*mut AnalysisState>() as libc::c_ulong,
1713 );
1714 let fresh7 = (*self_0).size;
1715 (*self_0).size = ((*self_0).size).wrapping_add(1);
1716 let ref mut fresh8 = *((*self_0).contents).offset(fresh7 as isize);
1717 *fresh8 = new_item;
1718}
1719#[inline]
1720unsafe extern "C" fn analysis_state_set__clear(
1721 mut self_0: *mut AnalysisStateSet,
1722 mut pool: *mut AnalysisStateSet,
1723) {
1724 _array__splice(
1725 pool as *mut Array,
1726 ::core::mem::size_of::<*mut AnalysisState>() as libc::c_ulong,
1727 (*pool).size,
1728 0 as libc::c_int as uint32_t,
1729 (*self_0).size,
1730 (*self_0).contents as *const libc::c_void,
1731 );
1732 (*self_0).size = 0 as libc::c_int as uint32_t;
1733}
1734#[inline]
1735unsafe extern "C" fn analysis_state_set__delete(mut self_0: *mut AnalysisStateSet) {
1736 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1737 while i < (*self_0).size {
1738 crate::core_transpiled::alloc::ts_free(
1739 *((*self_0).contents).offset(i as isize) as *mut libc::c_void
1740 );
1741 i = i.wrapping_add(1);
1742 }
1743 _array__delete(self_0 as *mut Array);
1744}
1745#[inline]
1746unsafe extern "C" fn query_analysis__new() -> QueryAnalysis {
1747 return {
1748 let mut init = QueryAnalysis {
1749 states: {
1750 let mut init = AnalysisStateSet {
1751 contents: 0 as *mut *mut AnalysisState,
1752 size: 0 as libc::c_int as uint32_t,
1753 capacity: 0 as libc::c_int as uint32_t,
1754 };
1755 init
1756 },
1757 next_states: {
1758 let mut init = AnalysisStateSet {
1759 contents: 0 as *mut *mut AnalysisState,
1760 size: 0 as libc::c_int as uint32_t,
1761 capacity: 0 as libc::c_int as uint32_t,
1762 };
1763 init
1764 },
1765 deeper_states: {
1766 let mut init = AnalysisStateSet {
1767 contents: 0 as *mut *mut AnalysisState,
1768 size: 0 as libc::c_int as uint32_t,
1769 capacity: 0 as libc::c_int as uint32_t,
1770 };
1771 init
1772 },
1773 state_pool: {
1774 let mut init = AnalysisStateSet {
1775 contents: 0 as *mut *mut AnalysisState,
1776 size: 0 as libc::c_int as uint32_t,
1777 capacity: 0 as libc::c_int as uint32_t,
1778 };
1779 init
1780 },
1781 final_step_indices: {
1782 let mut init = C2RustUnnamed_22 {
1783 contents: 0 as *mut uint16_t,
1784 size: 0 as libc::c_int as uint32_t,
1785 capacity: 0 as libc::c_int as uint32_t,
1786 };
1787 init
1788 },
1789 finished_parent_symbols: {
1790 let mut init = C2RustUnnamed_21 {
1791 contents: 0 as *mut TSSymbol,
1792 size: 0 as libc::c_int as uint32_t,
1793 capacity: 0 as libc::c_int as uint32_t,
1794 };
1795 init
1796 },
1797 did_abort: 0 as libc::c_int != 0,
1798 };
1799 init
1800 };
1801}
1802#[inline]
1803unsafe extern "C" fn query_analysis__delete(mut self_0: *mut QueryAnalysis) {
1804 analysis_state_set__delete(&mut (*self_0).states);
1805 analysis_state_set__delete(&mut (*self_0).next_states);
1806 analysis_state_set__delete(&mut (*self_0).deeper_states);
1807 analysis_state_set__delete(&mut (*self_0).state_pool);
1808 _array__delete(&mut (*self_0).final_step_indices as *mut C2RustUnnamed_22 as *mut Array);
1809 _array__delete(&mut (*self_0).finished_parent_symbols as *mut C2RustUnnamed_21 as *mut Array);
1810}
1811#[inline]
1812unsafe extern "C" fn analysis_subgraph_node__compare(
1813 mut self_0: *const AnalysisSubgraphNode,
1814 mut other: *const AnalysisSubgraphNode,
1815) -> libc::c_int {
1816 if ((*self_0).state as libc::c_int) < (*other).state as libc::c_int {
1817 return -(1 as libc::c_int);
1818 }
1819 if (*self_0).state as libc::c_int > (*other).state as libc::c_int {
1820 return 1 as libc::c_int;
1821 }
1822 if ((*self_0).child_index() as libc::c_int) < (*other).child_index() as libc::c_int {
1823 return -(1 as libc::c_int);
1824 }
1825 if (*self_0).child_index() as libc::c_int > (*other).child_index() as libc::c_int {
1826 return 1 as libc::c_int;
1827 }
1828 if ((*self_0).done() as libc::c_int) < (*other).done() as libc::c_int {
1829 return -(1 as libc::c_int);
1830 }
1831 if (*self_0).done() as libc::c_int > (*other).done() as libc::c_int {
1832 return 1 as libc::c_int;
1833 }
1834 if ((*self_0).production_id as libc::c_int) < (*other).production_id as libc::c_int {
1835 return -(1 as libc::c_int);
1836 }
1837 if (*self_0).production_id as libc::c_int > (*other).production_id as libc::c_int {
1838 return 1 as libc::c_int;
1839 }
1840 return 0 as libc::c_int;
1841}
1842#[inline]
1843unsafe extern "C" fn ts_query__pattern_map_search(
1844 mut self_0: *const TSQuery,
1845 mut needle: TSSymbol,
1846 mut result: *mut uint32_t,
1847) -> bool {
1848 let mut base_index: uint32_t = (*self_0).wildcard_root_pattern_count as uint32_t;
1849 let mut size: uint32_t = ((*self_0).pattern_map.size).wrapping_sub(base_index);
1850 if size == 0 as libc::c_int as libc::c_uint {
1851 *result = base_index;
1852 return 0 as libc::c_int != 0;
1853 }
1854 while size > 1 as libc::c_int as libc::c_uint {
1855 let mut half_size: uint32_t = size.wrapping_div(2 as libc::c_int as libc::c_uint);
1856 let mut mid_index: uint32_t = base_index.wrapping_add(half_size);
1857 let mut mid_symbol: TSSymbol = (*((*self_0).steps.contents).offset(
1858 (*((*self_0).pattern_map.contents).offset(mid_index as isize)).step_index as isize,
1859 ))
1860 .symbol;
1861 if needle as libc::c_int > mid_symbol as libc::c_int {
1862 base_index = mid_index;
1863 }
1864 size = (size as libc::c_uint).wrapping_sub(half_size) as uint32_t as uint32_t;
1865 }
1866 let mut symbol: TSSymbol = (*((*self_0).steps.contents).offset(
1867 (*((*self_0).pattern_map.contents).offset(base_index as isize)).step_index as isize,
1868 ))
1869 .symbol;
1870 if needle as libc::c_int > symbol as libc::c_int {
1871 base_index = base_index.wrapping_add(1);
1872 if base_index < (*self_0).pattern_map.size {
1873 symbol = (*((*self_0).steps.contents).offset(
1874 (*((*self_0).pattern_map.contents).offset(base_index as isize)).step_index as isize,
1875 ))
1876 .symbol;
1877 }
1878 }
1879 *result = base_index;
1880 return needle as libc::c_int == symbol as libc::c_int;
1881}
1882#[inline]
1883unsafe extern "C" fn ts_query__pattern_map_insert(
1884 mut self_0: *mut TSQuery,
1885 mut symbol: TSSymbol,
1886 mut new_entry: PatternEntry,
1887) {
1888 let mut index: uint32_t = 0;
1889 ts_query__pattern_map_search(self_0, symbol, &mut index);
1890 while index < (*self_0).pattern_map.size {
1891 let mut entry: *mut PatternEntry =
1892 &mut *((*self_0).pattern_map.contents).offset(index as isize) as *mut PatternEntry;
1893 if !((*((*self_0).steps.contents).offset((*entry).step_index as isize)).symbol
1894 as libc::c_int
1895 == symbol as libc::c_int
1896 && ((*entry).pattern_index as libc::c_int) < new_entry.pattern_index as libc::c_int)
1897 {
1898 break;
1899 }
1900 index = index.wrapping_add(1);
1901 }
1902 _array__splice(
1903 &mut (*self_0).pattern_map as *mut C2RustUnnamed_9 as *mut Array,
1904 ::core::mem::size_of::<PatternEntry>() as libc::c_ulong,
1905 index,
1906 0 as libc::c_int as uint32_t,
1907 1 as libc::c_int as uint32_t,
1908 &mut new_entry as *mut PatternEntry as *const libc::c_void,
1909 );
1910}
1911unsafe extern "C" fn ts_query__perform_analysis(
1912 mut self_0: *mut TSQuery,
1913 mut subgraphs: *const AnalysisSubgraphArray,
1914 mut analysis: *mut QueryAnalysis,
1915) {
1916 let mut recursion_depth_limit: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1917 let mut prev_final_step_count: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1918 (*analysis).final_step_indices.size = 0 as libc::c_int as uint32_t;
1919 (*analysis).finished_parent_symbols.size = 0 as libc::c_int as uint32_t;
1920 let mut iteration: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1921 loop {
1922 if iteration == 256 as libc::c_int as libc::c_uint {
1923 (*analysis).did_abort = 1 as libc::c_int != 0;
1924 break;
1925 } else {
1926 if (*analysis).states.size == 0 as libc::c_int as libc::c_uint {
1927 if !((*analysis).deeper_states.size > 0 as libc::c_int as libc::c_uint
1928 && (*analysis).final_step_indices.size > prev_final_step_count)
1929 {
1930 break;
1931 }
1932 prev_final_step_count = (*analysis).final_step_indices.size;
1933 recursion_depth_limit = recursion_depth_limit.wrapping_add(1);
1934 let mut _states: AnalysisStateSet = (*analysis).states;
1935 (*analysis).states = (*analysis).deeper_states;
1936 (*analysis).deeper_states = _states;
1937 } else {
1938 analysis_state_set__clear(
1939 &mut (*analysis).next_states,
1940 &mut (*analysis).state_pool,
1941 );
1942 let mut current_block_136: u64;
1943 let mut j: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1944 while j < (*analysis).states.size {
1945 let state: *mut AnalysisState =
1946 *((*analysis).states.contents).offset(j as isize);
1947 if (*analysis).next_states.size > 0 as libc::c_int as libc::c_uint {
1948 if ((*analysis).next_states.size)
1949 .wrapping_sub(1 as libc::c_int as libc::c_uint)
1950 < (*analysis).next_states.size
1951 {
1952 } else {
1953 panic!();
1954 }
1955 let mut comparison: libc::c_int = analysis_state__compare_position(
1956 &state,
1957 &mut *((*analysis).next_states.contents).offset(
1958 ((*analysis).next_states.size)
1959 .wrapping_sub(1 as libc::c_int as libc::c_uint)
1960 as isize,
1961 ),
1962 );
1963 if comparison == 0 as libc::c_int {
1964 analysis_state_set__insert_sorted(
1965 &mut (*analysis).next_states,
1966 &mut (*analysis).state_pool,
1967 state,
1968 );
1969 current_block_136 = 1841672684692190573;
1970 } else if comparison > 0 as libc::c_int {
1971 while j < (*analysis).states.size {
1972 analysis_state_set__push(
1973 &mut (*analysis).next_states,
1974 &mut (*analysis).state_pool,
1975 *((*analysis).states.contents).offset(j as isize),
1976 );
1977 j = j.wrapping_add(1);
1978 }
1979 break;
1980 } else {
1981 current_block_136 = 11042950489265723346;
1982 }
1983 } else {
1984 current_block_136 = 11042950489265723346;
1985 }
1986 match current_block_136 {
1987 11042950489265723346 => {
1988 let parse_state: TSStateId = (*analysis_state__top(state)).parse_state;
1989 let parent_symbol: TSSymbol =
1990 (*analysis_state__top(state)).parent_symbol;
1991 let parent_field_id: TSFieldId =
1992 (*analysis_state__top(state)).field_id();
1993 let child_index: libc::c_uint =
1994 (*analysis_state__top(state)).child_index as libc::c_uint;
1995 let step: *const QueryStep = &mut *((*self_0).steps.contents)
1996 .offset((*state).step_index as isize)
1997 as *mut QueryStep;
1998 let mut subgraph_index: libc::c_uint = 0;
1999 let mut exists: libc::c_uint = 0;
2000 subgraph_index = 0 as libc::c_int as libc::c_uint;
2001 exists = 0 as libc::c_int as libc::c_uint;
2002 let mut size: uint32_t =
2003 ((*subgraphs).size).wrapping_sub(subgraph_index);
2004 if !(size == 0 as libc::c_int as libc::c_uint) {
2005 let mut comparison_0: libc::c_int = 0;
2006 while size > 1 as libc::c_int as libc::c_uint {
2007 let mut half_size: uint32_t =
2008 size.wrapping_div(2 as libc::c_int as libc::c_uint);
2009 let mut mid_index: uint32_t =
2010 subgraph_index.wrapping_add(half_size);
2011 comparison_0 = (*((*subgraphs).contents)
2012 .offset(mid_index as isize))
2013 .symbol
2014 as libc::c_int
2015 - parent_symbol as libc::c_int;
2016 if comparison_0 <= 0 as libc::c_int {
2017 subgraph_index = mid_index;
2018 }
2019 size = (size as libc::c_uint).wrapping_sub(half_size)
2020 as uint32_t
2021 as uint32_t;
2022 }
2023 comparison_0 =
2024 (*((*subgraphs).contents).offset(subgraph_index as isize))
2025 .symbol as libc::c_int
2026 - parent_symbol as libc::c_int;
2027 if comparison_0 == 0 as libc::c_int {
2028 exists = 1 as libc::c_int as libc::c_uint;
2029 } else if comparison_0 < 0 as libc::c_int {
2030 subgraph_index = subgraph_index
2031 .wrapping_add(1 as libc::c_int as libc::c_uint);
2032 }
2033 }
2034 if !(exists == 0) {
2035 let mut subgraph: *const AnalysisSubgraph =
2036 &mut *((*subgraphs).contents).offset(subgraph_index as isize)
2037 as *mut AnalysisSubgraph;
2038 let mut lookahead_iterator: LookaheadIterator =
2039 ts_language_lookaheads((*self_0).language, parse_state);
2040 while ts_lookahead_iterator__next(&mut lookahead_iterator) {
2041 let mut sym: TSSymbol = lookahead_iterator.symbol;
2042 let mut successor: AnalysisSubgraphNode = {
2043 let mut init = AnalysisSubgraphNode {
2044 child_index_done: [0; 1],
2045 c2rust_padding: [0; 1],
2046 state: parse_state,
2047 production_id: 0,
2048 };
2049 init.set_child_index(child_index as uint8_t);
2050 init.set_done(false);
2051 init
2052 };
2053 if lookahead_iterator.action_count != 0 {
2054 let mut action: *const TSParseAction =
2055 &*(lookahead_iterator.actions).offset(
2056 (lookahead_iterator.action_count as libc::c_int
2057 - 1 as libc::c_int)
2058 as isize,
2059 )
2060 as *const TSParseAction;
2061 if !((*action).type_ as libc::c_int
2062 == TSParseActionTypeShift as libc::c_int)
2063 {
2064 continue;
2065 }
2066 if !(*action).shift.extra {
2067 successor.state = (*action).shift.state;
2068 successor.set_child_index(successor.child_index() + 1);
2069 }
2070 } else {
2071 if !(lookahead_iterator.next_state as libc::c_int
2072 != 0 as libc::c_int)
2073 {
2074 continue;
2075 }
2076 successor.state = lookahead_iterator.next_state;
2077 successor.set_child_index(successor.child_index() + 1);
2078 }
2079 let mut node_index: libc::c_uint = 0;
2080 node_index = 0 as libc::c_int as libc::c_uint;
2081 exists = 0 as libc::c_int as libc::c_uint;
2082 let mut size_0: uint32_t =
2083 ((*subgraph).nodes.size).wrapping_sub(node_index);
2084 if !(size_0 == 0 as libc::c_int as libc::c_uint) {
2085 let mut comparison_1: libc::c_int = 0;
2086 while size_0 > 1 as libc::c_int as libc::c_uint {
2087 let mut half_size_0: uint32_t = size_0
2088 .wrapping_div(2 as libc::c_int as libc::c_uint);
2089 let mut mid_index_0: uint32_t =
2090 node_index.wrapping_add(half_size_0);
2091 comparison_1 = analysis_subgraph_node__compare(
2092 &mut *((*subgraph).nodes.contents)
2093 .offset(mid_index_0 as isize),
2094 &mut successor,
2095 );
2096 if comparison_1 <= 0 as libc::c_int {
2097 node_index = mid_index_0;
2098 }
2099 size_0 = (size_0 as libc::c_uint)
2100 .wrapping_sub(half_size_0)
2101 as uint32_t
2102 as uint32_t;
2103 }
2104 comparison_1 = analysis_subgraph_node__compare(
2105 &mut *((*subgraph).nodes.contents)
2106 .offset(node_index as isize),
2107 &mut successor,
2108 );
2109 if comparison_1 == 0 as libc::c_int {
2110 exists = 1 as libc::c_int as libc::c_uint;
2111 } else if comparison_1 < 0 as libc::c_int {
2112 node_index = node_index
2113 .wrapping_add(1 as libc::c_int as libc::c_uint);
2114 }
2115 }
2116 while node_index < (*subgraph).nodes.size {
2117 let fresh9 = node_index;
2118 node_index = node_index.wrapping_add(1);
2119 let mut node: *mut AnalysisSubgraphNode =
2120 &mut *((*subgraph).nodes.contents)
2121 .offset(fresh9 as isize)
2122 as *mut AnalysisSubgraphNode;
2123 if (*node).state as libc::c_int
2124 != successor.state as libc::c_int
2125 || (*node).child_index() as libc::c_int
2126 != successor.child_index() as libc::c_int
2127 {
2128 break;
2129 }
2130 let mut alias: TSSymbol = ts_language_alias_at(
2131 (*self_0).language,
2132 (*node).production_id as uint32_t,
2133 child_index,
2134 );
2135 let mut visible_symbol: TSSymbol =
2136 (if alias as libc::c_int != 0 {
2137 alias as libc::c_int
2138 } else if (*((*(*self_0).language).symbol_metadata)
2139 .offset(sym as isize))
2140 .visible
2141 as libc::c_int
2142 != 0
2143 {
2144 *((*(*self_0).language).public_symbol_map)
2145 .offset(sym as isize)
2146 as libc::c_int
2147 } else {
2148 0 as libc::c_int
2149 })
2150 as TSSymbol;
2151 let mut field_id: TSFieldId = parent_field_id;
2152 if field_id == 0 {
2153 let mut field_map: *const TSFieldMapEntry =
2154 0 as *const TSFieldMapEntry;
2155 let mut field_map_end: *const TSFieldMapEntry =
2156 0 as *const TSFieldMapEntry;
2157 ts_language_field_map(
2158 (*self_0).language,
2159 (*node).production_id as uint32_t,
2160 &mut field_map,
2161 &mut field_map_end,
2162 );
2163 while field_map != field_map_end {
2164 if !(*field_map).inherited
2165 && (*field_map).child_index as libc::c_uint
2166 == child_index
2167 {
2168 field_id = (*field_map).field_id;
2169 break;
2170 } else {
2171 field_map = field_map.offset(1);
2172 }
2173 }
2174 }
2175 let mut next_state: AnalysisState = *state;
2176 let mut next_state_top: *mut AnalysisStateEntry =
2177 analysis_state__top(&mut next_state);
2178 (*next_state_top).child_index =
2179 successor.child_index() as uint16_t;
2180 (*next_state_top).parse_state = successor.state;
2181 if (*node).done() {
2182 (*next_state_top).set_done(1 as libc::c_int != 0);
2183 }
2184 let mut does_match: bool = 0 as libc::c_int != 0;
2185 if visible_symbol != 0 {
2186 does_match = 1 as libc::c_int != 0;
2187 if (*step).symbol as libc::c_int
2188 == WILDCARD_SYMBOL as libc::c_int
2189 {
2190 if (*step).is_named() as libc::c_int != 0
2191 && !(*((*(*self_0).language).symbol_metadata)
2192 .offset(visible_symbol as isize))
2193 .named
2194 {
2195 does_match = 0 as libc::c_int != 0;
2196 }
2197 } else if (*step).symbol as libc::c_int
2198 != visible_symbol as libc::c_int
2199 {
2200 does_match = 0 as libc::c_int != 0;
2201 }
2202 if (*step).field as libc::c_int != 0
2203 && (*step).field as libc::c_int
2204 != field_id as libc::c_int
2205 {
2206 does_match = 0 as libc::c_int != 0;
2207 }
2208 if (*step).supertype_symbol as libc::c_int != 0
2209 && !analysis_state__has_supertype(
2210 state,
2211 (*step).supertype_symbol,
2212 )
2213 {
2214 does_match = 0 as libc::c_int != 0;
2215 }
2216 } else if sym as libc::c_uint
2217 >= (*(*self_0).language).token_count
2218 {
2219 if !(*next_state_top).done() {
2220 if next_state.depth as libc::c_int
2221 + 1 as libc::c_int
2222 >= 8 as libc::c_int
2223 {
2224 (*analysis).did_abort = 1 as libc::c_int != 0;
2225 continue;
2226 } else {
2227 next_state.depth =
2228 (next_state.depth).wrapping_add(1);
2229 next_state_top =
2230 analysis_state__top(&mut next_state);
2231 }
2232 }
2233 *next_state_top = {
2234 let mut init = AnalysisStateEntry {
2235 field_id_done: [0; 2],
2236 parse_state: parse_state,
2237 parent_symbol: sym,
2238 child_index: 0 as libc::c_int as uint16_t,
2239 };
2240 init.set_field_id(field_id);
2241 init.set_done(0 as libc::c_int != 0);
2242 init
2243 };
2244 if analysis_state__recursion_depth(&mut next_state)
2245 > recursion_depth_limit
2246 {
2247 analysis_state_set__insert_sorted(
2248 &mut (*analysis).deeper_states,
2249 &mut (*analysis).state_pool,
2250 &mut next_state,
2251 );
2252 continue;
2253 }
2254 }
2255 while next_state.depth as libc::c_int > 0 as libc::c_int
2256 && (*next_state_top).done() as libc::c_int != 0
2257 {
2258 next_state.depth = (next_state.depth).wrapping_sub(1);
2259 next_state_top = analysis_state__top(&mut next_state);
2260 }
2261 let mut next_step: *const QueryStep = step;
2262 if does_match {
2263 loop {
2264 next_state.step_index =
2265 (next_state.step_index).wrapping_add(1);
2266 next_step = &mut *((*self_0).steps.contents)
2267 .offset(next_state.step_index as isize)
2268 as *mut QueryStep;
2269 if (*next_step).depth as libc::c_int
2270 == PATTERN_DONE_MARKER as libc::c_int
2271 || (*next_step).depth as libc::c_int
2272 <= (*step).depth as libc::c_int
2273 {
2274 break;
2275 }
2276 }
2277 } else if successor.state as libc::c_int
2278 == parse_state as libc::c_int
2279 {
2280 continue;
2281 }
2282 loop {
2283 if (*next_step).is_pass_through() {
2284 next_state.step_index =
2285 (next_state.step_index).wrapping_add(1);
2286 next_step = next_step.offset(1);
2287 } else {
2288 if !(*next_step).is_dead_end() {
2289 let mut did_finish_pattern: bool =
2290 (*((*self_0).steps.contents)
2291 .offset(next_state.step_index as isize))
2292 .depth
2293 as libc::c_int
2294 != (*step).depth as libc::c_int;
2295 if did_finish_pattern {
2296 let mut _index: libc::c_uint = 0;
2297 let mut _exists: libc::c_uint = 0;
2298 _index = 0 as libc::c_int as libc::c_uint;
2299 _exists = 0 as libc::c_int as libc::c_uint;
2300 let mut size_1: uint32_t = ((*analysis)
2301 .finished_parent_symbols
2302 .size)
2303 .wrapping_sub(_index);
2304 if !(size_1
2305 == 0 as libc::c_int as libc::c_uint)
2306 {
2307 let mut comparison_2: libc::c_int = 0;
2308 while size_1
2309 > 1 as libc::c_int as libc::c_uint
2310 {
2311 let mut half_size_1: uint32_t =
2312 size_1.wrapping_div(
2313 2 as libc::c_int
2314 as libc::c_uint,
2315 );
2316 let mut mid_index_1: uint32_t =
2317 _index
2318 .wrapping_add(half_size_1);
2319 comparison_2 = *((*analysis)
2320 .finished_parent_symbols
2321 .contents)
2322 .offset(mid_index_1 as isize)
2323 as libc::c_int
2324 - (*state).root_symbol
2325 as libc::c_int;
2326 if comparison_2 <= 0 as libc::c_int
2327 {
2328 _index = mid_index_1;
2329 }
2330 size_1 = (size_1 as libc::c_uint)
2331 .wrapping_sub(half_size_1)
2332 as uint32_t
2333 as uint32_t;
2334 }
2335 comparison_2 = *((*analysis)
2336 .finished_parent_symbols
2337 .contents)
2338 .offset(_index as isize)
2339 as libc::c_int
2340 - (*state).root_symbol
2341 as libc::c_int;
2342 if comparison_2 == 0 as libc::c_int {
2343 _exists = 1 as libc::c_int
2344 as libc::c_uint;
2345 } else if comparison_2
2346 < 0 as libc::c_int
2347 {
2348 _index = _index.wrapping_add(
2349 1 as libc::c_int
2350 as libc::c_uint,
2351 );
2352 }
2353 }
2354 if _exists == 0 {
2355 _array__splice(
2356 &mut (*analysis)
2357 .finished_parent_symbols
2358 as *mut C2RustUnnamed_21
2359 as *mut Array,
2360 ::core::mem::size_of::<TSSymbol>()
2361 as libc::c_ulong,
2362 _index,
2363 0 as libc::c_int as uint32_t,
2364 1 as libc::c_int as uint32_t,
2365 &mut (*state).root_symbol
2366 as *mut TSSymbol
2367 as *const libc::c_void,
2368 );
2369 }
2370 } else if next_state.depth as libc::c_int
2371 == 0 as libc::c_int
2372 {
2373 let mut _index_0: libc::c_uint = 0;
2374 let mut _exists_0: libc::c_uint = 0;
2375 _index_0 = 0 as libc::c_int as libc::c_uint;
2376 _exists_0 =
2377 0 as libc::c_int as libc::c_uint;
2378 let mut size_2: uint32_t =
2379 ((*analysis).final_step_indices.size)
2380 .wrapping_sub(_index_0);
2381 if !(size_2
2382 == 0 as libc::c_int as libc::c_uint)
2383 {
2384 let mut comparison_3: libc::c_int = 0;
2385 while size_2
2386 > 1 as libc::c_int as libc::c_uint
2387 {
2388 let mut half_size_2: uint32_t =
2389 size_2.wrapping_div(
2390 2 as libc::c_int
2391 as libc::c_uint,
2392 );
2393 let mut mid_index_2: uint32_t =
2394 _index_0
2395 .wrapping_add(half_size_2);
2396 comparison_3 = *((*analysis)
2397 .final_step_indices
2398 .contents)
2399 .offset(mid_index_2 as isize)
2400 as libc::c_int
2401 - next_state.step_index
2402 as libc::c_int;
2403 if comparison_3 <= 0 as libc::c_int
2404 {
2405 _index_0 = mid_index_2;
2406 }
2407 size_2 = (size_2 as libc::c_uint)
2408 .wrapping_sub(half_size_2)
2409 as uint32_t
2410 as uint32_t;
2411 }
2412 comparison_3 = *((*analysis)
2413 .final_step_indices
2414 .contents)
2415 .offset(_index_0 as isize)
2416 as libc::c_int
2417 - next_state.step_index
2418 as libc::c_int;
2419 if comparison_3 == 0 as libc::c_int {
2420 _exists_0 = 1 as libc::c_int
2421 as libc::c_uint;
2422 } else if comparison_3
2423 < 0 as libc::c_int
2424 {
2425 _index_0 = _index_0.wrapping_add(
2426 1 as libc::c_int
2427 as libc::c_uint,
2428 );
2429 }
2430 }
2431 if _exists_0 == 0 {
2432 _array__splice(
2433 &mut (*analysis).final_step_indices
2434 as *mut C2RustUnnamed_22
2435 as *mut Array,
2436 ::core::mem::size_of::<uint16_t>()
2437 as libc::c_ulong,
2438 _index_0,
2439 0 as libc::c_int as uint32_t,
2440 1 as libc::c_int as uint32_t,
2441 &mut next_state.step_index
2442 as *mut uint16_t
2443 as *const libc::c_void,
2444 );
2445 }
2446 } else {
2447 analysis_state_set__insert_sorted(
2448 &mut (*analysis).next_states,
2449 &mut (*analysis).state_pool,
2450 &mut next_state,
2451 );
2452 }
2453 }
2454 if !(does_match as libc::c_int != 0
2455 && (*next_step).alternative_index
2456 as libc::c_int
2457 != NONE as libc::c_int
2458 && (*next_step).alternative_index
2459 as libc::c_int
2460 > next_state.step_index as libc::c_int)
2461 {
2462 break;
2463 }
2464 next_state.step_index =
2465 (*next_step).alternative_index;
2466 next_step = &mut *((*self_0).steps.contents)
2467 .offset(next_state.step_index as isize)
2468 as *mut QueryStep;
2469 }
2470 }
2471 }
2472 }
2473 }
2474 }
2475 _ => {}
2476 }
2477 j = j.wrapping_add(1);
2478 }
2479 let mut _states_0: AnalysisStateSet = (*analysis).states;
2480 (*analysis).states = (*analysis).next_states;
2481 (*analysis).next_states = _states_0;
2482 }
2483 iteration = iteration.wrapping_add(1);
2484 }
2485 }
2486}
2487unsafe extern "C" fn ts_query__analyze_patterns(
2488 mut self_0: *mut TSQuery,
2489 mut error_offset: *mut libc::c_uint,
2490) -> bool {
2491 let mut non_rooted_pattern_start_steps: C2RustUnnamed_19 = {
2492 let mut init = C2RustUnnamed_19 {
2493 contents: 0 as *mut uint16_t,
2494 size: 0 as libc::c_int as uint32_t,
2495 capacity: 0 as libc::c_int as uint32_t,
2496 };
2497 init
2498 };
2499 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
2500 while i < (*self_0).pattern_map.size {
2501 let mut pattern: *mut PatternEntry =
2502 &mut *((*self_0).pattern_map.contents).offset(i as isize) as *mut PatternEntry;
2503 if !(*pattern).is_rooted {
2504 let mut step: *mut QueryStep = &mut *((*self_0).steps.contents)
2505 .offset((*pattern).step_index as isize)
2506 as *mut QueryStep;
2507 if (*step).symbol as libc::c_int != WILDCARD_SYMBOL as libc::c_int {
2508 _array__grow(
2509 &mut non_rooted_pattern_start_steps as *mut C2RustUnnamed_19 as *mut Array,
2510 1 as libc::c_int as uint32_t,
2511 ::core::mem::size_of::<uint16_t>() as libc::c_ulong,
2512 );
2513 let fresh10 = non_rooted_pattern_start_steps.size;
2514 non_rooted_pattern_start_steps.size =
2515 (non_rooted_pattern_start_steps.size).wrapping_add(1);
2516 *(non_rooted_pattern_start_steps.contents).offset(fresh10 as isize) = i as uint16_t;
2517 }
2518 }
2519 i = i.wrapping_add(1);
2520 }
2521 let mut parent_step_indices: C2RustUnnamed_18 = {
2522 let mut init = C2RustUnnamed_18 {
2523 contents: 0 as *mut uint32_t,
2524 size: 0 as libc::c_int as uint32_t,
2525 capacity: 0 as libc::c_int as uint32_t,
2526 };
2527 init
2528 };
2529 let mut i_0: libc::c_uint = 0 as libc::c_int as libc::c_uint;
2530 while i_0 < (*self_0).steps.size {
2531 let mut step_0: *mut QueryStep =
2532 &mut *((*self_0).steps.contents).offset(i_0 as isize) as *mut QueryStep;
2533 if (*step_0).depth as libc::c_int == PATTERN_DONE_MARKER as libc::c_int {
2534 (*step_0).set_parent_pattern_guaranteed(1 as libc::c_int != 0);
2535 (*step_0).set_root_pattern_guaranteed(1 as libc::c_int != 0);
2536 } else {
2537 let mut has_children: bool = 0 as libc::c_int != 0;
2538 let mut is_wildcard: bool =
2539 (*step_0).symbol as libc::c_int == WILDCARD_SYMBOL as libc::c_int;
2540 (*step_0).set_contains_captures(
2541 (*step_0).capture_ids[0 as libc::c_int as usize] as libc::c_int
2542 != NONE as libc::c_int,
2543 );
2544 let mut j: libc::c_uint = i_0.wrapping_add(1 as libc::c_int as libc::c_uint);
2545 while j < (*self_0).steps.size {
2546 let mut next_step: *mut QueryStep =
2547 &mut *((*self_0).steps.contents).offset(j as isize) as *mut QueryStep;
2548 if (*next_step).depth as libc::c_int == PATTERN_DONE_MARKER as libc::c_int
2549 || (*next_step).depth as libc::c_int <= (*step_0).depth as libc::c_int
2550 {
2551 break;
2552 }
2553 if (*next_step).capture_ids[0 as libc::c_int as usize] as libc::c_int
2554 != NONE as libc::c_int
2555 {
2556 (*step_0).set_contains_captures(1 as libc::c_int != 0);
2557 }
2558 if !is_wildcard {
2559 (*next_step).set_root_pattern_guaranteed(1 as libc::c_int != 0);
2560 (*next_step).set_parent_pattern_guaranteed(1 as libc::c_int != 0);
2561 }
2562 has_children = 1 as libc::c_int != 0;
2563 j = j.wrapping_add(1);
2564 }
2565 if has_children as libc::c_int != 0 && !is_wildcard {
2566 _array__grow(
2567 &mut parent_step_indices as *mut C2RustUnnamed_18 as *mut Array,
2568 1 as libc::c_int as uint32_t,
2569 ::core::mem::size_of::<uint32_t>() as libc::c_ulong,
2570 );
2571 let fresh11 = parent_step_indices.size;
2572 parent_step_indices.size = (parent_step_indices.size).wrapping_add(1);
2573 *(parent_step_indices.contents).offset(fresh11 as isize) = i_0;
2574 }
2575 }
2576 i_0 = i_0.wrapping_add(1);
2577 }
2578 let mut subgraphs: AnalysisSubgraphArray = {
2579 let mut init = AnalysisSubgraphArray {
2580 contents: 0 as *mut AnalysisSubgraph,
2581 size: 0 as libc::c_int as uint32_t,
2582 capacity: 0 as libc::c_int as uint32_t,
2583 };
2584 init
2585 };
2586 let mut i_1: libc::c_uint = 0 as libc::c_int as libc::c_uint;
2587 while i_1 < parent_step_indices.size {
2588 let mut parent_step_index: uint32_t = *(parent_step_indices.contents).offset(i_1 as isize);
2589 let mut parent_symbol: TSSymbol =
2590 (*((*self_0).steps.contents).offset(parent_step_index as isize)).symbol;
2591 let mut subgraph: AnalysisSubgraph = {
2592 let mut init = AnalysisSubgraph {
2593 symbol: parent_symbol,
2594 start_states: C2RustUnnamed_24 {
2595 contents: 0 as *mut TSStateId,
2596 size: 0,
2597 capacity: 0,
2598 },
2599 nodes: C2RustUnnamed_23 {
2600 contents: 0 as *mut AnalysisSubgraphNode,
2601 size: 0,
2602 capacity: 0,
2603 },
2604 };
2605 init
2606 };
2607 let mut _index: libc::c_uint = 0;
2608 let mut _exists: libc::c_uint = 0;
2609 _index = 0 as libc::c_int as libc::c_uint;
2610 _exists = 0 as libc::c_int as libc::c_uint;
2611 let mut size: uint32_t = (subgraphs.size).wrapping_sub(_index);
2612 if !(size == 0 as libc::c_int as libc::c_uint) {
2613 let mut comparison: libc::c_int = 0;
2614 while size > 1 as libc::c_int as libc::c_uint {
2615 let mut half_size: uint32_t = size.wrapping_div(2 as libc::c_int as libc::c_uint);
2616 let mut mid_index: uint32_t = _index.wrapping_add(half_size);
2617 comparison = (*(subgraphs.contents).offset(mid_index as isize)).symbol
2618 as libc::c_int
2619 - subgraph.symbol as libc::c_int;
2620 if comparison <= 0 as libc::c_int {
2621 _index = mid_index;
2622 }
2623 size = (size as libc::c_uint).wrapping_sub(half_size) as uint32_t as uint32_t;
2624 }
2625 comparison = (*(subgraphs.contents).offset(_index as isize)).symbol as libc::c_int
2626 - subgraph.symbol as libc::c_int;
2627 if comparison == 0 as libc::c_int {
2628 _exists = 1 as libc::c_int as libc::c_uint;
2629 } else if comparison < 0 as libc::c_int {
2630 _index = _index.wrapping_add(1 as libc::c_int as libc::c_uint);
2631 }
2632 }
2633 if _exists == 0 {
2634 _array__splice(
2635 &mut subgraphs as *mut AnalysisSubgraphArray as *mut Array,
2636 ::core::mem::size_of::<AnalysisSubgraph>() as libc::c_ulong,
2637 _index,
2638 0 as libc::c_int as uint32_t,
2639 1 as libc::c_int as uint32_t,
2640 &mut subgraph as *mut AnalysisSubgraph as *const libc::c_void,
2641 );
2642 }
2643 i_1 = i_1.wrapping_add(1);
2644 }
2645 let mut sym: TSSymbol = (*(*self_0).language).token_count as uint16_t;
2646 while (sym as libc::c_int) < (*(*self_0).language).symbol_count as uint16_t as libc::c_int {
2647 if !(ts_language_symbol_metadata((*self_0).language, sym)).visible {
2648 let mut subgraph_0: AnalysisSubgraph = {
2649 let mut init = AnalysisSubgraph {
2650 symbol: sym,
2651 start_states: C2RustUnnamed_24 {
2652 contents: 0 as *mut TSStateId,
2653 size: 0,
2654 capacity: 0,
2655 },
2656 nodes: C2RustUnnamed_23 {
2657 contents: 0 as *mut AnalysisSubgraphNode,
2658 size: 0,
2659 capacity: 0,
2660 },
2661 };
2662 init
2663 };
2664 let mut _index_0: libc::c_uint = 0;
2665 let mut _exists_0: libc::c_uint = 0;
2666 _index_0 = 0 as libc::c_int as libc::c_uint;
2667 _exists_0 = 0 as libc::c_int as libc::c_uint;
2668 let mut size_0: uint32_t = (subgraphs.size).wrapping_sub(_index_0);
2669 if !(size_0 == 0 as libc::c_int as libc::c_uint) {
2670 let mut comparison_0: libc::c_int = 0;
2671 while size_0 > 1 as libc::c_int as libc::c_uint {
2672 let mut half_size_0: uint32_t =
2673 size_0.wrapping_div(2 as libc::c_int as libc::c_uint);
2674 let mut mid_index_0: uint32_t = _index_0.wrapping_add(half_size_0);
2675 comparison_0 = (*(subgraphs.contents).offset(mid_index_0 as isize)).symbol
2676 as libc::c_int
2677 - subgraph_0.symbol as libc::c_int;
2678 if comparison_0 <= 0 as libc::c_int {
2679 _index_0 = mid_index_0;
2680 }
2681 size_0 =
2682 (size_0 as libc::c_uint).wrapping_sub(half_size_0) as uint32_t as uint32_t;
2683 }
2684 comparison_0 = (*(subgraphs.contents).offset(_index_0 as isize)).symbol
2685 as libc::c_int
2686 - subgraph_0.symbol as libc::c_int;
2687 if comparison_0 == 0 as libc::c_int {
2688 _exists_0 = 1 as libc::c_int as libc::c_uint;
2689 } else if comparison_0 < 0 as libc::c_int {
2690 _index_0 = _index_0.wrapping_add(1 as libc::c_int as libc::c_uint);
2691 }
2692 }
2693 if _exists_0 == 0 {
2694 _array__splice(
2695 &mut subgraphs as *mut AnalysisSubgraphArray as *mut Array,
2696 ::core::mem::size_of::<AnalysisSubgraph>() as libc::c_ulong,
2697 _index_0,
2698 0 as libc::c_int as uint32_t,
2699 1 as libc::c_int as uint32_t,
2700 &mut subgraph_0 as *mut AnalysisSubgraph as *const libc::c_void,
2701 );
2702 }
2703 }
2704 sym = sym.wrapping_add(1);
2705 }
2706 let mut predecessor_map: StatePredecessorMap = state_predecessor_map_new((*self_0).language);
2707 let mut state: TSStateId = 1 as libc::c_int as TSStateId;
2708 while (state as libc::c_int) < (*(*self_0).language).state_count as uint16_t as libc::c_int {
2709 let mut subgraph_index: libc::c_uint = 0;
2710 let mut exists: libc::c_uint = 0;
2711 let mut lookahead_iterator: LookaheadIterator =
2712 ts_language_lookaheads((*self_0).language, state);
2713 while ts_lookahead_iterator__next(&mut lookahead_iterator) {
2714 if lookahead_iterator.action_count != 0 {
2715 let mut i_2: libc::c_uint = 0 as libc::c_int as libc::c_uint;
2716 while i_2 < lookahead_iterator.action_count as libc::c_uint {
2717 let mut action: *const TSParseAction =
2718 &*(lookahead_iterator.actions).offset(i_2 as isize) as *const TSParseAction;
2719 if (*action).type_ as libc::c_int == TSParseActionTypeReduce as libc::c_int {
2720 let mut aliases: *const TSSymbol = 0 as *const TSSymbol;
2721 let mut aliases_end: *const TSSymbol = 0 as *const TSSymbol;
2722 ts_language_aliases_for_symbol(
2723 (*self_0).language,
2724 (*action).reduce.symbol,
2725 &mut aliases,
2726 &mut aliases_end,
2727 );
2728 let mut symbol: *const TSSymbol = aliases;
2729 while symbol < aliases_end {
2730 subgraph_index = 0 as libc::c_int as libc::c_uint;
2731 exists = 0 as libc::c_int as libc::c_uint;
2732 let mut size_1: uint32_t =
2733 (subgraphs.size).wrapping_sub(subgraph_index);
2734 if !(size_1 == 0 as libc::c_int as libc::c_uint) {
2735 let mut comparison_1: libc::c_int = 0;
2736 while size_1 > 1 as libc::c_int as libc::c_uint {
2737 let mut half_size_1: uint32_t =
2738 size_1.wrapping_div(2 as libc::c_int as libc::c_uint);
2739 let mut mid_index_1: uint32_t =
2740 subgraph_index.wrapping_add(half_size_1);
2741 comparison_1 =
2742 (*(subgraphs.contents).offset(mid_index_1 as isize)).symbol
2743 as libc::c_int
2744 - *symbol as libc::c_int;
2745 if comparison_1 <= 0 as libc::c_int {
2746 subgraph_index = mid_index_1;
2747 }
2748 size_1 = (size_1 as libc::c_uint).wrapping_sub(half_size_1)
2749 as uint32_t
2750 as uint32_t;
2751 }
2752 comparison_1 =
2753 (*(subgraphs.contents).offset(subgraph_index as isize)).symbol
2754 as libc::c_int
2755 - *symbol as libc::c_int;
2756 if comparison_1 == 0 as libc::c_int {
2757 exists = 1 as libc::c_int as libc::c_uint;
2758 } else if comparison_1 < 0 as libc::c_int {
2759 subgraph_index = subgraph_index
2760 .wrapping_add(1 as libc::c_int as libc::c_uint);
2761 }
2762 }
2763 if exists != 0 {
2764 let mut subgraph_1: *mut AnalysisSubgraph =
2765 &mut *(subgraphs.contents).offset(subgraph_index as isize)
2766 as *mut AnalysisSubgraph;
2767 if (*subgraph_1).nodes.size == 0 as libc::c_int as libc::c_uint || {
2768 if ((*subgraph_1).nodes.size)
2769 .wrapping_sub(1 as libc::c_int as libc::c_uint)
2770 < (*subgraph_1).nodes.size
2771 {
2772 } else {
2773 panic!();
2774 }
2775 (*(&mut *((*subgraph_1).nodes.contents).offset(
2776 ((*subgraph_1).nodes.size)
2777 .wrapping_sub(1 as libc::c_int as libc::c_uint)
2778 as isize,
2779 )
2780 as *mut AnalysisSubgraphNode))
2781 .state as libc::c_int
2782 != state as libc::c_int
2783 } {
2784 _array__grow(
2785 &mut (*subgraph_1).nodes as *mut C2RustUnnamed_23
2786 as *mut Array,
2787 1 as libc::c_int as uint32_t,
2788 ::core::mem::size_of::<AnalysisSubgraphNode>()
2789 as libc::c_ulong,
2790 );
2791 let fresh12 = (*subgraph_1).nodes.size;
2792 (*subgraph_1).nodes.size =
2793 ((*subgraph_1).nodes.size).wrapping_add(1);
2794 *((*subgraph_1).nodes.contents).offset(fresh12 as isize) = {
2795 let mut init = AnalysisSubgraphNode {
2796 child_index_done: [0; 1],
2797 c2rust_padding: [0; 1],
2798 state: state,
2799 production_id: (*action).reduce.production_id,
2800 };
2801 init.set_child_index((*action).reduce.child_count);
2802 init.set_done(1 as libc::c_int != 0);
2803 init
2804 };
2805 }
2806 }
2807 symbol = symbol.offset(1);
2808 }
2809 } else if (*action).type_ as libc::c_int
2810 == TSParseActionTypeShift as libc::c_int
2811 && !(*action).shift.extra
2812 {
2813 let mut next_state: TSStateId = (*action).shift.state;
2814 state_predecessor_map_add(&mut predecessor_map, next_state, state);
2815 }
2816 i_2 = i_2.wrapping_add(1);
2817 }
2818 } else if lookahead_iterator.next_state as libc::c_int != 0 as libc::c_int {
2819 if lookahead_iterator.next_state as libc::c_int != state as libc::c_int {
2820 state_predecessor_map_add(
2821 &mut predecessor_map,
2822 lookahead_iterator.next_state,
2823 state,
2824 );
2825 }
2826 if ts_language_state_is_primary((*self_0).language, state) {
2827 let mut aliases_0: *const TSSymbol = 0 as *const TSSymbol;
2828 let mut aliases_end_0: *const TSSymbol = 0 as *const TSSymbol;
2829 ts_language_aliases_for_symbol(
2830 (*self_0).language,
2831 lookahead_iterator.symbol,
2832 &mut aliases_0,
2833 &mut aliases_end_0,
2834 );
2835 let mut symbol_0: *const TSSymbol = aliases_0;
2836 while symbol_0 < aliases_end_0 {
2837 subgraph_index = 0 as libc::c_int as libc::c_uint;
2838 exists = 0 as libc::c_int as libc::c_uint;
2839 let mut size_2: uint32_t = (subgraphs.size).wrapping_sub(subgraph_index);
2840 if !(size_2 == 0 as libc::c_int as libc::c_uint) {
2841 let mut comparison_2: libc::c_int = 0;
2842 while size_2 > 1 as libc::c_int as libc::c_uint {
2843 let mut half_size_2: uint32_t =
2844 size_2.wrapping_div(2 as libc::c_int as libc::c_uint);
2845 let mut mid_index_2: uint32_t =
2846 subgraph_index.wrapping_add(half_size_2);
2847 comparison_2 = (*(subgraphs.contents).offset(mid_index_2 as isize))
2848 .symbol
2849 as libc::c_int
2850 - *symbol_0 as libc::c_int;
2851 if comparison_2 <= 0 as libc::c_int {
2852 subgraph_index = mid_index_2;
2853 }
2854 size_2 = (size_2 as libc::c_uint).wrapping_sub(half_size_2)
2855 as uint32_t
2856 as uint32_t;
2857 }
2858 comparison_2 = (*(subgraphs.contents).offset(subgraph_index as isize))
2859 .symbol as libc::c_int
2860 - *symbol_0 as libc::c_int;
2861 if comparison_2 == 0 as libc::c_int {
2862 exists = 1 as libc::c_int as libc::c_uint;
2863 } else if comparison_2 < 0 as libc::c_int {
2864 subgraph_index =
2865 subgraph_index.wrapping_add(1 as libc::c_int as libc::c_uint);
2866 }
2867 }
2868 if exists != 0 {
2869 let mut subgraph_2: *mut AnalysisSubgraph = &mut *(subgraphs.contents)
2870 .offset(subgraph_index as isize)
2871 as *mut AnalysisSubgraph;
2872 if (*subgraph_2).start_states.size == 0 as libc::c_int as libc::c_uint
2873 || {
2874 if ((*subgraph_2).start_states.size)
2875 .wrapping_sub(1 as libc::c_int as libc::c_uint)
2876 < (*subgraph_2).start_states.size
2877 {
2878 } else {
2879 panic!();
2880 }
2881 *(&mut *((*subgraph_2).start_states.contents).offset(
2882 ((*subgraph_2).start_states.size)
2883 .wrapping_sub(1 as libc::c_int as libc::c_uint)
2884 as isize,
2885 ) as *mut TSStateId)
2886 as libc::c_int
2887 != state as libc::c_int
2888 }
2889 {
2890 _array__grow(
2891 &mut (*subgraph_2).start_states as *mut C2RustUnnamed_24
2892 as *mut Array,
2893 1 as libc::c_int as uint32_t,
2894 ::core::mem::size_of::<TSStateId>() as libc::c_ulong,
2895 );
2896 let fresh13 = (*subgraph_2).start_states.size;
2897 (*subgraph_2).start_states.size =
2898 ((*subgraph_2).start_states.size).wrapping_add(1);
2899 *((*subgraph_2).start_states.contents).offset(fresh13 as isize) =
2900 state;
2901 }
2902 }
2903 symbol_0 = symbol_0.offset(1);
2904 }
2905 }
2906 }
2907 }
2908 state = state.wrapping_add(1);
2909 }
2910 let mut next_nodes: C2RustUnnamed_20 = {
2911 let mut init = C2RustUnnamed_20 {
2912 contents: 0 as *mut AnalysisSubgraphNode,
2913 size: 0 as libc::c_int as uint32_t,
2914 capacity: 0 as libc::c_int as uint32_t,
2915 };
2916 init
2917 };
2918 let mut i_3: libc::c_uint = 0 as libc::c_int as libc::c_uint;
2919 while i_3 < subgraphs.size {
2920 let mut subgraph_3: *mut AnalysisSubgraph =
2921 &mut *(subgraphs.contents).offset(i_3 as isize) as *mut AnalysisSubgraph;
2922 if (*subgraph_3).nodes.size == 0 as libc::c_int as libc::c_uint {
2923 _array__delete(&mut (*subgraph_3).start_states as *mut C2RustUnnamed_24 as *mut Array);
2924 _array__erase(
2925 &mut subgraphs as *mut AnalysisSubgraphArray as *mut Array,
2926 ::core::mem::size_of::<AnalysisSubgraph>() as libc::c_ulong,
2927 i_3,
2928 );
2929 i_3 = i_3.wrapping_sub(1);
2930 } else {
2931 _array__assign(
2932 &mut next_nodes as *mut C2RustUnnamed_20 as *mut Array,
2933 &mut (*subgraph_3).nodes as *mut C2RustUnnamed_23 as *const Array,
2934 ::core::mem::size_of::<AnalysisSubgraphNode>() as libc::c_ulong,
2935 );
2936 while next_nodes.size > 0 as libc::c_int as libc::c_uint {
2937 next_nodes.size = (next_nodes.size).wrapping_sub(1);
2938 let mut node: AnalysisSubgraphNode =
2939 *(next_nodes.contents).offset(next_nodes.size as isize);
2940 if node.child_index() as libc::c_int > 1 as libc::c_int {
2941 let mut predecessor_count: libc::c_uint = 0;
2942 let mut predecessors: *const TSStateId = state_predecessor_map_get(
2943 &mut predecessor_map,
2944 node.state,
2945 &mut predecessor_count,
2946 );
2947 let mut j_0: libc::c_uint = 0 as libc::c_int as libc::c_uint;
2948 while j_0 < predecessor_count {
2949 let mut predecessor_node: AnalysisSubgraphNode = {
2950 let mut init = AnalysisSubgraphNode {
2951 child_index_done: [0; 1],
2952 c2rust_padding: [0; 1],
2953 state: *predecessors.offset(j_0 as isize),
2954 production_id: node.production_id,
2955 };
2956 init.set_child_index(
2957 (node.child_index() as libc::c_int - 1 as libc::c_int) as uint8_t,
2958 );
2959 init.set_done(0 as libc::c_int != 0);
2960 init
2961 };
2962 let mut index: libc::c_uint = 0;
2963 let mut exists_0: libc::c_uint = 0;
2964 index = 0 as libc::c_int as libc::c_uint;
2965 exists_0 = 0 as libc::c_int as libc::c_uint;
2966 let mut size_3: uint32_t = ((*subgraph_3).nodes.size).wrapping_sub(index);
2967 if !(size_3 == 0 as libc::c_int as libc::c_uint) {
2968 let mut comparison_3: libc::c_int = 0;
2969 while size_3 > 1 as libc::c_int as libc::c_uint {
2970 let mut half_size_3: uint32_t =
2971 size_3.wrapping_div(2 as libc::c_int as libc::c_uint);
2972 let mut mid_index_3: uint32_t = index.wrapping_add(half_size_3);
2973 comparison_3 = analysis_subgraph_node__compare(
2974 &mut *((*subgraph_3).nodes.contents)
2975 .offset(mid_index_3 as isize),
2976 &mut predecessor_node,
2977 );
2978 if comparison_3 <= 0 as libc::c_int {
2979 index = mid_index_3;
2980 }
2981 size_3 = (size_3 as libc::c_uint).wrapping_sub(half_size_3)
2982 as uint32_t
2983 as uint32_t;
2984 }
2985 comparison_3 = analysis_subgraph_node__compare(
2986 &mut *((*subgraph_3).nodes.contents).offset(index as isize),
2987 &mut predecessor_node,
2988 );
2989 if comparison_3 == 0 as libc::c_int {
2990 exists_0 = 1 as libc::c_int as libc::c_uint;
2991 } else if comparison_3 < 0 as libc::c_int {
2992 index = index.wrapping_add(1 as libc::c_int as libc::c_uint);
2993 }
2994 }
2995 if exists_0 == 0 {
2996 _array__splice(
2997 &mut (*subgraph_3).nodes as *mut C2RustUnnamed_23 as *mut Array,
2998 ::core::mem::size_of::<AnalysisSubgraphNode>() as libc::c_ulong,
2999 index,
3000 0 as libc::c_int as uint32_t,
3001 1 as libc::c_int as uint32_t,
3002 &mut predecessor_node as *mut AnalysisSubgraphNode
3003 as *const libc::c_void,
3004 );
3005 _array__grow(
3006 &mut next_nodes as *mut C2RustUnnamed_20 as *mut Array,
3007 1 as libc::c_int as uint32_t,
3008 ::core::mem::size_of::<AnalysisSubgraphNode>() as libc::c_ulong,
3009 );
3010 let fresh14 = next_nodes.size;
3011 next_nodes.size = (next_nodes.size).wrapping_add(1);
3012 *(next_nodes.contents).offset(fresh14 as isize) = predecessor_node;
3013 }
3014 j_0 = j_0.wrapping_add(1);
3015 }
3016 }
3017 }
3018 }
3019 i_3 = i_3.wrapping_add(1);
3020 }
3021 let mut all_patterns_are_valid: bool = 1 as libc::c_int != 0;
3022 let mut analysis: QueryAnalysis = query_analysis__new();
3023 let mut i_4: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3024 while i_4 < parent_step_indices.size {
3025 let mut parent_step_index_0: uint16_t =
3026 *(parent_step_indices.contents).offset(i_4 as isize) as uint16_t;
3027 let mut parent_depth: uint16_t =
3028 (*((*self_0).steps.contents).offset(parent_step_index_0 as isize)).depth;
3029 let mut parent_symbol_0: TSSymbol =
3030 (*((*self_0).steps.contents).offset(parent_step_index_0 as isize)).symbol;
3031 if !(parent_symbol_0 as libc::c_int == -(1 as libc::c_int) as TSSymbol as libc::c_int) {
3032 let mut subgraph_index_0: libc::c_uint = 0;
3033 let mut exists_1: libc::c_uint = 0;
3034 subgraph_index_0 = 0 as libc::c_int as libc::c_uint;
3035 exists_1 = 0 as libc::c_int as libc::c_uint;
3036 let mut size_4: uint32_t = (subgraphs.size).wrapping_sub(subgraph_index_0);
3037 if !(size_4 == 0 as libc::c_int as libc::c_uint) {
3038 let mut comparison_4: libc::c_int = 0;
3039 while size_4 > 1 as libc::c_int as libc::c_uint {
3040 let mut half_size_4: uint32_t =
3041 size_4.wrapping_div(2 as libc::c_int as libc::c_uint);
3042 let mut mid_index_4: uint32_t = subgraph_index_0.wrapping_add(half_size_4);
3043 comparison_4 = (*(subgraphs.contents).offset(mid_index_4 as isize)).symbol
3044 as libc::c_int
3045 - parent_symbol_0 as libc::c_int;
3046 if comparison_4 <= 0 as libc::c_int {
3047 subgraph_index_0 = mid_index_4;
3048 }
3049 size_4 =
3050 (size_4 as libc::c_uint).wrapping_sub(half_size_4) as uint32_t as uint32_t;
3051 }
3052 comparison_4 = (*(subgraphs.contents).offset(subgraph_index_0 as isize)).symbol
3053 as libc::c_int
3054 - parent_symbol_0 as libc::c_int;
3055 if comparison_4 == 0 as libc::c_int {
3056 exists_1 = 1 as libc::c_int as libc::c_uint;
3057 } else if comparison_4 < 0 as libc::c_int {
3058 subgraph_index_0 =
3059 subgraph_index_0.wrapping_add(1 as libc::c_int as libc::c_uint);
3060 }
3061 }
3062 if exists_1 == 0 {
3063 let mut first_child_step_index: libc::c_uint =
3064 (parent_step_index_0 as libc::c_int + 1 as libc::c_int) as libc::c_uint;
3065 let mut j_1: uint32_t = 0;
3066 let mut child_exists: uint32_t = 0;
3067 j_1 = 0 as libc::c_int as uint32_t;
3068 child_exists = 0 as libc::c_int as uint32_t;
3069 let mut size_5: uint32_t = ((*self_0).step_offsets.size).wrapping_sub(j_1);
3070 if !(size_5 == 0 as libc::c_int as libc::c_uint) {
3071 let mut comparison_5: libc::c_int = 0;
3072 while size_5 > 1 as libc::c_int as libc::c_uint {
3073 let mut half_size_5: uint32_t =
3074 size_5.wrapping_div(2 as libc::c_int as libc::c_uint);
3075 let mut mid_index_5: uint32_t = j_1.wrapping_add(half_size_5);
3076 comparison_5 = (*((*self_0).step_offsets.contents)
3077 .offset(mid_index_5 as isize))
3078 .step_index as libc::c_int
3079 - first_child_step_index as libc::c_int;
3080 if comparison_5 <= 0 as libc::c_int {
3081 j_1 = mid_index_5;
3082 }
3083 size_5 = (size_5 as libc::c_uint).wrapping_sub(half_size_5) as uint32_t
3084 as uint32_t;
3085 }
3086 comparison_5 = (*((*self_0).step_offsets.contents).offset(j_1 as isize))
3087 .step_index as libc::c_int
3088 - first_child_step_index as libc::c_int;
3089 if comparison_5 == 0 as libc::c_int {
3090 child_exists = 1 as libc::c_int as uint32_t;
3091 } else if comparison_5 < 0 as libc::c_int {
3092 j_1 = (j_1 as libc::c_uint).wrapping_add(1 as libc::c_int as libc::c_uint)
3093 as uint32_t as uint32_t;
3094 }
3095 }
3096 if child_exists != 0 {
3097 } else {
3098 panic!();
3099 }
3100 *error_offset =
3101 (*((*self_0).step_offsets.contents).offset(j_1 as isize)).byte_offset;
3102 all_patterns_are_valid = 0 as libc::c_int != 0;
3103 break;
3104 } else {
3105 let mut subgraph_4: *mut AnalysisSubgraph = &mut *(subgraphs.contents)
3106 .offset(subgraph_index_0 as isize)
3107 as *mut AnalysisSubgraph;
3108 analysis_state_set__clear(&mut analysis.states, &mut analysis.state_pool);
3109 analysis_state_set__clear(&mut analysis.deeper_states, &mut analysis.state_pool);
3110 let mut j_2: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3111 while j_2 < (*subgraph_4).start_states.size {
3112 let mut parse_state: TSStateId =
3113 *((*subgraph_4).start_states.contents).offset(j_2 as isize);
3114 analysis_state_set__push(
3115 &mut analysis.states,
3116 &mut analysis.state_pool,
3117 &mut {
3118 let mut init = AnalysisState {
3119 stack: [
3120 {
3121 let mut init = AnalysisStateEntry {
3122 field_id_done: [0; 2],
3123 parse_state: parse_state,
3124 parent_symbol: parent_symbol_0,
3125 child_index: 0 as libc::c_int as uint16_t,
3126 };
3127 init.set_field_id(0 as libc::c_int as TSFieldId);
3128 init.set_done(0 as libc::c_int != 0);
3129 init
3130 },
3131 AnalysisStateEntry {
3132 parse_state: 0,
3133 parent_symbol: 0,
3134 child_index: 0,
3135 field_id_done: [0; 2],
3136 },
3137 AnalysisStateEntry {
3138 parse_state: 0,
3139 parent_symbol: 0,
3140 child_index: 0,
3141 field_id_done: [0; 2],
3142 },
3143 AnalysisStateEntry {
3144 parse_state: 0,
3145 parent_symbol: 0,
3146 child_index: 0,
3147 field_id_done: [0; 2],
3148 },
3149 AnalysisStateEntry {
3150 parse_state: 0,
3151 parent_symbol: 0,
3152 child_index: 0,
3153 field_id_done: [0; 2],
3154 },
3155 AnalysisStateEntry {
3156 parse_state: 0,
3157 parent_symbol: 0,
3158 child_index: 0,
3159 field_id_done: [0; 2],
3160 },
3161 AnalysisStateEntry {
3162 parse_state: 0,
3163 parent_symbol: 0,
3164 child_index: 0,
3165 field_id_done: [0; 2],
3166 },
3167 AnalysisStateEntry {
3168 parse_state: 0,
3169 parent_symbol: 0,
3170 child_index: 0,
3171 field_id_done: [0; 2],
3172 },
3173 ],
3174 depth: 1 as libc::c_int as uint16_t,
3175 step_index: (parent_step_index_0 as libc::c_int + 1 as libc::c_int)
3176 as uint16_t,
3177 root_symbol: parent_symbol_0,
3178 };
3179 init
3180 },
3181 );
3182 j_2 = j_2.wrapping_add(1);
3183 }
3184 analysis.did_abort = 0 as libc::c_int != 0;
3185 ts_query__perform_analysis(self_0, &mut subgraphs, &mut analysis);
3186 if analysis.did_abort {
3187 let mut j_3: libc::c_uint =
3188 (parent_step_index_0 as libc::c_int + 1 as libc::c_int) as libc::c_uint;
3189 while j_3 < (*self_0).steps.size {
3190 let mut step_1: *mut QueryStep =
3191 &mut *((*self_0).steps.contents).offset(j_3 as isize) as *mut QueryStep;
3192 if (*step_1).depth as libc::c_int <= parent_depth as libc::c_int
3193 || (*step_1).depth as libc::c_int == PATTERN_DONE_MARKER as libc::c_int
3194 {
3195 break;
3196 }
3197 if !(*step_1).is_dead_end() {
3198 (*step_1).set_parent_pattern_guaranteed(0 as libc::c_int != 0);
3199 (*step_1).set_root_pattern_guaranteed(0 as libc::c_int != 0);
3200 }
3201 j_3 = j_3.wrapping_add(1);
3202 }
3203 } else if analysis.finished_parent_symbols.size == 0 as libc::c_int as libc::c_uint
3204 {
3205 if analysis.final_step_indices.size > 0 as libc::c_int as libc::c_uint {
3206 } else {
3207 panic!();
3208 }
3209 if (analysis.final_step_indices.size)
3210 .wrapping_sub(1 as libc::c_int as libc::c_uint)
3211 < analysis.final_step_indices.size
3212 {
3213 } else {
3214 panic!();
3215 }
3216 let mut impossible_step_index: uint16_t =
3217 *(&mut *(analysis.final_step_indices.contents).offset(
3218 (analysis.final_step_indices.size)
3219 .wrapping_sub(1 as libc::c_int as libc::c_uint)
3220 as isize,
3221 ) as *mut uint16_t);
3222 let mut j_4: uint32_t = 0;
3223 let mut impossible_exists: uint32_t = 0;
3224 j_4 = 0 as libc::c_int as uint32_t;
3225 impossible_exists = 0 as libc::c_int as uint32_t;
3226 let mut size_6: uint32_t = ((*self_0).step_offsets.size).wrapping_sub(j_4);
3227 if !(size_6 == 0 as libc::c_int as libc::c_uint) {
3228 let mut comparison_6: libc::c_int = 0;
3229 while size_6 > 1 as libc::c_int as libc::c_uint {
3230 let mut half_size_6: uint32_t =
3231 size_6.wrapping_div(2 as libc::c_int as libc::c_uint);
3232 let mut mid_index_6: uint32_t = j_4.wrapping_add(half_size_6);
3233 comparison_6 = (*((*self_0).step_offsets.contents)
3234 .offset(mid_index_6 as isize))
3235 .step_index as libc::c_int
3236 - impossible_step_index as libc::c_int;
3237 if comparison_6 <= 0 as libc::c_int {
3238 j_4 = mid_index_6;
3239 }
3240 size_6 = (size_6 as libc::c_uint).wrapping_sub(half_size_6) as uint32_t
3241 as uint32_t;
3242 }
3243 comparison_6 = (*((*self_0).step_offsets.contents).offset(j_4 as isize))
3244 .step_index as libc::c_int
3245 - impossible_step_index as libc::c_int;
3246 if comparison_6 == 0 as libc::c_int {
3247 impossible_exists = 1 as libc::c_int as uint32_t;
3248 } else if comparison_6 < 0 as libc::c_int {
3249 j_4 = (j_4 as libc::c_uint)
3250 .wrapping_add(1 as libc::c_int as libc::c_uint)
3251 as uint32_t as uint32_t;
3252 }
3253 }
3254 if j_4 >= (*self_0).step_offsets.size {
3255 j_4 = ((*self_0).step_offsets.size)
3256 .wrapping_sub(1 as libc::c_int as libc::c_uint);
3257 }
3258 *error_offset =
3259 (*((*self_0).step_offsets.contents).offset(j_4 as isize)).byte_offset;
3260 all_patterns_are_valid = 0 as libc::c_int != 0;
3261 break;
3262 } else {
3263 let mut j_5: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3264 while j_5 < analysis.final_step_indices.size {
3265 let mut final_step_index: uint32_t = *(analysis.final_step_indices.contents)
3266 .offset(j_5 as isize)
3267 as uint32_t;
3268 let mut step_2: *mut QueryStep = &mut *((*self_0).steps.contents)
3269 .offset(final_step_index as isize)
3270 as *mut QueryStep;
3271 if (*step_2).depth as libc::c_int != PATTERN_DONE_MARKER as libc::c_int
3272 && (*step_2).depth as libc::c_int > parent_depth as libc::c_int
3273 && !(*step_2).is_dead_end()
3274 {
3275 (*step_2).set_parent_pattern_guaranteed(0 as libc::c_int != 0);
3276 (*step_2).set_root_pattern_guaranteed(0 as libc::c_int != 0);
3277 }
3278 j_5 = j_5.wrapping_add(1);
3279 }
3280 }
3281 }
3282 }
3283 i_4 = i_4.wrapping_add(1);
3284 }
3285 let mut predicate_capture_ids: C2RustUnnamed_17 = {
3286 let mut init = C2RustUnnamed_17 {
3287 contents: 0 as *mut uint16_t,
3288 size: 0 as libc::c_int as uint32_t,
3289 capacity: 0 as libc::c_int as uint32_t,
3290 };
3291 init
3292 };
3293 let mut i_5: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3294 while i_5 < (*self_0).patterns.size {
3295 let mut pattern_0: *mut QueryPattern =
3296 &mut *((*self_0).patterns.contents).offset(i_5 as isize) as *mut QueryPattern;
3297 predicate_capture_ids.size = 0 as libc::c_int as uint32_t;
3298 let mut start: libc::c_uint = (*pattern_0).predicate_steps.offset;
3299 let mut end: libc::c_uint = start.wrapping_add((*pattern_0).predicate_steps.length);
3300 let mut j_6: libc::c_uint = start;
3301 while j_6 < end {
3302 let mut step_3: *mut TSQueryPredicateStep = &mut *((*self_0).predicate_steps.contents)
3303 .offset(j_6 as isize)
3304 as *mut TSQueryPredicateStep;
3305 if (*step_3).type_ as libc::c_uint
3306 == TSQueryPredicateStepTypeCapture as libc::c_int as libc::c_uint
3307 {
3308 let mut value_id: uint16_t = (*step_3).value_id as uint16_t;
3309 let mut _index_1: libc::c_uint = 0;
3310 let mut _exists_1: libc::c_uint = 0;
3311 _index_1 = 0 as libc::c_int as libc::c_uint;
3312 _exists_1 = 0 as libc::c_int as libc::c_uint;
3313 let mut size_7: uint32_t = (predicate_capture_ids.size).wrapping_sub(_index_1);
3314 if !(size_7 == 0 as libc::c_int as libc::c_uint) {
3315 let mut comparison_7: libc::c_int = 0;
3316 while size_7 > 1 as libc::c_int as libc::c_uint {
3317 let mut half_size_7: uint32_t =
3318 size_7.wrapping_div(2 as libc::c_int as libc::c_uint);
3319 let mut mid_index_7: uint32_t = _index_1.wrapping_add(half_size_7);
3320 comparison_7 = *(predicate_capture_ids.contents)
3321 .offset(mid_index_7 as isize)
3322 as libc::c_int
3323 - value_id as libc::c_int;
3324 if comparison_7 <= 0 as libc::c_int {
3325 _index_1 = mid_index_7;
3326 }
3327 size_7 = (size_7 as libc::c_uint).wrapping_sub(half_size_7) as uint32_t
3328 as uint32_t;
3329 }
3330 comparison_7 = *(predicate_capture_ids.contents).offset(_index_1 as isize)
3331 as libc::c_int
3332 - value_id as libc::c_int;
3333 if comparison_7 == 0 as libc::c_int {
3334 _exists_1 = 1 as libc::c_int as libc::c_uint;
3335 } else if comparison_7 < 0 as libc::c_int {
3336 _index_1 = _index_1.wrapping_add(1 as libc::c_int as libc::c_uint);
3337 }
3338 }
3339 if _exists_1 == 0 {
3340 _array__splice(
3341 &mut predicate_capture_ids as *mut C2RustUnnamed_17 as *mut Array,
3342 ::core::mem::size_of::<uint16_t>() as libc::c_ulong,
3343 _index_1,
3344 0 as libc::c_int as uint32_t,
3345 1 as libc::c_int as uint32_t,
3346 &mut value_id as *mut uint16_t as *const libc::c_void,
3347 );
3348 }
3349 }
3350 j_6 = j_6.wrapping_add(1);
3351 }
3352 let mut start_0: libc::c_uint = (*pattern_0).steps.offset;
3353 let mut end_0: libc::c_uint = start_0.wrapping_add((*pattern_0).steps.length);
3354 let mut j_7: libc::c_uint = start_0;
3355 while j_7 < end_0 {
3356 let mut step_4: *mut QueryStep =
3357 &mut *((*self_0).steps.contents).offset(j_7 as isize) as *mut QueryStep;
3358 let mut k: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3359 while k < 3 as libc::c_int as libc::c_uint {
3360 let mut capture_id: uint16_t = (*step_4).capture_ids[k as usize];
3361 if capture_id as libc::c_int == NONE as libc::c_int {
3362 break;
3363 }
3364 let mut index_0: libc::c_uint = 0;
3365 let mut exists_2: libc::c_uint = 0;
3366 index_0 = 0 as libc::c_int as libc::c_uint;
3367 exists_2 = 0 as libc::c_int as libc::c_uint;
3368 let mut size_8: uint32_t = (predicate_capture_ids.size).wrapping_sub(index_0);
3369 if !(size_8 == 0 as libc::c_int as libc::c_uint) {
3370 let mut comparison_8: libc::c_int = 0;
3371 while size_8 > 1 as libc::c_int as libc::c_uint {
3372 let mut half_size_8: uint32_t =
3373 size_8.wrapping_div(2 as libc::c_int as libc::c_uint);
3374 let mut mid_index_8: uint32_t = index_0.wrapping_add(half_size_8);
3375 comparison_8 = *(predicate_capture_ids.contents)
3376 .offset(mid_index_8 as isize)
3377 as libc::c_int
3378 - capture_id as libc::c_int;
3379 if comparison_8 <= 0 as libc::c_int {
3380 index_0 = mid_index_8;
3381 }
3382 size_8 = (size_8 as libc::c_uint).wrapping_sub(half_size_8) as uint32_t
3383 as uint32_t;
3384 }
3385 comparison_8 = *(predicate_capture_ids.contents).offset(index_0 as isize)
3386 as libc::c_int
3387 - capture_id as libc::c_int;
3388 if comparison_8 == 0 as libc::c_int {
3389 exists_2 = 1 as libc::c_int as libc::c_uint;
3390 } else if comparison_8 < 0 as libc::c_int {
3391 index_0 = index_0.wrapping_add(1 as libc::c_int as libc::c_uint);
3392 }
3393 }
3394 if exists_2 != 0 {
3395 (*step_4).set_root_pattern_guaranteed(0 as libc::c_int != 0);
3396 break;
3397 } else {
3398 k = k.wrapping_add(1);
3399 }
3400 }
3401 j_7 = j_7.wrapping_add(1);
3402 }
3403 i_5 = i_5.wrapping_add(1);
3404 }
3405 let mut done: bool = (*self_0).steps.size == 0 as libc::c_int as libc::c_uint;
3406 while !done {
3407 done = 1 as libc::c_int != 0;
3408 let mut i_6: libc::c_uint =
3409 ((*self_0).steps.size).wrapping_sub(1 as libc::c_int as libc::c_uint);
3410 while i_6 > 0 as libc::c_int as libc::c_uint {
3411 let mut step_5: *mut QueryStep =
3412 &mut *((*self_0).steps.contents).offset(i_6 as isize) as *mut QueryStep;
3413 if !((*step_5).depth as libc::c_int == PATTERN_DONE_MARKER as libc::c_int) {
3414 let mut parent_pattern_guaranteed: bool = 0 as libc::c_int != 0;
3415 loop {
3416 if (*step_5).root_pattern_guaranteed() {
3417 parent_pattern_guaranteed = 1 as libc::c_int != 0;
3418 break;
3419 } else {
3420 if (*step_5).alternative_index as libc::c_int == NONE as libc::c_int
3421 || ((*step_5).alternative_index as libc::c_uint) < i_6
3422 {
3423 break;
3424 }
3425 step_5 = &mut *((*self_0).steps.contents)
3426 .offset((*step_5).alternative_index as isize)
3427 as *mut QueryStep;
3428 }
3429 }
3430 if !parent_pattern_guaranteed {
3431 let mut prev_step: *mut QueryStep = &mut *((*self_0).steps.contents)
3432 .offset(i_6.wrapping_sub(1 as libc::c_int as libc::c_uint) as isize)
3433 as *mut QueryStep;
3434 if !(*prev_step).is_dead_end()
3435 && (*prev_step).depth as libc::c_int != PATTERN_DONE_MARKER as libc::c_int
3436 && (*prev_step).root_pattern_guaranteed() as libc::c_int != 0
3437 {
3438 (*prev_step).set_root_pattern_guaranteed(0 as libc::c_int != 0);
3439 done = 0 as libc::c_int != 0;
3440 }
3441 }
3442 }
3443 i_6 = i_6.wrapping_sub(1);
3444 }
3445 }
3446 analysis.did_abort = 0 as libc::c_int != 0;
3447 let mut i_7: uint32_t = 0 as libc::c_int as uint32_t;
3448 while i_7 < non_rooted_pattern_start_steps.size {
3449 let mut pattern_entry_index: uint16_t =
3450 *(non_rooted_pattern_start_steps.contents).offset(i_7 as isize);
3451 let mut pattern_entry: *mut PatternEntry = &mut *((*self_0).pattern_map.contents)
3452 .offset(pattern_entry_index as isize)
3453 as *mut PatternEntry;
3454 analysis_state_set__clear(&mut analysis.states, &mut analysis.state_pool);
3455 analysis_state_set__clear(&mut analysis.deeper_states, &mut analysis.state_pool);
3456 let mut j_8: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3457 while j_8 < subgraphs.size {
3458 let mut subgraph_5: *mut AnalysisSubgraph =
3459 &mut *(subgraphs.contents).offset(j_8 as isize) as *mut AnalysisSubgraph;
3460 let mut metadata: TSSymbolMetadata =
3461 ts_language_symbol_metadata((*self_0).language, (*subgraph_5).symbol);
3462 if !(metadata.visible as libc::c_int != 0 || metadata.named as libc::c_int != 0) {
3463 let mut k_0: uint32_t = 0 as libc::c_int as uint32_t;
3464 while k_0 < (*subgraph_5).start_states.size {
3465 let mut parse_state_0: TSStateId =
3466 *((*subgraph_5).start_states.contents).offset(k_0 as isize);
3467 analysis_state_set__push(
3468 &mut analysis.states,
3469 &mut analysis.state_pool,
3470 &mut {
3471 let mut init = AnalysisState {
3472 stack: [
3473 {
3474 let mut init = AnalysisStateEntry {
3475 field_id_done: [0; 2],
3476 parse_state: parse_state_0,
3477 parent_symbol: (*subgraph_5).symbol,
3478 child_index: 0 as libc::c_int as uint16_t,
3479 };
3480 init.set_field_id(0 as libc::c_int as TSFieldId);
3481 init.set_done(0 as libc::c_int != 0);
3482 init
3483 },
3484 AnalysisStateEntry {
3485 parse_state: 0,
3486 parent_symbol: 0,
3487 child_index: 0,
3488 field_id_done: [0; 2],
3489 },
3490 AnalysisStateEntry {
3491 parse_state: 0,
3492 parent_symbol: 0,
3493 child_index: 0,
3494 field_id_done: [0; 2],
3495 },
3496 AnalysisStateEntry {
3497 parse_state: 0,
3498 parent_symbol: 0,
3499 child_index: 0,
3500 field_id_done: [0; 2],
3501 },
3502 AnalysisStateEntry {
3503 parse_state: 0,
3504 parent_symbol: 0,
3505 child_index: 0,
3506 field_id_done: [0; 2],
3507 },
3508 AnalysisStateEntry {
3509 parse_state: 0,
3510 parent_symbol: 0,
3511 child_index: 0,
3512 field_id_done: [0; 2],
3513 },
3514 AnalysisStateEntry {
3515 parse_state: 0,
3516 parent_symbol: 0,
3517 child_index: 0,
3518 field_id_done: [0; 2],
3519 },
3520 AnalysisStateEntry {
3521 parse_state: 0,
3522 parent_symbol: 0,
3523 child_index: 0,
3524 field_id_done: [0; 2],
3525 },
3526 ],
3527 depth: 1 as libc::c_int as uint16_t,
3528 step_index: (*pattern_entry).step_index,
3529 root_symbol: (*subgraph_5).symbol,
3530 };
3531 init
3532 },
3533 );
3534 k_0 = k_0.wrapping_add(1);
3535 }
3536 }
3537 j_8 = j_8.wrapping_add(1);
3538 }
3539 ts_query__perform_analysis(self_0, &mut subgraphs, &mut analysis);
3540 if analysis.finished_parent_symbols.size > 0 as libc::c_int as libc::c_uint {
3541 (*((*self_0).patterns.contents).offset((*pattern_entry).pattern_index as isize))
3542 .is_non_local = 1 as libc::c_int != 0;
3543 }
3544 let mut k_1: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3545 while k_1 < analysis.finished_parent_symbols.size {
3546 let mut symbol_1: TSSymbol =
3547 *(analysis.finished_parent_symbols.contents).offset(k_1 as isize);
3548 let mut _index_2: libc::c_uint = 0;
3549 let mut _exists_2: libc::c_uint = 0;
3550 _index_2 = 0 as libc::c_int as libc::c_uint;
3551 _exists_2 = 0 as libc::c_int as libc::c_uint;
3552 let mut size_9: uint32_t =
3553 ((*self_0).repeat_symbols_with_rootless_patterns.size).wrapping_sub(_index_2);
3554 if !(size_9 == 0 as libc::c_int as libc::c_uint) {
3555 let mut comparison_9: libc::c_int = 0;
3556 while size_9 > 1 as libc::c_int as libc::c_uint {
3557 let mut half_size_9: uint32_t =
3558 size_9.wrapping_div(2 as libc::c_int as libc::c_uint);
3559 let mut mid_index_9: uint32_t = _index_2.wrapping_add(half_size_9);
3560 comparison_9 = *((*self_0).repeat_symbols_with_rootless_patterns.contents)
3561 .offset(mid_index_9 as isize)
3562 as libc::c_int
3563 - symbol_1 as libc::c_int;
3564 if comparison_9 <= 0 as libc::c_int {
3565 _index_2 = mid_index_9;
3566 }
3567 size_9 =
3568 (size_9 as libc::c_uint).wrapping_sub(half_size_9) as uint32_t as uint32_t;
3569 }
3570 comparison_9 = *((*self_0).repeat_symbols_with_rootless_patterns.contents)
3571 .offset(_index_2 as isize) as libc::c_int
3572 - symbol_1 as libc::c_int;
3573 if comparison_9 == 0 as libc::c_int {
3574 _exists_2 = 1 as libc::c_int as libc::c_uint;
3575 } else if comparison_9 < 0 as libc::c_int {
3576 _index_2 = _index_2.wrapping_add(1 as libc::c_int as libc::c_uint);
3577 }
3578 }
3579 if _exists_2 == 0 {
3580 _array__splice(
3581 &mut (*self_0).repeat_symbols_with_rootless_patterns as *mut C2RustUnnamed_3
3582 as *mut Array,
3583 ::core::mem::size_of::<TSSymbol>() as libc::c_ulong,
3584 _index_2,
3585 0 as libc::c_int as uint32_t,
3586 1 as libc::c_int as uint32_t,
3587 &mut symbol_1 as *mut TSSymbol as *const libc::c_void,
3588 );
3589 }
3590 k_1 = k_1.wrapping_add(1);
3591 }
3592 i_7 = i_7.wrapping_add(1);
3593 }
3594 let mut i_8: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3595 while i_8 < subgraphs.size {
3596 _array__delete(
3597 &mut (*(subgraphs.contents).offset(i_8 as isize)).start_states as *mut C2RustUnnamed_24
3598 as *mut Array,
3599 );
3600 _array__delete(
3601 &mut (*(subgraphs.contents).offset(i_8 as isize)).nodes as *mut C2RustUnnamed_23
3602 as *mut Array,
3603 );
3604 i_8 = i_8.wrapping_add(1);
3605 }
3606 _array__delete(&mut subgraphs as *mut AnalysisSubgraphArray as *mut Array);
3607 query_analysis__delete(&mut analysis);
3608 _array__delete(&mut next_nodes as *mut C2RustUnnamed_20 as *mut Array);
3609 _array__delete(&mut non_rooted_pattern_start_steps as *mut C2RustUnnamed_19 as *mut Array);
3610 _array__delete(&mut parent_step_indices as *mut C2RustUnnamed_18 as *mut Array);
3611 _array__delete(&mut predicate_capture_ids as *mut C2RustUnnamed_17 as *mut Array);
3612 state_predecessor_map_delete(&mut predecessor_map);
3613 return all_patterns_are_valid;
3614}
3615unsafe extern "C" fn ts_query__add_negated_fields(
3616 mut self_0: *mut TSQuery,
3617 mut step_index: uint16_t,
3618 mut field_ids: *mut TSFieldId,
3619 mut field_count: uint16_t,
3620) {
3621 let mut step: *mut QueryStep =
3622 &mut *((*self_0).steps.contents).offset(step_index as isize) as *mut QueryStep;
3623 let mut failed_match: bool = 0 as libc::c_int != 0;
3624 let mut match_count: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3625 let mut start_i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3626 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
3627 while i < (*self_0).negated_fields.size {
3628 let mut existing_field_id: TSFieldId =
3629 *((*self_0).negated_fields.contents).offset(i as isize);
3630 if existing_field_id as libc::c_int == 0 as libc::c_int {
3631 if match_count == field_count as libc::c_uint {
3632 (*step).negated_field_list_id = start_i as uint16_t;
3633 return;
3634 } else {
3635 start_i = i.wrapping_add(1 as libc::c_int as libc::c_uint);
3636 match_count = 0 as libc::c_int as libc::c_uint;
3637 failed_match = 0 as libc::c_int != 0;
3638 }
3639 } else if match_count < field_count as libc::c_uint
3640 && existing_field_id as libc::c_int
3641 == *field_ids.offset(match_count as isize) as libc::c_int
3642 && !failed_match
3643 {
3644 match_count = match_count.wrapping_add(1);
3645 } else {
3646 match_count = 0 as libc::c_int as libc::c_uint;
3647 failed_match = 1 as libc::c_int != 0;
3648 }
3649 i = i.wrapping_add(1);
3650 }
3651 (*step).negated_field_list_id = (*self_0).negated_fields.size as uint16_t;
3652 _array__splice(
3653 &mut (*self_0).negated_fields as *mut C2RustUnnamed_5 as *mut Array,
3654 ::core::mem::size_of::<TSFieldId>() as libc::c_ulong,
3655 (*self_0).negated_fields.size,
3656 0 as libc::c_int as uint32_t,
3657 field_count as uint32_t,
3658 field_ids as *const libc::c_void,
3659 );
3660 _array__grow(
3661 &mut (*self_0).negated_fields as *mut C2RustUnnamed_5 as *mut Array,
3662 1 as libc::c_int as uint32_t,
3663 ::core::mem::size_of::<TSFieldId>() as libc::c_ulong,
3664 );
3665 let fresh15 = (*self_0).negated_fields.size;
3666 (*self_0).negated_fields.size = ((*self_0).negated_fields.size).wrapping_add(1);
3667 *((*self_0).negated_fields.contents).offset(fresh15 as isize) = 0 as libc::c_int as TSFieldId;
3668}
3669unsafe extern "C" fn ts_query__parse_string_literal(
3670 mut self_0: *mut TSQuery,
3671 mut stream: *mut Stream,
3672) -> TSQueryError {
3673 let mut string_start: *const libc::c_char = (*stream).input;
3674 if (*stream).next != '"' as i32 {
3675 return TSQueryErrorSyntax;
3676 }
3677 stream_advance(stream);
3678 let mut prev_position: *const libc::c_char = (*stream).input;
3679 let mut is_escaped: bool = 0 as libc::c_int != 0;
3680 (*self_0).string_buffer.size = 0 as libc::c_int as uint32_t;
3681 loop {
3682 if is_escaped {
3683 is_escaped = 0 as libc::c_int != 0;
3684 match (*stream).next {
3685 110 => {
3686 _array__grow(
3687 &mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array,
3688 1 as libc::c_int as uint32_t,
3689 ::core::mem::size_of::<libc::c_char>() as libc::c_ulong,
3690 );
3691 let fresh16 = (*self_0).string_buffer.size;
3692 (*self_0).string_buffer.size = ((*self_0).string_buffer.size).wrapping_add(1);
3693 *((*self_0).string_buffer.contents).offset(fresh16 as isize) =
3694 '\n' as i32 as libc::c_char;
3695 }
3696 114 => {
3697 _array__grow(
3698 &mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array,
3699 1 as libc::c_int as uint32_t,
3700 ::core::mem::size_of::<libc::c_char>() as libc::c_ulong,
3701 );
3702 let fresh17 = (*self_0).string_buffer.size;
3703 (*self_0).string_buffer.size = ((*self_0).string_buffer.size).wrapping_add(1);
3704 *((*self_0).string_buffer.contents).offset(fresh17 as isize) =
3705 '\r' as i32 as libc::c_char;
3706 }
3707 116 => {
3708 _array__grow(
3709 &mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array,
3710 1 as libc::c_int as uint32_t,
3711 ::core::mem::size_of::<libc::c_char>() as libc::c_ulong,
3712 );
3713 let fresh18 = (*self_0).string_buffer.size;
3714 (*self_0).string_buffer.size = ((*self_0).string_buffer.size).wrapping_add(1);
3715 *((*self_0).string_buffer.contents).offset(fresh18 as isize) =
3716 '\t' as i32 as libc::c_char;
3717 }
3718 48 => {
3719 _array__grow(
3720 &mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array,
3721 1 as libc::c_int as uint32_t,
3722 ::core::mem::size_of::<libc::c_char>() as libc::c_ulong,
3723 );
3724 let fresh19 = (*self_0).string_buffer.size;
3725 (*self_0).string_buffer.size = ((*self_0).string_buffer.size).wrapping_add(1);
3726 *((*self_0).string_buffer.contents).offset(fresh19 as isize) =
3727 '\0' as i32 as libc::c_char;
3728 }
3729 _ => {
3730 _array__splice(
3731 &mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array,
3732 ::core::mem::size_of::<libc::c_char>() as libc::c_ulong,
3733 (*self_0).string_buffer.size,
3734 0 as libc::c_int as uint32_t,
3735 (*stream).next_size as uint32_t,
3736 (*stream).input as *const libc::c_void,
3737 );
3738 }
3739 }
3740 prev_position = ((*stream).input).offset((*stream).next_size as libc::c_int as isize);
3741 } else if (*stream).next == '\\' as i32 {
3742 _array__splice(
3743 &mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array,
3744 ::core::mem::size_of::<libc::c_char>() as libc::c_ulong,
3745 (*self_0).string_buffer.size,
3746 0 as libc::c_int as uint32_t,
3747 ((*stream).input).offset_from(prev_position) as libc::c_long as uint32_t,
3748 prev_position as *const libc::c_void,
3749 );
3750 prev_position = ((*stream).input).offset(1 as libc::c_int as isize);
3751 is_escaped = 1 as libc::c_int != 0;
3752 } else if (*stream).next == '"' as i32 {
3753 _array__splice(
3754 &mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array,
3755 ::core::mem::size_of::<libc::c_char>() as libc::c_ulong,
3756 (*self_0).string_buffer.size,
3757 0 as libc::c_int as uint32_t,
3758 ((*stream).input).offset_from(prev_position) as libc::c_long as uint32_t,
3759 prev_position as *const libc::c_void,
3760 );
3761 stream_advance(stream);
3762 return TSQueryErrorNone;
3763 } else {
3764 if (*stream).next == '\n' as i32 {
3765 stream_reset(stream, string_start);
3766 return TSQueryErrorSyntax;
3767 }
3768 }
3769 if !stream_advance(stream) {
3770 stream_reset(stream, string_start);
3771 return TSQueryErrorSyntax;
3772 }
3773 }
3774}
3775unsafe extern "C" fn ts_query__parse_predicate(
3776 mut self_0: *mut TSQuery,
3777 mut stream: *mut Stream,
3778) -> TSQueryError {
3779 if !stream_is_ident_start(stream) {
3780 return TSQueryErrorSyntax;
3781 }
3782 let mut predicate_name: *const libc::c_char = (*stream).input;
3783 stream_scan_identifier(stream);
3784 let mut length: uint32_t =
3785 ((*stream).input).offset_from(predicate_name) as libc::c_long as uint32_t;
3786 let mut id: uint16_t =
3787 symbol_table_insert_name(&mut (*self_0).predicate_values, predicate_name, length);
3788 _array__grow(
3789 &mut (*self_0).predicate_steps as *mut C2RustUnnamed_8 as *mut Array,
3790 1 as libc::c_int as uint32_t,
3791 ::core::mem::size_of::<TSQueryPredicateStep>() as libc::c_ulong,
3792 );
3793 let fresh20 = (*self_0).predicate_steps.size;
3794 (*self_0).predicate_steps.size = ((*self_0).predicate_steps.size).wrapping_add(1);
3795 *((*self_0).predicate_steps.contents).offset(fresh20 as isize) = {
3796 let mut init = TSQueryPredicateStep {
3797 type_: TSQueryPredicateStepTypeString,
3798 value_id: id as uint32_t,
3799 };
3800 init
3801 };
3802 stream_skip_whitespace(stream);
3803 loop {
3804 if (*stream).next == ')' as i32 {
3805 stream_advance(stream);
3806 stream_skip_whitespace(stream);
3807 _array__grow(
3808 &mut (*self_0).predicate_steps as *mut C2RustUnnamed_8 as *mut Array,
3809 1 as libc::c_int as uint32_t,
3810 ::core::mem::size_of::<TSQueryPredicateStep>() as libc::c_ulong,
3811 );
3812 let fresh21 = (*self_0).predicate_steps.size;
3813 (*self_0).predicate_steps.size = ((*self_0).predicate_steps.size).wrapping_add(1);
3814 *((*self_0).predicate_steps.contents).offset(fresh21 as isize) = {
3815 let mut init = TSQueryPredicateStep {
3816 type_: TSQueryPredicateStepTypeDone,
3817 value_id: 0 as libc::c_int as uint32_t,
3818 };
3819 init
3820 };
3821 break;
3822 } else {
3823 if (*stream).next == '@' as i32 {
3824 stream_advance(stream);
3825 if !stream_is_ident_start(stream) {
3826 return TSQueryErrorSyntax;
3827 }
3828 let mut capture_name: *const libc::c_char = (*stream).input;
3829 stream_scan_identifier(stream);
3830 let mut capture_length: uint32_t =
3831 ((*stream).input).offset_from(capture_name) as libc::c_long as uint32_t;
3832 let mut capture_id: libc::c_int =
3833 symbol_table_id_for_name(&mut (*self_0).captures, capture_name, capture_length);
3834 if capture_id == -(1 as libc::c_int) {
3835 stream_reset(stream, capture_name);
3836 return TSQueryErrorCapture;
3837 }
3838 _array__grow(
3839 &mut (*self_0).predicate_steps as *mut C2RustUnnamed_8 as *mut Array,
3840 1 as libc::c_int as uint32_t,
3841 ::core::mem::size_of::<TSQueryPredicateStep>() as libc::c_ulong,
3842 );
3843 let fresh22 = (*self_0).predicate_steps.size;
3844 (*self_0).predicate_steps.size = ((*self_0).predicate_steps.size).wrapping_add(1);
3845 *((*self_0).predicate_steps.contents).offset(fresh22 as isize) = {
3846 let mut init = TSQueryPredicateStep {
3847 type_: TSQueryPredicateStepTypeCapture,
3848 value_id: capture_id as uint32_t,
3849 };
3850 init
3851 };
3852 } else if (*stream).next == '"' as i32 {
3853 let mut e: TSQueryError = ts_query__parse_string_literal(self_0, stream);
3854 if e as u64 != 0 {
3855 return e;
3856 }
3857 let mut query_id: uint16_t = symbol_table_insert_name(
3858 &mut (*self_0).predicate_values,
3859 (*self_0).string_buffer.contents,
3860 (*self_0).string_buffer.size,
3861 );
3862 _array__grow(
3863 &mut (*self_0).predicate_steps as *mut C2RustUnnamed_8 as *mut Array,
3864 1 as libc::c_int as uint32_t,
3865 ::core::mem::size_of::<TSQueryPredicateStep>() as libc::c_ulong,
3866 );
3867 let fresh23 = (*self_0).predicate_steps.size;
3868 (*self_0).predicate_steps.size = ((*self_0).predicate_steps.size).wrapping_add(1);
3869 *((*self_0).predicate_steps.contents).offset(fresh23 as isize) = {
3870 let mut init = TSQueryPredicateStep {
3871 type_: TSQueryPredicateStepTypeString,
3872 value_id: query_id as uint32_t,
3873 };
3874 init
3875 };
3876 } else if stream_is_ident_start(stream) {
3877 let mut symbol_start: *const libc::c_char = (*stream).input;
3878 stream_scan_identifier(stream);
3879 let mut symbol_length: uint32_t =
3880 ((*stream).input).offset_from(symbol_start) as libc::c_long as uint32_t;
3881 let mut query_id_0: uint16_t = symbol_table_insert_name(
3882 &mut (*self_0).predicate_values,
3883 symbol_start,
3884 symbol_length,
3885 );
3886 _array__grow(
3887 &mut (*self_0).predicate_steps as *mut C2RustUnnamed_8 as *mut Array,
3888 1 as libc::c_int as uint32_t,
3889 ::core::mem::size_of::<TSQueryPredicateStep>() as libc::c_ulong,
3890 );
3891 let fresh24 = (*self_0).predicate_steps.size;
3892 (*self_0).predicate_steps.size = ((*self_0).predicate_steps.size).wrapping_add(1);
3893 *((*self_0).predicate_steps.contents).offset(fresh24 as isize) = {
3894 let mut init = TSQueryPredicateStep {
3895 type_: TSQueryPredicateStepTypeString,
3896 value_id: query_id_0 as uint32_t,
3897 };
3898 init
3899 };
3900 } else {
3901 return TSQueryErrorSyntax;
3902 }
3903 stream_skip_whitespace(stream);
3904 }
3905 }
3906 return TSQueryErrorNone;
3907}
3908unsafe extern "C" fn ts_query__parse_pattern(
3909 mut self_0: *mut TSQuery,
3910 mut stream: *mut Stream,
3911 mut depth: uint32_t,
3912 mut is_immediate: bool,
3913 mut capture_quantifiers: *mut CaptureQuantifiers,
3914) -> TSQueryError {
3915 if (*stream).next == 0 as libc::c_int {
3916 return TSQueryErrorSyntax;
3917 }
3918 if (*stream).next == ')' as i32 || (*stream).next == ']' as i32 {
3919 return PARENT_DONE;
3920 }
3921 let starting_step_index: uint32_t = (*self_0).steps.size;
3922 if (*self_0).step_offsets.size == 0 as libc::c_int as libc::c_uint || {
3923 if ((*self_0).step_offsets.size).wrapping_sub(1 as libc::c_int as libc::c_uint)
3924 < (*self_0).step_offsets.size
3925 {
3926 } else {
3927 panic!();
3928 }
3929 (*(&mut *((*self_0).step_offsets.contents).offset(
3930 ((*self_0).step_offsets.size).wrapping_sub(1 as libc::c_int as libc::c_uint) as isize,
3931 ) as *mut StepOffset))
3932 .step_index as libc::c_uint
3933 != starting_step_index
3934 } {
3935 _array__grow(
3936 &mut (*self_0).step_offsets as *mut C2RustUnnamed_6 as *mut Array,
3937 1 as libc::c_int as uint32_t,
3938 ::core::mem::size_of::<StepOffset>() as libc::c_ulong,
3939 );
3940 let fresh25 = (*self_0).step_offsets.size;
3941 (*self_0).step_offsets.size = ((*self_0).step_offsets.size).wrapping_add(1);
3942 *((*self_0).step_offsets.contents).offset(fresh25 as isize) = {
3943 let mut init = StepOffset {
3944 byte_offset: stream_offset(stream),
3945 step_index: starting_step_index as uint16_t,
3946 };
3947 init
3948 };
3949 }
3950 if (*stream).next == '[' as i32 {
3951 stream_advance(stream);
3952 stream_skip_whitespace(stream);
3953 let mut branch_step_indices: C2RustUnnamed_25 = {
3954 let mut init = C2RustUnnamed_25 {
3955 contents: 0 as *mut uint32_t,
3956 size: 0 as libc::c_int as uint32_t,
3957 capacity: 0 as libc::c_int as uint32_t,
3958 };
3959 init
3960 };
3961 let mut branch_capture_quantifiers: CaptureQuantifiers = capture_quantifiers_new();
3962 loop {
3963 let mut start_index: uint32_t = (*self_0).steps.size;
3964 let mut e: TSQueryError = ts_query__parse_pattern(
3965 self_0,
3966 stream,
3967 depth,
3968 is_immediate,
3969 &mut branch_capture_quantifiers,
3970 );
3971 if e as libc::c_uint == PARENT_DONE as libc::c_uint {
3972 if (*stream).next == ']' as i32
3973 && branch_step_indices.size > 0 as libc::c_int as libc::c_uint
3974 {
3975 stream_advance(stream);
3976 break;
3977 } else {
3978 e = TSQueryErrorSyntax;
3979 }
3980 }
3981 if e as u64 != 0 {
3982 capture_quantifiers_delete(&mut branch_capture_quantifiers);
3983 _array__delete(&mut branch_step_indices as *mut C2RustUnnamed_25 as *mut Array);
3984 return e;
3985 }
3986 if start_index == starting_step_index {
3987 capture_quantifiers_replace(capture_quantifiers, &mut branch_capture_quantifiers);
3988 } else {
3989 capture_quantifiers_join_all(capture_quantifiers, &mut branch_capture_quantifiers);
3990 }
3991 _array__grow(
3992 &mut branch_step_indices as *mut C2RustUnnamed_25 as *mut Array,
3993 1 as libc::c_int as uint32_t,
3994 ::core::mem::size_of::<uint32_t>() as libc::c_ulong,
3995 );
3996 let fresh26 = branch_step_indices.size;
3997 branch_step_indices.size = (branch_step_indices.size).wrapping_add(1);
3998 *(branch_step_indices.contents).offset(fresh26 as isize) = start_index;
3999 _array__grow(
4000 &mut (*self_0).steps as *mut C2RustUnnamed_10 as *mut Array,
4001 1 as libc::c_int as uint32_t,
4002 ::core::mem::size_of::<QueryStep>() as libc::c_ulong,
4003 );
4004 let fresh27 = (*self_0).steps.size;
4005 (*self_0).steps.size = ((*self_0).steps.size).wrapping_add(1);
4006 *((*self_0).steps.contents).offset(fresh27 as isize) = query_step__new(
4007 0 as libc::c_int as TSSymbol,
4008 depth as uint16_t,
4009 0 as libc::c_int != 0,
4010 );
4011 capture_quantifiers_clear(&mut branch_capture_quantifiers);
4012 }
4013 (*self_0).steps.size = ((*self_0).steps.size).wrapping_sub(1);
4014 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
4015 while i < (branch_step_indices.size).wrapping_sub(1 as libc::c_int as libc::c_uint) {
4016 let mut step_index: uint32_t = *(branch_step_indices.contents).offset(i as isize);
4017 let mut next_step_index: uint32_t = *(branch_step_indices.contents)
4018 .offset(i.wrapping_add(1 as libc::c_int as libc::c_uint) as isize);
4019 let mut start_step: *mut QueryStep =
4020 &mut *((*self_0).steps.contents).offset(step_index as isize) as *mut QueryStep;
4021 let mut end_step: *mut QueryStep = &mut *((*self_0).steps.contents)
4022 .offset(next_step_index.wrapping_sub(1 as libc::c_int as libc::c_uint) as isize)
4023 as *mut QueryStep;
4024 (*start_step).alternative_index = next_step_index as uint16_t;
4025 (*end_step).alternative_index = (*self_0).steps.size as uint16_t;
4026 (*end_step).set_is_dead_end(1 as libc::c_int != 0);
4027 i = i.wrapping_add(1);
4028 }
4029 capture_quantifiers_delete(&mut branch_capture_quantifiers);
4030 _array__delete(&mut branch_step_indices as *mut C2RustUnnamed_25 as *mut Array);
4031 } else if (*stream).next == '(' as i32 {
4032 stream_advance(stream);
4033 stream_skip_whitespace(stream);
4034 if (*stream).next == '(' as i32
4035 || (*stream).next == '"' as i32
4036 || (*stream).next == '[' as i32
4037 {
4038 let mut child_is_immediate: bool = is_immediate;
4039 let mut child_capture_quantifiers: CaptureQuantifiers = capture_quantifiers_new();
4040 loop {
4041 if (*stream).next == '.' as i32 {
4042 child_is_immediate = 1 as libc::c_int != 0;
4043 stream_advance(stream);
4044 stream_skip_whitespace(stream);
4045 }
4046 let mut e_0: TSQueryError = ts_query__parse_pattern(
4047 self_0,
4048 stream,
4049 depth,
4050 child_is_immediate,
4051 &mut child_capture_quantifiers,
4052 );
4053 if e_0 as libc::c_uint == PARENT_DONE as libc::c_uint {
4054 if (*stream).next == ')' as i32 {
4055 stream_advance(stream);
4056 break;
4057 } else {
4058 e_0 = TSQueryErrorSyntax;
4059 }
4060 }
4061 if e_0 as u64 != 0 {
4062 capture_quantifiers_delete(&mut child_capture_quantifiers);
4063 return e_0;
4064 }
4065 capture_quantifiers_add_all(capture_quantifiers, &mut child_capture_quantifiers);
4066 capture_quantifiers_clear(&mut child_capture_quantifiers);
4067 child_is_immediate = 0 as libc::c_int != 0;
4068 }
4069 capture_quantifiers_delete(&mut child_capture_quantifiers);
4070 } else if (*stream).next == '.' as i32 || (*stream).next == '#' as i32 {
4071 stream_advance(stream);
4072 return ts_query__parse_predicate(self_0, stream);
4073 } else {
4074 let mut symbol: TSSymbol = 0;
4075 if stream_is_ident_start(stream) {
4076 let mut node_name: *const libc::c_char = (*stream).input;
4077 stream_scan_identifier(stream);
4078 let mut length: uint32_t =
4079 ((*stream).input).offset_from(node_name) as libc::c_long as uint32_t;
4080 if length == 1 as libc::c_int as libc::c_uint
4081 && *node_name.offset(0 as libc::c_int as isize) as libc::c_int == '_' as i32
4082 {
4083 symbol = WILDCARD_SYMBOL;
4084 } else {
4085 symbol = ts_language_symbol_for_name(
4086 (*self_0).language,
4087 node_name,
4088 length,
4089 1 as libc::c_int != 0,
4090 );
4091 if symbol == 0 {
4092 stream_reset(stream, node_name);
4093 return TSQueryErrorNodeType;
4094 }
4095 }
4096 } else {
4097 return TSQueryErrorSyntax;
4098 }
4099 _array__grow(
4100 &mut (*self_0).steps as *mut C2RustUnnamed_10 as *mut Array,
4101 1 as libc::c_int as uint32_t,
4102 ::core::mem::size_of::<QueryStep>() as libc::c_ulong,
4103 );
4104 let fresh28 = (*self_0).steps.size;
4105 (*self_0).steps.size = ((*self_0).steps.size).wrapping_add(1);
4106 *((*self_0).steps.contents).offset(fresh28 as isize) =
4107 query_step__new(symbol, depth as uint16_t, is_immediate);
4108 if ((*self_0).steps.size).wrapping_sub(1 as libc::c_int as libc::c_uint)
4109 < (*self_0).steps.size
4110 {
4111 } else {
4112 panic!();
4113 }
4114 let mut step: *mut QueryStep = &mut *((*self_0).steps.contents).offset(
4115 ((*self_0).steps.size).wrapping_sub(1 as libc::c_int as libc::c_uint) as isize,
4116 ) as *mut QueryStep;
4117 if (ts_language_symbol_metadata((*self_0).language, symbol)).supertype {
4118 (*step).supertype_symbol = (*step).symbol;
4119 (*step).symbol = WILDCARD_SYMBOL;
4120 }
4121 if symbol as libc::c_int == WILDCARD_SYMBOL as libc::c_int {
4122 (*step).set_is_named(1 as libc::c_int != 0);
4123 }
4124 stream_skip_whitespace(stream);
4125 if (*stream).next == '/' as i32 {
4126 stream_advance(stream);
4127 if !stream_is_ident_start(stream) {
4128 return TSQueryErrorSyntax;
4129 }
4130 let mut node_name_0: *const libc::c_char = (*stream).input;
4131 stream_scan_identifier(stream);
4132 let mut length_0: uint32_t =
4133 ((*stream).input).offset_from(node_name_0) as libc::c_long as uint32_t;
4134 (*step).symbol = ts_language_symbol_for_name(
4135 (*self_0).language,
4136 node_name_0,
4137 length_0,
4138 1 as libc::c_int != 0,
4139 );
4140 if (*step).symbol == 0 {
4141 stream_reset(stream, node_name_0);
4142 return TSQueryErrorNodeType;
4143 }
4144 stream_skip_whitespace(stream);
4145 }
4146 let mut child_is_immediate_0: bool = 0 as libc::c_int != 0;
4147 let mut last_child_step_index: uint16_t = 0 as libc::c_int as uint16_t;
4148 let mut negated_field_count: uint16_t = 0 as libc::c_int as uint16_t;
4149 let mut negated_field_ids: [TSFieldId; 8] = [0; 8];
4150 let mut child_capture_quantifiers_0: CaptureQuantifiers = capture_quantifiers_new();
4151 loop {
4152 if (*stream).next == '!' as i32 {
4153 stream_advance(stream);
4154 stream_skip_whitespace(stream);
4155 if !stream_is_ident_start(stream) {
4156 capture_quantifiers_delete(&mut child_capture_quantifiers_0);
4157 return TSQueryErrorSyntax;
4158 }
4159 let mut field_name: *const libc::c_char = (*stream).input;
4160 stream_scan_identifier(stream);
4161 let mut length_1: uint32_t =
4162 ((*stream).input).offset_from(field_name) as libc::c_long as uint32_t;
4163 stream_skip_whitespace(stream);
4164 let mut field_id: TSFieldId =
4165 ts_language_field_id_for_name((*self_0).language, field_name, length_1);
4166 if field_id == 0 {
4167 (*stream).input = field_name;
4168 capture_quantifiers_delete(&mut child_capture_quantifiers_0);
4169 return TSQueryErrorField;
4170 }
4171 if (negated_field_count as libc::c_int) < 8 as libc::c_int {
4172 negated_field_ids[negated_field_count as usize] = field_id;
4173 negated_field_count = negated_field_count.wrapping_add(1);
4174 }
4175 } else {
4176 if (*stream).next == '.' as i32 {
4177 child_is_immediate_0 = 1 as libc::c_int != 0;
4178 stream_advance(stream);
4179 stream_skip_whitespace(stream);
4180 }
4181 let mut step_index_0: uint16_t = (*self_0).steps.size as uint16_t;
4182 let mut e_1: TSQueryError = ts_query__parse_pattern(
4183 self_0,
4184 stream,
4185 depth.wrapping_add(1 as libc::c_int as libc::c_uint),
4186 child_is_immediate_0,
4187 &mut child_capture_quantifiers_0,
4188 );
4189 if e_1 as libc::c_uint == PARENT_DONE as libc::c_uint {
4190 if (*stream).next == ')' as i32 {
4191 if child_is_immediate_0 {
4192 if last_child_step_index as libc::c_int == 0 as libc::c_int {
4193 capture_quantifiers_delete(&mut child_capture_quantifiers_0);
4194 return TSQueryErrorSyntax;
4195 }
4196 let ref mut fresh29 = *((*self_0).steps.contents)
4197 .offset(last_child_step_index as isize);
4198 (*fresh29).set_is_last_child(1 as libc::c_int != 0);
4199 }
4200 if negated_field_count != 0 {
4201 ts_query__add_negated_fields(
4202 self_0,
4203 starting_step_index as uint16_t,
4204 negated_field_ids.as_mut_ptr(),
4205 negated_field_count,
4206 );
4207 }
4208 stream_advance(stream);
4209 break;
4210 } else {
4211 e_1 = TSQueryErrorSyntax;
4212 }
4213 }
4214 if e_1 as u64 != 0 {
4215 capture_quantifiers_delete(&mut child_capture_quantifiers_0);
4216 return e_1;
4217 }
4218 capture_quantifiers_add_all(
4219 capture_quantifiers,
4220 &mut child_capture_quantifiers_0,
4221 );
4222 last_child_step_index = step_index_0;
4223 child_is_immediate_0 = 0 as libc::c_int != 0;
4224 capture_quantifiers_clear(&mut child_capture_quantifiers_0);
4225 }
4226 }
4227 capture_quantifiers_delete(&mut child_capture_quantifiers_0);
4228 }
4229 } else if (*stream).next == '_' as i32 {
4230 stream_advance(stream);
4231 stream_skip_whitespace(stream);
4232 _array__grow(
4233 &mut (*self_0).steps as *mut C2RustUnnamed_10 as *mut Array,
4234 1 as libc::c_int as uint32_t,
4235 ::core::mem::size_of::<QueryStep>() as libc::c_ulong,
4236 );
4237 let fresh30 = (*self_0).steps.size;
4238 (*self_0).steps.size = ((*self_0).steps.size).wrapping_add(1);
4239 *((*self_0).steps.contents).offset(fresh30 as isize) =
4240 query_step__new(WILDCARD_SYMBOL, depth as uint16_t, is_immediate);
4241 } else if (*stream).next == '"' as i32 {
4242 let mut string_start: *const libc::c_char = (*stream).input;
4243 let mut e_2: TSQueryError = ts_query__parse_string_literal(self_0, stream);
4244 if e_2 as u64 != 0 {
4245 return e_2;
4246 }
4247 let mut symbol_0: TSSymbol = ts_language_symbol_for_name(
4248 (*self_0).language,
4249 (*self_0).string_buffer.contents,
4250 (*self_0).string_buffer.size,
4251 0 as libc::c_int != 0,
4252 );
4253 if symbol_0 == 0 {
4254 stream_reset(stream, string_start.offset(1 as libc::c_int as isize));
4255 return TSQueryErrorNodeType;
4256 }
4257 _array__grow(
4258 &mut (*self_0).steps as *mut C2RustUnnamed_10 as *mut Array,
4259 1 as libc::c_int as uint32_t,
4260 ::core::mem::size_of::<QueryStep>() as libc::c_ulong,
4261 );
4262 let fresh31 = (*self_0).steps.size;
4263 (*self_0).steps.size = ((*self_0).steps.size).wrapping_add(1);
4264 *((*self_0).steps.contents).offset(fresh31 as isize) =
4265 query_step__new(symbol_0, depth as uint16_t, is_immediate);
4266 } else if stream_is_ident_start(stream) {
4267 let mut field_name_0: *const libc::c_char = (*stream).input;
4268 stream_scan_identifier(stream);
4269 let mut length_2: uint32_t =
4270 ((*stream).input).offset_from(field_name_0) as libc::c_long as uint32_t;
4271 stream_skip_whitespace(stream);
4272 if (*stream).next != ':' as i32 {
4273 stream_reset(stream, field_name_0);
4274 return TSQueryErrorSyntax;
4275 }
4276 stream_advance(stream);
4277 stream_skip_whitespace(stream);
4278 let mut field_capture_quantifiers: CaptureQuantifiers = capture_quantifiers_new();
4279 let mut e_3: TSQueryError = ts_query__parse_pattern(
4280 self_0,
4281 stream,
4282 depth,
4283 is_immediate,
4284 &mut field_capture_quantifiers,
4285 );
4286 if e_3 as u64 != 0 {
4287 capture_quantifiers_delete(&mut field_capture_quantifiers);
4288 if e_3 as libc::c_uint == PARENT_DONE as libc::c_uint {
4289 e_3 = TSQueryErrorSyntax;
4290 }
4291 return e_3;
4292 }
4293 let mut field_id_0: TSFieldId =
4294 ts_language_field_id_for_name((*self_0).language, field_name_0, length_2);
4295 if field_id_0 == 0 {
4296 (*stream).input = field_name_0;
4297 return TSQueryErrorField;
4298 }
4299 let mut step_index_1: uint32_t = starting_step_index;
4300 let mut step_0: *mut QueryStep =
4301 &mut *((*self_0).steps.contents).offset(step_index_1 as isize) as *mut QueryStep;
4302 loop {
4303 (*step_0).field = field_id_0;
4304 if !((*step_0).alternative_index as libc::c_int != NONE as libc::c_int
4305 && (*step_0).alternative_index as libc::c_uint > step_index_1
4306 && ((*step_0).alternative_index as libc::c_uint) < (*self_0).steps.size)
4307 {
4308 break;
4309 }
4310 step_index_1 = (*step_0).alternative_index as uint32_t;
4311 step_0 =
4312 &mut *((*self_0).steps.contents).offset(step_index_1 as isize) as *mut QueryStep;
4313 }
4314 capture_quantifiers_add_all(capture_quantifiers, &mut field_capture_quantifiers);
4315 capture_quantifiers_delete(&mut field_capture_quantifiers);
4316 } else {
4317 return TSQueryErrorSyntax;
4318 }
4319 stream_skip_whitespace(stream);
4320 let mut quantifier: TSQuantifier = TSQuantifierOne;
4321 loop {
4322 if (*stream).next == '+' as i32 {
4323 quantifier = quantifier_join(TSQuantifierOneOrMore, quantifier);
4324 stream_advance(stream);
4325 stream_skip_whitespace(stream);
4326 let mut repeat_step: QueryStep =
4327 query_step__new(WILDCARD_SYMBOL, depth as uint16_t, 0 as libc::c_int != 0);
4328 repeat_step.alternative_index = starting_step_index as uint16_t;
4329 repeat_step.set_is_pass_through(1 as libc::c_int != 0);
4330 repeat_step.set_alternative_is_immediate(1 as libc::c_int != 0);
4331 _array__grow(
4332 &mut (*self_0).steps as *mut C2RustUnnamed_10 as *mut Array,
4333 1 as libc::c_int as uint32_t,
4334 ::core::mem::size_of::<QueryStep>() as libc::c_ulong,
4335 );
4336 let fresh32 = (*self_0).steps.size;
4337 (*self_0).steps.size = ((*self_0).steps.size).wrapping_add(1);
4338 *((*self_0).steps.contents).offset(fresh32 as isize) = repeat_step;
4339 } else if (*stream).next == '*' as i32 {
4340 quantifier = quantifier_join(TSQuantifierZeroOrMore, quantifier);
4341 stream_advance(stream);
4342 stream_skip_whitespace(stream);
4343 let mut repeat_step_0: QueryStep =
4344 query_step__new(WILDCARD_SYMBOL, depth as uint16_t, 0 as libc::c_int != 0);
4345 repeat_step_0.alternative_index = starting_step_index as uint16_t;
4346 repeat_step_0.set_is_pass_through(1 as libc::c_int != 0);
4347 repeat_step_0.set_alternative_is_immediate(1 as libc::c_int != 0);
4348 _array__grow(
4349 &mut (*self_0).steps as *mut C2RustUnnamed_10 as *mut Array,
4350 1 as libc::c_int as uint32_t,
4351 ::core::mem::size_of::<QueryStep>() as libc::c_ulong,
4352 );
4353 let fresh33 = (*self_0).steps.size;
4354 (*self_0).steps.size = ((*self_0).steps.size).wrapping_add(1);
4355 *((*self_0).steps.contents).offset(fresh33 as isize) = repeat_step_0;
4356 let mut step_1: *mut QueryStep = &mut *((*self_0).steps.contents)
4357 .offset(starting_step_index as isize)
4358 as *mut QueryStep;
4359 while (*step_1).alternative_index as libc::c_int != NONE as libc::c_int
4360 && ((*step_1).alternative_index as libc::c_uint)
4361 < ((*self_0).steps.size).wrapping_sub(1 as libc::c_int as libc::c_uint)
4362 {
4363 step_1 = &mut *((*self_0).steps.contents)
4364 .offset((*step_1).alternative_index as isize)
4365 as *mut QueryStep;
4366 }
4367 (*step_1).alternative_index = (*self_0).steps.size as uint16_t;
4368 } else if (*stream).next == '?' as i32 {
4369 quantifier = quantifier_join(TSQuantifierZeroOrOne, quantifier);
4370 stream_advance(stream);
4371 stream_skip_whitespace(stream);
4372 let mut step_2: *mut QueryStep = &mut *((*self_0).steps.contents)
4373 .offset(starting_step_index as isize)
4374 as *mut QueryStep;
4375 while (*step_2).alternative_index as libc::c_int != NONE as libc::c_int
4376 && ((*step_2).alternative_index as libc::c_uint) < (*self_0).steps.size
4377 {
4378 step_2 = &mut *((*self_0).steps.contents)
4379 .offset((*step_2).alternative_index as isize)
4380 as *mut QueryStep;
4381 }
4382 (*step_2).alternative_index = (*self_0).steps.size as uint16_t;
4383 } else {
4384 if !((*stream).next == '@' as i32) {
4385 break;
4386 }
4387 stream_advance(stream);
4388 if !stream_is_ident_start(stream) {
4389 return TSQueryErrorSyntax;
4390 }
4391 let mut capture_name: *const libc::c_char = (*stream).input;
4392 stream_scan_identifier(stream);
4393 let mut length_3: uint32_t =
4394 ((*stream).input).offset_from(capture_name) as libc::c_long as uint32_t;
4395 stream_skip_whitespace(stream);
4396 let mut capture_id: uint16_t =
4397 symbol_table_insert_name(&mut (*self_0).captures, capture_name, length_3);
4398 capture_quantifiers_add_for_id(capture_quantifiers, capture_id, TSQuantifierOne);
4399 let mut step_index_2: uint32_t = starting_step_index;
4400 loop {
4401 let mut step_3: *mut QueryStep = &mut *((*self_0).steps.contents)
4402 .offset(step_index_2 as isize)
4403 as *mut QueryStep;
4404 query_step__add_capture(step_3, capture_id);
4405 if !((*step_3).alternative_index as libc::c_int != NONE as libc::c_int
4406 && (*step_3).alternative_index as libc::c_uint > step_index_2
4407 && ((*step_3).alternative_index as libc::c_uint) < (*self_0).steps.size)
4408 {
4409 break;
4410 }
4411 step_index_2 = (*step_3).alternative_index as uint32_t;
4412 }
4413 }
4414 }
4415 capture_quantifiers_mul(capture_quantifiers, quantifier);
4416 return TSQueryErrorNone;
4417}
4418#[no_mangle]
4419pub unsafe extern "C" fn ts_query_new(
4420 mut language: *const TSLanguage,
4421 mut source: *const libc::c_char,
4422 mut source_len: uint32_t,
4423 mut error_offset: *mut uint32_t,
4424 mut error_type: *mut TSQueryError,
4425) -> *mut TSQuery {
4426 if language.is_null()
4427 || (*language).version > 14 as libc::c_int as libc::c_uint
4428 || (*language).version < 13 as libc::c_int as libc::c_uint
4429 {
4430 *error_type = TSQueryErrorLanguage;
4431 return 0 as *mut TSQuery;
4432 }
4433 let mut self_0: *mut TSQuery = crate::core_transpiled::alloc::ts_malloc(::core::mem::size_of::<
4434 TSQuery,
4435 >()
4436 as libc::c_ulong) as *mut TSQuery;
4437 *self_0 = {
4438 let mut init = TSQuery {
4439 captures: symbol_table_new(),
4440 predicate_values: symbol_table_new(),
4441 capture_quantifiers: {
4442 let mut init = C2RustUnnamed_11 {
4443 contents: 0 as *mut CaptureQuantifiers,
4444 size: 0 as libc::c_int as uint32_t,
4445 capacity: 0 as libc::c_int as uint32_t,
4446 };
4447 init
4448 },
4449 steps: {
4450 let mut init = C2RustUnnamed_10 {
4451 contents: 0 as *mut QueryStep,
4452 size: 0 as libc::c_int as uint32_t,
4453 capacity: 0 as libc::c_int as uint32_t,
4454 };
4455 init
4456 },
4457 pattern_map: {
4458 let mut init = C2RustUnnamed_9 {
4459 contents: 0 as *mut PatternEntry,
4460 size: 0 as libc::c_int as uint32_t,
4461 capacity: 0 as libc::c_int as uint32_t,
4462 };
4463 init
4464 },
4465 predicate_steps: {
4466 let mut init = C2RustUnnamed_8 {
4467 contents: 0 as *mut TSQueryPredicateStep,
4468 size: 0 as libc::c_int as uint32_t,
4469 capacity: 0 as libc::c_int as uint32_t,
4470 };
4471 init
4472 },
4473 patterns: {
4474 let mut init = C2RustUnnamed_7 {
4475 contents: 0 as *mut QueryPattern,
4476 size: 0 as libc::c_int as uint32_t,
4477 capacity: 0 as libc::c_int as uint32_t,
4478 };
4479 init
4480 },
4481 step_offsets: {
4482 let mut init = C2RustUnnamed_6 {
4483 contents: 0 as *mut StepOffset,
4484 size: 0 as libc::c_int as uint32_t,
4485 capacity: 0 as libc::c_int as uint32_t,
4486 };
4487 init
4488 },
4489 negated_fields: {
4490 let mut init = C2RustUnnamed_5 {
4491 contents: 0 as *mut TSFieldId,
4492 size: 0 as libc::c_int as uint32_t,
4493 capacity: 0 as libc::c_int as uint32_t,
4494 };
4495 init
4496 },
4497 string_buffer: {
4498 let mut init = C2RustUnnamed_4 {
4499 contents: 0 as *mut libc::c_char,
4500 size: 0 as libc::c_int as uint32_t,
4501 capacity: 0 as libc::c_int as uint32_t,
4502 };
4503 init
4504 },
4505 repeat_symbols_with_rootless_patterns: {
4506 let mut init = C2RustUnnamed_3 {
4507 contents: 0 as *mut TSSymbol,
4508 size: 0 as libc::c_int as uint32_t,
4509 capacity: 0 as libc::c_int as uint32_t,
4510 };
4511 init
4512 },
4513 language: ts_language_copy(language),
4514 wildcard_root_pattern_count: 0 as libc::c_int as uint16_t,
4515 };
4516 init
4517 };
4518 _array__grow(
4519 &mut (*self_0).negated_fields as *mut C2RustUnnamed_5 as *mut Array,
4520 1 as libc::c_int as uint32_t,
4521 ::core::mem::size_of::<TSFieldId>() as libc::c_ulong,
4522 );
4523 let fresh34 = (*self_0).negated_fields.size;
4524 (*self_0).negated_fields.size = ((*self_0).negated_fields.size).wrapping_add(1);
4525 *((*self_0).negated_fields.contents).offset(fresh34 as isize) = 0 as libc::c_int as TSFieldId;
4526 let mut stream: Stream = stream_new(source, source_len);
4527 stream_skip_whitespace(&mut stream);
4528 while stream.input < stream.end {
4529 let mut pattern_index: uint32_t = (*self_0).patterns.size;
4530 let mut start_step_index: uint32_t = (*self_0).steps.size;
4531 let mut start_predicate_step_index: uint32_t = (*self_0).predicate_steps.size;
4532 _array__grow(
4533 &mut (*self_0).patterns as *mut C2RustUnnamed_7 as *mut Array,
4534 1 as libc::c_int as uint32_t,
4535 ::core::mem::size_of::<QueryPattern>() as libc::c_ulong,
4536 );
4537 let fresh35 = (*self_0).patterns.size;
4538 (*self_0).patterns.size = ((*self_0).patterns.size).wrapping_add(1);
4539 *((*self_0).patterns.contents).offset(fresh35 as isize) = {
4540 let mut init = QueryPattern {
4541 steps: {
4542 let mut init = Slice {
4543 offset: start_step_index,
4544 length: 0,
4545 };
4546 init
4547 },
4548 predicate_steps: {
4549 let mut init = Slice {
4550 offset: start_predicate_step_index,
4551 length: 0,
4552 };
4553 init
4554 },
4555 start_byte: stream_offset(&mut stream),
4556 end_byte: 0,
4557 is_non_local: 0 as libc::c_int != 0,
4558 };
4559 init
4560 };
4561 let mut capture_quantifiers: CaptureQuantifiers = capture_quantifiers_new();
4562 *error_type = ts_query__parse_pattern(
4563 self_0,
4564 &mut stream,
4565 0 as libc::c_int as uint32_t,
4566 0 as libc::c_int != 0,
4567 &mut capture_quantifiers,
4568 );
4569 _array__grow(
4570 &mut (*self_0).steps as *mut C2RustUnnamed_10 as *mut Array,
4571 1 as libc::c_int as uint32_t,
4572 ::core::mem::size_of::<QueryStep>() as libc::c_ulong,
4573 );
4574 let fresh36 = (*self_0).steps.size;
4575 (*self_0).steps.size = ((*self_0).steps.size).wrapping_add(1);
4576 *((*self_0).steps.contents).offset(fresh36 as isize) = query_step__new(
4577 0 as libc::c_int as TSSymbol,
4578 PATTERN_DONE_MARKER,
4579 0 as libc::c_int != 0,
4580 );
4581 if ((*self_0).patterns.size).wrapping_sub(1 as libc::c_int as libc::c_uint)
4582 < (*self_0).patterns.size
4583 {
4584 } else {
4585 panic!();
4586 }
4587 let mut pattern: *mut QueryPattern = &mut *((*self_0).patterns.contents).offset(
4588 ((*self_0).patterns.size).wrapping_sub(1 as libc::c_int as libc::c_uint) as isize,
4589 ) as *mut QueryPattern;
4590 (*pattern).steps.length = ((*self_0).steps.size).wrapping_sub(start_step_index);
4591 (*pattern).predicate_steps.length =
4592 ((*self_0).predicate_steps.size).wrapping_sub(start_predicate_step_index);
4593 (*pattern).end_byte = stream_offset(&mut stream);
4594 if *error_type as u64 != 0 {
4595 if *error_type as libc::c_uint == PARENT_DONE as libc::c_uint {
4596 *error_type = TSQueryErrorSyntax;
4597 }
4598 *error_offset = stream_offset(&mut stream);
4599 capture_quantifiers_delete(&mut capture_quantifiers);
4600 ts_query_delete(self_0);
4601 return 0 as *mut TSQuery;
4602 }
4603 _array__grow(
4604 &mut (*self_0).capture_quantifiers as *mut C2RustUnnamed_11 as *mut Array,
4605 1 as libc::c_int as uint32_t,
4606 ::core::mem::size_of::<CaptureQuantifiers>() as libc::c_ulong,
4607 );
4608 let fresh37 = (*self_0).capture_quantifiers.size;
4609 (*self_0).capture_quantifiers.size = ((*self_0).capture_quantifiers.size).wrapping_add(1);
4610 *((*self_0).capture_quantifiers.contents).offset(fresh37 as isize) = capture_quantifiers;
4611 let mut wildcard_root_alternative_index: uint16_t = NONE;
4612 loop {
4613 let mut step: *mut QueryStep = &mut *((*self_0).steps.contents)
4614 .offset(start_step_index as isize)
4615 as *mut QueryStep;
4616 if (*step).symbol as libc::c_int == WILDCARD_SYMBOL as libc::c_int
4617 && (*step).depth as libc::c_int == 0 as libc::c_int
4618 && (*step).field == 0
4619 {
4620 let mut second_step: *mut QueryStep = &mut *((*self_0).steps.contents).offset(
4621 start_step_index.wrapping_add(1 as libc::c_int as libc::c_uint) as isize,
4622 ) as *mut QueryStep;
4623 if (*second_step).symbol as libc::c_int != WILDCARD_SYMBOL as libc::c_int
4624 && (*second_step).depth as libc::c_int == 1 as libc::c_int
4625 && !(*second_step).is_immediate()
4626 {
4627 wildcard_root_alternative_index = (*step).alternative_index;
4628 start_step_index = (start_step_index as libc::c_uint)
4629 .wrapping_add(1 as libc::c_int as libc::c_uint)
4630 as uint32_t as uint32_t;
4631 step = second_step;
4632 }
4633 }
4634 let mut start_depth: uint32_t = (*step).depth as uint32_t;
4635 let mut is_rooted: bool = start_depth == 0 as libc::c_int as libc::c_uint;
4636 let mut step_index: uint32_t =
4637 start_step_index.wrapping_add(1 as libc::c_int as libc::c_uint);
4638 while step_index < (*self_0).steps.size {
4639 let mut child_step: *mut QueryStep =
4640 &mut *((*self_0).steps.contents).offset(step_index as isize) as *mut QueryStep;
4641 if (*child_step).is_dead_end() {
4642 break;
4643 }
4644 if (*child_step).depth as libc::c_uint == start_depth {
4645 is_rooted = 0 as libc::c_int != 0;
4646 break;
4647 } else {
4648 step_index = step_index.wrapping_add(1);
4649 }
4650 }
4651 ts_query__pattern_map_insert(self_0, (*step).symbol, {
4652 let mut init = PatternEntry {
4653 step_index: start_step_index as uint16_t,
4654 pattern_index: pattern_index as uint16_t,
4655 is_rooted: is_rooted,
4656 };
4657 init
4658 });
4659 if (*step).symbol as libc::c_int == WILDCARD_SYMBOL as libc::c_int {
4660 (*self_0).wildcard_root_pattern_count =
4661 ((*self_0).wildcard_root_pattern_count).wrapping_add(1);
4662 }
4663 if (*step).alternative_index as libc::c_int != NONE as libc::c_int {
4664 start_step_index = (*step).alternative_index as uint32_t;
4665 } else {
4666 if !(wildcard_root_alternative_index as libc::c_int != NONE as libc::c_int) {
4667 break;
4668 }
4669 start_step_index = wildcard_root_alternative_index as uint32_t;
4670 wildcard_root_alternative_index = NONE;
4671 }
4672 }
4673 }
4674 if !ts_query__analyze_patterns(self_0, error_offset) {
4675 *error_type = TSQueryErrorStructure;
4676 ts_query_delete(self_0);
4677 return 0 as *mut TSQuery;
4678 }
4679 _array__delete(&mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array);
4680 return self_0;
4681}
4682#[no_mangle]
4683pub unsafe extern "C" fn ts_query_delete(mut self_0: *mut TSQuery) {
4684 if !self_0.is_null() {
4685 _array__delete(&mut (*self_0).steps as *mut C2RustUnnamed_10 as *mut Array);
4686 _array__delete(&mut (*self_0).pattern_map as *mut C2RustUnnamed_9 as *mut Array);
4687 _array__delete(&mut (*self_0).predicate_steps as *mut C2RustUnnamed_8 as *mut Array);
4688 _array__delete(&mut (*self_0).patterns as *mut C2RustUnnamed_7 as *mut Array);
4689 _array__delete(&mut (*self_0).step_offsets as *mut C2RustUnnamed_6 as *mut Array);
4690 _array__delete(&mut (*self_0).string_buffer as *mut C2RustUnnamed_4 as *mut Array);
4691 _array__delete(&mut (*self_0).negated_fields as *mut C2RustUnnamed_5 as *mut Array);
4692 _array__delete(
4693 &mut (*self_0).repeat_symbols_with_rootless_patterns as *mut C2RustUnnamed_3
4694 as *mut Array,
4695 );
4696 ts_language_delete((*self_0).language);
4697 symbol_table_delete(&mut (*self_0).captures);
4698 symbol_table_delete(&mut (*self_0).predicate_values);
4699 let mut index: uint32_t = 0 as libc::c_int as uint32_t;
4700 while index < (*self_0).capture_quantifiers.size {
4701 if index < (*self_0).capture_quantifiers.size {
4702 } else {
4703 panic!();
4704 }
4705 let mut capture_quantifiers: *mut CaptureQuantifiers =
4706 &mut *((*self_0).capture_quantifiers.contents).offset(index as isize)
4707 as *mut CaptureQuantifiers;
4708 capture_quantifiers_delete(capture_quantifiers);
4709 index = index.wrapping_add(1);
4710 }
4711 _array__delete(&mut (*self_0).capture_quantifiers as *mut C2RustUnnamed_11 as *mut Array);
4712 crate::core_transpiled::alloc::ts_free(self_0 as *mut libc::c_void);
4713 }
4714}
4715#[no_mangle]
4716pub unsafe extern "C" fn ts_query_pattern_count(mut self_0: *const TSQuery) -> uint32_t {
4717 return (*self_0).patterns.size;
4718}
4719#[no_mangle]
4720pub unsafe extern "C" fn ts_query_capture_count(mut self_0: *const TSQuery) -> uint32_t {
4721 return (*self_0).captures.slices.size;
4722}
4723#[no_mangle]
4724pub unsafe extern "C" fn ts_query_string_count(mut self_0: *const TSQuery) -> uint32_t {
4725 return (*self_0).predicate_values.slices.size;
4726}
4727#[no_mangle]
4728pub unsafe extern "C" fn ts_query_capture_name_for_id(
4729 mut self_0: *const TSQuery,
4730 mut index: uint32_t,
4731 mut length: *mut uint32_t,
4732) -> *const libc::c_char {
4733 return symbol_table_name_for_id(&(*self_0).captures, index as uint16_t, length);
4734}
4735#[no_mangle]
4736pub unsafe extern "C" fn ts_query_capture_quantifier_for_id(
4737 mut self_0: *const TSQuery,
4738 mut pattern_index: uint32_t,
4739 mut capture_index: uint32_t,
4740) -> TSQuantifier {
4741 if pattern_index < (*self_0).capture_quantifiers.size {
4742 } else {
4743 panic!();
4744 }
4745 let mut capture_quantifiers: *mut CaptureQuantifiers =
4746 &mut *((*self_0).capture_quantifiers.contents).offset(pattern_index as isize)
4747 as *mut CaptureQuantifiers;
4748 return capture_quantifier_for_id(capture_quantifiers, capture_index as uint16_t);
4749}
4750#[no_mangle]
4751pub unsafe extern "C" fn ts_query_string_value_for_id(
4752 mut self_0: *const TSQuery,
4753 mut index: uint32_t,
4754 mut length: *mut uint32_t,
4755) -> *const libc::c_char {
4756 return symbol_table_name_for_id(&(*self_0).predicate_values, index as uint16_t, length);
4757}
4758#[no_mangle]
4759pub unsafe extern "C" fn ts_query_predicates_for_pattern(
4760 mut self_0: *const TSQuery,
4761 mut pattern_index: uint32_t,
4762 mut step_count: *mut uint32_t,
4763) -> *const TSQueryPredicateStep {
4764 let mut slice: Slice =
4765 (*((*self_0).patterns.contents).offset(pattern_index as isize)).predicate_steps;
4766 *step_count = slice.length;
4767 if ((*self_0).predicate_steps.contents).is_null() {
4768 return 0 as *const TSQueryPredicateStep;
4769 }
4770 return &mut *((*self_0).predicate_steps.contents).offset(slice.offset as isize)
4771 as *mut TSQueryPredicateStep;
4772}
4773#[no_mangle]
4774pub unsafe extern "C" fn ts_query_start_byte_for_pattern(
4775 mut self_0: *const TSQuery,
4776 mut pattern_index: uint32_t,
4777) -> uint32_t {
4778 return (*((*self_0).patterns.contents).offset(pattern_index as isize)).start_byte;
4779}
4780#[no_mangle]
4781pub unsafe extern "C" fn ts_query_end_byte_for_pattern(
4782 mut self_0: *const TSQuery,
4783 mut pattern_index: uint32_t,
4784) -> uint32_t {
4785 return (*((*self_0).patterns.contents).offset(pattern_index as isize)).end_byte;
4786}
4787#[no_mangle]
4788pub unsafe extern "C" fn ts_query_is_pattern_rooted(
4789 mut self_0: *const TSQuery,
4790 mut pattern_index: uint32_t,
4791) -> bool {
4792 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
4793 while i < (*self_0).pattern_map.size {
4794 let mut entry: *mut PatternEntry =
4795 &mut *((*self_0).pattern_map.contents).offset(i as isize) as *mut PatternEntry;
4796 if (*entry).pattern_index as libc::c_uint == pattern_index {
4797 if !(*entry).is_rooted {
4798 return 0 as libc::c_int != 0;
4799 }
4800 }
4801 i = i.wrapping_add(1);
4802 }
4803 return 1 as libc::c_int != 0;
4804}
4805#[no_mangle]
4806pub unsafe extern "C" fn ts_query_is_pattern_non_local(
4807 mut self_0: *const TSQuery,
4808 mut pattern_index: uint32_t,
4809) -> bool {
4810 if pattern_index < (*self_0).patterns.size {
4811 return (*((*self_0).patterns.contents).offset(pattern_index as isize)).is_non_local;
4812 } else {
4813 return 0 as libc::c_int != 0;
4814 };
4815}
4816#[no_mangle]
4817pub unsafe extern "C" fn ts_query_is_pattern_guaranteed_at_step(
4818 mut self_0: *const TSQuery,
4819 mut byte_offset: uint32_t,
4820) -> bool {
4821 let mut step_index: uint32_t = 4294967295 as libc::c_uint;
4822 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
4823 while i < (*self_0).step_offsets.size {
4824 let mut step_offset: *mut StepOffset =
4825 &mut *((*self_0).step_offsets.contents).offset(i as isize) as *mut StepOffset;
4826 if (*step_offset).byte_offset > byte_offset {
4827 break;
4828 }
4829 step_index = (*step_offset).step_index as uint32_t;
4830 i = i.wrapping_add(1);
4831 }
4832 if step_index < (*self_0).steps.size {
4833 return (*((*self_0).steps.contents).offset(step_index as isize)).root_pattern_guaranteed();
4834 } else {
4835 return 0 as libc::c_int != 0;
4836 };
4837}
4838#[no_mangle]
4839pub unsafe extern "C" fn ts_query__step_is_fallible(
4840 mut self_0: *const TSQuery,
4841 mut step_index: uint16_t,
4842) -> bool {
4843 if (step_index as uint32_t).wrapping_add(1 as libc::c_int as libc::c_uint)
4844 < (*self_0).steps.size
4845 {
4846 } else {
4847 panic!();
4848 }
4849 let mut step: *mut QueryStep =
4850 &mut *((*self_0).steps.contents).offset(step_index as isize) as *mut QueryStep;
4851 let mut next_step: *mut QueryStep = &mut *((*self_0).steps.contents)
4852 .offset((step_index as libc::c_int + 1 as libc::c_int) as isize)
4853 as *mut QueryStep;
4854 return (*next_step).depth as libc::c_int != PATTERN_DONE_MARKER as libc::c_int
4855 && (*next_step).depth as libc::c_int > (*step).depth as libc::c_int
4856 && !(*next_step).parent_pattern_guaranteed();
4857}
4858#[no_mangle]
4859pub unsafe extern "C" fn ts_query_disable_capture(
4860 mut self_0: *mut TSQuery,
4861 mut name: *const libc::c_char,
4862 mut length: uint32_t,
4863) {
4864 let mut id: libc::c_int = symbol_table_id_for_name(&mut (*self_0).captures, name, length);
4865 if id != -(1 as libc::c_int) {
4866 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
4867 while i < (*self_0).steps.size {
4868 let mut step: *mut QueryStep =
4869 &mut *((*self_0).steps.contents).offset(i as isize) as *mut QueryStep;
4870 query_step__remove_capture(step, id as uint16_t);
4871 i = i.wrapping_add(1);
4872 }
4873 }
4874}
4875#[no_mangle]
4876pub unsafe extern "C" fn ts_query_disable_pattern(
4877 mut self_0: *mut TSQuery,
4878 mut pattern_index: uint32_t,
4879) {
4880 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
4881 while i < (*self_0).pattern_map.size {
4882 let mut pattern: *mut PatternEntry =
4883 &mut *((*self_0).pattern_map.contents).offset(i as isize) as *mut PatternEntry;
4884 if (*pattern).pattern_index as libc::c_uint == pattern_index {
4885 _array__erase(
4886 &mut (*self_0).pattern_map as *mut C2RustUnnamed_9 as *mut Array,
4887 ::core::mem::size_of::<PatternEntry>() as libc::c_ulong,
4888 i,
4889 );
4890 i = i.wrapping_sub(1);
4891 }
4892 i = i.wrapping_add(1);
4893 }
4894}
4895#[no_mangle]
4896pub unsafe extern "C" fn ts_query_cursor_new() -> *mut TSQueryCursor {
4897 let mut self_0: *mut TSQueryCursor = crate::core_transpiled::alloc::ts_malloc(
4898 ::core::mem::size_of::<TSQueryCursor>() as libc::c_ulong,
4899 ) as *mut TSQueryCursor;
4900 *self_0 = {
4901 let mut init = TSQueryCursor {
4902 query: 0 as *const TSQuery,
4903 cursor: TSTreeCursor {
4904 tree: 0 as *const libc::c_void,
4905 id: 0 as *const libc::c_void,
4906 context: [0; 3],
4907 },
4908 states: {
4909 let mut init = C2RustUnnamed_16 {
4910 contents: 0 as *mut QueryState,
4911 size: 0 as libc::c_int as uint32_t,
4912 capacity: 0 as libc::c_int as uint32_t,
4913 };
4914 init
4915 },
4916 finished_states: {
4917 let mut init = C2RustUnnamed_15 {
4918 contents: 0 as *mut QueryState,
4919 size: 0 as libc::c_int as uint32_t,
4920 capacity: 0 as libc::c_int as uint32_t,
4921 };
4922 init
4923 },
4924 capture_list_pool: capture_list_pool_new(),
4925 depth: 0,
4926 max_start_depth: 4294967295 as libc::c_uint,
4927 start_byte: 0 as libc::c_int as uint32_t,
4928 end_byte: 4294967295 as libc::c_uint,
4929 start_point: {
4930 let mut init = TSPoint {
4931 row: 0 as libc::c_int as uint32_t,
4932 column: 0 as libc::c_int as uint32_t,
4933 };
4934 init
4935 },
4936 end_point: {
4937 let mut init = TSPoint {
4938 row: 4294967295 as libc::c_uint,
4939 column: 4294967295 as libc::c_uint,
4940 };
4941 init
4942 },
4943 next_state_id: 0,
4944 end_clock: clock_null(),
4945 timeout_duration: 0 as libc::c_int as TSDuration,
4946 operation_count: 0 as libc::c_int as libc::c_uint,
4947 on_visible_node: false,
4948 ascending: 0 as libc::c_int != 0,
4949 halted: 0 as libc::c_int != 0,
4950 did_exceed_match_limit: 0 as libc::c_int != 0,
4951 };
4952 init
4953 };
4954 _array__reserve(
4955 &mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array,
4956 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
4957 8 as libc::c_int as uint32_t,
4958 );
4959 _array__reserve(
4960 &mut (*self_0).finished_states as *mut C2RustUnnamed_15 as *mut Array,
4961 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
4962 8 as libc::c_int as uint32_t,
4963 );
4964 return self_0;
4965}
4966#[no_mangle]
4967pub unsafe extern "C" fn ts_query_cursor_delete(mut self_0: *mut TSQueryCursor) {
4968 _array__delete(&mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array);
4969 _array__delete(&mut (*self_0).finished_states as *mut C2RustUnnamed_15 as *mut Array);
4970 ts_tree_cursor_delete(&mut (*self_0).cursor);
4971 capture_list_pool_delete(&mut (*self_0).capture_list_pool);
4972 crate::core_transpiled::alloc::ts_free(self_0 as *mut libc::c_void);
4973}
4974#[no_mangle]
4975pub unsafe extern "C" fn ts_query_cursor_did_exceed_match_limit(
4976 mut self_0: *const TSQueryCursor,
4977) -> bool {
4978 return (*self_0).did_exceed_match_limit;
4979}
4980#[no_mangle]
4981pub unsafe extern "C" fn ts_query_cursor_match_limit(mut self_0: *const TSQueryCursor) -> uint32_t {
4982 return (*self_0).capture_list_pool.max_capture_list_count;
4983}
4984#[no_mangle]
4985pub unsafe extern "C" fn ts_query_cursor_set_match_limit(
4986 mut self_0: *mut TSQueryCursor,
4987 mut limit: uint32_t,
4988) {
4989 (*self_0).capture_list_pool.max_capture_list_count = limit;
4990}
4991#[no_mangle]
4992pub unsafe extern "C" fn ts_query_cursor_timeout_micros(
4993 mut self_0: *const TSQueryCursor,
4994) -> uint64_t {
4995 return duration_to_micros((*self_0).timeout_duration);
4996}
4997#[no_mangle]
4998pub unsafe extern "C" fn ts_query_cursor_set_timeout_micros(
4999 mut self_0: *mut TSQueryCursor,
5000 mut timeout_micros: uint64_t,
5001) {
5002 (*self_0).timeout_duration = duration_from_micros(timeout_micros);
5003}
5004#[no_mangle]
5005pub unsafe extern "C" fn ts_query_cursor_exec(
5006 mut self_0: *mut TSQueryCursor,
5007 mut query: *const TSQuery,
5008 mut node: TSNode,
5009) {
5010 if !query.is_null() {
5011 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5012 while i < (*query).steps.size {
5013 let mut step: *mut QueryStep =
5014 &mut *((*query).steps.contents).offset(i as isize) as *mut QueryStep;
5015 if !((*step).depth as libc::c_int == PATTERN_DONE_MARKER as libc::c_int) {
5016 if !(*step).is_dead_end() {
5017 if !(*step).is_pass_through() {
5018 (*step).symbol as libc::c_int != WILDCARD_SYMBOL as libc::c_int;
5019 }
5020 }
5021 }
5022 (*step).field != 0;
5023 (*step).alternative_index as libc::c_int != NONE as libc::c_int;
5024 i = i.wrapping_add(1);
5025 }
5026 }
5027 (*self_0).states.size = 0 as libc::c_int as uint32_t;
5028 (*self_0).finished_states.size = 0 as libc::c_int as uint32_t;
5029 ts_tree_cursor_reset(&mut (*self_0).cursor, node);
5030 capture_list_pool_reset(&mut (*self_0).capture_list_pool);
5031 (*self_0).on_visible_node = 1 as libc::c_int != 0;
5032 (*self_0).next_state_id = 0 as libc::c_int as uint32_t;
5033 (*self_0).depth = 0 as libc::c_int as uint32_t;
5034 (*self_0).ascending = 0 as libc::c_int != 0;
5035 (*self_0).halted = 0 as libc::c_int != 0;
5036 (*self_0).query = query;
5037 (*self_0).did_exceed_match_limit = 0 as libc::c_int != 0;
5038 (*self_0).operation_count = 0 as libc::c_int as libc::c_uint;
5039 if (*self_0).timeout_duration != 0 {
5040 (*self_0).end_clock = clock_after(clock_now(), (*self_0).timeout_duration);
5041 } else {
5042 (*self_0).end_clock = clock_null();
5043 };
5044}
5045#[no_mangle]
5046pub unsafe extern "C" fn ts_query_cursor_set_byte_range(
5047 mut self_0: *mut TSQueryCursor,
5048 mut start_byte: uint32_t,
5049 mut end_byte: uint32_t,
5050) {
5051 if end_byte == 0 as libc::c_int as libc::c_uint {
5052 end_byte = 4294967295 as libc::c_uint;
5053 }
5054 (*self_0).start_byte = start_byte;
5055 (*self_0).end_byte = end_byte;
5056}
5057#[no_mangle]
5058pub unsafe extern "C" fn ts_query_cursor_set_point_range(
5059 mut self_0: *mut TSQueryCursor,
5060 mut start_point: TSPoint,
5061 mut end_point: TSPoint,
5062) {
5063 if end_point.row == 0 as libc::c_int as libc::c_uint
5064 && end_point.column == 0 as libc::c_int as libc::c_uint
5065 {
5066 end_point = {
5067 let mut init = TSPoint {
5068 row: 4294967295 as libc::c_uint,
5069 column: 4294967295 as libc::c_uint,
5070 };
5071 init
5072 };
5073 }
5074 (*self_0).start_point = start_point;
5075 (*self_0).end_point = end_point;
5076}
5077unsafe extern "C" fn ts_query_cursor__first_in_progress_capture(
5078 mut self_0: *mut TSQueryCursor,
5079 mut state_index: *mut uint32_t,
5080 mut byte_offset: *mut uint32_t,
5081 mut pattern_index: *mut uint32_t,
5082 mut root_pattern_guaranteed: *mut bool,
5083) -> bool {
5084 let mut result: bool = 0 as libc::c_int != 0;
5085 *state_index = 4294967295 as libc::c_uint;
5086 *byte_offset = 4294967295 as libc::c_uint;
5087 *pattern_index = 4294967295 as libc::c_uint;
5088 let mut current_block_10: u64;
5089 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5090 while i < (*self_0).states.size {
5091 let mut state: *mut QueryState =
5092 &mut *((*self_0).states.contents).offset(i as isize) as *mut QueryState;
5093 if !(*state).dead() {
5094 let mut captures: *const CaptureList = capture_list_pool_get(
5095 &mut (*self_0).capture_list_pool,
5096 (*state).capture_list_id as uint16_t,
5097 );
5098 if !((*state).consumed_capture_count() as libc::c_uint >= (*captures).size) {
5099 let mut node: TSNode = (*((*captures).contents)
5100 .offset((*state).consumed_capture_count() as isize))
5101 .node;
5102 if ts_node_end_byte(node) <= (*self_0).start_byte
5103 || point_lte(ts_node_end_point(node), (*self_0).start_point) as libc::c_int != 0
5104 {
5105 (*state).set_consumed_capture_count((*state).consumed_capture_count() + 1);
5106 i = i.wrapping_sub(1);
5107 } else {
5108 let mut node_start_byte: uint32_t = ts_node_start_byte(node);
5109 if !result
5110 || node_start_byte < *byte_offset
5111 || node_start_byte == *byte_offset
5112 && ((*state).pattern_index as libc::c_uint) < *pattern_index
5113 {
5114 let mut step: *mut QueryStep = &mut *((*(*self_0).query).steps.contents)
5115 .offset((*state).step_index as isize)
5116 as *mut QueryStep;
5117 if !root_pattern_guaranteed.is_null() {
5118 *root_pattern_guaranteed = (*step).root_pattern_guaranteed();
5119 current_block_10 = 17860125682698302841;
5120 } else if (*step).root_pattern_guaranteed() {
5121 current_block_10 = 14155750587950065367;
5122 } else {
5123 current_block_10 = 17860125682698302841;
5124 }
5125 match current_block_10 {
5126 14155750587950065367 => {}
5127 _ => {
5128 result = 1 as libc::c_int != 0;
5129 *state_index = i;
5130 *byte_offset = node_start_byte;
5131 *pattern_index = (*state).pattern_index as uint32_t;
5132 }
5133 }
5134 }
5135 }
5136 }
5137 }
5138 i = i.wrapping_add(1);
5139 }
5140 return result;
5141}
5142#[no_mangle]
5143pub unsafe extern "C" fn ts_query_cursor__compare_nodes(
5144 mut left: TSNode,
5145 mut right: TSNode,
5146) -> libc::c_int {
5147 if left.id != right.id {
5148 let mut left_start: uint32_t = ts_node_start_byte(left);
5149 let mut right_start: uint32_t = ts_node_start_byte(right);
5150 if left_start < right_start {
5151 return -(1 as libc::c_int);
5152 }
5153 if left_start > right_start {
5154 return 1 as libc::c_int;
5155 }
5156 let mut left_node_count: uint32_t = ts_node_end_byte(left);
5157 let mut right_node_count: uint32_t = ts_node_end_byte(right);
5158 if left_node_count > right_node_count {
5159 return -(1 as libc::c_int);
5160 }
5161 if left_node_count < right_node_count {
5162 return 1 as libc::c_int;
5163 }
5164 }
5165 return 0 as libc::c_int;
5166}
5167#[no_mangle]
5168pub unsafe extern "C" fn ts_query_cursor__compare_captures(
5169 mut self_0: *mut TSQueryCursor,
5170 mut left_state: *mut QueryState,
5171 mut right_state: *mut QueryState,
5172 mut left_contains_right: *mut bool,
5173 mut right_contains_left: *mut bool,
5174) {
5175 let mut left_captures: *const CaptureList = capture_list_pool_get(
5176 &mut (*self_0).capture_list_pool,
5177 (*left_state).capture_list_id as uint16_t,
5178 );
5179 let mut right_captures: *const CaptureList = capture_list_pool_get(
5180 &mut (*self_0).capture_list_pool,
5181 (*right_state).capture_list_id as uint16_t,
5182 );
5183 *left_contains_right = 1 as libc::c_int != 0;
5184 *right_contains_left = 1 as libc::c_int != 0;
5185 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5186 let mut j: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5187 loop {
5188 if i < (*left_captures).size {
5189 if j < (*right_captures).size {
5190 let mut left: *mut TSQueryCapture =
5191 &mut *((*left_captures).contents).offset(i as isize) as *mut TSQueryCapture;
5192 let mut right: *mut TSQueryCapture =
5193 &mut *((*right_captures).contents).offset(j as isize) as *mut TSQueryCapture;
5194 if (*left).node.id == (*right).node.id && (*left).index == (*right).index {
5195 i = i.wrapping_add(1);
5196 j = j.wrapping_add(1);
5197 } else {
5198 match ts_query_cursor__compare_nodes((*left).node, (*right).node) {
5199 -1 => {
5200 *right_contains_left = 0 as libc::c_int != 0;
5201 i = i.wrapping_add(1);
5202 }
5203 1 => {
5204 *left_contains_right = 0 as libc::c_int != 0;
5205 j = j.wrapping_add(1);
5206 }
5207 _ => {
5208 *right_contains_left = 0 as libc::c_int != 0;
5209 *left_contains_right = 0 as libc::c_int != 0;
5210 i = i.wrapping_add(1);
5211 j = j.wrapping_add(1);
5212 }
5213 }
5214 }
5215 } else {
5216 *right_contains_left = 0 as libc::c_int != 0;
5217 break;
5218 }
5219 } else {
5220 if j < (*right_captures).size {
5221 *left_contains_right = 0 as libc::c_int != 0;
5222 }
5223 break;
5224 }
5225 }
5226}
5227unsafe extern "C" fn ts_query_cursor__add_state(
5228 mut self_0: *mut TSQueryCursor,
5229 mut pattern: *const PatternEntry,
5230) {
5231 let mut step: *mut QueryStep = &mut *((*(*self_0).query).steps.contents)
5232 .offset((*pattern).step_index as isize)
5233 as *mut QueryStep;
5234 let mut start_depth: uint32_t = ((*self_0).depth).wrapping_sub((*step).depth as libc::c_uint);
5235 let mut index: uint32_t = (*self_0).states.size;
5236 while index > 0 as libc::c_int as libc::c_uint {
5237 let mut prev_state: *mut QueryState = &mut *((*self_0).states.contents)
5238 .offset(index.wrapping_sub(1 as libc::c_int as libc::c_uint) as isize)
5239 as *mut QueryState;
5240 if ((*prev_state).start_depth as libc::c_uint) < start_depth {
5241 break;
5242 }
5243 if (*prev_state).start_depth as libc::c_uint == start_depth {
5244 if (*prev_state).pattern_index as libc::c_int == (*pattern).pattern_index as libc::c_int
5245 && (*prev_state).step_index as libc::c_int == (*pattern).step_index as libc::c_int
5246 {
5247 return;
5248 }
5249 if (*prev_state).pattern_index as libc::c_int <= (*pattern).pattern_index as libc::c_int
5250 {
5251 break;
5252 }
5253 }
5254 index = index.wrapping_sub(1);
5255 }
5256 _array__splice(
5257 &mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array,
5258 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
5259 index,
5260 0 as libc::c_int as uint32_t,
5261 1 as libc::c_int as uint32_t,
5262 &mut {
5263 let mut init = QueryState { consumed_capture_count_seeking_immediate_match_has_in_progress_alternatives_dead_needs_parent : [0 ; 2] , id : 4294967295 as libc :: c_uint , capture_list_id : NONE as uint32_t , start_depth : start_depth as uint16_t , step_index : (* pattern) . step_index , pattern_index : (* pattern) . pattern_index , } ;
5264 init.set_consumed_capture_count(0 as libc::c_int as uint16_t);
5265 init.set_seeking_immediate_match(1 as libc::c_int != 0);
5266 init.set_has_in_progress_alternatives(0 as libc::c_int != 0);
5267 init.set_dead(0 as libc::c_int != 0);
5268 init.set_needs_parent((*step).depth as libc::c_int == 1 as libc::c_int);
5269 init
5270 } as *mut QueryState as *const libc::c_void,
5271 );
5272}
5273unsafe extern "C" fn ts_query_cursor__prepare_to_capture(
5274 mut self_0: *mut TSQueryCursor,
5275 mut state: *mut QueryState,
5276 mut state_index_to_preserve: libc::c_uint,
5277) -> *mut CaptureList {
5278 if (*state).capture_list_id == NONE as libc::c_uint {
5279 (*state).capture_list_id =
5280 capture_list_pool_acquire(&mut (*self_0).capture_list_pool) as uint32_t;
5281 if (*state).capture_list_id == NONE as libc::c_uint {
5282 (*self_0).did_exceed_match_limit = 1 as libc::c_int != 0;
5283 let mut state_index: uint32_t = 0;
5284 let mut byte_offset: uint32_t = 0;
5285 let mut pattern_index: uint32_t = 0;
5286 if ts_query_cursor__first_in_progress_capture(
5287 self_0,
5288 &mut state_index,
5289 &mut byte_offset,
5290 &mut pattern_index,
5291 0 as *mut bool,
5292 ) as libc::c_int
5293 != 0
5294 && state_index != state_index_to_preserve
5295 {
5296 let mut other_state: *mut QueryState = &mut *((*self_0).states.contents)
5297 .offset(state_index as isize)
5298 as *mut QueryState;
5299 (*state).capture_list_id = (*other_state).capture_list_id;
5300 (*other_state).capture_list_id = NONE as uint32_t;
5301 (*other_state).set_dead(1 as libc::c_int != 0);
5302 let mut list: *mut CaptureList = capture_list_pool_get_mut(
5303 &mut (*self_0).capture_list_pool,
5304 (*state).capture_list_id as uint16_t,
5305 );
5306 (*list).size = 0 as libc::c_int as uint32_t;
5307 return list;
5308 } else {
5309 return 0 as *mut CaptureList;
5310 }
5311 }
5312 }
5313 return capture_list_pool_get_mut(
5314 &mut (*self_0).capture_list_pool,
5315 (*state).capture_list_id as uint16_t,
5316 );
5317}
5318unsafe extern "C" fn ts_query_cursor__capture(
5319 mut self_0: *mut TSQueryCursor,
5320 mut state: *mut QueryState,
5321 mut step: *mut QueryStep,
5322 mut node: TSNode,
5323) {
5324 if (*state).dead() {
5325 return;
5326 }
5327 let mut capture_list: *mut CaptureList =
5328 ts_query_cursor__prepare_to_capture(self_0, state, 4294967295 as libc::c_uint);
5329 if capture_list.is_null() {
5330 (*state).set_dead(1 as libc::c_int != 0);
5331 return;
5332 }
5333 let mut j: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5334 while j < 3 as libc::c_int as libc::c_uint {
5335 let mut capture_id: uint16_t = (*step).capture_ids[j as usize];
5336 if (*step).capture_ids[j as usize] as libc::c_int == NONE as libc::c_int {
5337 break;
5338 }
5339 _array__grow(
5340 capture_list as *mut Array,
5341 1 as libc::c_int as uint32_t,
5342 ::core::mem::size_of::<TSQueryCapture>() as libc::c_ulong,
5343 );
5344 let fresh38 = (*capture_list).size;
5345 (*capture_list).size = ((*capture_list).size).wrapping_add(1);
5346 *((*capture_list).contents).offset(fresh38 as isize) = {
5347 let mut init = TSQueryCapture {
5348 node: node,
5349 index: capture_id as uint32_t,
5350 };
5351 init
5352 };
5353 j = j.wrapping_add(1);
5354 }
5355}
5356unsafe extern "C" fn ts_query_cursor__copy_state(
5357 mut self_0: *mut TSQueryCursor,
5358 mut state_ref: *mut *mut QueryState,
5359) -> *mut QueryState {
5360 let mut state: *const QueryState = *state_ref;
5361 let mut state_index: uint32_t =
5362 state.offset_from((*self_0).states.contents) as libc::c_long as uint32_t;
5363 let mut copy: QueryState = *state;
5364 copy.capture_list_id = NONE as uint32_t;
5365 if (*state).capture_list_id != NONE as libc::c_uint {
5366 let mut new_captures: *mut CaptureList =
5367 ts_query_cursor__prepare_to_capture(self_0, &mut copy, state_index);
5368 if new_captures.is_null() {
5369 return 0 as *mut QueryState;
5370 }
5371 let mut old_captures: *const CaptureList = capture_list_pool_get(
5372 &mut (*self_0).capture_list_pool,
5373 (*state).capture_list_id as uint16_t,
5374 );
5375 _array__splice(
5376 new_captures as *mut Array,
5377 ::core::mem::size_of::<TSQueryCapture>() as libc::c_ulong,
5378 (*new_captures).size,
5379 0 as libc::c_int as uint32_t,
5380 (*old_captures).size,
5381 (*old_captures).contents as *const libc::c_void,
5382 );
5383 }
5384 _array__splice(
5385 &mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array,
5386 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
5387 state_index.wrapping_add(1 as libc::c_int as libc::c_uint),
5388 0 as libc::c_int as uint32_t,
5389 1 as libc::c_int as uint32_t,
5390 &mut copy as *mut QueryState as *const libc::c_void,
5391 );
5392 *state_ref = &mut *((*self_0).states.contents).offset(state_index as isize) as *mut QueryState;
5393 return &mut *((*self_0).states.contents)
5394 .offset(state_index.wrapping_add(1 as libc::c_int as libc::c_uint) as isize)
5395 as *mut QueryState;
5396}
5397#[inline]
5398unsafe extern "C" fn ts_query_cursor__should_descend(
5399 mut self_0: *mut TSQueryCursor,
5400 mut node_intersects_range: bool,
5401) -> bool {
5402 if node_intersects_range as libc::c_int != 0 && (*self_0).depth < (*self_0).max_start_depth {
5403 return 1 as libc::c_int != 0;
5404 }
5405 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5406 while i < (*self_0).states.size {
5407 let mut state: *mut QueryState =
5408 &mut *((*self_0).states.contents).offset(i as isize) as *mut QueryState;
5409 let mut next_step: *mut QueryStep = &mut *((*(*self_0).query).steps.contents)
5410 .offset((*state).step_index as isize)
5411 as *mut QueryStep;
5412 if (*next_step).depth as libc::c_int != PATTERN_DONE_MARKER as libc::c_int
5413 && ((*state).start_depth as libc::c_int + (*next_step).depth as libc::c_int)
5414 as libc::c_uint
5415 > (*self_0).depth
5416 {
5417 return 1 as libc::c_int != 0;
5418 }
5419 i = i.wrapping_add(1);
5420 }
5421 if (*self_0).depth >= (*self_0).max_start_depth {
5422 return 0 as libc::c_int != 0;
5423 }
5424 if !(*self_0).on_visible_node {
5425 let mut subtree: Subtree = ts_tree_cursor_current_subtree(&mut (*self_0).cursor);
5426 if ts_subtree_is_repetition(subtree) != 0 {
5427 let mut exists: bool = false;
5428 let mut index: uint32_t = 0;
5429 index = 0 as libc::c_int as uint32_t;
5430 exists = 0 as libc::c_int != 0;
5431 let mut size: uint32_t = ((*(*self_0).query)
5432 .repeat_symbols_with_rootless_patterns
5433 .size)
5434 .wrapping_sub(index);
5435 if !(size == 0 as libc::c_int as libc::c_uint) {
5436 let mut comparison: libc::c_int = 0;
5437 while size > 1 as libc::c_int as libc::c_uint {
5438 let mut half_size: uint32_t =
5439 size.wrapping_div(2 as libc::c_int as libc::c_uint);
5440 let mut mid_index: uint32_t = index.wrapping_add(half_size);
5441 comparison = *((*(*self_0).query)
5442 .repeat_symbols_with_rootless_patterns
5443 .contents)
5444 .offset(mid_index as isize) as libc::c_int
5445 - ts_subtree_symbol(subtree) as libc::c_int;
5446 if comparison <= 0 as libc::c_int {
5447 index = mid_index;
5448 }
5449 size = (size as libc::c_uint).wrapping_sub(half_size) as uint32_t as uint32_t;
5450 }
5451 comparison = *((*(*self_0).query)
5452 .repeat_symbols_with_rootless_patterns
5453 .contents)
5454 .offset(index as isize) as libc::c_int
5455 - ts_subtree_symbol(subtree) as libc::c_int;
5456 if comparison == 0 as libc::c_int {
5457 exists = 1 as libc::c_int != 0;
5458 } else if comparison < 0 as libc::c_int {
5459 index = (index as libc::c_uint).wrapping_add(1 as libc::c_int as libc::c_uint)
5460 as uint32_t as uint32_t;
5461 }
5462 }
5463 return exists;
5464 }
5465 return 1 as libc::c_int != 0;
5466 }
5467 return 0 as libc::c_int != 0;
5468}
5469#[inline]
5470unsafe extern "C" fn ts_query_cursor__advance(
5471 mut self_0: *mut TSQueryCursor,
5472 mut stop_on_definite_step: bool,
5473) -> bool {
5474 let mut did_match: bool = 0 as libc::c_int != 0;
5475 let mut current_block_189: u64;
5476 loop {
5477 if (*self_0).halted {
5478 while (*self_0).states.size > 0 as libc::c_int as libc::c_uint {
5479 (*self_0).states.size = ((*self_0).states.size).wrapping_sub(1);
5480 let mut state: QueryState =
5481 *((*self_0).states.contents).offset((*self_0).states.size as isize);
5482 capture_list_pool_release(
5483 &mut (*self_0).capture_list_pool,
5484 state.capture_list_id as uint16_t,
5485 );
5486 }
5487 }
5488 (*self_0).operation_count = ((*self_0).operation_count).wrapping_add(1);
5489 if (*self_0).operation_count == OP_COUNT_PER_QUERY_TIMEOUT_CHECK {
5490 (*self_0).operation_count = 0 as libc::c_int as libc::c_uint;
5491 }
5492 if did_match as libc::c_int != 0
5493 || (*self_0).halted as libc::c_int != 0
5494 || (*self_0).operation_count == 0 as libc::c_int as libc::c_uint
5495 && !clock_is_null((*self_0).end_clock)
5496 && clock_is_gt(clock_now(), (*self_0).end_clock) as libc::c_int != 0
5497 {
5498 return did_match;
5499 }
5500 if (*self_0).ascending {
5501 if (*self_0).on_visible_node {
5502 let mut deleted_count: uint32_t = 0 as libc::c_int as uint32_t;
5503 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5504 let mut n: libc::c_uint = (*self_0).states.size;
5505 while i < n {
5506 let mut state_0: *mut QueryState =
5507 &mut *((*self_0).states.contents).offset(i as isize) as *mut QueryState;
5508 let mut step: *mut QueryStep = &mut *((*(*self_0).query).steps.contents)
5509 .offset((*state_0).step_index as isize)
5510 as *mut QueryStep;
5511 if (*step).depth as libc::c_int == PATTERN_DONE_MARKER as libc::c_int
5512 && ((*state_0).start_depth as libc::c_uint > (*self_0).depth
5513 || (*self_0).depth == 0 as libc::c_int as libc::c_uint)
5514 {
5515 _array__grow(
5516 &mut (*self_0).finished_states as *mut C2RustUnnamed_15 as *mut Array,
5517 1 as libc::c_int as uint32_t,
5518 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
5519 );
5520 let fresh39 = (*self_0).finished_states.size;
5521 (*self_0).finished_states.size =
5522 ((*self_0).finished_states.size).wrapping_add(1);
5523 *((*self_0).finished_states.contents).offset(fresh39 as isize) = *state_0;
5524 did_match = 1 as libc::c_int != 0;
5525 deleted_count = deleted_count.wrapping_add(1);
5526 } else if (*step).depth as libc::c_int != PATTERN_DONE_MARKER as libc::c_int
5527 && ((*state_0).start_depth as uint32_t)
5528 .wrapping_add((*step).depth as uint32_t)
5529 > (*self_0).depth
5530 {
5531 capture_list_pool_release(
5532 &mut (*self_0).capture_list_pool,
5533 (*state_0).capture_list_id as uint16_t,
5534 );
5535 deleted_count = deleted_count.wrapping_add(1);
5536 } else if deleted_count > 0 as libc::c_int as libc::c_uint {
5537 *((*self_0).states.contents)
5538 .offset(i.wrapping_sub(deleted_count) as isize) = *state_0;
5539 }
5540 i = i.wrapping_add(1);
5541 }
5542 (*self_0).states.size = ((*self_0).states.size as libc::c_uint)
5543 .wrapping_sub(deleted_count) as uint32_t
5544 as uint32_t;
5545 }
5546 match ts_tree_cursor_goto_next_sibling_internal(&mut (*self_0).cursor) as libc::c_uint {
5547 2 => {
5548 if !(*self_0).on_visible_node {
5549 (*self_0).depth = ((*self_0).depth).wrapping_add(1);
5550 (*self_0).on_visible_node = 1 as libc::c_int != 0;
5551 }
5552 (*self_0).ascending = 0 as libc::c_int != 0;
5553 }
5554 1 => {
5555 if (*self_0).on_visible_node {
5556 (*self_0).depth = ((*self_0).depth).wrapping_sub(1);
5557 (*self_0).on_visible_node = 0 as libc::c_int != 0;
5558 }
5559 (*self_0).ascending = 0 as libc::c_int != 0;
5560 }
5561 _ => {
5562 if ts_tree_cursor_goto_parent(&mut (*self_0).cursor) {
5563 (*self_0).depth = ((*self_0).depth).wrapping_sub(1);
5564 } else {
5565 (*self_0).halted = 1 as libc::c_int != 0;
5566 }
5567 }
5568 }
5569 } else {
5570 let mut node: TSNode = ts_tree_cursor_current_node(&mut (*self_0).cursor);
5571 let mut parent_node: TSNode = ts_tree_cursor_parent_node(&mut (*self_0).cursor);
5572 let mut start_byte: uint32_t = ts_node_start_byte(node);
5573 let mut end_byte: uint32_t = ts_node_end_byte(node);
5574 let mut start_point: TSPoint = ts_node_start_point(node);
5575 let mut end_point: TSPoint = ts_node_end_point(node);
5576 let mut is_empty: bool = start_byte == end_byte;
5577 let mut parent_precedes_range: bool = !ts_node_is_null(parent_node)
5578 && (ts_node_end_byte(parent_node) <= (*self_0).start_byte
5579 || point_lte(ts_node_end_point(parent_node), (*self_0).start_point)
5580 as libc::c_int
5581 != 0);
5582 let mut parent_follows_range: bool = !ts_node_is_null(parent_node)
5583 && (ts_node_start_byte(parent_node) >= (*self_0).end_byte
5584 || point_gte(ts_node_start_point(parent_node), (*self_0).end_point)
5585 as libc::c_int
5586 != 0);
5587 let mut node_precedes_range: bool = parent_precedes_range as libc::c_int != 0
5588 || end_byte < (*self_0).start_byte
5589 || point_lt(end_point, (*self_0).start_point) as libc::c_int != 0
5590 || !is_empty && end_byte == (*self_0).start_byte
5591 || !is_empty && point_eq(end_point, (*self_0).start_point) as libc::c_int != 0;
5592 let mut node_follows_range: bool = parent_follows_range as libc::c_int != 0
5593 || (start_byte >= (*self_0).end_byte
5594 || point_gte(start_point, (*self_0).end_point) as libc::c_int != 0);
5595 let mut parent_intersects_range: bool = !parent_precedes_range && !parent_follows_range;
5596 let mut node_intersects_range: bool = !node_precedes_range && !node_follows_range;
5597 if (*self_0).on_visible_node {
5598 let mut symbol: TSSymbol = ts_node_symbol(node);
5599 let mut is_named: bool = ts_node_is_named(node);
5600 let mut has_later_siblings: bool = false;
5601 let mut has_later_named_siblings: bool = false;
5602 let mut can_have_later_siblings_with_this_field: bool = false;
5603 let mut field_id: TSFieldId = 0 as libc::c_int as TSFieldId;
5604 let mut supertypes: [TSSymbol; 8] =
5605 [0 as libc::c_int as TSSymbol, 0, 0, 0, 0, 0, 0, 0];
5606 let mut supertype_count: libc::c_uint = 8 as libc::c_int as libc::c_uint;
5607 ts_tree_cursor_current_status(
5608 &mut (*self_0).cursor,
5609 &mut field_id,
5610 &mut has_later_siblings,
5611 &mut has_later_named_siblings,
5612 &mut can_have_later_siblings_with_this_field,
5613 supertypes.as_mut_ptr(),
5614 &mut supertype_count,
5615 );
5616 let mut node_is_error: bool =
5617 symbol as libc::c_int == -(1 as libc::c_int) as TSSymbol as libc::c_int;
5618 let mut parent_is_error: bool = !ts_node_is_null(parent_node)
5619 && ts_node_symbol(parent_node) as libc::c_int
5620 == -(1 as libc::c_int) as TSSymbol as libc::c_int;
5621 if !node_is_error {
5622 let mut i_0: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5623 while i_0 < (*(*self_0).query).wildcard_root_pattern_count as libc::c_uint {
5624 let mut pattern: *mut PatternEntry =
5625 &mut *((*(*self_0).query).pattern_map.contents).offset(i_0 as isize)
5626 as *mut PatternEntry;
5627 let mut step_0: *mut QueryStep = &mut *((*(*self_0).query).steps.contents)
5628 .offset((*pattern).step_index as isize)
5629 as *mut QueryStep;
5630 let mut start_depth: uint32_t =
5631 ((*self_0).depth).wrapping_sub((*step_0).depth as libc::c_uint);
5632 if (if (*pattern).is_rooted as libc::c_int != 0 {
5633 node_intersects_range as libc::c_int
5634 } else {
5635 (parent_intersects_range as libc::c_int != 0 && !parent_is_error)
5636 as libc::c_int
5637 }) != 0
5638 && ((*step_0).field == 0
5639 || field_id as libc::c_int == (*step_0).field as libc::c_int)
5640 && ((*step_0).supertype_symbol == 0
5641 || supertype_count > 0 as libc::c_int as libc::c_uint)
5642 && start_depth <= (*self_0).max_start_depth
5643 {
5644 ts_query_cursor__add_state(self_0, pattern);
5645 }
5646 i_0 = i_0.wrapping_add(1);
5647 }
5648 }
5649 let mut i_1: libc::c_uint = 0;
5650 if ts_query__pattern_map_search((*self_0).query, symbol, &mut i_1) {
5651 let mut pattern_0: *mut PatternEntry =
5652 &mut *((*(*self_0).query).pattern_map.contents).offset(i_1 as isize)
5653 as *mut PatternEntry;
5654 let mut step_1: *mut QueryStep = &mut *((*(*self_0).query).steps.contents)
5655 .offset((*pattern_0).step_index as isize)
5656 as *mut QueryStep;
5657 let mut start_depth_0: uint32_t =
5658 ((*self_0).depth).wrapping_sub((*step_1).depth as libc::c_uint);
5659 loop {
5660 if (if (*pattern_0).is_rooted as libc::c_int != 0 {
5661 node_intersects_range as libc::c_int
5662 } else {
5663 (parent_intersects_range as libc::c_int != 0 && !parent_is_error)
5664 as libc::c_int
5665 }) != 0
5666 && ((*step_1).field == 0
5667 || field_id as libc::c_int == (*step_1).field as libc::c_int)
5668 && start_depth_0 <= (*self_0).max_start_depth
5669 {
5670 ts_query_cursor__add_state(self_0, pattern_0);
5671 }
5672 i_1 = i_1.wrapping_add(1);
5673 if i_1 == (*(*self_0).query).pattern_map.size {
5674 break;
5675 }
5676 pattern_0 = &mut *((*(*self_0).query).pattern_map.contents)
5677 .offset(i_1 as isize)
5678 as *mut PatternEntry;
5679 step_1 = &mut *((*(*self_0).query).steps.contents)
5680 .offset((*pattern_0).step_index as isize)
5681 as *mut QueryStep;
5682 if !((*step_1).symbol as libc::c_int == symbol as libc::c_int) {
5683 break;
5684 }
5685 }
5686 }
5687 let mut j: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5688 let mut copy_count: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5689 while j < (*self_0).states.size {
5690 let mut state_1: *mut QueryState =
5691 &mut *((*self_0).states.contents).offset(j as isize) as *mut QueryState;
5692 let mut step_2: *mut QueryStep = &mut *((*(*self_0).query).steps.contents)
5693 .offset((*state_1).step_index as isize)
5694 as *mut QueryStep;
5695 (*state_1).set_has_in_progress_alternatives(0 as libc::c_int != 0);
5696 copy_count = 0 as libc::c_int as libc::c_uint;
5697 if !(((*state_1).start_depth as uint32_t)
5698 .wrapping_add((*step_2).depth as uint32_t)
5699 != (*self_0).depth)
5700 {
5701 let mut node_does_match: bool = 0 as libc::c_int != 0;
5702 if (*step_2).symbol as libc::c_int == WILDCARD_SYMBOL as libc::c_int {
5703 node_does_match = !node_is_error
5704 && (is_named as libc::c_int != 0 || !(*step_2).is_named());
5705 } else {
5706 node_does_match =
5707 symbol as libc::c_int == (*step_2).symbol as libc::c_int;
5708 }
5709 let mut later_sibling_can_match: bool = has_later_siblings;
5710 if (*step_2).is_immediate() as libc::c_int != 0
5711 && is_named as libc::c_int != 0
5712 || (*state_1).seeking_immediate_match() as libc::c_int != 0
5713 {
5714 later_sibling_can_match = 0 as libc::c_int != 0;
5715 }
5716 if (*step_2).is_last_child() as libc::c_int != 0
5717 && has_later_named_siblings as libc::c_int != 0
5718 {
5719 node_does_match = 0 as libc::c_int != 0;
5720 }
5721 if (*step_2).supertype_symbol != 0 {
5722 let mut has_supertype: bool = 0 as libc::c_int != 0;
5723 let mut k: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5724 while k < supertype_count {
5725 if supertypes[k as usize] as libc::c_int
5726 == (*step_2).supertype_symbol as libc::c_int
5727 {
5728 has_supertype = 1 as libc::c_int != 0;
5729 break;
5730 } else {
5731 k = k.wrapping_add(1);
5732 }
5733 }
5734 if !has_supertype {
5735 node_does_match = 0 as libc::c_int != 0;
5736 }
5737 }
5738 if (*step_2).field != 0 {
5739 if (*step_2).field as libc::c_int == field_id as libc::c_int {
5740 if !can_have_later_siblings_with_this_field {
5741 later_sibling_can_match = 0 as libc::c_int != 0;
5742 }
5743 } else {
5744 node_does_match = 0 as libc::c_int != 0;
5745 }
5746 }
5747 if (*step_2).negated_field_list_id != 0 {
5748 let mut negated_field_ids: *mut TSFieldId =
5749 &mut *((*(*self_0).query).negated_fields.contents)
5750 .offset((*step_2).negated_field_list_id as isize)
5751 as *mut TSFieldId;
5752 loop {
5753 let mut negated_field_id: TSFieldId = *negated_field_ids;
5754 if !(negated_field_id != 0) {
5755 break;
5756 }
5757 negated_field_ids = negated_field_ids.offset(1);
5758 if ((ts_node_child_by_field_id(node, negated_field_id)).id)
5759 .is_null()
5760 {
5761 continue;
5762 }
5763 node_does_match = 0 as libc::c_int != 0;
5764 break;
5765 }
5766 }
5767 if !node_does_match {
5768 if !later_sibling_can_match {
5769 capture_list_pool_release(
5770 &mut (*self_0).capture_list_pool,
5771 (*state_1).capture_list_id as uint16_t,
5772 );
5773 _array__erase(
5774 &mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array,
5775 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
5776 j,
5777 );
5778 j = j.wrapping_sub(1);
5779 }
5780 } else {
5781 if later_sibling_can_match as libc::c_int != 0
5782 && ((*step_2).contains_captures() as libc::c_int != 0
5783 || ts_query__step_is_fallible(
5784 (*self_0).query,
5785 (*state_1).step_index,
5786 ) as libc::c_int
5787 != 0)
5788 {
5789 if !(ts_query_cursor__copy_state(self_0, &mut state_1)).is_null() {
5790 copy_count = copy_count.wrapping_add(1);
5791 }
5792 }
5793 if (*state_1).needs_parent() {
5794 let mut parent: TSNode =
5795 ts_tree_cursor_parent_node(&mut (*self_0).cursor);
5796 if ts_node_is_null(parent) {
5797 (*state_1).set_dead(1 as libc::c_int != 0);
5798 } else {
5799 (*state_1).set_needs_parent(0 as libc::c_int != 0);
5800 let mut skipped_wildcard_step: *mut QueryStep = step_2;
5801 loop {
5802 skipped_wildcard_step = skipped_wildcard_step.offset(-1);
5803 if !((*skipped_wildcard_step).is_dead_end() as libc::c_int
5804 != 0
5805 || (*skipped_wildcard_step).is_pass_through()
5806 as libc::c_int
5807 != 0
5808 || (*skipped_wildcard_step).depth as libc::c_int
5809 > 0 as libc::c_int)
5810 {
5811 break;
5812 }
5813 }
5814 if (*skipped_wildcard_step).capture_ids
5815 [0 as libc::c_int as usize]
5816 as libc::c_int
5817 != NONE as libc::c_int
5818 {
5819 ts_query_cursor__capture(
5820 self_0,
5821 state_1,
5822 skipped_wildcard_step,
5823 parent,
5824 );
5825 }
5826 }
5827 }
5828 if (*step_2).capture_ids[0 as libc::c_int as usize] as libc::c_int
5829 != NONE as libc::c_int
5830 {
5831 ts_query_cursor__capture(self_0, state_1, step_2, node);
5832 }
5833 if (*state_1).dead() {
5834 _array__erase(
5835 &mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array,
5836 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
5837 j,
5838 );
5839 j = j.wrapping_sub(1);
5840 } else {
5841 (*state_1).step_index = ((*state_1).step_index).wrapping_add(1);
5842 (*state_1).set_seeking_immediate_match(0 as libc::c_int != 0);
5843 let mut next_step: *mut QueryStep =
5844 &mut *((*(*self_0).query).steps.contents)
5845 .offset((*state_1).step_index as isize)
5846 as *mut QueryStep;
5847 if stop_on_definite_step as libc::c_int != 0
5848 && (*next_step).root_pattern_guaranteed() as libc::c_int != 0
5849 {
5850 did_match = 1 as libc::c_int != 0;
5851 }
5852 let mut end_index: libc::c_uint =
5853 j.wrapping_add(1 as libc::c_int as libc::c_uint);
5854 let mut k_0: libc::c_uint = j;
5855 while k_0 < end_index {
5856 let mut child_state: *mut QueryState =
5857 &mut *((*self_0).states.contents).offset(k_0 as isize)
5858 as *mut QueryState;
5859 let mut child_step: *mut QueryStep =
5860 &mut *((*(*self_0).query).steps.contents)
5861 .offset((*child_state).step_index as isize)
5862 as *mut QueryStep;
5863 if (*child_step).alternative_index as libc::c_int
5864 != NONE as libc::c_int
5865 {
5866 if (*child_step).is_dead_end() {
5867 (*child_state).step_index =
5868 (*child_step).alternative_index;
5869 k_0 = k_0.wrapping_sub(1);
5870 } else {
5871 if (*child_step).is_pass_through() {
5872 (*child_state).step_index =
5873 ((*child_state).step_index).wrapping_add(1);
5874 k_0 = k_0.wrapping_sub(1);
5875 }
5876 let mut copy: *mut QueryState =
5877 ts_query_cursor__copy_state(
5878 self_0,
5879 &mut child_state,
5880 );
5881 if !copy.is_null() {
5882 end_index = end_index.wrapping_add(1);
5883 copy_count = copy_count.wrapping_add(1);
5884 (*copy).step_index =
5885 (*child_step).alternative_index;
5886 if (*child_step).alternative_is_immediate() {
5887 (*copy).set_seeking_immediate_match(
5888 1 as libc::c_int != 0,
5889 );
5890 }
5891 }
5892 }
5893 }
5894 k_0 = k_0.wrapping_add(1);
5895 }
5896 }
5897 }
5898 }
5899 j = j.wrapping_add((1 as libc::c_int as libc::c_uint).wrapping_add(copy_count));
5900 }
5901 let mut j_0: libc::c_uint = 0 as libc::c_int as libc::c_uint;
5902 while j_0 < (*self_0).states.size {
5903 let mut state_2: *mut QueryState =
5904 &mut *((*self_0).states.contents).offset(j_0 as isize) as *mut QueryState;
5905 if (*state_2).dead() {
5906 _array__erase(
5907 &mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array,
5908 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
5909 j_0,
5910 );
5911 j_0 = j_0.wrapping_sub(1);
5912 } else {
5913 let mut did_remove: bool = 0 as libc::c_int != 0;
5914 let mut current_block_167: u64;
5915 let mut k_1: libc::c_uint =
5916 j_0.wrapping_add(1 as libc::c_int as libc::c_uint);
5917 while k_1 < (*self_0).states.size {
5918 let mut other_state: *mut QueryState = &mut *((*self_0).states.contents)
5919 .offset(k_1 as isize)
5920 as *mut QueryState;
5921 if (*other_state).start_depth as libc::c_int
5922 != (*state_2).start_depth as libc::c_int
5923 || (*other_state).pattern_index as libc::c_int
5924 != (*state_2).pattern_index as libc::c_int
5925 {
5926 break;
5927 }
5928 let mut left_contains_right: bool = false;
5929 let mut right_contains_left: bool = false;
5930 ts_query_cursor__compare_captures(
5931 self_0,
5932 state_2,
5933 other_state,
5934 &mut left_contains_right,
5935 &mut right_contains_left,
5936 );
5937 if left_contains_right {
5938 if (*state_2).step_index as libc::c_int
5939 == (*other_state).step_index as libc::c_int
5940 {
5941 capture_list_pool_release(
5942 &mut (*self_0).capture_list_pool,
5943 (*other_state).capture_list_id as uint16_t,
5944 );
5945 _array__erase(
5946 &mut (*self_0).states as *mut C2RustUnnamed_16
5947 as *mut Array,
5948 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
5949 k_1,
5950 );
5951 k_1 = k_1.wrapping_sub(1);
5952 current_block_167 = 145651165234646754;
5953 } else {
5954 (*other_state)
5955 .set_has_in_progress_alternatives(1 as libc::c_int != 0);
5956 current_block_167 = 10485226111480991281;
5957 }
5958 } else {
5959 current_block_167 = 10485226111480991281;
5960 }
5961 match current_block_167 {
5962 10485226111480991281 => {
5963 if right_contains_left {
5964 if (*state_2).step_index as libc::c_int
5965 == (*other_state).step_index as libc::c_int
5966 {
5967 capture_list_pool_release(
5968 &mut (*self_0).capture_list_pool,
5969 (*state_2).capture_list_id as uint16_t,
5970 );
5971 _array__erase(
5972 &mut (*self_0).states as *mut C2RustUnnamed_16
5973 as *mut Array,
5974 ::core::mem::size_of::<QueryState>()
5975 as libc::c_ulong,
5976 j_0,
5977 );
5978 j_0 = j_0.wrapping_sub(1);
5979 did_remove = 1 as libc::c_int != 0;
5980 break;
5981 } else {
5982 (*state_2).set_has_in_progress_alternatives(
5983 1 as libc::c_int != 0,
5984 );
5985 }
5986 }
5987 }
5988 _ => {}
5989 }
5990 k_1 = k_1.wrapping_add(1);
5991 }
5992 if !did_remove {
5993 let mut next_step_0: *mut QueryStep =
5994 &mut *((*(*self_0).query).steps.contents)
5995 .offset((*state_2).step_index as isize)
5996 as *mut QueryStep;
5997 if (*next_step_0).depth as libc::c_int
5998 == PATTERN_DONE_MARKER as libc::c_int
5999 {
6000 if !(*state_2).has_in_progress_alternatives() {
6001 _array__grow(
6002 &mut (*self_0).finished_states as *mut C2RustUnnamed_15
6003 as *mut Array,
6004 1 as libc::c_int as uint32_t,
6005 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
6006 );
6007 let fresh40 = (*self_0).finished_states.size;
6008 (*self_0).finished_states.size =
6009 ((*self_0).finished_states.size).wrapping_add(1);
6010 *((*self_0).finished_states.contents)
6011 .offset(fresh40 as isize) = *state_2;
6012 _array__erase(
6013 &mut (*self_0).states as *mut C2RustUnnamed_16
6014 as *mut Array,
6015 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
6016 state_2.offset_from((*self_0).states.contents)
6017 as libc::c_long
6018 as uint32_t,
6019 );
6020 did_match = 1 as libc::c_int != 0;
6021 j_0 = j_0.wrapping_sub(1);
6022 }
6023 }
6024 }
6025 }
6026 j_0 = j_0.wrapping_add(1);
6027 }
6028 }
6029 if ts_query_cursor__should_descend(self_0, node_intersects_range) {
6030 match ts_tree_cursor_goto_first_child_internal(&mut (*self_0).cursor)
6031 as libc::c_uint
6032 {
6033 2 => {
6034 current_block_189 = 10043285778187427915;
6035 match current_block_189 {
6036 17416027944940096235 => {
6037 (*self_0).on_visible_node = 0 as libc::c_int != 0;
6038 continue;
6039 }
6040 _ => {
6041 (*self_0).depth = ((*self_0).depth).wrapping_add(1);
6042 (*self_0).on_visible_node = 1 as libc::c_int != 0;
6043 continue;
6044 }
6045 }
6046 }
6047 1 => {
6048 current_block_189 = 17416027944940096235;
6049 match current_block_189 {
6050 17416027944940096235 => {
6051 (*self_0).on_visible_node = 0 as libc::c_int != 0;
6052 continue;
6053 }
6054 _ => {
6055 (*self_0).depth = ((*self_0).depth).wrapping_add(1);
6056 (*self_0).on_visible_node = 1 as libc::c_int != 0;
6057 continue;
6058 }
6059 }
6060 }
6061 _ => {}
6062 }
6063 }
6064 (*self_0).ascending = 1 as libc::c_int != 0;
6065 }
6066 }
6067}
6068#[no_mangle]
6069pub unsafe extern "C" fn ts_query_cursor_next_match(
6070 mut self_0: *mut TSQueryCursor,
6071 mut match_0: *mut TSQueryMatch,
6072) -> bool {
6073 if (*self_0).finished_states.size == 0 as libc::c_int as libc::c_uint {
6074 if !ts_query_cursor__advance(self_0, 0 as libc::c_int != 0) {
6075 return 0 as libc::c_int != 0;
6076 }
6077 }
6078 let mut state: *mut QueryState = &mut *((*self_0).finished_states.contents)
6079 .offset(0 as libc::c_int as isize) as *mut QueryState;
6080 if (*state).id == 4294967295 as libc::c_uint {
6081 let fresh41 = (*self_0).next_state_id;
6082 (*self_0).next_state_id = ((*self_0).next_state_id).wrapping_add(1);
6083 (*state).id = fresh41;
6084 }
6085 (*match_0).id = (*state).id;
6086 (*match_0).pattern_index = (*state).pattern_index;
6087 let mut captures: *const CaptureList = capture_list_pool_get(
6088 &mut (*self_0).capture_list_pool,
6089 (*state).capture_list_id as uint16_t,
6090 );
6091 (*match_0).captures = (*captures).contents;
6092 (*match_0).capture_count = (*captures).size as uint16_t;
6093 capture_list_pool_release(
6094 &mut (*self_0).capture_list_pool,
6095 (*state).capture_list_id as uint16_t,
6096 );
6097 _array__erase(
6098 &mut (*self_0).finished_states as *mut C2RustUnnamed_15 as *mut Array,
6099 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
6100 0 as libc::c_int as uint32_t,
6101 );
6102 return 1 as libc::c_int != 0;
6103}
6104#[no_mangle]
6105pub unsafe extern "C" fn ts_query_cursor_remove_match(
6106 mut self_0: *mut TSQueryCursor,
6107 mut match_id: uint32_t,
6108) {
6109 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
6110 while i < (*self_0).finished_states.size {
6111 let mut state: *const QueryState =
6112 &mut *((*self_0).finished_states.contents).offset(i as isize) as *mut QueryState;
6113 if (*state).id == match_id {
6114 capture_list_pool_release(
6115 &mut (*self_0).capture_list_pool,
6116 (*state).capture_list_id as uint16_t,
6117 );
6118 _array__erase(
6119 &mut (*self_0).finished_states as *mut C2RustUnnamed_15 as *mut Array,
6120 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
6121 i,
6122 );
6123 return;
6124 }
6125 i = i.wrapping_add(1);
6126 }
6127 let mut i_0: libc::c_uint = 0 as libc::c_int as libc::c_uint;
6128 while i_0 < (*self_0).states.size {
6129 let mut state_0: *const QueryState =
6130 &mut *((*self_0).states.contents).offset(i_0 as isize) as *mut QueryState;
6131 if (*state_0).id == match_id {
6132 capture_list_pool_release(
6133 &mut (*self_0).capture_list_pool,
6134 (*state_0).capture_list_id as uint16_t,
6135 );
6136 _array__erase(
6137 &mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array,
6138 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
6139 i_0,
6140 );
6141 return;
6142 }
6143 i_0 = i_0.wrapping_add(1);
6144 }
6145}
6146#[no_mangle]
6147pub unsafe extern "C" fn ts_query_cursor_next_capture(
6148 mut self_0: *mut TSQueryCursor,
6149 mut match_0: *mut TSQueryMatch,
6150 mut capture_index: *mut uint32_t,
6151) -> bool {
6152 loop {
6153 let mut first_unfinished_capture_byte: uint32_t = 0;
6154 let mut first_unfinished_pattern_index: uint32_t = 0;
6155 let mut first_unfinished_state_index: uint32_t = 0;
6156 let mut first_unfinished_state_is_definite: bool = 0 as libc::c_int != 0;
6157 let mut found_unfinished_state: bool = ts_query_cursor__first_in_progress_capture(
6158 self_0,
6159 &mut first_unfinished_state_index,
6160 &mut first_unfinished_capture_byte,
6161 &mut first_unfinished_pattern_index,
6162 &mut first_unfinished_state_is_definite,
6163 );
6164 let mut first_finished_state: *mut QueryState = 0 as *mut QueryState;
6165 let mut first_finished_capture_byte: uint32_t = first_unfinished_capture_byte;
6166 let mut first_finished_pattern_index: uint32_t = first_unfinished_pattern_index;
6167 let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
6168 while i < (*self_0).finished_states.size {
6169 let mut state: *mut QueryState =
6170 &mut *((*self_0).finished_states.contents).offset(i as isize) as *mut QueryState;
6171 let mut captures: *const CaptureList = capture_list_pool_get(
6172 &mut (*self_0).capture_list_pool,
6173 (*state).capture_list_id as uint16_t,
6174 );
6175 if (*state).consumed_capture_count() as libc::c_uint >= (*captures).size {
6176 capture_list_pool_release(
6177 &mut (*self_0).capture_list_pool,
6178 (*state).capture_list_id as uint16_t,
6179 );
6180 _array__erase(
6181 &mut (*self_0).finished_states as *mut C2RustUnnamed_15 as *mut Array,
6182 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
6183 i,
6184 );
6185 } else {
6186 let mut node: TSNode = (*((*captures).contents)
6187 .offset((*state).consumed_capture_count() as isize))
6188 .node;
6189 let mut node_precedes_range: bool = ts_node_end_byte(node) <= (*self_0).start_byte
6190 || point_lte(ts_node_end_point(node), (*self_0).start_point) as libc::c_int
6191 != 0;
6192 let mut node_follows_range: bool = ts_node_start_byte(node) >= (*self_0).end_byte
6193 || point_gte(ts_node_start_point(node), (*self_0).end_point) as libc::c_int
6194 != 0;
6195 let mut node_outside_of_range: bool = node_precedes_range as libc::c_int != 0
6196 || node_follows_range as libc::c_int != 0;
6197 if node_outside_of_range {
6198 (*state).set_consumed_capture_count((*state).consumed_capture_count() + 1);
6199 } else {
6200 let mut node_start_byte: uint32_t = ts_node_start_byte(node);
6201 if node_start_byte < first_finished_capture_byte
6202 || node_start_byte == first_finished_capture_byte
6203 && ((*state).pattern_index as libc::c_uint)
6204 < first_finished_pattern_index
6205 {
6206 first_finished_state = state;
6207 first_finished_capture_byte = node_start_byte;
6208 first_finished_pattern_index = (*state).pattern_index as uint32_t;
6209 }
6210 i = i.wrapping_add(1);
6211 }
6212 }
6213 }
6214 let mut state_0: *mut QueryState = 0 as *mut QueryState;
6215 if !first_finished_state.is_null() {
6216 state_0 = first_finished_state;
6217 } else if first_unfinished_state_is_definite {
6218 state_0 = &mut *((*self_0).states.contents)
6219 .offset(first_unfinished_state_index as isize)
6220 as *mut QueryState;
6221 } else {
6222 state_0 = 0 as *mut QueryState;
6223 }
6224 if !state_0.is_null() {
6225 if (*state_0).id == 4294967295 as libc::c_uint {
6226 let fresh42 = (*self_0).next_state_id;
6227 (*self_0).next_state_id = ((*self_0).next_state_id).wrapping_add(1);
6228 (*state_0).id = fresh42;
6229 }
6230 (*match_0).id = (*state_0).id;
6231 (*match_0).pattern_index = (*state_0).pattern_index;
6232 let mut captures_0: *const CaptureList = capture_list_pool_get(
6233 &mut (*self_0).capture_list_pool,
6234 (*state_0).capture_list_id as uint16_t,
6235 );
6236 (*match_0).captures = (*captures_0).contents;
6237 (*match_0).capture_count = (*captures_0).size as uint16_t;
6238 *capture_index = (*state_0).consumed_capture_count() as uint32_t;
6239 (*state_0).set_consumed_capture_count((*state_0).consumed_capture_count() + 1);
6240 return 1 as libc::c_int != 0;
6241 }
6242 if capture_list_pool_is_empty(&mut (*self_0).capture_list_pool) as libc::c_int != 0
6243 && found_unfinished_state as libc::c_int != 0
6244 {
6245 capture_list_pool_release(
6246 &mut (*self_0).capture_list_pool,
6247 (*((*self_0).states.contents).offset(first_unfinished_state_index as isize))
6248 .capture_list_id as uint16_t,
6249 );
6250 _array__erase(
6251 &mut (*self_0).states as *mut C2RustUnnamed_16 as *mut Array,
6252 ::core::mem::size_of::<QueryState>() as libc::c_ulong,
6253 first_unfinished_state_index,
6254 );
6255 }
6256 if !ts_query_cursor__advance(self_0, 1 as libc::c_int != 0)
6257 && (*self_0).finished_states.size == 0 as libc::c_int as libc::c_uint
6258 {
6259 return 0 as libc::c_int != 0;
6260 }
6261 }
6262}
6263#[no_mangle]
6264pub unsafe extern "C" fn ts_query_cursor_set_max_start_depth(
6265 mut self_0: *mut TSQueryCursor,
6266 mut max_start_depth: uint32_t,
6267) {
6268 (*self_0).max_start_depth = max_start_depth;
6269}
6270pub const TreeCursorStep_TreeCursorStepHidden: TreeCursorStep = TreeCursorStepHidden;
6271pub const TreeCursorStep_TreeCursorStepVisible: TreeCursorStep = TreeCursorStepVisible;
6272pub const TreeCursorStep_TreeCursorStepNone: TreeCursorStep = TreeCursorStepNone;