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: remove forward declarations for fu...



details:   https://anonhg.NetBSD.org/src/rev/3eb6f6f786fb
branches:  trunk
changeset: 378277:3eb6f6f786fb
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 29 07:03:19 2023 +0000

description:
lint: remove forward declarations for functions

No functional change.

diffstat:

 usr.bin/xlint/lint1/decl.c |  1014 +++++++++++++++++++++----------------------
 1 files changed, 498 insertions(+), 516 deletions(-)

diffs (truncated from 1164 to 300 lines):

diff -r b9b3cf062160 -r 3eb6f6f786fb usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Jul 29 07:00:00 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Jul 29 07:03:19 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.363 2023/07/28 21:50:03 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.364 2023/07/29 07:03:19 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.363 2023/07/28 21:50:03 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.364 2023/07/29 07:03:19 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -63,24 +63,6 @@ int  enumval;
  */
 decl_level     *dcs;
 
-static type_t  *typedef_error(type_t *, tspec_t);
-static void    set_first_typedef(type_t *, sym_t *);
-static void    dcs_align(unsigned int, unsigned int);
-static sym_t   *new_tag(sym_t *, scl_t, bool, bool);
-static bool    prototypes_compatible(const type_t *, const type_t *, bool *);
-static bool    matches_no_arg_function(const type_t *, bool *);
-static bool    check_old_style_definition(sym_t *, sym_t *);
-static bool    check_prototype_declaration(sym_t *, sym_t *);
-static void    check_prototype_parameters(sym_t *);
-static void    old_style_function(sym_t *, sym_t *);
-static void    declare_external_in_block(sym_t *);
-static bool    check_init(sym_t *);
-static void    check_argument_usage(bool, sym_t *);
-static void    check_variable_usage(bool, sym_t *);
-static void    check_label_usage(sym_t *);
-static void    check_tag_usage(sym_t *);
-static void    check_global_variable(const sym_t *);
-static void    check_global_variable_size(const sym_t *);
 
 /*
  * initializes all global vars used in declarations
@@ -233,6 +215,84 @@ dcs_add_storage_class(scl_t sc)
                dcs->d_multiple_storage_classes = true;
 }
 
+/* Merge the signedness into the abstract type. */
+static tspec_t
+merge_signedness(tspec_t t, tspec_t s)
+{
+
+       if (s == SIGNED)
+               return t == CHAR ? SCHAR : t;
+       if (s != UNSIGN)
+               return t;
+       return t == CHAR ? UCHAR
+           : t == SHORT ? USHORT
+           : t == INT ? UINT
+           : t == LONG ? ULONG
+           : t == LLONG ? ULLONG
+           : t;
+}
+
+/*
+ * 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 = td->t_tspec;
+
+       if ((t == SIGNED || t == UNSIGN) &&
+           (t2 == CHAR || t2 == SHORT || t2 == INT ||
+            t2 == LONG || t2 == LLONG)) {
+               if (allow_c90)
+                       /* modifying typedef with '%s'; only qualifiers... */
+                       warning(5, tspec_name(t));
+               td = block_dup_type(gettyp(merge_signedness(t2, t)));
+               td->t_typedef = true;
+               return td;
+       }
+
+       if (t == SHORT && (t2 == INT || t2 == UINT)) {
+               /* modifying typedef with '%s'; only qualifiers allowed */
+               warning(5, "short");
+               td = block_dup_type(gettyp(t2 == INT ? SHORT : USHORT));
+               td->t_typedef = true;
+               return td;
+       }
+
+       if (t != LONG)
+               goto invalid;
+
+       if (t2 == INT)
+               td = gettyp(LONG);
+       else if (t2 == UINT)
+               td = gettyp(ULONG);
+       else if (t2 == LONG)
+               td = gettyp(LLONG);
+       else if (t2 == ULONG)
+               td = gettyp(ULLONG);
+       else if (t2 == FLOAT)
+               td = gettyp(DOUBLE);
+       else if (t2 == DOUBLE)
+               td = gettyp(LDOUBLE);
+       else if (t2 == DCOMPLEX)
+               td = gettyp(LCOMPLEX);
+       else
+               goto invalid;
+
+       /* modifying typedef with '%s'; only qualifiers allowed */
+       warning(5, "long");
+       td = block_dup_type(td);
+       td->t_typedef = true;
+       return td;
+
+invalid:
+       /* Anything else is not accepted. */
+       dcs->d_invalid_type_combination = true;
+       return td;
+}
+
 /*
  * Remember the type, modifier or typedef name returned by the parser in the
  * top element of the declaration stack. This information is used in
@@ -344,84 +404,6 @@ dcs_add_type(type_t *tp)
        }
 }
 
-/* Merge the signedness into the abstract type. */
-static tspec_t
-merge_signedness(tspec_t t, tspec_t s)
-{
-
-       if (s == SIGNED)
-               return t == CHAR ? SCHAR : t;
-       if (s != UNSIGN)
-               return t;
-       return t == CHAR ? UCHAR
-           : t == SHORT ? USHORT
-           : t == INT ? UINT
-           : t == LONG ? ULONG
-           : t == LLONG ? ULLONG
-           : t;
-}
-
-/*
- * 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 = td->t_tspec;
-
-       if ((t == SIGNED || t == UNSIGN) &&
-           (t2 == CHAR || t2 == SHORT || t2 == INT ||
-            t2 == LONG || t2 == LLONG)) {
-               if (allow_c90)
-                       /* modifying typedef with '%s'; only qualifiers... */
-                       warning(5, tspec_name(t));
-               td = block_dup_type(gettyp(merge_signedness(t2, t)));
-               td->t_typedef = true;
-               return td;
-       }
-
-       if (t == SHORT && (t2 == INT || t2 == UINT)) {
-               /* modifying typedef with '%s'; only qualifiers allowed */
-               warning(5, "short");
-               td = block_dup_type(gettyp(t2 == INT ? SHORT : USHORT));
-               td->t_typedef = true;
-               return td;
-       }
-
-       if (t != LONG)
-               goto invalid;
-
-       if (t2 == INT)
-               td = gettyp(LONG);
-       else if (t2 == UINT)
-               td = gettyp(ULONG);
-       else if (t2 == LONG)
-               td = gettyp(LLONG);
-       else if (t2 == ULONG)
-               td = gettyp(ULLONG);
-       else if (t2 == FLOAT)
-               td = gettyp(DOUBLE);
-       else if (t2 == DOUBLE)
-               td = gettyp(LDOUBLE);
-       else if (t2 == DCOMPLEX)
-               td = gettyp(LCOMPLEX);
-       else
-               goto invalid;
-
-       /* modifying typedef with '%s'; only qualifiers allowed */
-       warning(5, "long");
-       td = block_dup_type(td);
-       td->t_typedef = true;
-       return td;
-
-invalid:
-       /* Anything else is not accepted. */
-       dcs->d_invalid_type_combination = true;
-       return td;
-}
-
 static void
 set_first_typedef(type_t *tp, sym_t *sym)
 {
@@ -1010,6 +992,21 @@ check_bit_field(sym_t *dsym, tspec_t *in
        }
 }
 
