Home | History | Annotate | Line # | Download | only in lint2
lint2.h revision 1.1
      1  1.1  cgd /*
      2  1.1  cgd  * Copyright (c) 1994, 1995 Jochen Pohl
      3  1.1  cgd  * All Rights Reserved.
      4  1.1  cgd  *
      5  1.1  cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1  cgd  * modification, are permitted provided that the following conditions
      7  1.1  cgd  * are met:
      8  1.1  cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1  cgd  *    must display the following acknowledgement:
     15  1.1  cgd  *      This product includes software developed by Jochen Pohl for
     16  1.1  cgd  *	The NetBSD Project.
     17  1.1  cgd  * 4. The name of the author may not be used to endorse or promote products
     18  1.1  cgd  *    derived from this software without specific prior written permission.
     19  1.1  cgd  *
     20  1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  cgd  *
     31  1.1  cgd  *	$Id: lint2.h,v 1.1 1995/07/03 20:56:38 cgd Exp $
     32  1.1  cgd  */
     33  1.1  cgd 
     34  1.1  cgd #include "lint.h"
     35  1.1  cgd 
     36  1.1  cgd /*
     37  1.1  cgd  * Types are described by structures of type type_t.
     38  1.1  cgd  */
     39  1.1  cgd typedef	struct type {
     40  1.1  cgd 	tspec_t	t_tspec;	/* type specifier */
     41  1.1  cgd 	u_int	t_const : 1;	/* constant */
     42  1.1  cgd 	u_int	t_volatile : 1;	/* volatile */
     43  1.1  cgd 	u_int	t_vararg : 1;	/* function has variable number of arguments */
     44  1.1  cgd 	u_int	t_isenum : 1;	/* enum type */
     45  1.1  cgd 	u_int	t_proto : 1;	/* this is a prototype */
     46  1.1  cgd 	u_int	t_istag : 1;	/* tag with _t_tag valid */
     47  1.1  cgd 	u_int	t_istynam : 1;	/* tag with _t_tynam valid */
     48  1.1  cgd 	union {
     49  1.1  cgd 		int	_t_dim;		/* if the type is an ARRAY than this
     50  1.1  cgd 					   is the dimension of the array. */
     51  1.1  cgd 		struct	hte *_t_tag;	/* hash table entry of tag if
     52  1.1  cgd 					   t_isenum, STRUCT or UNION */
     53  1.1  cgd 		struct	hte *_t_tynam;	/* hash table entry of typename if
     54  1.1  cgd 					   t_isenum, STRUCT or UNION */
     55  1.1  cgd 		struct	type **_t_args;	/* list of argument types if this
     56  1.1  cgd 					   is a prototype */
     57  1.1  cgd 	} t_u;
     58  1.1  cgd 	struct	type *t_subt;	/* indirected type (array element, pointed to
     59  1.1  cgd 				   type, type of return value) */
     60  1.1  cgd } type_t;
     61  1.1  cgd 
     62  1.1  cgd #define	t_dim	t_u._t_dim
     63  1.1  cgd #define	t_tag	t_u._t_tag
     64  1.1  cgd #define t_tynam	t_u._t_tynam
     65  1.1  cgd #define	t_args	t_u._t_args
     66  1.1  cgd 
     67  1.1  cgd /*
     68  1.1  cgd  * argument information
     69  1.1  cgd  *
     70  1.1  cgd  * Such a structure is created for each argument of a function call
     71  1.1  cgd  * which is an integer constant or a constant string.
     72  1.1  cgd  */
     73  1.1  cgd typedef	struct arginf {
     74  1.1  cgd 	int	a_num;		/* # of argument (1..) */
     75  1.1  cgd 	u_int	a_zero : 1;	/* argument is 0 */
     76  1.1  cgd 	u_int	a_pcon : 1;	/* msb of argument is not set */
     77  1.1  cgd 	u_int	a_ncon : 1;	/* msb of argument is set */
     78  1.1  cgd 	u_int	a_fmt : 1;	/* a_fstrg points to format string */
     79  1.1  cgd 	char	*a_fstrg;	/* format string */
     80  1.1  cgd 	struct	arginf *a_nxt;	/* information for next const. argument */
     81  1.1  cgd } arginf_t;
     82  1.1  cgd 
     83  1.1  cgd /*
     84  1.1  cgd  * Keeps information about position in source file.
     85  1.1  cgd  */
     86  1.1  cgd typedef	struct {
     87  1.1  cgd 	u_short	p_src;		/* index of name of translation unit
     88  1.1  cgd 				   (the name which was specified at the
     89  1.1  cgd 				   command line) */
     90  1.1  cgd 	u_short	p_line;		/* line number in p_src */
     91  1.1  cgd 	u_short	p_isrc;		/* index of (included) file */
     92  1.1  cgd 	u_short p_iline;	/* line number in p_iline */
     93  1.1  cgd } pos_t;
     94  1.1  cgd 
     95  1.1  cgd /*
     96  1.1  cgd  * Used for definitions and declarations
     97  1.1  cgd  *
     98  1.1  cgd  * To save memory, variable sized structures are used. If
     99  1.1  cgd  * all s_va, s_prfl and s_scfl are not set, the memory allocated
    100  1.1  cgd  * for a symbol is only large enough to keep the first member of
    101  1.1  cgd  * struct sym, s_s.
    102  1.1  cgd  */
    103  1.1  cgd typedef	struct sym {
    104  1.1  cgd 	struct {
    105  1.1  cgd 		pos_t	s_pos;		/* pos of def./decl. */
    106  1.1  cgd #ifndef lint
    107  1.1  cgd 		u_int	s_def : 3;	/* DECL, TDEF or DEF */
    108  1.1  cgd #else
    109  1.1  cgd 		def_t	s_def;
    110  1.1  cgd #endif
    111  1.1  cgd 		u_int	s_rval : 1;	/* function has return value */
    112  1.1  cgd 		u_int	s_osdef : 1;	/* old style function definition */
    113  1.1  cgd 		u_int	s_static : 1;	/* symbol is static */
    114  1.1  cgd 		u_int	s_va : 1;	/* check only first s_nva arguments */
    115  1.1  cgd 		u_int	s_prfl : 1;	/* printflike */
    116  1.1  cgd 		u_int	s_scfl : 1;	/* scanflike */
    117  1.1  cgd 		u_short	s_type;		/* type */
    118  1.1  cgd 		struct	sym *s_nxt;	/* next symbol with same name */
    119  1.1  cgd 	} s_s;
    120  1.1  cgd 	short	s_nva;
    121  1.1  cgd 	short	s_nprfl;
    122  1.1  cgd 	short	s_nscfl;
    123  1.1  cgd } sym_t;
    124  1.1  cgd 
    125  1.1  cgd #define s_pos		s_s.s_pos
    126  1.1  cgd #define s_rval		s_s.s_rval
    127  1.1  cgd #define s_osdef		s_s.s_osdef
    128  1.1  cgd #define s_static	s_s.s_static
    129  1.1  cgd #define s_def		s_s.s_def
    130  1.1  cgd #define s_va		s_s.s_va
    131  1.1  cgd #define s_prfl		s_s.s_prfl
    132  1.1  cgd #define s_scfl		s_s.s_scfl
    133  1.1  cgd #define s_type		s_s.s_type
    134  1.1  cgd #define s_nxt		s_s.s_nxt
    135  1.1  cgd 
    136  1.1  cgd /*
    137  1.1  cgd  * Used to store informations about function calls.
    138  1.1  cgd  */
    139  1.1  cgd typedef	struct fcall {
    140  1.1  cgd 	pos_t	f_pos;		/* position of call */
    141  1.1  cgd 	u_int	f_rused : 1;	/* return value used */
    142  1.1  cgd 	u_int	f_rdisc : 1;	/* return value discarded (casted to void) */
    143  1.1  cgd 	u_short	f_type;		/* types of expected return value and args */
    144  1.1  cgd 	arginf_t *f_args;	/* information about constant arguments */
    145  1.1  cgd 	struct	fcall *f_nxt;	/* next call of same function */
    146  1.1  cgd } fcall_t;
    147  1.1  cgd 
    148  1.1  cgd /*
    149  1.1  cgd  * Used to store information about usage of symbols other
    150  1.1  cgd  * than for function calls.
    151  1.1  cgd  */
    152  1.1  cgd typedef	struct usym {
    153  1.1  cgd 	pos_t	u_pos;		/* position */
    154  1.1  cgd 	struct	usym *u_nxt;	/* next usage */
    155  1.1  cgd } usym_t;
    156  1.1  cgd 
    157  1.1  cgd /*
    158  1.1  cgd  * hash table entry
    159  1.1  cgd  */
    160  1.1  cgd typedef	struct hte {
    161  1.1  cgd 	const	char *h_name;	/* name */
    162  1.1  cgd 	u_int	h_used : 1;	/* symbol is used */
    163  1.1  cgd 	u_int	h_def : 1;	/* symbol is defined */
    164  1.1  cgd 	u_int	h_static : 1;	/* static symbol */
    165  1.1  cgd 	sym_t	*h_syms;	/* declarations and definitions */
    166  1.1  cgd 	sym_t	**h_lsym;	/* points to s_nxt of last decl./def. */
    167  1.1  cgd 	fcall_t	*h_calls;	/* function calls */
    168  1.1  cgd 	fcall_t	**h_lcall;	/* points to f_nxt of last call */
    169  1.1  cgd 	usym_t	*h_usyms;	/* usage info */
    170  1.1  cgd 	usym_t	**h_lusym;	/* points to u_nxt of last usage info */
    171  1.1  cgd 	struct	hte *h_link;	/* next hte with same hash function */
    172  1.1  cgd } hte_t;
    173  1.1  cgd 
    174  1.1  cgd /* maps type indices into pointers to type structs */
    175  1.1  cgd #define TP(idx)		(tlst[idx])
    176  1.1  cgd 
    177  1.1  cgd #include "externs2.h"
    178