externs1.h revision 1.242 1 /* $NetBSD: externs1.h,v 1.242 2025/09/14 11:14:00 rillig Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Jochen Pohl for
18 * The NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <signal.h>
35
36 /* tyname.c */
37 const char *expr_type_name(const tnode_t *);
38
39 /*
40 * main1.c
41 */
42 extern bool Fflag;
43 extern bool Pflag;
44 extern bool Tflag;
45 extern int aflag;
46 extern bool bflag;
47 extern bool cflag;
48 extern bool eflag;
49 extern bool hflag;
50 extern bool pflag;
51 extern bool rflag;
52 extern bool vflag;
53 extern bool wflag;
54 extern bool yflag;
55 extern bool zflag;
56
57 extern bool allow_trad;
58 extern bool allow_c90;
59 extern bool allow_c99;
60 extern bool allow_c11;
61 extern bool allow_c23;
62 extern bool allow_gcc;
63
64 extern sig_atomic_t fpe;
65
66 void norecover(void);
67
68 /*
69 * cgram.y
70 */
71 extern int block_level;
72 extern size_t mem_block_level;
73 extern int yydebug;
74
75 int yyerror(const char *);
76 int yyparse(void);
77 extern char *yytext;
78
79 /*
80 * lex.c
81 */
82 extern bool in_gcc_attribute;
83 extern pos_t curr_pos;
84 extern pos_t csrc_pos;
85 extern bool in_system_header;
86 extern symbol_kind sym_kind;
87 extern FILE *yyin;
88
89 void init_lex(void);
90 int64_t convert_integer(int64_t, tspec_t, unsigned int);
91 void reset_suppressions(void);
92 sym_t *getsym(sbuf_t *);
93 void clean_up_after_error(void);
94 sym_t *pushdown(const sym_t *);
95 sym_t *mktempsym(type_t *);
96 void symtab_remove_forever(sym_t *);
97 void symtab_remove_level(sym_t *);
98 void inssym(int, sym_t *);
99 void freeyyv(void *, int);
100 int yylex(void);
101
102 /*
103 * mem1.c
104 */
105 const char *record_filename(const char *, size_t);
106 int get_filename_id(const char *);
107 void add_directory_replacement(char *);
108 const char *transform_filename(const char *, size_t);
109
110 #ifdef DEBUG_MEM
111 void *block_zero_alloc(size_t, const char *);
112 void *level_zero_alloc(size_t, size_t, const char *);
113 #else
114 void *block_zero_alloc(size_t);
115 void *level_zero_alloc(size_t, size_t);
116 #define block_zero_alloc(size, descr) (block_zero_alloc)(size)
117 #define level_zero_alloc(level, size, descr) (level_zero_alloc)(level, size)
118 #endif
119 void level_free_all(size_t);
120
121 #ifdef DEBUG_MEM
122 void *expr_zero_alloc(size_t, const char *);
123 #else
124 void *expr_zero_alloc(size_t);
125 #define expr_zero_alloc(size, descr) (expr_zero_alloc)(size)
126 #endif
127 tnode_t *expr_alloc_tnode(void);
128 void expr_free_all(void);
129 memory_pool expr_save_memory(void);
130 void expr_restore_memory(memory_pool);
131
132 /*
133 * debug.c
134 */
135
136 #ifdef DEBUG
137 extern bool debug_enabled;
138 const char *decl_level_kind_name(decl_level_kind);
139 const char *scl_name(scl_t);
140 const char *symbol_kind_name(symbol_kind);
141 const char *type_qualifiers_string(type_qualifiers);
142 const char *type_attributes_string(type_attributes);
143 const char *function_specifier_name(function_specifier);
144 const char *named_constant_name(named_constant);
145 void debug_dcs(void);
146 void debug_dcs_all(void);
147 void debug_node(const tnode_t *);
148 void debug_type(const type_t *);
149 void debug_sym(const char *, const sym_t *, const char *);
150 void debug_symtab(void);
151 void debug_printf(const char *fmt, ...) __printflike(1, 2);
152 void debug_skip_indent(void);
153 void debug_indent_inc(void);
154 void debug_indent_dec(void);
155 bool debug_push_indented(bool);
156 void debug_pop_indented(bool);
157 void debug_enter_func(const char *);
158 void debug_step(const char *fmt, ...) __printflike(1, 2);
159 void debug_leave_func(const char *);
160 void debug_attribute_list(const attribute_list *);
161 #define debug_enter() debug_enter_func(__func__)
162 #define debug_leave() debug_leave_func(__func__)
163 #else
164 #define debug_noop() do { } while (false)
165 #define debug_dcs() debug_noop()
166 #define debug_dcs_all() debug_noop()
167 #define debug_sym(p, sym, s) debug_noop()
168 #define debug_symtab() debug_noop()
169 #define debug_node(tn) debug_noop()
170 #define debug_type(tp) debug_noop()
171 #define debug_printf(...) debug_noop()
172 #define debug_skip_indent() debug_noop()
173 #define debug_indent_inc() debug_noop()
174 #define debug_indent_dec() debug_noop()
175 #define debug_push_indented(c) true
176 #define debug_pop_indented(c) (void)(c)
177 #define debug_enter() debug_noop()
178 #define debug_step(...) debug_noop()
179 #define debug_leave() debug_noop()
180 #define debug_attribute_list(list) debug_noop()
181 #endif
182
183 /*
184 * err.c
185 */
186 extern bool seen_error;
187 extern bool seen_warning;
188 extern int sytxerr;
189 extern bool any_query_enabled;
190 extern bool is_query_enabled[];
191
192 void msglist(void);
193 void error_at(int, const pos_t *, ...);
194 void warning_at(int, const pos_t *, ...);
195 void message_at(int, const pos_t *, ...);
196 void error(int, ...);
197 void warning(int, ...);
198 bool gnuism(int, ...);
199 void c99ism(int, ...);
200 void c11ism(int, ...);
201 void c23ism(int, ...);
202 void assert_failed(const char *, int, const char *, const char *) __dead;
203 void update_location(const char *, int, bool, bool);
204 void suppress_messages(const char *);
205
206 void query_message(int, ...);
207 void enable_queries(const char *);
208
209 /*
210 * decl.c
211 */
212 extern decl_level *dcs;
213 extern const char unnamed[];
214 extern int enumval;
215
216 void init_decl(void);
217 type_t *gettyp(tspec_t);
218 type_t *block_dup_type(const type_t *);
219 type_t *expr_dup_type(const type_t *);
220 type_t *expr_unqualified_type(const type_t *);
221 bool is_incomplete(const type_t *);
222 void dcs_add_function_specifier(function_specifier);
223 void dcs_add_storage_class(scl_t);
224 void dcs_add_type(type_t *);
225 void dcs_add_qualifiers(type_qualifiers);
226 void dcs_add_type_attributes(type_attributes);
227 void dcs_add_alignas(tnode_t *);
228 void dcs_add_packed(void);
229 void dcs_set_used(void);
230 void begin_declaration_level(decl_level_kind);
231 void end_declaration_level(void);
232 void dcs_set_asm(void);
233 void dcs_begin_type(void);
234 void dcs_end_type(void);
235 int length_in_bits(const type_t *, const char *);
236 unsigned int alignment(const type_t *);
237 sym_t *concat_symbols(sym_t *, sym_t *);
238 void check_type(sym_t *);
239 sym_t *declare_unnamed_member(void);
240 sym_t *declare_member(sym_t *);
241 sym_t *set_bit_field_width(sym_t *, int);
242 void add_type_qualifiers(type_qualifiers *, type_qualifiers);
243 qual_ptr *append_qualified_pointer(qual_ptr *, qual_ptr *);
244 sym_t *add_pointer(sym_t *, qual_ptr *);
245 sym_t *add_array(sym_t *, bool, int);
246 sym_t *add_function(sym_t *, parameter_list);
247 void check_extern_declaration(const sym_t *);
248 void check_function_definition(sym_t *, bool);
249 sym_t *declarator_name(sym_t *);
250 sym_t *old_style_function_parameter_name(sym_t *);
251 type_t *make_tag_type(sym_t *, tspec_t, bool, bool);
252 type_t *complete_struct_or_union(sym_t *);
253 type_t *complete_enum(sym_t *);
254 sym_t *enumeration_constant(sym_t *, int, bool);
255 void declare(sym_t *, bool, sbuf_t *);
256 void copy_usage_info(sym_t *, const sym_t *);
257 bool check_redeclaration(sym_t *, bool *);
258 bool pointer_types_are_compatible(const type_t *, const type_t *, bool);
259 bool types_compatible(const type_t *, const type_t *, bool, bool, bool *);
260 void complete_type(sym_t *, const sym_t *);
261 sym_t *declare_parameter(sym_t *, bool);
262 void check_func_lint_directives(void);
263 void check_func_old_style_parameters(void);
264
265 void declare_local(sym_t *, bool);
266 sym_t *abstract_name(void);
267 sym_t *abstract_enclosing_name(void);
268 void global_clean_up(void);
269 sym_t *declare_abstract_type(sym_t *);
270 void check_size(const sym_t *);
271 void mark_as_set(sym_t *);
272 void mark_as_used(sym_t *, bool, bool);
273 void check_usage(const decl_level *);
274 void check_usage_sym(bool, const sym_t *);
275 void end_translation_unit(void);
276 void print_previous_declaration(const sym_t *);
277 int to_int_constant(tnode_t *, bool);
278
279 /*
280 * tree.c
281 */
282 const tnode_t *before_conversion(const tnode_t *);
283 type_t *block_derive_type(type_t *, tspec_t);
284 type_t *expr_derive_type(type_t *, tspec_t);
285 bool is_compiler_builtin(const char *);
286 tnode_t *build_constant(type_t *, val_t *);
287 tnode_t *build_name(sym_t *, bool);
288 tnode_t *build_string(buffer *);
289 tnode_t *build_generic_selection(const tnode_t *,
290 struct generic_association *);
291
292 tnode_t *build_binary(tnode_t *, op_t, bool, tnode_t *);
293 tnode_t *build_unary(op_t, bool, tnode_t *);
294 tnode_t *build_member_access(tnode_t *, op_t, bool, sbuf_t *);
295 tnode_t *cconv(tnode_t *);
296 bool is_typeok_bool_compares_with_zero(const tnode_t *, bool);
297 bool typeok(op_t, const function_call *, int,
298 const tnode_t *, const tnode_t *);
299 tnode_t *promote(op_t, bool, tnode_t *);
300 tnode_t *convert(op_t, int, type_t *, tnode_t *);
301 void convert_constant(op_t, int, const type_t *, val_t *, val_t *);
302 tnode_t *build_sizeof(const type_t *);
303 tnode_t *build_offsetof(const type_t *, designation);
304 tnode_t *build_alignof(const type_t *);
305 tnode_t *cast(tnode_t *, bool, type_t *);
306 void add_function_argument(function_call *, tnode_t *);
307 tnode_t *build_function_call(tnode_t *, bool, function_call *);
308 val_t *integer_constant(tnode_t *, bool);
309 void expr(tnode_t *, bool, bool, bool, bool, const char *);
310 void check_expr_misc(const tnode_t *, bool, bool, bool, bool, bool, bool);
311 bool constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *);
312 buffer *cat_strings(buffer *, buffer *);
313 unsigned int type_size_in_bits(const type_t *);
314 sym_t *find_member(const struct_or_union *, const char *);
315 uint64_t possible_bits(const tnode_t *);
316 bool attributes_contain(const attribute_list *, const char *);
317
318 void begin_statement_expr(void);
319 void do_statement_expr(tnode_t *);
320 tnode_t *end_statement_expr(void);
321 bool in_statement_expr(void);
322
323 /*
324 * func.c
325 */
326 extern sym_t *funcsym;
327 extern bool reached;
328 extern bool warn_about_unreachable;
329 extern bool suppress_fallthrough;
330 extern int nargusg;
331 extern pos_t argsused_pos;
332 extern int nvararg;
333 extern pos_t vapos;
334 extern int printflike_argnum;
335 extern pos_t printflike_pos;
336 extern int scanflike_argnum;
337 extern pos_t scanflike_pos;
338 extern bool llibflg;
339 extern int lwarn;
340 extern bool suppress_bitfieldtype;
341 extern bool plibflg;
342 extern bool suppress_longlong;
343
344 void begin_control_statement(control_statement_kind);
345 void end_control_statement(control_statement_kind);
346 void check_statement_reachable(const char *);
347 void begin_function(sym_t *);
348 void end_function(void);
349 void named_label(sym_t *);
350 void case_label(tnode_t *);
351 void default_label(void);
352 void stmt_if_expr(tnode_t *);
353 void stmt_if_then_stmt(void);
354 void stmt_if_else_stmt(bool);
355 void stmt_switch_expr(tnode_t *);
356 void stmt_switch_expr_stmt(void);
357 void stmt_while_expr(tnode_t *);
358 void stmt_while_expr_stmt(void);
359 void stmt_do(void);
360 void stmt_do_while_expr(tnode_t *);
361 void stmt_for_exprs(tnode_t *, tnode_t *, tnode_t *);
362 void stmt_for_exprs_stmt(void);
363 void stmt_goto(sym_t *);
364 void stmt_continue(void);
365 void stmt_break(void);
366 void stmt_return(bool, tnode_t *);
367 void stmt_call_noreturn(void);
368 void global_clean_up_decl(bool);
369 void handle_lint_comment(lint_comment, int);
370
371 /*
372 * init.c
373 */
374 void begin_initialization(sym_t *);
375 void end_initialization(void);
376 sym_t *current_initsym(void);
377
378 void init_rbrace(void);
379 void init_lbrace(void);
380 void init_expr(tnode_t *);
381 void begin_designation(void);
382 void add_designator_member(sbuf_t *);
383 void add_designator_subscript(range_t);
384 void designation_push(designation *, designator_kind, const sym_t *, size_t);
385
386 /*
387 * emit.c
388 */
389 void outtype(const type_t *);
390 void outsym(const sym_t *, scl_t, def_t);
391 void outfdef(const sym_t *, const pos_t *, bool, bool, const sym_t *);
392 void outcall(const tnode_t *, bool, bool);
393 void outusg(const sym_t *);
394
395 /*
396 * lex.c
397 */
398 void lex_pp_begin(void);
399 void lex_pp_identifier(const char *);
400 void lex_pp_number(const char *);
401 void lex_pp_character_constant(void);
402 void lex_pp_string_literal(void);
403 void lex_pp_punctuator(const char *);
404 void lex_pp_comment(void);
405 void lex_pp_whitespace(void);
406 void lex_pp_end(void);
407 int lex_name(const char *, size_t);
408 int lex_integer_constant(const char *, size_t, int);
409 int lex_floating_constant(const char *, size_t);
410 int lex_operator(int, op_t);
411 int lex_string(void);
412 int lex_wide_string(void);
413 int lex_character_constant(void);
414 int lex_wide_character_constant(void);
415 void lex_next_line(void);
416 void lex_comment(void);
417 void lex_slash_slash_comment(void);
418 void lex_unknown_character(int);
419 int lex_input(void);
420 bool quoted_next(const buffer *, quoted_iterator *);
421 balanced_token_sequence lex_balanced(void);
422
423 /*
424 * ckbool.c
425 */
426 bool typeok_scalar_strict_bool(op_t, const mod_t *, int,
427 const tnode_t *, const tnode_t *);
428 bool fallback_symbol_strict_bool(sym_t *);
429
430 /*
431 * ckctype.c
432 */
433 void check_ctype_function_call(const function_call *);
434 void check_ctype_macro_invocation(const tnode_t *, const tnode_t *);
435
436 /*
437 * ckgetopt.c
438 */
439 void check_getopt_begin_while(const tnode_t *);
440 void check_getopt_begin_switch(void);
441 void check_getopt_case_label(int64_t);
442 void check_getopt_end_switch(void);
443 void check_getopt_end_while(void);
444
445 /* cksnprintb.c */
446 void check_snprintb(const function_call *);
447