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