[BACK]Return to cgram.y CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / xlint / lint1

Annotation of src/usr.bin/xlint/lint1/cgram.y, Revision 1.327

1.2       cgd         1: %{
1.327   ! rillig      2: /* $NetBSD: cgram.y,v 1.326 2021/07/15 18:13:25 rillig Exp $ */
1.2       cgd         3:
1.1       cgd         4: /*
1.9       cgd         5:  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
1.1       cgd         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:  * 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
                     20:  *     The NetBSD Project.
                     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.
                     23:  *
                     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.
                     34:  */
                     35:
1.13      christos   36: #include <sys/cdefs.h>
1.23      tv         37: #if defined(__RCSID) && !defined(lint)
1.327   ! rillig     38: __RCSID("$NetBSD: cgram.y,v 1.326 2021/07/15 18:13:25 rillig Exp $");
1.1       cgd        39: #endif
                     40:
1.108     rillig     41: #include <limits.h>
1.1       cgd        42: #include <stdlib.h>
1.12      cjs        43: #include <string.h>
1.1       cgd        44:
                     45: #include "lint1.h"
                     46:
1.41      christos   47: extern char *yytext;
1.132     rillig     48:
1.1       cgd        49: /*
1.148     rillig     50:  * Contains the level of current declaration, used for symbol table entries.
                     51:  * 0 is the top-level, > 0 is inside a function body.
1.1       cgd        52:  */
1.171     rillig     53: int    block_level;
1.1       cgd        54:
                     55: /*
1.171     rillig     56:  * level for memory allocation. Normally the same as block_level.
1.49      wiz        57:  * An exception is the declaration of arguments in prototypes. Memory
1.1       cgd        58:  * for these can't be freed after the declaration, but symbols must
                     59:  * be removed from the symbol table after the declaration.
                     60:  */
1.171     rillig     61: int    mem_block_level;
1.1       cgd        62:
1.15      christos   63: /*
                     64:  * Save the no-warns state and restore it to avoid the problem where
                     65:  * if (expr) { stmt } / * NOLINT * / stmt;
                     66:  */
1.55      christos   67: static int olwarn = LWARN_BAD;
1.15      christos   68:
1.174     rillig     69: static void    cgram_declare(sym_t *, bool, sbuf_t *);
1.148     rillig     70: static void    ignore_up_to_rparen(void);
1.75      christos   71: static sym_t   *symbolrename(sym_t *, sbuf_t *);
                     72:
1.1       cgd        73:
1.15      christos   74: #ifdef DEBUG
1.148     rillig     75: static void
                     76: CLEAR_WARN_FLAGS(const char *file, size_t line)
1.15      christos   77: {
1.190     rillig     78:        printf("%s:%d: %s:%zu: clearing flags\n",
                     79:            curr_pos.p_file, curr_pos.p_line, file, line);
1.148     rillig     80:        clear_warn_flags();
1.55      christos   81:        olwarn = LWARN_BAD;
1.15      christos   82: }
                     83:
1.148     rillig     84: static void
                     85: SAVE_WARN_FLAGS(const char *file, size_t line)
1.15      christos   86: {
1.149     rillig     87:        lint_assert(olwarn == LWARN_BAD);
1.190     rillig     88:        printf("%s:%d: %s:%zu: saving flags %d\n",
                     89:            curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
1.55      christos   90:        olwarn = lwarn;
1.15      christos   91: }
                     92:
1.148     rillig     93: static void
                     94: RESTORE_WARN_FLAGS(const char *file, size_t line)
1.15      christos   95: {
1.55      christos   96:        if (olwarn != LWARN_BAD) {
                     97:                lwarn = olwarn;
1.190     rillig     98:                printf("%s:%d: %s:%zu: restoring flags %d\n",
                     99:                    curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
1.55      christos  100:                olwarn = LWARN_BAD;
1.15      christos  101:        } else
1.148     rillig    102:                CLEAR_WARN_FLAGS(file, line);
1.15      christos  103: }
1.117     rillig    104: #define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args)
1.15      christos  105: #else
1.190     rillig    106: #define CLEAR_WARN_FLAGS(f, l) clear_warn_flags(), olwarn = LWARN_BAD
1.148     rillig    107: #define SAVE_WARN_FLAGS(f, l)  olwarn = lwarn
                    108: #define RESTORE_WARN_FLAGS(f, l) \
                    109:        (void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn))
1.176     rillig    110: #define cgram_debug(fmt, args...) do { } while (false)
1.15      christos  111: #endif
1.73      christos  112:
1.190     rillig    113: #define clear_warning_flags()  CLEAR_WARN_FLAGS(__FILE__, __LINE__)
                    114: #define save_warning_flags()   SAVE_WARN_FLAGS(__FILE__, __LINE__)
                    115: #define restore_warning_flags()        RESTORE_WARN_FLAGS(__FILE__, __LINE__)
1.187     rillig    116:
1.73      christos  117: /* unbind the anonymous struct members from the struct */
                    118: static void
                    119: anonymize(sym_t *s)
                    120: {
1.219     rillig    121:        for ( ; s != NULL; s = s->s_next)
1.73      christos  122:                s->s_styp = NULL;
                    123: }
1.297     rillig    124:
1.1       cgd       125: %}
                    126:
1.314     rillig    127: %expect 165
1.40      christos  128:
1.1       cgd       129: %union {
                    130:        val_t   *y_val;
1.297     rillig    131:        sbuf_t  *y_name;
1.1       cgd       132:        sym_t   *y_sym;
                    133:        op_t    y_op;
                    134:        scl_t   y_scl;
                    135:        tspec_t y_tspec;
                    136:        tqual_t y_tqual;
                    137:        type_t  *y_type;
                    138:        tnode_t *y_tnode;
1.35      christos  139:        range_t y_range;
1.121     rillig    140:        strg_t  *y_string;
1.243     rillig    141:        qual_ptr *y_qual_ptr;
1.219     rillig    142:        bool    y_seen_statement;
1.253     rillig    143:        struct generic_association *y_generic;
1.1       cgd       144: };
                    145:
1.126     rillig    146: %token                 T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
1.230     rillig    147: %token                 T_POINT T_ARROW
1.310     rillig    148: %token                 T_COMPLEMENT T_LOGNOT
1.1       cgd       149: %token <y_op>          T_INCDEC
                    150: %token                 T_SIZEOF
1.94      christos  151: %token                 T_BUILTIN_OFFSETOF
1.58      christos  152: %token                 T_TYPEOF
                    153: %token                 T_EXTENSION
1.199     christos  154: %token                 T_ALIGNAS
1.44      christos  155: %token                 T_ALIGNOF
1.189     rillig    156: %token                 T_ASTERISK
1.150     rillig    157: %token <y_op>          T_MULTIPLICATIVE
                    158: %token <y_op>          T_ADDITIVE
                    159: %token <y_op>          T_SHIFT
                    160: %token <y_op>          T_RELATIONAL
                    161: %token <y_op>          T_EQUALITY
1.189     rillig    162: %token                 T_AMPER
1.191     rillig    163: %token                 T_BITXOR
1.189     rillig    164: %token                 T_BITOR
                    165: %token                 T_LOGAND
                    166: %token                 T_LOGOR
1.1       cgd       167: %token                 T_QUEST
                    168: %token                 T_COLON
1.189     rillig    169: %token                 T_ASSIGN
1.150     rillig    170: %token <y_op>          T_OPASSIGN
1.1       cgd       171: %token                 T_COMMA
                    172: %token                 T_SEMI
1.147     rillig    173: %token                 T_ELLIPSIS
1.41      christos  174: %token                 T_REAL
                    175: %token                 T_IMAG
1.81      christos  176: %token                 T_GENERIC
1.95      christos  177: %token                 T_NORETURN
1.1       cgd       178:
                    179: /* storage classes (extern, static, auto, register and typedef) */
                    180: %token <y_scl>         T_SCLASS
                    181:
1.152     rillig    182: /*
                    183:  * predefined type keywords (char, int, short, long, unsigned, signed,
1.326     rillig    184:  * float, double, void); see T_TYPENAME for types from typedef
1.152     rillig    185:  */
1.1       cgd       186: %token <y_tspec>       T_TYPE
                    187:
1.152     rillig    188: /* qualifiers (const, volatile, restrict, _Thread_local) */
1.1       cgd       189: %token <y_tqual>       T_QUAL
                    190:
                    191: /* struct or union */
1.152     rillig    192: %token <y_tspec>       T_STRUCT_OR_UNION
1.1       cgd       193:
                    194: /* remaining keywords */
1.153     rillig    195: %token                 T_ASM
                    196: %token                 T_BREAK
1.1       cgd       197: %token                 T_CASE
1.153     rillig    198: %token                 T_CONTINUE
1.1       cgd       199: %token                 T_DEFAULT
1.153     rillig    200: %token                 T_DO
1.1       cgd       201: %token                 T_ELSE
1.153     rillig    202: %token                 T_ENUM
1.1       cgd       203: %token                 T_FOR
                    204: %token                 T_GOTO
1.153     rillig    205: %token                 T_IF
                    206: %token                 T_PACKED
1.1       cgd       207: %token                 T_RETURN
1.153     rillig    208: %token                 T_SWITCH
1.11      cgd       209: %token                 T_SYMBOLRENAME
1.153     rillig    210: %token                 T_WHILE
1.266     rillig    211:
                    212: %token                 T_ATTRIBUTE
                    213: %token                 T_AT_ALIAS
                    214: %token                 T_AT_ALIGNED
                    215: %token                 T_AT_ALLOC_SIZE
                    216: %token                 T_AT_ALWAYS_INLINE
                    217: %token                 T_AT_BOUNDED
                    218: %token                 T_AT_BUFFER
                    219: %token                 T_AT_COLD
                    220: %token                 T_AT_COMMON
                    221: %token                 T_AT_CONSTRUCTOR
                    222: %token                 T_AT_DEPRECATED
                    223: %token                 T_AT_DESTRUCTOR
                    224: %token                 T_AT_FALLTHROUGH
                    225: %token                 T_AT_FORMAT
                    226: %token                 T_AT_FORMAT_ARG
                    227: %token                 T_AT_FORMAT_GNU_PRINTF
                    228: %token                 T_AT_FORMAT_PRINTF
                    229: %token                 T_AT_FORMAT_SCANF
                    230: %token                 T_AT_FORMAT_STRFMON
                    231: %token                 T_AT_FORMAT_STRFTIME
                    232: %token                 T_AT_FORMAT_SYSLOG
                    233: %token                 T_AT_GNU_INLINE
1.313     rillig    234: %token                 T_AT_HOT
1.266     rillig    235: %token                 T_AT_MALLOC
                    236: %token                 T_AT_MAY_ALIAS
                    237: %token                 T_AT_MINBYTES
                    238: %token                 T_AT_MODE
                    239: %token                 T_AT_NOINLINE
                    240: %token                 T_AT_NONNULL
                    241: %token                 T_AT_NONSTRING
                    242: %token                 T_AT_NORETURN
                    243: %token                 T_AT_NOTHROW
                    244: %token                 T_AT_NO_INSTRUMENT_FUNCTION
                    245: %token                 T_AT_OPTIMIZE
                    246: %token                 T_AT_PACKED
                    247: %token                 T_AT_PCS
                    248: %token                 T_AT_PURE
                    249: %token                 T_AT_RETURNS_TWICE
                    250: %token                 T_AT_SECTION
                    251: %token                 T_AT_SENTINEL
                    252: %token                 T_AT_STRING
                    253: %token                 T_AT_TLS_MODEL
                    254: %token                 T_AT_TUNION
                    255: %token                 T_AT_UNUSED
                    256: %token                 T_AT_USED
                    257: %token                 T_AT_VISIBILITY
                    258: %token                 T_AT_WARN_UNUSED_RESULT
                    259: %token                 T_AT_WEAK
1.1       cgd       260:
1.312     rillig    261: %left  T_THEN
                    262: %left  T_ELSE
1.1       cgd       263: %left  T_COMMA
1.150     rillig    264: %right T_ASSIGN T_OPASSIGN
1.1       cgd       265: %right T_QUEST T_COLON
                    266: %left  T_LOGOR
                    267: %left  T_LOGAND
1.150     rillig    268: %left  T_BITOR
1.191     rillig    269: %left  T_BITXOR
1.145     rillig    270: %left  T_AMPER
1.150     rillig    271: %left  T_EQUALITY
                    272: %left  T_RELATIONAL
                    273: %left  T_SHIFT
                    274: %left  T_ADDITIVE
                    275: %left  T_ASTERISK T_MULTIPLICATIVE
1.1       cgd       276:
1.297     rillig    277: %token <y_name>        T_NAME
                    278: %token <y_name>        T_TYPENAME
1.1       cgd       279: %token <y_val>         T_CON
1.121     rillig    280: %token <y_string>      T_STRING
1.1       cgd       281:
1.320     rillig    282: %type  <y_sym>         identifier_sym
                    283: %type  <y_name>        identifier
                    284: %type  <y_string>      string
                    285: %type  <y_string>      string2
                    286:
1.307     rillig    287: %type  <y_tnode>       primary_expression
1.320     rillig    288: %type  <y_tnode>       generic_selection
                    289: %type  <y_generic>     generic_assoc_list
                    290: %type  <y_generic>     generic_association
1.307     rillig    291: %type  <y_tnode>       postfix_expression
1.320     rillig    292: %type  <y_tnode>       gcc_statement_expr_list
                    293: %type  <y_tnode>       gcc_statement_expr_item
                    294: %type  <y_op>          point_or_arrow
1.316     rillig    295: %type  <y_tnode>       argument_expression_list
1.308     rillig    296: %type  <y_tnode>       unary_expression
1.316     rillig    297: %type  <y_tnode>       cast_expression
1.325     rillig    298: %type  <y_tnode>       conditional_expression
                    299: %type  <y_tnode>       assignment_expression
1.322     rillig    300: %type  <y_tnode>       expression_opt
                    301: %type  <y_tnode>       expression
1.320     rillig    302: %type  <y_tnode>       constant_expr
1.307     rillig    303:
1.320     rillig    304: %type  <y_type>        begin_type_typespec
1.300     rillig    305: %type  <y_type>        type_specifier
                    306: %type  <y_type>        notype_type_specifier
                    307: %type  <y_type>        struct_or_union_specifier
                    308: %type  <y_tspec>       struct_or_union
1.306     rillig    309: %type  <y_sym>         braced_struct_declaration_list
                    310: %type  <y_sym>         struct_declaration_list_with_rbrace
1.300     rillig    311: %type  <y_sym>         struct_declaration_list
1.1       cgd       312: %type  <y_sym>         struct_declaration
1.324     rillig    313: %type  <y_sym>         notype_struct_declarators
                    314: %type  <y_sym>         type_struct_declarators
                    315: %type  <y_sym>         notype_struct_declarator
                    316: %type  <y_sym>         type_struct_declarator
1.320     rillig    317: %type  <y_type>        enum_specifier
1.306     rillig    318: %type  <y_sym>         enum_declaration
                    319: %type  <y_sym>         enums_with_opt_comma
1.259     rillig    320: %type  <y_sym>         enumerator_list
1.1       cgd       321: %type  <y_sym>         enumerator
1.320     rillig    322: %type  <y_qual_ptr>    type_qualifier
                    323: %type  <y_qual_ptr>    pointer
                    324: %type  <y_qual_ptr>    asterisk
                    325: %type  <y_qual_ptr>    type_qualifier_list_opt
                    326: %type  <y_qual_ptr>    type_qualifier_list
1.324     rillig    327: %type  <y_sym>         notype_declarator
                    328: %type  <y_sym>         type_declarator
                    329: %type  <y_sym>         notype_direct_declarator
                    330: %type  <y_sym>         type_direct_declarator
                    331: %type  <y_sym>         type_param_declarator
                    332: %type  <y_sym>         notype_param_declarator
                    333: %type  <y_sym>         direct_param_declarator
                    334: %type  <y_sym>         direct_notype_param_declarator
1.320     rillig    335: %type  <y_sym>         param_list
                    336: %type  <y_tnode>       array_size
1.1       cgd       337: %type  <y_sym>         identifier_list
1.320     rillig    338: %type  <y_type>        type_name
                    339: %type  <y_sym>         abstract_declaration
1.246     rillig    340: %type  <y_sym>         abstract_declarator
                    341: %type  <y_sym>         direct_abstract_declarator
1.320     rillig    342: %type  <y_sym>         abstract_decl_param_list
1.1       cgd       343: %type  <y_sym>         vararg_parameter_type_list
                    344: %type  <y_sym>         parameter_type_list
                    345: %type  <y_sym>         parameter_declaration
1.320     rillig    346: %type  <y_range>       range
1.297     rillig    347: %type  <y_name>        asm_or_symbolrename_opt
1.320     rillig    348:
1.185     rillig    349: %type  <y_seen_statement> block_item_list
                    350: %type  <y_seen_statement> block_item
1.320     rillig    351: %type  <y_tnode>       do_while_expr
1.324     rillig    352: %type  <y_sym>         func_declarator
1.1       cgd       353:
                    354: %%
                    355:
                    356: program:
                    357:          /* empty */ {
                    358:                if (sflag) {
                    359:                        /* empty translation unit */
                    360:                        error(272);
                    361:                } else if (!tflag) {
                    362:                        /* empty translation unit */
                    363:                        warning(272);
                    364:                }
                    365:          }
                    366:        | translation_unit
                    367:        ;
                    368:
1.319     rillig    369: identifier_sym:                        /* helper for struct/union/enum */
                    370:          identifier {
                    371:                $$ = getsym($1);
                    372:          }
                    373:        ;
                    374:
1.321     rillig    375: /* K&R ???, C90 ???, C99 6.4.2.1, C11 ??? */
1.319     rillig    376: identifier:
                    377:          T_NAME {
                    378:                $$ = $1;
                    379:                cgram_debug("name '%s'", $$->sb_name);
                    380:          }
                    381:        | T_TYPENAME {
                    382:                $$ = $1;
                    383:                cgram_debug("typename '%s'", $$->sb_name);
                    384:          }
                    385:        ;
                    386:
                    387: /* see C99 6.4.5, string literals are joined by 5.1.1.2 */
                    388: string:
                    389:          T_STRING
                    390:        | T_STRING string2 {
                    391:                $$ = cat_strings($1, $2);
                    392:          }
                    393:        ;
                    394:
                    395: /* see C99 6.4.5, string literals are joined by 5.1.1.2 */
                    396: string2:
                    397:          T_STRING {
                    398:                if (tflag) {
                    399:                        /* concatenated strings are illegal in traditional C */
                    400:                        warning(219);
                    401:                }
                    402:                $$ = $1;
                    403:          }
                    404:        | string2 T_STRING {
                    405:                $$ = cat_strings($1, $2);
                    406:          }
                    407:        ;
                    408:
1.321     rillig    409: /* K&R 7.1, C90 ???, C99 6.5.1, C11 6.5.1 */
1.319     rillig    410: primary_expression:
                    411:          T_NAME {
                    412:                /* XXX really necessary? */
                    413:                if (yychar < 0)
                    414:                        yychar = yylex();
                    415:                $$ = new_name_node(getsym($1), yychar);
                    416:          }
                    417:        | T_CON {
                    418:                $$ = expr_new_constant(gettyp($1->v_tspec), $1);
                    419:          }
                    420:        | string {
                    421:                $$ = new_string_node($1);
                    422:          }
1.322     rillig    423:        | T_LPAREN expression T_RPAREN {
1.319     rillig    424:                if ($2 != NULL)
                    425:                        $2->tn_parenthesized = true;
                    426:                $$ = $2;
                    427:          }
                    428:        | generic_selection
                    429:        /* GCC primary-expression, see c_parser_postfix_expression */
                    430:        | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
                    431:                symtyp = FMEMBER;
                    432:                $$ = build_offsetof($3, getsym($5));
                    433:          }
                    434:        ;
                    435:
