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