externs1.h revision 1.179
1/*	$NetBSD: externs1.h,v 1.179 2023/06/29 05:03:03 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	int	aflag;
40extern	bool	bflag;
41extern	bool	cflag;
42extern	bool	eflag;
43extern	bool	Fflag;
44extern	bool	hflag;
45extern	bool	pflag;
46extern	bool	rflag;
47extern	bool	uflag;
48extern	bool	vflag;
49extern	bool	yflag;
50extern	bool	wflag;
51extern	bool	zflag;
52extern	bool	Tflag;
53extern	bool	Pflag;
54
55extern	bool	allow_trad;
56extern	bool	allow_c90;
57extern	bool	allow_c99;
58extern	bool	allow_c11;
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);
74
75/*
76 * scan.l
77 */
78extern  bool	in_gcc_attribute;
79extern	pos_t	curr_pos;
80extern	pos_t	csrc_pos;
81extern	bool	in_system_header;
82extern	symt_t	symtyp;
83extern	FILE	*yyin;
84
85void	initscan(void);
86int64_t	convert_integer(int64_t, tspec_t, unsigned int);
87void	clear_warn_flags(void);
88sym_t	*getsym(sbuf_t *);
89void	clean_up_after_error(void);
90sym_t	*pushdown(const sym_t *);
91sym_t	*mktempsym(type_t *);
92void	rmsym(sym_t *);
93void	rmsyms(sym_t *);
94void	inssym(int, sym_t *);
95void	freeyyv(void *, int);
96int	yylex(void);
97
98/*
99 * mem1.c
100 */
101const	char *record_filename(const char *, size_t);
102int	get_filename_id(const char *);
103void	add_directory_replacement(char *);
104const char *transform_filename(const char *, size_t);
105
106void	*block_zero_alloc(size_t);
107void	*level_zero_alloc(size_t, size_t);
108void	level_free_all(size_t);
109
110void	*expr_zero_alloc(size_t);
111tnode_t	*expr_alloc_tnode(void);
112void	expr_free_all(void);
113memory_pool expr_save_memory(void);
114void	expr_restore_memory(memory_pool);
115
116/*
117 * debug.c
118 */
119
120#ifdef DEBUG
121const char *declaration_kind_name(declaration_kind);
122const char *scl_name(scl_t);
123const char *symt_name(symt_t);
124const char *tqual_name(tqual_t);
125void	debug_dinfo(const dinfo_t *);
126void	debug_node(const tnode_t *);
127void	debug_type(const type_t *);
128void	debug_sym(const char *, const sym_t *, const char *);
129void	debug_symtab(void);
130void	debug_printf(const char *fmt, ...) __printflike(1, 2);
131void	debug_print_indent(void);
132void	debug_indent_inc(void);
133void	debug_indent_dec(void);
134void	debug_enter_func(const char *);
135void	debug_step(const char *fmt, ...) __printflike(1, 2);
136void	debug_leave_func(const char *);
137#define	debug_enter()		debug_enter_func(__func__)
138#define	debug_leave()		debug_leave_func(__func__)
139#else
140#define	debug_noop()		do { } while (false)
141#define	debug_dinfo(d)		debug_noop()
142#define	debug_sym(p, sym, s)	debug_noop()
143#define	debug_symtab()		debug_noop()
144#define	debug_node(tn)		debug_noop()
145#define	debug_type(tp)		debug_noop()
146#define	debug_printf(...)	debug_noop()
147#define	debug_print_indent()	debug_noop()
148#define	debug_indent_inc()	debug_noop()
149#define	debug_indent_dec()	debug_noop()
150#define	debug_enter()		debug_noop()
151#define	debug_step(...)		debug_noop()
152#define	debug_leave()		debug_noop()
153#endif
154
155/*
156 * err.c
157 */
158extern	int	nerr;
159extern	int	sytxerr;
160extern	bool	any_query_enabled;
161
162void	msglist(void);
163void	error_at(int, const pos_t *, ...);
164void	warning_at(int, const pos_t *, ...);
165void	message_at(int, const pos_t *, ...);
166void	error(int, ...);
167void	warning(int, ...);
168bool	gnuism(int, ...);
169void	c99ism(int, ...);
170void	c11ism(int, ...);
171void	assert_failed(const char *, int, const char *, const char *)
172		__attribute__((__noreturn__));
173void	update_location(const char *, int, bool, bool);
174void	suppress_messages(const char *);
175
176void	query_message(int, ...);
177void	enable_queries(const char *);
178
179/*
180 * decl.c
181 */
182extern	dinfo_t	*dcs;
183extern	const char unnamed[];
184extern	int	enumval;
185
186void	initdecl(void);
187type_t	*gettyp(tspec_t);
188type_t	*block_dup_type(const type_t *);
189type_t	*expr_dup_type(const type_t *);
190type_t	*expr_unqualified_type(const type_t *);
191bool	is_incomplete(const type_t *);
192void	dcs_add_storage_class(scl_t);
193void	dcs_add_type(type_t *);
194void	dcs_add_qualifier(tqual_t);
195void	dcs_add_packed(void);
196void	dcs_set_used(void);
197void	begin_declaration_level(declaration_kind);
198void	end_declaration_level(void);
199void	dcs_set_asm(void);
200void	dcs_begin_type(void);
201void	dcs_end_type(void);
202int	length_in_bits(const type_t *, const char *);
203unsigned int alignment_in_bits(const type_t *);
204sym_t	*concat_lists(sym_t *, sym_t *);
205void	check_type(sym_t *);
206sym_t	*declarator_1_struct_union(sym_t *);
207sym_t	*set_bit_field_width(sym_t *, int);
208qual_ptr *merge_qualified_pointer(qual_ptr *, qual_ptr *);
209sym_t	*add_pointer(sym_t *, qual_ptr *);
210sym_t	*add_array(sym_t *, bool, int);
211sym_t	*add_function(sym_t *, sym_t *);
212void	check_function_definition(sym_t *, bool);
213sym_t	*declarator_name(sym_t *);
214sym_t	*old_style_function_name(sym_t *);
215type_t	*make_tag_type(sym_t *, tspec_t, bool, bool);
216const	char *storage_class_name(scl_t);
217type_t	*complete_struct_or_union(sym_t *);
218type_t	*complete_enum(sym_t *);
219sym_t	*enumeration_constant(sym_t *, int, bool);
220void	declare(sym_t *, bool, sbuf_t *);
221void	copy_usage_info(sym_t *, sym_t *);
222bool	check_redeclaration(sym_t *, bool *);
223bool	pointer_types_are_compatible(const type_t *, const type_t *, bool);
224bool	types_compatible(const type_t *, const type_t *, bool, bool, bool *);
225void	complete_type(sym_t *, sym_t *);
226sym_t	*declare_argument(sym_t *, bool);
227void	check_func_lint_directives(void);
228void	check_func_old_style_arguments(void);
229
230void	declare_local(sym_t *, bool);
231sym_t	*abstract_name(void);
232void	global_clean_up(void);
233sym_t	*declare_1_abstract(sym_t *);
234void	check_size(sym_t *);
235void	mark_as_set(sym_t *);
236void	mark_as_used(sym_t *, bool, bool);
237void	check_usage(dinfo_t *);
238void	check_usage_sym(bool, sym_t *);
239void	check_global_symbols(void);
240void	print_previous_declaration(const sym_t *);
241int	to_int_constant(tnode_t *, bool);
242
243/*
244 * tree.c
245 */
246const tnode_t *before_conversion(const tnode_t *);
247type_t	*block_derive_type(type_t *, tspec_t);
248type_t	*expr_derive_type(type_t *, tspec_t);
249bool	is_compiler_builtin(const char *);
250tnode_t	*build_constant(type_t *, val_t *);
251tnode_t	*build_name(sym_t *, bool);
252tnode_t	*build_string(strg_t *);
253tnode_t	*build_generic_selection(const tnode_t *,
254		    struct generic_association *);
255
256tnode_t	*build_binary(tnode_t *, op_t, bool, tnode_t *);
257tnode_t	*build_unary(op_t, bool, tnode_t *);
258tnode_t	*build_member_access(tnode_t *, op_t, bool, sbuf_t *);
259tnode_t	*cconv(tnode_t *);
260bool	is_typeok_bool_compares_with_zero(const tnode_t *);
261bool	typeok(op_t, int, const tnode_t *, const tnode_t *);
262tnode_t	*promote(op_t, bool, tnode_t *);
263tnode_t	*convert(op_t, int, type_t *, tnode_t *);
264void	convert_constant(op_t, int, const type_t *, val_t *, val_t *);
265tnode_t	*build_sizeof(const type_t *);
266tnode_t	*build_offsetof(const type_t *, const sym_t *);
267tnode_t	*build_alignof(const type_t *);
268tnode_t	*cast(tnode_t *, type_t *);
269tnode_t	*build_function_argument(tnode_t *, tnode_t *);
270tnode_t	*build_function_call(tnode_t *, bool, tnode_t *);
271val_t	*constant(tnode_t *, bool);
272void	expr(tnode_t *, bool, bool, bool, bool);
273void	check_expr_misc(const tnode_t *, bool, bool, bool, bool, bool, bool);
274bool	constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *);
275strg_t	*cat_strings(strg_t *, strg_t *);
276unsigned int type_size_in_bits(const type_t *);
277
278void begin_statement_expr(void);
279void do_statement_expr(tnode_t *);
280tnode_t *end_statement_expr(void);
281
282/*
283 * func.c
284 */
285extern	sym_t	*funcsym;
286extern	bool	reached;
287extern	bool	warn_about_unreachable;
288extern	bool	seen_fallthrough;
289extern	int	nargusg;
290extern	pos_t	argsused_pos;
291extern	int	nvararg;
292extern	pos_t	vapos;
293extern	int	printflike_argnum;
294extern	pos_t	printflike_pos;
295extern	int	scanflike_argnum;
296extern	pos_t	scanflike_pos;
297extern	bool	constcond_flag;
298extern	bool	llibflg;
299extern	int	lwarn;
300extern	bool	bitfieldtype_ok;
301extern	bool	plibflg;
302extern	bool	quadflg;
303
304void	begin_control_statement(control_statement_kind);
305void	end_control_statement(control_statement_kind);
306void	check_statement_reachable(void);
307void	begin_function(sym_t *);
308void	end_function(void);
309void	named_label(sym_t *);
310void	case_label(tnode_t *);
311void	default_label(void);
312void	if1(tnode_t *);
313void	if2(void);
314void	if3(bool);
315void	switch1(tnode_t *);
316void	switch2(void);
317void	while1(tnode_t *);
318void	while2(void);
319void	do1(void);
320void	do2(tnode_t *);
321void	for1(tnode_t *, tnode_t *, tnode_t *);
322void	for2(void);
323void	do_goto(sym_t *);
324void	do_continue(void);
325void	do_break(void);
326void	do_return(bool, tnode_t *);
327void	global_clean_up_decl(bool);
328void	argsused(int);
329void	constcond(int);
330void	fallthru(int);
331void	not_reached(int);
332void	lintlib(int);
333void	linted(int);
334void	varargs(int);
335void	printflike(int);
336void	scanflike(int);
337void	protolib(int);
338void	longlong(int);
339void	bitfieldtype(int);
340
341/*
342 * init.c
343 */
344void	begin_initialization(sym_t *);
345void	end_initialization(void);
346sym_t	*current_initsym(void);
347
348void	init_rbrace(void);
349void	init_lbrace(void);
350void	init_expr(tnode_t *);
351void	begin_designation(void);
352void	add_designator_member(sbuf_t *);
353void	add_designator_subscript(range_t);
354
355/*
356 * emit.c
357 */
358void	outtype(const type_t *);
359void	outsym(const sym_t *, scl_t, def_t);
360void	outfdef(const sym_t *, const pos_t *, bool, bool, const sym_t *);
361void	outcall(const tnode_t *, bool, bool);
362void	outusg(const sym_t *);
363
364/*
365 * lex.c
366 */
367int	lex_name(const char *, size_t);
368int	lex_integer_constant(const char *, size_t, int);
369int	lex_floating_constant(const char *, size_t);
370int	lex_operator(int, op_t);
371int	lex_string(void);
372int	lex_wide_string(void);
373int	lex_character_constant(void);
374int	lex_wide_character_constant(void);
375void	lex_directive(const char *);
376void	lex_next_line(void);
377void	lex_comment(void);
378void	lex_slash_slash_comment(void);
379void	lex_unknown_character(int);
380int	lex_input(void);
381
382/*
383 * ckbool.c
384 */
385bool	typeok_scalar_strict_bool(op_t, const mod_t *, int,
386		    const tnode_t *, const tnode_t *);
387bool	fallback_symbol_strict_bool(sym_t *);
388
389/*
390 * ckctype.c
391 */
392void	check_ctype_function_call(const tnode_t *, const tnode_t *);
393void	check_ctype_macro_invocation(const tnode_t *, const tnode_t *);
394
395/*
396 * ckgetopt.c
397 */
398void	check_getopt_begin_while(const tnode_t *);
399void	check_getopt_begin_switch(void);
400void	check_getopt_case_label(int64_t);
401void	check_getopt_end_switch(void);
402void	check_getopt_end_while(void);
403