1.321     rillig    436: /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
1.319     rillig    437: generic_selection:
                    438:          T_GENERIC T_LPAREN assignment_expression T_COMMA
                    439:            generic_assoc_list T_RPAREN {
                    440:                /* generic selection requires C11 or later */
                    441:                c11ism(345);
                    442:                $$ = build_generic_selection($3, $5);
                    443:          }
                    444:        ;
                    445:
1.321     rillig    446: /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
1.319     rillig    447: generic_assoc_list:
                    448:          generic_association
                    449:        | generic_assoc_list T_COMMA generic_association {
                    450:                $3->ga_prev = $1;
                    451:                $$ = $3;
                    452:          }
                    453:        ;
                    454:
1.321     rillig    455: /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
1.319     rillig    456: generic_association:
                    457:          type_name T_COLON assignment_expression {
                    458:                $$ = getblk(sizeof(*$$));
                    459:                $$->ga_arg = $1;
                    460:                $$->ga_result = $3;
                    461:          }
                    462:        | T_DEFAULT T_COLON assignment_expression {
                    463:                $$ = getblk(sizeof(*$$));
                    464:                $$->ga_arg = NULL;
                    465:                $$->ga_result = $3;
                    466:          }
1.1       cgd       467:        ;
                    468:
1.321     rillig    469: /* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
1.319     rillig    470: postfix_expression:
                    471:          primary_expression
1.322     rillig    472:        | postfix_expression T_LBRACK expression T_RBRACK {
1.319     rillig    473:                $$ = build(INDIR, build(PLUS, $1, $3), NULL);
                    474:          }
                    475:        | postfix_expression T_LPAREN T_RPAREN {
                    476:                $$ = new_function_call_node($1, NULL);
                    477:          }
                    478:        | postfix_expression T_LPAREN argument_expression_list T_RPAREN {
                    479:                $$ = new_function_call_node($1, $3);
                    480:          }
                    481:        | postfix_expression point_or_arrow T_NAME {
1.323     rillig    482:                $$ = build_member_access($1, $2, $3);
1.319     rillig    483:          }
                    484:        | postfix_expression T_INCDEC {
                    485:                $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
                    486:          }
                    487:        | T_LPAREN type_name T_RPAREN { /* C99 6.5.2.5 "Compound literals" */
                    488:                sym_t *tmp = mktempsym($2);
                    489:                begin_initialization(tmp);
                    490:                cgram_declare(tmp, true, NULL);
                    491:          } init_lbrace initializer_list comma_opt init_rbrace {
                    492:                if (!Sflag)
                    493:                         /* compound literals are a C9X/GCC extension */
                    494:                         gnuism(319);
                    495:                $$ = new_name_node(*current_initsym(), 0);
                    496:                end_initialization();
1.1       cgd       497:          }
1.319     rillig    498:        | T_LPAREN compound_statement_lbrace gcc_statement_expr_list {
                    499:                block_level--;
                    500:                mem_block_level--;
                    501:                begin_initialization(mktempsym(dup_type($3->tn_type)));
                    502:                mem_block_level++;
                    503:                block_level++;
                    504:                /* ({ }) is a GCC extension */
                    505:                gnuism(320);
                    506:          } compound_statement_rbrace T_RPAREN {
                    507:                $$ = new_name_node(*current_initsym(), 0);
                    508:                end_initialization();
1.1       cgd       509:          }
                    510:        ;
                    511:
1.319     rillig    512: comma_opt:                     /* helper for 'postfix_expression' */
                    513:          /* empty */
                    514:        | T_COMMA
                    515:        ;
                    516:
1.193     rillig    517: /*
1.319     rillig    518:  * The inner part of a GCC statement-expression of the form ({ ... }).
1.193     rillig    519:  *
1.319     rillig    520:  * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
1.193     rillig    521:  */
1.319     rillig    522: gcc_statement_expr_list:
                    523:          gcc_statement_expr_item
                    524:        | gcc_statement_expr_list gcc_statement_expr_item {
                    525:                $$ = $2;
                    526:          }
                    527:        ;
                    528:
                    529: gcc_statement_expr_item:
1.326     rillig    530:          declaration_or_error {
1.319     rillig    531:                clear_warning_flags();
                    532:                $$ = NULL;
                    533:          }
                    534:        | non_expr_statement {
                    535:                $$ = expr_zalloc_tnode();
                    536:                $$->tn_type = gettyp(VOID);
                    537:          }
