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