| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: init.c,v 1.153 2021/03/28 09:51:16 rillig Exp $ */ | | 1 | /* $NetBSD: init.c,v 1.154 2021/03/28 09:57:31 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.153 2021/03/28 09:51:16 rillig Exp $"); | | 40 | __RCSID("$NetBSD: init.c,v 1.154 2021/03/28 09:57:31 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 | * |
| @@ -604,42 +604,42 @@ current_initerr(void) | | | @@ -604,42 +604,42 @@ current_initerr(void) |
604 | | | 604 | |
605 | sym_t ** | | 605 | sym_t ** |
606 | current_initsym(void) | | 606 | current_initsym(void) |
607 | { | | 607 | { |
608 | return ¤t_init()->initsym; | | 608 | return ¤t_init()->initsym; |
609 | } | | 609 | } |
610 | | | 610 | |
611 | #define initsym (*current_initsym()) | | 611 | #define initsym (*current_initsym()) |
612 | | | 612 | |
613 | | | 613 | |
614 | void | | 614 | void |
615 | begin_initialization(sym_t *sym) | | 615 | begin_initialization(sym_t *sym) |
616 | { | | 616 | { |
617 | struct initialization *curr_init; | | 617 | struct initialization *in; |
618 | | | 618 | |
619 | debug_step("begin initialization of '%s'", type_name(sym->s_type)); | | 619 | debug_step("begin initialization of '%s'", type_name(sym->s_type)); |
620 | curr_init = initialization_new(sym); | | 620 | in = initialization_new(sym); |
621 | curr_init->next = init; | | 621 | in->next = init; |
622 | init = curr_init; | | 622 | init = in; |
623 | } | | 623 | } |
624 | | | 624 | |
625 | void | | 625 | void |
626 | end_initialization(void) | | 626 | end_initialization(void) |
627 | { | | 627 | { |
628 | struct initialization *curr_init; | | 628 | struct initialization *in; |
629 | | | 629 | |
630 | curr_init = init; | | 630 | in = init; |
631 | init = init->next; | | 631 | init = init->next; |
632 | initialization_free(curr_init); | | 632 | initialization_free(in); |
633 | debug_step("end initialization"); | | 633 | debug_step("end initialization"); |
634 | } | | 634 | } |
635 | | | 635 | |
636 | | | 636 | |
637 | | | 637 | |
638 | void | | 638 | void |
639 | designation_add_name(sbuf_t *sb) | | 639 | designation_add_name(sbuf_t *sb) |
640 | { | | 640 | { |
641 | designation_add(¤t_init()->designation, | | 641 | designation_add(¤t_init()->designation, |
642 | designator_new(sb->sb_name)); | | 642 | designator_new(sb->sb_name)); |
643 | } | | 643 | } |
644 | | | 644 | |
645 | /* TODO: Move the function body up here, to avoid the forward declaration. */ | | 645 | /* TODO: Move the function body up here, to avoid the forward declaration. */ |
| @@ -875,31 +875,27 @@ extend_if_array_of_unknown_size(struct i | | | @@ -875,31 +875,27 @@ extend_if_array_of_unknown_size(struct i |
875 | | | 875 | |
876 | debug_step("extended type is '%s'", type_name(level->bl_type)); | | 876 | debug_step("extended type is '%s'", type_name(level->bl_type)); |
877 | } | | 877 | } |
878 | | | 878 | |
879 | /* TODO: document me */ | | 879 | /* TODO: document me */ |
880 | /* TODO: think of a better name than 'push' */ | | 880 | /* TODO: think of a better name than 'push' */ |
881 | static void | | 881 | static void |
882 | initstack_push_array(struct initialization *in) | | 882 | initstack_push_array(struct initialization *in) |
883 | { | | 883 | { |
884 | struct brace_level *level = in->brace_level; | | 884 | struct brace_level *level = in->brace_level; |
885 | | | 885 | |
886 | if (level->bl_enclosing->bl_seen_named_member) { | | 886 | if (level->bl_enclosing->bl_seen_named_member) { |
887 | level->bl_brace = true; | | 887 | level->bl_brace = true; |
888 | debug_step("ARRAY%s%s", | | 888 | debug_step("ARRAY, seen named member, needs closing brace"); |
889 | level->bl_brace ? ", needs closing brace" : "", | | | |
890 | /* TODO: this is redundant, always true */ | | | |
891 | level->bl_enclosing->bl_seen_named_member | | | |
892 | ? ", seen named member" : ""); | | | |
893 | } | | 889 | } |
894 | | | 890 | |
895 | if (is_incomplete(level->bl_type) && | | 891 | if (is_incomplete(level->bl_type) && |
896 | level->bl_enclosing->bl_enclosing != NULL) { | | 892 | level->bl_enclosing->bl_enclosing != NULL) { |
897 | /* initialization of an incomplete type */ | | 893 | /* initialization of an incomplete type */ |
898 | error(175); | | 894 | error(175); |
899 | initialization_set_error(in); | | 895 | initialization_set_error(in); |
900 | return; | | 896 | return; |
901 | } | | 897 | } |
902 | | | 898 | |
903 | level->bl_subtype = level->bl_type->t_subt; | | 899 | level->bl_subtype = level->bl_type->t_subt; |
904 | level->bl_array_of_unknown_size = is_incomplete(level->bl_type); | | 900 | level->bl_array_of_unknown_size = is_incomplete(level->bl_type); |
905 | level->bl_remaining = level->bl_type->t_dim; | | 901 | level->bl_remaining = level->bl_type->t_dim; |