1.322     rillig    538:        | expression T_SEMI {
1.319     rillig    539:                if ($1 == NULL) {       /* in case of syntax errors */
                    540:                        $$ = expr_zalloc_tnode();
                    541:                        $$->tn_type = gettyp(VOID);
                    542:                } else {
                    543:                        /* XXX: do that only on the last name */
                    544:                        if ($1->tn_op == NAME)
                    545:                                $1->tn_sym->s_used = true;
                    546:                        $$ = $1;
                    547:                        expr($1, false, false, false, false);
                    548:                        seen_fallthrough = false;
                    549:                }
                    550:          }
                    551:        ;
                    552:
                    553: point_or_arrow:                        /* helper for 'postfix_expression' */
                    554:          T_POINT {
                    555:                symtyp = FMEMBER;
                    556:                $$ = POINT;
                    557:          }
                    558:        | T_ARROW {
                    559:                symtyp = FMEMBER;
                    560:                $$ = ARROW;
                    561:          }
                    562:        ;
                    563:
1.321     rillig    564: /* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
1.319     rillig    565: argument_expression_list:
1.325     rillig    566:          assignment_expression {
1.319     rillig    567:                $$ = new_function_argument_node(NULL, $1);
                    568:          }
1.325     rillig    569:        | argument_expression_list T_COMMA assignment_expression {
1.319     rillig    570:                $$ = new_function_argument_node($1, $3);
                    571:          }
                    572:        ;
                    573:
1.321     rillig    574: /* K&R 7.2, C90 ???, C99 6.5.3, C11 6.5.3 */
1.319     rillig    575: unary_expression:
                    576:          postfix_expression
                    577:        | T_INCDEC unary_expression {
                    578:                $$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
                    579:          }
                    580:        | T_AMPER cast_expression {
                    581:                $$ = build(ADDR, $2, NULL);
                    582:          }
                    583:        | T_ASTERISK cast_expression {
                    584:                $$ = build(INDIR, $2, NULL);
                    585:          }
                    586:        | T_ADDITIVE cast_expression {
                    587:                if (tflag && $1 == PLUS) {
                    588:                        /* unary + is illegal in traditional C */
                    589:                        warning(100);
1.1       cgd       590:                }
1.319     rillig    591:                $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
                    592:          }
                    593:        | T_COMPLEMENT cast_expression {
                    594:                $$ = build(COMPL, $2, NULL);
                    595:          }
                    596:        | T_LOGNOT cast_expression {
                    597:                $$ = build(NOT, $2, NULL);
                    598:          }
                    599:        | T_REAL cast_expression {      /* GCC c_parser_unary_expression */
                    600:                $$ = build(REAL, $2, NULL);
                    601:          }
                    602:        | T_IMAG cast_expression {      /* GCC c_parser_unary_expression */
                    603:                $$ = build(IMAG, $2, NULL);
                    604:          }
                    605:        | T_EXTENSION cast_expression { /* GCC c_parser_unary_expression */
                    606:                $$ = $2;
                    607:          }
                    608:        | T_SIZEOF unary_expression {
                    609:                $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
                    610:                if ($$ != NULL)
                    611:                        check_expr_misc($2, false, false, false, false, false, true);
                    612:          }
                    613:        | T_SIZEOF T_LPAREN type_name T_RPAREN {
                    614:                $$ = build_sizeof($3);
                    615:          }
1.321     rillig    616:        /* K&R ---, C90 ---, C99 ---, C11 6.5.3 */
1.319     rillig    617:        | T_ALIGNOF T_LPAREN type_name T_RPAREN {
                    618:                $$ = build_alignof($3);
                    619:          }
                    620:        ;
                    621:
                    622: /* The rule 'unary_operator' is inlined into unary_expression. */
                    623:
1.321     rillig    624: /* K&R 7.2, C90 ???, C99 6.5.4, C11 6.5.4 */
1.319     rillig    625: cast_expression:
                    626:          unary_expression
                    627:        | T_LPAREN type_name T_RPAREN cast_expression {
                    628:                $$ = cast($4, $2);
                    629:          }
                    630:        ;
                    631:
1.322     rillig    632: expression_opt:
1.319     rillig    633:          /* empty */ {
                    634:                $$ = NULL;
                    635:          }
1.322     rillig    636:        | expression
1.319     rillig    637:        ;
                    638:
1.325     rillig    639: /* 'conditional_expression' also implements 'multiplicative_expression'. */
                    640: /* 'conditional_expression' also implements 'additive_expression'. */
                    641: /* 'conditional_expression' also implements 'shift_expression'. */
                    642: /* 'conditional_expression' also implements 'relational_expression'. */
                    643: /* 'conditional_expression' also implements 'equality_expression'. */
                    644: /* 'conditional_expression' also implements 'AND_expression'. */
                    645: /* 'conditional_expression' also implements 'exclusive_OR_expression'. */
                    646: /* 'conditional_expression' also implements 'inclusive_OR_expression'. */
                    647: /* 'conditional_expression' also implements 'logical_AND_expression'. */
                    648: /* 'conditional_expression' also implements 'logical_OR_expression'. */
                    649: /* K&R ???, C90 ???, C99 6.5.5 to 6.5.15, C11 6.5.5 to 6.5.15 */
                    650: conditional_expression:
                    651:          conditional_expression T_ASTERISK conditional_expression {
1.319     rillig    652:                $$ = build(MULT, $1, $3);
                    653:          }
1.325     rillig    654:        | conditional_expression T_MULTIPLICATIVE conditional_expression {
1.319     rillig    655:                $$ = build($2, $1, $3);
                    656:          }
1.325     rillig    657:        | conditional_expression T_ADDITIVE conditional_expression {
1.319     rillig    658:                $$ = build($2, $1, $3);
                    659:          }
1.325     rillig    660:        | conditional_expression T_SHIFT conditional_expression {
1.319     rillig    661:                $$ = build($2, $1, $3);
                    662:          }
1.325     rillig    663:        | conditional_expression T_RELATIONAL conditional_expression {
1.319     rillig    664:                $$ = build($2, $1, $3);
                    665:          }
1.325     rillig    666:        | conditional_expression T_EQUALITY conditional_expression {
1.319     rillig    667:                $$ = build($2, $1, $3);
1.1       cgd       668:          }
1.325     rillig    669:        | conditional_expression T_AMPER conditional_expression {
1.319     rillig    670:                $$ = build(BITAND, $1, $3);
1.1       cgd       671:          }
1.325     rillig    672:        | conditional_expression T_BITXOR conditional_expression {
1.319     rillig    673:                $$ = build(BITXOR, $1, $3);
1.306     rillig    674:          }
1.325     rillig    675:        | conditional_expression T_BITOR conditional_expression {
1.319     rillig    676:                $$ = build(BITOR, $1, $3);
1.306     rillig    677:          }
1.325     rillig    678:        | conditional_expression T_LOGAND conditional_expression {
1.319     rillig    679:                $$ = build(LOGAND, $1, $3);
1.1       cgd       680:          }
1.325     rillig    681:        | conditional_expression T_LOGOR conditional_expression {
1.319     rillig    682:                $$ = build(LOGOR, $1, $3);
1.1       cgd       683:          }
1.325     rillig    684:        | conditional_expression T_QUEST conditional_expression
                    685:            T_COLON conditional_expression {
1.319     rillig    686:                $$ = build(QUEST, $1, build(COLON, $3, $5));
1.1       cgd       687:          }
1.325     rillig    688:        | cast_expression;
                    689:
                    690: /* K&R ???, C90 ???, C99 6.5.16, C11 6.5.16 */
                    691: assignment_expression:
                    692:          conditional_expression
                    693:        | assignment_expression T_ASSIGN conditional_expression {
1.319     rillig    694:                $$ = build(ASSIGN, $1, $3);
1.1       cgd       695:          }
1.325     rillig    696:        | assignment_expression T_OPASSIGN conditional_expression {
1.319     rillig    697:                $$ = build($2, $1, $3);
1.1       cgd       698:          }
1.325     rillig    699:        ;
                    700:
                    701: /* K&R ???, C90 ???, C99 6.5.17, C11 6.5.17 */
                    702: expression:
                    703:          assignment_expression
                    704:        | expression T_COMMA assignment_expression {
1.319     rillig    705:                $$ = build(COMMA, $1, $3);
1.1       cgd       706:          }
                    707:        ;
                    708:
1.319     rillig    709: constant_expr_list_opt:                /* helper for gcc_attribute */
1.1       cgd       710:          /* empty */
1.319     rillig    711:        | constant_expr_list
1.1       cgd       712:        ;
                    713:
1.319     rillig    714: constant_expr_list:            /* helper for gcc_attribute */
                    715:          constant_expr
                    716:        | constant_expr_list T_COMMA constant_expr
1.1       cgd       717:        ;
                    718:
1.319     rillig    719: constant_expr:                 /* C99 6.6 */
1.325     rillig    720:          conditional_expression
1.1       cgd       721:        ;
                    722:
1.326     rillig    723: declaration_or_error:
                    724:          declaration
                    725:        | error T_SEMI
                    726:        ;
                    727:
1.193     rillig    728: declaration:                   /* C99 6.7 */
1.306     rillig    729:          begin_type_declmods end_type T_SEMI {
1.3       jpo       730:                if (dcs->d_scl == TYPEDEF) {
1.1       cgd       731:                        /* typedef declares no type name */
                    732:                        warning(72);
                    733:                } else {
                    734:                        /* empty declaration */
                    735:                        warning(2);
                    736:                }
                    737:          }
1.324     rillig    738:        | begin_type_declmods end_type notype_init_declarators T_SEMI
1.306     rillig    739:        | begin_type_declaration_specifiers end_type T_SEMI {
1.3       jpo       740:                if (dcs->d_scl == TYPEDEF) {
1.1       cgd       741:                        /* typedef declares no type name */
                    742:                        warning(72);
1.195     rillig    743:                } else if (!dcs->d_nonempty_decl) {
1.1       cgd       744:                        /* empty declaration */
                    745:                        warning(2);
                    746:                }
                    747:          }
1.324     rillig    748:        | begin_type_declaration_specifiers end_type
                    749:            type_init_declarators T_SEMI
1.1       cgd       750:        ;
                    751:
1.306     rillig    752: begin_type_declaration_specifiers:     /* see C99 6.7 */
                    753:          begin_type_typespec {
                    754:                add_type($1);
                    755:          }
                    756:        | begin_type_declmods type_specifier {
                    757:                add_type($2);
                    758:          }
                    759:        | type_attribute begin_type_declaration_specifiers
                    760:        | begin_type_declaration_specifiers declmod
                    761:        | begin_type_declaration_specifiers notype_type_specifier {
                    762:                add_type($2);
                    763:          }
1.1       cgd       764:        ;
                    765:
1.319     rillig    766: begin_type_declmods:           /* see C99 6.7 */
1.306     rillig    767:          begin_type T_QUAL {
                    768:                add_qualifier($2);
                    769:          }
                    770:        | begin_type T_SCLASS {
                    771:                add_storage_class($2);
1.1       cgd       772:          }
1.306     rillig    773:        | begin_type_declmods declmod
1.1       cgd       774:        ;
                    775:
1.319     rillig    776: begin_type_noclass_declspecs:
                    777:          begin_type_typespec {
                    778:                add_type($1);
                    779:          }
                    780:        | type_attribute begin_type_noclass_declspecs
                    781:        | begin_type_noclass_declmods type_specifier {
                    782:                add_type($2);
                    783:          }
                    784:        | begin_type_noclass_declspecs T_QUAL {
                    785:                add_qualifier($2);
1.306     rillig    786:          }
1.319     rillig    787:        | begin_type_noclass_declspecs notype_type_specifier {
                    788:                add_type($2);
1.299     rillig    789:          }
1.319     rillig    790:        | begin_type_noclass_declspecs type_attribute
1.299     rillig    791:        ;
                    792:
1.306     rillig    793: begin_type_typespec:
                    794:          begin_type notype_type_specifier {
                    795:                $$ = $2;
                    796:          }
                    797:        | T_TYPENAME begin_type {
                    798:                $$ = getsym($1)->s_type;
                    799:          }
1.302     rillig    800:        ;
                    801:
