Module Name: src Committed By: christos Date: Wed Apr 14 13:34:08 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: cgram.y err.c Log Message: support parsing c99's static class for array size expressions. To generate a diff of this commit: cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.106 -r1.107 src/usr.bin/xlint/lint1/err.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.213 src/usr.bin/xlint/lint1/cgram.y:1.214 --- src/usr.bin/xlint/lint1/cgram.y:1.213 Tue Apr 13 18:22:02 2021 +++ src/usr.bin/xlint/lint1/cgram.y Wed Apr 14 09:34:08 2021 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.213 2021/04/13 22:22:02 christos Exp $ */ +/* $NetBSD: cgram.y,v 1.214 2021/04/14 13:34:08 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.y,v 1.213 2021/04/13 22:22:02 christos Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.214 2021/04/14 13:34:08 christos Exp $"); #endif #include <limits.h> @@ -296,6 +296,7 @@ anonymize(sym_t *s) %type <y_sym> notype_member_decl %type <y_sym> type_member_decl %type <y_tnode> constant_expr +%type <y_tnode> array_size %type <y_sym> enum_declaration %type <y_sym> enums_with_opt_comma %type <y_sym> enums @@ -1071,7 +1072,7 @@ notype_direct_decl: | notype_direct_decl T_LBRACK T_RBRACK { $$ = add_array($1, false, 0); } - | notype_direct_decl T_LBRACK constant_expr T_RBRACK { + | notype_direct_decl T_LBRACK array_size T_RBRACK { $$ = add_array($1, true, to_int_constant($3, false)); } | notype_direct_decl param_list opt_asm_or_symbolrename { @@ -1104,7 +1105,7 @@ type_direct_decl: | type_direct_decl T_LBRACK T_RBRACK { $$ = add_array($1, false, 0); } - | type_direct_decl T_LBRACK constant_expr T_RBRACK { + | type_direct_decl T_LBRACK array_size T_RBRACK { $$ = add_array($1, true, to_int_constant($3, false)); } | type_direct_decl param_list opt_asm_or_symbolrename { @@ -1131,6 +1132,19 @@ param_decl: } ; +array_size: + T_SCLASS constant_expr { + /* C99 6.7.6.3 */ + if ($1 != STATIC) + yyerror("Bad attribute"); + c99ism(343); + $$ = $2; + } + | constant_expr { + $$ = $1; + } + ; + direct_param_decl: identifier type_attribute_list { $$ = declarator_name(getsym($1)); @@ -1144,7 +1158,7 @@ direct_param_decl: | direct_param_decl T_LBRACK T_RBRACK { $$ = add_array($1, false, 0); } - | direct_param_decl T_LBRACK constant_expr T_RBRACK { + | direct_param_decl T_LBRACK array_size T_RBRACK { $$ = add_array($1, true, to_int_constant($3, false)); } | direct_param_decl param_list opt_asm_or_symbolrename { @@ -1173,7 +1187,7 @@ direct_notype_param_decl: | direct_notype_param_decl T_LBRACK T_RBRACK { $$ = add_array($1, false, 0); } - | direct_notype_param_decl T_LBRACK constant_expr T_RBRACK { + | direct_notype_param_decl T_LBRACK array_size T_RBRACK { $$ = add_array($1, true, to_int_constant($3, false)); } | direct_notype_param_decl param_list opt_asm_or_symbolrename { @@ -1468,7 +1482,7 @@ direct_abstract_decl: | T_LBRACK T_RBRACK { $$ = add_array(abstract_name(), false, 0); } - | T_LBRACK constant_expr T_RBRACK { + | T_LBRACK array_size T_RBRACK { $$ = add_array(abstract_name(), true, to_int_constant($2, false)); } | type_attribute direct_abstract_decl { @@ -1477,7 +1491,7 @@ direct_abstract_decl: | direct_abstract_decl T_LBRACK T_RBRACK { $$ = add_array($1, false, 0); } - | direct_abstract_decl T_LBRACK constant_expr T_RBRACK { + | direct_abstract_decl T_LBRACK array_size T_RBRACK { $$ = add_array($1, true, to_int_constant($3, false)); } | abstract_decl_param_list opt_asm_or_symbolrename { Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.106 src/usr.bin/xlint/lint1/err.c:1.107 --- src/usr.bin/xlint/lint1/err.c:1.106 Fri Apr 9 16:12:00 2021 +++ src/usr.bin/xlint/lint1/err.c Wed Apr 14 09:34:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.106 2021/04/09 20:12:00 rillig Exp $ */ +/* $NetBSD: err.c,v 1.107 2021/04/14 13:34:08 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: err.c,v 1.106 2021/04/09 20:12:00 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.107 2021/04/14 13:34:08 christos Exp $"); #endif #include <sys/types.h> @@ -397,6 +397,7 @@ const char *msgs[] = { "initialization with '[a...b]' is a GNU extension", /* 340 */ "argument to '%s' must be 'unsigned char' or EOF, not '%s'", /* 341 */ "argument to '%s' must be cast to 'unsigned char', not to '%s'", /* 342 */ + "static array size is a C99 extension", /* 343 */ }; static struct include_level {