Exemplo n.º 1
0
const char *
fnnalloc(const char *s, size_t len)
{
	fn_t	*fn;

	static	int	nxt_id = 0;

	if (s == NULL)
		return (NULL);

	if ((fn = srchfn(s, len)) == NULL) {
		if ((fn = malloc(sizeof (fn_t))) == NULL)
			nomem();
		/* Do not used strdup() because string is not NUL-terminated.*/
		if ((fn->fn_name = malloc(len + 1)) == NULL)
			nomem();
		(void)memcpy(fn->fn_name, s, len);
		fn->fn_name[len] = '\0';
		fn->fn_len = len;
		fn->fn_id = nxt_id++;
		fn->fn_nxt = fnames;
		fnames = fn;
		/* Write id of this filename to the output file. */
		outclr();
		outint(fn->fn_id);
		outchar('s');
		outstrg(fn->fn_name);
	}
	return (fn->fn_name);
}
Exemplo n.º 2
0
/*
 * Write a new lint library.
 */
void
outlib(const char *name)
{
	/* Open of output file and initialisation of the output buffer */
	outopen(name);

	/* write name of lint library */
	outsrc(name);

	/* name of lint lib has index 0 */
	outclr();
	outint(0);
	outchar('s');
	outstrg(name);

	/*
	 * print the names of all files references by unnamed
	 * struct/union/enum declarations.
	 */
	outfiles();

	/* write all definitions with external linkage */
	forall(dumpname);

	/* close the output */
	outclose();
}
Exemplo n.º 3
0
static void
outfiles(void)
{
	struct outflist *ofl;
	int i;

	for (ofl = outflist, i = 1; ofl != NULL; ofl = ofl->ofl_next, i++) {
		/* reset output buffer */
		outclr();

		outint(i);
		outchar('s');
		outstrg(fnames[ofl->ofl_num]);
	}
}
Exemplo n.º 4
0
/*
 * Write a definition.
 */
static void
outdef(hte_t *hte, sym_t *sym)
{

	/* reset output buffer */
	outclr();

	/* line number in C source file */
	outint(0);

	/* this is a definition */
	outchar('d');

	/* index of file where symbol was defined and line number of def. */
	outint(0);
	outchar('.');
	outint(0);

	/* flags */
	if (sym->s_va) {
		outchar('v');		/* varargs */
		outint(sym->s_nva);
	}
	if (sym->s_scfl) {
		outchar('S');		/* scanflike */
		outint(sym->s_nscfl);
	}
	if (sym->s_prfl) {
		outchar('P');		/* printflike */
		outint(sym->s_nprfl);
	}
	/* definition or tentative definition */
	outchar(sym->s_def == DEF ? 'd' : 't');
	if (TP(sym->s_type)->t_tspec == FUNC) {
		if (sym->s_rval)
			outchar('r');	/* fkt. has return value */
		if (sym->s_osdef)
			outchar('o');	/* old style definition */
	}
	outchar('u');			/* used (no warning if not used) */

	/* name */
	outname(hte->h_name);

	/* type */
	outtype(TP(sym->s_type));
}
Exemplo n.º 5
0
/*
 * Write a new lint library.
 */
void
outlib(const char *name)
{
	/* Open of output file and initialisation of the output buffer */
	outopen(name);

	/* write name of lint library */
	outsrc(name);

	/* name of lint lib has index 0 */
	outclr();
	outint(0);
	outchar('s');
	outstrg(name);

	/* write all definitions with external linkage */
	forall(dumpname);

	/* close the output */
	outclose();
}
Exemplo n.º 6
0
/*
 * writes a record if sym was used
 */
void
outusg(sym_t *sym)
{
	/* reset buffer */
	outclr();

	/*
	 * line number of .c source, 'u' for used, Id of current
	 * source (.c or .h), and line in current source
	 */
	outint(csrc_pos.p_line);
	outchar('u');
	outint(getfnid(curr_pos.p_file));
	outchar('.');
	outint(curr_pos.p_line);

	/* necessary to delimit both numbers */
	outchar('x');

	/* Den Namen des Symbols ausgeben */
	outname(sym->s_name);
}
Exemplo n.º 7
0
/*
 * write out all information necessary for lint2 to check function
 * calls
 *
 * rvused is set if the return value is used (asigned to a variable)
 * rvdisc is set if the return value is not used and not ignored
 * (casted to void)
 */