1.319     rillig    802: begin_type_noclass_declmods:
                    803:          begin_type T_QUAL {
                    804:                add_qualifier($2);
                    805:          }
                    806:        | begin_type_noclass_declmods T_QUAL {
                    807:                add_qualifier($2);
                    808:          }
                    809:        ;
                    810:
                    811: declmod:
                    812:          T_QUAL {
                    813:                add_qualifier($1);
                    814:          }
                    815:        | T_SCLASS {
                    816:                add_storage_class($1);
                    817:          }
                    818:        | type_attribute_list
                    819:        ;
                    820:
1.302     rillig    821: type_attribute_list:
                    822:          type_attribute
                    823:        | type_attribute_list type_attribute
                    824:        ;
                    825:
                    826: type_attribute_opt:
                    827:          /* empty */
                    828:        | type_attribute
                    829:        ;
                    830:
                    831: type_attribute:                        /* See C11 6.7 declaration-specifiers */
1.306     rillig    832:          T_ATTRIBUTE T_LPAREN T_LPAREN {
                    833:            attron = true;
                    834:          } gcc_attribute_spec_list {
                    835:            attron = false;
                    836:          } T_RPAREN T_RPAREN
1.302     rillig    837:        | T_ALIGNAS T_LPAREN align_as T_RPAREN
                    838:        | T_PACKED {
                    839:                addpacked();
                    840:          }
                    841:        | T_NORETURN
                    842:        ;
                    843:
1.319     rillig    844: align_as:                      /* See alignment-specifier in C11 6.7.5 */
                    845:          type_specifier
                    846:        | constant_expr
                    847:        ;
                    848:
                    849: begin_type:
                    850:          /* empty */ {
                    851:                begin_type();
                    852:          }
                    853:        ;
                    854:
                    855: end_type:
                    856:          /* empty */ {
                    857:                end_type();
                    858:          }
                    859:        ;
                    860:
1.300     rillig    861: type_specifier:                        /* C99 6.7.2 */
                    862:          notype_type_specifier
1.1       cgd       863:        | T_TYPENAME {
                    864:                $$ = getsym($1)->s_type;
                    865:          }
                    866:        ;
                    867:
1.319     rillig    868: notype_type_specifier:         /* see C99 6.7.2 */
1.1       cgd       869:          T_TYPE {
                    870:                $$ = gettyp($1);
                    871:          }
1.316     rillig    872:        | T_TYPEOF cast_expression {    /* GCC extension */
1.60      christos  873:                $$ = $2->tn_type;
1.58      christos  874:          }
1.300     rillig    875:        | struct_or_union_specifier {
1.202     rillig    876:                end_declaration_level();
1.1       cgd       877:                $$ = $1;
                    878:          }
1.300     rillig    879:        | enum_specifier {
1.202     rillig    880:                end_declaration_level();
1.1       cgd       881:                $$ = $1;
                    882:          }
                    883:        ;
                    884:
1.300     rillig    885: struct_or_union_specifier:     /* C99 6.7.2.1 */
1.301     rillig    886:          struct_or_union identifier_sym {
1.1       cgd       887:                /*
                    888:                 * STDC requires that "struct a;" always introduces
                    889:                 * a new tag if "a" is not declared at current level
                    890:                 *
1.110     rillig    891:                 * yychar is valid because otherwise the parser would not
                    892:                 * have been able to decide if it must shift or reduce
1.1       cgd       893:                 */
1.183     rillig    894:                $$ = mktag($2, $1, false, yychar == T_SEMI);
1.1       cgd       895:          }
1.306     rillig    896:        | struct_or_union identifier_sym {
1.183     rillig    897:                dcs->d_tagtyp = mktag($2, $1, true, false);
1.306     rillig    898:          } braced_struct_declaration_list {
                    899:                $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
                    900:          }
                    901:        | struct_or_union {
                    902:                dcs->d_tagtyp = mktag(NULL, $1, true, false);
                    903:          } braced_struct_declaration_list {
                    904:                $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
1.1       cgd       905:          }
1.300     rillig    906:        | struct_or_union error {
1.1       cgd       907:                symtyp = FVFT;
                    908:                $$ = gettyp(INT);
                    909:          }
                    910:        ;
                    911:
1.300     rillig    912: struct_or_union:               /* C99 6.7.2.1 */
1.306     rillig    913:          struct_or_union type_attribute
                    914:        | T_STRUCT_OR_UNION {
1.1       cgd       915:                symtyp = FTAG;
1.202     rillig    916:                begin_declaration_level($1 == STRUCT ? MOS : MOU);
1.3       jpo       917:                dcs->d_offset = 0;
1.250     rillig    918:                dcs->d_sou_align_in_bits = CHAR_SIZE;
1.306     rillig    919:                $$ = $1;
                    920:          }
                    921:        ;
                    922:
1.319     rillig    923: braced_struct_declaration_list:        /* see C99 6.7.2.1 */
1.306     rillig    924:          struct_declaration_lbrace struct_declaration_list_with_rbrace {
                    925:                $$ = $2;
                    926:          }
1.1       cgd       927:        ;
                    928:
1.319     rillig    929: struct_declaration_lbrace:     /* see C99 6.7.2.1 */
1.306     rillig    930:          T_LBRACE {
                    931:                symtyp = FVFT;
1.269     rillig    932:          }
1.306     rillig    933:        ;
                    934:
1.319     rillig    935: struct_declaration_list_with_rbrace:   /* see C99 6.7.2.1 */
1.306     rillig    936:          struct_declaration_list T_SEMI T_RBRACE
                    937:        | struct_declaration_list T_RBRACE {
1.1       cgd       938:                if (sflag) {
1.123     rillig    939:                        /* syntax req. ';' after last struct/union member */
1.1       cgd       940:                        error(66);
                    941:                } else {
1.123     rillig    942:                        /* syntax req. ';' after last struct/union member */
1.1       cgd       943:                        warning(66);
                    944:                }
                    945:                $$ = $1;
                    946:          }
1.306     rillig    947:        | T_RBRACE {
                    948:                $$ = NULL;
                    949:          }
1.1       cgd       950:        ;
                    951:
1.319     rillig    952: struct_declaration_list:       /* C99 6.7.2.1 */
1.300     rillig    953:          struct_declaration
                    954:        | struct_declaration_list T_SEMI struct_declaration {
1.1       cgd       955:                $$ = lnklst($1, $3);
                    956:          }
                    957:        ;
                    958:
1.319     rillig    959: struct_declaration:            /* C99 6.7.2.1 */
1.306     rillig    960:          begin_type_noclass_declmods end_type {
1.1       cgd       961:                /* too late, i know, but getsym() compensates it */
1.120     rillig    962:                symtyp = FMEMBER;
1.324     rillig    963:          } notype_struct_declarators type_attribute_opt {
1.1       cgd       964:                symtyp = FVFT;
1.306     rillig    965:                $$ = $4;
1.1       cgd       966:          }
1.306     rillig    967:        | begin_type_noclass_declspecs end_type {
1.120     rillig    968:                symtyp = FMEMBER;
1.324     rillig    969:          } type_struct_declarators type_attribute_opt {
1.1       cgd       970:                symtyp = FVFT;
1.306     rillig    971:                $$ = $4;
1.1       cgd       972:          }
1.306     rillig    973:        | begin_type_noclass_declmods end_type type_attribute_opt {
1.288     rillig    974:                /* syntax error '%s' */
                    975:                error(249, "member without type");
                    976:                $$ = NULL;
1.1       cgd       977:          }
1.306     rillig    978:        | begin_type_noclass_declspecs end_type type_attribute_opt {
1.74      christos  979:                symtyp = FVFT;
1.73      christos  980:                if (!Sflag)
1.127     rillig    981:                        /* anonymous struct/union members is a C9X feature */
1.73      christos  982:                        warning(49);
1.228     rillig    983:                if (is_struct_or_union(dcs->d_type->t_tspec)) {
                    984:                        $$ = dcs->d_type->t_str->sou_first_member;
                    985:                        /* add all the members of the anonymous struct/union */
                    986:                        anonymize($$);
                    987:                } else {
                    988:                        /* syntax error '%s' */
                    989:                        error(249, "unnamed member");
1.232     rillig    990:                        $$ = NULL;
1.228     rillig    991:                }
1.1       cgd       992:          }
                    993:        | error {
                    994:                symtyp = FVFT;
                    995:                $$ = NULL;
                    996:          }
                    997:        ;
                    998:
1.324     rillig    999: notype_struct_declarators:
                   1000:          notype_struct_declarator {
1.111     rillig   1001:                $$ = declarator_1_struct_union($1);
1.1       cgd      1002:          }
1.324     rillig   1003:        | notype_struct_declarators {
1.120     rillig   1004:                symtyp = FMEMBER;
1.324     rillig   1005:          } T_COMMA type_struct_declarator {
1.111     rillig   1006:                $$ = lnklst($1, declarator_1_struct_union($4));
1.1       cgd      1007:          }
                   1008:        ;
                   1009:
1.324     rillig   1010: type_struct_declarators:
                   1011:          type_struct_declarator {
1.111     rillig   1012:                $$ = declarator_1_struct_union($1);
1.1       cgd      1013:          }
1.324     rillig   1014:        | type_struct_declarators {
1.120     rillig   1015:                symtyp = FMEMBER;
1.324     rillig   1016:          } T_COMMA type_struct_declarator {
1.111     rillig   1017:                $$ = lnklst($1, declarator_1_struct_union($4));
1.1       cgd      1018:          }
                   1019:        ;
                   1020:
1.324     rillig   1021: notype_struct_declarator:
                   1022:          notype_declarator
                   1023:        | notype_declarator T_COLON constant_expr {             /* C99 6.7.2.1 */
1.175     rillig   1024:                $$ = bitfield($1, to_int_constant($3, true));
1.1       cgd      1025:          }
                   1026:        | {
                   1027:                symtyp = FVFT;
1.168     rillig   1028:          } T_COLON constant_expr {                     /* C99 6.7.2.1 */
1.175     rillig   1029:                $$ = bitfield(NULL, to_int_constant($3, true));
1.1       cgd      1030:          }
                   1031:        ;
                   1032:
1.324     rillig   1033: type_struct_declarator:
                   1034:          type_declarator
                   1035:        | type_declarator T_COLON constant_expr {
1.175     rillig   1036:                $$ = bitfield($1, to_int_constant($3, true));
1.1       cgd      1037:          }
                   1038:        | {
                   1039:                symtyp = FVFT;
1.168     rillig   1040:          } T_COLON constant_expr {
1.175     rillig   1041:                $$ = bitfield(NULL, to_int_constant($3, true));
1.1       cgd      1042:          }
                   1043:        ;
                   1044:
1.319     rillig   1045: enum_specifier:                        /* C99 6.7.2.2 */
1.301     rillig   1046:          enum identifier_sym {
1.183     rillig   1047:                $$ = mktag($2, ENUM, false, false);
1.1       cgd      1048:          }
1.306     rillig   1049:        | enum identifier_sym {
1.183     rillig   1050:                dcs->d_tagtyp = mktag($2, ENUM, true, false);
1.306     rillig   1051:          } enum_declaration {
                   1052:                $$ = complete_tag_enum(dcs->d_tagtyp, $4);
                   1053:          }
                   1054:        | enum {
                   1055:                dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
                   1056:          } enum_declaration {
                   1057:                $$ = complete_tag_enum(dcs->d_tagtyp, $3);
1.1       cgd      1058:          }
                   1059:        | enum error {
                   1060:                symtyp = FVFT;
                   1061:                $$ = gettyp(INT);
                   1062:          }
                   1063:        ;
                   1064:
1.319     rillig   1065: enum:                          /* helper for C99 6.7.2.2 */
1.1       cgd      1066:          T_ENUM {
                   1067:                symtyp = FTAG;
1.202     rillig   1068:                begin_declaration_level(CTCONST);
1.1       cgd      1069:          }
                   1070:        ;
                   1071:
1.319     rillig   1072: enum_declaration:              /* helper for C99 6.7.2.2 */
1.306     rillig   1073:          enum_decl_lbrace enums_with_opt_comma T_RBRACE {
                   1074:                $$ = $2;
1.259     rillig   1075:          }
1.306     rillig   1076:        ;
                   1077:
1.319     rillig   1078: enum_decl_lbrace:              /* helper for C99 6.7.2.2 */
1.306     rillig   1079:          T_LBRACE {
                   1080:                symtyp = FVFT;
                   1081:                enumval = 0;
1.259     rillig   1082:          }
                   1083:        ;
                   1084:
