tree_sitter_c2rust/core_wrapper/core/
tree.rs

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