Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 support parsing c99's static class for a...



details:   https://anonhg.NetBSD.org/src/rev/d579b825393b
branches:  trunk
changeset: 378478:d579b825393b
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Apr 14 13:34:08 2021 +0000

description:
support parsing c99's static class for array size expressions.

diffstat:

 usr.bin/xlint/lint1/cgram.y |  30 ++++++++++++++++++++++--------
 usr.bin/xlint/lint1/err.c   |   5 +++--
 2 files changed, 25 insertions(+), 10 deletions(-)

diffs (127 lines):

diff -r 84fa4c380b13 -r d579b825393b usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Wed Apr 14 12:20:59 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Wed Apr 14 13:34:08 2021 +0000
@@ -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 {
diff -r 84fa4c380b13 -r d579b825393b usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Wed Apr 14 12:20:59 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Wed Apr 14 13:34:08 2021 +0000
@@ -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 {



Home | Main Index | Thread Index | Old Index