1.319     rillig   1085: enums_with_opt_comma:          /* helper for C99 6.7.2.2 */
1.306     rillig   1086:          enumerator_list
                   1087:        | enumerator_list T_COMMA {
1.1       cgd      1088:                if (sflag) {
1.123     rillig   1089:                        /* trailing ',' prohibited in enum declaration */
1.1       cgd      1090:                        error(54);
                   1091:                } else {
1.319     rillig   1092:                        /* trailing ',' prohibited in enum declaration */
                   1093:                        c99ism(54);
                   1094:                }
                   1095:                $$ = $1;
                   1096:          }
                   1097:        ;
                   1098:
                   1099: enumerator_list:               /* C99 6.7.2.2 */
                   1100:          enumerator
                   1101:        | enumerator_list T_COMMA enumerator {
                   1102:                $$ = lnklst($1, $3);
                   1103:          }
                   1104:        | error {
                   1105:                $$ = NULL;
                   1106:          }
                   1107:        ;
                   1108:
                   1109: enumerator:                    /* C99 6.7.2.2 */
                   1110:          identifier_sym {
                   1111:                $$ = enumeration_constant($1, enumval, true);
                   1112:          }
                   1113:        | identifier_sym T_ASSIGN constant_expr {
                   1114:                $$ = enumeration_constant($1, to_int_constant($3, true), false);
                   1115:          }
                   1116:        ;
                   1117:
                   1118: type_qualifier:                        /* C99 6.7.3 */
                   1119:          T_QUAL {
                   1120:                $$ = xcalloc(1, sizeof(*$$));
                   1121:                if ($1 == CONST) {
                   1122:                        $$->p_const = true;
                   1123:                } else if ($1 == VOLATILE) {
                   1124:                        $$->p_volatile = true;
                   1125:                } else {
                   1126:                        lint_assert($1 == RESTRICT || $1 == THREAD);
                   1127:                }
                   1128:          }
                   1129:        ;
                   1130:
                   1131: pointer:                       /* C99 6.7.5 */
                   1132:          asterisk type_qualifier_list_opt {
                   1133:                $$ = merge_qualified_pointer($1, $2);
                   1134:          }
                   1135:        | asterisk type_qualifier_list_opt pointer {
                   1136:                $$ = merge_qualified_pointer($1, $2);
                   1137:                $$ = merge_qualified_pointer($$, $3);
1.306     rillig   1138:          }
                   1139:        ;
                   1140:
1.319     rillig   1141: asterisk:                      /* helper for 'pointer' */
                   1142:          T_ASTERISK {
                   1143:                $$ = xcalloc(1, sizeof(*$$));
                   1144:                $$->p_pointer = true;
1.306     rillig   1145:          }
1.319     rillig   1146:        ;
                   1147:
                   1148: type_qualifier_list_opt:       /* see C99 6.7.5 */
                   1149:          /* empty */ {
1.306     rillig   1150:                $$ = NULL;
1.1       cgd      1151:          }
1.319     rillig   1152:        | type_qualifier_list
1.1       cgd      1153:        ;
                   1154:
1.319     rillig   1155: type_qualifier_list:           /* C99 6.7.5 */
                   1156:          type_qualifier
                   1157:        | type_qualifier_list type_qualifier {
                   1158:                $$ = merge_qualified_pointer($1, $2);
1.1       cgd      1159:          }
                   1160:        ;
                   1161:
1.256     rillig   1162: /*
                   1163:  * For an explanation of 'notype' in the following rules, see the Bison
                   1164:  * manual, section 7.1 "Semantic Info in Token Kinds".
                   1165:  */
                   1166:
1.324     rillig   1167: notype_init_declarators:
                   1168:          notype_init_declarator
                   1169:        | notype_init_declarators T_COMMA type_init_declarator
1.1       cgd      1170:        ;
                   1171:
1.324     rillig   1172: type_init_declarators:
                   1173:          type_init_declarator
                   1174:        | type_init_declarators T_COMMA type_init_declarator
1.1       cgd      1175:        ;
                   1176:
1.324     rillig   1177: notype_init_declarator:
                   1178:          notype_declarator asm_or_symbolrename_opt {
1.174     rillig   1179:                cgram_declare($1, false, $2);
1.111     rillig   1180:                check_size($1);
1.1       cgd      1181:          }
1.324     rillig   1182:        | notype_declarator asm_or_symbolrename_opt {
1.198     rillig   1183:                begin_initialization($1);
1.174     rillig   1184:                cgram_declare($1, true, $2);
1.198     rillig   1185:          } T_ASSIGN initializer {
1.111     rillig   1186:                check_size($1);
1.198     rillig   1187:                end_initialization();
1.1       cgd      1188:          }
                   1189:        ;
                   1190:
1.324     rillig   1191: type_init_declarator:
                   1192:          type_declarator asm_or_symbolrename_opt {
1.174     rillig   1193:                cgram_declare($1, false, $2);
1.111     rillig   1194:                check_size($1);
1.1       cgd      1195:          }
1.324     rillig   1196:        | type_declarator asm_or_symbolrename_opt {
1.198     rillig   1197:                begin_initialization($1);
1.174     rillig   1198:                cgram_declare($1, true, $2);
1.198     rillig   1199:          } T_ASSIGN initializer {
1.111     rillig   1200:                check_size($1);
1.198     rillig   1201:                end_initialization();
1.1       cgd      1202:          }
                   1203:        ;
                   1204:
1.324     rillig   1205: notype_declarator:
                   1206:          notype_direct_declarator
                   1207:        | pointer notype_direct_declarator {
1.306     rillig   1208:                $$ = add_pointer($2, $1);
1.1       cgd      1209:          }
                   1210:        ;
                   1211:
1.324     rillig   1212: type_declarator:
                   1213:          type_direct_declarator
                   1214:        | pointer type_direct_declarator {
1.306     rillig   1215:                $$ = add_pointer($2, $1);
1.239     rillig   1216:          }
                   1217:        ;
                   1218:
1.324     rillig   1219: notype_direct_declarator:
1.1       cgd      1220:          T_NAME {
1.111     rillig   1221:                $$ = declarator_name(getsym($1));
1.1       cgd      1222:          }
1.324     rillig   1223:        | T_LPAREN type_declarator T_RPAREN {
1.1       cgd      1224:                $$ = $2;
                   1225:          }
1.324     rillig   1226:        | type_attribute notype_direct_declarator {
1.306     rillig   1227:                $$ = $2;
                   1228:          }
1.324     rillig   1229:        | notype_direct_declarator T_LBRACK T_RBRACK {
1.183     rillig   1230:                $$ = add_array($1, false, 0);
1.1       cgd      1231:          }
1.324     rillig   1232:        | notype_direct_declarator T_LBRACK array_size T_RBRACK {
1.183     rillig   1233:                $$ = add_array($1, true, to_int_constant($3, false));
1.1       cgd      1234:          }
1.324     rillig   1235:        | notype_direct_declarator param_list asm_or_symbolrename_opt {
1.111     rillig   1236:                $$ = add_function(symbolrename($1, $3), $2);
1.202     rillig   1237:                end_declaration_level();
1.171     rillig   1238:                block_level--;
1.1       cgd      1239:          }
1.324     rillig   1240:        | notype_direct_declarator type_attribute
1.1       cgd      1241:        ;
                   1242:
1.324     rillig   1243: type_direct_declarator:
1.1       cgd      1244:          identifier {
1.111     rillig   1245:                $$ = declarator_name(getsym($1));
1.1       cgd      1246:          }
1.324     rillig   1247:        | T_LPAREN type_declarator T_RPAREN {
1.1       cgd      1248:                $$ = $2;
                   1249:          }
1.324     rillig   1250:        | type_attribute type_direct_declarator {
1.306     rillig   1251:                $$ = $2;
                   1252:          }
1.324     rillig   1253:        | type_direct_declarator T_LBRACK T_RBRACK {
1.183     rillig   1254:                $$ = add_array($1, false, 0);
1.1       cgd      1255:          }
1.324     rillig   1256:        | type_direct_declarator T_LBRACK array_size T_RBRACK {
1.183     rillig   1257:                $$ = add_array($1, true, to_int_constant($3, false));
1.1       cgd      1258:          }
1.324     rillig   1259:        | type_direct_declarator param_list asm_or_symbolrename_opt {
1.111     rillig   1260:                $$ = add_function(symbolrename($1, $3), $2);
1.202     rillig   1261:                end_declaration_level();
1.171     rillig   1262:                block_level--;
1.1       cgd      1263:          }
1.324     rillig   1264:        | type_direct_declarator type_attribute
1.1       cgd      1265:        ;
                   1266:
                   1267: /*
1.324     rillig   1268:  * The two distinct rules type_param_declarator and notype_param_declarator avoid a
1.257     rillig   1269:  * conflict in argument lists. A typename enclosed in parentheses is always
                   1270:  * treated as a typename, not an argument name. For example, after
                   1271:  * "typedef double a;", the declaration "f(int (a));" is interpreted as
                   1272:  * "f(int (double));", not "f(int a);".
1.1       cgd      1273:  */
1.324     rillig   1274: type_param_declarator:
                   1275:          direct_param_declarator
                   1276:        | pointer direct_param_declarator {
1.111     rillig   1277:                $$ = add_pointer($2, $1);
1.1       cgd      1278:          }
                   1279:        ;
                   1280:
1.324     rillig   1281: notype_param_declarator:
                   1282:          direct_notype_param_declarator
                   1283:        | pointer direct_notype_param_declarator {
1.319     rillig   1284:                $$ = add_pointer($2, $1);
1.257     rillig   1285:          }
                   1286:        ;
                   1287:
1.324     rillig   1288: direct_param_declarator:
1.306     rillig   1289:          identifier type_attribute_list {
                   1290:                $$ = declarator_name(getsym($1));
                   1291:          }
                   1292:        | identifier {
1.111     rillig   1293:                $$ = declarator_name(getsym($1));
1.1       cgd      1294:          }
1.324     rillig   1295:        | T_LPAREN notype_param_declarator T_RPAREN {
1.1       cgd      1296:                $$ = $2;
                   1297:          }
1.324     rillig   1298:        | direct_param_declarator T_LBRACK T_RBRACK {
1.183     rillig   1299:                $$ = add_array($1, false, 0);
1.1       cgd      1300:          }
1.324     rillig   1301:        | direct_param_declarator T_LBRACK array_size T_RBRACK {
1.183     rillig   1302:                $$ = add_array($1, true, to_int_constant($3, false));
1.1       cgd      1303:          }
1.324     rillig   1304:        | direct_param_declarator param_list asm_or_symbolrename_opt {
1.111     rillig   1305:                $$ = add_function(symbolrename($1, $3), $2);
1.202     rillig   1306:                end_declaration_level();
1.171     rillig   1307:                block_level--;
1.1       cgd      1308:          }
                   1309:        ;
                   1310:
1.324     rillig   1311: direct_notype_param_declarator:
1.306     rillig   1312:          identifier {
1.111     rillig   1313:                $$ = declarator_name(getsym($1));
1.1       cgd      1314:          }
1.324     rillig   1315:        | T_LPAREN notype_param_declarator T_RPAREN {
1.1       cgd      1316:                $$ = $2;
                   1317:          }
1.324     rillig   1318:        | direct_notype_param_declarator T_LBRACK T_RBRACK {
1.183     rillig   1319:                $$ = add_array($1, false, 0);
1.1       cgd      1320:          }
1.324     rillig   1321:        | direct_notype_param_declarator T_LBRACK array_size T_RBRACK {
1.183     rillig   1322:                $$ = add_array($1, true, to_int_constant($3, false));
1.1       cgd      1323:          }
1.324     rillig   1324:        | direct_notype_param_declarator param_list asm_or_symbolrename_opt {
1.111     rillig   1325:                $$ = add_function(symbolrename($1, $3), $2);
1.202     rillig   1326:                end_declaration_level();
1.171     rillig   1327:                block_level--;
1.1       cgd      1328:          }
                   1329:        ;
                   1330:
1.319     rillig   1331: param_list:
                   1332:          id_list_lparen identifier_list T_RPAREN {
                   1333:                $$ = $2;
1.1       cgd      1334:          }
1.319     rillig   1335:        | abstract_decl_param_list
                   1336:        ;
                   1337:
                   1338: id_list_lparen:
                   1339:          T_LPAREN {
                   1340:                block_level++;
                   1341:                begin_declaration_level(PROTO_ARG);
1.1       cgd      1342:          }
                   1343:        ;
                   1344:
