2 /* $NetBSD: cgram.y,v 1.40 2008/04/25 17:18:24 christos Exp $ */
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
6 * Copyright (c) 1994, 1995 Jochen Pohl
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Jochen Pohl for
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
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.
36 #include <sys/cdefs.h>
37 #if defined(__RCSID) && !defined(lint)
38 __RCSID("$NetBSD: cgram.y,v 1.40 2008/04/25 17:18:24 christos Exp $");
40 __FBSDID("$FreeBSD$");
49 * Contains the level of current declaration. 0 is extern.
50 * Used for symbol table entries.
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.
63 * Save the no-warns state and restore it to avoid the problem where
64 * if (expr) { stmt } / * NOLINT * / stmt;
66 static int onowarn = -1;
68 static int toicon(tnode_t *, int);
69 static void idecl(sym_t *, int, sbuf_t *);
70 static void ignuptorp(void);
73 static inline void CLRWFLGS(void);
74 static inline void CLRWFLGS(void)
76 printf("%s, %d: clear flags %s %d\n", curr_pos.p_file,
77 curr_pos.p_line, __FILE__, __LINE__);
82 static inline void SAVE(void);
83 static inline void SAVE(void)
87 printf("%s, %d: save flags %s %d = %d\n", curr_pos.p_file,
88 curr_pos.p_line, __FILE__, __LINE__, nowarn);
92 static inline void RESTORE(void);
93 static inline void RESTORE(void)
97 printf("%s, %d: restore flags %s %d = %d\n", curr_pos.p_file,
98 curr_pos.p_line, __FILE__, __LINE__, nowarn);
104 #define CLRWFLGS() clrwflgs(), onowarn = -1
105 #define SAVE() onowarn = nowarn
106 #define RESTORE() (void)(onowarn == -1 ? (clrwflgs(), 0) : (nowarn = onowarn))
128 %token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPARN T_RPARN
129 %token <y_op> T_STROP
131 %token <y_op> T_INCDEC
134 %token <y_op> T_DIVOP
135 %token <y_op> T_ADDOP
136 %token <y_op> T_SHFTOP
137 %token <y_op> T_RELOP
142 %token <y_op> T_LOGAND
143 %token <y_op> T_LOGOR
146 %token <y_op> T_ASSIGN
147 %token <y_op> T_OPASS
152 /* storage classes (extern, static, auto, register and typedef) */
153 %token <y_scl> T_SCLASS
155 /* types (char, int, short, long, unsigned, signed, float, double, void) */
156 %token <y_tspec> T_TYPE
158 /* qualifiers (const, volatile) */
159 %token <y_tqual> T_QUAL
161 /* struct or union */
162 %token <y_tspec> T_SOU
167 /* remaining keywords */
181 %token T_SYMBOLRENAME
184 %right T_ASSIGN T_OPASS
185 %right T_QUEST T_COLON
196 %right T_UNOP T_INCDEC T_SIZEOF
197 %left T_LPARN T_LBRACK T_STROP
200 %token <y_sb> T_TYPENAME
202 %token <y_strg> T_STRING
204 %type <y_sym> func_decl
205 %type <y_sym> notype_decl
206 %type <y_sym> type_decl
207 %type <y_type> typespec
208 %type <y_type> clrtyp_typespec
209 %type <y_type> notype_typespec
210 %type <y_type> struct_spec
211 %type <y_type> enum_spec
212 %type <y_sym> struct_tag
213 %type <y_sym> enum_tag
214 %type <y_tspec> struct
215 %type <y_sym> struct_declaration
216 %type <y_sb> identifier
217 %type <y_sym> member_declaration_list_with_rbrace
218 %type <y_sym> member_declaration_list
219 %type <y_sym> member_declaration
220 %type <y_sym> notype_member_decls
221 %type <y_sym> type_member_decls
222 %type <y_sym> notype_member_decl
223 %type <y_sym> type_member_decl
224 %type <y_tnode> constant
225 %type <y_sym> enum_declaration
226 %type <y_sym> enums_with_opt_comma
228 %type <y_sym> enumerator
230 %type <y_sym> notype_direct_decl
231 %type <y_sym> type_direct_decl
232 %type <y_pqinf> pointer
233 %type <y_pqinf> asterisk
234 %type <y_sym> param_decl
235 %type <y_sym> param_list
236 %type <y_sym> abs_decl_param_list
237 %type <y_sym> direct_param_decl
238 %type <y_sym> notype_param_decl
239 %type <y_sym> direct_notype_param_decl
240 %type <y_pqinf> type_qualifier_list
241 %type <y_pqinf> type_qualifier
242 %type <y_sym> identifier_list
243 %type <y_sym> abs_decl
244 %type <y_sym> direct_abs_decl
245 %type <y_sym> vararg_parameter_type_list
246 %type <y_sym> parameter_type_list
247 %type <y_sym> parameter_declaration
249 %type <y_tnode> expr_stmnt_val
250 %type <y_tnode> expr_stmnt_list
252 %type <y_tnode> func_arg_list
253 %type <y_op> point_or_arrow
254 %type <y_type> type_name
255 %type <y_sym> abstract_declaration
256 %type <y_tnode> do_while_expr
257 %type <y_tnode> opt_expr
258 %type <y_strg> string
259 %type <y_strg> string2
260 %type <y_sb> opt_asm_or_symbolrename
261 %type <y_range> range
262 %type <y_range> lorange
270 /* empty translation unit */
273 /* empty translation unit */
282 | translation_unit ext_decl
300 /* syntax error: empty declaration */
303 /* syntax error: empty declaration */
307 | clrtyp deftyp notype_init_decls T_SEMI {
309 /* old style declaration; add "int" */
312 /* old style declaration; add "int" */
316 | declmods deftyp T_SEMI {
317 if (dcs->d_scl == TYPEDEF) {
318 /* typedef declares no type name */
321 /* empty declaration */
325 | declmods deftyp notype_init_decls T_SEMI
326 | declspecs deftyp T_SEMI {
327 if (dcs->d_scl == TYPEDEF) {
328 /* typedef declares no type name */
330 } else if (!dcs->d_nedecl) {
331 /* empty declaration */
335 | declspecs deftyp type_init_decls T_SEMI
346 if ($1->s_type->t_tspec != FUNC) {
351 if ($1->s_type->t_typedef) {
352 /* ()-less function definition */
359 } opt_arg_declaration_list {
371 clrtyp deftyp notype_decl {
374 | declmods deftyp notype_decl {
377 | declspecs deftyp type_decl {
382 opt_arg_declaration_list:
384 | arg_declaration_list
387 arg_declaration_list:
389 | arg_declaration_list arg_declaration
390 /* XXX or better "arg_declaration error" ? */
395 * "arg_declaration" is separated from "declaration" because it
396 * needs other error handling.
400 declmods deftyp T_SEMI {
401 /* empty declaration */
404 | declmods deftyp notype_init_decls T_SEMI
405 | declspecs deftyp T_SEMI {
406 if (!dcs->d_nedecl) {
407 /* empty declaration */
410 tspec_t ts = dcs->d_type->t_tspec;
411 /* %s declared in argument declaration list */
412 warning(3, ts == STRUCT ? "struct" :
413 (ts == UNION ? "union" : "enum"));
416 | declspecs deftyp type_init_decls T_SEMI {
418 tspec_t ts = dcs->d_type->t_tspec;
419 /* %s declared in argument declaration list */
420 warning(3, ts == STRUCT ? "struct" :
421 (ts == UNION ? "union" : "enum"));
429 declmods deftyp T_SEMI {
430 if (dcs->d_scl == TYPEDEF) {
431 /* typedef declares no type name */
434 /* empty declaration */
438 | declmods deftyp notype_init_decls T_SEMI
439 | declspecs deftyp T_SEMI {
440 if (dcs->d_scl == TYPEDEF) {
441 /* typedef declares no type name */
443 } else if (!dcs->d_nedecl) {
444 /* empty declaration */
448 | declspecs deftyp type_init_decls T_SEMI
468 | declmods typespec {
472 | declspecs notype_typespec {
497 clrtyp notype_typespec {
500 | T_TYPENAME clrtyp {
501 $$ = getsym($1)->s_type;
510 $$ = getsym($1)->s_type;
531 * STDC requires that "struct a;" always introduces
532 * a new tag if "a" is not declared at current level
534 * yychar is valid because otherwise the parser would
535 * not been able to deceide if he must shift or reduce
537 $$ = mktag($2, $1, 0, yychar == T_SEMI);
539 | struct struct_tag {
540 dcs->d_tagtyp = mktag($2, $1, 1, 0);
541 } struct_declaration {
542 $$ = compltag(dcs->d_tagtyp, $4);
545 dcs->d_tagtyp = mktag(NULL, $1, 1, 0);
546 } struct_declaration {
547 $$ = compltag(dcs->d_tagtyp, $3);
558 pushdecl($1 == STRUCT ? MOS : MOU);
560 dcs->d_stralign = CHAR_BIT;
572 struct_decl_lbrace member_declaration_list_with_rbrace {
583 member_declaration_list_with_rbrace:
584 member_declaration_list T_SEMI T_RBRACE {
587 | member_declaration_list T_RBRACE {
589 /* syntax req. ";" after last struct/union member */
592 /* syntax req. ";" after last struct/union member */
602 member_declaration_list:
606 | member_declaration_list T_SEMI member_declaration {
612 noclass_declmods deftyp {
613 /* too late, i know, but getsym() compensates it */
615 } notype_member_decls {
619 | noclass_declspecs deftyp {
621 } type_member_decls {
625 | noclass_declmods deftyp {
626 /* struct or union member must be named */
630 | noclass_declspecs deftyp {
631 /* struct or union member must be named */
645 | noclass_declmods typespec {
648 | noclass_declspecs T_QUAL {
651 | noclass_declspecs notype_typespec {
660 | noclass_declmods T_QUAL {
669 | notype_member_decls {
671 } T_COMMA type_member_decl {
672 $$ = lnklst($1, decl1str($4));
680 | type_member_decls {
682 } T_COMMA type_member_decl {
683 $$ = lnklst($1, decl1str($4));
691 | notype_decl T_COLON constant {
692 $$ = bitfield($1, toicon($3, 1));
697 $$ = bitfield(NULL, toicon($3, 1));
705 | type_decl T_COLON constant {
706 $$ = bitfield($1, toicon($3, 1));
711 $$ = bitfield(NULL, toicon($3, 1));
717 $$ = mktag($2, ENUM, 0, 0);
720 dcs->d_tagtyp = mktag($2, ENUM, 1, 0);
722 $$ = compltag(dcs->d_tagtyp, $4);
725 dcs->d_tagtyp = mktag(NULL, ENUM, 1, 0);
727 $$ = compltag(dcs->d_tagtyp, $3);
749 enum_decl_lbrace enums_with_opt_comma T_RBRACE {
761 enums_with_opt_comma:
767 /* trailing "," prohibited in enum declaration */
770 /* trailing "," prohibited in enum declaration */
781 | enums T_COMMA enumerator {
791 $$ = ename($1, enumval, 1);
793 | ename T_ASSIGN constant {
794 $$ = ename($1, toicon($3, 1), 0);
807 | notype_init_decls T_COMMA type_init_decl
812 | type_init_decls T_COMMA type_init_decl
816 notype_decl opt_asm_or_symbolrename {
820 | notype_decl opt_asm_or_symbolrename {
822 } T_ASSIGN initializer {
828 type_decl opt_asm_or_symbolrename {
832 | type_decl opt_asm_or_symbolrename {
834 } T_ASSIGN initializer {
843 | pointer notype_direct_decl {
850 $$ = dname(getsym($1));
852 | T_LPARN type_decl T_RPARN {
855 | notype_direct_decl T_LBRACK T_RBRACK {
856 $$ = addarray($1, 0, 0);
858 | notype_direct_decl T_LBRACK constant T_RBRACK {
859 $$ = addarray($1, 1, toicon($3, 0));
861 | notype_direct_decl param_list {
862 $$ = addfunc($1, $2);
872 | pointer type_direct_decl {
879 $$ = dname(getsym($1));
881 | T_LPARN type_decl T_RPARN {
884 | type_direct_decl T_LBRACK T_RBRACK {
885 $$ = addarray($1, 0, 0);
887 | type_direct_decl T_LBRACK constant T_RBRACK {
888 $$ = addarray($1, 1, toicon($3, 0));
890 | type_direct_decl param_list {
891 $$ = addfunc($1, $2);
898 * param_decl and notype_param_decl exist to avoid a conflict in
899 * argument lists. A typename enclosed in parens should always be
900 * treated as a typename, not an argument.
901 * "typedef int a; f(int (a));" is "typedef int a; f(int foo(a));"
902 * not "typedef int a; f(int a);"
908 | pointer direct_param_decl {
915 $$ = dname(getsym($1));
917 | T_LPARN notype_param_decl T_RPARN {
920 | direct_param_decl T_LBRACK T_RBRACK {
921 $$ = addarray($1, 0, 0);
923 | direct_param_decl T_LBRACK constant T_RBRACK {
924 $$ = addarray($1, 1, toicon($3, 0));
926 | direct_param_decl param_list {
927 $$ = addfunc($1, $2);
934 direct_notype_param_decl {
937 | pointer direct_notype_param_decl {
942 direct_notype_param_decl:
944 $$ = dname(getsym($1));
946 | T_LPARN notype_param_decl T_RPARN {
949 | direct_notype_param_decl T_LBRACK T_RBRACK {
950 $$ = addarray($1, 0, 0);
952 | direct_notype_param_decl T_LBRACK constant T_RBRACK {
953 $$ = addarray($1, 1, toicon($3, 0));
955 | direct_notype_param_decl param_list {
956 $$ = addfunc($1, $2);
966 | asterisk type_qualifier_list {
967 $$ = mergepq($1, $2);
970 $$ = mergepq($1, $2);
972 | asterisk type_qualifier_list pointer {
973 $$ = mergepq(mergepq($1, $2), $3);
979 $$ = xcalloc(1, sizeof (pqinf_t));
988 | type_qualifier_list type_qualifier {
989 $$ = mergepq($1, $2);
995 $$ = xcalloc(1, sizeof (pqinf_t));
1005 id_list_lparn identifier_list T_RPARN {
1008 | abs_decl_param_list {
1022 $$ = iname(getsym($1));
1024 | identifier_list T_COMMA T_NAME {
1025 $$ = lnklst($1, iname(getsym($3)));
1027 | identifier_list error {
1032 abs_decl_param_list:
1033 abs_decl_lparn T_RPARN {
1036 | abs_decl_lparn vararg_parameter_type_list T_RPARN {
1040 | abs_decl_lparn error T_RPARN {
1052 vararg_parameter_type_list:
1053 parameter_type_list {
1056 | parameter_type_list T_COMMA T_ELLIPSE {
1062 /* ANSI C requires formal parameter before "..." */
1064 } else if (!tflag) {
1065 /* ANSI C requires formal parameter before "..." */
1073 parameter_type_list:
1074 parameter_declaration {
1077 | parameter_type_list T_COMMA parameter_declaration {
1078 $$ = lnklst($1, $3);
1082 parameter_declaration:
1084 $$ = decl1arg(aname(), 0);
1086 | declspecs deftyp {
1087 $$ = decl1arg(aname(), 0);
1089 | declmods deftyp notype_param_decl {
1090 $$ = decl1arg($3, 0);
1093 * param_decl is needed because of following conflict:
1094 * "typedef int a; f(int (a));" could be parsed as
1095 * "function with argument a of type int", or
1096 * "function with an abstract argument of type function".
1097 * This grammar realizes the second case.
1099 | declspecs deftyp param_decl {
1100 $$ = decl1arg($3, 0);
1102 | declmods deftyp abs_decl {
1103 $$ = decl1arg($3, 0);
1105 | declspecs deftyp abs_decl {
1106 $$ = decl1arg($3, 0);
1110 opt_asm_or_symbolrename: /* expect only one */
1114 | T_ASM T_LPARN T_STRING T_RPARN {
1115 freeyyv(&$3, T_STRING);
1118 | T_SYMBOLRENAME T_LPARN T_NAME T_RPARN {
1128 expr %prec T_COMMA {
1131 | init_by_name init_expr %prec T_COMMA
1132 | init_lbrace init_expr_list init_rbrace
1133 | init_lbrace init_expr_list T_COMMA init_rbrace
1138 init_expr %prec T_COMMA
1139 | init_expr_list T_COMMA init_expr
1143 constant T_ELLIPSE {
1144 $$.lo = toicon($1, 1);
1149 $$.lo = toicon($1, 1);
1152 | lorange constant {
1154 $$.hi = toicon($2, 1);
1159 T_LBRACK range T_RBRACK T_ASSIGN {
1163 | point identifier T_ASSIGN {
1168 | identifier T_COLON {
1189 } abstract_declaration {
1195 abstract_declaration:
1196 noclass_declmods deftyp {
1197 $$ = decl1abs(aname());
1199 | noclass_declspecs deftyp {
1200 $$ = decl1abs(aname());
1202 | noclass_declmods deftyp abs_decl {
1205 | noclass_declspecs deftyp abs_decl {
1212 $$ = addptr(aname(), $1);
1217 | pointer direct_abs_decl {
1218 $$ = addptr($2, $1);
1223 T_LPARN abs_decl T_RPARN {
1226 | T_LBRACK T_RBRACK {
1227 $$ = addarray(aname(), 0, 0);
1229 | T_LBRACK constant T_RBRACK {
1230 $$ = addarray(aname(), 1, toicon($2, 0));
1232 | direct_abs_decl T_LBRACK T_RBRACK {
1233 $$ = addarray($1, 0, 0);
1235 | direct_abs_decl T_LBRACK constant T_RBRACK {
1236 $$ = addarray($1, 1, toicon($3, 0));
1238 | abs_decl_param_list {
1239 $$ = addfunc(aname(), $1);
1243 | direct_abs_decl abs_decl_param_list {
1244 $$ = addfunc($1, $2);
1270 identifier T_COLON {
1272 label(T_NAME, getsym($1), NULL);
1274 | T_CASE constant T_COLON {
1275 label(T_CASE, NULL, $2);
1278 | T_CASE constant T_ELLIPSE constant T_COLON {
1279 /* XXX: We don't fill all cases */
1280 label(T_CASE, NULL, $2);
1283 | T_DEFAULT T_COLON {
1284 label(T_DEFAULT, NULL, NULL);
1290 comp_stmnt_lbrace declaration_list opt_stmnt_list comp_stmnt_rbrace
1291 | comp_stmnt_lbrace opt_stmnt_list comp_stmnt_rbrace
1319 | stmnt_list stmnt {
1322 | stmnt_list error T_SEMI
1336 * The following two productions are used to implement
1337 * ({ [[decl-list] stmt-list] }).
1338 * XXX: This is not well tested.
1342 /* XXX: We should really do that only on the last name */
1343 if ($1->tn_op == NAME)
1344 $1->tn_sym->s_used = 1;
1351 $$->tn_type = gettyp(VOID);
1357 | expr_stmnt_list expr_stmnt_val {
1360 | expr_stmnt_list expr_stmnt_val
1369 | if_without_else T_ELSE {
1376 | if_without_else T_ELSE error {
1380 | switch_expr stmnt {
1384 | switch_expr error {
1396 T_IF T_LPARN expr T_RPARN {
1403 T_SWITCH T_LPARN expr T_RPARN {
1420 | while_expr error {
1424 | do_stmnt do_while_expr {
1443 T_WHILE T_LPARN expr T_RPARN {
1456 T_WHILE T_LPARN expr T_RPARN T_SEMI {
1462 T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN {
1478 goto identifier T_SEMI {
1481 | goto error T_SEMI {
1484 | T_CONTINUE T_SEMI {
1493 | T_RETURN expr T_SEMI {
1505 T_ASM T_LPARN read_until_rparn T_SEMI {
1508 | T_ASM T_QUAL T_LPARN read_until_rparn T_SEMI {
1524 | declaration_list declaration {
1530 expr %prec T_COMMA {
1537 $$ = build(MULT, $1, $3);
1539 | expr T_DIVOP expr {
1540 $$ = build($2, $1, $3);
1542 | expr T_ADDOP expr {
1543 $$ = build($2, $1, $3);
1545 | expr T_SHFTOP expr {
1546 $$ = build($2, $1, $3);
1548 | expr T_RELOP expr {
1549 $$ = build($2, $1, $3);
1551 | expr T_EQOP expr {
1552 $$ = build($2, $1, $3);
1555 $$ = build(AND, $1, $3);
1558 $$ = build(XOR, $1, $3);
1561 $$ = build(OR, $1, $3);
1563 | expr T_LOGAND expr {
1564 $$ = build(LOGAND, $1, $3);
1566 | expr T_LOGOR expr {
1567 $$ = build(LOGOR, $1, $3);
1569 | expr T_QUEST expr T_COLON expr {
1570 $$ = build(QUEST, $1, build(COLON, $3, $5));
1572 | expr T_ASSIGN expr {
1573 $$ = build(ASSIGN, $1, $3);
1575 | expr T_OPASS expr {
1576 $$ = build($2, $1, $3);
1578 | expr T_COMMA expr {
1579 $$ = build(COMMA, $1, $3);
1588 /* XXX really necessary? */
1591 $$ = getnnode(getsym($1), yychar);
1597 $$ = getcnode(gettyp($1->v_tspec), $1);
1599 | T_LPARN expr T_RPARN {
1604 | T_LPARN comp_stmnt_lbrace declaration_list expr_stmnt_list {
1607 initsym = mktempsym(duptyp($4->tn_type));
1611 } comp_stmnt_rbrace T_RPARN {
1612 $$ = getnnode(initsym, 0);
1614 | T_LPARN comp_stmnt_lbrace expr_stmnt_list {
1617 initsym = mktempsym($3->tn_type);
1621 } comp_stmnt_rbrace T_RPARN {
1622 $$ = getnnode(initsym, 0);
1625 $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
1628 $$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
1631 $$ = build(STAR, $2, NULL);
1634 $$ = build(AMPER, $2, NULL);
1637 $$ = build($1, $2, NULL);
1640 if (tflag && $1 == PLUS) {
1641 /* unary + is illegal in traditional C */
1644 $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
1646 | term T_LBRACK expr T_RBRACK {
1647 $$ = build(STAR, build(PLUS, $1, $3), NULL);
1649 | term T_LPARN T_RPARN {
1650 $$ = funccall($1, NULL);
1652 | term T_LPARN func_arg_list T_RPARN {
1653 $$ = funccall($1, $3);
1655 | term point_or_arrow T_NAME {
1658 /* XXX strmemb should be integrated in build() */
1660 /* must to this before strmemb is called */
1663 msym = strmemb($1, $2, getsym($3));
1664 $$ = build($2, $1, getnnode(msym, 0));
1669 | T_SIZEOF term %prec T_SIZEOF {
1670 if (($$ = $2 == NULL ? NULL : bldszof($2->tn_type)) != NULL)
1671 chkmisc($2, 0, 0, 0, 0, 0, 1);
1673 | T_SIZEOF T_LPARN type_name T_RPARN %prec T_SIZEOF {
1676 | T_LPARN type_name T_RPARN term %prec T_UNOP {
1679 | T_LPARN type_name T_RPARN %prec T_UNOP {
1680 sym_t *tmp = mktempsym($2);
1681 idecl(tmp, 1, NULL);
1682 } init_lbrace init_expr_list init_rbrace {
1685 $$ = getnnode(initsym, 0);
1693 | T_STRING string2 {
1694 $$ = catstrg($1, $2);
1701 /* concatenated strings are illegal in traditional C */
1706 | string2 T_STRING {
1707 $$ = catstrg($1, $2);
1712 expr %prec T_COMMA {
1713 $$ = funcarg(NULL, $1);
1715 | func_arg_list T_COMMA expr {
1716 $$ = funcarg($1, $3);
1755 static __inline int uq_gt(uint64_t, uint64_t);
1757 uq_gt(uint64_t a, uint64_t b)
1763 static __inline int q_gt(int64_t, int64_t);
1765 q_gt(int64_t a, int64_t b)
1771 #define q_lt(a, b) q_gt(b, a)
1774 * Gets a node for a constant and returns the value of this constant
1776 * Is the node not constant or too large for int or of type float,
1777 * a warning will be printed.
1779 * toicon() should be used only inside declarations. If it is used in
1780 * expressions, it frees the memory used for the expression.
1783 toicon(tnode_t *tn, int required)
1789 v = constant(tn, required);
1792 * Abstract declarations are used inside expression. To free
1793 * the memory would be a fatal error.
1795 if (dcs->d_ctx != ABSTRACT)
1798 if ((t = v->v_tspec) == FLOAT || t == DOUBLE || t == LDOUBLE) {
1800 /* integral constant expression expected */
1805 if (uq_gt((uint64_t)v->v_quad,
1806 (uint64_t)INT_MAX)) {
1807 /* integral constant too large */
1811 if (q_gt(v->v_quad, (int64_t)INT_MAX) ||
1812 q_lt(v->v_quad, (int64_t)INT_MIN)) {
1813 /* integral constant too large */
1823 idecl(sym_t *decl, int initflg, sbuf_t *rename)
1830 switch (dcs->d_ctx) {
1832 if (rename != NULL) {
1833 if (decl->s_rename != NULL)
1836 s = getlblk(1, rename->sb_len + 1);
1837 (void)memcpy(s, rename->sb_name, rename->sb_len + 1);
1839 freeyyv(&rename, T_NAME);
1841 decl1ext(decl, initflg);
1844 if (rename != NULL) {
1845 /* symbol renaming can't be used on function arguments */
1847 freeyyv(&rename, T_NAME);
1850 (void)decl1arg(decl, initflg);
1853 if (rename != NULL) {
1854 /* symbol renaming can't be used on automatic variables */
1856 freeyyv(&rename, T_NAME);
1859 decl1loc(decl, initflg);
1865 if (initflg && !initerr)
1870 * Discard all input tokens up to and including the next
1871 * unmatched right paren
1880 freeyyv(&yylval, yychar);
1883 while (yychar != T_RPARN || --level > 0) {
1884 if (yychar == T_LPARN) {
1886 } else if (yychar <= 0) {
1889 freeyyv(&yylval, yychar = yylex());