| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | %{ | | 1 | %{ |
2 | /* $NetBSD: cgram.y,v 1.201 2021/03/26 16:05:19 rillig Exp $ */ | | 2 | /* $NetBSD: cgram.y,v 1.202 2021/03/26 17:44:52 rillig 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.201 2021/03/26 16:05:19 rillig Exp $"); | | 38 | __RCSID("$NetBSD: cgram.y,v 1.202 2021/03/26 17:44:52 rillig Exp $"); |
39 | #endif | | 39 | #endif |
40 | | | 40 | |
41 | #include <limits.h> | | 41 | #include <limits.h> |
42 | #include <stdlib.h> | | 42 | #include <stdlib.h> |
43 | #include <string.h> | | 43 | #include <string.h> |
44 | | | 44 | |
45 | #include "lint1.h" | | 45 | #include "lint1.h" |
46 | | | 46 | |
47 | extern char *yytext; | | 47 | extern char *yytext; |
48 | | | 48 | |
49 | /* | | 49 | /* |
50 | * Contains the level of current declaration, used for symbol table entries. | | 50 | * Contains the level of current declaration, used for symbol table entries. |
51 | * 0 is the top-level, > 0 is inside a function body. | | 51 | * 0 is the top-level, > 0 is inside a function body. |
| @@ -429,31 +429,31 @@ function_definition: /* C99 6.9.1 */ | | | @@ -429,31 +429,31 @@ function_definition: /* C99 6.9.1 */ |
429 | func_decl { | | 429 | func_decl { |
430 | if ($1->s_type->t_tspec != FUNC) { | | 430 | if ($1->s_type->t_tspec != FUNC) { |
431 | /* syntax error '%s' */ | | 431 | /* syntax error '%s' */ |
432 | error(249, yytext); | | 432 | error(249, yytext); |
433 | YYERROR; | | 433 | YYERROR; |
434 | } | | 434 | } |
435 | if ($1->s_type->t_typedef) { | | 435 | if ($1->s_type->t_typedef) { |
436 | /* ()-less function definition */ | | 436 | /* ()-less function definition */ |
437 | error(64); | | 437 | error(64); |
438 | YYERROR; | | 438 | YYERROR; |
439 | } | | 439 | } |
440 | funcdef($1); | | 440 | funcdef($1); |
441 | block_level++; | | 441 | block_level++; |
442 | pushdecl(ARG); | | 442 | begin_declaration_level(ARG); |
443 | if (lwarn == LWARN_NONE) | | 443 | if (lwarn == LWARN_NONE) |
444 | $1->s_used = true; | | 444 | $1->s_used = true; |
445 | } arg_declaration_list_opt { | | 445 | } arg_declaration_list_opt { |
446 | popdecl(); | | 446 | end_declaration_level(); |
447 | block_level--; | | 447 | block_level--; |
448 | check_func_lint_directives(); | | 448 | check_func_lint_directives(); |
449 | check_func_old_style_arguments(); | | 449 | check_func_old_style_arguments(); |
450 | pushctrl(0); | | 450 | pushctrl(0); |
451 | } compound_statement { | | 451 | } compound_statement { |
452 | funcend(); | | 452 | funcend(); |
453 | popctrl(0); | | 453 | popctrl(0); |
454 | } | | 454 | } |
455 | ; | | 455 | ; |
456 | | | 456 | |
457 | func_decl: | | 457 | func_decl: |
458 | clrtyp deftyp notype_decl { | | 458 | clrtyp deftyp notype_decl { |
459 | $$ = $3; | | 459 | $$ = $3; |
| @@ -693,31 +693,31 @@ typespec: | | | @@ -693,31 +693,31 @@ typespec: |
693 | | T_TYPENAME { | | 693 | | T_TYPENAME { |
694 | $$ = getsym($1)->s_type; | | 694 | $$ = getsym($1)->s_type; |
695 | } | | 695 | } |
696 | ; | | 696 | ; |
697 | | | 697 | |
698 | notype_typespec: | | 698 | notype_typespec: |
699 | T_TYPE { | | 699 | T_TYPE { |
700 | $$ = gettyp($1); | | 700 | $$ = gettyp($1); |
701 | } | | 701 | } |
702 | | T_TYPEOF term { | | 702 | | T_TYPEOF term { |
703 | $$ = $2->tn_type; | | 703 | $$ = $2->tn_type; |
704 | } | | 704 | } |
705 | | struct_spec { | | 705 | | struct_spec { |
706 | popdecl(); | | 706 | end_declaration_level(); |
707 | $$ = $1; | | 707 | $$ = $1; |
708 | } | | 708 | } |
709 | | enum_spec { | | 709 | | enum_spec { |
710 | popdecl(); | | 710 | end_declaration_level(); |
711 | $$ = $1; | | 711 | $$ = $1; |
712 | } | | 712 | } |
713 | ; | | 713 | ; |
714 | | | 714 | |
715 | struct_spec: | | 715 | struct_spec: |
716 | struct struct_tag { | | 716 | struct struct_tag { |
717 | /* | | 717 | /* |
718 | * STDC requires that "struct a;" always introduces | | 718 | * STDC requires that "struct a;" always introduces |
719 | * a new tag if "a" is not declared at current level | | 719 | * a new tag if "a" is not declared at current level |
720 | * | | 720 | * |
721 | * yychar is valid because otherwise the parser would not | | 721 | * yychar is valid because otherwise the parser would not |
722 | * have been able to decide if it must shift or reduce | | 722 | * have been able to decide if it must shift or reduce |
723 | */ | | 723 | */ |
| @@ -733,27 +733,27 @@ struct_spec: | | | @@ -733,27 +733,27 @@ struct_spec: |
733 | } struct_declaration { | | 733 | } struct_declaration { |
734 | $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3); | | 734 | $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3); |
735 | } | | 735 | } |
736 | | struct error { | | 736 | | struct error { |
737 | symtyp = FVFT; | | 737 | symtyp = FVFT; |
738 | $$ = gettyp(INT); | | 738 | $$ = gettyp(INT); |
739 | } | | 739 | } |
740 | ; | | 740 | ; |
741 | | | 741 | |
742 | struct: | | 742 | struct: |
743 | struct type_attribute | | 743 | struct type_attribute |
744 | | T_STRUCT_OR_UNION { | | 744 | | T_STRUCT_OR_UNION { |
745 | symtyp = FTAG; | | 745 | symtyp = FTAG; |
746 | pushdecl($1 == STRUCT ? MOS : MOU); | | 746 | begin_declaration_level($1 == STRUCT ? MOS : MOU); |
747 | dcs->d_offset = 0; | | 747 | dcs->d_offset = 0; |
748 | dcs->d_stralign = CHAR_SIZE; | | 748 | dcs->d_stralign = CHAR_SIZE; |
749 | $$ = $1; | | 749 | $$ = $1; |
750 | } | | 750 | } |
751 | ; | | 751 | ; |
752 | | | 752 | |
753 | struct_tag: | | 753 | struct_tag: |
754 | identifier { | | 754 | identifier { |
755 | $$ = getsym($1); | | 755 | $$ = getsym($1); |
756 | } | | 756 | } |
757 | ; | | 757 | ; |
758 | | | 758 | |
759 | struct_declaration: | | 759 | struct_declaration: |
| @@ -930,27 +930,27 @@ enum_spec: | | | @@ -930,27 +930,27 @@ enum_spec: |
930 | dcs->d_tagtyp = mktag(NULL, ENUM, true, false); | | 930 | dcs->d_tagtyp = mktag(NULL, ENUM, true, false); |
931 | } enum_declaration { | | 931 | } enum_declaration { |
932 | $$ = complete_tag_enum(dcs->d_tagtyp, $3); | | 932 | $$ = complete_tag_enum(dcs->d_tagtyp, $3); |
933 | } | | 933 | } |
934 | | enum error { | | 934 | | enum error { |
935 | symtyp = FVFT; | | 935 | symtyp = FVFT; |
936 | $$ = gettyp(INT); | | 936 | $$ = gettyp(INT); |
937 | } | | 937 | } |
938 | ; | | 938 | ; |
939 | | | 939 | |
940 | enum: | | 940 | enum: |
941 | T_ENUM { | | 941 | T_ENUM { |
942 | symtyp = FTAG; | | 942 | symtyp = FTAG; |
943 | pushdecl(CTCONST); | | 943 | begin_declaration_level(CTCONST); |
944 | } | | 944 | } |
945 | ; | | 945 | ; |
946 | | | 946 | |
947 | enum_tag: | | 947 | enum_tag: |
948 | identifier { | | 948 | identifier { |
949 | $$ = getsym($1); | | 949 | $$ = getsym($1); |
950 | } | | 950 | } |
951 | ; | | 951 | ; |
952 | | | 952 | |
953 | enum_declaration: | | 953 | enum_declaration: |
954 | enum_decl_lbrace enums_with_opt_comma T_RBRACE { | | 954 | enum_decl_lbrace enums_with_opt_comma T_RBRACE { |
955 | $$ = $2; | | 955 | $$ = $2; |
956 | } | | 956 | } |
| @@ -1062,27 +1062,27 @@ notype_direct_decl: | | | @@ -1062,27 +1062,27 @@ notype_direct_decl: |
1062 | $$ = $2; | | 1062 | $$ = $2; |
1063 | } | | 1063 | } |
1064 | | type_attribute notype_direct_decl { | | 1064 | | type_attribute notype_direct_decl { |
1065 | $$ = $2; | | 1065 | $$ = $2; |
1066 | } | | 1066 | } |
1067 | | notype_direct_decl T_LBRACK T_RBRACK { | | 1067 | | notype_direct_decl T_LBRACK T_RBRACK { |
1068 | $$ = add_array($1, false, 0); | | 1068 | $$ = add_array($1, false, 0); |
1069 | } | | 1069 | } |
1070 | | notype_direct_decl T_LBRACK constant_expr T_RBRACK { | | 1070 | | notype_direct_decl T_LBRACK constant_expr T_RBRACK { |
1071 | $$ = add_array($1, true, to_int_constant($3, false)); | | 1071 | $$ = add_array($1, true, to_int_constant($3, false)); |
1072 | } | | 1072 | } |
1073 | | notype_direct_decl param_list opt_asm_or_symbolrename { | | 1073 | | notype_direct_decl param_list opt_asm_or_symbolrename { |
1074 | $$ = add_function(symbolrename($1, $3), $2); | | 1074 | $$ = add_function(symbolrename($1, $3), $2); |
1075 | popdecl(); | | 1075 | end_declaration_level(); |
1076 | block_level--; | | 1076 | block_level--; |
1077 | } | | 1077 | } |
1078 | | notype_direct_decl type_attribute_list | | 1078 | | notype_direct_decl type_attribute_list |
1079 | ; | | 1079 | ; |
1080 | | | 1080 | |
1081 | type_decl: | | 1081 | type_decl: |
1082 | type_direct_decl { | | 1082 | type_direct_decl { |
1083 | $$ = $1; | | 1083 | $$ = $1; |
1084 | } | | 1084 | } |
1085 | | pointer type_direct_decl { | | 1085 | | pointer type_direct_decl { |
1086 | $$ = add_pointer($2, $1); | | 1086 | $$ = add_pointer($2, $1); |
1087 | } | | 1087 | } |
1088 | ; | | 1088 | ; |
| @@ -1095,27 +1095,27 @@ type_direct_decl: | | | @@ -1095,27 +1095,27 @@ type_direct_decl: |
1095 | $$ = $2; | | 1095 | $$ = $2; |
1096 | } | | 1096 | } |
1097 | | type_attribute type_direct_decl { | | 1097 | | type_attribute type_direct_decl { |
1098 | $$ = $2; | | 1098 | $$ = $2; |
1099 | } | | 1099 | } |
1100 | | type_direct_decl T_LBRACK T_RBRACK { | | 1100 | | type_direct_decl T_LBRACK T_RBRACK { |
1101 | $$ = add_array($1, false, 0); | | 1101 | $$ = add_array($1, false, 0); |
1102 | } | | 1102 | } |
1103 | | type_direct_decl T_LBRACK constant_expr T_RBRACK { | | 1103 | | type_direct_decl T_LBRACK constant_expr T_RBRACK { |
1104 | $$ = add_array($1, true, to_int_constant($3, false)); | | 1104 | $$ = add_array($1, true, to_int_constant($3, false)); |
1105 | } | | 1105 | } |
1106 | | type_direct_decl param_list opt_asm_or_symbolrename { | | 1106 | | type_direct_decl param_list opt_asm_or_symbolrename { |
1107 | $$ = add_function(symbolrename($1, $3), $2); | | 1107 | $$ = add_function(symbolrename($1, $3), $2); |
1108 | popdecl(); | | 1108 | end_declaration_level(); |
1109 | block_level--; | | 1109 | block_level--; |
1110 | } | | 1110 | } |
1111 | | type_direct_decl type_attribute_list | | 1111 | | type_direct_decl type_attribute_list |
1112 | ; | | 1112 | ; |
1113 | | | 1113 | |
1114 | /* | | 1114 | /* |
1115 | * param_decl and notype_param_decl exist to avoid a conflict in | | 1115 | * param_decl and notype_param_decl exist to avoid a conflict in |
1116 | * argument lists. A typename enclosed in parens should always be | | 1116 | * argument lists. A typename enclosed in parens should always be |
1117 | * treated as a typename, not an argument. | | 1117 | * treated as a typename, not an argument. |
1118 | * "typedef int a; f(int (a));" is "typedef int a; f(int foo(a));" | | 1118 | * "typedef int a; f(int (a));" is "typedef int a; f(int foo(a));" |
1119 | * not "typedef int a; f(int a);" | | 1119 | * not "typedef int a; f(int a);" |
1120 | */ | | 1120 | */ |
1121 | param_decl: | | 1121 | param_decl: |
| @@ -1135,27 +1135,27 @@ direct_param_decl: | | | @@ -1135,27 +1135,27 @@ direct_param_decl: |
1135 | $$ = declarator_name(getsym($1)); | | 1135 | $$ = declarator_name(getsym($1)); |
1136 | } | | 1136 | } |
1137 | | T_LPAREN notype_param_decl T_RPAREN { | | 1137 | | T_LPAREN notype_param_decl T_RPAREN { |
1138 | $$ = $2; | | 1138 | $$ = $2; |
1139 | } | | 1139 | } |
1140 | | direct_param_decl T_LBRACK T_RBRACK { | | 1140 | | direct_param_decl T_LBRACK T_RBRACK { |
1141 | $$ = add_array($1, false, 0); | | 1141 | $$ = add_array($1, false, 0); |
1142 | } | | 1142 | } |
1143 | | direct_param_decl T_LBRACK constant_expr T_RBRACK { | | 1143 | | direct_param_decl T_LBRACK constant_expr T_RBRACK { |
1144 | $$ = add_array($1, true, to_int_constant($3, false)); | | 1144 | $$ = add_array($1, true, to_int_constant($3, false)); |
1145 | } | | 1145 | } |
1146 | | direct_param_decl param_list opt_asm_or_symbolrename { | | 1146 | | direct_param_decl param_list opt_asm_or_symbolrename { |
1147 | $$ = add_function(symbolrename($1, $3), $2); | | 1147 | $$ = add_function(symbolrename($1, $3), $2); |
1148 | popdecl(); | | 1148 | end_declaration_level(); |
1149 | block_level--; | | 1149 | block_level--; |
1150 | } | | 1150 | } |
1151 | ; | | 1151 | ; |
1152 | | | 1152 | |
1153 | notype_param_decl: | | 1153 | notype_param_decl: |
1154 | direct_notype_param_decl { | | 1154 | direct_notype_param_decl { |
1155 | $$ = $1; | | 1155 | $$ = $1; |
1156 | } | | 1156 | } |
1157 | | pointer direct_notype_param_decl { | | 1157 | | pointer direct_notype_param_decl { |
1158 | $$ = add_pointer($2, $1); | | 1158 | $$ = add_pointer($2, $1); |
1159 | } | | 1159 | } |
1160 | ; | | 1160 | ; |
1161 | | | 1161 | |
| @@ -1164,27 +1164,27 @@ direct_notype_param_decl: | | | @@ -1164,27 +1164,27 @@ direct_notype_param_decl: |
1164 | $$ = declarator_name(getsym($1)); | | 1164 | $$ = declarator_name(getsym($1)); |
1165 | } | | 1165 | } |
1166 | | T_LPAREN notype_param_decl T_RPAREN { | | 1166 | | T_LPAREN notype_param_decl T_RPAREN { |
1167 | $$ = $2; | | 1167 | $$ = $2; |
1168 | } | | 1168 | } |
1169 | | direct_notype_param_decl T_LBRACK T_RBRACK { | | 1169 | | direct_notype_param_decl T_LBRACK T_RBRACK { |
1170 | $$ = add_array($1, false, 0); | | 1170 | $$ = add_array($1, false, 0); |
1171 | } | | 1171 | } |
1172 | | direct_notype_param_decl T_LBRACK constant_expr T_RBRACK { | | 1172 | | direct_notype_param_decl T_LBRACK constant_expr T_RBRACK { |
1173 | $$ = add_array($1, true, to_int_constant($3, false)); | | 1173 | $$ = add_array($1, true, to_int_constant($3, false)); |
1174 | } | | 1174 | } |
1175 | | direct_notype_param_decl param_list opt_asm_or_symbolrename { | | 1175 | | direct_notype_param_decl param_list opt_asm_or_symbolrename { |
1176 | $$ = add_function(symbolrename($1, $3), $2); | | 1176 | $$ = add_function(symbolrename($1, $3), $2); |
1177 | popdecl(); | | 1177 | end_declaration_level(); |
1178 | block_level--; | | 1178 | block_level--; |
1179 | } | | 1179 | } |
1180 | ; | | 1180 | ; |
1181 | | | 1181 | |
1182 | pointer: | | 1182 | pointer: |
1183 | asterisk { | | 1183 | asterisk { |
1184 | $$ = $1; | | 1184 | $$ = $1; |
1185 | } | | 1185 | } |
1186 | | asterisk type_qualifier_list { | | 1186 | | asterisk type_qualifier_list { |
1187 | $$ = merge_pointers_and_qualifiers($1, $2); | | 1187 | $$ = merge_pointers_and_qualifiers($1, $2); |
1188 | } | | 1188 | } |
1189 | | asterisk pointer { | | 1189 | | asterisk pointer { |
1190 | $$ = merge_pointers_and_qualifiers($1, $2); | | 1190 | $$ = merge_pointers_and_qualifiers($1, $2); |
| @@ -1226,27 +1226,27 @@ type_qualifier: | | | @@ -1226,27 +1226,27 @@ type_qualifier: |
1226 | | | 1226 | |
1227 | param_list: | | 1227 | param_list: |
1228 | id_list_lparen identifier_list T_RPAREN { | | 1228 | id_list_lparen identifier_list T_RPAREN { |
1229 | $$ = $2; | | 1229 | $$ = $2; |
1230 | } | | 1230 | } |
1231 | | abstract_decl_param_list { | | 1231 | | abstract_decl_param_list { |
1232 | $$ = $1; | | 1232 | $$ = $1; |
1233 | } | | 1233 | } |
1234 | ; | | 1234 | ; |
1235 | | | 1235 | |
1236 | id_list_lparen: | | 1236 | id_list_lparen: |
1237 | T_LPAREN { | | 1237 | T_LPAREN { |
1238 | block_level++; | | 1238 | block_level++; |
1239 | pushdecl(PROTO_ARG); | | 1239 | begin_declaration_level(PROTO_ARG); |
1240 | } | | 1240 | } |
1241 | ; | | 1241 | ; |
1242 | | | 1242 | |
1243 | identifier_list: | | 1243 | identifier_list: |
1244 | T_NAME { | | 1244 | T_NAME { |
1245 | $$ = old_style_function_name(getsym($1)); | | 1245 | $$ = old_style_function_name(getsym($1)); |
1246 | } | | 1246 | } |
1247 | | identifier_list T_COMMA T_NAME { | | 1247 | | identifier_list T_COMMA T_NAME { |
1248 | $$ = lnklst($1, old_style_function_name(getsym($3))); | | 1248 | $$ = lnklst($1, old_style_function_name(getsym($3))); |
1249 | } | | 1249 | } |
1250 | | identifier_list error { | | 1250 | | identifier_list error { |
1251 | $$ = $1; | | 1251 | $$ = $1; |
1252 | } | | 1252 | } |
| @@ -1258,27 +1258,27 @@ abstract_decl_param_list: | | | @@ -1258,27 +1258,27 @@ abstract_decl_param_list: |
1258 | } | | 1258 | } |
1259 | | abstract_decl_lparen vararg_parameter_type_list T_RPAREN { | | 1259 | | abstract_decl_lparen vararg_parameter_type_list T_RPAREN { |
1260 | dcs->d_proto = true; | | 1260 | dcs->d_proto = true; |
1261 | $$ = $2; | | 1261 | $$ = $2; |
1262 | } | | 1262 | } |
1263 | | abstract_decl_lparen error T_RPAREN { | | 1263 | | abstract_decl_lparen error T_RPAREN { |
1264 | $$ = NULL; | | 1264 | $$ = NULL; |
1265 | } | | 1265 | } |
1266 | ; | | 1266 | ; |
1267 | | | 1267 | |
1268 | abstract_decl_lparen: | | 1268 | abstract_decl_lparen: |
1269 | T_LPAREN { | | 1269 | T_LPAREN { |
1270 | block_level++; | | 1270 | block_level++; |
1271 | pushdecl(PROTO_ARG); | | 1271 | begin_declaration_level(PROTO_ARG); |
1272 | } | | 1272 | } |
1273 | ; | | 1273 | ; |
1274 | | | 1274 | |
1275 | vararg_parameter_type_list: | | 1275 | vararg_parameter_type_list: |
1276 | parameter_type_list { | | 1276 | parameter_type_list { |
1277 | $$ = $1; | | 1277 | $$ = $1; |
1278 | } | | 1278 | } |
1279 | | parameter_type_list T_COMMA T_ELLIPSIS { | | 1279 | | parameter_type_list T_COMMA T_ELLIPSIS { |
1280 | dcs->d_vararg = true; | | 1280 | dcs->d_vararg = true; |
1281 | $$ = $1; | | 1281 | $$ = $1; |
1282 | } | | 1282 | } |
1283 | | T_ELLIPSIS { | | 1283 | | T_ELLIPSIS { |
1284 | if (sflag) { | | 1284 | if (sflag) { |
| @@ -1410,29 +1410,29 @@ init_lbrace: | | | @@ -1410,29 +1410,29 @@ init_lbrace: |
1410 | T_LBRACE { | | 1410 | T_LBRACE { |
1411 | init_lbrace(); | | 1411 | init_lbrace(); |
1412 | } | | 1412 | } |
1413 | ; | | 1413 | ; |
1414 | | | 1414 | |
1415 | init_rbrace: | | 1415 | init_rbrace: |
1416 | T_RBRACE { | | 1416 | T_RBRACE { |
1417 | init_rbrace(); | | 1417 | init_rbrace(); |
1418 | } | | 1418 | } |
1419 | ; | | 1419 | ; |
1420 | | | 1420 | |
1421 | type_name: | | 1421 | type_name: |
1422 | { | | 1422 | { |
1423 | pushdecl(ABSTRACT); | | 1423 | begin_declaration_level(ABSTRACT); |
1424 | } abstract_declaration { | | 1424 | } abstract_declaration { |
1425 | popdecl(); | | 1425 | end_declaration_level(); |
1426 | $$ = $2->s_type; | | 1426 | $$ = $2->s_type; |
1427 | } | | 1427 | } |
1428 | ; | | 1428 | ; |
1429 | | | 1429 | |
1430 | abstract_declaration: | | 1430 | abstract_declaration: |
1431 | noclass_declmods deftyp { | | 1431 | noclass_declmods deftyp { |
1432 | $$ = declare_1_abstract(abstract_name()); | | 1432 | $$ = declare_1_abstract(abstract_name()); |
1433 | } | | 1433 | } |
1434 | | noclass_declspecs deftyp { | | 1434 | | noclass_declspecs deftyp { |
1435 | $$ = declare_1_abstract(abstract_name()); | | 1435 | $$ = declare_1_abstract(abstract_name()); |
1436 | } | | 1436 | } |
1437 | | noclass_declmods deftyp abstract_decl { | | 1437 | | noclass_declmods deftyp abstract_decl { |
1438 | $$ = declare_1_abstract($3); | | 1438 | $$ = declare_1_abstract($3); |
| @@ -1468,32 +1468,32 @@ direct_abstract_decl: | | | @@ -1468,32 +1468,32 @@ direct_abstract_decl: |
1468 | $$ = add_array(abstract_name(), true, to_int_constant($2, false)); | | 1468 | $$ = add_array(abstract_name(), true, to_int_constant($2, false)); |
1469 | } | | 1469 | } |
1470 | | type_attribute direct_abstract_decl { | | 1470 | | type_attribute direct_abstract_decl { |
1471 | $$ = $2; | | 1471 | $$ = $2; |
1472 | } | | 1472 | } |
1473 | | direct_abstract_decl T_LBRACK T_RBRACK { | | 1473 | | direct_abstract_decl T_LBRACK T_RBRACK { |
1474 | $$ = add_array($1, false, 0); | | 1474 | $$ = add_array($1, false, 0); |
1475 | } | | 1475 | } |
1476 | | direct_abstract_decl T_LBRACK constant_expr T_RBRACK { | | 1476 | | direct_abstract_decl T_LBRACK constant_expr T_RBRACK { |
1477 | $$ = add_array($1, true, to_int_constant($3, false)); | | 1477 | $$ = add_array($1, true, to_int_constant($3, false)); |
1478 | } | | 1478 | } |
1479 | | abstract_decl_param_list opt_asm_or_symbolrename { | | 1479 | | abstract_decl_param_list opt_asm_or_symbolrename { |
1480 | $$ = add_function(symbolrename(abstract_name(), $2), $1); | | 1480 | $$ = add_function(symbolrename(abstract_name(), $2), $1); |
1481 | popdecl(); | | 1481 | end_declaration_level(); |
1482 | block_level--; | | 1482 | block_level--; |
1483 | } | | 1483 | } |
1484 | | direct_abstract_decl abstract_decl_param_list opt_asm_or_symbolrename { | | 1484 | | direct_abstract_decl abstract_decl_param_list opt_asm_or_symbolrename { |
1485 | $$ = add_function(symbolrename($1, $3), $2); | | 1485 | $$ = add_function(symbolrename($1, $3), $2); |
1486 | popdecl(); | | 1486 | end_declaration_level(); |
1487 | block_level--; | | 1487 | block_level--; |
1488 | } | | 1488 | } |
1489 | | direct_abstract_decl type_attribute_list | | 1489 | | direct_abstract_decl type_attribute_list |
1490 | ; | | 1490 | ; |
1491 | | | 1491 | |
1492 | non_expr_statement: | | 1492 | non_expr_statement: |
1493 | labeled_statement | | 1493 | labeled_statement |
1494 | | compound_statement | | 1494 | | compound_statement |
1495 | | selection_statement | | 1495 | | selection_statement |
1496 | | iteration_statement | | 1496 | | iteration_statement |
1497 | | jump_statement { | | 1497 | | jump_statement { |
1498 | seen_fallthrough = false; | | 1498 | seen_fallthrough = false; |
1499 | } | | 1499 | } |
| @@ -1527,33 +1527,33 @@ label: | | | @@ -1527,33 +1527,33 @@ label: |
1527 | seen_fallthrough = true; | | 1527 | seen_fallthrough = true; |
1528 | } | | 1528 | } |
1529 | ; | | 1529 | ; |
1530 | | | 1530 | |
1531 | compound_statement: /* C99 6.8.2 */ | | 1531 | compound_statement: /* C99 6.8.2 */ |
1532 | compound_statement_lbrace compound_statement_rbrace | | 1532 | compound_statement_lbrace compound_statement_rbrace |
1533 | | compound_statement_lbrace block_item_list compound_statement_rbrace | | 1533 | | compound_statement_lbrace block_item_list compound_statement_rbrace |
1534 | ; | | 1534 | ; |
1535 | | | 1535 | |
1536 | compound_statement_lbrace: | | 1536 | compound_statement_lbrace: |
1537 | T_LBRACE { | | 1537 | T_LBRACE { |
1538 | block_level++; | | 1538 | block_level++; |
1539 | mem_block_level++; | | 1539 | mem_block_level++; |
1540 | pushdecl(AUTO); | | 1540 | begin_declaration_level(AUTO); |
1541 | } | | 1541 | } |
1542 | ; | | 1542 | ; |
1543 | | | 1543 | |
1544 | compound_statement_rbrace: | | 1544 | compound_statement_rbrace: |
1545 | T_RBRACE { | | 1545 | T_RBRACE { |
1546 | popdecl(); | | 1546 | end_declaration_level(); |
1547 | freeblk(); | | 1547 | freeblk(); |
1548 | mem_block_level--; | | 1548 | mem_block_level--; |
1549 | block_level--; | | 1549 | block_level--; |
1550 | seen_fallthrough = false; | | 1550 | seen_fallthrough = false; |
1551 | } | | 1551 | } |
1552 | ; | | 1552 | ; |
1553 | | | 1553 | |
1554 | block_item_list: | | 1554 | block_item_list: |
1555 | block_item | | 1555 | block_item |
1556 | | block_item_list block_item { | | 1556 | | block_item_list block_item { |
1557 | if (!Sflag && $1 && !$2) | | 1557 | if (!Sflag && $1 && !$2) |
1558 | /* declarations after statements is a C99 feature */ | | 1558 | /* declarations after statements is a C99 feature */ |
1559 | c99ism(327); | | 1559 | c99ism(327); |
| @@ -1686,59 +1686,59 @@ iteration_statement: /* C99 6.8.5 */ | | | @@ -1686,59 +1686,59 @@ iteration_statement: /* C99 6.8.5 */ |
1686 | while2(); | | 1686 | while2(); |
1687 | } | | 1687 | } |
1688 | | do_statement do_while_expr { | | 1688 | | do_statement do_while_expr { |
1689 | do2($2); | | 1689 | do2($2); |
1690 | seen_fallthrough = false; | | 1690 | seen_fallthrough = false; |
1691 | } | | 1691 | } |
1692 | | do error { | | 1692 | | do error { |
1693 | clear_warning_flags(); | | 1693 | clear_warning_flags(); |
1694 | do2(NULL); | | 1694 | do2(NULL); |
1695 | } | | 1695 | } |
1696 | | for_exprs statement { | | 1696 | | for_exprs statement { |
1697 | clear_warning_flags(); | | 1697 | clear_warning_flags(); |
1698 | for2(); | | 1698 | for2(); |
1699 | popdecl(); | | 1699 | end_declaration_level(); |
1700 | block_level--; | | 1700 | block_level--; |
1701 | } | | 1701 | } |
1702 | | for_exprs error { | | 1702 | | for_exprs error { |
1703 | clear_warning_flags(); | | 1703 | clear_warning_flags(); |
1704 | for2(); | | 1704 | for2(); |
1705 | popdecl(); | | 1705 | end_declaration_level(); |
1706 | block_level--; | | 1706 | block_level--; |
1707 | } | | 1707 | } |
1708 | ; | | 1708 | ; |
1709 | | | 1709 | |
1710 | while_expr: | | 1710 | while_expr: |
1711 | T_WHILE T_LPAREN expr T_RPAREN { | | 1711 | T_WHILE T_LPAREN expr T_RPAREN { |
1712 | while1($3); | | 1712 | while1($3); |
1713 | clear_warning_flags(); | | 1713 | clear_warning_flags(); |
1714 | } | | 1714 | } |
1715 | ; | | 1715 | ; |
1716 | | | 1716 | |
1717 | do: | | 1717 | do: |
1718 | T_DO { | | 1718 | T_DO { |
1719 | do1(); | | 1719 | do1(); |
1720 | } | | 1720 | } |
1721 | ; | | 1721 | ; |
1722 | | | 1722 | |
1723 | do_while_expr: | | 1723 | do_while_expr: |
1724 | T_WHILE T_LPAREN expr T_RPAREN T_SEMI { | | 1724 | T_WHILE T_LPAREN expr T_RPAREN T_SEMI { |
1725 | $$ = $3; | | 1725 | $$ = $3; |
1726 | } | | 1726 | } |
1727 | ; | | 1727 | ; |
1728 | | | 1728 | |
1729 | for_start: | | 1729 | for_start: |
1730 | T_FOR T_LPAREN { | | 1730 | T_FOR T_LPAREN { |
1731 | pushdecl(AUTO); | | 1731 | begin_declaration_level(AUTO); |
1732 | block_level++; | | 1732 | block_level++; |
1733 | } | | 1733 | } |
1734 | ; | | 1734 | ; |
1735 | for_exprs: | | 1735 | for_exprs: |
1736 | for_start declaration_specifiers deftyp notype_init_decls T_SEMI | | 1736 | for_start declaration_specifiers deftyp notype_init_decls T_SEMI |
1737 | opt_expr T_SEMI opt_expr T_RPAREN { | | 1737 | opt_expr T_SEMI opt_expr T_RPAREN { |
1738 | /* variable declaration in for loop */ | | 1738 | /* variable declaration in for loop */ |
1739 | c99ism(325); | | 1739 | c99ism(325); |
1740 | for1(NULL, $6, $8); | | 1740 | for1(NULL, $6, $8); |
1741 | clear_warning_flags(); | | 1741 | clear_warning_flags(); |
1742 | } | | 1742 | } |
1743 | | for_start opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPAREN { | | 1743 | | for_start opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPAREN { |
1744 | for1($2, $4, $6); | | 1744 | for1($2, $4, $6); |