1/*	$NetBSD: externs1.h,v 1.229 2024/05/12 18:00:58 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/*
37 * main1.c
38 */
39extern bool Fflag;
40extern bool Pflag;
41extern bool Tflag;
42extern int aflag;
43extern bool bflag;
44extern bool cflag;
45extern bool eflag;
46extern bool hflag;
47extern bool pflag;
48extern bool rflag;
49extern bool vflag;
50extern bool wflag;
51extern bool yflag;
52extern bool zflag;
53
54extern bool allow_trad;
55extern bool allow_c90;
56extern bool allow_c99;
57extern bool allow_c11;
58extern bool allow_c23;
59extern bool allow_gcc;
60
61extern sig_atomic_t fpe;
62
63void norecover(void);
64
65/*
66 * cgram.y
67 */
68extern int block_level;
69extern size_t mem_block_level;
70extern int yydebug;
71
72int yyerror(const char *);
73int yyparse(void);
74extern char *yytext;
75
76/*
77 * lex.c
78 */
79extern bool in_gcc_attribute;
80extern pos_t curr_pos;
81extern pos_t csrc_pos;
82extern bool in_system_header;
83extern symbol_kind sym_kind;
84extern FILE *yyin;
85
86void init_lex(void);
87int64_t convert_integer(int64_t, tspec_t, unsigned int);
88void reset_suppressions(void);
89sym_t *getsym(sbuf_t *);
90void clean_up_after_error(void);
91sym_t *pushdown(const sym_t *);
92sym_t *mktempsym(type_t *);
93void symtab_remove_forever(sym_t *);
94void symtab_remove_level(sym_t *);
95void inssym(int, sym_t *);
96void freeyyv(void *, int);
97int yylex(void);
98
99/*
100 * mem1.c
101 */
102const char *record_filename(const char *, size_t);
103int get_filename_id(const char *);
104void add_directory_replacement(char *);
105const char *transform_filename(const char *, size_t);
106
107#ifdef DEBUG_MEM
108void *block_zero_alloc(size_t, const char *);
109void *level_zero_alloc(size_t, size_t, const char *);
110#else
111void *block_zero_alloc(size_t);
112void *level_zero_alloc(size_t, size_t);
113#define block_zero_alloc(size, descr) (block_zero_alloc)(size)
114#define level_zero_alloc(level, size, descr) (level_zero_alloc)(level, size)
115#endif
116void level_free_all(size_t);
117
118#ifdef DEBUG_MEM
119void *expr_zero_alloc(size_t, const char *);
120#else
121void *expr_zero_alloc(size_t);
122#define expr_zero_alloc(size, descr) (expr_zero_alloc)(size)
123#endif
124tnode_t *expr_alloc_tnode(void);
125void expr_free_all(void);
126memory_pool expr_save_memory(void);
127void expr_restore_memory(memory_pool);
128
129/*
130 * debug.c
131 */
132
133#ifdef DEBUG
134const char *decl_level_kind_name(decl_level_kind);
135const char *scl_name(scl_t);
136const char *symbol_kind_name(symbol_kind);
137const char *type_qualifiers_string(type_qualifiers);
138const char *function_specifier_name(function_specifier);
139const char *named_constant_name(named_constant);
140void debug_dcs(void);
141void debug_dcs_all(void);
142void debug_node(const tnode_t *);
143void debug_type(const type_t *);
144void debug_sym(const char *, const sym_t *, const char *);
145void debug_symtab(void);
146void debug_printf(const char *fmt, ...) __printflike(1, 2);
147void debug_skip_indent(void);
148void debug_indent_inc(void);
149void debug_indent_dec(void);
150bool debug_push_indented(bool);
151void debug_pop_indented(bool);
152void debug_enter_func(const char *);
153void debug_step(const char *fmt, ...) __printflike(1, 2);
154void debug_leave_func(const char *);
155void debug_attribute_list(const attribute_list *);
156#define	debug_enter()		debug_enter_func(__func__)
157#define	debug_leave()		debug_leave_func(__func__)
158#else
159#define	debug_noop()		do { } while (false)
160#define	debug_dcs()		debug_noop()
161#define	debug_dcs_all()		debug_noop()
162#define	debug_sym(p, sym, s)	debug_noop()
163#define	debug_symtab()		debug_noop()
164#define	debug_node(tn)		debug_noop()
165#define	debug_type(tp)		debug_noop()
166#define	debug_printf(...)	debug_noop()
167#define	debug_skip_indent()	debug_noop()
168#define	debug_indent_inc()	debug_noop()
169#define	debug_indent_dec()	debug_noop()
170#define debug_push_indented(c)	true
171#define debug_pop_indented(c)	(void)(c)
172#define	debug_enter()		debug_noop()
173#define	debug_step(...)		debug_noop()
174#define	debug_leave()		debug_noop()
175#define	debug_attribute_list(list) debug_noop()
176#endif
177
178/*
179 * err.c
180 */
181extern bool seen_error;
182extern bool seen_warning;
183extern int sytxerr;
184extern bool any_query_enabled;
185extern bool is_query_enabled[];
186
187void msglist(void);
188void error_at(int, const pos_t *, ...);
189void warning_at(int, const pos_t *, ...);
190void message_at(int, const pos_t *, ...);
191void error(int, ...);
192void warning(int, ...);
193bool gnuism(int, ...);
194void c99ism(int, ...);
195void c11ism(int, ...);
196void c23ism(int, ...);
197void assert_failed(const char *, int, const char *, const char *) __dead;
198void update_location(const char *, int, bool, bool);
199void suppress_messages(const char *);
200
201void query_message(int, ...);
202void enable_queries(const char *);
203
204/*
205 * decl.c
206 */
207extern decl_level *dcs;
208extern const char unnamed[];
209extern int enumval;
210
211void init_decl(void);
212type_t *gettyp(tspec_t);
213type_t *block_dup_type(const type_t *);
214type_t *expr_dup_type(const type_t *);
215type_t *expr_unqualified_type(const type_t *);
216bool is_incomplete(const type_t *);
217void dcs_add_function_specifier(function_specifier);
218void dcs_add_storage_class(scl_t);
219void dcs_add_type(type_t *);
220void dcs_add_qualifiers(type_qualifiers);
221void dcs_add_alignas(tnode_t *);
222void dcs_add_packed(void);
223void dcs_set_used(void);
224void begin_declaration_level(decl_level_kind);
225void end_declaration_level(void);
226void dcs_set_asm(void);
227void dcs_begin_type(void);
228void dcs_end_type(void);
229int length_in_bits(const type_t *, const char *);
230unsigned int alignment(const type_t *);
231sym_t *concat_symbols(sym_t *, sym_t *);
232void check_type(sym_t *);
233sym_t *declare_unnamed_member(void);
234sym_t *declare_member(sym_t *);
235sym_t *set_bit_field_width(sym_t *, int);
236void add_type_qualifiers(type_qualifiers *, type_qualifiers);
237qual_ptr *append_qualified_pointer(qual_ptr *, qual_ptr *);
238sym_t *add_pointer(sym_t *, qual_ptr *);
239sym_t *add_array(sym_t *, bool, int);
240sym_t *add_function(sym_t *, parameter_list);
241void check_extern_declaration(const sym_t *);
242void check_function_definition(sym_t *, bool);
243sym_t *declarator_name(sym_t *);
244sym_t *old_style_function_parameter_name(sym_t *);
245type_t *make_tag_type(sym_t *, tspec_t, bool, bool);
246type_t *complete_struct_or_union(sym_t *);
247type_t *complete_enum(sym_t *);
248sym_t *enumeration_constant(sym_t *, int, bool);
249void declare(sym_t *, bool, sbuf_t *);
250void copy_usage_info(sym_t *, sym_t *);
251bool check_redeclaration(sym_t *, bool *);
252bool pointer_types_are_compatible(const type_t *, const type_t *, bool);
253bool types_compatible(const type_t *, const type_t *, bool, bool, bool *);
254void complete_type(sym_t *, sym_t *);
255sym_t *declare_parameter(sym_t *, bool);
256void check_func_lint_directives(void);
257void check_func_old_style_parameters(void);
258
259void declare_local(sym_t *, bool);
260sym_t *abstract_name(void);
261sym_t *abstract_enclosing_name(void);
262void global_clean_up(void);
263sym_t *declare_abstract_type(sym_t *);
264void check_size(const sym_t *);
265void mark_as_set(sym_t *);
266void mark_as_used(sym_t *, bool, bool);
267void check_usage(const decl_level *);
268void check_usage_sym(bool, const sym_t *);
269void end_translation_unit(void);
270void print_previous_declaration(const sym_t *);
271int to_int_constant(tnode_t *, bool);
272
273/*
274 * tree.c
275 */
276const tnode_t *before_conversion(const tnode_t *);
277type_t *block_derive_type(type_t *, tspec_t);
278type_t *expr_derive_type(type_t *, tspec_t);
279bool is_compiler_builtin(const char *);
280tnode_t *build_constant(type_t *, val_t *);
281tnode_t *build_name(sym_t *, bool);
282tnode_t *build_string(buffer *);
283tnode_t *build_generic_selection(const tnode_t *,
284		    struct generic_association *);
285
286tnode_t *build_binary(tnode_t *, op_t, bool, tnode_t *);
287tnode_t *build_unary(op_t, bool, tnode_t *);
288tnode_t *build_member_access(tnode_t *, op_t, bool, sbuf_t *);
289tnode_t *cconv(tnode_t *);
290bool is_typeok_bool_compares_with_zero(const tnode_t *, bool);
291bool typeok(op_t, int, const tnode_t *, const tnode_t *);
292tnode_t *promote(op_t, bool, tnode_t *);
293tnode_t *convert(op_t, int, type_t *, tnode_t *);
294void convert_constant(op_t, int, const type_t *, val_t *, val_t *);
295tnode_t *build_sizeof(const type_t *);
296tnode_t *build_offsetof(const type_t *, designation);
297tnode_t *build_alignof(const type_t *);
298tnode_t *cast(tnode_t *, bool, type_t *);
299void add_function_argument(function_call *, tnode_t *);
300tnode_t *build_function_call(tnode_t *, bool, function_call *);
301val_t *integer_constant(tnode_t *, bool);
302void expr(tnode_t *, bool, bool, bool, bool);
303void check_expr_misc(const tnode_t *, bool, bool, bool, bool, bool, bool);
304bool constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *);
305buffer *cat_strings(buffer *, buffer *);
306unsigned int type_size_in_bits(const type_t *);
307sym_t *find_member(const struct_or_union *, const char *);
308uint64_t possible_bits(const tnode_t *);
309
310void begin_statement_expr(void);
311void do_statement_expr(tnode_t *);
312tnode_t *end_statement_expr(void);
313bool in_statement_expr(void);
314
315/*
316 * func.c
317 */
318extern sym_t *funcsym;
319extern bool reached;
320extern bool warn_about_unreachable;
321extern bool suppress_fallthrough;
322extern int nargusg;
323extern pos_t argsused_pos;
324extern int nvararg;
325extern pos_t vapos;
326extern int printflike_argnum;
327extern pos_t printflike_pos;
328extern int scanflike_argnum;
329extern pos_t scanflike_pos;
330extern bool suppress_constcond;
331extern bool llibflg;
332extern int lwarn;
333extern bool suppress_bitfieldtype;
334extern bool plibflg;
335extern bool suppress_longlong;
336
337void begin_control_statement(control_statement_kind);
338void end_control_statement(control_statement_kind);
339void check_statement_reachable(void);
340void begin_function(sym_t *);
341void end_function(void);
342void named_label(sym_t *);
343void case_label(tnode_t *);
344void default_label(void);
345void stmt_if_expr(tnode_t *);
346void stmt_if_then_stmt(void);
347void stmt_if_else_stmt(bool);
348void stmt_switch_expr(tnode_t *);
349void stmt_switch_expr_stmt(void);
350void stmt_while_expr(tnode_t *);
351void stmt_while_expr_stmt(void);
352void stmt_do(void);
353void stmt_do_while_expr(tnode_t *);
354void stmt_for_exprs(tnode_t *, tnode_t *, tnode_t *);
355void stmt_for_exprs_stmt(void);
356void stmt_goto(sym_t *);
357void stmt_continue(void);
358void stmt_break(void);
359void stmt_return(bool, tnode_t *);
360void global_clean_up_decl(bool);
361void handle_lint_comment(lint_comment, int);
362
363/*
364 * init.c
365 */
366void begin_initialization(sym_t *);
367void end_initialization(void);
368sym_t *current_initsym(void);
369
370void init_rbrace(void);
371void init_lbrace(void);
372void init_expr(tnode_t *);
373void begin_designation(void);
374void add_designator_member(sbuf_t *);
375void add_designator_subscript(range_t);
376void designation_push(designation *, designator_kind, const sym_t *, size_t);
377
378/*
379 * emit.c
380 */
381void outtype(const type_t *);
382void outsym(const sym_t *, scl_t, def_t);
383void outfdef(const sym_t *, const pos_t *, bool, bool, const sym_t *);
384void outcall(const tnode_t *, bool, bool);
385void outusg(const sym_t *);
386
387/*
388 * lex.c
389 */
390int lex_name(const char *, size_t);
391int lex_integer_constant(const char *, size_t, int);
392int lex_floating_constant(const char *, size_t);
393int lex_operator(int, op_t);
394int lex_string(void);
395int lex_wide_string(void);
396int lex_character_constant(void);
397int lex_wide_character_constant(void);
398void lex_directive(const char *);
399void lex_next_line(void);
400void lex_comment(void);
401void lex_slash_slash_comment(void);
402void lex_unknown_character(int);
403int lex_input(void);
404bool quoted_next(const buffer *, quoted_iterator *);
405balanced_token_sequence lex_balanced(void);
406
407/*
408 * ckbool.c
409 */
410bool typeok_scalar_strict_bool(op_t, const mod_t *, int,
411		    const tnode_t *, const tnode_t *);
412bool fallback_symbol_strict_bool(sym_t *);
413
414/*
415 * ckctype.c
416 */
417void check_ctype_function_call(const function_call *);
418void check_ctype_macro_invocation(const tnode_t *, const tnode_t *);
419
420/*
421 * ckgetopt.c
422 */
423void check_getopt_begin_while(const tnode_t *);
424void check_getopt_begin_switch(void);
425void check_getopt_case_label(int64_t);
426void check_getopt_end_switch(void);
427void check_getopt_end_while(void);
428
429/* cksnprintb.c */
430void check_snprintb(const function_call *);
431