LINTED and CONSTCOND are now valid up to the next end of a

global or local declaration/definition/statement. Originally they were
valid on the current and next line, which made it hard to suppress
warnings in constructs with more then one line.

LONGLONG can now be used to suppress errors or warnings in the next
declaration, definition or statement.
This commit is contained in:
jpo 1995-10-02 17:29:45 +00:00
parent b95167a01a
commit 5888f3bb16
8 changed files with 100 additions and 52 deletions

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: cgram.y,v 1.6 1995/10/02 17:26:52 jpo Exp $ */
/* $NetBSD: cgram.y,v 1.7 1995/10/02 17:29:45 jpo Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -33,7 +33,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: cgram.y,v 1.6 1995/10/02 17:26:52 jpo Exp $";
static char rcsid[] = "$NetBSD: cgram.y,v 1.7 1995/10/02 17:29:45 jpo Exp $";
#endif
#include <stdlib.h>
@ -230,9 +230,11 @@ translation_unit:
ext_decl:
func_def {
glclrlc(0);
clrwflgs();
}
| data_def {
glclrlc(0);
clrwflgs();
}
;
@ -1210,9 +1212,15 @@ opt_stmnt_list:
;
stmnt_list:
stmnt
| stmnt_list stmnt
| stmnt_list error T_SEMI
stmnt {
clrwflgs();
}
| stmnt_list stmnt {
clrwflgs();
}
| stmnt_list error T_SEMI {
clrwflgs();
}
;
expr_stmnt:
@ -1254,12 +1262,14 @@ if_without_else:
if_expr:
T_IF T_LPARN expr T_RPARN {
if1($3);
clrwflgs();
}
;
switch_expr:
T_SWITCH T_LPARN expr T_RPARN {
switch1($3);
clrwflgs();
}
;
@ -1288,6 +1298,7 @@ iteration_stmnt:
while_expr:
T_WHILE T_LPARN expr T_RPARN {
while1($3);
clrwflgs();
}
;
@ -1306,6 +1317,7 @@ do_while_expr:
for_exprs:
T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN {
for1($3, $5, $7);
clrwflgs();
}
;
@ -1357,8 +1369,12 @@ read_until_rparn:
;
declaration_list:
declaration
| declaration_list declaration
declaration {
clrwflgs();
}
| declaration_list declaration {
clrwflgs();
}
;
constant:

View File

@ -1,4 +1,4 @@
/* $NetBSD: decl.c,v 1.8 1995/10/02 17:26:54 jpo Exp $ */
/* $NetBSD: decl.c,v 1.9 1995/10/02 17:29:48 jpo Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -32,7 +32,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: decl.c,v 1.8 1995/10/02 17:26:54 jpo Exp $";
static char rcsid[] = "$NetBSD: decl.c,v 1.9 1995/10/02 17:29:48 jpo Exp $";
#endif
#include <sys/param.h>
@ -380,8 +380,9 @@ addtype(tp)
/* "long long" or "long ... long" */
t = QUAD;
dcs->d_lmod = NOTSPEC;
/* %s C does not support 'long long' */
(void)gnuism(265, tflag ? "traditional" : "ANSI");
if (!quadflg)
/* %s C does not support 'long long' */
(void)gnuism(265, tflag ? "traditional" : "ANSI");
}
if (dcs->d_type != NULL && dcs->d_type->t_typedef) {
@ -2797,16 +2798,16 @@ chkusage(syms)
sym_t *syms;
{
sym_t *sym;
int tmpll;
int mknowarn;
/* for this warnings LINTED has no effect */
tmpll = lline;
lline = -1;
mknowarn = nowarn;
nowarn = 0;
for (sym = syms; sym != NULL; sym = sym->s_dlnxt)
chkusg1(sym);
lline = tmpll;
nowarn = mknowarn;
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.6 1995/10/02 17:22:48 jpo Exp $ */
/* $NetBSD: err.c,v 1.7 1995/10/02 17:29:49 jpo Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -32,7 +32,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: err.c,v 1.6 1995/10/02 17:22:48 jpo Exp $";
static char rcsid[] = "$NetBSD: err.c,v 1.7 1995/10/02 17:29:49 jpo Exp $";
#endif
/* number of errors found */
@ -412,7 +412,7 @@ vwarning(n, ap)
{
const char *fn;
if (lline == isrcline || lline + 1 == isrcline)
if (nowarn)
/* this warning is suppressed by a LINTED comment */
return;

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs1.h,v 1.5 1995/10/02 17:26:55 jpo Exp $ */
/* $NetBSD: externs1.h,v 1.6 1995/10/02 17:29:52 jpo Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -68,7 +68,6 @@ extern int yyparse __P((void));
*/
extern pos_t curr_pos;
extern pos_t csrc_pos;
extern int isrcline;
extern symt_t symtyp;
extern FILE *yyin;
extern u_quad_t qbmasks[], qlmasks[], qumasks[];
@ -77,6 +76,7 @@ extern void initscan __P((void));
extern int sign __P((quad_t, tspec_t, int));
extern int msb __P((quad_t, tspec_t, int));
extern quad_t xsign __P((quad_t, tspec_t, int));
extern void clrwflgs __P((void));
extern sym_t *getsym __P((sbuf_t *));
extern void cleanup __P((void));
extern sym_t *pushdown __P((sym_t *));
@ -217,10 +217,11 @@ extern int prflstrg;
extern pos_t prflpos;
extern int scflstrg;
extern pos_t scflpos;
extern int ccline;
extern int ccflg;
extern int llibflg;
extern int lline;
extern int nowarn;
extern int plibflg;
extern int quadflg;
extern void pushctrl __P((int));
extern void popctrl __P((int));
@ -254,6 +255,7 @@ extern void varargs __P((int));
extern void printflike __P((int));
extern void scanflike __P((int));
extern void protolib __P((int));
extern void longlong __P((int));
/*
* init.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: func.c,v 1.5 1995/10/02 17:21:35 jpo Exp $ */
/* $NetBSD: func.c,v 1.6 1995/10/02 17:29:53 jpo Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -32,7 +32,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: func.c,v 1.5 1995/10/02 17:21:35 jpo Exp $";
static char rcsid[] = "$NetBSD: func.c,v 1.6 1995/10/02 17:29:53 jpo Exp $";
#endif
#include <stdlib.h>
@ -111,11 +111,10 @@ pos_t scflpos;
int plibflg;
/*
* Absolute line number of last CONSTCOND comment. A warning is suppressed
* at this and the following line.
* (An absolute line number is the number of the line in the .i file)
* Nonzero means that no warnings about constands in conditional
* context are printed.
*/
int ccline = -1;
int ccflg;
/*
* llibflg is set if a lint library shall be created. The effect of
@ -125,10 +124,15 @@ int ccline = -1;
int llibflg;
/*
* Contains the absolute line number (lint in .i file) of last LINTED
* comment. All warnings at this and the following line are suppressed.
* Nonzero if warnings are suppressed by a LINTED directive
*/
int lline = -1;
int nowarn;
/*
* Nonzero if complaints about use of "long long" are suppressed in
* the next statement or declaration.
*/
int quadflg;
/*
* Puts a new element at the top of the stack used for control statements.
@ -1016,15 +1020,15 @@ doreturn(tn)
* definitions/declarations.
*/
void
glclrlc(nowarn)
int nowarn;
glclrlc(silent)
int silent;
{
pos_t cpos;
STRUCT_ASSIGN(cpos, curr_pos);
if (nargusg != -1) {
if (!nowarn) {
if (!silent) {
STRUCT_ASSIGN(curr_pos, aupos);
/* must precede function definition: %s */
warning(282, "ARGSUSED");
@ -1032,7 +1036,7 @@ glclrlc(nowarn)
nargusg = -1;
}
if (nvararg != -1) {
if (!nowarn) {
if (!silent) {
STRUCT_ASSIGN(curr_pos, vapos);
/* must precede function definition: %s */
warning(282, "VARARGS");
@ -1040,7 +1044,7 @@ glclrlc(nowarn)
nvararg = -1;
}
if (prflstrg != -1) {
if (!nowarn) {
if (!silent) {
STRUCT_ASSIGN(curr_pos, prflpos);
/* must precede function definition: %s */
warning(282, "PRINTFLIKE");
@ -1048,7 +1052,7 @@ glclrlc(nowarn)
prflstrg = -1;
}
if (scflstrg != -1) {
if (!nowarn) {
if (!silent) {
STRUCT_ASSIGN(curr_pos, scflpos);
/* must precede function definition: %s */
warning(282, "SCANFLIKE");
@ -1172,7 +1176,7 @@ void
constcond(n)
int n;
{
ccline = isrcline;
ccflg = 1;
}
/*
@ -1222,7 +1226,7 @@ void
linted(n)
int n;
{
lline = isrcline;
nowarn = 1;
}
/*
@ -1241,3 +1245,15 @@ protolib(n)
}
plibflg = n == 0 ? 0 : 1;
}
/*
* Set quadflg to nonzero which means that the next statement/declaration
* may use "long long" without an error or warning.
*/
/* ARGSUSED */
void
longlong(n)
int n;
{
quadflg = 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: main1.c,v 1.2 1995/07/03 21:24:22 cgd Exp $ */
/* $NetBSD: main1.c,v 1.3 1995/10/02 17:29:56 jpo Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -32,7 +32,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: main1.c,v 1.2 1995/07/03 21:24:22 cgd Exp $";
static char rcsid[] = "$NetBSD: main1.c,v 1.3 1995/10/02 17:29:56 jpo Exp $";
#endif
#include <stdio.h>
@ -158,7 +158,7 @@ main(argc, argv)
yyparse();
/* Following warnings cannot be suppressed by LINTED */
lline = -1;
nowarn = 0;
chkglsyms();

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: scan.l,v 1.6 1995/10/02 17:26:57 jpo Exp $ */
/* $NetBSD: scan.l,v 1.7 1995/10/02 17:29:59 jpo Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -33,7 +33,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: scan.l,v 1.6 1995/10/02 17:26:57 jpo Exp $";
static char rcsid[] = "$NetBSD: scan.l,v 1.7 1995/10/02 17:29:59 jpo Exp $";
#endif
#include <stdlib.h>
@ -62,9 +62,6 @@ pos_t curr_pos = { 1, "" };
*/
pos_t csrc_pos = { 1, "" };
/* Line number in output of cpp */
int isrcline = 1;
static void incline __P((void));
static void badchar __P((int));
static sbuf_t *allocsb __P((void));
@ -165,7 +162,6 @@ static void
incline()
{
curr_pos.p_line++;
isrcline++;
if (curr_pos.p_file == csrc_pos.p_file)
csrc_pos.p_line++;
}
@ -996,6 +992,7 @@ directive()
* FALLTHRU FALLTHROUGH
* LINTLIBRARY
* LINTED NOSTRICT
* LONGLONG
* NOTREACHED
* PRINTFLIKEn
* PROTOLIB
@ -1021,6 +1018,7 @@ comment()
{ "FALLTHROUGH", 0, fallthru },
{ "LINTLIBRARY", 0, lintlib },
{ "LINTED", 0, linted },
{ "LONGLONG", 0, longlong },
{ "NOSTRICT", 0, linted },
{ "NOTREACHED", 0, notreach },
{ "PRINTFLIKE", 1, printflike },
@ -1101,6 +1099,21 @@ comment()
}
}
/*
* Clear flags for lint comments LINTED, LONGLONG and CONSTCOND.
* clrwflgs() is called after function definitions and global and
* local declarations and definitions. It is also called between
* the controlling expression and the body of control statements
* (if, switch, for, while).
*/
void
clrwflgs()
{
nowarn = 0;
quadflg = 0;
ccflg = 0;
}
/*
* Strings are stored in a dynamically alloceted buffer and passed
* in yylval.y_xstrg to the parser. The parser or the routines called

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.7 1995/10/02 17:22:51 jpo Exp $ */
/* $NetBSD: tree.c,v 1.8 1995/10/02 17:30:04 jpo Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -32,7 +32,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: tree.c,v 1.7 1995/10/02 17:22:51 jpo Exp $";
static char rcsid[] = "$NetBSD: tree.c,v 1.8 1995/10/02 17:30:04 jpo Exp $";
#endif
#include <stdlib.h>
@ -685,7 +685,7 @@ build(op, ln, rn)
if (mp->m_tctx) {
if (ln->tn_op == CON ||
((mp->m_binary && op != QUEST) && rn->tn_op == CON)) {
if (hflag && isrcline > ccline + 1)
if (hflag && !ccflg)
/* constant in conditional context */
warning(161);
}
@ -3358,7 +3358,7 @@ expr(tn, vctx, tctx)
/* assignment in conditional context */
warning(159);
} else if (tn->tn_op == CON) {
if (hflag && tctx && isrcline > ccline + 1)
if (hflag && tctx && !ccflg)
/* constant in conditional context */
warning(161);
}