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: extract 'vararg' and 'prototype' f...



details:   https://anonhg.NetBSD.org/src/rev/02f3429d8b63
branches:  trunk
changeset: 378266:02f3429d8b63
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 28 21:50:03 2023 +0000

description:
lint: extract 'vararg' and 'prototype' flags from global 'dcs'

These flags are only relevant for parameter lists, so add a separate
type for it.

No functional change.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  33 ++++++++++++++++++---------------
 usr.bin/xlint/lint1/debug.c    |   6 ++----
 usr.bin/xlint/lint1/decl.c     |  24 ++++++++++++------------
 usr.bin/xlint/lint1/externs1.h |   4 ++--
 usr.bin/xlint/lint1/lint1.h    |  11 +++++++----
 5 files changed, 41 insertions(+), 37 deletions(-)

diffs (267 lines):

diff -r ca8e1dc29644 -r 02f3429d8b63 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Fri Jul 28 19:01:44 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Fri Jul 28 21:50:03 2023 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.465 2023/07/15 21:47:35 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.466 2023/07/28 21:50:03 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.465 2023/07/15 21:47:35 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.466 2023/07/28 21:50:03 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -143,6 +143,7 @@ is_either(const char *s, const char *a, 
        tspec_t y_tspec;
        type_qualifiers y_type_qualifiers;
        function_specifier y_function_specifier;
+       struct parameter_list y_parameter_list;
        type_t  *y_type;
        tnode_t *y_tnode;
        range_t y_range;
@@ -351,7 +352,7 @@ is_either(const char *s, const char *a, 
 %type  <y_sym>         notype_param_declarator
 %type  <y_sym>         direct_param_declarator
 %type  <y_sym>         direct_notype_param_declarator
-%type  <y_sym>         param_list
+%type  <y_parameter_list>      param_list
 /* No type for id_list_lparen. */
 /* No type for abstract_decl_lparen. */
 %type  <y_array_size>  array_size_opt
@@ -361,10 +362,10 @@ is_either(const char *s, const char *a, 
 %type  <y_sym>         abstract_declaration
 %type  <y_sym>         abstract_declarator
 %type  <y_sym>         direct_abstract_declarator
-%type  <y_sym>         abstract_decl_param_list
+%type  <y_parameter_list>      abstract_decl_param_list
 /* No type for abstract_decl_lparen. */
-%type  <y_sym>         vararg_parameter_type_list
-%type  <y_sym>         parameter_type_list
+%type  <y_parameter_list>      vararg_parameter_type_list
+%type  <y_parameter_list>      parameter_type_list
 %type  <y_sym>         parameter_declaration
 /* No type for braced_initializer. */
 /* No type for initializer. */
@@ -1411,7 +1412,7 @@ direct_notype_param_declarator:
 
 param_list:
        id_list_lparen identifier_list T_RPAREN {
-               $$ = $2;
+               $$ = (struct parameter_list){ .first = $2 };
        }
 |      abstract_decl_param_list
 ;
@@ -1539,15 +1540,15 @@ direct_abstract_declarator:
 
 abstract_decl_param_list:      /* specific to lint */
        abstract_decl_lparen T_RPAREN type_attribute_opt {
-               $$ = NULL;
+               $$ = (struct parameter_list){ .first = NULL };
        }
 |      abstract_decl_lparen vararg_parameter_type_list T_RPAREN
            type_attribute_opt {
-               dcs->d_prototype = true;
                $$ = $2;
+               $$.prototype = true;
        }
 |      abstract_decl_lparen error T_RPAREN type_attribute_opt {
-               $$ = NULL;
+               $$ = (struct parameter_list){ .first = NULL };
        }
 ;
 
@@ -1561,8 +1562,8 @@ abstract_decl_lparen:             /* specific to li
 vararg_parameter_type_list:    /* specific to lint */
        parameter_type_list
 |      parameter_type_list T_COMMA T_ELLIPSIS {
-               dcs->d_vararg = true;
                $$ = $1;
+               $$.vararg = true;
        }
 |      T_ELLIPSIS {
                /* TODO: C99 6.7.5 makes this an error as well. */
@@ -1573,16 +1574,18 @@ vararg_parameter_type_list:     /* specific 
                        /* ANSI C requires formal parameter before '...' */
                        warning(84);
                }
-               dcs->d_vararg = true;
-               $$ = NULL;
+               $$ = (struct parameter_list){ .vararg = true };
        }
 ;
 
 /* XXX: C99 6.7.5 defines the same name, but it looks different. */
 parameter_type_list:
-       parameter_declaration
+       parameter_declaration {
+               $$ = (struct parameter_list){ .first = $1 };
+       }
 |      parameter_type_list T_COMMA parameter_declaration {
-               $$ = concat_symbols($1, $3);
+               $$ = $1;
+               $$.first = concat_symbols($1.first, $3);
        }
 ;
 
diff -r ca8e1dc29644 -r 02f3429d8b63 usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Fri Jul 28 19:01:44 2023 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Fri Jul 28 21:50:03 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.55 2023/07/13 23:27:20 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.56 2023/07/28 21:50:03 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.55 2023/07/13 23:27:20 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.56 2023/07/28 21:50:03 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -440,8 +440,6 @@ debug_decl_level(const decl_level *dl)
        debug_word(dl->d_multiple_storage_classes, "multiple_storage_classes");
        debug_word(dl->d_invalid_type_combination, "invalid_type_combination");
        debug_word(dl->d_nonempty_decl, "nonempty_decl");
-       debug_word(dl->d_vararg, "vararg");
-       debug_word(dl->d_prototype, "prototype");
        debug_word(dl->d_no_type_specifier, "no_type_specifier");
        debug_word(dl->d_asm, "asm");
        debug_word(dl->d_packed, "packed");
diff -r ca8e1dc29644 -r 02f3429d8b63 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Fri Jul 28 19:01:44 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Fri Jul 28 21:50:03 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.362 2023/07/25 16:56:35 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.363 2023/07/28 21:50:03 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.362 2023/07/25 16:56:35 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.363 2023/07/28 21:50:03 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1290,26 +1290,27 @@ block_derive_function(type_t *ret, bool 
 }
 
 sym_t *
-add_function(sym_t *decl, sym_t *args)
+add_function(sym_t *decl, struct parameter_list params)
 {
 
        debug_enter();
        debug_dcs(true);
        debug_sym("decl: ", decl, "\n");
 #ifdef DEBUG
-       for (const sym_t *arg = args; arg != NULL; arg = arg->s_next)
+       for (const sym_t *arg = params.first; arg != NULL; arg = arg->s_next)
                debug_sym("arg: ", arg, "\n");
 #endif
 
-       if (dcs->d_prototype) {
+       if (params.prototype) {
                if (!allow_c90)
                        /* function prototypes are illegal in traditional C */
                        warning(270);
-               check_prototype_parameters(args);
-               if (args != NULL && args->s_type->t_tspec == VOID)
-                       args = NULL;
+               check_prototype_parameters(params.first);
+               if (params.first != NULL
+                   && params.first->s_type->t_tspec == VOID)
+                       params.first = NULL;
        } else
-               old_style_function(decl, args);
+               old_style_function(decl, params.first);
 
        /*
         * The symbols are removed from the symbol table by
@@ -1324,7 +1325,7 @@ add_function(sym_t *decl, sym_t *args)
        if (dcs->d_enclosing->d_kind == DLK_EXTERN &&
            decl->s_type == dcs->d_enclosing->d_type) {
                dcs->d_enclosing->d_func_proto_syms = dcs->d_first_dlsym;
-               dcs->d_enclosing->d_func_args = args;
+               dcs->d_enclosing->d_func_args = params.first;
        }
 
        /*
@@ -1348,7 +1349,7 @@ add_function(sym_t *decl, sym_t *args)
        }
 
        *tpp = block_derive_function(dcs->d_enclosing->d_type,
-           dcs->d_prototype, args, dcs->d_vararg);
+           params.prototype, params.first, params.vararg);
 
        debug_step("add_function: '%s'", type_name(decl->s_type));
        debug_dcs(true);
@@ -2779,7 +2780,6 @@ abstract_name(void)
         */
        sym->s_type = dcs->d_type;
        dcs->d_redeclared_symbol = NULL;
-       dcs->d_vararg = false;
 
        return sym;
 }
diff -r ca8e1dc29644 -r 02f3429d8b63 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Fri Jul 28 19:01:44 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Fri Jul 28 21:50:03 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.198 2023/07/15 15:51:22 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.199 2023/07/28 21:50:03 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -227,7 +227,7 @@ void        add_type_qualifiers(type_qualifiers
 qual_ptr *append_qualified_pointer(qual_ptr *, qual_ptr *);
 sym_t  *add_pointer(sym_t *, qual_ptr *);
 sym_t  *add_array(sym_t *, bool, int);
-sym_t  *add_function(sym_t *, sym_t *);
+sym_t  *add_function(sym_t *, struct parameter_list);
 void   check_extern_declaration(const sym_t *);
 void   check_function_definition(sym_t *, bool);
 sym_t  *declarator_name(sym_t *);
diff -r ca8e1dc29644 -r 02f3429d8b63 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Fri Jul 28 19:01:44 2023 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Fri Jul 28 21:50:03 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.195 2023/07/19 22:24:28 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.196 2023/07/28 21:50:03 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -385,9 +385,6 @@ typedef     struct decl_level {
        bool    d_invalid_type_combination:1;
        bool    d_nonempty_decl:1; /* in a function declaration, whether at
                                 * least one tag was declared */
-       bool    d_vararg:1;
-       bool    d_prototype:1;  /* in a function declaration, whether the
-                                * function has a prototype */
        bool    d_no_type_specifier:1;
        bool    d_asm:1;        /* set if d_ctx == AUTO and asm() present */
        bool    d_packed:1;
@@ -404,6 +401,12 @@ typedef    struct decl_level {
        struct decl_level *d_enclosing; /* the enclosing declaration level */
 } decl_level;
 
+struct parameter_list {
+       sym_t   *first;
+       bool    vararg:1;
+       bool    prototype:1;
+};
+
 /*
  * A sequence of asterisks and qualifiers, from right to left.  For example,
  * 'const ***volatile **const volatile' results in [c-v-, ----, --v-, ----,



Home | Main Index | Thread Index | Old Index