Debian Codegraph @

src/util/pm_newline_list.c

raw symbols SCIP
1 #cxx . . $ `<file>/src/util/pm_newline_list.c`/include "prism/util/pm_newline_list.h"cxx . . $ `<file>/include/prism/util/pm_newline_list.h`/
2
3 /**
4 * Initialize a new newline list with the given capacity. Returns true if the
5 * allocation of the offsets succeeds, otherwise returns false.
6 */
7 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
8 pm_newline_list_initcxx . . $ pm_newline_list_init(340008c22afd583).(pm_newline_list_tcxx . . $ pm_newline_list_t# *list, const uint8_tcxx . . $ uint8_t# *start, size_t capacity) {
9 list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets. = (size_t *) xcalloccxx . . $ `include/prism/defines.h:195:17`!(capacity, sizeof(size_t));
10 if (list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
11
12 list->startcxx . . $ $anonymous_type_9901d064858912af_0#start. = start;
13
14 // This is 1 instead of 0 because we want to include the first line of the
15 // file as having offset 0, which is set because of calloc.
16 list->sizecxx . . $ $anonymous_type_9901d064858912af_0#size. = 1;
17 list->capacitycxx . . $ $anonymous_type_9901d064858912af_0#capacity. = capacity;
18
19 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
20 }
21
22 /**
23 * Clear out the newlines that have been appended to the list.
24 */
25 void
26 pm_newline_list_clearcxx . . $ pm_newline_list_clear(6eb44ba19cf4754d).(pm_newline_list_tcxx . . $ pm_newline_list_t# *list) {
27 list->sizecxx . . $ $anonymous_type_9901d064858912af_0#size. = 1;
28 }
29
30 /**
31 * Append a new offset to the newline list. Returns true if the reallocation of
32 * the offsets succeeds (if one was necessary), otherwise returns false.
33 */
34 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
35 pm_newline_list_appendcxx . . $ pm_newline_list_append(93623494a75c4b1f).(pm_newline_list_tcxx . . $ pm_newline_list_t# *list, const uint8_tcxx . . $ uint8_t# *cursor) {
36 if (list->sizecxx . . $ $anonymous_type_9901d064858912af_0#size. == list->capacitycxx . . $ $anonymous_type_9901d064858912af_0#capacity.) {
37 size_t *original_offsets = list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets.;
38
39 list->capacitycxx . . $ $anonymous_type_9901d064858912af_0#capacity. = (list->capacitycxx . . $ $anonymous_type_9901d064858912af_0#capacity. * 3) / 2;
40 list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets. = (size_t *) xcalloccxx . . $ `include/prism/defines.h:195:17`!(list->capacitycxx . . $ $anonymous_type_9901d064858912af_0#capacity., sizeof(size_t));
41 if (list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
42
43 memcpycxx . . $ memcpy(cc817cb175f282d).(list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets., original_offsets, list->sizecxx . . $ $anonymous_type_9901d064858912af_0#size. * sizeof(size_t));
44 xfreecxx . . $ `include/prism/defines.h:203:17`!(original_offsets);
45 }
46
47 assertcxx . . $ `<external>/4398592474888995393/assert.h:108:11`!(*cursor == '\n');
48 assertcxx . . $ `<external>/4398592474888995393/assert.h:108:11`!(cursor >= list->start);
49 size_t newline_offset = (size_t) (cursor - list->startcxx . . $ $anonymous_type_9901d064858912af_0#start. + 1);
50
51 assertcxx . . $ `<external>/4398592474888995393/assert.h:108:11`!(list->size == 0 || newline_offset > list->offsets[list->size - 1]);
52 list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets.[list->sizecxx . . $ $anonymous_type_9901d064858912af_0#size.++] = newline_offset;
53
54 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
55 }
56
57 /**
58 * Returns the line of the given offset. If the offset is not in the list, the
59 * line of the closest offset less than the given offset is returned.
60 */
61 int32_tcxx . . $ int32_t#
62 pm_newline_list_linecxx . . $ pm_newline_list_line(5c8a19f31b9c22e2).(const pm_newline_list_tcxx . . $ pm_newline_list_t# *list, const uint8_tcxx . . $ uint8_t# *cursor, int32_tcxx . . $ int32_t# start_line) {
63 assertcxx . . $ `<external>/4398592474888995393/assert.h:108:11`!(cursor >= list->start);
64 size_t offset = (size_t) (cursor - list->startcxx . . $ $anonymous_type_9901d064858912af_0#start.);
65
66 size_t left = 0;
67 size_t right = list->sizecxx . . $ $anonymous_type_9901d064858912af_0#size. - 1;
68
69 while (left <= right) {
70 size_t mid = left + (right - left) / 2;
71
72 if (list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets.[mid] == offset) {
73 return ((int32_tcxx . . $ int32_t#) mid) + start_line;
74 }
75
76 if (list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets.[mid] < offset) {
77 left = mid + 1;
78 } else {
79 right = mid - 1;
80 }
81 }
82
83 return ((int32_tcxx . . $ int32_t#) left) + start_line - 1;
84 }
85
86 /**
87 * Returns the line and column of the given offset. If the offset is not in the
88 * list, the line and column of the closest offset less than the given offset
89 * are returned.
90 */
91 pm_line_column_tcxx . . $ pm_line_column_t#
92 pm_newline_list_line_columncxx . . $ pm_newline_list_line_column(1a8b391d550aa6bd).(const pm_newline_list_tcxx . . $ pm_newline_list_t# *list, const uint8_tcxx . . $ uint8_t# *cursor, int32_tcxx . . $ int32_t# start_line) {
93 assertcxx . . $ `<external>/4398592474888995393/assert.h:108:11`!(cursor >= list->start);
94 size_t offset = (size_t) (cursor - list->startcxx . . $ $anonymous_type_9901d064858912af_0#start.);
95
96 size_t left = 0;
97 size_t right = list->sizecxx . . $ $anonymous_type_9901d064858912af_0#size. - 1;
98
99 while (left <= right) {
100 size_t mid = left + (right - left) / 2;
101
102 if (list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets.[mid] == offset) {
103 return ((pm_line_column_tcxx . . $ pm_line_column_t#) { ((int32_tcxx . . $ int32_t#) mid) + start_line, 0 });
104 }
105
106 if (list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets.[mid] < offset) {
107 left = mid + 1;
108 } else {
109 right = mid - 1;
110 }
111 }
112
113 return ((pm_line_column_tcxx . . $ pm_line_column_t#) {
114 .line = ((int32_tcxx . . $ int32_t#) left) + start_line - 1,
115 .column = (uint32_tcxx . . $ uint32_t#) (offset - list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets.[left - 1])
116 });
117 }
118
119 /**
120 * Free the internal memory allocated for the newline list.
121 */
122 void
123 pm_newline_list_freecxx . . $ pm_newline_list_free(6eb44ba19cf4754d).(pm_newline_list_tcxx . . $ pm_newline_list_t# *list) {
124 xfreecxx . . $ `include/prism/defines.h:203:17`!(list->offsetscxx . . $ $anonymous_type_9901d064858912af_0#offsets.);
125 }