1 /* Definitions for C parsing and type checking.
2 Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "diagnostic.h"
28 /* struct lang_identifier is private to c-decl.c, but langhooks.c needs to
29 know how big it is. This is sanity-checked in c-decl.c. */
30 #define C_SIZEOF_STRUCT_LANG_IDENTIFIER \
31 (sizeof (struct c_common_identifier) + 3 * sizeof (void *))
33 /* Language-specific declaration information. */
35 struct lang_decl
GTY(())
40 /* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is read-only. */
41 #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1 (TYPE)
43 /* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is volatile. */
44 #define C_TYPE_FIELDS_VOLATILE(TYPE) TREE_LANG_FLAG_2 (TYPE)
46 /* In a RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE
47 nonzero if the definition of the type has already started. */
48 #define C_TYPE_BEING_DEFINED(TYPE) TYPE_LANG_FLAG_0 (TYPE)
50 /* In an incomplete RECORD_TYPE or UNION_TYPE, a list of variable
51 declarations whose type would be completed by completing that type. */
52 #define C_TYPE_INCOMPLETE_VARS(TYPE) TYPE_VFIELD (TYPE)
54 /* In an IDENTIFIER_NODE, nonzero if this identifier is actually a
55 keyword. C_RID_CODE (node) is then the RID_* value of the keyword,
56 and C_RID_YYCODE is the token number wanted by Yacc. */
57 #define C_IS_RESERVED_WORD(ID) TREE_LANG_FLAG_0 (ID)
59 struct lang_type
GTY(())
61 /* In a RECORD_TYPE, a sorted array of the fields of the type. */
62 struct sorted_fields_type
* GTY ((reorder ("resort_sorted_fields"))) s
;
63 /* In an ENUMERAL_TYPE, the min and max values. */
66 /* In a RECORD_TYPE, information specific to Objective-C, such
67 as a list of adopted protocols or a pointer to a corresponding
68 @interface. See objc/objc-act.h for details. */
72 /* Record whether a type or decl was written with nonconstant size.
73 Note that TYPE_SIZE may have simplified to a constant. */
74 #define C_TYPE_VARIABLE_SIZE(TYPE) TYPE_LANG_FLAG_1 (TYPE)
75 #define C_DECL_VARIABLE_SIZE(TYPE) DECL_LANG_FLAG_0 (TYPE)
77 /* Record whether a typedef for type `int' was actually `signed int'. */
78 #define C_TYPEDEF_EXPLICITLY_SIGNED(EXP) DECL_LANG_FLAG_1 (EXP)
80 /* For a FUNCTION_DECL, nonzero if it was defined without an explicit
82 #define C_FUNCTION_IMPLICIT_INT(EXP) DECL_LANG_FLAG_1 (EXP)
84 /* For a FUNCTION_DECL, nonzero if it was an implicit declaration. */
85 #define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87 /* For FUNCTION_DECLs, evaluates true if the decl is built-in but has
89 #define C_DECL_DECLARED_BUILTIN(EXP) \
90 DECL_LANG_FLAG_3 (FUNCTION_DECL_CHECK (EXP))
92 /* Record whether a decl was declared register. This is strictly a
93 front-end flag, whereas DECL_REGISTER is used for code generation;
94 they may differ for structures with volatile fields. */
95 #define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4 (EXP)
97 /* Record whether a decl was used in an expression anywhere except an
98 unevaluated operand of sizeof / typeof / alignof. This is only
99 used for functions declared static but not defined, though outside
100 sizeof and typeof it is set for other function decls as well. */
101 #define C_DECL_USED(EXP) DECL_LANG_FLAG_5 (FUNCTION_DECL_CHECK (EXP))
103 /* Record whether a label was defined in a statement expression which
104 has finished and so can no longer be jumped to. */
105 #define C_DECL_UNJUMPABLE_STMT_EXPR(EXP) \
106 DECL_LANG_FLAG_6 (LABEL_DECL_CHECK (EXP))
108 /* Record whether a label was the subject of a goto from outside the
109 current level of statement expression nesting and so cannot be
110 defined right now. */
111 #define C_DECL_UNDEFINABLE_STMT_EXPR(EXP) \
112 DECL_LANG_FLAG_7 (LABEL_DECL_CHECK (EXP))
114 /* Record whether a label was defined in the scope of an identifier
115 with variably modified type which has finished and so can no longer
117 #define C_DECL_UNJUMPABLE_VM(EXP) \
118 DECL_LANG_FLAG_3 (LABEL_DECL_CHECK (EXP))
120 /* Record whether a label was the subject of a goto from outside the
121 current level of scopes of identifiers with variably modified type
122 and so cannot be defined right now. */
123 #define C_DECL_UNDEFINABLE_VM(EXP) \
124 DECL_LANG_FLAG_5 (LABEL_DECL_CHECK (EXP))
126 /* Nonzero for a decl which either doesn't exist or isn't a prototype.
127 N.B. Could be simplified if all built-in decls had complete prototypes
128 (but this is presently difficult because some of them need FILE*). */
129 #define C_DECL_ISNT_PROTOTYPE(EXP) \
131 || (TYPE_ARG_TYPES (TREE_TYPE (EXP)) == 0 \
132 && !DECL_BUILT_IN (EXP)))
134 /* For FUNCTION_TYPE, a hidden list of types of arguments. The same as
135 TYPE_ARG_TYPES for functions with prototypes, but created for functions
136 without prototypes. */
137 #define TYPE_ACTUAL_ARG_TYPES(NODE) TYPE_LANG_SLOT_1 (NODE)
139 /* Record parser information about an expression that is irrelevant
140 for code generation alongside a tree representing its value. */
143 /* The value of the expression. */
145 /* Record the original binary operator of an expression, which may
146 have been changed by fold, STRING_CST for unparenthesized string
147 constants, or ERROR_MARK for other expressions (including
148 parenthesized expressions). */
149 enum tree_code original_code
;
152 /* A kind of type specifier. Note that this information is currently
153 only used to distinguish tag definitions, tag references and typeof
155 enum c_typespec_kind
{
156 /* A reserved keyword type specifier. */
158 /* A reference to a tag, previously declared, such as "struct foo".
159 This includes where the previous declaration was as a different
160 kind of tag, in which case this is only valid if shadowing that
161 tag in an inner scope. */
163 /* A reference to a tag, not previously declared in a visible
166 /* A definition of a tag such as "struct foo { int a; }". */
168 /* A typedef name. */
170 /* An ObjC-specific kind of type specifier. */
172 /* A typeof specifier. */
176 /* A type specifier: this structure is created in the parser and
177 passed to declspecs_add_type only. */
179 /* What kind of type specifier this is. */
180 enum c_typespec_kind kind
;
181 /* The specifier itself. */
185 /* A storage class specifier. */
186 enum c_storage_class
{
195 /* A type specifier keyword "void", "_Bool", "char", "int", "float",
196 "double", or none of these. */
197 enum c_typespec_keyword
{
207 /* A sequence of declaration specifiers in C. */
209 /* The type specified, if a single type specifier such as a struct,
210 union or enum specifier, typedef name or typeof specifies the
211 whole type, or NULL_TREE if none or a keyword such as "void" or
212 "char" is used. Does not include qualifiers. */
214 /* The attributes from a typedef decl. */
216 /* When parsing, the attributes. Outside the parser, this will be
217 NULL; attributes (possibly from multiple lists) will be passed
220 /* Any type specifier keyword used such as "int", not reflecting
221 modifiers such as "short", or cts_none if none. */
222 enum c_typespec_keyword typespec_word
;
223 /* The storage class specifier, or csc_none if none. */
224 enum c_storage_class storage_class
;
225 /* Whether any declaration specifiers have been seen at all. */
226 BOOL_BITFIELD declspecs_seen_p
: 1;
227 /* Whether a type specifier has been seen. */
228 BOOL_BITFIELD type_seen_p
: 1;
229 /* Whether something other than a storage class specifier or
230 attribute has been seen. This is used to warn for the
231 obsolescent usage of storage class specifiers other than at the
232 start of the list. (Doing this properly would require function
233 specifiers to be handled separately from storage class
235 BOOL_BITFIELD non_sc_seen_p
: 1;
236 /* Whether the type is specified by a typedef or typeof name. */
237 BOOL_BITFIELD typedef_p
: 1;
238 /* Whether a struct, union or enum type either had its content
239 defined by a type specifier in the list or was the first visible
240 declaration of its tag. */
241 BOOL_BITFIELD tag_defined_p
: 1;
242 /* Whether the type is explicitly "signed" or specified by a typedef
243 whose type is explicitly "signed". */
244 BOOL_BITFIELD explicit_signed_p
: 1;
245 /* Whether the specifiers include a deprecated typedef. */
246 BOOL_BITFIELD deprecated_p
: 1;
247 /* Whether the type defaulted to "int" because there were no type
249 BOOL_BITFIELD default_int_p
;
250 /* Whether "long" was specified. */
251 BOOL_BITFIELD long_p
: 1;
252 /* Whether "long" was specified more than once. */
253 BOOL_BITFIELD long_long_p
: 1;
254 /* Whether "short" was specified. */
255 BOOL_BITFIELD short_p
: 1;
256 /* Whether "signed" was specified. */
257 BOOL_BITFIELD signed_p
: 1;
258 /* Whether "unsigned" was specified. */
259 BOOL_BITFIELD unsigned_p
: 1;
260 /* Whether "complex" was specified. */
261 BOOL_BITFIELD complex_p
: 1;
262 /* Whether "inline" was specified. */
263 BOOL_BITFIELD inline_p
: 1;
264 /* Whether "__thread" was specified. */
265 BOOL_BITFIELD thread_p
: 1;
266 /* Whether "const" was specified. */
267 BOOL_BITFIELD const_p
: 1;
268 /* Whether "volatile" was specified. */
269 BOOL_BITFIELD volatile_p
: 1;
270 /* Whether "restrict" was specified. */
271 BOOL_BITFIELD restrict_p
: 1;
274 /* The various kinds of declarators in C. */
275 enum c_declarator_kind
{
284 /* Parenthesized declarator with nested attributes. */
288 /* Information about the parameters in a function declarator. */
290 /* A list of parameter decls. */
292 /* A list of structure, union and enum tags defined. */
294 /* A list of argument types to go in the FUNCTION_TYPE. */
296 /* A list of non-parameter decls (notably enumeration constants)
297 defined with the parameters. */
302 struct c_declarator
{
303 /* The kind of declarator. */
304 enum c_declarator_kind kind
;
305 /* Except for cdk_id, the contained declarator. For cdk_id, NULL. */
306 struct c_declarator
*declarator
;
307 location_t id_loc
; /* Currently only set for cdk_id. */
309 /* For identifiers, an IDENTIFIER_NODE or NULL_TREE if an abstract
313 struct c_arg_info
*arg_info
;
316 /* The array dimension, or NULL for [] and [*]. */
318 /* The qualifiers inside []. */
320 /* The attributes (currently ignored) inside []. */
322 /* Whether [static] was used. */
323 BOOL_BITFIELD static_p
: 1;
324 /* Whether [*] was used. */
325 BOOL_BITFIELD vla_unspec_p
: 1;
327 /* For pointers, the qualifiers on the pointer type. */
329 /* For attributes. */
336 /* The declaration specifiers. */
337 struct c_declspecs
*specs
;
338 /* The declarator. */
339 struct c_declarator
*declarator
;
344 /* The declaration specifiers, minus any prefix attributes. */
345 struct c_declspecs
*specs
;
346 /* The attributes. */
348 /* The declarator. */
349 struct c_declarator
*declarator
;
352 /* Save and restore the variables in this file and elsewhere
353 that keep track of the progress of compilation of the current function.
354 Used for nested functions. */
356 struct language_function
GTY(())
358 struct c_language_function base
;
361 struct c_switch
* GTY((skip
)) x_switch_stack
;
362 struct c_arg_info
* GTY((skip
)) arg_info
;
365 int returns_abnormally
;
366 int warn_about_return_type
;
370 /* Save lists of labels used or defined in particular contexts.
371 Allocated on the parser obstack. */
375 /* The label at the head of the list. */
377 /* The rest of the list. */
378 struct c_label_list
*next
;
381 /* Statement expression context. */
383 struct c_label_context_se
385 /* The labels defined at this level of nesting. */
386 struct c_label_list
*labels_def
;
387 /* The labels used at this level of nesting. */
388 struct c_label_list
*labels_used
;
389 /* The next outermost context. */
390 struct c_label_context_se
*next
;
393 /* Context of variably modified declarations. */
395 struct c_label_context_vm
397 /* The labels defined at this level of nesting. */
398 struct c_label_list
*labels_def
;
399 /* The labels used at this level of nesting. */
400 struct c_label_list
*labels_used
;
401 /* The scope of this context. Multiple contexts may be at the same
402 numbered scope, since each variably modified declaration starts a
405 /* The next outermost context. */
406 struct c_label_context_vm
*next
;
411 extern void c_parse_init (void);
413 /* in c-aux-info.c */
414 extern void gen_aux_info_record (tree
, int, int, int);
417 extern struct obstack parser_obstack
;
418 extern tree c_break_label
;
419 extern tree c_cont_label
;
421 extern int global_bindings_p (void);
422 extern void push_scope (void);
423 extern tree
pop_scope (void);
424 extern void insert_block (tree
);
425 extern tree
pushdecl (tree
);
426 extern void c_expand_body (tree
);
428 extern void c_init_decl_processing (void);
429 extern void c_dup_lang_specific_decl (tree
);
430 extern void c_print_identifier (FILE *, tree
, int);
431 extern int quals_from_declspecs (const struct c_declspecs
*);
432 extern struct c_declarator
*build_array_declarator (tree
, struct c_declspecs
*,
434 extern tree
build_enumerator (tree
, tree
);
435 extern void check_for_loop_decls (void);
436 extern void mark_forward_parm_decls (void);
437 extern void declare_parm_level (void);
438 extern void undeclared_variable (tree
, location_t
);
439 extern tree
declare_label (tree
);
440 extern tree
define_label (location_t
, tree
);
441 extern void finish_decl (tree
, tree
, tree
);
442 extern tree
finish_enum (tree
, tree
, tree
);
443 extern void finish_function (void);
444 extern tree
finish_struct (tree
, tree
, tree
);
445 extern struct c_arg_info
*get_parm_info (bool);
446 extern tree
grokfield (struct c_declarator
*, struct c_declspecs
*, tree
);
447 extern tree
groktypename (struct c_type_name
*);
448 extern tree
grokparm (const struct c_parm
*);
449 extern tree
implicitly_declare (tree
);
450 extern void keep_next_level (void);
451 extern tree
lookup_name (tree
);
452 extern void pending_xref_error (void);
453 extern void c_push_function_context (struct function
*);
454 extern void c_pop_function_context (struct function
*);
455 extern void push_parm_decl (const struct c_parm
*);
456 extern tree
pushdecl_top_level (tree
);
457 extern struct c_declarator
*set_array_declarator_inner (struct c_declarator
*,
458 struct c_declarator
*,
460 extern tree
builtin_function (const char *, tree
, int, enum built_in_class
,
462 extern void shadow_tag (const struct c_declspecs
*);
463 extern void shadow_tag_warned (const struct c_declspecs
*, int);
464 extern tree
start_enum (tree
);
465 extern int start_function (struct c_declspecs
*, struct c_declarator
*, tree
);
466 extern tree
start_decl (struct c_declarator
*, struct c_declspecs
*, bool,
468 extern tree
start_struct (enum tree_code
, tree
);
469 extern void store_parm_decls (void);
470 extern void store_parm_decls_from (struct c_arg_info
*);
471 extern tree
xref_tag (enum tree_code
, tree
);
472 extern struct c_typespec
parser_xref_tag (enum tree_code
, tree
);
473 extern int c_expand_decl (tree
);
474 extern struct c_parm
*build_c_parm (struct c_declspecs
*, tree
,
475 struct c_declarator
*);
476 extern struct c_declarator
*build_attrs_declarator (tree
,
477 struct c_declarator
*);
478 extern struct c_declarator
*build_function_declarator (struct c_arg_info
*,
479 struct c_declarator
*);
480 extern struct c_declarator
*build_id_declarator (tree
);
481 extern struct c_declarator
*make_pointer_declarator (struct c_declspecs
*,
482 struct c_declarator
*);
483 extern struct c_declspecs
*build_null_declspecs (void);
484 extern struct c_declspecs
*declspecs_add_qual (struct c_declspecs
*, tree
);
485 extern struct c_declspecs
*declspecs_add_type (struct c_declspecs
*,
487 extern struct c_declspecs
*declspecs_add_scspec (struct c_declspecs
*, tree
);
488 extern struct c_declspecs
*declspecs_add_attrs (struct c_declspecs
*, tree
);
489 extern struct c_declspecs
*finish_declspecs (struct c_declspecs
*);
491 /* in c-objc-common.c */
492 extern int c_disregard_inline_limits (tree
);
493 extern int c_cannot_inline_tree_fn (tree
*);
494 extern bool c_objc_common_init (void);
495 extern bool c_missing_noreturn_ok_p (tree
);
496 extern tree
c_objc_common_truthvalue_conversion (tree expr
);
497 extern bool c_warn_unused_global_decl (tree
);
498 extern void c_initialize_diagnostics (diagnostic_context
*);
500 #define c_build_type_variant(TYPE, CONST_P, VOLATILE_P) \
501 c_build_qualified_type ((TYPE), \
502 ((CONST_P) ? TYPE_QUAL_CONST : 0) | \
503 ((VOLATILE_P) ? TYPE_QUAL_VOLATILE : 0))
506 extern int in_alignof
;
507 extern int in_sizeof
;
508 extern int in_typeof
;
510 extern struct c_switch
*c_switch_stack
;
511 extern struct c_label_context_se
*label_context_stack_se
;
512 extern struct c_label_context_vm
*label_context_stack_vm
;
514 extern tree
require_complete_type (tree
);
515 extern int same_translation_unit_p (tree
, tree
);
516 extern int comptypes (tree
, tree
);
517 extern bool c_mark_addressable (tree
);
518 extern void c_incomplete_type_error (tree
, tree
);
519 extern tree
c_type_promotes_to (tree
);
520 extern tree
default_conversion (tree
);
521 extern tree
composite_type (tree
, tree
);
522 extern tree
build_component_ref (tree
, tree
);
523 extern tree
build_indirect_ref (tree
, const char *);
524 extern tree
build_array_ref (tree
, tree
);
525 extern tree
build_external_ref (tree
, int, location_t
);
526 extern void pop_maybe_used (bool);
527 extern struct c_expr
c_expr_sizeof_expr (struct c_expr
);
528 extern struct c_expr
c_expr_sizeof_type (struct c_type_name
*);
529 extern struct c_expr
parser_build_binary_op (enum tree_code
, struct c_expr
,
531 extern tree
build_conditional_expr (tree
, tree
, tree
);
532 extern tree
build_compound_expr (tree
, tree
);
533 extern tree
c_cast_expr (struct c_type_name
*, tree
);
534 extern tree
build_c_cast (tree
, tree
);
535 extern tree
build_modify_expr (tree
, enum tree_code
, tree
);
536 extern void store_init_value (tree
, tree
);
537 extern void error_init (const char *);
538 extern void pedwarn_init (const char *);
539 extern void maybe_warn_string_init (tree
, struct c_expr
);
540 extern void start_init (tree
, tree
, int);
541 extern void finish_init (void);
542 extern void really_start_incremental_init (tree
);
543 extern void push_init_level (int);
544 extern struct c_expr
pop_init_level (int);
545 extern void set_init_index (tree
, tree
);
546 extern void set_init_label (tree
);
547 extern void process_init_element (struct c_expr
);
548 extern tree
build_compound_literal (tree
, tree
);
549 extern tree
c_start_case (tree
);
550 extern void c_finish_case (tree
);
551 extern tree
build_asm_expr (tree
, tree
, tree
, tree
, bool);
552 extern tree
build_asm_stmt (tree
, tree
);
553 extern tree
c_convert_parm_for_inlining (tree
, tree
, tree
, int);
554 extern int c_types_compatible_p (tree
, tree
);
555 extern tree
c_begin_compound_stmt (bool);
556 extern tree
c_end_compound_stmt (tree
, bool);
557 extern void c_finish_if_stmt (location_t
, tree
, tree
, tree
, bool);
558 extern void c_finish_loop (location_t
, tree
, tree
, tree
, tree
, tree
, bool);
559 extern tree
c_begin_stmt_expr (void);
560 extern tree
c_finish_stmt_expr (tree
);
561 extern tree
c_process_expr_stmt (tree
);
562 extern tree
c_finish_expr_stmt (tree
);
563 extern tree
c_finish_return (tree
);
564 extern tree
c_finish_bc_stmt (tree
*, bool);
565 extern tree
c_finish_goto_label (tree
);
566 extern tree
c_finish_goto_ptr (tree
);
567 extern void c_begin_vm_scope (unsigned int);
568 extern void c_end_vm_scope (unsigned int);
570 /* Set to 0 at beginning of a function definition, set to 1 if
571 a return statement that specifies a return value is seen. */
573 extern int current_function_returns_value
;
575 /* Set to 0 at beginning of a function definition, set to 1 if
576 a return statement with no argument is seen. */
578 extern int current_function_returns_null
;
580 /* Set to 0 at beginning of a function definition, set to 1 if
581 a call to a noreturn function is seen. */
583 extern int current_function_returns_abnormally
;
585 /* Nonzero means we are reading code that came from a system header file. */
587 extern int system_header_p
;
589 /* True means global_bindings_p should return false even if the scope stack
590 says we are in file scope. */
592 extern bool c_override_global_bindings_to_false
;
594 /* True means we've initialized exception handling. */
595 extern bool c_eh_initialized_p
;
598 extern void c_finish_incomplete_decl (tree
);
599 extern void c_write_global_declarations (void);
601 /* In order for the format checking to accept the C frontend
602 diagnostic framework extensions, you must include this file before
603 toplev.h, not after. */
604 #define GCC_DIAG_STYLE __gcc_cdiag__
605 #if GCC_VERSION >= 3005
606 #define ATTRIBUTE_GCC_CDIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m ,n))) ATTRIBUTE_NONNULL(m)
608 #define ATTRIBUTE_GCC_CDIAG(m, n) ATTRIBUTE_NONNULL(m)
611 extern void pedwarn_c90 (const char *, ...) ATTRIBUTE_GCC_CDIAG(1,2);
612 extern void pedwarn_c99 (const char *, ...) ATTRIBUTE_GCC_CDIAG(1,2);
614 #endif /* ! GCC_C_TREE_H */