+/* Aligns the next structure element as required. */
+static void
+dcs_align(unsigned int member_alignment, unsigned int bit_field_width)
+{
+
+       if (member_alignment > dcs->d_sou_align_in_bits)
+               dcs->d_sou_align_in_bits = member_alignment;
+
+       unsigned int offset = (dcs->d_sou_size_in_bits + member_alignment - 1)
+           & ~(member_alignment - 1);
+       if (bit_field_width == 0
+           || dcs->d_sou_size_in_bits + bit_field_width > offset)
+               dcs->d_sou_size_in_bits = offset;
+}
+
 /* Add a member to the struct or union type that is being built in 'dcs'. */
 static void
 dcs_add_member(sym_t *mem)
@@ -1106,21 +1103,6 @@ declare_member(sym_t *dsym)
        return dsym;
 }
 
-/* Aligns the next structure element as required. */
-static void
-dcs_align(unsigned int member_alignment, unsigned int bit_field_width)
-{
-
-       if (member_alignment > dcs->d_sou_align_in_bits)
-               dcs->d_sou_align_in_bits = member_alignment;
-
-       unsigned int offset = (dcs->d_sou_size_in_bits + member_alignment - 1)
-           & ~(member_alignment - 1);
-       if (bit_field_width == 0
-           || dcs->d_sou_size_in_bits + bit_field_width > offset)
-               dcs->d_sou_size_in_bits = offset;
-}
-
 sym_t *
 set_bit_field_width(sym_t *dsym, int bit_field_width)
 {
@@ -1289,6 +1271,54 @@ block_derive_function(type_t *ret, bool 
        return tp;
 }
 
+static void
+check_prototype_parameters(sym_t *args)
+{
+
+       for (sym_t *sym = dcs->d_first_dlsym;
+            sym != NULL; sym = sym->s_level_next) {
+               scl_t sc = sym->s_scl;
+               if (sc == STRUCT_TAG || sc == UNION_TAG || sc == ENUM_TAG) {
+                       /* dubious tag declaration '%s %s' */
+                       warning(85, storage_class_name(sc), sym->s_name);
+               }
+       }
+
+       for (sym_t *arg = args; arg != NULL; arg = arg->s_next) {
+               if (arg->s_type->t_tspec == VOID &&
+                   !(arg == args && arg->s_next == NULL)) {
+                       /* void must be sole parameter */
+                       error(60);
+                       arg->s_type = gettyp(INT);
+               }
+       }
+}
+
+static void
+old_style_function(sym_t *decl, sym_t *args)
+{
+
+       /*
+        * Remember the list of parameters only if this really seems to be a
+        * function definition.
+        */
+       if (dcs->d_enclosing->d_kind == DLK_EXTERN &&
+           decl->s_type == dcs->d_enclosing->d_type) {
+               /*
+                * Assume that this becomes a function definition. If not, it
+                * will be corrected in check_function_definition.
+                */
+               if (args != NULL) {
+                       decl->s_osdef = true;



Home | Main Index | Thread Index | Old Index