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