1/* Definitions for C parsing and type checking. 2 Copyright (C) 1987, 93, 94, 95, 97, 98, 1999 Free Software Foundation, Inc. 3 4This file is part of GNU CC. 5 6GNU CC is free software; you can redistribute it and/or modify 7it under the terms of the GNU General Public License as published by 8the Free Software Foundation; either version 2, or (at your option) 9any later version. 10 11GNU CC is distributed in the hope that it will be useful, 12but WITHOUT ANY WARRANTY; without even the implied warranty of 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14GNU General Public License for more details. 15 16You should have received a copy of the GNU General Public License 17along with GNU CC; see the file COPYING. If not, write to 18the Free Software Foundation, 59 Temple Place - Suite 330, 19Boston, MA 02111-1307, USA. */ 20 21#ifndef _C_TREE_H 22#define _C_TREE_H 23 24/* Language-dependent contents of an identifier. */ 25 26/* The limbo_value is used for block level extern declarations, which need 27 to be type checked against subsequent extern declarations. They can't 28 be referenced after they fall out of scope, so they can't be global. */ 29 30struct lang_identifier 31{ 32 struct tree_identifier ignore; 33 tree global_value, local_value, label_value, implicit_decl; 34 tree error_locus, limbo_value; 35}; 36 37/* Macros for access to language-specific slots in an identifier. */ 38/* Each of these slots contains a DECL node or null. */ 39 40/* This represents the value which the identifier has in the 41 file-scope namespace. */ 42#define IDENTIFIER_GLOBAL_VALUE(NODE) \ 43 (((struct lang_identifier *) (NODE))->global_value) 44/* This represents the value which the identifier has in the current 45 scope. */ 46#define IDENTIFIER_LOCAL_VALUE(NODE) \ 47 (((struct lang_identifier *) (NODE))->local_value) 48/* This represents the value which the identifier has as a label in 49 the current label scope. */ 50#define IDENTIFIER_LABEL_VALUE(NODE) \ 51 (((struct lang_identifier *) (NODE))->label_value) 52/* This records the extern decl of this identifier, if it has had one 53 at any point in this compilation. */ 54#define IDENTIFIER_LIMBO_VALUE(NODE) \ 55 (((struct lang_identifier *) (NODE))->limbo_value) 56/* This records the implicit function decl of this identifier, if it 57 has had one at any point in this compilation. */ 58#define IDENTIFIER_IMPLICIT_DECL(NODE) \ 59 (((struct lang_identifier *) (NODE))->implicit_decl) 60/* This is the last function in which we printed an "undefined variable" 61 message for this identifier. Value is a FUNCTION_DECL or null. */ 62#define IDENTIFIER_ERROR_LOCUS(NODE) \ 63 (((struct lang_identifier *) (NODE))->error_locus) 64 65/* In identifiers, C uses the following fields in a special way: 66 TREE_PUBLIC to record that there was a previous local extern decl. 67 TREE_USED to record that such a decl was used. 68 TREE_ADDRESSABLE to record that the address of such a decl was used. */ 69 70/* Nonzero means reject anything that ANSI standard C forbids. */ 71extern int pedantic; 72 73/* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is read-only. */ 74#define C_TYPE_FIELDS_READONLY(type) TREE_LANG_FLAG_1 (type) 75 76/* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is volatile. */ 77#define C_TYPE_FIELDS_VOLATILE(type) TREE_LANG_FLAG_2 (type) 78 79/* In a RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE 80 nonzero if the definition of the type has already started. */ 81#define C_TYPE_BEING_DEFINED(type) TYPE_LANG_FLAG_0 (type) 82 83/* C types are partitioned into three subsets: object, function, and 84 incomplete types. */ 85#define C_TYPE_OBJECT_P(type) \ 86 (TREE_CODE (type) != FUNCTION_TYPE && TYPE_SIZE (type)) 87 88#define C_TYPE_FUNCTION_P(type) \ 89 (TREE_CODE (type) == FUNCTION_TYPE) 90 91#define C_TYPE_INCOMPLETE_P(type) \ 92 (TREE_CODE (type) != FUNCTION_TYPE && TYPE_SIZE (type) == 0) 93 94/* For convenience we define a single macro to identify the class of 95 object or incomplete types. */ 96#define C_TYPE_OBJECT_OR_INCOMPLETE_P(type) \ 97 (!C_TYPE_FUNCTION_P (type)) 98 99/* In a RECORD_TYPE, a sorted array of the fields of the type. */ 100struct lang_type 101{ 102 int len; 103 tree elts[1]; 104}; 105 106/* Mark which labels are explicitly declared. 107 These may be shadowed, and may be referenced from nested functions. */ 108#define C_DECLARED_LABEL_FLAG(label) TREE_LANG_FLAG_1 (label) 109 110/* Record whether a type or decl was written with nonconstant size. 111 Note that TYPE_SIZE may have simplified to a constant. */ 112#define C_TYPE_VARIABLE_SIZE(type) TYPE_LANG_FLAG_1 (type) 113#define C_DECL_VARIABLE_SIZE(type) DECL_LANG_FLAG_0 (type) 114 115/* Record in each node resulting from a binary operator 116 what operator was specified for it. */ 117#define C_EXP_ORIGINAL_CODE(exp) ((enum tree_code) TREE_COMPLEXITY (exp)) 118 119#if 0 /* Not used. */ 120/* Record whether a decl for a function or function pointer has 121 already been mentioned (in a warning) because it was called 122 but didn't have a prototype. */ 123#define C_MISSING_PROTOTYPE_WARNED(decl) DECL_LANG_FLAG_2(decl) 124#endif 125 126/* Store a value in that field. */ 127#define C_SET_EXP_ORIGINAL_CODE(exp, code) \ 128 (TREE_COMPLEXITY (exp) = (int) (code)) 129 130/* Record whether a typedef for type `int' was actually `signed int'. */ 131#define C_TYPEDEF_EXPLICITLY_SIGNED(exp) DECL_LANG_FLAG_1 ((exp)) 132 133/* Nonzero for a declaration of a built in function if there has been no 134 occasion that would declare the function in ordinary C. 135 Using the function draws a pedantic warning in this case. */ 136#define C_DECL_ANTICIPATED(exp) DECL_LANG_FLAG_3 ((exp)) 137 138/* For FUNCTION_TYPE, a hidden list of types of arguments. The same as 139 TYPE_ARG_TYPES for functions with prototypes, but created for functions 140 without prototypes. */ 141#define TYPE_ACTUAL_ARG_TYPES(NODE) TYPE_NONCOPIED_PARTS (NODE) 142 143/* In a FIELD_DECL, nonzero if the decl was originally a bitfield. */ 144#define DECL_C_BIT_FIELD(NODE) DECL_LANG_FLAG_4 (NODE) 145 146/* Nonzero if the type T promotes to itself. 147 ANSI C states explicitly the list of types that promote; 148 in particular, short promotes to int even if they have the same width. */ 149#define C_PROMOTING_INTEGER_TYPE_P(t) \ 150 (TREE_CODE ((t)) == INTEGER_TYPE \ 151 && (TYPE_MAIN_VARIANT (t) == char_type_node \ 152 || TYPE_MAIN_VARIANT (t) == signed_char_type_node \ 153 || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node \ 154 || TYPE_MAIN_VARIANT (t) == short_integer_type_node \ 155 || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node)) 156 157/* In a VAR_DECL, means the variable is really an iterator. */ 158#define ITERATOR_P(D) (DECL_LANG_FLAG_4(D)) 159 160/* In a VAR_DECL for an iterator, means we are within 161 an explicit loop over that iterator. */ 162#define ITERATOR_BOUND_P(NODE) ((NODE)->common.readonly_flag) 163 164/* in c-lang.c and objc-act.c */ 165extern tree lookup_interface PROTO((tree)); 166extern tree is_class_name PROTO((tree)); 167extern void maybe_objc_check_decl PROTO((tree)); 168extern void finish_file PROTO((void)); 169extern int maybe_objc_comptypes PROTO((tree, tree, int)); 170extern tree maybe_building_objc_message_expr PROTO((void)); 171extern tree maybe_objc_method_name PROTO((tree)); 172extern int recognize_objc_keyword PROTO((void)); 173extern tree build_objc_string PROTO((int, const char *)); 174 175/* in c-aux-info.c */ 176extern void gen_aux_info_record PROTO((tree, int, int, int)); 177 178/* in c-common.c */ 179extern void declare_function_name PROTO((void)); 180extern void decl_attributes PROTO((tree, tree, tree)); 181extern void init_function_format_info PROTO((void)); 182extern void check_function_format PROTO((tree, tree, tree)); 183extern int c_get_alias_set PROTO((tree)); 184extern void c_apply_type_quals_to_decl PROTO((int, tree)); 185/* Print an error message for invalid operands to arith operation CODE. 186 NOP_EXPR is used as a special case (see truthvalue_conversion). */ 187extern void binary_op_error PROTO((enum tree_code)); 188extern void c_expand_expr_stmt PROTO((tree)); 189extern void c_expand_start_cond PROTO((tree, int, int)); 190extern void c_expand_start_else PROTO((void)); 191extern void c_expand_end_cond PROTO((void)); 192/* Validate the expression after `case' and apply default promotions. */ 193extern tree check_case_value PROTO((tree)); 194/* Concatenate a list of STRING_CST nodes into one STRING_CST. */ 195extern tree combine_strings PROTO((tree)); 196extern void constant_expression_warning PROTO((tree)); 197extern tree convert_and_check PROTO((tree, tree)); 198extern void overflow_warning PROTO((tree)); 199extern void unsigned_conversion_warning PROTO((tree, tree)); 200/* Read the rest of the current #-directive line. */ 201#if USE_CPPLIB 202extern char *get_directive_line PROTO((void)); 203#define GET_DIRECTIVE_LINE() get_directive_line () 204#else 205extern char *get_directive_line PROTO((FILE *)); 206#define GET_DIRECTIVE_LINE() get_directive_line (finput) 207#endif 208 209/* Subroutine of build_binary_op, used for comparison operations. 210 See if the operands have both been converted from subword integer types 211 and, if so, perhaps change them both back to their original type. */ 212extern tree shorten_compare PROTO((tree *, tree *, tree *, enum tree_code *)); 213/* Prepare expr to be an argument of a TRUTH_NOT_EXPR, 214 or validate its data type for an `if' or `while' statement or ?..: exp. */ 215extern tree truthvalue_conversion PROTO((tree)); 216extern tree type_for_mode PROTO((enum machine_mode, int)); 217extern tree type_for_size PROTO((unsigned, int)); 218 219/* in c-convert.c */ 220extern tree convert PROTO((tree, tree)); 221 222/* in c-decl.c */ 223/* Standard named or nameless data types of the C compiler. */ 224extern tree char_array_type_node; 225extern tree char_type_node; 226extern tree const_ptr_type_node; 227extern tree const_string_type_node; 228extern tree default_function_type; 229extern tree double_ftype_double; 230extern tree double_ftype_double_double; 231extern tree double_type_node; 232extern tree float_type_node; 233#if HOST_BITS_PER_WIDE_INT >= 64 234extern tree intTI_type_node; 235#endif 236extern tree intDI_type_node; 237extern tree intHI_type_node; 238extern tree intQI_type_node; 239extern tree intSI_type_node; 240extern tree int_array_type_node; 241extern tree int_ftype_cptr_cptr_sizet; 242extern tree int_ftype_int; 243extern tree int_ftype_ptr_ptr_int; 244extern tree int_ftype_string_string; 245extern tree integer_type_node; 246extern tree long_double_type_node; 247extern tree long_ftype_long; 248extern tree long_integer_type_node; 249extern tree long_long_integer_type_node; 250extern tree long_long_unsigned_type_node; 251extern tree long_unsigned_type_node; 252extern tree complex_integer_type_node; 253extern tree complex_float_type_node; 254extern tree complex_double_type_node; 255extern tree complex_long_double_type_node; 256extern tree ptr_type_node; 257extern tree ptrdiff_type_node; 258extern tree short_integer_type_node; 259extern tree short_unsigned_type_node; 260extern tree signed_char_type_node; 261extern tree signed_wchar_type_node; 262extern tree string_ftype_ptr_ptr; 263extern tree string_type_node; 264extern tree unsigned_char_type_node; 265#if HOST_BITS_PER_WIDE_INT >= 64 266extern tree unsigned_intTI_type_node; 267#endif 268extern tree unsigned_intDI_type_node; 269extern tree unsigned_intHI_type_node; 270extern tree unsigned_intQI_type_node; 271extern tree unsigned_intSI_type_node; 272extern tree unsigned_type_node; 273extern tree unsigned_wchar_type_node; 274extern tree void_ftype_ptr_int_int; 275extern tree void_ftype_ptr_ptr_int; 276extern tree void_type_node; 277extern tree wchar_array_type_node; 278extern tree wchar_type_node; 279extern tree boolean_type_node; 280extern tree boolean_true_node; 281extern tree boolean_false_node; 282 283extern tree build_enumerator PROTO((tree, tree)); 284/* Declare a predefined function. Return the declaration. */ 285extern tree builtin_function PROTO((const char *, tree, enum built_in_function function_, const char *)); 286/* Add qualifiers to a type, in the fashion for C. */ 287extern tree c_build_qualified_type PROTO((tree, int)); 288#define c_build_type_variant(TYPE, CONST_P, VOLATILE_P) \ 289 c_build_qualified_type (TYPE, \ 290 ((CONST_P) ? TYPE_QUAL_CONST : 0) | \ 291 ((VOLATILE_P) ? TYPE_QUAL_VOLATILE : 0)) 292extern int c_decode_option PROTO((int, char **)); 293extern void c_mark_varargs PROTO((void)); 294extern tree check_identifier PROTO((tree, tree)); 295extern void clear_parm_order PROTO((void)); 296extern tree combine_parm_decls PROTO((tree, tree, int)); 297extern int complete_array_type PROTO((tree, tree, int)); 298extern void declare_parm_level PROTO((int)); 299extern tree define_label PROTO((char *, int, tree)); 300extern void delete_block PROTO((tree)); 301extern void finish_decl PROTO((tree, tree, tree)); 302extern void finish_decl_top_level PROTO((tree, tree, tree)); 303extern tree finish_enum PROTO((tree, tree, tree)); 304extern void finish_function PROTO((int)); 305extern tree finish_struct PROTO((tree, tree, tree)); 306extern tree get_parm_info PROTO((int)); 307extern tree getdecls PROTO((void)); 308extern tree gettags PROTO((void)); 309extern int global_bindings_p PROTO((void)); 310extern tree grokfield PROTO((const char *, int, tree, tree, tree)); 311extern tree groktypename PROTO((tree)); 312extern tree groktypename_in_parm_context PROTO((tree)); 313extern tree implicitly_declare PROTO((tree)); 314extern int in_parm_level_p PROTO((void)); 315extern void init_decl_processing PROTO((void)); 316extern void insert_block PROTO((tree)); 317extern void keep_next_level PROTO((void)); 318extern int kept_level_p PROTO((void)); 319extern tree lookup_label PROTO((tree)); 320extern tree lookup_name PROTO((tree)); 321extern tree lookup_name_current_level PROTO((tree)); 322extern tree lookup_name_current_level_global PROTO((tree)); 323extern tree maybe_build_cleanup PROTO((tree)); 324extern void parmlist_tags_warning PROTO((void)); 325extern void pending_xref_error PROTO((void)); 326extern void pop_c_function_context PROTO((void)); 327extern void pop_label_level PROTO((void)); 328extern tree poplevel PROTO((int, int, int)); 329extern void print_lang_decl PROTO((FILE *, tree, int)); 330extern void print_lang_identifier PROTO((FILE *, tree, int)); 331extern void print_lang_type PROTO((FILE *, tree, int)); 332extern void push_c_function_context PROTO((void)); 333extern void push_label_level PROTO((void)); 334extern void push_parm_decl PROTO((tree)); 335extern tree pushdecl PROTO((tree)); 336extern tree pushdecl_top_level PROTO((tree)); 337extern void pushlevel PROTO((int)); 338extern void pushtag PROTO((tree, tree)); 339extern void set_block PROTO((tree)); 340extern tree shadow_label PROTO((tree)); 341extern void shadow_record_fields PROTO((tree)); 342extern void shadow_tag PROTO((tree)); 343extern void shadow_tag_warned PROTO((tree, int)); 344extern tree start_enum PROTO((tree)); 345extern int start_function PROTO((tree, tree, tree, 346 tree, int)); 347extern tree start_decl PROTO((tree, tree, int, 348 tree, tree)); 349extern tree start_struct PROTO((enum tree_code, tree)); 350extern void store_parm_decls PROTO((void)); 351extern tree xref_tag PROTO((enum tree_code, tree)); 352 353/* in c-typeck.c */ 354extern tree require_complete_type PROTO((tree)); 355extern void incomplete_type_error PROTO((tree, tree)); 356/* Given two integer or real types, return the type for their sum. 357 Given two compatible ANSI C types, returns the merged type. */ 358extern tree common_type PROTO((tree, tree)); 359extern int comptypes PROTO((tree, tree)); 360extern int self_promoting_args_p PROTO((tree)); 361extern tree c_sizeof PROTO((tree)); 362extern tree c_sizeof_nowarn PROTO((tree)); 363extern tree c_size_in_bytes PROTO((tree)); 364extern tree c_alignof PROTO((tree)); 365extern tree c_alignof_expr PROTO((tree)); 366extern tree default_conversion PROTO((tree)); 367extern tree build_component_ref PROTO((tree, tree)); 368extern tree build_indirect_ref PROTO((tree, const char *)); 369extern tree build_array_ref PROTO((tree, tree)); 370extern tree build_function_call PROTO((tree, tree)); 371extern tree parser_build_binary_op PROTO((enum tree_code, 372 tree, tree)); 373extern tree build_binary_op PROTO((enum tree_code, 374 tree, tree, int)); 375extern tree build_unary_op PROTO((enum tree_code, 376 tree, int)); 377extern int lvalue_p PROTO((tree)); 378extern int lvalue_or_else PROTO((tree, const char *)); 379extern void readonly_warning PROTO((tree, const char *)); 380extern int mark_addressable PROTO((tree)); 381extern tree build_conditional_expr PROTO((tree, tree, tree)); 382extern tree build_compound_expr PROTO((tree)); 383extern tree build_c_cast PROTO((tree, tree)); 384extern tree build_modify_expr PROTO((tree, enum tree_code, 385 tree)); 386extern tree initializer_constant_valid_p PROTO((tree, tree)); 387extern void store_init_value PROTO((tree, tree)); 388extern void error_init PROTO((const char *)); 389extern void pedwarn_init PROTO((const char *)); 390extern void start_init PROTO((tree, tree, int)); 391extern void finish_init PROTO((void)); 392extern void really_start_incremental_init PROTO((tree)); 393extern void push_init_level PROTO((int)); 394extern tree pop_init_level PROTO((int)); 395extern void set_init_index PROTO((tree, tree)); 396extern void set_init_label PROTO((tree)); 397extern void process_init_element PROTO((tree)); 398extern void c_expand_asm_operands PROTO((tree, tree, tree, tree, 399 int, char *, int)); 400extern void c_expand_return PROTO((tree)); 401extern tree c_expand_start_case PROTO((tree)); 402 403/* in c-iterate.c */ 404extern void init_iterators PROTO((void)); 405extern void iterator_expand PROTO((tree)); 406extern void iterator_for_loop_start PROTO((tree)); 407extern void iterator_for_loop_end PROTO((tree)); 408extern void iterator_for_loop_record PROTO((tree)); 409extern void push_iterator_stack PROTO((void)); 410extern void pop_iterator_stack PROTO((void)); 411 412/* Set to 0 at beginning of a function definition, set to 1 if 413 a return statement that specifies a return value is seen. */ 414 415extern int current_function_returns_value; 416 417/* Set to 0 at beginning of a function definition, set to 1 if 418 a return statement with no argument is seen. */ 419 420extern int current_function_returns_null; 421 422/* Nonzero means the expression being parsed will never be evaluated. 423 This is a count, since unevaluated expressions can nest. */ 424 425extern int skip_evaluation; 426 427/* Nonzero means `$' can be in an identifier. */ 428 429extern int dollars_in_ident; 430 431/* Nonzero means allow type mismatches in conditional expressions; 432 just make their values `void'. */ 433 434extern int flag_cond_mismatch; 435 436/* Nonzero means don't recognize the keyword `asm'. */ 437 438extern int flag_no_asm; 439 440/* Nonzero means environment is hosted (i.e., not freestanding) */ 441 442extern int flag_hosted; 443 444/* Nonzero means warn about implicit declarations. */ 445 446extern int warn_implicit; 447 448/* Nonzero means give string constants the type `const char *' 449 to get extra warnings from them. These warnings will be too numerous 450 to be useful, except in thoroughly ANSIfied programs. */ 451 452extern int flag_const_strings; 453 454/* Nonzero means warn about sizeof (function) or addition/subtraction 455 of function pointers. */ 456 457extern int warn_pointer_arith; 458 459/* Nonzero means warn for all old-style non-prototype function decls. */ 460 461extern int warn_strict_prototypes; 462 463/* Nonzero means warn about multiple (redundant) decls for the same single 464 variable or function. */ 465 466extern int warn_redundant_decls; 467 468/* Nonzero means warn about extern declarations of objects not at 469 file-scope level and about *all* declarations of functions (whether 470 extern or static) not at file-scope level. Note that we exclude 471 implicit function declarations. To get warnings about those, use 472 -Wimplicit. */ 473 474extern int warn_nested_externs; 475 476/* Nonzero means warn about pointer casts that can drop a type qualifier 477 from the pointer target type. */ 478 479extern int warn_cast_qual; 480 481/* Nonzero means warn when casting a function call to a type that does 482 not match the return type (e.g. (float)sqrt() or (anything*)malloc() 483 when there is no previous declaration of sqrt or malloc. */ 484 485extern int warn_bad_function_cast; 486 487/* Warn about functions which might be candidates for attribute noreturn. */ 488 489extern int warn_missing_noreturn; 490 491/* Warn about traditional constructs whose meanings changed in ANSI C. */ 492 493extern int warn_traditional; 494 495/* Warn about *printf or *scanf format/argument anomalies. */ 496 497extern int warn_format; 498 499/* Warn about a subscript that has type char. */ 500 501extern int warn_char_subscripts; 502 503/* Warn if a type conversion is done that might have confusing results. */ 504 505extern int warn_conversion; 506 507/* Warn if main is suspicious. */ 508 509extern int warn_main; 510 511/* Nonzero means do some things the same way PCC does. */ 512 513extern int flag_traditional; 514 515/* Nonzero means use the ISO C9x dialect of C. */ 516 517extern int flag_isoc9x; 518 519/* Nonzero means to allow single precision math even if we're generally 520 being traditional. */ 521extern int flag_allow_single_precision; 522 523/* Nonzero means warn about suggesting putting in ()'s. */ 524 525extern int warn_parentheses; 526 527/* Warn if initializer is not completely bracketed. */ 528 529extern int warn_missing_braces; 530 531/* Warn about comparison of signed and unsigned values. */ 532 533extern int warn_sign_compare; 534 535/* Warn about multicharacter constants. */ 536 537extern int warn_multichar; 538 539/* Warn about long long. */ 540 541extern int warn_long_long; 542 543/* Nonzero means we are reading code that came from a system header file. */ 544 545extern int system_header_p; 546 547/* Nonzero enables objc features. */ 548 549extern int doing_objc_thang; 550 551/* In c-decl.c */ 552extern void finish_incomplete_decl PROTO((tree)); 553 554#endif /* not _C_TREE_H */ 555