Deleted Added
full compact
cgram.y (80284) cgram.y (91592)
1%{
1%{
2/* $NetBSD: cgram.y,v 1.8 1995/10/02 17:31:35 jpo Exp $ */
2/* $NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $ */
3
4/*
3
4/*
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.

--- 14 unchanged lines hidden (view full) ---

27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
6 * Copyright (c) 1994, 1995 Jochen Pohl
7 * All Rights Reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.

--- 14 unchanged lines hidden (view full) ---

28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
35#ifndef lint
36static char rcsid[] = "$FreeBSD: head/usr.bin/xlint/lint1/cgram.y 80284 2001-07-24 14:02:07Z obrien $";
36#include <sys/cdefs.h>
37#if defined(__RCSID) && !defined(lint)
38__RCSID("$NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $");
37#endif
39#endif
40__FBSDID("$FreeBSD: head/usr.bin/xlint/lint1/cgram.y 91592 2002-03-03 15:12:50Z markm $");
38
39#include <stdlib.h>
41
42#include <stdlib.h>
43#include <string.h>
40#include <limits.h>
41
42#include "lint1.h"
43
44/*
45 * Contains the level of current declaration. 0 is extern.
46 * Used for symbol table entries.
47 */
48int blklev;
49
50/*
51 * level for memory allocation. Normaly the same as blklev.
52 * An exeption is the declaration of arguments in prototypes. Memory
53 * for these can't be freed after the declaration, but symbols must
54 * be removed from the symbol table after the declaration.
55 */
56int mblklev;
57
44#include <limits.h>
45
46#include "lint1.h"
47
48/*
49 * Contains the level of current declaration. 0 is extern.
50 * Used for symbol table entries.
51 */
52int blklev;
53
54/*
55 * level for memory allocation. Normaly the same as blklev.
56 * An exeption is the declaration of arguments in prototypes. Memory
57 * for these can't be freed after the declaration, but symbols must
58 * be removed from the symbol table after the declaration.
59 */
60int mblklev;
61
58static int toicon __P((tnode_t *));
59static void idecl __P((sym_t *, int));
60static void ignuptorp __P((void));
62/*
63 * Save the no-warns state and restore it to avoid the problem where
64 * if (expr) { stmt } / * NOLINT * / stmt;
65 */
66static int onowarn = -1;
61
67
68static int toicon(tnode_t *);
69static void idecl(sym_t *, int, sbuf_t *);
70static void ignuptorp(void);
71
72#ifdef DEBUG
73static __inline void CLRWFLGS(void);
74static __inline void CLRWFLGS(void)
75{
76 printf("%s, %d: clear flags %s %d\n", curr_pos.p_file,
77 curr_pos.p_line, __FILE__, __LINE__);
78 clrwflgs();
79 onowarn = -1;
80}
81
82static __inline void SAVE(void);
83static __inline void SAVE(void)
84{
85 if (onowarn != -1)
86 abort();
87 printf("%s, %d: save flags %s %d = %d\n", curr_pos.p_file,
88 curr_pos.p_line, __FILE__, __LINE__, nowarn);
89 onowarn = nowarn;
90}
91
92static __inline void RESTORE(void);
93static __inline void RESTORE(void)
94{
95 if (onowarn != -1) {
96 nowarn = onowarn;
97 printf("%s, %d: restore flags %s %d = %d\n", curr_pos.p_file,
98 curr_pos.p_line, __FILE__, __LINE__, nowarn);
99 onowarn = -1;
100 } else
101 CLRWFLGS();
102}
103#else
104#define CLRWFLGS() clrwflgs(), onowarn = -1
105#define SAVE() onowarn = nowarn
106#define RESTORE() (void)(onowarn == -1 ? (clrwflgs(), 0) : (nowarn = onowarn))
107#endif
62%}
63
64%union {
65 int y_int;
66 val_t *y_val;
67 sbuf_t *y_sb;
68 sym_t *y_sym;
69 op_t y_op;

--- 54 unchanged lines hidden (view full) ---

124%token T_DO
125%token T_WHILE
126%token T_FOR
127%token T_GOTO
128%token T_CONTINUE
129%token T_BREAK
130%token T_RETURN
131%token T_ASM
108%}
109
110%union {
111 int y_int;
112 val_t *y_val;
113 sbuf_t *y_sb;
114 sym_t *y_sym;
115 op_t y_op;

--- 54 unchanged lines hidden (view full) ---

170%token T_DO
171%token T_WHILE
172%token T_FOR
173%token T_GOTO
174%token T_CONTINUE
175%token T_BREAK
176%token T_RETURN
177%token T_ASM
178%token T_SYMBOLRENAME
132
133%left T_COMMA
134%right T_ASSIGN T_OPASS
135%right T_QUEST T_COLON
136%left T_LOGOR
137%left T_LOGAND
138%left T_OR
139%left T_XOR

--- 60 unchanged lines hidden (view full) ---

200%type <y_tnode> func_arg_list
201%type <y_op> point_or_arrow
202%type <y_type> type_name
203%type <y_sym> abstract_declaration
204%type <y_tnode> do_while_expr
205%type <y_tnode> opt_expr
206%type <y_strg> string
207%type <y_strg> string2
179
180%left T_COMMA
181%right T_ASSIGN T_OPASS
182%right T_QUEST T_COLON
183%left T_LOGOR
184%left T_LOGAND
185%left T_OR
186%left T_XOR

--- 60 unchanged lines hidden (view full) ---

247%type <y_tnode> func_arg_list
248%type <y_op> point_or_arrow
249%type <y_type> type_name
250%type <y_sym> abstract_declaration
251%type <y_tnode> do_while_expr
252%type <y_tnode> opt_expr
253%type <y_strg> string
254%type <y_strg> string2
255%type <y_sb> opt_asm_or_symbolrename
208
209
210%%
211
212program:
213 /* empty */ {
214 if (sflag) {
215 /* empty translation unit */

--- 7 unchanged lines hidden (view full) ---

223 ;
224
225translation_unit:
226 ext_decl
227 | translation_unit ext_decl
228 ;
229
230ext_decl:
256
257
258%%
259
260program:
261 /* empty */ {
262 if (sflag) {
263 /* empty translation unit */

--- 7 unchanged lines hidden (view full) ---

271 ;
272
273translation_unit:
274 ext_decl
275 | translation_unit ext_decl
276 ;
277
278ext_decl:
231 func_def {
279 asm_stmnt
280 | func_def {
232 glclup(0);
281 glclup(0);
233 clrwflgs();
282 CLRWFLGS();
234 }
235 | data_def {
236 glclup(0);
283 }
284 | data_def {
285 glclup(0);
237 clrwflgs();
286 CLRWFLGS();
238 }
239 ;
240
241data_def:
242 T_SEMI {
243 if (sflag) {
244 /* syntax error: empty declaration */
245 error(0);

--- 27 unchanged lines hidden (view full) ---

273 warning(72);
274 } else if (!dcs->d_nedecl) {
275 /* empty declaration */
276 warning(2);
277 }
278 }
279 | declspecs deftyp type_init_decls T_SEMI
280 | error T_SEMI {
287 }
288 ;
289
290data_def:
291 T_SEMI {
292 if (sflag) {
293 /* syntax error: empty declaration */
294 error(0);

--- 27 unchanged lines hidden (view full) ---

322 warning(72);
323 } else if (!dcs->d_nedecl) {
324 /* empty declaration */
325 warning(2);
326 }
327 }
328 | declspecs deftyp type_init_decls T_SEMI
329 | error T_SEMI {
281 globclup();
330 globclup();
282 }
283 | error T_RBRACE {
284 globclup();
285 }
286 ;
287
288func_def:
289 func_decl {

--- 417 unchanged lines hidden (view full) ---

707 $$ = $1;
708 }
709 | enums T_COMMA {
710 if (sflag) {
711 /* trailing "," prohibited in enum declaration */
712 error(54);
713 } else {
714 /* trailing "," prohibited in enum declaration */
331 }
332 | error T_RBRACE {
333 globclup();
334 }
335 ;
336
337func_def:
338 func_decl {

--- 417 unchanged lines hidden (view full) ---

756 $$ = $1;
757 }
758 | enums T_COMMA {
759 if (sflag) {
760 /* trailing "," prohibited in enum declaration */
761 error(54);
762 } else {
763 /* trailing "," prohibited in enum declaration */
715 warning(54);
764 (void)gnuism(54);
716 }
717 $$ = $1;
718 }
719 ;
720
721enums:
722 enumerator {
723 $$ = $1;

--- 28 unchanged lines hidden (view full) ---

752 ;
753
754type_init_decls:
755 type_init_decl
756 | type_init_decls T_COMMA type_init_decl
757 ;
758
759notype_init_decl:
765 }
766 $$ = $1;
767 }
768 ;
769
770enums:
771 enumerator {
772 $$ = $1;

--- 28 unchanged lines hidden (view full) ---

801 ;
802
803type_init_decls:
804 type_init_decl
805 | type_init_decls T_COMMA type_init_decl
806 ;
807
808notype_init_decl:
760 notype_decl opt_asm_spec {
761 idecl($1, 0);
809 notype_decl opt_asm_or_symbolrename {
810 idecl($1, 0, $2);
762 chksz($1);
763 }
811 chksz($1);
812 }
764 | notype_decl opt_asm_spec {
765 idecl($1, 1);
813 | notype_decl opt_asm_or_symbolrename {
814 idecl($1, 1, $2);
766 } T_ASSIGN initializer {
767 chksz($1);
768 }
769 ;
770
771type_init_decl:
815 } T_ASSIGN initializer {
816 chksz($1);
817 }
818 ;
819
820type_init_decl:
772 type_decl opt_asm_spec {
773 idecl($1, 0);
821 type_decl opt_asm_or_symbolrename {
822 idecl($1, 0, $2);
774 chksz($1);
775 }
823 chksz($1);
824 }
776 | type_decl opt_asm_spec {
777 idecl($1, 1);
825 | type_decl opt_asm_or_symbolrename {
826 idecl($1, 1, $2);
778 } T_ASSIGN initializer {
779 chksz($1);
780 }
781 ;
782
783notype_decl:
784 notype_direct_decl {
785 $$ = $1;

--- 129 unchanged lines hidden (view full) ---

915 }
916 | asterisk type_qualifier_list pointer {
917 $$ = mergepq(mergepq($1, $2), $3);
918 }
919 ;
920
921asterisk:
922 T_MULT {
827 } T_ASSIGN initializer {
828 chksz($1);
829 }
830 ;
831
832notype_decl:
833 notype_direct_decl {
834 $$ = $1;

--- 129 unchanged lines hidden (view full) ---

964 }
965 | asterisk type_qualifier_list pointer {
966 $$ = mergepq(mergepq($1, $2), $3);
967 }
968 ;
969
970asterisk:
971 T_MULT {
923 if (($$ = calloc(1, sizeof (pqinf_t))) == NULL)
924 nomem();
972 $$ = xcalloc(1, sizeof (pqinf_t));
925 $$->p_pcnt = 1;
926 }
927 ;
928
929type_qualifier_list:
930 type_qualifier {
931 $$ = $1;
932 }
933 | type_qualifier_list type_qualifier {
934 $$ = mergepq($1, $2);
935 }
936 ;
937
938type_qualifier:
939 T_QUAL {
973 $$->p_pcnt = 1;
974 }
975 ;
976
977type_qualifier_list:
978 type_qualifier {
979 $$ = $1;
980 }
981 | type_qualifier_list type_qualifier {
982 $$ = mergepq($1, $2);
983 }
984 ;
985
986type_qualifier:
987 T_QUAL {
940 if (($$ = calloc(1, sizeof (pqinf_t))) == NULL)
941 nomem();
988 $$ = xcalloc(1, sizeof (pqinf_t));
942 if ($1 == CONST) {
943 $$->p_const = 1;
944 } else {
945 $$->p_volatile = 1;
946 }
947 }
948 ;
949

--- 62 unchanged lines hidden (view full) ---

1012 warning(84);
1013 }
1014 dcs->d_vararg = 1;
1015 $$ = NULL;
1016 }
1017 ;
1018
1019parameter_type_list:
989 if ($1 == CONST) {
990 $$->p_const = 1;
991 } else {
992 $$->p_volatile = 1;
993 }
994 }
995 ;
996

--- 62 unchanged lines hidden (view full) ---

1059 warning(84);
1060 }
1061 dcs->d_vararg = 1;
1062 $$ = NULL;
1063 }
1064 ;
1065
1066parameter_type_list:
1020 parameter_declaration opt_asm_spec {
1067 parameter_declaration {
1021 $$ = $1;
1022 }
1068 $$ = $1;
1069 }
1023 | parameter_type_list T_COMMA parameter_declaration opt_asm_spec {
1070 | parameter_type_list T_COMMA parameter_declaration {
1024 $$ = lnklst($1, $3);
1025 }
1026 ;
1027
1028parameter_declaration:
1029 declmods deftyp {
1030 $$ = decl1arg(aname(), 0);
1031 }

--- 16 unchanged lines hidden (view full) ---

1048 | declmods deftyp abs_decl {
1049 $$ = decl1arg($3, 0);
1050 }
1051 | declspecs deftyp abs_decl {
1052 $$ = decl1arg($3, 0);
1053 }
1054 ;
1055
1071 $$ = lnklst($1, $3);
1072 }
1073 ;
1074
1075parameter_declaration:
1076 declmods deftyp {
1077 $$ = decl1arg(aname(), 0);
1078 }

--- 16 unchanged lines hidden (view full) ---

1095 | declmods deftyp abs_decl {
1096 $$ = decl1arg($3, 0);
1097 }
1098 | declspecs deftyp abs_decl {
1099 $$ = decl1arg($3, 0);
1100 }
1101 ;
1102
1056opt_asm_spec:
1057 /* empty */
1103opt_asm_or_symbolrename: /* expect only one */
1104 /* empty */ {
1105 $$ = NULL;
1106 }
1058 | T_ASM T_LPARN T_STRING T_RPARN {
1059 freeyyv(&$3, T_STRING);
1107 | T_ASM T_LPARN T_STRING T_RPARN {
1108 freeyyv(&$3, T_STRING);
1109 $$ = NULL;
1060 }
1110 }
1111 | T_SYMBOLRENAME T_LPARN T_NAME T_RPARN {
1112 $$ = $3;
1113 }
1061 ;
1062
1063initializer:
1064 init_expr
1065 ;
1066
1067init_expr:
1068 expr %prec T_COMMA {

--- 140 unchanged lines hidden (view full) ---

1209 ;
1210
1211opt_stmnt_list:
1212 /* empty */
1213 | stmnt_list
1214 ;
1215
1216stmnt_list:
1114 ;
1115
1116initializer:
1117 init_expr
1118 ;
1119
1120init_expr:
1121 expr %prec T_COMMA {

--- 140 unchanged lines hidden (view full) ---

1262 ;
1263
1264opt_stmnt_list:
1265 /* empty */
1266 | stmnt_list
1267 ;
1268
1269stmnt_list:
1217 stmnt {
1218 clrwflgs();
1219 }
1270 stmnt
1220 | stmnt_list stmnt {
1271 | stmnt_list stmnt {
1221 clrwflgs();
1272 RESTORE();
1222 }
1273 }
1223 | stmnt_list error T_SEMI {
1224 clrwflgs();
1225 }
1274 | stmnt_list error T_SEMI
1226 ;
1227
1228expr_stmnt:
1229 expr T_SEMI {
1230 expr($1, 0, 0);
1231 ftflg = 0;
1232 }
1233 | T_SEMI {
1234 ftflg = 0;
1235 }
1236 ;
1237
1238selection_stmnt:
1239 if_without_else {
1275 ;
1276
1277expr_stmnt:
1278 expr T_SEMI {
1279 expr($1, 0, 0);
1280 ftflg = 0;
1281 }
1282 | T_SEMI {
1283 ftflg = 0;
1284 }
1285 ;
1286
1287selection_stmnt:
1288 if_without_else {
1289 SAVE();
1240 if2();
1241 if3(0);
1242 }
1243 | if_without_else T_ELSE {
1290 if2();
1291 if3(0);
1292 }
1293 | if_without_else T_ELSE {
1294 SAVE();
1244 if2();
1245 } stmnt {
1295 if2();
1296 } stmnt {
1297 CLRWFLGS();
1246 if3(1);
1247 }
1248 | if_without_else T_ELSE error {
1298 if3(1);
1299 }
1300 | if_without_else T_ELSE error {
1301 CLRWFLGS();
1249 if3(0);
1250 }
1251 | switch_expr stmnt {
1302 if3(0);
1303 }
1304 | switch_expr stmnt {
1305 CLRWFLGS();
1252 switch2();
1253 }
1254 | switch_expr error {
1306 switch2();
1307 }
1308 | switch_expr error {
1309 CLRWFLGS();
1255 switch2();
1256 }
1257 ;
1258
1259if_without_else:
1260 if_expr stmnt
1261 | if_expr error
1262 ;
1263
1264if_expr:
1265 T_IF T_LPARN expr T_RPARN {
1266 if1($3);
1310 switch2();
1311 }
1312 ;
1313
1314if_without_else:
1315 if_expr stmnt
1316 | if_expr error
1317 ;
1318
1319if_expr:
1320 T_IF T_LPARN expr T_RPARN {
1321 if1($3);
1267 clrwflgs();
1322 CLRWFLGS();
1268 }
1269 ;
1270
1271switch_expr:
1272 T_SWITCH T_LPARN expr T_RPARN {
1273 switch1($3);
1323 }
1324 ;
1325
1326switch_expr:
1327 T_SWITCH T_LPARN expr T_RPARN {
1328 switch1($3);
1274 clrwflgs();
1329 CLRWFLGS();
1275 }
1276 ;
1277
1330 }
1331 ;
1332
1333do_stmnt:
1334 do stmnt {
1335 CLRWFLGS();
1336 }
1337 ;
1338
1278iteration_stmnt:
1279 while_expr stmnt {
1339iteration_stmnt:
1340 while_expr stmnt {
1341 CLRWFLGS();
1280 while2();
1281 }
1282 | while_expr error {
1342 while2();
1343 }
1344 | while_expr error {
1345 CLRWFLGS();
1283 while2();
1284 }
1346 while2();
1347 }
1285 | do stmnt do_while_expr {
1286 do2($3);
1348 | do_stmnt do_while_expr {
1349 do2($2);
1287 ftflg = 0;
1288 }
1289 | do error {
1350 ftflg = 0;
1351 }
1352 | do error {
1353 CLRWFLGS();
1290 do2(NULL);
1291 }
1292 | for_exprs stmnt {
1354 do2(NULL);
1355 }
1356 | for_exprs stmnt {
1357 CLRWFLGS();
1293 for2();
1294 }
1295 | for_exprs error {
1358 for2();
1359 }
1360 | for_exprs error {
1361 CLRWFLGS();
1296 for2();
1297 }
1298 ;
1299
1300while_expr:
1301 T_WHILE T_LPARN expr T_RPARN {
1302 while1($3);
1362 for2();
1363 }
1364 ;
1365
1366while_expr:
1367 T_WHILE T_LPARN expr T_RPARN {
1368 while1($3);
1303 clrwflgs();
1369 CLRWFLGS();
1304 }
1305 ;
1306
1307do:
1308 T_DO {
1309 do1();
1310 }
1311 ;
1312
1313do_while_expr:
1314 T_WHILE T_LPARN expr T_RPARN T_SEMI {
1315 $$ = $3;
1316 }
1317 ;
1318
1319for_exprs:
1320 T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN {
1321 for1($3, $5, $7);
1370 }
1371 ;
1372
1373do:
1374 T_DO {
1375 do1();
1376 }
1377 ;
1378
1379do_while_expr:
1380 T_WHILE T_LPARN expr T_RPARN T_SEMI {
1381 $$ = $3;
1382 }
1383 ;
1384
1385for_exprs:
1386 T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN {
1387 for1($3, $5, $7);
1322 clrwflgs();
1388 CLRWFLGS();
1323 }
1324 ;
1325
1326opt_expr:
1327 /* empty */ {
1328 $$ = NULL;
1329 }
1330 | expr {

--- 41 unchanged lines hidden (view full) ---

1372read_until_rparn:
1373 /* empty */ {
1374 ignuptorp();
1375 }
1376 ;
1377
1378declaration_list:
1379 declaration {
1389 }
1390 ;
1391
1392opt_expr:
1393 /* empty */ {
1394 $$ = NULL;
1395 }
1396 | expr {

--- 41 unchanged lines hidden (view full) ---

1438read_until_rparn:
1439 /* empty */ {
1440 ignuptorp();
1441 }
1442 ;
1443
1444declaration_list:
1445 declaration {
1380 clrwflgs();
1446 CLRWFLGS();
1381 }
1382 | declaration_list declaration {
1447 }
1448 | declaration_list declaration {
1383 clrwflgs();
1449 CLRWFLGS();
1384 }
1385 ;
1386
1387constant:
1388 expr %prec T_COMMA {
1389 $$ = $1;
1390 }
1391 ;

--- 46 unchanged lines hidden (view full) ---

1438 }
1439 | term {
1440 $$ = $1;
1441 }
1442 ;
1443
1444term:
1445 T_NAME {
1450 }
1451 ;
1452
1453constant:
1454 expr %prec T_COMMA {
1455 $$ = $1;
1456 }
1457 ;

--- 46 unchanged lines hidden (view full) ---

1504 }
1505 | term {
1506 $$ = $1;
1507 }
1508 ;
1509
1510term:
1511 T_NAME {
1446 /* XXX realy neccessary? */
1512 /* XXX really necessary? */
1447 if (yychar < 0)
1448 yychar = yylex();
1449 $$ = getnnode(getsym($1), yychar);
1450 }
1451 | string {
1452 $$ = getsnode($1);
1453 }
1454 | T_CON {

--- 107 unchanged lines hidden (view full) ---

1562 $$ = $1;
1563 }
1564 ;
1565
1566%%
1567
1568/* ARGSUSED */
1569int
1513 if (yychar < 0)
1514 yychar = yylex();
1515 $$ = getnnode(getsym($1), yychar);
1516 }
1517 | string {
1518 $$ = getsnode($1);
1519 }
1520 | T_CON {

--- 107 unchanged lines hidden (view full) ---

1628 $$ = $1;
1629 }
1630 ;
1631
1632%%
1633
1634/* ARGSUSED */
1635int
1570yyerror(msg)
1571 char *msg;
1636yyerror(char *msg)
1572{
1637{
1638
1573 error(249);
1574 if (++sytxerr >= 5)
1575 norecover();
1576 return (0);
1577}
1578
1639 error(249);
1640 if (++sytxerr >= 5)
1641 norecover();
1642 return (0);
1643}
1644
1645static inline int uq_gt(uint64_t, uint64_t);
1646static inline int q_gt(int64_t, int64_t);
1647
1648static inline int
1649uq_gt(uint64_t a, uint64_t b)
1650{
1651
1652 return (a > b);
1653}
1654
1655static inline int
1656q_gt(int64_t a, int64_t b)
1657{
1658
1659 return (a > b);
1660}
1661
1662#define q_lt(a, b) q_gt(b, a)
1663
1579/*
1580 * Gets a node for a constant and returns the value of this constant
1581 * as integer.
1582 * Is the node not constant or too large for int or of type float,
1583 * a warning will be printed.
1584 *
1585 * toicon() should be used only inside declarations. If it is used in
1586 * expressions, it frees the memory used for the expression.
1587 */
1588static int
1664/*
1665 * Gets a node for a constant and returns the value of this constant
1666 * as integer.
1667 * Is the node not constant or too large for int or of type float,
1668 * a warning will be printed.
1669 *
1670 * toicon() should be used only inside declarations. If it is used in
1671 * expressions, it frees the memory used for the expression.
1672 */
1673static int
1589toicon(tn)
1590 tnode_t *tn;
1674toicon(tnode_t *tn)
1591{
1592 int i;
1593 tspec_t t;
1594 val_t *v;
1595
1596 v = constant(tn);
1597
1598 /*

--- 5 unchanged lines hidden (view full) ---

1604
1605 if ((t = v->v_tspec) == FLOAT || t == DOUBLE || t == LDOUBLE) {
1606 i = (int)v->v_ldbl;
1607 /* integral constant expression expected */
1608 error(55);
1609 } else {
1610 i = (int)v->v_quad;
1611 if (isutyp(t)) {
1675{
1676 int i;
1677 tspec_t t;
1678 val_t *v;
1679
1680 v = constant(tn);
1681
1682 /*

--- 5 unchanged lines hidden (view full) ---

1688
1689 if ((t = v->v_tspec) == FLOAT || t == DOUBLE || t == LDOUBLE) {
1690 i = (int)v->v_ldbl;
1691 /* integral constant expression expected */
1692 error(55);
1693 } else {
1694 i = (int)v->v_quad;
1695 if (isutyp(t)) {
1612 if ((u_quad_t)v->v_quad > INT_MAX) {
1696 if (uq_gt((uint64_t)v->v_quad,
1697 (uint64_t)INT_MAX)) {
1613 /* integral constant too large */
1614 warning(56);
1615 }
1616 } else {
1698 /* integral constant too large */
1699 warning(56);
1700 }
1701 } else {
1617#ifdef XXX_BROKEN_GCC
1618 if (v->v_quad > INT_MAX) {
1702 if (q_gt(v->v_quad, (int64_t)INT_MAX) ||
1703 q_lt(v->v_quad, (int64_t)INT_MIN)) {
1619 /* integral constant too large */
1620 warning(56);
1621 }
1704 /* integral constant too large */
1705 warning(56);
1706 }
1622 else if (v->v_quad < INT_MIN) {
1623 /* integral constant too large */
1624 warning(56);
1625 }
1626#else
1627 if (v->v_quad > INT_MAX || v->v_quad < INT_MIN) {
1628 /* integral constant too large */
1629 warning(56);
1630 }
1631#endif
1632 }
1633 }
1634 free(v);
1635 return (i);
1636}
1637
1638static void
1707 }
1708 }
1709 free(v);
1710 return (i);
1711}
1712
1713static void
1639idecl(decl, initflg)
1640 sym_t *decl;
1641 int initflg;
1714idecl(sym_t *decl, int initflg, sbuf_t *rename)
1642{
1715{
1716 char *s;
1717
1643 initerr = 0;
1644 initsym = decl;
1645
1646 switch (dcs->d_ctx) {
1647 case EXTERN:
1718 initerr = 0;
1719 initsym = decl;
1720
1721 switch (dcs->d_ctx) {
1722 case EXTERN:
1723 if (rename != NULL) {
1724 if (decl->s_rename != NULL)
1725 lerror("idecl() 1");
1726
1727 s = getlblk(1, rename->sb_len + 1);
1728 (void)memcpy(s, rename->sb_name, rename->sb_len + 1);
1729 decl->s_rename = s;
1730 freeyyv(&rename, T_NAME);
1731 }
1648 decl1ext(decl, initflg);
1649 break;
1650 case ARG:
1732 decl1ext(decl, initflg);
1733 break;
1734 case ARG:
1735 if (rename != NULL) {
1736 /* symbol renaming can't be used on function arguments */
1737 error(310);
1738 freeyyv(&rename, T_NAME);
1739 break;
1740 }
1651 (void)decl1arg(decl, initflg);
1652 break;
1653 case AUTO:
1741 (void)decl1arg(decl, initflg);
1742 break;
1743 case AUTO:
1744 if (rename != NULL) {
1745 /* symbol renaming can't be used on automatic variables */
1746 error(311);
1747 freeyyv(&rename, T_NAME);
1748 break;
1749 }
1654 decl1loc(decl, initflg);
1655 break;
1656 default:
1750 decl1loc(decl, initflg);
1751 break;
1752 default:
1657 lerror("idecl()");
1753 lerror("idecl() 2");
1658 }
1659
1660 if (initflg && !initerr)
1661 prepinit();
1662}
1663
1664/*
1665 * Discard all input tokens up to and including the next
1666 * unmatched right paren
1667 */
1754 }
1755
1756 if (initflg && !initerr)
1757 prepinit();
1758}
1759
1760/*
1761 * Discard all input tokens up to and including the next
1762 * unmatched right paren
1763 */
1668void
1669ignuptorp()
1764static void
1765ignuptorp(void)
1670{
1671 int level;
1672
1673 if (yychar < 0)
1674 yychar = yylex();
1675 freeyyv(&yylval, yychar);
1676
1677 level = 1;
1678 while (yychar != T_RPARN || --level > 0) {
1679 if (yychar == T_LPARN) {
1680 level++;
1681 } else if (yychar <= 0) {
1682 break;
1683 }
1684 freeyyv(&yylval, yychar = yylex());
1685 }
1686
1687 yyclearin;
1688}
1766{
1767 int level;
1768
1769 if (yychar < 0)
1770 yychar = yylex();
1771 freeyyv(&yylval, yychar);
1772
1773 level = 1;
1774 while (yychar != T_RPARN || --level > 0) {
1775 if (yychar == T_LPARN) {
1776 level++;
1777 } else if (yychar <= 0) {
1778 break;
1779 }
1780 freeyyv(&yylval, yychar = yylex());
1781 }
1782
1783 yyclearin;
1784}