lint.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 831 行 · 第 1/2 页

C
831
字号
				}			}		/* not there: update entry */		np2->lid = npx->lid;		np2->flgs = npx->flgs;		++np2;		foundit: ;		}	/* all finished: merged list is at np1 */	lnp = np2;	}zecode( n ){	/* n integer words of zeros */	OFFSZ temp;	temp = n;	inoff += temp*SZINT;	;	}andable( p ) NODE *p; {  /* p is a NAME node; can it accept & ? */	register r;	if( p->in.op != NAME ) cerror( "andable error" );	if( (r = p->tn.rval) < 0 ) return(1);  /* labels are andable */	if( stab[r].sclass == AUTO || stab[r].sclass == PARAM ) return(0); #ifndef FLEXNAMES	if( stab[r].sclass == REGISTER ) uerror( "can't take & of %.8s", stab[r].sname );#else	if( stab[r].sclass == REGISTER ) uerror( "can't take & of %s", stab[r].sname );#endif	return(1);	}NODE *clocal(p) NODE *p; {	/* this is called to do local transformations on	   an expression tree preparitory to its being	   written out in intermediate code.	*/	/* the major essential job is rewriting the	   automatic variables and arguments in terms of	   REG and OREG nodes */	/* conversion ops which are not necessary are also clobbered here */	/* in addition, any special features (such as rewriting	   exclusive or) are easily handled here as well */	register o;	register unsigned t, tl;	switch( o = p->in.op ){	case SCONV:	case PCONV:		if( p->in.left->in.type==ENUMTY ){			p->in.left = pconvert( p->in.left );			}		/* assume conversion takes place; type is inherited */		t = p->in.type;		tl = p->in.left->in.type;		if( aflag && (tl==LONG||tl==ULONG) && (t!=LONG&&t!=ULONG) ){			werror( "long assignment may lose accuracy" );			}		if( aflag>=2 && (tl!=LONG&&tl!=ULONG) && (t==LONG||t==ULONG) && p->in.left->in.op != ICON ){			werror( "assignment to long may sign-extend incorrectly" );			}		if( ISPTR(tl) && ISPTR(t) ){			tl = DECREF(tl);			t = DECREF(t);			switch( ISFTN(t) + ISFTN(tl) ){			case 0:  /* neither is a function pointer */				if( talign(t,p->fn.csiz) > talign(tl,p->in.left->fn.csiz) ){					if( hflag||pflag ) werror( "possible pointer alignment problem" );					}				break;			case 1:				werror( "questionable conversion of function pointer" );			case 2:				;				}			}		p->in.left->in.type = p->in.type;		p->in.left->fn.cdim = p->fn.cdim;		p->in.left->fn.csiz = p->fn.csiz;		p->in.op = FREE;		return( p->in.left );	case PVCONV:	case PMCONV:		if( p->in.right->in.op != ICON ) cerror( "bad conversion");		p->in.op = FREE;		return( buildtree( o==PMCONV?MUL:DIV, p->in.left, p->in.right ) );		}	return(p);	}NODE *offcon( off, t, d, s ) OFFSZ off; TWORD t;{  /* make a structure offset node */	register NODE *p;	p = bcon(0);	p->tn.lval = off/SZCHAR;	return(p);	}noinit(){	/* storage class for such as "int a;" */	return( pflag ? EXTDEF : EXTERN );	}cinit( p, sz ) NODE *p; { /* initialize p into size sz */	inoff += sz;	if( p->in.op == INIT ){		if( p->in.left->in.op == ICON ) return;		if( p->in.left->in.op == NAME && p->in.left->in.type == MOE ) return;		}	uerror( "illegal initialization" );	}char *strip(s) char *s; {#ifndef FLEXNAMES	static char x[LFNM+1];#else	static char x[BUFSIZ];#endif	register char *p;	static	int	stripping = 0;	if (stripping)		return(s);	stripping++;	for( p=x; *s; ++s ){		if( *s != '"' ){#ifndef FLEXNAMES/* PATCHED by ROBERT HENRY on 8Jul80 to fix 14 character file name bug */			if( p >= &x[LFNM] )#else			if( p >= &x[BUFSIZ] )#endif				cerror( "filename too long" );			*p++ = *s;		}	}	stripping = 0;	*p = '\0';#ifndef FLEXNAMES	return( x );#else	return( hash(x) );#endif	}fsave( s ) char *s; {	static union rec fsname;	s = strip( s );#ifndef FLEXNAMES	if( strncmp( s, fsname.f.fn, LFNM ) ){#else	if (fsname.f.fn == NULL || strcmp(s, fsname.f.fn)) {#endif		/* new one */#ifndef FLEXNAMES		strncpy( fsname.f.fn, s, LFNM );#else		fsname.f.fn = s;#endif		fsname.f.decflag = LFN;		fwrite( (char *)&fsname, sizeof(fsname), 1, stdout );#ifdef FLEXNAMES		/* if generating a library, prefix with the library name */		/* only do this for flexnames */		if( libname ){			fwrite( libname, strlen(libname), 1, stdout );			putchar( ':' );			}		fwrite( fsname.f.fn, strlen(fsname.f.fn)+1, 1, stdout );#endif		}	}where(f){ /* print true location of error */	if( f == 'u' && nerrors > 1 )		--nerrors; /* don't get "too many errors" */	fprintf( stderr, "%s(%d): ", strip(ftitle), lineno);	}	/* a number of dummy routines, unneeded by lint */branch(n){;}defalign(n){;}deflab(n){;}bycode(t,i){;}cisreg(t) TWORD t; {return(1);}  /* everyting is a register variable! */fldty(p) struct symtab *p; {	; /* all types are OK here... */	}fldal(t) unsigned t; { /* field alignment... */	if( t == ENUMTY ) return( ALCHAR );  /* this should be thought through better... */	if( ISPTR(t) ){ /* really for the benefit of honeywell (and someday IBM) */		if( pflag ) uerror( "nonportable field type" );		}	else uerror( "illegal field type" );	return(ALINT);	}main( argc, argv ) char *argv[]; {	/* definitions for CXREF */	char *p, *cp;	int n = 1;	/* handle options */	for( p=argv[1]; n < argc && *p == '-'; p = argv[++n]){		switch( *++p ){		/* the next bunch of cases are for CXREF */		case 'd':			++ddebug;			continue;		case 'I':			++idebug;			continue;		case 'b':			++bdebug;			continue;		case 't':			++tdebug;			continue;		case 'e':			++edebug;			continue;		case 'x':			++xdebug;			continue;		case 'f':	/* filename sent to cpp */			p = argv[++n];			infile[0] = '"';	/* put quotes around name */			cp = &infile[1];			while (*cp++ = *p++) ;	/* copy filename */			*--cp = '"';			*++cp = '\0';			continue;		case 'i':	/* actual input filename */			p = argv[++n];			if (freopen(p,"r",stdin) == NULL) {				fprintf(stderr, "Can't open %s\n",p);				exit(1);			}			continue;		case 'o':			p = argv[++n];			if ((outfp = fopen(p,"a")) == NULL) {				fprintf(stderr, "Can't Open %s\n",p);				exit(2);			}			continue;		default:			uerror( "illegal option: %c", *p );			continue;			}		}	if( !pflag ){  /* set sizes to sizes of target machine */# ifdef gcos		SZCHAR = ALCHAR = 9;# else/*		SZCHAR = ALCHAR = 8;	CXREF */# endif/*		SZINT = ALINT = sizeof(int)*SZCHAR;		SZFLOAT = ALFLOAT = sizeof(float)*SZCHAR;		SZDOUBLE = ALDOUBLE = sizeof(double)*SZCHAR;		SZLONG = ALLONG = sizeof(long)*SZCHAR;		SZSHORT = ALSHORT = sizeof(short)*SZCHAR;		SZPOINT = ALPOINT = sizeof(int *)*SZCHAR;		ALSTRUCT = ALINT;	CXREF		*/		/* now, fix some things up for various machines (I wish we had "alignof") */# ifdef pdp11		ALLONG = ALDOUBLE = ALFLOAT = ALINT;#endif# ifdef ibm		ALSTRUCT = ALCHAR;#endif		}	return( mainp1( argc, argv ) );	}ctype( type ) unsigned type; { /* are there any funny types? */	return( type );	}isitfloat ( s ) char *s; {	/* s is a character string;	   if floating point is implemented, set dcon to the value of s */	/* lint version	*/	dcon = atof( s );	return( FCON );	}fldcon( p ) register NODE *p; {	/* p is an assignment of a constant to a field */	/* check to see if the assignment is going to overflow, or otherwise cause trouble */	register s;	CONSZ v;	if( !hflag & !pflag ) return;	s = UPKFSZ(p->in.left->tn.rval);	v = p->in.right->tn.lval;	switch( p->in.left->in.type ){	case CHAR:	case INT:	case SHORT:	case LONG:	case ENUMTY:		if( v>=0 && (v>>(s-1))==0 ) return;		werror( "precision lost in assignment to (possibly sign-extended) field" );	default:		return;	case UNSIGNED:	case UCHAR:	case USHORT:	case ULONG:		if( v<0 || (v>>s)!=0 ) werror( "precision lost in field assignment" );				return;		}	}outdef( p, lty, mode ) struct symtab *p; {	/* output a definition for the second pass */	/* if mode is > USUAL, it is the number of args */	char *fname;	TWORD t;	int line;	static union rec rc;	if( mode == NOFILE ){		fname = "???";		line = p->suse;		}	else if( mode == SVLINE ){		fname = ftitle;		line = -p->suse;		}	else {		fname = ftitle;		line = lineno;		}	fsave( fname );#ifndef FLEXNAMES	strncpy( rc.l.name, exname(p->sname), LCHNM );#endif	rc.l.decflag = lty;	t = p->stype;	if( mode == DECTY ) t = DECREF(t);	rc.l.type.aty = t;	rc.l.type.extra = 0;	rc.l.type.extra1 = 0;	astype( &rc.l.type, p->sizoff );	rc.l.nargs = (mode>USUAL) ? mode : 0;	rc.l.fline = line;	fwrite( (char *)&rc, sizeof(rc), 1, stdout );#ifdef FLEXNAMES	rc.l.name = exname(p->sname);	fwrite( rc.l.name, strlen(rc.l.name)+1, 1, stdout );#endif	}int proflg;int gdebug;bbcode()	/* CXREF */{	/* code for beginning a new block */	blocknos[blockptr] = nextblock++;	fprintf(outfp, "B%d\t%05d\n", blocknos[blockptr], lineno);	blockptr++;}becode()	/* CXREF */{	/* code for ending a block */	if (--blockptr < 0)		uerror("bad nesting");	else		fprintf( outfp, "E%d\t%05d\n", blocknos[blockptr], lineno);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?