| @@ -1,392 +1,393 @@ | | | @@ -1,392 +1,393 @@ |
1 | /* $NetBSD: debug.c,v 1.64 2023/06/16 11:48:32 rillig Exp $ */ | | 1 | /* $NetBSD: debug.c,v 1.65 2023/06/16 23:17:22 rillig Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2023 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2023 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Roland Illig <rillig@NetBSD.org>. | | 8 | * by Roland Illig <rillig@NetBSD.org>. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __RCSID("$NetBSD: debug.c,v 1.64 2023/06/16 11:48:32 rillig Exp $"); | | 33 | __RCSID("$NetBSD: debug.c,v 1.65 2023/06/16 23:17:22 rillig Exp $"); |
34 | | | 34 | |
35 | #include <stdarg.h> | | 35 | #include <stdarg.h> |
36 | #include <string.h> | | 36 | #include <string.h> |
37 | | | 37 | |
38 | #include "indent.h" | | 38 | #include "indent.h" |
39 | | | 39 | |
40 | #ifdef debug | | 40 | #ifdef debug |
41 | | | 41 | |
42 | static struct { | | 42 | static struct { |
43 | // false show only the changes to the parser state | | 43 | // false show only the changes to the parser state |
44 | // true show unchanged parts of the parser state as well | | 44 | // true show unchanged parts of the parser state as well |
45 | bool full_parser_state; | | 45 | bool full_parser_state; |
46 | } config = { | | 46 | } config = { |
47 | .full_parser_state = false, | | 47 | .full_parser_state = false, |
48 | }; | | 48 | }; |
49 | | | 49 | |
50 | const char *const lsym_name[] = { | | 50 | const char *const lsym_name[] = { |
51 | "eof", | | 51 | "eof", |
52 | "preprocessing", | | 52 | "preprocessing", |
53 | "newline", | | 53 | "newline", |
54 | "comment", | | 54 | "comment", |
55 | "lparen", | | 55 | "lparen", |
56 | "rparen", | | 56 | "rparen", |
57 | "lbracket", | | 57 | "lbracket", |
58 | "rbracket", | | 58 | "rbracket", |
59 | "lbrace", | | 59 | "lbrace", |
60 | "rbrace", | | 60 | "rbrace", |
61 | "period", | | 61 | "period", |
62 | "unary_op", | | 62 | "unary_op", |
63 | "sizeof", | | 63 | "sizeof", |
64 | "offsetof", | | 64 | "offsetof", |
65 | "postfix_op", | | 65 | "postfix_op", |
66 | "binary_op", | | 66 | "binary_op", |
67 | "question", | | 67 | "question", |
68 | "question_colon", | | 68 | "question_colon", |
69 | "comma", | | 69 | "comma", |
70 | "typedef", | | 70 | "typedef", |
71 | "modifier", | | 71 | "modifier", |
72 | "tag", | | 72 | "tag", |
73 | "type_outside_parentheses", | | 73 | "type_outside_parentheses", |
74 | "type_in_parentheses", | | 74 | "type_in_parentheses", |
75 | "word", | | 75 | "word", |
76 | "funcname", | | 76 | "funcname", |
77 | "label_colon", | | 77 | "label_colon", |
78 | "other_colon", | | 78 | "other_colon", |
79 | "semicolon", | | 79 | "semicolon", |
80 | "case", | | 80 | "case", |
81 | "default", | | 81 | "default", |
82 | "do", | | 82 | "do", |
83 | "else", | | 83 | "else", |
84 | "for", | | 84 | "for", |
85 | "if", | | 85 | "if", |
86 | "switch", | | 86 | "switch", |
87 | "while", | | 87 | "while", |
88 | "return", | | 88 | "return", |
89 | }; | | 89 | }; |
90 | | | 90 | |
91 | const char *const psym_name[] = { | | 91 | const char *const psym_name[] = { |
92 | "-", | | 92 | "-", |
93 | "{block", | | 93 | "{block", |
94 | "{struct", | | 94 | "{struct", |
95 | "{union", | | 95 | "{union", |
96 | "{enum", | | 96 | "{enum", |
97 | "}", | | 97 | "}", |
98 | "decl", | | 98 | "decl", |
99 | "stmt", | | 99 | "stmt", |
100 | "for_exprs", | | 100 | "for_exprs", |
101 | "if_expr", | | 101 | "if_expr", |
102 | "if_expr_stmt", | | 102 | "if_expr_stmt", |
103 | "if_expr_stmt_else", | | 103 | "if_expr_stmt_else", |
104 | "else", | | 104 | "else", |
105 | "switch_expr", | | 105 | "switch_expr", |
106 | "do", | | 106 | "do", |
107 | "do_stmt", | | 107 | "do_stmt", |
108 | "while_expr", | | 108 | "while_expr", |
109 | }; | | 109 | }; |
110 | | | 110 | |
111 | static const char *const declaration_name[] = { | | 111 | static const char *const declaration_name[] = { |
112 | "no", | | 112 | "no", |
113 | "begin", | | 113 | "begin", |
114 | "end", | | 114 | "end", |
115 | }; | | 115 | }; |
116 | | | 116 | |
117 | const char *const paren_level_cast_name[] = { | | 117 | const char *const paren_level_cast_name[] = { |
118 | "(unknown cast)", | | 118 | "(unknown cast)", |
119 | "(maybe cast)", | | 119 | "(maybe cast)", |
120 | "(no cast)", | | 120 | "(no cast)", |
121 | }; | | 121 | }; |
122 | | | 122 | |
123 | const char *const line_kind_name[] = { | | 123 | const char *const line_kind_name[] = { |
124 | "other", | | 124 | "other", |
125 | "blank", | | 125 | "blank", |
126 | "#if", | | 126 | "#if", |
127 | "#endif", | | 127 | "#endif", |
128 | "#other", | | 128 | "#other", |
129 | "stmt head", | | 129 | "stmt head", |
130 | "}", | | 130 | "}", |
131 | "block comment", | | 131 | "block comment", |
132 | "case/default", | | 132 | "case/default", |
133 | }; | | 133 | }; |
134 | | | 134 | |
135 | static const char *const extra_expr_indent_name[] = { | | 135 | static const char *const extra_expr_indent_name[] = { |
136 | "no", | | 136 | "no", |
137 | "maybe", | | 137 | "maybe", |
138 | "last", | | 138 | "last", |
139 | }; | | 139 | }; |
140 | | | 140 | |
141 | static struct { | | 141 | static struct { |
142 | struct parser_state prev_ps; | | 142 | struct parser_state prev_ps; |
143 | bool ps_first; | | 143 | bool ps_first; |
144 | const char *heading; | | 144 | const char *heading; |
145 | unsigned wrote_newlines; | | 145 | unsigned wrote_newlines; |
146 | } state = { | | 146 | } state = { |
147 | .ps_first = true, | | 147 | .ps_first = true, |
148 | .wrote_newlines = 1, | | 148 | .wrote_newlines = 1, |
149 | }; | | 149 | }; |
150 | | | 150 | |
151 | void | | 151 | void |
152 | debug_printf(const char *fmt, ...) | | 152 | debug_printf(const char *fmt, ...) |
153 | { | | 153 | { |
154 | FILE *f = output == stdout ? stderr : stdout; | | 154 | FILE *f = output == stdout ? stderr : stdout; |
155 | va_list ap; | | 155 | va_list ap; |
156 | | | 156 | |
157 | if (state.heading != NULL) { | | 157 | if (state.heading != NULL) { |
158 | fprintf(f, "%s\n", state.heading); | | 158 | fprintf(f, "%s\n", state.heading); |
159 | state.heading = NULL; | | 159 | state.heading = NULL; |
160 | } | | 160 | } |
161 | va_start(ap, fmt); | | 161 | va_start(ap, fmt); |
162 | vfprintf(f, fmt, ap); | | 162 | vfprintf(f, fmt, ap); |
163 | va_end(ap); | | 163 | va_end(ap); |
164 | state.wrote_newlines = 0; | | 164 | state.wrote_newlines = 0; |
165 | } | | 165 | } |
166 | | | 166 | |
167 | void | | 167 | void |
168 | debug_println(const char *fmt, ...) | | 168 | debug_println(const char *fmt, ...) |
169 | { | | 169 | { |
170 | FILE *f = output == stdout ? stderr : stdout; | | 170 | FILE *f = output == stdout ? stderr : stdout; |
171 | va_list ap; | | 171 | va_list ap; |
172 | | | 172 | |
173 | if (state.heading != NULL) { | | 173 | if (state.heading != NULL) { |
174 | fprintf(f, "%s\n", state.heading); | | 174 | fprintf(f, "%s\n", state.heading); |
175 | state.heading = NULL; | | 175 | state.heading = NULL; |
176 | state.wrote_newlines = 1; | | 176 | state.wrote_newlines = 1; |
177 | } | | 177 | } |
178 | va_start(ap, fmt); | | 178 | va_start(ap, fmt); |
179 | vfprintf(f, fmt, ap); | | 179 | vfprintf(f, fmt, ap); |
180 | va_end(ap); | | 180 | va_end(ap); |
181 | fprintf(f, "\n"); | | 181 | fprintf(f, "\n"); |
182 | state.wrote_newlines = fmt[0] == '\0' ? state.wrote_newlines + 1 : 1; | | 182 | state.wrote_newlines = fmt[0] == '\0' ? state.wrote_newlines + 1 : 1; |
183 | } | | 183 | } |
184 | | | 184 | |
185 | void | | 185 | void |
186 | debug_blank_line(void) | | 186 | debug_blank_line(void) |
187 | { | | 187 | { |
188 | while (state.wrote_newlines < 2) | | 188 | while (state.wrote_newlines < 2) |
189 | debug_println(""); | | 189 | debug_println(""); |
190 | } | | 190 | } |
191 | | | 191 | |
192 | void | | 192 | void |
193 | debug_vis_range(const char *s, size_t len) | | 193 | debug_vis_range(const char *s, size_t len) |
194 | { | | 194 | { |
195 | debug_printf("\""); | | 195 | debug_printf("\""); |
196 | for (size_t i = 0; i < len; i++) { | | 196 | for (size_t i = 0; i < len; i++) { |
197 | const char *p = s + i; | | 197 | const char *p = s + i; |
198 | if (*p == '\\' || *p == '"') | | 198 | if (*p == '\\' || *p == '"') |
199 | debug_printf("\\%c", *p); | | 199 | debug_printf("\\%c", *p); |
200 | else if (isprint((unsigned char)*p)) | | 200 | else if (isprint((unsigned char)*p)) |
201 | debug_printf("%c", *p); | | 201 | debug_printf("%c", *p); |
202 | else if (*p == '\n') | | 202 | else if (*p == '\n') |
203 | debug_printf("\\n"); | | 203 | debug_printf("\\n"); |
204 | else if (*p == '\t') | | 204 | else if (*p == '\t') |
205 | debug_printf("\\t"); | | 205 | debug_printf("\\t"); |
206 | else | | 206 | else |
207 | debug_printf("\\x%02x", (unsigned char)*p); | | 207 | debug_printf("\\x%02x", (unsigned char)*p); |
208 | } | | 208 | } |
209 | debug_printf("\""); | | 209 | debug_printf("\""); |
210 | } | | 210 | } |
211 | | | 211 | |
212 | void | | 212 | void |
213 | debug_print_buf(const char *name, const struct buffer *buf) | | 213 | debug_print_buf(const char *name, const struct buffer *buf) |
214 | { | | 214 | { |
215 | if (buf->len > 0) { | | 215 | if (buf->len > 0) { |
216 | debug_printf(" %s ", name); | | 216 | debug_printf(" %s ", name); |
217 | debug_vis_range(buf->s, buf->len); | | 217 | debug_vis_range(buf->s, buf->len); |
218 | } | | 218 | } |
219 | } | | 219 | } |
220 | | | 220 | |
221 | void | | 221 | void |
222 | debug_buffers(void) | | 222 | debug_buffers(void) |
223 | { | | 223 | { |
224 | debug_print_buf("label", &lab); | | 224 | debug_print_buf("label", &lab); |
225 | debug_print_buf("code", &code); | | 225 | debug_print_buf("code", &code); |
226 | debug_print_buf("comment", &com); | | 226 | debug_print_buf("comment", &com); |
227 | debug_blank_line(); | | 227 | debug_blank_line(); |
228 | } | | 228 | } |
229 | | | 229 | |
230 | static void | | 230 | static void |
231 | debug_ps_bool_member(const char *name, bool prev, bool curr) | | 231 | debug_ps_bool_member(const char *name, bool prev, bool curr) |
232 | { | | 232 | { |
233 | if (!state.ps_first && curr != prev) { | | 233 | if (!state.ps_first && curr != prev) { |
234 | char diff = " -+x"[(prev ? 1 : 0) + (curr ? 2 : 0)]; | | 234 | char diff = " -+x"[(prev ? 1 : 0) + (curr ? 2 : 0)]; |
235 | debug_println(" [%c] ps.%s", diff, name); | | 235 | debug_println(" [%c] ps.%s", diff, name); |
236 | } else if (config.full_parser_state || state.ps_first) | | 236 | } else if (config.full_parser_state || state.ps_first) |
237 | debug_println(" [%c] ps.%s", curr ? 'x' : ' ', name); | | 237 | debug_println(" [%c] ps.%s", curr ? 'x' : ' ', name); |
238 | } | | 238 | } |
239 | | | 239 | |
240 | static void | | 240 | static void |
241 | debug_ps_int_member(const char *name, int prev, int curr) | | 241 | debug_ps_int_member(const char *name, int prev, int curr) |
242 | { | | 242 | { |
243 | if (!state.ps_first && curr != prev) | | 243 | if (!state.ps_first && curr != prev) |
244 | debug_println(" %3d -> %3d ps.%s", prev, curr, name); | | 244 | debug_println(" %3d -> %3d ps.%s", prev, curr, name); |
245 | else if (config.full_parser_state || state.ps_first) | | 245 | else if (config.full_parser_state || state.ps_first) |
246 | debug_println(" %3d ps.%s", curr, name); | | 246 | debug_println(" %3d ps.%s", curr, name); |
247 | } | | 247 | } |
248 | | | 248 | |
249 | static void | | 249 | static void |
250 | debug_ps_enum_member(const char *name, const char *prev, const char *curr) | | 250 | debug_ps_enum_member(const char *name, const char *prev, const char *curr) |
251 | { | | 251 | { |
252 | if (!state.ps_first && strcmp(prev, curr) != 0) | | 252 | if (!state.ps_first && strcmp(prev, curr) != 0) |
253 | debug_println(" %3s -> %3s ps.%s", prev, curr, name); | | 253 | debug_println(" %3s -> %3s ps.%s", prev, curr, name); |
254 | else if (config.full_parser_state || state.ps_first) | | 254 | else if (config.full_parser_state || state.ps_first) |
255 | debug_println(" %10s ps.%s", curr, name); | | 255 | debug_println(" %10s ps.%s", curr, name); |
256 | } | | 256 | } |
257 | | | 257 | |
258 | static bool | | 258 | static bool |
259 | paren_stack_equal(const struct paren_stack *a, const struct paren_stack *b) | | 259 | paren_stack_equal(const struct paren_stack *a, const struct paren_stack *b) |
260 | { | | 260 | { |
261 | if (a->len != b->len) | | 261 | if (a->len != b->len) |
262 | return false; | | 262 | return false; |
263 | | | 263 | |
264 | for (size_t i = 0, n = a->len; i < n; i++) | | 264 | for (size_t i = 0, n = a->len; i < n; i++) |
265 | if (a->item[i].indent != b->item[i].indent | | 265 | if (a->item[i].indent != b->item[i].indent |
266 | || a->item[i].cast != b->item[i].cast) | | 266 | || a->item[i].cast != b->item[i].cast) |
267 | return true; | | 267 | return true; |
268 | return false; | | 268 | return false; |
269 | } | | 269 | } |
270 | | | 270 | |
271 | static void | | 271 | static void |
272 | debug_ps_paren(void) | | 272 | debug_ps_paren(void) |
273 | { | | 273 | { |
274 | if (!config.full_parser_state | | 274 | if (!config.full_parser_state |
275 | && paren_stack_equal(&state.prev_ps.paren, &ps.paren) | | 275 | && paren_stack_equal(&state.prev_ps.paren, &ps.paren) |
276 | && !state.ps_first) | | 276 | && !state.ps_first) |
277 | return; | | 277 | return; |
278 | | | 278 | |
279 | debug_printf(" ps.paren:"); | | 279 | debug_printf(" ps.paren:"); |
280 | for (size_t i = 0; i < ps.paren.len; i++) { | | 280 | for (size_t i = 0; i < ps.paren.len; i++) { |
281 | debug_printf(" %s%d", | | 281 | debug_printf(" %s%d", |
282 | paren_level_cast_name[ps.paren.item[i].cast], | | 282 | paren_level_cast_name[ps.paren.item[i].cast], |
283 | ps.paren.item[i].indent); | | 283 | ps.paren.item[i].indent); |
284 | } | | 284 | } |
285 | if (ps.paren.len == 0) | | 285 | if (ps.paren.len == 0) |
286 | debug_printf(" none"); | | 286 | debug_printf(" none"); |
287 | debug_println(""); | | 287 | debug_println(""); |
288 | } | | 288 | } |
289 | | | 289 | |
290 | static bool | | 290 | static bool |
291 | ps_di_stack_has_changed(void) | | 291 | ps_di_stack_has_changed(void) |
292 | { | | 292 | { |
293 | if (state.prev_ps.decl_level != ps.decl_level) | | 293 | if (state.prev_ps.decl_level != ps.decl_level) |
294 | return true; | | 294 | return true; |
295 | for (int i = 0; i < ps.decl_level; i++) | | 295 | for (int i = 0; i < ps.decl_level; i++) |
296 | if (state.prev_ps.di_stack[i] != ps.di_stack[i]) | | 296 | if (state.prev_ps.di_stack[i] != ps.di_stack[i]) |
297 | return true; | | 297 | return true; |
298 | return false; | | 298 | return false; |
299 | } | | 299 | } |
300 | | | 300 | |
301 | static void | | 301 | static void |
302 | debug_ps_di_stack(void) | | 302 | debug_ps_di_stack(void) |
303 | { | | 303 | { |
304 | bool changed = ps_di_stack_has_changed(); | | 304 | bool changed = ps_di_stack_has_changed(); |
305 | if (!config.full_parser_state && !changed && !state.ps_first) | | 305 | if (!config.full_parser_state && !changed && !state.ps_first) |
306 | return; | | 306 | return; |
307 | | | 307 | |
308 | debug_printf(" %s ps.di_stack:", changed ? "->" : " "); | | 308 | debug_printf(" %s ps.di_stack:", changed ? "->" : " "); |
309 | for (int i = 0; i < ps.decl_level; i++) | | 309 | for (int i = 0; i < ps.decl_level; i++) |
310 | debug_printf(" %d", ps.di_stack[i]); | | 310 | debug_printf(" %d", ps.di_stack[i]); |
311 | if (ps.decl_level == 0) | | 311 | if (ps.decl_level == 0) |
312 | debug_printf(" none"); | | 312 | debug_printf(" none"); |
313 | debug_println(""); | | 313 | debug_println(""); |
314 | } | | 314 | } |
315 | | | 315 | |
316 | #define debug_ps_bool(name) \ | | 316 | #define debug_ps_bool(name) \ |
317 | debug_ps_bool_member(#name, state.prev_ps.name, ps.name) | | 317 | debug_ps_bool_member(#name, state.prev_ps.name, ps.name) |
318 | #define debug_ps_int(name) \ | | 318 | #define debug_ps_int(name) \ |
319 | debug_ps_int_member(#name, state.prev_ps.name, ps.name) | | 319 | debug_ps_int_member(#name, state.prev_ps.name, ps.name) |
320 | #define debug_ps_enum(name, names) \ | | 320 | #define debug_ps_enum(name, names) \ |
321 | debug_ps_enum_member(#name, (names)[state.prev_ps.name], \ | | 321 | debug_ps_enum_member(#name, (names)[state.prev_ps.name], \ |
322 | (names)[ps.name]) | | 322 | (names)[ps.name]) |
323 | | | 323 | |
324 | void | | 324 | void |
325 | debug_parser_state(void) | | 325 | debug_parser_state(void) |
326 | { | | 326 | { |
327 | debug_blank_line(); | | 327 | debug_blank_line(); |
328 | | | 328 | |
329 | state.heading = "token classification"; | | 329 | state.heading = "token classification"; |
330 | debug_ps_enum(prev_lsym, lsym_name); | | 330 | debug_ps_enum(prev_lsym, lsym_name); |
331 | debug_ps_bool(in_stmt_or_decl); | | 331 | debug_ps_bool(in_stmt_or_decl); |
332 | debug_ps_bool(in_decl); | | 332 | debug_ps_bool(in_decl); |
| | | 333 | debug_ps_bool(in_typedef_decl); |
333 | debug_ps_bool(in_var_decl); | | 334 | debug_ps_bool(in_var_decl); |
334 | debug_ps_bool(in_init); | | 335 | debug_ps_bool(in_init); |
335 | debug_ps_int(init_level); | | 336 | debug_ps_int(init_level); |
336 | debug_ps_bool(line_has_func_def); | | 337 | debug_ps_bool(line_has_func_def); |
337 | debug_ps_bool(in_func_def_params); | | 338 | debug_ps_bool(in_func_def_params); |
338 | debug_ps_bool(line_has_decl); | | 339 | debug_ps_bool(line_has_decl); |
339 | debug_ps_enum(lbrace_kind, psym_name); | | 340 | debug_ps_enum(lbrace_kind, psym_name); |
340 | debug_ps_enum(spaced_expr_psym, psym_name); | | 341 | debug_ps_enum(spaced_expr_psym, psym_name); |
341 | debug_ps_bool(seen_case); | | 342 | debug_ps_bool(seen_case); |
342 | debug_ps_bool(prev_paren_was_cast); | | 343 | debug_ps_bool(prev_paren_was_cast); |
343 | debug_ps_int(quest_level); | | 344 | debug_ps_int(quest_level); |
344 | | | 345 | |
345 | state.heading = "indentation of statements and declarations"; | | 346 | state.heading = "indentation of statements and declarations"; |
346 | debug_ps_int(ind_level); | | 347 | debug_ps_int(ind_level); |
347 | debug_ps_int(ind_level_follow); | | 348 | debug_ps_int(ind_level_follow); |
348 | debug_ps_bool(line_is_stmt_cont); | | 349 | debug_ps_bool(line_is_stmt_cont); |
349 | debug_ps_int(decl_level); | | 350 | debug_ps_int(decl_level); |
350 | debug_ps_di_stack(); | | 351 | debug_ps_di_stack(); |
351 | debug_ps_bool(decl_indent_done); | | 352 | debug_ps_bool(decl_indent_done); |
352 | debug_ps_int(decl_ind); | | 353 | debug_ps_int(decl_ind); |
353 | debug_ps_bool(tabs_to_var); | | 354 | debug_ps_bool(tabs_to_var); |
354 | debug_ps_enum(extra_expr_indent, extra_expr_indent_name); | | 355 | debug_ps_enum(extra_expr_indent, extra_expr_indent_name); |
355 | | | 356 | |
356 | // The parser symbol stack is printed in debug_psyms_stack instead. | | 357 | // The parser symbol stack is printed in debug_psyms_stack instead. |
357 | | | 358 | |
358 | state.heading = "spacing inside a statement or declaration"; | | 359 | state.heading = "spacing inside a statement or declaration"; |
359 | debug_ps_bool(next_unary); | | 360 | debug_ps_bool(next_unary); |
360 | debug_ps_bool(want_blank); | | 361 | debug_ps_bool(want_blank); |
361 | debug_ps_int(ind_paren_level); | | 362 | debug_ps_int(ind_paren_level); |
362 | debug_ps_paren(); | | 363 | debug_ps_paren(); |
363 | | | 364 | |
364 | state.heading = "indentation of comments"; | | 365 | state.heading = "indentation of comments"; |
365 | debug_ps_int(comment_ind); | | 366 | debug_ps_int(comment_ind); |
366 | debug_ps_int(comment_shift); | | 367 | debug_ps_int(comment_shift); |
367 | debug_ps_bool(comment_cont); | | 368 | debug_ps_bool(comment_cont); |
368 | | | 369 | |
369 | state.heading = "vertical spacing"; | | 370 | state.heading = "vertical spacing"; |
370 | debug_ps_bool(break_after_comma); | | 371 | debug_ps_bool(break_after_comma); |
371 | debug_ps_bool(want_newline); | | 372 | debug_ps_bool(want_newline); |
372 | debug_ps_enum(declaration, declaration_name); | | 373 | debug_ps_enum(declaration, declaration_name); |
373 | debug_ps_bool(blank_line_after_decl); | | 374 | debug_ps_bool(blank_line_after_decl); |
374 | | | 375 | |
375 | state.heading = NULL; | | 376 | state.heading = NULL; |
376 | debug_blank_line(); | | 377 | debug_blank_line(); |
377 | | | 378 | |
378 | state.prev_ps = ps; | | 379 | state.prev_ps = ps; |
379 | state.ps_first = false; | | 380 | state.ps_first = false; |
380 | } | | 381 | } |
381 | | | 382 | |
382 | void | | 383 | void |
383 | debug_psyms_stack(const char *situation) | | 384 | debug_psyms_stack(const char *situation) |
384 | { | | 385 | { |
385 | debug_printf("parse stack %s:", situation); | | 386 | debug_printf("parse stack %s:", situation); |
386 | const struct psym_stack *psyms = &ps.psyms; | | 387 | const struct psym_stack *psyms = &ps.psyms; |
387 | for (size_t i = 0; i < psyms->len; ++i) | | 388 | for (size_t i = 0; i < psyms->len; ++i) |
388 | debug_printf(" %d %s", | | 389 | debug_printf(" %d %s", |
389 | psyms->ind_level[i], psym_name[psyms->sym[i]]); | | 390 | psyms->ind_level[i], psym_name[psyms->sym[i]]); |
390 | debug_println(""); | | 391 | debug_println(""); |
391 | } | | 392 | } |
392 | #endif | | 393 | #endif |