191586Smarkm/* $NetBSD: lint2.h,v 1.5 2000/06/14 06:49:23 cgd Exp $ */
212099Sjoerg
312099Sjoerg/*
491586Smarkm * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
512099Sjoerg * Copyright (c) 1994, 1995 Jochen Pohl
612099Sjoerg * All Rights Reserved.
712099Sjoerg *
812099Sjoerg * Redistribution and use in source and binary forms, with or without
912099Sjoerg * modification, are permitted provided that the following conditions
1012099Sjoerg * are met:
1112099Sjoerg * 1. Redistributions of source code must retain the above copyright
1212099Sjoerg *    notice, this list of conditions and the following disclaimer.
1312099Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1412099Sjoerg *    notice, this list of conditions and the following disclaimer in the
1512099Sjoerg *    documentation and/or other materials provided with the distribution.
1612099Sjoerg * 3. All advertising materials mentioning features or use of this software
1712099Sjoerg *    must display the following acknowledgement:
1812099Sjoerg *      This product includes software developed by Jochen Pohl for
1912099Sjoerg *	The NetBSD Project.
2012099Sjoerg * 4. The name of the author may not be used to endorse or promote products
2112099Sjoerg *    derived from this software without specific prior written permission.
2212099Sjoerg *
2312099Sjoerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2412099Sjoerg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2512099Sjoerg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2612099Sjoerg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2712099Sjoerg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2812099Sjoerg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2912099Sjoerg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3012099Sjoerg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3112099Sjoerg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3212099Sjoerg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3312099Sjoerg */
3412099Sjoerg
3512099Sjoerg#include "lint.h"
3612099Sjoerg
3712099Sjoerg/*
3812099Sjoerg * Types are described by structures of type type_t.
3912099Sjoerg */
4012099Sjoergtypedef	struct type {
4112099Sjoerg	tspec_t	t_tspec;	/* type specifier */
4212099Sjoerg	u_int	t_const : 1;	/* constant */
4312099Sjoerg	u_int	t_volatile : 1;	/* volatile */
4412099Sjoerg	u_int	t_vararg : 1;	/* function has variable number of arguments */
4512099Sjoerg	u_int	t_isenum : 1;	/* enum type */
4612099Sjoerg	u_int	t_proto : 1;	/* this is a prototype */
4712099Sjoerg	u_int	t_istag : 1;	/* tag with _t_tag valid */
4812099Sjoerg	u_int	t_istynam : 1;	/* tag with _t_tynam valid */
4991586Smarkm	u_int	t_isuniqpos : 1; /* tag with _t_uniqpos valid */
5012099Sjoerg	union {
5112099Sjoerg		int	_t_dim;		/* if the type is an ARRAY than this
5212099Sjoerg					   is the dimension of the array. */
5312099Sjoerg		struct	hte *_t_tag;	/* hash table entry of tag if
5412099Sjoerg					   t_isenum, STRUCT or UNION */
5512099Sjoerg		struct	hte *_t_tynam;	/* hash table entry of typename if
5612099Sjoerg					   t_isenum, STRUCT or UNION */
5791586Smarkm		struct {
5891586Smarkm			int p_line;
5991586Smarkm			short p_file;
6091586Smarkm			int p_uniq;
6191586Smarkm		} _t_uniqpos;		/* unique position, for untagged
6291586Smarkm					   untyped STRUCTs, UNIONS, and ENUMs,
6391586Smarkm					   if t_isuniqpos */
6412099Sjoerg		struct	type **_t_args;	/* list of argument types if this
6512099Sjoerg					   is a prototype */
6612099Sjoerg	} t_u;
6712099Sjoerg	struct	type *t_subt;	/* indirected type (array element, pointed to
6812099Sjoerg				   type, type of return value) */
6912099Sjoerg} type_t;
7012099Sjoerg
7191586Smarkm#define	t_dim		t_u._t_dim
7291586Smarkm#define	t_tag		t_u._t_tag
7391586Smarkm#define	t_tynam		t_u._t_tynam
7491586Smarkm#define	t_uniqpos	t_u._t_uniqpos
7591586Smarkm#define	t_args		t_u._t_args
7612099Sjoerg
7712099Sjoerg/*
7812099Sjoerg * argument information
7912099Sjoerg *
8012099Sjoerg * Such a structure is created for each argument of a function call
8112099Sjoerg * which is an integer constant or a constant string.
8212099Sjoerg */
8312099Sjoergtypedef	struct arginf {
8412099Sjoerg	int	a_num;		/* # of argument (1..) */
8512099Sjoerg	u_int	a_zero : 1;	/* argument is 0 */
8612099Sjoerg	u_int	a_pcon : 1;	/* msb of argument is not set */
8712099Sjoerg	u_int	a_ncon : 1;	/* msb of argument is set */
8812099Sjoerg	u_int	a_fmt : 1;	/* a_fstrg points to format string */
8912099Sjoerg	char	*a_fstrg;	/* format string */
9012099Sjoerg	struct	arginf *a_nxt;	/* information for next const. argument */
9112099Sjoerg} arginf_t;
9212099Sjoerg
9312099Sjoerg/*
9412099Sjoerg * Keeps information about position in source file.
9512099Sjoerg */
9612099Sjoergtypedef	struct {
9712099Sjoerg	u_short	p_src;		/* index of name of translation unit
9812099Sjoerg				   (the name which was specified at the
9912099Sjoerg				   command line) */
10012099Sjoerg	u_short	p_line;		/* line number in p_src */
10112099Sjoerg	u_short	p_isrc;		/* index of (included) file */
10212099Sjoerg	u_short p_iline;	/* line number in p_iline */
10391586Smarkm} pos_t;
10412099Sjoerg
10512099Sjoerg/*
10612099Sjoerg * Used for definitions and declarations
10712099Sjoerg *
10812099Sjoerg * To save memory, variable sized structures are used. If
10912099Sjoerg * all s_va, s_prfl and s_scfl are not set, the memory allocated
11012099Sjoerg * for a symbol is only large enough to keep the first member of
11112099Sjoerg * struct sym, s_s.
11212099Sjoerg */
11312099Sjoergtypedef	struct sym {
11412099Sjoerg	struct {
11512099Sjoerg		pos_t	s_pos;		/* pos of def./decl. */
11612099Sjoerg#ifndef lint
11712099Sjoerg		u_int	s_def : 3;	/* DECL, TDEF or DEF */
11812099Sjoerg#else
11912099Sjoerg		def_t	s_def;
12091586Smarkm#endif
12112099Sjoerg		u_int	s_rval : 1;	/* function has return value */
12212099Sjoerg		u_int	s_osdef : 1;	/* old style function definition */
12312099Sjoerg		u_int	s_static : 1;	/* symbol is static */
12412099Sjoerg		u_int	s_va : 1;	/* check only first s_nva arguments */
12512099Sjoerg		u_int	s_prfl : 1;	/* printflike */
12612099Sjoerg		u_int	s_scfl : 1;	/* scanflike */
12712099Sjoerg		u_short	s_type;		/* type */
12812099Sjoerg		struct	sym *s_nxt;	/* next symbol with same name */
12912099Sjoerg	} s_s;
13012099Sjoerg	short	s_nva;
13112099Sjoerg	short	s_nprfl;
13212099Sjoerg	short	s_nscfl;
13312099Sjoerg} sym_t;
13412099Sjoerg
13512099Sjoerg#define s_pos		s_s.s_pos
13612099Sjoerg#define s_rval		s_s.s_rval
13712099Sjoerg#define s_osdef		s_s.s_osdef
13812099Sjoerg#define s_static	s_s.s_static
13912099Sjoerg#define s_def		s_s.s_def
14012099Sjoerg#define s_va		s_s.s_va
14112099Sjoerg#define s_prfl		s_s.s_prfl
14212099Sjoerg#define s_scfl		s_s.s_scfl
14312099Sjoerg#define s_type		s_s.s_type
14412099Sjoerg#define s_nxt		s_s.s_nxt
14512099Sjoerg
14612099Sjoerg/*
14712099Sjoerg * Used to store informations about function calls.
14812099Sjoerg */
14912099Sjoergtypedef	struct fcall {
15012099Sjoerg	pos_t	f_pos;		/* position of call */
15112099Sjoerg	u_int	f_rused : 1;	/* return value used */
15212099Sjoerg	u_int	f_rdisc : 1;	/* return value discarded (casted to void) */
15312099Sjoerg	u_short	f_type;		/* types of expected return value and args */
15412099Sjoerg	arginf_t *f_args;	/* information about constant arguments */
15512099Sjoerg	struct	fcall *f_nxt;	/* next call of same function */
15612099Sjoerg} fcall_t;
15712099Sjoerg
15812099Sjoerg/*
15912099Sjoerg * Used to store information about usage of symbols other
16012099Sjoerg * than for function calls.
16112099Sjoerg */
16212099Sjoergtypedef	struct usym {
16312099Sjoerg	pos_t	u_pos;		/* position */
16412099Sjoerg	struct	usym *u_nxt;	/* next usage */
16512099Sjoerg} usym_t;
16612099Sjoerg
16712099Sjoerg/*
16812099Sjoerg * hash table entry
16912099Sjoerg */
17012099Sjoergtypedef	struct hte {
17112099Sjoerg	const	char *h_name;	/* name */
17212099Sjoerg	u_int	h_used : 1;	/* symbol is used */
17312099Sjoerg	u_int	h_def : 1;	/* symbol is defined */
17412099Sjoerg	u_int	h_static : 1;	/* static symbol */
17512099Sjoerg	sym_t	*h_syms;	/* declarations and definitions */
17612099Sjoerg	sym_t	**h_lsym;	/* points to s_nxt of last decl./def. */
17712099Sjoerg	fcall_t	*h_calls;	/* function calls */
17812099Sjoerg	fcall_t	**h_lcall;	/* points to f_nxt of last call */
17912099Sjoerg	usym_t	*h_usyms;	/* usage info */
18012099Sjoerg	usym_t	**h_lusym;	/* points to u_nxt of last usage info */
18112099Sjoerg	struct	hte *h_link;	/* next hte with same hash function */
18291586Smarkm	struct  hte *h_hte;	/* pointer to other htes (for renames */
18312099Sjoerg} hte_t;
18412099Sjoerg
18512099Sjoerg/* maps type indices into pointers to type structs */
18612099Sjoerg#define TP(idx)		(tlst[idx])
18712099Sjoerg
18812099Sjoerg#include "externs2.h"
189