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: order functions to to reduce forwa...
details: https://anonhg.NetBSD.org/src/rev/720942833884
branches: trunk
changeset: 373705:720942833884
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Feb 24 19:18:50 2023 +0000
description:
lint: order functions to to reduce forward declarations
No functional change.
diffstat:
usr.bin/xlint/lint1/tree.c | 3620 +++++++++++++++++++++----------------------
1 files changed, 1789 insertions(+), 1831 deletions(-)
diffs (truncated from 3854 to 300 lines):
diff -r 4ec82798c5b1 -r 720942833884 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Fri Feb 24 19:04:54 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c Fri Feb 24 19:18:50 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.505 2023/02/22 22:30:40 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.506 2023/02/24 19:18:50 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.505 2023/02/22 22:30:40 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.506 2023/02/24 19:18:50 rillig Exp $");
#endif
#include <float.h>
@@ -49,6 +49,7 @@
#include "lint1.h"
+
typedef struct integer_constraints {
int64_t smin; /* signed minimum */
int64_t smax; /* signed maximum */
@@ -58,52 +59,10 @@
uint64_t bclr; /* bits that are definitely clear */
} integer_constraints;
-static tnode_t *build_integer_constant(tspec_t, int64_t);
-static void check_pointer_comparison(op_t,
- const tnode_t *, const tnode_t *);
-static bool check_assign_types_compatible(op_t, int,
- const tnode_t *, const tnode_t *);
-static void check_bad_enum_operation(op_t,
- const tnode_t *, const tnode_t *);
-static void check_enum_type_mismatch(op_t, int,
- const tnode_t *, const tnode_t *);
-static void check_enum_int_mismatch(op_t, int,
- const tnode_t *, const tnode_t *);
-static tnode_t *new_tnode(op_t, bool, type_t *, tnode_t *, tnode_t *);
-static void balance(op_t, tnode_t **, tnode_t **);
-static void warn_incompatible_types(op_t, const type_t *, tspec_t,
- const type_t *, tspec_t);
-static void warn_incompatible_pointers(const mod_t *,
- const type_t *, const type_t *);
-static bool has_constant_member(const type_t *);
-static void check_prototype_conversion(int, tspec_t, tspec_t, type_t *,
- tnode_t *);
-static void convert_integer_from_integer(op_t, int, tspec_t, tspec_t,
- type_t *, tnode_t *);
-static void convert_integer_from_pointer(op_t, tspec_t, type_t *,
- tnode_t *);
-static void convert_pointer_from_pointer(type_t *, tnode_t *);
-static tnode_t *build_struct_access(op_t, bool, tnode_t *, tnode_t *);
-static tnode_t *build_prepost_incdec(op_t, bool, tnode_t *);
-static tnode_t *build_real_imag(op_t, bool, tnode_t *);
-static tnode_t *build_address(bool, tnode_t *, bool);
-static tnode_t *build_plus_minus(op_t, bool, tnode_t *, tnode_t *);
-static tnode_t *build_bit_shift(op_t, bool, tnode_t *, tnode_t *);
-static tnode_t *build_colon(bool, tnode_t *, tnode_t *);
-static tnode_t *build_assignment(op_t, bool, tnode_t *, tnode_t *);
-static tnode_t *subt_size_in_bytes(type_t *);
-static tnode_t *fold(tnode_t *);
-static tnode_t *fold_bool(tnode_t *);
-static tnode_t *fold_float(tnode_t *);
-static tnode_t *check_function_arguments(type_t *, tnode_t *);
-static tnode_t *check_prototype_argument(int, type_t *, tnode_t *);
-static void check_null_effect(const tnode_t *);
-static void check_array_index(tnode_t *, bool);
-static void check_integer_comparison(op_t, tnode_t *, tnode_t *);
-static void check_precedence_confusion(tnode_t *);
extern sig_atomic_t fpe;
+
static uint64_t
u64_fill_right(uint64_t x)
{
@@ -116,6 +75,21 @@
return x;
}
+static bool
+str_endswith(const char *haystack, const char *needle)
+{
+ size_t hlen = strlen(haystack);
+ size_t nlen = strlen(needle);
+
+ return nlen <= hlen &&
+ memcmp(haystack + hlen - nlen, needle, nlen) == 0;
+}
+static const char *
+op_name(op_t op)
+{
+ return modtab[op].m_name;
+}
+
static unsigned
width_in_bits(const type_t *tp)
{
@@ -318,12 +292,6 @@
}
}
-static const char *
-op_name(op_t op)
-{
- return modtab[op].m_name;
-}
-
/* Build 'pointer to tp', 'array of tp' or 'function returning tp'. */
type_t *
block_derive_type(type_t *tp, tspec_t t)
@@ -352,6 +320,30 @@
}
/*
+ * Build and initialize a new node.
+ */
+static tnode_t *
+new_tnode(op_t op, bool sys, type_t *type, tnode_t *ln, tnode_t *rn)
+{
+
+ tnode_t *ntn = expr_alloc_tnode();
+ ntn->tn_op = op;
+ ntn->tn_type = type;
+ ntn->tn_sys = sys;
+ ntn->tn_left = ln;
+ ntn->tn_right = rn;
+
+ if (op == INDIR || op == FSEL) {
+ lint_assert(ln->tn_type->t_tspec == PTR);
+ tspec_t t = ln->tn_type->t_subt->t_tspec;
+ if (t != FUNC && t != VOID)
+ ntn->tn_lvalue = true;
+ }
+
+ return ntn;
+}
+
+/*
* Create a node for a constant.
*/
tnode_t *
@@ -440,16 +432,6 @@
return false;
}
-static bool
-str_endswith(const char *haystack, const char *needle)
-{
- size_t hlen = strlen(haystack);
- size_t nlen = strlen(needle);
-
- return nlen <= hlen &&
- memcmp(haystack + hlen - nlen, needle, nlen) == 0;
-}
-
/* https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html */
static bool
is_gcc_bool_builtin(const char *name)
@@ -557,164 +539,6 @@
return n;
}
-/*
- * Return whether all struct/union members with the same name have the same
- * type and offset.
- */
-static bool
-all_members_compatible(const sym_t *msym)
-{
- for (const sym_t *csym = msym;
- csym != NULL; csym = csym->s_symtab_next) {
- if (!is_member(csym))
- continue;
- if (strcmp(msym->s_name, csym->s_name) != 0)
- continue;
-
- for (const sym_t *sym = csym->s_symtab_next;
- sym != NULL; sym = sym->s_symtab_next) {
-
- if (!is_member(sym))
- continue;
- if (strcmp(csym->s_name, sym->s_name) != 0)
- continue;
- if (csym->u.s_member.sm_offset_in_bits !=
- sym->u.s_member.sm_offset_in_bits)
- return false;
-
- bool w = false;
- if (!types_compatible(csym->s_type, sym->s_type,
- false, false, &w) && !w)
- return false;
- if (csym->s_bitfield != sym->s_bitfield)
- return false;
- if (csym->s_bitfield) {
- type_t *tp1 = csym->s_type;
- type_t *tp2 = sym->s_type;
- if (tp1->t_flen != tp2->t_flen)
- return false;
- if (tp1->t_foffs != tp2->t_foffs)
- return false;
- }
- }
- }
- return true;
-}
-
-/*
- * Returns a symbol which has the same name as the msym argument and is a
- * member of the struct or union specified by the tn argument.
- */
-static sym_t *
-struct_or_union_member(tnode_t *tn, op_t op, sym_t *msym)
-{
- struct_or_union *str;
- type_t *tp;
- tspec_t t;
-
- /*
- * Remove the member if it was unknown until now, which means
- * that no defined struct or union has a member with the same name.
- */
- if (msym->s_scl == NOSCL) {
- /* type '%s' does not have member '%s' */
- error(101, type_name(tn->tn_type), msym->s_name);
- rmsym(msym);
- msym->s_kind = FMEMBER;
- msym->s_scl = STRUCT_MEMBER;
-
- struct_or_union *sou = expr_zero_alloc(sizeof(*sou));
- sou->sou_tag = expr_zero_alloc(sizeof(*sou->sou_tag));
- sou->sou_tag->s_name = unnamed;
-
- msym->u.s_member.sm_sou_type = sou;
- /*
- * The member sm_offset_in_bits is not needed here since this
- * symbol can only be used for error reporting.
- */
- return msym;
- }
-
- /* Set str to the tag of which msym is expected to be a member. */
- str = NULL;
- t = (tp = tn->tn_type)->t_tspec;
- if (op == POINT) {
- if (is_struct_or_union(t))
- str = tp->t_str;
- } else if (op == ARROW && t == PTR) {
- t = (tp = tp->t_subt)->t_tspec;
- if (is_struct_or_union(t))
- str = tp->t_str;
- }
-
- /*
- * If this struct/union has a member with the name of msym, return it.
- */
- if (str != NULL) {
- for (sym_t *sym = msym;
- sym != NULL; sym = sym->s_symtab_next) {
- if (!is_member(sym))
- continue;
- if (sym->u.s_member.sm_sou_type != str)
- continue;
- if (strcmp(sym->s_name, msym->s_name) != 0)
- continue;
- return sym;
- }
- }
-
- bool eq = all_members_compatible(msym);
-
- /*
- * Now handle the case in which the left operand refers really
- * to a struct/union, but the right operand is not member of it.
- */
- if (str != NULL) {
- if (eq && !allow_c90) {
- /* illegal use of member '%s' */
- warning(102, msym->s_name);
- } else {
- /* illegal use of member '%s' */
- error(102, msym->s_name);
- }
- return msym;
- }
-
- /*
- * Now the left operand of ARROW does not point to a struct/union
- * or the left operand of POINT is no struct/union.
- */
- if (eq) {
- if (op == POINT) {
- if (!allow_c90) {
- /* left operand of '.' must be struct ... */
- warning(103, type_name(tn->tn_type));
- } else {
Home |
Main Index |
Thread Index |
Old Index