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