1use crate::util::*;
2use crate::*;
3use c2rust_bitfields;
4use std::os;
5pub type __u8 = os::raw::c_uchar;
6pub type __int16_t = os::raw::c_short;
7pub type __u16 = os::raw::c_ushort;
8pub type __int32_t = os::raw::c_int;
9pub type __u32 = os::raw::c_uint;
10pub type __off_t = isize;
11pub type __off64_t = isize;
12type _IO_FILE = u8;
13pub type _IO_lock_t = ();
14pub type FILE = _IO_FILE;
15pub type int16_t = __int16_t;
16pub type int32_t = __int32_t;
17pub type TSSymbol = u16;
18pub type TSFieldId = u16;
19pub type TSStateId = u16;
20#[derive(Copy, Clone)]
21#[repr(C)]
22pub struct C2RustUnnamed {
23 pub states: *const bool,
24 pub symbol_map: *const TSSymbol,
25 pub create: Option<unsafe extern "C" fn() -> *mut os::raw::c_void>,
26 pub destroy: Option<unsafe extern "C" fn(*mut os::raw::c_void) -> ()>,
27 pub scan: Option<unsafe extern "C" fn(*mut os::raw::c_void, *mut TSLexer, *const bool) -> bool>,
28 pub serialize:
29 Option<unsafe extern "C" fn(*mut os::raw::c_void, *mut os::raw::c_char) -> os::raw::c_uint>,
30 pub deserialize: Option<
31 unsafe extern "C" fn(*mut os::raw::c_void, *const os::raw::c_char, os::raw::c_uint) -> (),
32 >,
33}
34#[derive(Copy, Clone)]
35#[repr(C)]
36pub struct C2RustUnnamed_0 {
37 pub count: u8,
38 pub reusable: bool,
39}
40#[derive(Copy, Clone)]
41#[repr(C)]
42pub struct C2RustUnnamed_1 {
43 pub type_: u8,
44 pub child_count: u8,
45 pub symbol: TSSymbol,
46 pub dynamic_precedence: int16_t,
47 pub production_id: u16,
48}
49#[derive(Copy, Clone)]
50#[repr(C)]
51pub struct C2RustUnnamed_2 {
52 pub type_: u8,
53 pub state: TSStateId,
54 pub extra: bool,
55 pub repetition: bool,
56}
57#[derive(Copy, Clone)]
58#[repr(C)]
59pub struct TSTree {
60 pub root: Subtree,
61 pub language: *const TSLanguage,
62 pub included_ranges: *mut TSRange,
63 pub included_range_count: os::raw::c_uint,
64}
65type C2RustUnnamed_3 = crate::util::ScannerStateWithLookahead;
66type C2RustUnnamed_4 = crate::util::LongShortData;
67type C2RustUnnamed_5 = crate::util::ScannerStateLookaheadMeta;
68type C2RustUnnamed_6 = crate::util::ScannerStateLookaheadFirstLeaf;
69#[derive(Copy, Clone)]
70#[repr(C)]
71pub struct VoidArray {
72 pub contents: *mut os::raw::c_void,
73 pub size: u32,
74 pub capacity: u32,
75}
76type C2RustUnnamed_7 = crate::util::StackElement<*mut TreeCursorEntry>;
77#[inline]
78unsafe extern "C" fn array__delete(mut self_0: *mut VoidArray) {
79 crate::alloc::ts_free((*self_0).contents);
80 let ref mut fresh0 = (*self_0).contents;
81 *fresh0 = 0 as *mut os::raw::c_void;
82 (*self_0).size = 0 as os::raw::c_int as u32;
83 (*self_0).capacity = 0 as os::raw::c_int as u32;
84}
85#[inline]
86unsafe extern "C" fn point__new(mut row: os::raw::c_uint, mut column: os::raw::c_uint) -> TSPoint {
87 let mut result: TSPoint = {
88 let mut init = TSPoint {
89 row: row,
90 column: column,
91 };
92 init
93 };
94 return result;
95}
96#[inline]
97unsafe extern "C" fn length_add(mut len1: Length, mut len2: Length) -> Length {
98 let mut result: Length = Length {
99 bytes: 0,
100 extent: TSPoint { row: 0, column: 0 },
101 };
102 result.bytes = (len1.bytes).wrapping_add(len2.bytes);
103 result.extent = point_add(len1.extent, len2.extent);
104 return result;
105}
106#[inline]
107unsafe extern "C" fn point_add(mut a: TSPoint, mut b: TSPoint) -> TSPoint {
108 if b.row > 0 as os::raw::c_int as os::raw::c_uint {
109 return point__new((a.row).wrapping_add(b.row), b.column);
110 } else {
111 return point__new(a.row, (a.column).wrapping_add(b.column));
112 };
113}
114#[inline]
115unsafe extern "C" fn point_sub(mut a: TSPoint, mut b: TSPoint) -> TSPoint {
116 if a.row > b.row {
117 return point__new((a.row).wrapping_sub(b.row), a.column);
118 } else {
119 return point__new(
120 0 as os::raw::c_int as os::raw::c_uint,
121 (a.column).wrapping_sub(b.column),
122 );
123 };
124}
125#[inline]
126unsafe extern "C" fn ts_subtree_padding(mut self_0: Subtree) -> Length {
127 if (self_0.data).is_inline() {
128 let mut result: Length = {
129 let mut init = Length {
130 bytes: self_0.data.padding_bytes as u32,
131 extent: {
132 let mut init = TSPoint {
133 row: (self_0.data).padding_rows() as u32,
134 column: self_0.data.padding_columns as u32,
135 };
136 init
137 },
138 };
139 init
140 };
141 return result;
142 } else {
143 return (*self_0.ptr).padding;
144 };
145}
146#[no_mangle]
147pub unsafe extern "C" fn ts_tree_new(
148 mut root: Subtree,
149 mut language: *const TSLanguage,
150 mut included_ranges: *const TSRange,
151 mut included_range_count: os::raw::c_uint,
152) -> *mut TSTree {
153 let mut result: *mut TSTree =
154 crate::alloc::ts_malloc(::std::mem::size_of::<TSTree>() as usize) as *mut TSTree;
155 (*result).root = root;
156 let ref mut fresh1 = (*result).language;
157 *fresh1 = language;
158 let ref mut fresh2 = (*result).included_ranges;
159 *fresh2 = crate::alloc::ts_calloc(
160 included_range_count as size_t,
161 ::std::mem::size_of::<TSRange>() as usize,
162 ) as *mut TSRange;
163 std::ptr::copy_nonoverlapping(
164 included_ranges as *const os::raw::c_void,
165 (*result).included_ranges as *mut os::raw::c_void,
166 (included_range_count as usize).wrapping_mul(::std::mem::size_of::<TSRange>() as usize),
167 );
168 (*result).included_range_count = included_range_count;
169 return result;
170}
171#[no_mangle]
172pub unsafe extern "C" fn ts_tree_copy(mut self_0: *const TSTree) -> *mut TSTree {
173 ts_subtree_retain((*self_0).root);
174 return ts_tree_new(
175 (*self_0).root,
176 (*self_0).language,
177 (*self_0).included_ranges,
178 (*self_0).included_range_count,
179 );
180}
181#[no_mangle]
182pub unsafe extern "C" fn ts_tree_delete(mut self_0: *mut TSTree) {
183 if self_0.is_null() {
184 return;
185 }
186 let mut pool: SubtreePool = ts_subtree_pool_new(0 as os::raw::c_int as u32);
187 ts_subtree_release(&mut pool, (*self_0).root);
188 ts_subtree_pool_delete(&mut pool);
189 crate::alloc::ts_free((*self_0).included_ranges as *mut os::raw::c_void);
190 crate::alloc::ts_free(self_0 as *mut os::raw::c_void);
191}
192#[no_mangle]
193pub unsafe extern "C" fn ts_tree_root_node(mut self_0: *const TSTree) -> TSNode {
194 return ts_node_new(
195 self_0,
196 &(*self_0).root,
197 ts_subtree_padding((*self_0).root),
198 0 as os::raw::c_int as TSSymbol,
199 );
200}
201#[no_mangle]
202pub unsafe extern "C" fn ts_tree_root_node_with_offset(
203 mut self_0: *const TSTree,
204 mut offset_bytes: u32,
205 mut offset_extent: TSPoint,
206) -> TSNode {
207 let mut offset: Length = {
208 let mut init = Length {
209 bytes: offset_bytes,
210 extent: offset_extent,
211 };
212 init
213 };
214 return ts_node_new(
215 self_0,
216 &(*self_0).root,
217 length_add(offset, ts_subtree_padding((*self_0).root)),
218 0 as os::raw::c_int as TSSymbol,
219 );
220}
221#[no_mangle]
222pub unsafe extern "C" fn ts_tree_language(mut self_0: *const TSTree) -> *const TSLanguage {
223 return (*self_0).language;
224}
225#[no_mangle]
226pub unsafe extern "C" fn ts_tree_edit(mut self_0: *mut TSTree, mut edit: *const TSInputEdit) {
227 let mut i: os::raw::c_uint = 0 as os::raw::c_int as os::raw::c_uint;
228 while i < (*self_0).included_range_count {
229 let mut range: *mut TSRange =
230 &mut *((*self_0).included_ranges).offset(i as isize) as *mut TSRange;
231 if (*range).end_byte >= (*edit).old_end_byte {
232 if (*range).end_byte != 4294967295 as os::raw::c_uint {
233 (*range).end_byte = ((*edit).new_end_byte)
234 .wrapping_add(((*range).end_byte).wrapping_sub((*edit).old_end_byte));
235 (*range).end_point = point_add(
236 (*edit).new_end_point,
237 point_sub((*range).end_point, (*edit).old_end_point),
238 );
239 if (*range).end_byte < (*edit).new_end_byte {
240 (*range).end_byte = 4294967295 as os::raw::c_uint;
241 (*range).end_point = {
242 let mut init = TSPoint {
243 row: 4294967295 as os::raw::c_uint,
244 column: 4294967295 as os::raw::c_uint,
245 };
246 init
247 };
248 }
249 }
250 if (*range).start_byte >= (*edit).old_end_byte {
251 (*range).start_byte = ((*edit).new_end_byte)
252 .wrapping_add(((*range).start_byte).wrapping_sub((*edit).old_end_byte));
253 (*range).start_point = point_add(
254 (*edit).new_end_point,
255 point_sub((*range).start_point, (*edit).old_end_point),
256 );
257 if (*range).start_byte < (*edit).new_end_byte {
258 (*range).start_byte = 4294967295 as os::raw::c_uint;
259 (*range).start_point = {
260 let mut init = TSPoint {
261 row: 4294967295 as os::raw::c_uint,
262 column: 4294967295 as os::raw::c_uint,
263 };
264 init
265 };
266 }
267 }
268 }
269 i = i.wrapping_add(1);
270 }
271 let mut pool: SubtreePool = ts_subtree_pool_new(0 as os::raw::c_int as u32);
272 (*self_0).root = ts_subtree_edit((*self_0).root, edit, &mut pool);
273 ts_subtree_pool_delete(&mut pool);
274}
275#[no_mangle]
276pub unsafe extern "C" fn ts_tree_get_changed_ranges(
277 mut self_0: *const TSTree,
278 mut other: *const TSTree,
279 mut count: *mut u32,
280) -> *mut TSRange {
281 let mut cursor1: TreeCursor = {
282 let mut init = TreeCursor {
283 tree: 0 as *const TSTree,
284 stack: {
285 let mut init = C2RustUnnamed_7 {
286 contents: 0 as *mut TreeCursorEntry,
287 size: 0 as os::raw::c_int as u32,
288 capacity: 0 as os::raw::c_int as u32,
289 };
290 init
291 },
292 };
293 init
294 };
295 let mut cursor2: TreeCursor = {
296 let mut init = TreeCursor {
297 tree: 0 as *const TSTree,
298 stack: {
299 let mut init = C2RustUnnamed_7 {
300 contents: 0 as *mut TreeCursorEntry,
301 size: 0 as os::raw::c_int as u32,
302 capacity: 0 as os::raw::c_int as u32,
303 };
304 init
305 },
306 };
307 init
308 };
309 ts_tree_cursor_init(&mut cursor1, ts_tree_root_node(self_0));
310 ts_tree_cursor_init(&mut cursor2, ts_tree_root_node(other));
311 let mut included_range_differences: TSRangeArray = {
312 let mut init = TSRangeArray {
313 contents: 0 as *mut TSRange,
314 size: 0 as os::raw::c_int as u32,
315 capacity: 0 as os::raw::c_int as u32,
316 };
317 init
318 };
319 ts_range_array_get_changed_ranges(
320 (*self_0).included_ranges,
321 (*self_0).included_range_count,
322 (*other).included_ranges,
323 (*other).included_range_count,
324 &mut included_range_differences,
325 );
326 let mut result: *mut TSRange = 0 as *mut TSRange;
327 *count = ts_subtree_get_changed_ranges(
328 &(*self_0).root,
329 &(*other).root,
330 &mut cursor1,
331 &mut cursor2,
332 (*self_0).language,
333 &mut included_range_differences,
334 &mut result,
335 );
336 array__delete(&mut included_range_differences as *mut TSRangeArray as *mut VoidArray);
337 array__delete(&mut cursor1.stack as *mut C2RustUnnamed_7 as *mut VoidArray);
338 array__delete(&mut cursor2.stack as *mut C2RustUnnamed_7 as *mut VoidArray);
339 return result;
340}
341#[no_mangle]
342pub unsafe extern "C" fn ts_tree_print_dot_graph(mut self_0: *const TSTree, mut file: *mut FILE) {
343 ts_subtree_print_dot_graph((*self_0).root, (*self_0).language, file);
344}