1.319     rillig   1345: array_size:
                   1346:          type_qualifier_list_opt T_SCLASS constant_expr {
                   1347:                /* C11 6.7.6.3p7 */
                   1348:                if ($2 != STATIC)
                   1349:                        yyerror("Bad attribute");
                   1350:                /* static array size is a C11 extension */
                   1351:                c11ism(343);
                   1352:                $$ = $3;
1.1       cgd      1353:          }
1.319     rillig   1354:        | constant_expr
1.1       cgd      1355:        ;
                   1356:
1.319     rillig   1357: identifier_list:               /* C99 6.7.5 */
                   1358:          T_NAME {
                   1359:                $$ = old_style_function_name(getsym($1));
                   1360:          }
                   1361:        | identifier_list T_COMMA T_NAME {
                   1362:                $$ = lnklst($1, old_style_function_name(getsym($3)));
1.245     rillig   1363:          }
1.319     rillig   1364:        | identifier_list error
1.245     rillig   1365:        ;
                   1366:
1.319     rillig   1367: /* XXX: C99 requires an additional specifier-qualifier-list. */
                   1368: type_name:                     /* C99 6.7.6 */
                   1369:          {
                   1370:                begin_declaration_level(ABSTRACT);
                   1371:          } abstract_declaration {
                   1372:                end_declaration_level();
                   1373:                $$ = $2->s_type;
1.1       cgd      1374:          }
                   1375:        ;
                   1376:
1.319     rillig   1377: abstract_declaration:
                   1378:          begin_type_noclass_declmods end_type {
                   1379:                $$ = declare_1_abstract(abstract_name());
                   1380:          }
                   1381:        | begin_type_noclass_declspecs end_type {
                   1382:                $$ = declare_1_abstract(abstract_name());
                   1383:          }
                   1384:        | begin_type_noclass_declmods end_type abstract_declarator {
                   1385:                $$ = declare_1_abstract($3);
                   1386:          }
                   1387:        | begin_type_noclass_declspecs end_type abstract_declarator {
                   1388:                $$ = declare_1_abstract($3);
1.1       cgd      1389:          }
                   1390:        ;
                   1391:
1.319     rillig   1392: abstract_declarator:           /* C99 6.7.6 */
                   1393:          pointer {
                   1394:                $$ = add_pointer(abstract_name(), $1);
                   1395:          }
                   1396:        | direct_abstract_declarator
                   1397:        | pointer direct_abstract_declarator {
                   1398:                $$ = add_pointer($2, $1);
                   1399:          }
                   1400:        | T_TYPEOF cast_expression {    /* GCC extension */
                   1401:                $$ = mktempsym($2->tn_type);
                   1402:          }
1.260     rillig   1403:        ;
                   1404:
1.319     rillig   1405: direct_abstract_declarator:    /* C99 6.7.6 */
                   1406:          T_LPAREN abstract_declarator T_RPAREN {
                   1407:                $$ = $2;
                   1408:          }
                   1409:        | T_LBRACK T_RBRACK {
                   1410:                $$ = add_array(abstract_name(), false, 0);
                   1411:          }
                   1412:        | T_LBRACK array_size T_RBRACK {
                   1413:                $$ = add_array(abstract_name(), true, to_int_constant($2, false));
                   1414:          }
                   1415:        | type_attribute direct_abstract_declarator {
1.1       cgd      1416:                $$ = $2;
                   1417:          }
1.319     rillig   1418:        | direct_abstract_declarator T_LBRACK T_RBRACK {
                   1419:                $$ = add_array($1, false, 0);
                   1420:          }
                   1421:        | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */
                   1422:                $$ = add_array($1, false, 0);
                   1423:          }
                   1424:        | direct_abstract_declarator T_LBRACK array_size T_RBRACK {
                   1425:                $$ = add_array($1, true, to_int_constant($3, false));
1.1       cgd      1426:          }
1.319     rillig   1427:        | abstract_decl_param_list asm_or_symbolrename_opt {
                   1428:                $$ = add_function(symbolrename(abstract_name(), $2), $1);
                   1429:                end_declaration_level();
                   1430:                block_level--;
1.1       cgd      1431:          }
1.319     rillig   1432:        | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt {
                   1433:                $$ = add_function(symbolrename($1, $3), $2);
                   1434:                end_declaration_level();
                   1435:                block_level--;
1.1       cgd      1436:          }
1.319     rillig   1437:        | direct_abstract_declarator type_attribute_list
1.1       cgd      1438:        ;
                   1439:
1.155     rillig   1440: abstract_decl_param_list:
1.241     rillig   1441:          abstract_decl_lparen T_RPAREN type_attribute_opt {
1.1       cgd      1442:                $$ = NULL;
                   1443:          }
1.241     rillig   1444:        | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt {
1.140     rillig   1445:                dcs->d_proto = true;
1.1       cgd      1446:                $$ = $2;
                   1447:          }
1.241     rillig   1448:        | abstract_decl_lparen error T_RPAREN type_attribute_opt {
1.1       cgd      1449:                $$ = NULL;
                   1450:          }
                   1451:        ;
                   1452:
1.170     rillig   1453: abstract_decl_lparen:
1.126     rillig   1454:          T_LPAREN {
1.171     rillig   1455:                block_level++;
1.202     rillig   1456:                begin_declaration_level(PROTO_ARG);
1.1       cgd      1457:          }
                   1458:        ;
                   1459:
                   1460: vararg_parameter_type_list:
1.240     rillig   1461:          parameter_type_list
1.147     rillig   1462:        | parameter_type_list T_COMMA T_ELLIPSIS {
1.140     rillig   1463:                dcs->d_vararg = true;
1.1       cgd      1464:                $$ = $1;
                   1465:          }
1.147     rillig   1466:        | T_ELLIPSIS {
1.1       cgd      1467:                if (sflag) {
1.123     rillig   1468:                        /* ANSI C requires formal parameter before '...' */
1.1       cgd      1469:                        error(84);
                   1470:                } else if (!tflag) {
1.123     rillig   1471:                        /* ANSI C requires formal parameter before '...' */
1.1       cgd      1472:                        warning(84);
                   1473:                }
1.140     rillig   1474:                dcs->d_vararg = true;
1.1       cgd      1475:                $$ = NULL;
                   1476:          }
                   1477:        ;
                   1478:
1.319     rillig   1479: /* XXX: C99 6.7.5 defines the same name, but it looks different. */
1.1       cgd      1480: parameter_type_list:
1.240     rillig   1481:          parameter_declaration
1.11      cgd      1482:        | parameter_type_list T_COMMA parameter_declaration {
1.1       cgd      1483:                $$ = lnklst($1, $3);
                   1484:          }
                   1485:        ;
                   1486:
1.258     rillig   1487: /* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
1.1       cgd      1488: parameter_declaration:
1.306     rillig   1489:          begin_type_declmods end_type {
1.183     rillig   1490:                $$ = declare_argument(abstract_name(), false);
1.1       cgd      1491:          }
1.306     rillig   1492:        | begin_type_declaration_specifiers end_type {
1.183     rillig   1493:                $$ = declare_argument(abstract_name(), false);
1.1       cgd      1494:          }
1.324     rillig   1495:        | begin_type_declmods end_type notype_param_declarator {
1.306     rillig   1496:                $$ = declare_argument($3, false);
1.1       cgd      1497:          }
1.306     rillig   1498:        /*
1.324     rillig   1499:         * type_param_declarator is needed because of following conflict:
1.306     rillig   1500:         * "typedef int a; f(int (a));" could be parsed as
                   1501:         * "function with argument a of type int", or
                   1502:         * "function with an abstract argument of type function".
                   1503:         * This grammar realizes the second case.
                   1504:         */
1.324     rillig   1505:        | begin_type_declaration_specifiers end_type type_param_declarator {
1.306     rillig   1506:                $$ = declare_argument($3, false);
1.1       cgd      1507:          }
1.306     rillig   1508:        | begin_type_declmods end_type abstract_declarator {
                   1509:                $$ = declare_argument($3, false);
1.1       cgd      1510:          }
1.306     rillig   1511:        | begin_type_declaration_specifiers end_type abstract_declarator {
                   1512:                $$ = declare_argument($3, false);
1.1       cgd      1513:          }
                   1514:        ;
                   1515:
1.179     rillig   1516: initializer:                   /* C99 6.7.8 "Initialization" */
1.325     rillig   1517:          assignment_expression {
1.207     rillig   1518:                init_expr($1);
1.1       cgd      1519:          }
1.178     rillig   1520:        | init_lbrace init_rbrace {
                   1521:                /* XXX: Empty braces are not covered by C99 6.7.8. */
                   1522:          }
1.182     rillig   1523:        | init_lbrace initializer_list comma_opt init_rbrace
1.1       cgd      1524:        | error
                   1525:        ;
                   1526:
1.179     rillig   1527: initializer_list:              /* C99 6.7.8 "Initialization" */
1.192     rillig   1528:          initializer_list_item
1.180     rillig   1529:        | initializer_list T_COMMA initializer_list_item
                   1530:        ;
                   1531:
1.319     rillig   1532: initializer_list_item:         /* helper */
1.180     rillig   1533:          designation initializer
                   1534:        | initializer
1.1       cgd      1535:        ;
                   1536:
1.239     rillig   1537: designation:                   /* C99 6.7.8 "Initialization" */
                   1538:          designator_list T_ASSIGN
                   1539:        | identifier T_COLON {
                   1540:                /* GCC style struct or union member name in initializer */
                   1541:                gnuism(315);
                   1542:                add_designator_member($1);
1.35      christos 1543:          }
1.239     rillig   1544:        ;
                   1545:
                   1546: designator_list:               /* C99 6.7.8 "Initialization" */
                   1547:          designator
                   1548:        | designator_list designator
1.35      christos 1549:        ;
                   1550:
1.167     rillig   1551: designator:                    /* C99 6.7.8 "Initialization" */
1.71      christos 1552:          T_LBRACK range T_RBRACK {
1.205     rillig   1553:                add_designator_subscript($2);
1.34      yamt     1554:                if (!Sflag)
1.127     rillig   1555:                        /* array initializer with des.s is a C9X feature */
1.34      yamt     1556:                        warning(321);
                   1557:          }
1.230     rillig   1558:        | T_POINT identifier {
1.26      christos 1559:                if (!Sflag)
1.127     rillig   1560:                        /* struct or union member name in initializer is ... */
1.26      christos 1561:                        warning(313);
1.205     rillig   1562:                add_designator_member($2);
1.26      christos 1563:          }
1.71      christos 1564:        ;
                   1565:
1.239     rillig   1566: range:
                   1567:          constant_expr {
                   1568:                $$.lo = to_int_constant($1, true);
                   1569:                $$.hi = $$.lo;
                   1570:          }
                   1571:        | constant_expr T_ELLIPSIS constant_expr {
                   1572:                $$.lo = to_int_constant($1, true);
                   1573:                $$.hi = to_int_constant($3, true);
1.251     rillig   1574:                /* initialization with '[a...b]' is a GCC extension */
1.239     rillig   1575:                gnuism(340);
1.26      christos 1576:          }
                   1577:        ;
                   1578:
1.319     rillig   1579: init_lbrace:                   /* helper */
1.1       cgd      1580:          T_LBRACE {
1.114     rillig   1581:                init_lbrace();
1.1       cgd      1582:          }
                   1583:        ;
                   1584:
1.319     rillig   1585: init_rbrace:                   /* helper */
1.1       cgd      1586:          T_RBRACE {
1.114     rillig   1587:                init_rbrace();
1.1       cgd      1588:          }
                   1589:        ;
                   1590:
1.319     rillig   1591: asm_or_symbolrename_opt:       /* GCC extensions */
                   1592:          /* empty */ {
                   1593:                $$ = NULL;
1.1       cgd      1594:          }
1.319     rillig   1595:        | T_ASM T_LPAREN T_STRING T_RPAREN {
                   1596:                freeyyv(&$3, T_STRING);
                   1597:                $$ = NULL;
1.1       cgd      1598:          }
1.319     rillig   1599:        | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN {
                   1600:                $$ = $3;
1.1       cgd      1601:          }
                   1602:        ;
                   1603:
