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