Module Name: src Committed By: rillig Date: Mon Jan 18 20:02:34 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: t_integration.sh src/usr.bin/xlint/lint1: func.c mem1.c oper.c scan.l tree.c src/usr.bin/xlint/lint2: chk.c Log Message: lint: clean up code (mostly comments) To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/tests/usr.bin/xlint/lint1/t_integration.sh cvs rdiff -u -r1.63 -r1.64 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/mem1.c cvs rdiff -u -r1.4 -r1.5 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.128 -r1.129 src/usr.bin/xlint/lint1/scan.l cvs rdiff -u -r1.181 -r1.182 src/usr.bin/xlint/lint1/tree.c cvs rdiff -u -r1.35 -r1.36 src/usr.bin/xlint/lint2/chk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/t_integration.sh diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.27 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.28 --- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.27 Sun Jan 17 23:00:41 2021 +++ src/tests/usr.bin/xlint/lint1/t_integration.sh Mon Jan 18 20:02:34 2021 @@ -1,4 +1,4 @@ -# $NetBSD: t_integration.sh,v 1.27 2021/01/17 23:00:41 rillig Exp $ +# $NetBSD: t_integration.sh,v 1.28 2021/01/18 20:02:34 rillig Exp $ # # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. # All rights reserved. @@ -177,7 +177,8 @@ test_case long_double_int "Checks for co "'long int'; PR bin/39639" test_case all_messages -all_messages_body() { +all_messages_body() +{ local srcdir ok msg base flags srcdir="$(atf_get_srcdir)" Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.63 src/usr.bin/xlint/lint1/func.c:1.64 --- src/usr.bin/xlint/lint1/func.c:1.63 Mon Jan 18 19:24:09 2021 +++ src/usr.bin/xlint/lint1/func.c Mon Jan 18 20:02:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.63 2021/01/18 19:24:09 rillig Exp $ */ +/* $NetBSD: func.c,v 1.64 2021/01/18 20:02:34 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: func.c,v 1.63 2021/01/18 19:24:09 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.64 2021/01/18 20:02:34 rillig Exp $"); #endif #include <stdlib.h> @@ -462,7 +462,7 @@ check_case_label(tnode_t *tn, cstk_t *ci * to the type of the switch expression */ v = constant(tn, true); - (void) memset(&nv, 0, sizeof nv); + (void)memset(&nv, 0, sizeof nv); convert_constant(CASE, 0, ci->c_swtype, &nv, v); free(v); Index: src/usr.bin/xlint/lint1/mem1.c diff -u src/usr.bin/xlint/lint1/mem1.c:1.23 src/usr.bin/xlint/lint1/mem1.c:1.24 --- src/usr.bin/xlint/lint1/mem1.c:1.23 Sat Jan 16 02:40:02 2021 +++ src/usr.bin/xlint/lint1/mem1.c Mon Jan 18 20:02:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: mem1.c,v 1.23 2021/01/16 02:40:02 rillig Exp $ */ +/* $NetBSD: mem1.c,v 1.24 2021/01/18 20:02:34 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: mem1.c,v 1.23 2021/01/16 02:40:02 rillig Exp $"); +__RCSID("$NetBSD: mem1.c,v 1.24 2021/01/18 20:02:34 rillig Exp $"); #endif #include <sys/types.h> @@ -140,7 +140,7 @@ fnnalloc(const char *s, size_t len) if ((fn = srchfn(s, len)) == NULL) { fn = xmalloc(sizeof (fn_t)); - /* Do not used strdup() because string is not NUL-terminated.*/ + /* Do not use strdup() because string is not NUL-terminated.*/ fn->fn_name = xmalloc(len + 1); (void)memcpy(fn->fn_name, s, len); fn->fn_name[len] = '\0'; Index: src/usr.bin/xlint/lint1/oper.c diff -u src/usr.bin/xlint/lint1/oper.c:1.4 src/usr.bin/xlint/lint1/oper.c:1.5 --- src/usr.bin/xlint/lint1/oper.c:1.4 Sat Jan 16 02:40:02 2021 +++ src/usr.bin/xlint/lint1/oper.c Mon Jan 18 20:02:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: oper.c,v 1.4 2021/01/16 02:40:02 rillig Exp $ */ +/* $NetBSD: oper.c,v 1.5 2021/01/18 20:02:34 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -51,7 +51,8 @@ static const struct { #include "ops.def" const char * -getopname(op_t op) { +getopname(op_t op) +{ return imods[op].m.m_name; } Index: src/usr.bin/xlint/lint1/scan.l diff -u src/usr.bin/xlint/lint1/scan.l:1.128 src/usr.bin/xlint/lint1/scan.l:1.129 --- src/usr.bin/xlint/lint1/scan.l:1.128 Mon Jan 18 17:54:50 2021 +++ src/usr.bin/xlint/lint1/scan.l Mon Jan 18 20:02:34 2021 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.128 2021/01/18 17:54:50 rillig Exp $ */ +/* $NetBSD: scan.l,v 1.129 2021/01/18 20:02:34 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: scan.l,v 1.128 2021/01/18 17:54:50 rillig Exp $"); +__RCSID("$NetBSD: scan.l,v 1.129 2021/01/18 20:02:34 rillig Exp $"); #endif #include <ctype.h> @@ -108,11 +108,11 @@ TL ([fFlL]?[i]?) 0{OD}*[lLuU]* return icon(8); {NZD}{D}*[lLuU]* return icon(10); 0[xX]{HD}+[lLuU]* return icon(16); -{D}+\.{D}*{EX}?{TL} | -{D}+{EX}{TL} | -0[xX]{HD}+\.{HD}*{HX}{TL} | -0[xX]{HD}+{HX}{TL} | -\.{D}+{EX}?{TL} return fcon(); +{D}+\.{D}*{EX}?{TL} | +{D}+{EX}{TL} | +0[xX]{HD}+\.{HD}*{HX}{TL} | +0[xX]{HD}+{HX}{TL} | +\.{D}+{EX}?{TL} return fcon(); "=" return operator(T_ASSIGN, NOOP); "*=" return operator(T_OPASSIGN, MULASS); "/=" return operator(T_OPASSIGN, DIVASS); @@ -328,7 +328,7 @@ uint64_t qumasks[64 + 1]; /* free list for sbuf structures */ static sbuf_t *sbfrlst; -/* Typ of next expected symbol */ +/* type of next expected symbol */ symt_t symtyp; @@ -598,7 +598,7 @@ icon(int base) /* read suffixes */ l_suffix = u_suffix = 0; - for ( ; ; ) { + for (;;) { if ((c = cp[len - 1]) == 'l' || c == 'L') { l_suffix++; } else if (c == 'u' || c == 'U') { @@ -1225,14 +1225,14 @@ directive(void) * PROTOLIB * SCANFLIKEn * VARARGSn - * If one of this comments is recognized, the arguments, if any, are + * If one of these comments is recognized, the argument, if any, is * parsed and a function which handles this comment is called. */ static void comment(void) { int c, lc; - static struct { + static const struct { const char *keywd; int arg; void (*func)(int); @@ -1262,7 +1262,7 @@ comment(void) eoc = false; - /* Skip white spaces after the start of the comment */ + /* Skip whitespace after the start of the comment */ while ((c = inpc()) != EOF && isspace(c)) continue; @@ -1282,7 +1282,7 @@ comment(void) if (i == sizeof (keywtab) / sizeof (keywtab[0])) goto skip_rest; - /* skip white spaces after the keyword */ + /* skip whitespace after the keyword */ while (c != EOF && isspace(c)) c = inpc(); @@ -1297,7 +1297,7 @@ comment(void) arg[l] = '\0'; a = l != 0 ? atoi(arg) : -1; - /* skip white spaces after the argument */ + /* skip whitespace after the argument */ while (c != EOF && isspace(c)) c = inpc(); @@ -1462,9 +1462,9 @@ wcstrg(void) * * getsym() is called as soon as it is probably ok to put the symbol to * the symbol table. This does not mean that it is not possible that - * symbols are put to the symbol table which are than not completely + * symbols are put to the symbol table which are not completely * declared due to syntax errors. To avoid too many problems in this - * case symbols get type int in getsym(). + * case, symbols get type int in getsym(). * * XXX calls to getsym() should be delayed until decl1*() is called */ @@ -1498,7 +1498,7 @@ getsym(sbuf_t *sb) /* create a new symbol table entry */ - /* labels must always be allocated at level 1 (outhermost block) */ + /* labels must always be allocated at level 1 (outermost block) */ if (symtyp == FLABEL) { sym = getlblk(1, sizeof (sym_t)); s = getlblk(1, sb->sb_len + 1); Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.181 src/usr.bin/xlint/lint1/tree.c:1.182 --- src/usr.bin/xlint/lint1/tree.c:1.181 Sun Jan 17 23:04:09 2021 +++ src/usr.bin/xlint/lint1/tree.c Mon Jan 18 20:02:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.181 2021/01/17 23:04:09 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.182 2021/01/18 20:02:34 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.181 2021/01/17 23:04:09 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.182 2021/01/18 20:02:34 rillig Exp $"); #endif #include <float.h> @@ -342,8 +342,8 @@ struct_or_union_member(tnode_t *tn, op_t 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). + * 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) { /* undefined struct/union member: %s */ @@ -371,8 +371,7 @@ struct_or_union_member(tnode_t *tn, op_t } /* - * If this struct/union has a member with the name of msym, return - * return this it. + * If this struct/union has a member with the name of msym, return it. */ if (str != NULL) { for (sym = msym; sym != NULL; sym = sym->s_link) { @@ -912,11 +911,12 @@ typeok_shr(const mod_t *mp, } static void -typeok_shl(const mod_t *mp, tspec_t lt, tspec_t rt) { +typeok_shl(const mod_t *mp, tspec_t lt, tspec_t rt) +{ /* - * ANSI C does not perform balancing for shift operations, + * C90 does not perform balancing for shift operations, * but traditional C does. If the width of the right operand - * is greater than the width of the left operand, than in + * is greater than the width of the left operand, then in * traditional C the left operand would be extended to the * width of the right operand. For SHL this may result in * different results. @@ -1648,10 +1648,7 @@ check_assign_types_compatible(op_t op, i return false; } -/* - * Prints a warning if an operator, which should be senseless for an - * enum type, is applied to an enum type. - */ +/* Prints a warning if a strange operator is used on an enum type. */ static void check_bad_enum_operation(op_t op, const tnode_t *ln, const tnode_t *rn) { @@ -1720,10 +1717,7 @@ check_enum_type_mismatch(op_t op, int ar } } -/* - * Prints a warning if an operator has both enum and other integer - * types. - */ +/* Prints a warning if the operands mix between enum and integer. */ static void check_enum_int_mismatch(op_t op, int arg, const tnode_t *ln, const tnode_t *rn) { @@ -1734,9 +1728,8 @@ check_enum_int_mismatch(op_t op, int arg switch (op) { case INIT: /* - * Initializations with 0 should be allowed. Otherwise, - * we should complain about all uninitialized enums, - * consequently. + * Initialization with 0 is allowed. Otherwise, all implicit + * initializations would need to be warned upon as well. */ if (!rn->tn_type->t_isenum && rn->tn_op == CON && is_integer(rn->tn_type->t_tspec) && @@ -1832,11 +1825,11 @@ new_tnode(op_t op, type_t *type, tnode_t } /* - * Performs usual conversion of operands to (unsigned) int. + * Performs the "integer promotions" (C99 6.3.1.1p2), which convert small + * integer types to either int or unsigned int. * - * If tflag is set or the operand is a function argument with no - * type information (no prototype or variable # of args), convert - * float to double. + * If tflag is set or the operand is a function argument with no type + * information (no prototype or variable # of args), converts float to double. */ tnode_t * promote(op_t op, bool farg, tnode_t *tn) @@ -1909,8 +1902,10 @@ promote(op_t op, bool farg, tnode_t *tn) } /* - * Insert conversions which are necessary to give both operands the same - * type. This is done in different ways for traditional C and ANIS C. + * Apply the "usual arithmetic conversions" (C99 6.3.1.8). + * + * This gives both operands the same type. + * This is done in different ways for traditional C and C90. */ static void balance(op_t op, tnode_t **lnp, tnode_t **rnp) @@ -1919,7 +1914,7 @@ balance(op_t op, tnode_t **lnp, tnode_t int i; bool u; type_t *ntp; - static tspec_t tl[] = { + static const tspec_t tl[] = { LDOUBLE, DOUBLE, FLOAT, UQUAD, QUAD, ULONG, LONG, UINT, INT, }; @@ -2042,7 +2037,7 @@ convert(op_t op, int arg, type_t *tp, tn * different from what would happen to the same argument in the * absence of a prototype. * - * Errors/Warnings about illegal type combinations are already printed + * Errors/warnings about illegal type combinations are already printed * in check_assign_types_compatible(). */ static void @@ -2059,6 +2054,7 @@ check_prototype_conversion(int arg, tspe * would be useless, because functions declared the old style * can't expect char/short arguments. */ + /* XXX: what about SCHAR? */ if (nt == CHAR || nt == UCHAR || nt == SHORT || nt == USHORT) return; @@ -2688,6 +2684,7 @@ build_real_imag(op_t op, tnode_t *ln) switch (ln->tn_type->t_tspec) { case LCOMPLEX: + /* XXX: integer and LDOUBLE don't match. */ cn = new_integer_constant_node(LDOUBLE, (int64_t)1); break; case DCOMPLEX: @@ -2708,12 +2705,11 @@ build_real_imag(op_t op, tnode_t *ln) return ntn; } /* - * Create a tree node for the & operator + * Create a tree node for the unary & operator */ static tnode_t * build_address(tnode_t *tn, bool noign) { - tnode_t *ntn; tspec_t t; if (!noign && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) { @@ -2730,9 +2726,7 @@ build_address(tnode_t *tn, bool noign) return tn->tn_left; } - ntn = new_tnode(ADDR, tincref(tn->tn_type, PTR), tn, NULL); - - return ntn; + return new_tnode(ADDR, tincref(tn->tn_type, PTR), tn, NULL); } /* @@ -3015,8 +3009,7 @@ plength(type_t *tp) */ /* * Do only as much as necessary to compute constant expressions. - * Called only if the operator allows folding and (both) operands - * are constants. + * Called only if the operator allows folding and all operands are constants. */ static tnode_t * fold(tnode_t *tn) @@ -3160,7 +3153,8 @@ fold(tnode_t *tn) } /* - * Same for operators whose operands are compared with 0 (test context). + * Fold constant nodes, as much as is needed for comparing the value with 0 + * (test context, for controlling expressions). */ static tnode_t * fold_test(tnode_t *tn) @@ -3196,7 +3190,7 @@ fold_test(tnode_t *tn) } /* - * Same for operands with floating point type. + * Fold constant nodes having operands with floating point type. */ static tnode_t * fold_float(tnode_t *tn) @@ -3391,8 +3385,6 @@ tsize(type_t *tp) return (int64_t)(elem * elsz); } -/* - */ tnode_t * build_alignof(type_t *tp) { @@ -3459,7 +3451,7 @@ cast(tnode_t *tn, type_t *tp) if (nt == VOID) { /* * XXX ANSI C requires scalar types or void (Plauger & Brodie). - * But this seams really questionable. + * But this seems really questionable. */ } else if (nt == UNION) { sym_t *m; Index: src/usr.bin/xlint/lint2/chk.c diff -u src/usr.bin/xlint/lint2/chk.c:1.35 src/usr.bin/xlint/lint2/chk.c:1.36 --- src/usr.bin/xlint/lint2/chk.c:1.35 Sat Jan 16 16:53:24 2021 +++ src/usr.bin/xlint/lint2/chk.c Mon Jan 18 20:02:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.35 2021/01/16 16:53:24 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.36 2021/01/18 20:02:34 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: chk.c,v 1.35 2021/01/16 16:53:24 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.36 2021/01/18 20:02:34 rillig Exp $"); #endif #include <ctype.h> @@ -611,7 +611,7 @@ printflike(hte_t *hte, fcall_t *call, in fp = fmt; fc = *fp++; - for ( ; ; ) { + for (;;) { if (fc == '\0') { if (*ap != NULL) tomanyarg(hte, call); @@ -626,7 +626,7 @@ printflike(hte_t *hte, fcall_t *call, in sz = NOTSPEC; /* Flags */ - for ( ; ; ) { + for (;;) { if (fc == '-') { if (left) break; @@ -836,7 +836,7 @@ scanflike(hte_t *hte, fcall_t *call, int fp = fmt; fc = *fp++; - for ( ; ; ) { + for (;;) { if (fc == '\0') { if (*ap != NULL) tomanyarg(hte, call);