1.319     rillig   1604: statement:                     /* C99 6.8 */
                   1605:          expression_statement
                   1606:        | non_expr_statement
1.256     rillig   1607:        ;
                   1608:
1.319     rillig   1609: non_expr_statement:            /* helper for C99 6.8 */
1.306     rillig   1610:          type_attribute T_SEMI
1.212     christos 1611:        | labeled_statement
1.133     rillig   1612:        | compound_statement
                   1613:        | selection_statement
                   1614:        | iteration_statement
                   1615:        | jump_statement {
1.188     rillig   1616:                seen_fallthrough = false;
1.1       cgd      1617:          }
1.133     rillig   1618:        | asm_statement
1.212     christos 1619:        ;
1.32      christos 1620:
1.134     rillig   1621: labeled_statement:             /* C99 6.8.1 */
1.306     rillig   1622:          label type_attribute_opt statement
1.1       cgd      1623:        ;
                   1624:
                   1625: label:
1.53      christos 1626:          T_NAME T_COLON {
1.120     rillig   1627:                symtyp = FLABEL;
1.125     rillig   1628:                named_label(getsym($1));
1.1       cgd      1629:          }
1.168     rillig   1630:        | T_CASE constant_expr T_COLON {
1.125     rillig   1631:                case_label($2);
1.188     rillig   1632:                seen_fallthrough = true;
1.130     rillig   1633:          }
1.168     rillig   1634:        | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON {
1.40      christos 1635:                /* XXX: We don't fill all cases */
1.125     rillig   1636:                case_label($2);
1.188     rillig   1637:                seen_fallthrough = true;
1.130     rillig   1638:          }
1.1       cgd      1639:        | T_DEFAULT T_COLON {
1.125     rillig   1640:                default_label();
1.188     rillig   1641:                seen_fallthrough = true;
1.1       cgd      1642:          }
                   1643:        ;
                   1644:
1.134     rillig   1645: compound_statement:            /* C99 6.8.2 */
1.306     rillig   1646:          compound_statement_lbrace compound_statement_rbrace
                   1647:        | compound_statement_lbrace block_item_list compound_statement_rbrace
1.1       cgd      1648:        ;
                   1649:
1.133     rillig   1650: compound_statement_lbrace:
1.1       cgd      1651:          T_LBRACE {
1.171     rillig   1652:                block_level++;
                   1653:                mem_block_level++;
1.202     rillig   1654:                begin_declaration_level(AUTO);
1.1       cgd      1655:          }
                   1656:        ;
                   1657:
1.133     rillig   1658: compound_statement_rbrace:
1.1       cgd      1659:          T_RBRACE {
1.202     rillig   1660:                end_declaration_level();
1.1       cgd      1661:                freeblk();
1.171     rillig   1662:                mem_block_level--;
                   1663:                block_level--;
1.188     rillig   1664:                seen_fallthrough = false;
1.1       cgd      1665:          }
                   1666:        ;
                   1667:
1.300     rillig   1668: block_item_list:               /* C99 6.8.2 */
1.185     rillig   1669:          block_item
                   1670:        | block_item_list block_item {
                   1671:                if (!Sflag && $1 && !$2)
                   1672:                        /* declarations after statements is a C99 feature */
                   1673:                        c99ism(327);
1.234     rillig   1674:                $$ = $1 || $2;
1.254     rillig   1675:          }
1.185     rillig   1676:        ;
                   1677:
1.300     rillig   1678: block_item:                    /* C99 6.8.2 */
1.326     rillig   1679:          declaration_or_error {
1.300     rillig   1680:                $$ = false;
1.187     rillig   1681:                restore_warning_flags();
1.185     rillig   1682:          }
1.300     rillig   1683:        | statement {
                   1684:                $$ = true;
1.187     rillig   1685:                restore_warning_flags();
1.7       jpo      1686:          }
1.1       cgd      1687:        ;
                   1688:
1.270     rillig   1689: expression_statement:          /* C99 6.8.3 */
1.322     rillig   1690:          expression T_SEMI {
1.160     rillig   1691:                expr($1, false, false, false, false);
1.188     rillig   1692:                seen_fallthrough = false;
1.1       cgd      1693:          }
                   1694:        | T_SEMI {
1.188     rillig   1695:                seen_fallthrough = false;
1.1       cgd      1696:          }
                   1697:        ;
                   1698:
1.134     rillig   1699: selection_statement:           /* C99 6.8.4 */
1.312     rillig   1700:          if_without_else %prec T_THEN {
1.187     rillig   1701:                save_warning_flags();
1.1       cgd      1702:                if2();
1.183     rillig   1703:                if3(false);
1.1       cgd      1704:          }
                   1705:        | if_without_else T_ELSE {
1.187     rillig   1706:                save_warning_flags();
1.1       cgd      1707:                if2();
1.133     rillig   1708:          } statement {
1.187     rillig   1709:                clear_warning_flags();
1.183     rillig   1710:                if3(true);
1.1       cgd      1711:          }
                   1712:        | if_without_else T_ELSE error {
1.187     rillig   1713:                clear_warning_flags();
1.183     rillig   1714:                if3(false);
1.1       cgd      1715:          }
1.133     rillig   1716:        | switch_expr statement {
1.187     rillig   1717:                clear_warning_flags();
1.1       cgd      1718:                switch2();
                   1719:          }
                   1720:        | switch_expr error {
1.187     rillig   1721:                clear_warning_flags();
1.1       cgd      1722:                switch2();
                   1723:          }
                   1724:        ;
                   1725:
1.270     rillig   1726: if_without_else:               /* see C99 6.8.4 */
1.133     rillig   1727:          if_expr statement
1.1       cgd      1728:        | if_expr error
                   1729:        ;
                   1730:
1.270     rillig   1731: if_expr:                       /* see C99 6.8.4 */
1.322     rillig   1732:          T_IF T_LPAREN expression T_RPAREN {
1.1       cgd      1733:                if1($3);
1.187     rillig   1734:                clear_warning_flags();
1.1       cgd      1735:          }
                   1736:        ;
                   1737:
1.270     rillig   1738: switch_expr:                   /* see C99 6.8.4 */
1.322     rillig   1739:          T_SWITCH T_LPAREN expression T_RPAREN {
1.1       cgd      1740:                switch1($3);
1.187     rillig   1741:                clear_warning_flags();
1.1       cgd      1742:          }
                   1743:        ;
                   1744:
1.134     rillig   1745: iteration_statement:           /* C99 6.8.5 */
1.306     rillig   1746:          while_expr statement {
1.187     rillig   1747:                clear_warning_flags();
1.306     rillig   1748:                while2();
                   1749:          }
                   1750:        | while_expr error {
1.187     rillig   1751:                clear_warning_flags();
1.1       cgd      1752:                while2();
                   1753:          }
1.306     rillig   1754:        | do_statement do_while_expr {
                   1755:                do2($2);
1.188     rillig   1756:                seen_fallthrough = false;
1.1       cgd      1757:          }
                   1758:        | do error {
1.187     rillig   1759:                clear_warning_flags();
1.1       cgd      1760:                do2(NULL);
                   1761:          }
1.306     rillig   1762:        | for_exprs statement {
                   1763:                clear_warning_flags();
                   1764:                for2();
                   1765:                end_declaration_level();
                   1766:                block_level--;
                   1767:          }
                   1768:        | for_exprs error {
1.187     rillig   1769:                clear_warning_flags();
1.1       cgd      1770:                for2();
1.202     rillig   1771:                end_declaration_level();
1.171     rillig   1772:                block_level--;
1.1       cgd      1773:          }
                   1774:        ;
                   1775:
1.319     rillig   1776: while_expr:                    /* see C99 6.8.5 */
1.322     rillig   1777:          T_WHILE T_LPAREN expression T_RPAREN {
1.306     rillig   1778:                while1($3);
                   1779:                clear_warning_flags();
                   1780:          }
1.1       cgd      1781:        ;
                   1782:
1.319     rillig   1783: do_statement:                  /* see C99 6.8.5 */
                   1784:          do statement {
                   1785:                clear_warning_flags();
                   1786:          }
                   1787:        ;
                   1788:
1.270     rillig   1789: do:                            /* see C99 6.8.5 */
1.1       cgd      1790:          T_DO {
                   1791:                do1();
                   1792:          }
                   1793:        ;
                   1794:
1.319     rillig   1795: do_while_expr:                 /* see C99 6.8.5 */
1.322     rillig   1796:          T_WHILE T_LPAREN expression T_RPAREN T_SEMI {
1.306     rillig   1797:                $$ = $3;
                   1798:          }
                   1799:        ;
                   1800:
1.270     rillig   1801: for_start:                     /* see C99 6.8.5 */
1.126     rillig   1802:          T_FOR T_LPAREN {
1.202     rillig   1803:                begin_declaration_level(AUTO);
1.171     rillig   1804:                block_level++;
1.66      christos 1805:          }
                   1806:        ;
1.254     rillig   1807:
1.270     rillig   1808: for_exprs:                     /* see C99 6.8.5 */
1.322     rillig   1809:          for_start
                   1810:            begin_type_declaration_specifiers end_type
1.324     rillig   1811:            notype_init_declarators T_SEMI
1.322     rillig   1812:            expression_opt T_SEMI expression_opt T_RPAREN {
1.127     rillig   1813:                /* variable declaration in for loop */
1.43      christos 1814:                c99ism(325);
1.306     rillig   1815:                for1(NULL, $6, $8);
1.187     rillig   1816:                clear_warning_flags();
1.43      christos 1817:            }
1.322     rillig   1818:          | for_start
                   1819:              expression_opt T_SEMI
                   1820:              expression_opt T_SEMI
                   1821:              expression_opt T_RPAREN {
1.66      christos 1822:                for1($2, $4, $6);
1.187     rillig   1823:                clear_warning_flags();
1.1       cgd      1824:          }
                   1825:        ;
                   1826:
1.319     rillig   1827: jump_statement:                        /* C99 6.8.6 */
                   1828:          goto identifier T_SEMI {
                   1829:                do_goto(getsym($2));
1.1       cgd      1830:          }
1.319     rillig   1831:        | goto error T_SEMI {
                   1832:                symtyp = FVFT;
1.1       cgd      1833:          }
1.319     rillig   1834:        | T_CONTINUE T_SEMI {
                   1835:                do_continue();
1.1       cgd      1836:          }
1.319     rillig   1837:        | T_BREAK T_SEMI {
                   1838:                do_break();
1.1       cgd      1839:          }
1.319     rillig   1840:        | T_RETURN T_SEMI {
                   1841:                do_return(NULL);
1.310     rillig   1842:          }
1.322     rillig   1843:        | T_RETURN expression T_SEMI {
1.319     rillig   1844:                do_return($2);
1.308     rillig   1845:          }
1.319     rillig   1846:        ;
                   1847:
                   1848: goto:                          /* see C99 6.8.6 */
                   1849:          T_GOTO {
                   1850:                symtyp = FLABEL;
1.315     rillig   1851:          }
1.319     rillig   1852:        ;
                   1853:
                   1854: asm_statement:                 /* GCC extension */
                   1855:          T_ASM T_LPAREN read_until_rparen T_SEMI {
                   1856:                setasm();
1.315     rillig   1857:          }
1.319     rillig   1858:        | T_ASM T_QUAL T_LPAREN read_until_rparen T_SEMI {
                   1859:                setasm();
1.315     rillig   1860:          }
1.319     rillig   1861:        | T_ASM error
                   1862:        ;
                   1863:
                   1864: read_until_rparen:             /* helper for 'asm_statement' */
                   1865:          /* empty */ {
                   1866:                ignore_up_to_rparen();
1.315     rillig   1867:          }
1.308     rillig   1868:        ;
                   1869:
1.319     rillig   1870: translation_unit:              /* C99 6.9 */
                   1871:          external_declaration
                   1872:        | translation_unit external_declaration
                   1873:        ;
                   1874:
                   1875: external_declaration:          /* C99 6.9 */
                   1876:          asm_statement
                   1877:        | function_definition {
                   1878:                global_clean_up_decl(false);
                   1879:                clear_warning_flags();
                   1880:          }
                   1881:        | top_level_declaration {
                   1882:                global_clean_up_decl(false);
                   1883:                clear_warning_flags();
1.1       cgd      1884:          }
                   1885:        ;
                   1886:
