| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: init.c,v 1.144 2021/03/27 23:18:37 rillig Exp $ */ | | 1 | /* $NetBSD: init.c,v 1.145 2021/03/28 07:59:09 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1994, 1995 Jochen Pohl | | 4 | * Copyright (c) 1994, 1995 Jochen Pohl |
5 | * All Rights Reserved. | | 5 | * All Rights Reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #if HAVE_NBTOOL_CONFIG_H | | 34 | #if HAVE_NBTOOL_CONFIG_H |
35 | #include "nbtool_config.h" | | 35 | #include "nbtool_config.h" |
36 | #endif | | 36 | #endif |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | #if defined(__RCSID) && !defined(lint) | | 39 | #if defined(__RCSID) && !defined(lint) |
40 | __RCSID("$NetBSD: init.c,v 1.144 2021/03/27 23:18:37 rillig Exp $"); | | 40 | __RCSID("$NetBSD: init.c,v 1.145 2021/03/28 07:59:09 rillig Exp $"); |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | #include <stdlib.h> | | 43 | #include <stdlib.h> |
44 | #include <string.h> | | 44 | #include <string.h> |
45 | | | 45 | |
46 | #include "lint1.h" | | 46 | #include "lint1.h" |
47 | | | 47 | |
48 | | | 48 | |
49 | /* | | 49 | /* |
50 | * Initialization | | 50 | * Initialization |
51 | * | | 51 | * |
52 | * Handles initializations of global or local objects, like in: | | 52 | * Handles initializations of global or local objects, like in: |
53 | * | | 53 | * |
| @@ -247,28 +247,86 @@ struct initialization { | | | @@ -247,28 +247,86 @@ struct initialization { |
247 | | | 247 | |
248 | /* The innermost brace level. */ | | 248 | /* The innermost brace level. */ |
249 | struct brace_level *brace_level; | | 249 | struct brace_level *brace_level; |
250 | | | 250 | |
251 | /* | | 251 | /* |
252 | * The C99 designator, if any, for the current initialization | | 252 | * The C99 designator, if any, for the current initialization |
253 | * expression. | | 253 | * expression. |
254 | */ | | 254 | */ |
255 | struct designation designation; | | 255 | struct designation designation; |
256 | | | 256 | |
257 | struct initialization *next; | | 257 | struct initialization *next; |
258 | }; | | 258 | }; |
259 | | | 259 | |
| | | 260 | |
260 | static struct initialization *init; | | 261 | static struct initialization *init; |
261 | | | 262 | |
| | | 263 | #ifdef DEBUG |
| | | 264 | static int debug_ind = 0; |
| | | 265 | #endif |
| | | 266 | |
| | | 267 | |
| | | 268 | #ifdef DEBUG |
| | | 269 | |
| | | 270 | static void __printflike(1, 2) |
| | | 271 | debug_printf(const char *fmt, ...) |
| | | 272 | { |
| | | 273 | va_list va; |
| | | 274 | |
| | | 275 | va_start(va, fmt); |
| | | 276 | vfprintf(stdout, fmt, va); |
| | | 277 | va_end(va); |
| | | 278 | } |
| | | 279 | |
| | | 280 | static void |
| | | 281 | debug_indent(void) |
| | | 282 | { |
| | | 283 | debug_printf("%*s", 2 * debug_ind, ""); |
| | | 284 | } |
| | | 285 | |
| | | 286 | static void |
| | | 287 | debug_enter(const char *func) |
| | | 288 | { |
| | | 289 | printf("%*s+ %s\n", 2 * debug_ind++, "", func); |
| | | 290 | } |
| | | 291 | |
| | | 292 | static void __printflike(1, 2) |
| | | 293 | debug_step(const char *fmt, ...) |
| | | 294 | { |
| | | 295 | va_list va; |
| | | 296 | |
| | | 297 | debug_indent(); |
| | | 298 | va_start(va, fmt); |
| | | 299 | vfprintf(stdout, fmt, va); |
| | | 300 | va_end(va); |
| | | 301 | printf("\n"); |
| | | 302 | } |
| | | 303 | |
| | | 304 | static void |
| | | 305 | debug_leave(const char *func) |
| | | 306 | { |
| | | 307 | printf("%*s- %s\n", 2 * --debug_ind, "", func); |
| | | 308 | } |
| | | 309 | |
| | | 310 | #else |
| | | 311 | |
| | | 312 | #define debug_printf(fmt, ...) do { } while (false) |
| | | 313 | #define debug_indent() do { } while (false) |
| | | 314 | #define debug_enter(function) do { } while (false) |
| | | 315 | #define debug_step(fmt, ...) do { } while (false) |
| | | 316 | #define debug_leave(function) do { } while (false) |
| | | 317 | |
| | | 318 | #endif |
| | | 319 | |
262 | | | 320 | |
263 | /* XXX: unnecessary prototype since it is not recursive */ | | 321 | /* XXX: unnecessary prototype since it is not recursive */ |
264 | static bool init_array_using_string(tnode_t *); | | 322 | static bool init_array_using_string(tnode_t *); |
265 | | | 323 | |
266 | | | 324 | |
267 | static struct initialization * | | 325 | static struct initialization * |
268 | current_init(void) | | 326 | current_init(void) |
269 | { | | 327 | { |
270 | lint_assert(init != NULL); | | 328 | lint_assert(init != NULL); |
271 | return init; | | 329 | return init; |
272 | } | | 330 | } |
273 | | | 331 | |
274 | bool * | | 332 | bool * |
| @@ -323,79 +381,32 @@ free_initialization(struct initializatio | | | @@ -323,79 +381,32 @@ free_initialization(struct initializatio |
323 | static void | | 381 | static void |
324 | set_initerr(void) | | 382 | set_initerr(void) |
325 | { | | 383 | { |
326 | current_init()->initerr = true; | | 384 | current_init()->initerr = true; |
327 | } | | 385 | } |
328 | | | 386 | |
329 | #define initerr (*current_initerr()) | | 387 | #define initerr (*current_initerr()) |
330 | #define initsym (*current_initsym()) | | 388 | #define initsym (*current_initsym()) |
331 | #define brace_level_rvalue (current_brace_level()) | | 389 | #define brace_level_rvalue (current_brace_level()) |
332 | #define brace_level_lvalue (*current_brace_level_lvalue()) | | 390 | #define brace_level_lvalue (*current_brace_level_lvalue()) |
333 | | | 391 | |
334 | #ifndef DEBUG | | 392 | #ifndef DEBUG |
335 | | | 393 | |
336 | #define debug_printf(fmt, ...) do { } while (false) | | | |
337 | #define debug_indent() do { } while (false) | | | |
338 | #define debug_enter(a) do { } while (false) | | | |
339 | #define debug_step(fmt, ...) do { } while (false) | | | |
340 | #define debug_leave(a) do { } while (false) | | | |
341 | #define debug_designation() do { } while (false) | | 394 | #define debug_designation() do { } while (false) |
342 | #define debug_brace_level(level) do { } while (false) | | 395 | #define debug_brace_level(level) do { } while (false) |
343 | #define debug_initstack() do { } while (false) | | 396 | #define debug_initstack() do { } while (false) |
344 | | | 397 | |
345 | #else | | 398 | #else |
346 | | | 399 | |
347 | static int debug_ind = 0; | | | |
348 | | | | |
349 | static void __printflike(1, 2) | | | |
350 | debug_printf(const char *fmt, ...) | | | |
351 | { | | | |
352 | va_list va; | | | |
353 | | | | |
354 | va_start(va, fmt); | | | |
355 | vfprintf(stdout, fmt, va); | | | |
356 | va_end(va); | | | |
357 | } | | | |
358 | | | | |
359 | static void | | | |
360 | debug_indent(void) | | | |
361 | { | | | |
362 | debug_printf("%*s", 2 * debug_ind, ""); | | | |
363 | } | | | |
364 | | | | |
365 | static void | | | |
366 | debug_enter(const char *func) | | | |
367 | { | | | |
368 | printf("%*s+ %s\n", 2 * debug_ind++, "", func); | | | |
369 | } | | | |
370 | | | | |
371 | static void __printflike(1, 2) | | | |
372 | debug_step(const char *fmt, ...) | | | |
373 | { | | | |
374 | va_list va; | | | |
375 | | | | |
376 | printf("%*s", 2 * debug_ind, ""); | | | |
377 | va_start(va, fmt); | | | |
378 | vfprintf(stdout, fmt, va); | | | |
379 | va_end(va); | | | |
380 | printf("\n"); | | | |
381 | } | | | |
382 | | | | |
383 | static void | | | |
384 | debug_leave(const char *func) | | | |
385 | { | | | |
386 | printf("%*s- %s\n", 2 * --debug_ind, "", func); | | | |
387 | } | | | |
388 | | | | |
389 | static void | | 400 | static void |
390 | debug_designation(void) | | 401 | debug_designation(void) |
391 | { | | 402 | { |
392 | const struct designator *head = current_designation().head, *p; | | 403 | const struct designator *head = current_designation().head, *p; |
393 | if (head == NULL) | | 404 | if (head == NULL) |
394 | return; | | 405 | return; |
395 | | | 406 | |
396 | debug_indent(); | | 407 | debug_indent(); |
397 | debug_printf("designation: "); | | 408 | debug_printf("designation: "); |
398 | for (p = head; p != NULL; p = p->next) | | 409 | for (p = head; p != NULL; p = p->next) |
399 | debug_printf(".%s", p->name); | | 410 | debug_printf(".%s", p->name); |
400 | debug_printf("\n"); | | 411 | debug_printf("\n"); |
401 | } | | 412 | } |