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: condense code
details: https://anonhg.NetBSD.org/src/rev/34c56810fc96
branches: trunk
changeset: 374233:34c56810fc96
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Apr 11 19:02:19 2023 +0000
description:
lint: condense code
No functional change.
diffstat:
usr.bin/xlint/lint1/mem1.c | 16 +-
usr.bin/xlint/lint1/tree.c | 251 ++++++++++++++++----------------------------
2 files changed, 101 insertions(+), 166 deletions(-)
diffs (truncated from 649 to 300 lines):
diff -r 1d549cb55d02 -r 34c56810fc96 usr.bin/xlint/lint1/mem1.c
--- a/usr.bin/xlint/lint1/mem1.c Tue Apr 11 18:23:42 2023 +0000
+++ b/usr.bin/xlint/lint1/mem1.c Tue Apr 11 19:02:19 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mem1.c,v 1.64 2023/01/13 19:41:50 rillig Exp $ */
+/* $NetBSD: mem1.c,v 1.65 2023/04/11 19:02:19 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: mem1.c,v 1.64 2023/01/13 19:41:50 rillig Exp $");
+__RCSID("$NetBSD: mem1.c,v 1.65 2023/04/11 19:02:19 rillig Exp $");
#endif
#include <sys/param.h>
@@ -122,18 +122,16 @@ transform_filename(const char *name, siz
const char *
record_filename(const char *s, size_t slen)
{
- const struct filename *existing_fn;
- struct filename *fn;
- char *name;
- if ((existing_fn = search_filename(s, slen)) != NULL)
+ const struct filename *existing_fn = search_filename(s, slen);
+ if (existing_fn != NULL)
return existing_fn->fn_name;
- name = xmalloc(slen + 1);
+ char *name = xmalloc(slen + 1);
(void)memcpy(name, s, slen);
name[slen] = '\0';
- fn = xmalloc(sizeof(*fn));
+ struct filename *fn = xmalloc(sizeof(*fn));
fn->fn_name = name;
fn->fn_len = slen;
fn->fn_id = next_filename_id++;
@@ -160,12 +158,12 @@ get_filename_id(const char *s)
return fn->fn_id;
}
-/* Array of memory pools, indexed by mem_block_level. */
typedef struct memory_pools {
struct memory_pool *pools;
size_t cap;
} memory_pools;
+/* Array of memory pools, indexed by mem_block_level. */
static memory_pools mpools;
/* The pool for the current expression is independent of any block level. */
diff -r 1d549cb55d02 -r 34c56810fc96 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Tue Apr 11 18:23:42 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c Tue Apr 11 19:02:19 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.508 2023/04/11 00:03:42 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.509 2023/04/11 19:02:19 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.508 2023/04/11 00:03:42 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.509 2023/04/11 19:02:19 rillig Exp $");
#endif
#include <float.h>
@@ -1503,15 +1503,16 @@ fold_bool(tnode_t *tn)
static ldbl_t
floating_error_value(tspec_t t, ldbl_t lv)
{
- if (t == FLOAT) {
+ if (t == FLOAT)
return lv < 0 ? -FLT_MAX : FLT_MAX;
- } else if (t == DOUBLE) {
+ if (t == DOUBLE)
return lv < 0 ? -DBL_MAX : DBL_MAX;
- } else {
- /* LINTED 248: floating-point constant out of range */
- ldbl_t max = LDBL_MAX;
- return lv < 0 ? -max : max;
- }
+
+ /* FIXME: Remove the '(double)' cast near 'isfinite'. */
+ /* FIXME: Inlining the variable 'max' produces a wrong warning. */
+ /* LINTED 248: floating-point constant out of range */
+ ldbl_t max = LDBL_MAX;
+ return lv < 0 ? -max : max;
}
/*
@@ -1885,13 +1886,10 @@ struct_or_union_member(tnode_t *tn, op_t
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;
+ if (is_member(sym) &&
+ sym->u.s_member.sm_sou_type == str &&
+ strcmp(sym->s_name, msym->s_name) == 0)
+ return sym;
}
}
@@ -1977,8 +1975,6 @@ build_member_access(tnode_t *ln, op_t op
tnode_t *
cconv(tnode_t *tn)
{
- type_t *tp;
-
/*
* Array-lvalue (array of type T) is converted into rvalue
* (pointer to type T)
@@ -2003,7 +1999,7 @@ cconv(tnode_t *tn)
/* lvalue to rvalue */
if (tn->tn_lvalue) {
- tp = expr_dup_type(tn->tn_type);
+ type_t *tp = expr_dup_type(tn->tn_type);
/* C99 6.3.2.1p2 sentence 2 says to remove the qualifiers. */
tp->t_const = tp->t_volatile = false;
tn = new_tnode(LOAD, tn->tn_sys, tp, tn, NULL);
@@ -2083,10 +2079,10 @@ typeok_incdec(op_t op, const tnode_t *tn
/* %soperand of '%s' must be lvalue */
error(114, "", op_name(op));
return false;
- } else if (tp->t_const) {
- if (allow_c90)
- /* %soperand of '%s' must be modifiable lvalue */
- warning(115, "", op_name(op));
+ }
+ if (tp->t_const && allow_c90) {
+ /* %soperand of '%s' must be modifiable lvalue */
+ warning(115, "", op_name(op));
}
return true;
}
@@ -2137,18 +2133,12 @@ typeok_indir(const type_t *tp, tspec_t t
return true;
}
-/*
- * Called if incompatible types were detected.
- * Prints a appropriate warning.
- */
static void
warn_incompatible_types(op_t op,
const type_t *ltp, tspec_t lt,
const type_t *rtp, tspec_t rt)
{
- const mod_t *mp;
-
- mp = &modtab[op];
+ const mod_t *mp = &modtab[op];
if (lt == VOID || (mp->m_binary && rt == VOID)) {
/* void type illegal in expression */
@@ -2190,12 +2180,10 @@ typeok_minus(op_t op,
warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
- if (lt == PTR && rt == PTR) {
- if (!types_compatible(ltp->t_subt, rtp->t_subt,
- true, false, NULL)) {
- /* illegal pointer subtraction */
- error(116);
- }
+ if (lt == PTR && rt == PTR &&
+ !types_compatible(ltp->t_subt, rtp->t_subt, true, false, NULL)) {
+ /* illegal pointer subtraction */
+ error(116);
}
return true;
}
@@ -2229,10 +2217,7 @@ typeok_shr(const mod_t *mp,
}
} else if (allow_trad && allow_c90 &&
!is_uinteger(olt) && is_uinteger(ort)) {
- /*
- * The left operand would become unsigned in
- * traditional C.
- */
+ /* The left operand would become unsigned in traditional C. */
if (hflag && (ln->tn_op != CON || ln->tn_val->v_quad < 0)) {
/* semantics of '%s' change in ANSI C; use ... */
warning(118, mp->m_name);
@@ -2313,13 +2298,11 @@ static void
warn_incompatible_pointers(const mod_t *mp,
const type_t *ltp, const type_t *rtp)
{
- tspec_t lt, rt;
-
lint_assert(ltp->t_tspec == PTR);
lint_assert(rtp->t_tspec == PTR);
- lt = ltp->t_subt->t_tspec;
- rt = rtp->t_subt->t_tspec;
+ tspec_t lt = ltp->t_subt->t_tspec;
+ tspec_t rt = rtp->t_subt->t_tspec;
if (is_struct_or_union(lt) && is_struct_or_union(rt)) {
if (mp == NULL) {
@@ -2344,18 +2327,15 @@ warn_incompatible_pointers(const mod_t *
static void
check_pointer_comparison(op_t op, const tnode_t *ln, const tnode_t *rn)
{
- type_t *ltp, *rtp;
- tspec_t lst, rst;
- const char *lsts, *rsts;
-
- lst = (ltp = ln->tn_type)->t_subt->t_tspec;
- rst = (rtp = rn->tn_type)->t_subt->t_tspec;
+ type_t *ltp = ln->tn_type, *rtp = rn->tn_type;
+ tspec_t lst = ltp->t_subt->t_tspec, rst = rtp->t_subt->t_tspec;
if (lst == VOID || rst == VOID) {
/* TODO: C99 behaves like C90 here. */
if ((!allow_trad && !allow_c99) &&
(lst == FUNC || rst == FUNC)) {
- /* (void *)0 already handled in typeok() */
+ /* (void *)0 is already handled in typeok() */
+ const char *lsts, *rsts;
*(lst == FUNC ? &lsts : &rsts) = "function pointer";
*(lst == VOID ? &lsts : &rsts) = "'void *'";
/* ANSI C forbids comparison of %s with %s */
@@ -2382,8 +2362,6 @@ typeok_compare(op_t op,
const tnode_t *ln, const type_t *ltp, tspec_t lt,
const tnode_t *rn, const type_t *rtp, tspec_t rt)
{
- const char *lx, *rx;
-
if (lt == PTR && rt == PTR) {
check_pointer_comparison(op, ln, rn);
return true;
@@ -2397,8 +2375,8 @@ typeok_compare(op_t op,
return false;
}
- lx = lt == PTR ? "pointer" : "integer";
- rx = rt == PTR ? "pointer" : "integer";
+ const char *lx = lt == PTR ? "pointer" : "integer";
+ const char *rx = rt == PTR ? "pointer" : "integer";
/* illegal combination of %s '%s' and %s '%s', op '%s' */
warning(123, lx, type_name(ltp), rx, type_name(rtp), op_name(op));
return true;
@@ -2494,11 +2472,10 @@ typeok_colon(const mod_t *mp,
static bool
has_constant_member(const type_t *tp)
{
- sym_t *m;
-
lint_assert(is_struct_or_union(tp->t_tspec));
- for (m = tp->t_str->sou_first_member; m != NULL; m = m->s_next) {
+ for (sym_t *m = tp->t_str->sou_first_member;
+ m != NULL; m = m->s_next) {
const type_t *mtp = m->s_type;
if (mtp->t_const)
return true;
@@ -2572,7 +2549,6 @@ check_assign_void_pointer(op_t op, int a
tspec_t lt, tspec_t lst,
tspec_t rt, tspec_t rst)
{
- const char *lts, *rts;
if (!(lt == PTR && rt == PTR && (lst == VOID || rst == VOID)))
return;
@@ -2583,6 +2559,7 @@ check_assign_void_pointer(op_t op, int a
return;
/* comb. of ptr to func and ptr to void */
+ const char *lts, *rts;
*(lst == FUNC ? <s : &rts) = "function pointer";
*(lst == VOID ? <s : &rts) = "'void *'";
@@ -2630,8 +2607,6 @@ is_unconst_function(const char *name)
static bool
is_const_char_pointer(const tnode_t *tn)
{
- const type_t *tp;
-
/*
* For traditional reasons, C99 6.4.5p5 defines that string literals
* have type 'char[]'. They are often implicitly converted to
@@ -2648,7 +2623,7 @@ is_const_char_pointer(const tnode_t *tn)
tn->tn_left->tn_left->tn_op == STRING)
return true;
- tp = before_conversion(tn)->tn_type;
Home |
Main Index |
Thread Index |
Old Index