| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | %{ | | 1 | %{ |
2 | /* $NetBSD: cgram.y,v 1.72 2015/10/13 16:09:33 christos Exp $ */ | | 2 | /* $NetBSD: cgram.y,v 1.73 2015/10/13 20:25:21 christos Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | | 5 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. |
6 | * Copyright (c) 1994, 1995 Jochen Pohl | | 6 | * Copyright (c) 1994, 1995 Jochen Pohl |
7 | * All Rights Reserved. | | 7 | * All Rights Reserved. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the | | 15 | * notice, this list of conditions and the following disclaimer in the |
| @@ -25,27 +25,27 @@ | | | @@ -25,27 +25,27 @@ |
25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | #if defined(__RCSID) && !defined(lint) | | 37 | #if defined(__RCSID) && !defined(lint) |
38 | __RCSID("$NetBSD: cgram.y,v 1.72 2015/10/13 16:09:33 christos Exp $"); | | 38 | __RCSID("$NetBSD: cgram.y,v 1.73 2015/10/13 20:25:21 christos Exp $"); |
39 | #endif | | 39 | #endif |
40 | | | 40 | |
41 | #include <stdlib.h> | | 41 | #include <stdlib.h> |
42 | #include <string.h> | | 42 | #include <string.h> |
43 | #include <limits.h> | | 43 | #include <limits.h> |
44 | | | 44 | |
45 | #include "lint1.h" | | 45 | #include "lint1.h" |
46 | | | 46 | |
47 | extern char *yytext; | | 47 | extern char *yytext; |
48 | /* | | 48 | /* |
49 | * Contains the level of current declaration. 0 is extern. | | 49 | * Contains the level of current declaration. 0 is extern. |
50 | * Used for symbol table entries. | | 50 | * Used for symbol table entries. |
51 | */ | | 51 | */ |
| @@ -95,26 +95,34 @@ static inline void RESTORE(const char *f | | | @@ -95,26 +95,34 @@ static inline void RESTORE(const char *f |
95 | if (olwarn != LWARN_BAD) { | | 95 | if (olwarn != LWARN_BAD) { |
96 | lwarn = olwarn; | | 96 | lwarn = olwarn; |
97 | printf("%s, %d: restore flags %s %zu = %d\n", curr_pos.p_file, | | 97 | printf("%s, %d: restore flags %s %zu = %d\n", curr_pos.p_file, |
98 | curr_pos.p_line, file, line, lwarn); | | 98 | curr_pos.p_line, file, line, lwarn); |
99 | olwarn = LWARN_BAD; | | 99 | olwarn = LWARN_BAD; |
100 | } else | | 100 | } else |
101 | CLRWFLGS(file, line); | | 101 | CLRWFLGS(file, line); |
102 | } | | 102 | } |
103 | #else | | 103 | #else |
104 | #define CLRWFLGS(f, l) clrwflgs(), olwarn = LWARN_BAD | | 104 | #define CLRWFLGS(f, l) clrwflgs(), olwarn = LWARN_BAD |
105 | #define SAVE(f, l) olwarn = lwarn | | 105 | #define SAVE(f, l) olwarn = lwarn |
106 | #define RESTORE(f, l) (void)(olwarn == LWARN_BAD ? (clrwflgs(), 0) : (lwarn = olwarn)) | | 106 | #define RESTORE(f, l) (void)(olwarn == LWARN_BAD ? (clrwflgs(), 0) : (lwarn = olwarn)) |
107 | #endif | | 107 | #endif |
| | | 108 | |
| | | 109 | /* unbind the anonymous struct members from the struct */ |
| | | 110 | static void |
| | | 111 | anonymize(sym_t *s) |
| | | 112 | { |
| | | 113 | for ( ; s; s = s->s_nxt) |
| | | 114 | s->s_styp = NULL; |
| | | 115 | } |
108 | %} | | 116 | %} |
109 | | | 117 | |
110 | %expect 80 | | 118 | %expect 80 |
111 | | | 119 | |
112 | %union { | | 120 | %union { |
113 | int y_int; | | 121 | int y_int; |
114 | val_t *y_val; | | 122 | val_t *y_val; |
115 | sbuf_t *y_sb; | | 123 | sbuf_t *y_sb; |
116 | sym_t *y_sym; | | 124 | sym_t *y_sym; |
117 | op_t y_op; | | 125 | op_t y_op; |
118 | scl_t y_scl; | | 126 | scl_t y_scl; |
119 | tspec_t y_tspec; | | 127 | tspec_t y_tspec; |
120 | tqual_t y_tqual; | | 128 | tqual_t y_tqual; |
| @@ -688,34 +696,42 @@ member_declaration: | | | @@ -688,34 +696,42 @@ member_declaration: |
688 | /* too late, i know, but getsym() compensates it */ | | 696 | /* too late, i know, but getsym() compensates it */ |
689 | symtyp = FMOS; | | 697 | symtyp = FMOS; |
690 | } notype_member_decls { | | 698 | } notype_member_decls { |
691 | symtyp = FVFT; | | 699 | symtyp = FVFT; |
692 | $$ = $4; | | 700 | $$ = $4; |
693 | } | | 701 | } |
694 | | noclass_declspecs deftyp { | | 702 | | noclass_declspecs deftyp { |
695 | symtyp = FMOS; | | 703 | symtyp = FMOS; |
696 | } type_member_decls { | | 704 | } type_member_decls { |
697 | symtyp = FVFT; | | 705 | symtyp = FVFT; |
698 | $$ = $4; | | 706 | $$ = $4; |
699 | } | | 707 | } |
700 | | noclass_declmods deftyp { | | 708 | | noclass_declmods deftyp { |
| | | 709 | symtyp = FMOS; |
701 | /* struct or union member must be named */ | | 710 | /* struct or union member must be named */ |
702 | warning(49); | | 711 | if (!Sflag) |
703 | $$ = NULL; | | 712 | warning(49); |
| | | 713 | /* add all the members of the anonymous struct/union */ |
| | | 714 | $$ = dcs->d_type->t_str->memb; |
| | | 715 | anonymize($$); |
704 | } | | 716 | } |
705 | | noclass_declspecs deftyp { | | 717 | | noclass_declspecs deftyp { |
| | | 718 | symtyp = FMOS; |
706 | /* struct or union member must be named */ | | 719 | /* struct or union member must be named */ |
707 | warning(49); | | 720 | if (!Sflag) |
708 | $$ = NULL; | | 721 | warning(49); |
| | | 722 | $$ = dcs->d_type->t_str->memb; |
| | | 723 | /* add all the members of the anonymous struct/union */ |
| | | 724 | anonymize($$); |
709 | } | | 725 | } |
710 | | error { | | 726 | | error { |
711 | symtyp = FVFT; | | 727 | symtyp = FVFT; |
712 | $$ = NULL; | | 728 | $$ = NULL; |
713 | } | | 729 | } |
714 | ; | | 730 | ; |
715 | | | 731 | |
716 | noclass_declspecs: | | 732 | noclass_declspecs: |
717 | clrtyp_typespec { | | 733 | clrtyp_typespec { |
718 | addtype($1); | | 734 | addtype($1); |
719 | } | | 735 | } |
720 | | type_attribute noclass_declspecs | | 736 | | type_attribute noclass_declspecs |
721 | | noclass_declmods typespec { | | 737 | | noclass_declmods typespec { |