1.226     rillig   1887: /*
1.319     rillig   1888:  * On the top level, lint allows several forms of declarations that it doesn't
                   1889:  * allow in functions.  For example, a single ';' is an empty declaration and
                   1890:  * is supported by some compilers, but in a function it would be an empty
                   1891:  * statement, not a declaration.  This makes a difference in C90 mode, where
                   1892:  * a statement must not be followed by a declaration.
1.226     rillig   1893:  *
1.319     rillig   1894:  * See 'declaration' for all other declarations.
1.226     rillig   1895:  */
1.319     rillig   1896: top_level_declaration:         /* C99 6.9 calls this 'declaration' */
                   1897:          T_SEMI {
                   1898:                if (sflag) {
                   1899:                        /* empty declaration */
                   1900:                        error(0);
                   1901:                } else if (!tflag) {
                   1902:                        /* empty declaration */
                   1903:                        warning(0);
                   1904:                }
1.226     rillig   1905:          }
1.324     rillig   1906:        | begin_type end_type notype_init_declarators T_SEMI {
1.319     rillig   1907:                if (sflag) {
                   1908:                        /* old style declaration; add 'int' */
                   1909:                        error(1);
                   1910:                } else if (!tflag) {
                   1911:                        /* old style declaration; add 'int' */
                   1912:                        warning(1);
                   1913:                }
1.226     rillig   1914:          }
1.327   ! rillig   1915:        | declaration
1.319     rillig   1916:        | error T_SEMI {
                   1917:                global_clean_up();
                   1918:          }
                   1919:        | error T_RBRACE {
                   1920:                global_clean_up();
                   1921:          }
1.226     rillig   1922:        ;
                   1923:
1.319     rillig   1924: function_definition:           /* C99 6.9.1 */
1.324     rillig   1925:          func_declarator {
1.319     rillig   1926:                if ($1->s_type->t_tspec != FUNC) {
                   1927:                        /* syntax error '%s' */
                   1928:                        error(249, yytext);
                   1929:                        YYERROR;
                   1930:                }
                   1931:                if ($1->s_type->t_typedef) {
                   1932:                        /* ()-less function definition */
                   1933:                        error(64);
                   1934:                        YYERROR;
                   1935:                }
                   1936:                funcdef($1);
                   1937:                block_level++;
                   1938:                begin_declaration_level(ARG);
                   1939:                if (lwarn == LWARN_NONE)
                   1940:                        $1->s_used = true;
                   1941:          } arg_declaration_list_opt {
                   1942:                end_declaration_level();
                   1943:                block_level--;
                   1944:                check_func_lint_directives();
                   1945:                check_func_old_style_arguments();
                   1946:                begin_control_statement(CS_FUNCTION_BODY);
                   1947:          } compound_statement {
                   1948:                funcend();
                   1949:                end_control_statement(CS_FUNCTION_BODY);
1.1       cgd      1950:          }
                   1951:        ;
                   1952:
1.324     rillig   1953: func_declarator:
                   1954:          begin_type end_type notype_declarator {
1.319     rillig   1955:                $$ = $3;
                   1956:          }
1.324     rillig   1957:        | begin_type_declmods end_type notype_declarator {
1.319     rillig   1958:                $$ = $3;
1.1       cgd      1959:          }
1.324     rillig   1960:        | begin_type_declaration_specifiers end_type type_declarator {
1.319     rillig   1961:                $$ = $3;
1.1       cgd      1962:          }
                   1963:        ;
                   1964:
1.319     rillig   1965: arg_declaration_list_opt:      /* C99 6.9.1p13 example 1 */
                   1966:          /* empty */
                   1967:        | arg_declaration_list
1.1       cgd      1968:        ;
                   1969:
1.319     rillig   1970: arg_declaration_list:          /* C99 6.9.1p13 example 1 */
                   1971:          arg_declaration
                   1972:        | arg_declaration_list arg_declaration
                   1973:        /* XXX or better "arg_declaration error" ? */
                   1974:        | error
1.301     rillig   1975:        ;
                   1976:
1.319     rillig   1977: /*
                   1978:  * "arg_declaration" is separated from "declaration" because it
                   1979:  * needs other error handling.
                   1980:  */
                   1981: arg_declaration:
                   1982:          begin_type_declmods end_type T_SEMI {
                   1983:                /* empty declaration */
                   1984:                warning(2);
                   1985:          }
1.324     rillig   1986:        | begin_type_declmods end_type notype_init_declarators T_SEMI
1.319     rillig   1987:        | begin_type_declaration_specifiers end_type T_SEMI {
                   1988:                if (!dcs->d_nonempty_decl) {
                   1989:                        /* empty declaration */
                   1990:                        warning(2);
                   1991:                } else {
                   1992:                        /* '%s' declared in argument declaration list */
                   1993:                        warning(3, type_name(dcs->d_type));
                   1994:                }
1.1       cgd      1995:          }
1.324     rillig   1996:        | begin_type_declaration_specifiers end_type
                   1997:            type_init_declarators T_SEMI {
1.319     rillig   1998:                if (dcs->d_nonempty_decl) {
                   1999:                        /* '%s' declared in argument declaration list */
                   2000:                        warning(3, type_name(dcs->d_type));
                   2001:                }
1.1       cgd      2002:          }
1.319     rillig   2003:        | begin_type_declmods error
                   2004:        | begin_type_declaration_specifiers error
1.180     rillig   2005:        ;
1.254     rillig   2006:
1.261     rillig   2007: gcc_attribute_spec_list:
                   2008:          gcc_attribute_spec
                   2009:        | gcc_attribute_spec_list T_COMMA gcc_attribute_spec
1.260     rillig   2010:        ;
                   2011:
1.261     rillig   2012: gcc_attribute_spec:
1.260     rillig   2013:          /* empty */
                   2014:        | T_AT_ALWAYS_INLINE
                   2015:        | T_AT_ALIAS T_LPAREN string T_RPAREN
                   2016:        | T_AT_ALIGNED T_LPAREN constant_expr T_RPAREN
                   2017:        | T_AT_ALIGNED
                   2018:        | T_AT_ALLOC_SIZE T_LPAREN constant_expr T_COMMA constant_expr T_RPAREN
                   2019:        | T_AT_ALLOC_SIZE T_LPAREN constant_expr T_RPAREN
1.261     rillig   2020:        | T_AT_BOUNDED T_LPAREN gcc_attribute_bounded
1.260     rillig   2021:          T_COMMA constant_expr T_COMMA constant_expr T_RPAREN
                   2022:        | T_AT_COLD
                   2023:        | T_AT_COMMON
                   2024:        | T_AT_CONSTRUCTOR T_LPAREN constant_expr T_RPAREN
                   2025:        | T_AT_CONSTRUCTOR
                   2026:        | T_AT_DEPRECATED T_LPAREN string T_RPAREN
                   2027:        | T_AT_DEPRECATED
                   2028:        | T_AT_DESTRUCTOR T_LPAREN constant_expr T_RPAREN
                   2029:        | T_AT_DESTRUCTOR
                   2030:        | T_AT_FALLTHROUGH {
                   2031:                fallthru(1);
                   2032:          }
1.261     rillig   2033:        | T_AT_FORMAT T_LPAREN gcc_attribute_format T_COMMA
1.260     rillig   2034:            constant_expr T_COMMA constant_expr T_RPAREN
                   2035:        | T_AT_FORMAT_ARG T_LPAREN constant_expr T_RPAREN
                   2036:        | T_AT_GNU_INLINE
1.313     rillig   2037:        | T_AT_HOT
1.260     rillig   2038:        | T_AT_MALLOC
                   2039:        | T_AT_MAY_ALIAS
                   2040:        | T_AT_MODE T_LPAREN T_NAME T_RPAREN
                   2041:        | T_AT_NOINLINE
                   2042:        | T_AT_NONNULL T_LPAREN constant_expr_list_opt T_RPAREN
                   2043:        | T_AT_NONNULL
                   2044:        | T_AT_NONSTRING
                   2045:        | T_AT_NORETURN
                   2046:        | T_AT_NOTHROW
                   2047:        | T_AT_NO_INSTRUMENT_FUNCTION
                   2048:        | T_AT_OPTIMIZE T_LPAREN string T_RPAREN
                   2049:        | T_AT_PACKED {
                   2050:                addpacked();
                   2051:          }
                   2052:        | T_AT_PCS T_LPAREN string T_RPAREN
                   2053:        | T_AT_PURE
                   2054:        | T_AT_RETURNS_TWICE
                   2055:        | T_AT_SECTION T_LPAREN string T_RPAREN
                   2056:        | T_AT_SENTINEL T_LPAREN constant_expr T_RPAREN
                   2057:        | T_AT_SENTINEL
                   2058:        | T_AT_TLS_MODEL T_LPAREN string T_RPAREN
                   2059:        | T_AT_TUNION
                   2060:        | T_AT_UNUSED {
                   2061:                add_attr_used();
                   2062:          }
                   2063:        | T_AT_USED {
                   2064:                add_attr_used();
                   2065:          }
                   2066:        | T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN
                   2067:        | T_AT_WARN_UNUSED_RESULT
                   2068:        | T_AT_WEAK
                   2069:        | T_QUAL {
                   2070:                if ($1 != CONST)
                   2071:                        yyerror("Bad attribute");
                   2072:          }
                   2073:        ;
                   2074:
1.261     rillig   2075: gcc_attribute_bounded:
1.260     rillig   2076:          T_AT_MINBYTES
                   2077:        | T_AT_STRING
                   2078:        | T_AT_BUFFER
                   2079:        ;
                   2080:
1.261     rillig   2081: gcc_attribute_format:
1.260     rillig   2082:          T_AT_FORMAT_GNU_PRINTF
                   2083:        | T_AT_FORMAT_PRINTF
                   2084:        | T_AT_FORMAT_SCANF
                   2085:        | T_AT_FORMAT_STRFMON
                   2086:        | T_AT_FORMAT_STRFTIME
                   2087:        | T_AT_FORMAT_SYSLOG
                   2088:        ;
                   2089:
1.1       cgd      2090: %%
                   2091:
                   2092: /* ARGSUSED */
                   2093: int
1.42      dholland 2094: yyerror(const char *msg)
1.1       cgd      2095: {
1.127     rillig   2096:        /* syntax error '%s' */
1.41      christos 2097:        error(249, yytext);
1.1       cgd      2098:        if (++sytxerr >= 5)
                   2099:                norecover();
1.112     rillig   2100:        return 0;
1.1       cgd      2101: }
                   2102:
                   2103: static void
1.174     rillig   2104: cgram_declare(sym_t *decl, bool initflg, sbuf_t *renaming)
1.1       cgd      2105: {
1.174     rillig   2106:        declare(decl, initflg, renaming);
                   2107:        if (renaming != NULL)
                   2108:                freeyyv(&renaming, T_NAME);
1.6       jpo      2109: }
                   2110:
                   2111: /*
                   2112:  * Discard all input tokens up to and including the next
                   2113:  * unmatched right paren
                   2114:  */
1.22      thorpej  2115: static void
1.148     rillig   2116: ignore_up_to_rparen(void)
1.6       jpo      2117: {
                   2118:        int     level;
                   2119:
                   2120:        if (yychar < 0)
                   2121:                yychar = yylex();
                   2122:        freeyyv(&yylval, yychar);
                   2123:
                   2124:        level = 1;
1.126     rillig   2125:        while (yychar != T_RPAREN || --level > 0) {
                   2126:                if (yychar == T_LPAREN) {
1.6       jpo      2127:                        level++;
                   2128:                } else if (yychar <= 0) {
                   2129:                        break;
                   2130:                }
                   2131:                freeyyv(&yylval, yychar = yylex());
                   2132:        }
                   2133:
                   2134:        yyclearin;
1.1       cgd      2135: }
1.75      christos 2136:
                   2137: static sym_t *
                   2138: symbolrename(sym_t *s, sbuf_t *sb)
                   2139: {
1.219     rillig   2140:        if (sb != NULL)
1.75      christos 2141:                s->s_rename = sb->sb_name;
                   2142:        return s;
                   2143: }

CVSweb <webmaster@jp.NetBSD.org>