void
outcall(tnode_t *tn, int rvused, int rvdisc)
{
	tnode_t	*args, *arg;
	int	narg, n, i;
	int64_t	q;
	tspec_t	t;

	/* reset buffer */
	outclr();

	/*
	 * line number of .c source, 'c' for function call, Id of current
	 * source (.c or .h), and line in current source
	 */
	outint(csrc_pos.p_line);
	outchar('c');
	outint(getfnid(curr_pos.p_file));
	outchar('.');
	outint(curr_pos.p_line);

	/*
	 * flags; 'u' and 'i' must be last to make sure a letter
	 * is between the numeric argument of a flag and the name of
	 * the function
	 */
	narg = 0;
	args = tn->tn_right;
	for (arg = args; arg != NULL; arg = arg->tn_right)
		narg++;
	/* informations about arguments */
	for (n = 1; n <= narg; n++) {
		/* the last argument is the top one in the tree */
		for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
			continue;
		arg = arg->tn_left;
		if (arg->tn_op == CON) {
			if (isityp(t = arg->tn_type->t_tspec)) {
				/*
				 * XXX it would probably be better to
				 * explicitly test the sign
				 */
				if ((q = arg->tn_val->v_quad) == 0) {
					/* zero constant */
					outchar('z');
				} else if (msb(q, t, 0) == 0) {
					/* positive if casted to signed */
					outchar('p');
				} else {
					/* negative if casted to signed */
					outchar('n');
				}
				outint(n);
			}
		} else if (arg->tn_op == AMPER &&
			   arg->tn_left->tn_op == STRING &&
			   arg->tn_left->tn_strg->st_tspec == CHAR) {
			/* constant string, write all format specifiers */
			outchar('s');
			outint(n);
			outfstrg(arg->tn_left->tn_strg);
		}

	}
	/* return value discarded/used/ignored */
	outchar(rvdisc ? 'd' : (rvused ? 'u' : 'i'));

	/* name of the called function */
	outname(tn->tn_left->tn_left->tn_sym->s_name);

	/* types of arguments */
	outchar('f');
	outint(narg);
	for (n = 1; n <= narg; n++) {
		/* the last argument is the top one in the tree */
		for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
			continue;
		outtype(arg->tn_left->tn_type);
	}
	/* expected type of return value */
	outtype(tn->tn_type);
}
Exemplo n.º 8
0
/*
 * write information about function definition
 *
 * this is also done for static functions so we are able to check if
 * they are called with proper argument types
 */
void
outfdef(sym_t *fsym, pos_t *posp, int rval, int osdef, sym_t *args)
{
	int	narg;
	sym_t	*arg;

	/* reset the buffer */
	outclr();

	/*
	 * line number of .c source, 'd' for declaration, Id of current
	 * source (.c or .h), and line in current source
	 *
	 * we are already at the end of the function. If we are in the
	 * .c source, posp->p_line is correct, otherwise csrc_pos.p_line
	 * (for functions defined in header files).
	 */
	if (posp->p_file == csrc_pos.p_file) {
		outint(posp->p_line);
	} else {
		outint(csrc_pos.p_line);
	}
	outchar('d');
	outint(getfnid(posp->p_file));
	outchar('.');
	outint(posp->p_line);

	/* flags */

	/* both SCANFLIKE and PRINTFLIKE imply VARARGS */
	if (prflstrg != -1) {
		nvararg = prflstrg;
	} else if (scflstrg != -1) {
		nvararg = scflstrg;
	}

	if (nvararg != -1) {
		outchar('v');
		outint(nvararg);
	}
	if (scflstrg != -1) {
		outchar('S');
		outint(scflstrg);
	}
	if (prflstrg != -1) {
		outchar('P');
		outint(prflstrg);
	}
	nvararg = prflstrg = scflstrg = -1;

	outchar('d');

	if (rval)
		/* has return value */
		outchar('r');

	if (llibflg)
		/*
		 * mark it as used so lint2 does not complain about
		 * unused symbols in libraries
		 */
		outchar('u');

	if (osdef)
		/* old style function definition */
		outchar('o');

	if (fsym->s_scl == STATIC)
		outchar('s');

	/* name of function */
	outname(fsym->s_name);

	/* renamed name of function, if necessary */
	if (fsym->s_rename) {
		outchar('r');
		outname(fsym->s_rename);
	}

	/* argument types and return value */
	if (osdef) {
		narg = 0;
		for (arg = args; arg != NULL; arg = arg->s_nxt)
			narg++;
		outchar('f');
		outint(narg);
		for (arg = args; arg != NULL; arg = arg->s_nxt)
			outtype(arg->s_type);
		outtype(fsym->s_type->t_subt);
	} else {
		outtype(fsym->s_type);
	}
}
Exemplo n.º 9
0
/*
 * write information about an global declared/defined symbol
 * with storage class extern
 *
 * informations about function definitions are written in outfdef(),
 * not here
 */
void
outsym(sym_t *sym, scl_t sc, def_t def)
{

	/*
	 * Static function declarations must also be written to the output
	 * file. Compatibility of function declarations (for both static
	 * and extern functions) must be checked in lint2. Lint1 can't do
	 * this, especially not, if functions are declared at block level
	 * before their first declaration at level 0.
	 */
	if (sc != EXTERN && !(sc == STATIC && sym->s_type->t_tspec == FUNC))
		return;

	/* reset buffer */
	outclr();

	/*
	 * line number of .c source, 'd' for declaration, Id of current
	 * source (.c or .h), and line in current source.
	 */
	outint(csrc_pos.p_line);
	outchar('d');
	outint(getfnid(sym->s_dpos.p_file));
	outchar('.');
	outint(sym->s_dpos.p_line);

	/* flags */

	switch (def) {
	case DEF:
		/* defined */
		outchar('d');
		break;
	case TDEF:
		/* tentative defined */
		outchar('t');
		break;
	case DECL:
		/* declared */
		outchar('e');
		break;
	default:
		LERROR("outsym()");
	}
	if (llibflg && def != DECL) {
		/*
		 * mark it as used so we get no warnings from lint2 about
		 * unused symbols in libraries.
		 */
		outchar('u');
	}

	if (sc == STATIC)
		outchar('s');

	/* name of the symbol */
	outname(sym->s_name);

	/* renamed name of symbol, if necessary */
	if (sym->s_rename) {
		outchar('r');
		outname(sym->s_rename);
	}

	/* type of the symbol */
	outtype(sym->s_type);
}