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 lint: allow [*] everywhere where [] and ...
details: https://anonhg.NetBSD.org/src/rev/a3b2dd71aac5
branches: trunk
changeset: 1023555:a3b2dd71aac5
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Sep 14 19:44:40 2021 +0000
description:
lint: allow [*] everywhere where [] and [integer] are allowed
It's a seldom used feature, but now it's at least consistent.
diffstat:
usr.bin/xlint/lint1/cgram.y | 73 +++++++++++++++++++-------------------------
usr.bin/xlint/lint1/lint1.h | 7 +++-
2 files changed, 38 insertions(+), 42 deletions(-)
diffs (170 lines):
diff -r 85da5b28a799 -r a3b2dd71aac5 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Tue Sep 14 19:08:40 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Tue Sep 14 19:44:40 2021 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.363 2021/09/14 19:06:27 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.364 2021/09/14 19:44:40 rillig 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.363 2021/09/14 19:06:27 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.364 2021/09/14 19:44:40 rillig Exp $");
#endif
#include <limits.h>
@@ -143,6 +143,7 @@
qual_ptr *y_qual_ptr;
bool y_seen_statement;
struct generic_association *y_generic;
+ struct array_size y_array_size;
};
%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
@@ -335,6 +336,7 @@
%type <y_sym> direct_param_declarator
%type <y_sym> direct_notype_param_declarator
%type <y_sym> param_list
+%type <y_array_size> array_size_opt
%type <y_tnode> array_size
%type <y_sym> identifier_list
%type <y_type> type_name
@@ -1225,11 +1227,8 @@
| type_attribute notype_direct_declarator {
$$ = $2;
}
- | notype_direct_declarator T_LBRACK T_RBRACK {
- $$ = add_array($1, false, 0);
- }
- | notype_direct_declarator T_LBRACK array_size T_RBRACK {
- $$ = add_array($1, true, to_int_constant($3, false));
+ | notype_direct_declarator T_LBRACK array_size_opt T_RBRACK {
+ $$ = add_array($1, $3.has_dim, $3.dim);
}
| notype_direct_declarator param_list asm_or_symbolrename_opt {
$$ = add_function(symbolrename($1, $3), $2);
@@ -1249,11 +1248,8 @@
| type_attribute type_direct_declarator {
$$ = $2;
}
- | type_direct_declarator T_LBRACK T_RBRACK {
- $$ = add_array($1, false, 0);
- }
- | type_direct_declarator T_LBRACK array_size T_RBRACK {
- $$ = add_array($1, true, to_int_constant($3, false));
+ | type_direct_declarator T_LBRACK array_size_opt T_RBRACK {
+ $$ = add_array($1, $3.has_dim, $3.dim);
}
| type_direct_declarator param_list asm_or_symbolrename_opt {
$$ = add_function(symbolrename($1, $3), $2);
@@ -1294,12 +1290,9 @@
| T_LPAREN notype_param_declarator T_RPAREN {
$$ = $2;
}
- | direct_param_declarator T_LBRACK T_RBRACK gcc_attribute_list_opt {
- $$ = add_array($1, false, 0);
- }
- | direct_param_declarator T_LBRACK array_size T_RBRACK
+ | direct_param_declarator T_LBRACK array_size_opt T_RBRACK
gcc_attribute_list_opt {
- $$ = add_array($1, true, to_int_constant($3, false));
+ $$ = add_array($1, $3.has_dim, $3.dim);
}
| direct_param_declarator param_list asm_or_symbolrename_opt {
$$ = add_function(symbolrename($1, $3), $2);
@@ -1315,11 +1308,8 @@
| T_LPAREN notype_param_declarator T_RPAREN {
$$ = $2;
}
- | direct_notype_param_declarator T_LBRACK T_RBRACK {
- $$ = add_array($1, false, 0);
- }
- | direct_notype_param_declarator T_LBRACK array_size T_RBRACK {
- $$ = add_array($1, true, to_int_constant($3, false));
+ | direct_notype_param_declarator T_LBRACK array_size_opt T_RBRACK {
+ $$ = add_array($1, $3.has_dim, $3.dim);
}
| direct_notype_param_declarator param_list asm_or_symbolrename_opt {
$$ = add_function(symbolrename($1, $3), $2);
@@ -1342,6 +1332,22 @@
}
;
+array_size_opt:
+ /* empty */ {
+ $$.has_dim = false;
+ $$.dim = 0;
+ }
+ | T_ASTERISK {
+ /* since C99; variable length array of unspecified size */
+ $$.has_dim = false; /* TODO: maybe change to true */
+ $$.dim = 0; /* just as a placeholder */
+ }
+ | array_size {
+ $$.has_dim = true;
+ $$.dim = to_int_constant($1, false);
+ }
+ ;
+
array_size:
type_qualifier_list_opt T_SCLASS constant_expr {
/* C11 6.7.6.3p7 */
@@ -1407,29 +1413,14 @@
T_LPAREN abstract_declarator T_RPAREN {
$$ = $2;
}
- | T_LBRACK T_RBRACK {
- $$ = add_array(abstract_name(), false, 0);
- }
- | T_LBRACK T_ASTERISK T_RBRACK {
- /* since C99 */
- $$ = add_array(abstract_name(), false, 0);
- }
- | T_LBRACK array_size T_RBRACK {
- $$ = add_array(abstract_name(), true,
- to_int_constant($2, false));
+ | T_LBRACK array_size_opt T_RBRACK {
+ $$ = add_array(abstract_name(), $2.has_dim, $2.dim);
}
| type_attribute direct_abstract_declarator {
$$ = $2;
}
- | direct_abstract_declarator T_LBRACK T_RBRACK {
- $$ = add_array($1, false, 0);
- }
- | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK {
- /* since C99 */
- $$ = add_array($1, false, 0);
- }
- | direct_abstract_declarator T_LBRACK array_size T_RBRACK {
- $$ = add_array($1, true, to_int_constant($3, false));
+ | direct_abstract_declarator T_LBRACK array_size_opt T_RBRACK {
+ $$ = add_array($1, $3.has_dim, $3.dim);
}
| abstract_decl_param_list asm_or_symbolrename_opt {
$$ = add_function(symbolrename(abstract_name(), $2), $1);
diff -r 85da5b28a799 -r a3b2dd71aac5 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h Tue Sep 14 19:08:40 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h Tue Sep 14 19:44:40 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.128 2021/08/31 17:51:30 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.129 2021/09/14 19:44:40 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -335,6 +335,11 @@
struct generic_association *ga_prev;
};
+struct array_size {
+ bool has_dim;
+ int dim;
+};
+
/*
* For nested declarations a stack exists, which holds all information
* needed for the current level. dcs points to the innermost element of this
Home |
Main Index |
Thread Index |
Old Index