4.1bsd lint additions to catch "if (condition) ;"
Arthur David Olson
ado at elsie.UUCP
Mon Aug 19 11:50:55 AEST 1985
In article <389 at phri.UUCP>, roy at phri.UUCP (Roy Smith) writes:
>
> Here's one that just got me:
>
> if (sv > score); <----- note extraneous semi-colon
> score = sv;
Here are additions to 4.1bsd's "lint" to catch constructs like that above.
Warnings are only produced if lint's "-h" flag is used.
Two files are involved.
In the description below, all code to be added appears between
"#ifndef OLDVERSION" and "#endif" directives.
As usual, the trade secret status of the code precludes a clearer posting.
First, additions to "lint.c". Add this declaration just before the function
"ecode":
#ifndef OLDVERSION
char * gripenull;
#endif
. . .and, as the last statement in "ecode", add this:
#ifndef OLDVERSION
gripenull = 0;
#endif
Second, additions to "cgram.y". Just after the declaration of "fake",
add a declaration of "gripenull":
#ifndef OLDVERSION
extern char * gripenull;
#endif
In the code handling the "ifprefix statement" variant of a "statement"
add this code:
| ifprefix statement
={ deflab($1);
#ifndef OLDVERSION
gripenull = 0;
#endif
In the code handling the "ifelprefix statement" variant of a "statement"
add this code:
| ifelprefix statement
={ if( $1 != NOLAB ){
deflab( $1 );
reached = 1;
}
#ifndef OLDVERSION
gripenull = 0;
#endif
In the code handling the "SM" variant of a "statement" add this code:
| SM
/* #ifndef OLDVERSION */
={
if (hflag && gripenull != 0)
werror(gripenull);
}
/* #endif OLDVERSION */
In the code for "ifprefix"es, add this code:
={ ecomp( buildtree( CBRANCH, $3, bcon( $$=getlab()) ) ) ;
#ifndef OLDVERSION
gripenull = "bodyless if";
#endif
And, finally, in the code for "ifelprefix"es, add this code:
={ if( reached ) branch( $$ = getlab() );
else $$ = NOLAB;
#ifndef OLDVERSION
gripenull = "bodyless else";
#endif
--
Lint is an Oscar Madison trademark.
--
UUCP: ..decvax!seismo!elsie!ado ARPA: elsie!ado at seismo.ARPA
DEC, VAX and Elsie are Digital Equipment and Borden trademarks
More information about the Comp.lang.c
mailing list