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: clean up handling of declarations
details: https://anonhg.NetBSD.org/src/rev/545759e74808
branches: trunk
changeset: 377196:545759e74808
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 30 19:10:49 2023 +0000
description:
lint: clean up handling of declarations
No functional change.
diffstat:
tests/usr.bin/xlint/lint1/msg_085.c | 7 +-
usr.bin/xlint/lint1/cgram.y | 19 +-
usr.bin/xlint/lint1/decl.c | 613 ++++++++++++++---------------------
usr.bin/xlint/lint1/externs1.h | 6 +-
usr.bin/xlint/lint1/lint1.h | 10 +-
5 files changed, 265 insertions(+), 390 deletions(-)
diffs (truncated from 1456 to 300 lines):
diff -r feba680573a9 -r 545759e74808 tests/usr.bin/xlint/lint1/msg_085.c
--- a/tests/usr.bin/xlint/lint1/msg_085.c Fri Jun 30 16:39:17 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_085.c Fri Jun 30 19:10:49 2023 +0000
@@ -1,8 +1,13 @@
-/* $NetBSD: msg_085.c,v 1.6 2023/03/28 14:44:34 rillig Exp $ */
+/* $NetBSD: msg_085.c,v 1.7 2023/06/30 19:10:49 rillig Exp $ */
# 3 "msg_085.c"
// Test for message: dubious tag declaration '%s %s' [85]
+/*
+ * Declarations of structs/unions/enums in parameter lists are allowed
+ * but useless.
+ */
+
/* lint1-extra-flags: -X 351 */
/* expect+1: warning: dubious tag declaration 'struct in_argument' [85] */
diff -r feba680573a9 -r 545759e74808 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Fri Jun 30 16:39:17 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Fri Jun 30 19:10:49 2023 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.440 2023/06/30 08:03:01 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.441 2023/06/30 19:10:49 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.440 2023/06/30 08:03:01 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.441 2023/06/30 19:10:49 rillig Exp $");
#endif
#include <limits.h>
@@ -938,7 +938,7 @@ struct_declaration_list_with_rbrace: /*
struct_declaration_list: /* C99 6.7.2.1 */
struct_declaration
| struct_declaration_list struct_declaration {
- $$ = concat_lists($1, $2);
+ $$ = concat_symbols($1, $2);
}
;
@@ -994,7 +994,7 @@ notype_struct_declarators:
| notype_struct_declarators {
symtyp = FMEMBER;
} T_COMMA type_struct_declarator {
- $$ = concat_lists($1, declare_member($4));
+ $$ = concat_symbols($1, declare_member($4));
}
;
@@ -1005,7 +1005,7 @@ type_struct_declarators:
| type_struct_declarators {
symtyp = FMEMBER;
} T_COMMA type_struct_declarator {
- $$ = concat_lists($1, declare_member($4));
+ $$ = concat_symbols($1, declare_member($4));
}
;
@@ -1091,7 +1091,7 @@ enums_with_opt_comma: /* helper for C99
enumerator_list: /* C99 6.7.2.2 */
enumerator
| enumerator_list T_COMMA enumerator {
- $$ = concat_lists($1, $3);
+ $$ = concat_symbols($1, $3);
}
| error {
$$ = NULL;
@@ -1368,10 +1368,11 @@ array_size:
identifier_list: /* C99 6.7.5 */
T_NAME {
- $$ = old_style_function_name(getsym($1));
+ $$ = old_style_function_parameter_name(getsym($1));
}
| identifier_list T_COMMA T_NAME {
- $$ = concat_lists($1, old_style_function_name(getsym($3)));
+ $$ = concat_symbols($1,
+ old_style_function_parameter_name(getsym($3)));
}
| identifier_list error
;
@@ -1490,7 +1491,7 @@ vararg_parameter_type_list: /* specific
parameter_type_list:
parameter_declaration
| parameter_type_list T_COMMA parameter_declaration {
- $$ = concat_lists($1, $3);
+ $$ = concat_symbols($1, $3);
}
;
diff -r feba680573a9 -r 545759e74808 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Fri Jun 30 16:39:17 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c Fri Jun 30 19:10:49 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.326 2023/06/30 15:19:09 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.327 2023/06/30 19:10:49 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.326 2023/06/30 15:19:09 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.327 2023/06/30 19:10:49 rillig Exp $");
#endif
#include <sys/param.h>
@@ -132,9 +132,8 @@ gettyp(tspec_t t)
type_t *
block_dup_type(const type_t *tp)
{
- type_t *ntp;
-
- ntp = block_zero_alloc(sizeof(*ntp));
+
+ type_t *ntp = block_zero_alloc(sizeof(*ntp));
*ntp = *tp;
return ntp;
}
@@ -143,9 +142,8 @@ block_dup_type(const type_t *tp)
type_t *
expr_dup_type(const type_t *tp)
{
- type_t *ntp;
-
- ntp = expr_zero_alloc(sizeof(*ntp));
+
+ type_t *ntp = expr_zero_alloc(sizeof(*ntp));
*ntp = *tp;
return ntp;
}
@@ -159,9 +157,8 @@ expr_dup_type(const type_t *tp)
type_t *
expr_unqualified_type(const type_t *tp)
{
- type_t *ntp;
-
- ntp = expr_zero_alloc(sizeof(*ntp));
+
+ type_t *ntp = expr_zero_alloc(sizeof(*ntp));
*ntp = *tp;
ntp->t_const = false;
ntp->t_volatile = false;
@@ -178,15 +175,15 @@ expr_unqualified_type(const type_t *tp)
}
/*
- * Returns whether the argument is void or an incomplete array,
- * struct, union or enum type.
+ * Returns whether the argument is void or an incomplete array, struct, union
+ * or enum type.
*/
bool
is_incomplete(const type_t *tp)
{
- tspec_t t;
-
- if ((t = tp->t_tspec) == VOID)
+ tspec_t t = tp->t_tspec;
+
+ if (t == VOID)
return true;
if (t == ARRAY)
return tp->t_incomplete_array;
@@ -194,7 +191,6 @@ is_incomplete(const type_t *tp)
return tp->t_sou->sou_incomplete;
if (t == ENUM)
return tp->t_enum->en_incomplete;
-
return false;
}
@@ -227,19 +223,17 @@ dcs_add_storage_class(scl_t sc)
}
/*
- * Remember the type, modifier or typedef name returned by the parser
- * in *dcs (top element of decl stack). This information is used in
- * dcs_end_type to build the type used for all declarators in this
- * declaration.
+ * Remember the type, modifier or typedef name returned by the parser in the
+ * top element of the declaration stack. This information is used in
+ * dcs_end_type to build the type used for all declarators in this declaration.
*
- * If tp->t_typedef is true, the type comes from a previously defined
- * typename. Otherwise, it comes from a type specifier (int, long, ...) or a
+ * If tp->t_typedef is true, the type comes from a previously defined typename.
+ * Otherwise, it comes from a type specifier (int, long, ...) or a
* struct/union/enum tag.
*/
void
dcs_add_type(type_t *tp)
{
- tspec_t t;
debug_step("%s: %s", __func__, type_name(tp));
if (tp->t_typedef) {
@@ -256,8 +250,7 @@ dcs_add_type(type_t *tp)
return;
}
- t = tp->t_tspec;
-
+ tspec_t t = tp->t_tspec;
if (is_struct_or_union(t) || t == ENUM) {
/*
* something like "int struct a ..."
@@ -313,19 +306,10 @@ dcs_add_type(type_t *tp)
/* now it can be only a combination of arithmetic types and void */
if (t == SIGNED || t == UNSIGN) {
- /*
- * remember specifiers "signed" & "unsigned" in
- * dcs->d_sign_mod
- */
if (dcs->d_sign_mod != NO_TSPEC)
- /* more than one "signed" and/or "unsigned" */
dcs->d_invalid_type_combination = true;
dcs->d_sign_mod = t;
} else if (t == SHORT || t == LONG || t == QUAD) {
- /*
- * remember specifiers "short", "long" and "long long" in
- * dcs->d_rank_mod
- */
if (dcs->d_rank_mod != NO_TSPEC)
dcs->d_invalid_type_combination = true;
dcs->d_rank_mod = t;
@@ -343,10 +327,6 @@ dcs_add_type(type_t *tp)
} else if (t == PTR) {
dcs->d_type = tp;
} else {
- /*
- * remember specifiers "void", "char", "int",
- * or "_Complex" in dcs->d_abstract_type
- */
if (dcs->d_abstract_type != NO_TSPEC)
dcs->d_invalid_type_combination = true;
dcs->d_abstract_type = t;
@@ -371,15 +351,14 @@ merge_signedness(tspec_t t, tspec_t s)
}
/*
- * called if a list of declaration specifiers contains a typedef name
- * and other specifiers (except struct, union, enum, typedef name)
+ * Called if a list of declaration specifiers contains a typedef name
+ * and other specifiers (except struct, union, enum, typedef name).
*/
static type_t *
typedef_error(type_t *td, tspec_t t)
{
- tspec_t t2;
-
- t2 = td->t_tspec;
+
+ tspec_t t2 = td->t_tspec;
if ((t == SIGNED || t == UNSIGN) &&
(t2 == CHAR || t2 == SHORT || t2 == INT ||
@@ -432,31 +411,19 @@ invalid:
return td;
}
-/*
- * Remember the symbol of a typedef name (2nd arg) in a struct, union
- * or enum tag if the typedef name is the first defined for this tag.
- *
- * If the tag is unnamed, the typedef name is used for identification
- * of this tag in lint2. Although it's possible that more than one typedef
- * name is defined for one tag, the first name defined should be unique
- * if the tag is unnamed.
- */
static void
set_first_typedef(type_t *tp, sym_t *sym)
{
- tspec_t t;
-
- if (is_struct_or_union(t = tp->t_tspec)) {
- if (tp->t_sou->sou_first_typedef == NULL)
- tp->t_sou->sou_first_typedef = sym;
- } else if (t == ENUM) {
- if (tp->t_enum->en_first_typedef == NULL)
- tp->t_enum->en_first_typedef = sym;
- }
+
+ tspec_t t = tp->t_tspec;
+ if (is_struct_or_union(t) && tp->t_sou->sou_first_typedef == NULL)
+ tp->t_sou->sou_first_typedef = sym;
+ if (t == ENUM && tp->t_enum->en_first_typedef == NULL)
+ tp->t_enum->en_first_typedef = sym;
}
static unsigned int
-bit_field_width(sym_t **mem, bool *named)
Home |
Main Index |
Thread Index |
Old Index