Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint lint: move all declarations above statements
details: https://anonhg.NetBSD.org/src/rev/02399eff91c9
branches: trunk
changeset: 1024740:02399eff91c9
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Nov 01 19:10:07 2021 +0000
description:
lint: move all declarations above statements
All code that is used by src/tools is supposed to be compatible with C90.
No functional change.
diffstat:
usr.bin/xlint/Makefile.inc | 3 +-
usr.bin/xlint/lint1/ckgetopt.c | 14 +++++++----
usr.bin/xlint/lint1/decl.c | 18 +++++++++----
usr.bin/xlint/lint1/lex.c | 10 ++++---
usr.bin/xlint/lint1/tree.c | 52 ++++++++++++++++++++++++-----------------
5 files changed, 59 insertions(+), 38 deletions(-)
diffs (truncated from 308 to 300 lines):
diff -r 25171e03ef41 -r 02399eff91c9 usr.bin/xlint/Makefile.inc
--- a/usr.bin/xlint/Makefile.inc Mon Nov 01 18:11:25 2021 +0000
+++ b/usr.bin/xlint/Makefile.inc Mon Nov 01 19:10:07 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.15 2021/08/07 17:38:41 rillig Exp $
+# $NetBSD: Makefile.inc,v 1.16 2021/11/01 19:10:07 rillig Exp $
.include <bsd.own.mk>
@@ -16,6 +16,7 @@
CPPFLAGS+= -I${.CURDIR}/../arch/${ARCHSUBDIR}
CPPFLAGS+= -I${.CURDIR}/../common
+CWARNFLAGS+= -Wdeclaration-after-statement # it's a build tool
CLEANFILES+= *.gcno *.gcda *.gcov
diff -r 25171e03ef41 -r 02399eff91c9 usr.bin/xlint/lint1/ckgetopt.c
--- a/usr.bin/xlint/lint1/ckgetopt.c Mon Nov 01 18:11:25 2021 +0000
+++ b/usr.bin/xlint/lint1/ckgetopt.c Mon Nov 01 19:10:07 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.12 2021/10/09 14:22:42 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.13 2021/11/01 19:10:07 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckgetopt.c,v 1.12 2021/10/09 14:22:42 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.13 2021/11/01 19:10:07 rillig Exp $");
#endif
#include <stdbool.h>
@@ -85,11 +85,13 @@
static bool
is_getopt_condition(const tnode_t *tn, char **out_options)
{
+ const tnode_t *call, *last_arg;
+
NEED(tn != NULL);
NEED(tn->tn_op == NE);
NEED(tn->tn_left->tn_op == ASSIGN);
- const tnode_t *call = tn->tn_left->tn_right;
+ call = tn->tn_left->tn_right;
NEED(call->tn_op == CALL);
NEED(call->tn_left->tn_op == ADDR);
NEED(call->tn_left->tn_left->tn_op == NAME);
@@ -97,7 +99,7 @@
NEED(call->tn_right->tn_op == PUSH);
- const tnode_t *last_arg = call->tn_right->tn_left;
+ last_arg = call->tn_right->tn_left;
NEED(last_arg->tn_op == CVT);
NEED(last_arg->tn_left->tn_op == ADDR);
NEED(last_arg->tn_left->tn_left->tn_op == STRING);
@@ -111,12 +113,14 @@
static void
check_unlisted_option(char opt)
{
+ char *optptr;
+
lint_assert(ck.options != NULL);
if (opt == ':' && ck.options[0] != ':')
goto warn;
- char *optptr = strchr(ck.options, opt);
+ optptr = strchr(ck.options, opt);
if (optptr != NULL)
*optptr = ' ';
else if (opt != '?') {
diff -r 25171e03ef41 -r 02399eff91c9 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Mon Nov 01 18:11:25 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c Mon Nov 01 19:10:07 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.241 2021/09/17 21:15:19 christos Exp $ */
+/* $NetBSD: decl.c,v 1.242 2021/11/01 19:10:07 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.241 2021/09/17 21:15:19 christos Exp $");
+__RCSID("$NetBSD: decl.c,v 1.242 2021/11/01 19:10:07 rillig Exp $");
#endif
#include <sys/param.h>
@@ -541,12 +541,14 @@
sp->sou_size_in_bits = 0;
for (mem = sp->sou_first_member;
mem != NULL; mem = mem->s_next) {
+ unsigned int x;
+
if (mem->s_type->t_bitfield) {
sp->sou_size_in_bits += bitfieldsize(&mem);
if (mem == NULL)
break;
}
- unsigned int x = type_size_in_bits(mem->s_type);
+ x = type_size_in_bits(mem->s_type);
if (tp->t_tspec == STRUCT)
sp->sou_size_in_bits += x;
else if (x > sp->sou_size_in_bits)
@@ -1098,9 +1100,11 @@
* above are okay only if BITFIELDTYPE is in effect.
*/
if (!(bitfieldtype_ok || gflag) || !is_integer(t)) {
+ unsigned int sz;
+
/* illegal bit-field type '%s' */
warning(35, type_name(tp));
- unsigned int sz = tp->t_flen;
+ sz = tp->t_flen;
dsym->s_type = tp = dup_type(gettyp(t = INT));
if ((tp->t_flen = sz) > size_in_bits(t))
tp->t_flen = size_in_bits(t);
@@ -1113,11 +1117,13 @@
static void
declare_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **const inout_tp)
{
+ type_t *tp;
+ tspec_t t;
check_bit_field_type(dsym, inout_tp, inout_t);
- type_t *const tp = *inout_tp;
- tspec_t const t = *inout_t;
+ tp = *inout_tp;
+ t = *inout_t;
if (tp->t_flen > size_in_bits(t)) {
/* illegal bit-field size: %d */
error(36, tp->t_flen);
diff -r 25171e03ef41 -r 02399eff91c9 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Mon Nov 01 18:11:25 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Mon Nov 01 19:10:07 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.84 2021/09/18 10:46:17 jmcneill Exp $ */
+/* $NetBSD: lex.c,v 1.85 2021/11/01 19:10:07 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.84 2021/09/18 10:46:17 jmcneill Exp $");
+__RCSID("$NetBSD: lex.c,v 1.85 2021/11/01 19:10:07 rillig Exp $");
#endif
#include <ctype.h>
@@ -997,13 +997,15 @@
*is_system = false;
while (*p != '\0') {
+ const char *word_start, *word_end;
+
while (ch_isspace(*p))
p++;
- const char *word_start = p;
+ word_start = p;
while (*p != '\0' && !ch_isspace(*p))
p++;
- const char *word_end = p;
+ word_end = p;
if (word_end - word_start == 1 && word_start[0] == '1')
*is_begin = true;
diff -r 25171e03ef41 -r 02399eff91c9 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Mon Nov 01 18:11:25 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Mon Nov 01 19:10:07 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.391 2021/11/01 18:11:25 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.392 2021/11/01 19:10:07 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.391 2021/11/01 18:11:25 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.392 2021/11/01 19:10:07 rillig Exp $");
#endif
#include <float.h>
@@ -1024,6 +1024,8 @@
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;
@@ -1037,8 +1039,8 @@
return false;
}
- const char *lx = lt == PTR ? "pointer" : "integer";
- const char *rx = rt == PTR ? "pointer" : "integer";
+ lx = lt == PTR ? "pointer" : "integer";
+ 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;
@@ -1552,11 +1554,13 @@
const type_t *const ltp, tspec_t const lt,
const type_t *const rtp, tspec_t const rt)
{
+ const char *lx, *rx;
+
if (!((lt == PTR && is_integer(rt)) || (is_integer(lt) && rt == PTR)))
return false;
- const char *lx = lt == PTR ? "pointer" : "integer";
- const char *rx = rt == PTR ? "pointer" : "integer";
+ lx = lt == PTR ? "pointer" : "integer";
+ rx = rt == PTR ? "pointer" : "integer";
switch (op) {
case INIT:
@@ -2715,14 +2719,15 @@
merge_qualifiers(type_t *tp1, const type_t *tp2)
{
type_t *ntp, *nstp;
+ bool c1, c2, v1, v2;
lint_assert(tp1->t_tspec == PTR);
lint_assert(tp2->t_tspec == PTR);
- bool c1 = tp1->t_subt->t_const;
- bool c2 = tp2->t_subt->t_const;
- bool v1 = tp1->t_subt->t_volatile;
- bool v2 = tp2->t_subt->t_volatile;
+ c1 = tp1->t_subt->t_const;
+ c2 = tp2->t_subt->t_const;
+ v1 = tp1->t_subt->t_volatile;
+ v2 = tp2->t_subt->t_volatile;
if (c1 == (c1 | c2) && v1 == (v1 | v2))
return tp1;
@@ -3453,14 +3458,16 @@
tnode_t *
build_offsetof(const type_t *tp, const sym_t *sym)
{
- tspec_t t = tp->t_tspec;
- if (t != STRUCT && t != UNION)
+ unsigned int offset_in_bytes;
+ tnode_t *tn;
+
+ if (!is_struct_or_union(tp->t_tspec))
/* unacceptable operand of '%s' */
error(111, "offsetof");
// XXX: wrong size, no checking for sym fixme
- unsigned int offset_in_bytes = type_size_in_bits(tp) / CHAR_SIZE;
- tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes);
+ offset_in_bytes = type_size_in_bits(tp) / CHAR_SIZE;
+ tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes);
tn->tn_system_dependent = true;
return tn;
}
@@ -4166,9 +4173,10 @@
check_expr_misc(const tnode_t *tn, bool vctx, bool tctx,
bool eqwarn, bool fcall, bool retval_discarded, bool szof)
{
- tnode_t *ln, *rn;
+ tnode_t *ln, *rn;
const mod_t *mp;
- op_t op;
+ op_t op;
+ bool cvctx, ctctx, eq, discard;
if (tn == NULL)
return;
@@ -4181,11 +4189,11 @@
szof, fcall, vctx, tctx, retval_discarded, eqwarn))
return;
- bool cvctx = mp->m_left_value_context;
- bool ctctx = mp->m_left_test_context;
- bool eq = mp->m_warn_if_operand_eq &&
- !ln->tn_parenthesized &&
- rn != NULL && !rn->tn_parenthesized;
+ cvctx = mp->m_left_value_context;
+ ctctx = mp->m_left_test_context;
+ eq = mp->m_warn_if_operand_eq &&
+ !ln->tn_parenthesized &&
+ rn != NULL && !rn->tn_parenthesized;
/*
* values of operands of ':' are not used if the type of at least
@@ -4195,7 +4203,7 @@
Home |
Main Index |
Thread Index |
Old Index