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 /* For gc purposes, return the most likely link for the longest chain. */
34 #define C_LANG_TREE_NODE_CHAIN_NEXT(T) \
35 ((union lang_tree_node *) \
36 (TREE_CODE (T) == INTEGER_TYPE ? TYPE_NEXT_VARIANT (T) \
37 : TREE_CODE (T) == COMPOUND_EXPR ? TREE_OPERAND (T, 1) \
40 /* Language-specific declaration information. */
42 struct lang_decl
GTY(())
47 /* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is read-only. */
48 #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1 (TYPE)
50 /* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is volatile. */
51 #define C_TYPE_FIELDS_VOLATILE(TYPE) TREE_LANG_FLAG_2 (TYPE)
53 /* In a RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE
54 nonzero if the definition of the type has already started. */
55 #define C_TYPE_BEING_DEFINED(TYPE) TYPE_LANG_FLAG_0 (TYPE)
57 /* In an incomplete RECORD_TYPE or UNION_TYPE, a list of variable
58 declarations whose type would be completed by completing that type. */
59 #define C_TYPE_INCOMPLETE_VARS(TYPE) TYPE_VFIELD (TYPE)
61 /* In an IDENTIFIER_NODE, nonzero if this identifier is actually a
62 keyword. C_RID_CODE (node) is then the RID_* value of the keyword,
63 and C_RID_YYCODE is the token number wanted by Yacc. */
64 #define C_IS_RESERVED_WORD(ID) TREE_LANG_FLAG_0 (ID)
66 struct lang_type
GTY(())
68 /* In a RECORD_TYPE, a sorted array of the fields of the type. */
69 struct sorted_fields_type
* GTY ((reorder ("resort_sorted_fields"))) s
;
70 /* In an ENUMERAL_TYPE, the min and max values. */
73 /* In a RECORD_TYPE, information specific to Objective-C, such
74 as a list of adopted protocols or a pointer to a corresponding
75 @interface. See objc/objc-act.h for details. */
79 /* Record whether a type or decl was written with nonconstant size.
80 Note that TYPE_SIZE may have simplified to a constant. */
81 #define C_TYPE_VARIABLE_SIZE(TYPE) TYPE_LANG_FLAG_1 (TYPE)
82 #define C_DECL_VARIABLE_SIZE(TYPE) DECL_LANG_FLAG_0 (TYPE)
84 /* Record whether a typedef for type `int' was actually `signed int'. */
85 #define C_TYPEDEF_EXPLICITLY_SIGNED(EXP) DECL_LANG_FLAG_1 (EXP)
87 /* For a FUNCTION_DECL, nonzero if it was defined without an explicit
89 #define C_FUNCTION_IMPLICIT_INT(EXP) DECL_LANG_FLAG_1 (EXP)
91 /* For a FUNCTION_DECL, nonzero if it was an implicit declaration. */
92 #define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
94 /* For FUNCTION_DECLs, evaluates true if the decl is built-in but has
96 #define C_DECL_DECLARED_BUILTIN(EXP) DECL_LANG_FLAG_3 (EXP)
98 /* Record whether a decl was declared register. This is strictly a
99 front-end flag, whereas DECL_REGISTER is used for code generation;
100 they may differ for structures with volatile fields. */
101 #define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4 (EXP)
103 /* Record whether a decl was used in an expression anywhere except an
104 unevaluated operand of sizeof / typeof / alignof. This is only
105 used for functions declared static but not defined, though outside
106 sizeof and typeof it is set for other function decls as well. */
107 #define C_DECL_USED(EXP) DECL_LANG_FLAG_5 (EXP)
109 /* Nonzero for a decl which either doesn't exist or isn't a prototype.
110 N.B. Could be simplified if all built-in decls had complete prototypes
111 (but this is presently difficult because some of them need FILE*). */
112 #define C_DECL_ISNT_PROTOTYPE(EXP) \
114 || (TYPE_ARG_TYPES (TREE_TYPE (EXP)) == 0 \
115 && !DECL_BUILT_IN (EXP)))
117 /* For FUNCTION_TYPE, a hidden list of types of arguments. The same as
118 TYPE_ARG_TYPES for functions with prototypes, but created for functions
119 without prototypes. */
120 #define TYPE_ACTUAL_ARG_TYPES(NODE) TYPE_LANG_SLOT_1 (NODE)
122 /* Record parser information about an expression that is irrelevant
123 for code generation alongside a tree representing its value. */
126 /* The value of the expression. */
128 /* Record the original binary operator of an expression, which may
129 have been changed by fold, STRING_CST for unparenthesized string
130 constants, or ERROR_MARK for other expressions (including
131 parenthesized expressions). */
132 enum tree_code original_code
;
135 /* A kind of type specifier. Note that this information is currently
136 only used to distinguish tag definitions, tag references and typeof
138 enum c_typespec_kind
{
139 /* A reserved keyword type specifier. */
141 /* A reference to a tag, previously declared, such as "struct foo".
142 This includes where the previous declaration was as a different
143 kind of tag, in which case this is only valid if shadowing that
144 tag in an inner scope. */
146 /* A reference to a tag, not previously declared in a visible
149 /* A definition of a tag such as "struct foo { int a; }". */
151 /* A typedef name. */
153 /* An ObjC-specific kind of type specifier. */
155 /* A typeof specifier. */
159 /* A type specifier: this structure is created in the parser and
160 passed to declspecs_add_type only. */
162 /* What kind of type specifier this is. */
163 enum c_typespec_kind kind
;
164 /* The specifier itself. */
168 /* A storage class specifier. */
169 enum c_storage_class
{
178 /* A type specifier keyword "void", "_Bool", "char", "int", "float",
179 "double", or none of these. */
180 enum c_typespec_keyword
{
190 /* A sequence of declaration specifiers in C. */
192 /* The type specified, if a single type specifier such as a struct,
193 union or enum specifier, typedef name or typeof specifies the
194 whole type, or NULL_TREE if none or a keyword such as "void" or
195 "char" is used. Does not include qualifiers. */
197 /* The attributes from a typedef decl. */
199 /* When parsing, the attributes. Outside the parser, this will be
200 NULL; attributes (possibly from multiple lists) will be passed
203 /* Any type specifier keyword used such as "int", not reflecting
204 modifiers such as "short", or cts_none if none. */
205 enum c_typespec_keyword typespec_word
;
206 /* The storage class specifier, or csc_none if none. */
207 enum c_storage_class storage_class
;
208 /* Whether any declaration specifiers have been seen at all. */
209 BOOL_BITFIELD declspecs_seen_p
: 1;
210 /* Whether a type specifier has been seen. */
211 BOOL_BITFIELD type_seen_p
: 1;
212 /* Whether something other than a storage class specifier or
213 attribute has been seen. This is used to warn for the
214 obsolescent usage of storage class specifiers other than at the
215 start of the list. (Doing this properly would require function
216 specifiers to be handled separately from storage class
218 BOOL_BITFIELD non_sc_seen_p
: 1;
219 /* Whether the type is specified by a typedef or typeof name. */
220 BOOL_BITFIELD typedef_p
: 1;
221 /* Whether a struct, union or enum type either had its content
222 defined by a type specifier in the list or was the first visible
223 declaration of its tag. */
224 BOOL_BITFIELD tag_defined_p
: 1;
225 /* Whether the type is explicitly "signed" or specified by a typedef
226 whose type is explicitly "signed". */
227 BOOL_BITFIELD explicit_signed_p
: 1;
228 /* Whether the specifiers include a deprecated typedef. */
229 BOOL_BITFIELD deprecated_p
: 1;
230 /* Whether the type defaulted to "int" because there were no type
232 BOOL_BITFIELD default_int_p
;
233 /* Whether "long" was specified. */
234 BOOL_BITFIELD long_p
: 1;
235 /* Whether "long" was specified more than once. */
236 BOOL_BITFIELD long_long_p
: 1;
237 /* Whether "short" was specified. */
238 BOOL_BITFIELD short_p
: 1;
239 /* Whether "signed" was specified. */
240 BOOL_BITFIELD signed_p
: 1;
241 /* Whether "unsigned" was specified. */
242 BOOL_BITFIELD unsigned_p
: 1;
243 /* Whether "complex" was specified. */
244 BOOL_BITFIELD complex_p
: 1;
245 /* Whether "inline" was specified. */
246 BOOL_BITFIELD inline_p
: 1;
247 /* Whether "__thread" was specified. */
248 BOOL_BITFIELD thread_p
: 1;
249 /* Whether "const" was specified. */
250 BOOL_BITFIELD const_p
: 1;
251 /* Whether "volatile" was specified. */
252 BOOL_BITFIELD volatile_p
: 1;
253 /* Whether "restrict" was specified. */
254 BOOL_BITFIELD restrict_p
: 1;
257 /* The various kinds of declarators in C. */
258 enum c_declarator_kind
{
267 /* Parenthesized declarator with nested attributes. */
271 /* Information about the parameters in a function declarator. */
273 /* A list of parameter decls. */
275 /* A list of structure, union and enum tags defined. */
277 /* A list of argument types to go in the FUNCTION_TYPE. */
279 /* A list of non-parameter decls (notably enumeration constants)
280 defined with the parameters. */
285 struct c_declarator
{
286 /* The kind of declarator. */
287 enum c_declarator_kind kind
;
288 /* Except for cdk_id, the contained declarator. For cdk_id, NULL. */
289 struct c_declarator
*declarator
;
291 /* For identifiers, an IDENTIFIER_NODE or NULL_TREE if an abstract
295 struct c_arg_info
*arg_info
;
298 /* The array dimension, or NULL for [] and [*]. */
300 /* The qualifiers inside []. */
302 /* The attributes (currently ignored) inside []. */
304 /* Whether [static] was used. */
305 BOOL_BITFIELD static_p
: 1;
306 /* Whether [*] was used. */
307 BOOL_BITFIELD vla_unspec_p
: 1;
309 /* For pointers, the qualifiers on the pointer type. */
311 /* For attributes. */
318 /* The declaration specifiers. */
319 struct c_declspecs
*specs
;
320 /* The declarator. */
321 struct c_declarator
*declarator
;
326 /* The declaration specifiers, minus any prefix attributes. */
327 struct c_declspecs
*specs
;
328 /* The attributes. */
330 /* The declarator. */
331 struct c_declarator
*declarator
;
334 /* Save and restore the variables in this file and elsewhere
335 that keep track of the progress of compilation of the current function.
336 Used for nested functions. */
338 struct language_function
GTY(())
340 struct c_language_function base
;
343 struct c_switch
* GTY((skip
)) x_switch_stack
;
344 struct c_arg_info
* GTY((skip
)) arg_info
;
347 int returns_abnormally
;
348 int warn_about_return_type
;
354 extern void c_parse_init (void);
356 /* in c-aux-info.c */
357 extern void gen_aux_info_record (tree
, int, int, int);
360 extern struct obstack parser_obstack
;
361 extern tree c_break_label
;
362 extern tree c_cont_label
;
364 extern int global_bindings_p (void);
365 extern void push_scope (void);
366 extern tree
pop_scope (void);
367 extern void insert_block (tree
);
368 extern tree
pushdecl (tree
);
369 extern void c_expand_body (tree
);
371 extern void c_init_decl_processing (void);
372 extern void c_dup_lang_specific_decl (tree
);
373 extern void c_print_identifier (FILE *, tree
, int);
374 extern int quals_from_declspecs (const struct c_declspecs
*);
375 extern struct c_declarator
*build_array_declarator (tree
, struct c_declspecs
*,
377 extern tree
build_enumerator (tree
, tree
);
378 extern void check_for_loop_decls (void);
379 extern void mark_forward_parm_decls (void);
380 extern int complete_array_type (tree
, tree
, int);
381 extern void declare_parm_level (void);
382 extern void undeclared_variable (tree
, location_t
);
383 extern tree
declare_label (tree
);
384 extern tree
define_label (location_t
, tree
);
385 extern void finish_decl (tree
, tree
, tree
);
386 extern tree
finish_enum (tree
, tree
, tree
);
387 extern void finish_function (void);
388 extern tree
finish_struct (tree
, tree
, tree
);
389 extern struct c_arg_info
*get_parm_info (bool);
390 extern tree
grokfield (struct c_declarator
*, struct c_declspecs
*, tree
);
391 extern tree
groktypename (struct c_type_name
*);
392 extern tree
grokparm (const struct c_parm
*);
393 extern tree
implicitly_declare (tree
);
394 extern void keep_next_level (void);
395 extern tree
lookup_name (tree
);
396 extern void pending_xref_error (void);
397 extern void c_push_function_context (struct function
*);
398 extern void c_pop_function_context (struct function
*);
399 extern void push_parm_decl (const struct c_parm
*);
400 extern tree
pushdecl_top_level (tree
);
401 extern struct c_declarator
*set_array_declarator_inner (struct c_declarator
*,
402 struct c_declarator
*,
404 extern tree
builtin_function (const char *, tree
, int, enum built_in_class
,
406 extern void shadow_tag (const struct c_declspecs
*);
407 extern void shadow_tag_warned (const struct c_declspecs
*, int);
408 extern tree
start_enum (tree
);
409 extern int start_function (struct c_declspecs
*, struct c_declarator
*, tree
);
410 extern tree
start_decl (struct c_declarator
*, struct c_declspecs
*, bool,
412 extern tree
start_struct (enum tree_code
, tree
);
413 extern void store_parm_decls (void);
414 extern void store_parm_decls_from (struct c_arg_info
*);
415 extern tree
xref_tag (enum tree_code
, tree
);
416 extern struct c_typespec
parser_xref_tag (enum tree_code
, tree
);
417 extern int c_expand_decl (tree
);
418 extern struct c_parm
*build_c_parm (struct c_declspecs
*, tree
,
419 struct c_declarator
*);
420 extern struct c_declarator
*build_attrs_declarator (tree
,
421 struct c_declarator
*);
422 extern struct c_declarator
*build_function_declarator (struct c_arg_info
*,
423 struct c_declarator
*);
424 extern struct c_declarator
*build_id_declarator (tree
);
425 extern struct c_declarator
*make_pointer_declarator (struct c_declspecs
*,
426 struct c_declarator
*);
427 extern struct c_declspecs
*build_null_declspecs (void);
428 extern struct c_declspecs
*declspecs_add_qual (struct c_declspecs
*, tree
);
429 extern struct c_declspecs
*declspecs_add_type (struct c_declspecs
*,
431 extern struct c_declspecs
*declspecs_add_scspec (struct c_declspecs
*, tree
);
432 extern struct c_declspecs
*declspecs_add_attrs (struct c_declspecs
*, tree
);
433 extern struct c_declspecs
*finish_declspecs (struct c_declspecs
*);
435 /* in c-objc-common.c */
436 extern int c_disregard_inline_limits (tree
);
437 extern int c_cannot_inline_tree_fn (tree
*);
438 extern bool c_objc_common_init (void);
439 extern bool c_missing_noreturn_ok_p (tree
);
440 extern tree
c_objc_common_truthvalue_conversion (tree expr
);
441 extern bool c_warn_unused_global_decl (tree
);
442 extern void c_initialize_diagnostics (diagnostic_context
*);
444 #define c_build_type_variant(TYPE, CONST_P, VOLATILE_P) \
445 c_build_qualified_type ((TYPE), \
446 ((CONST_P) ? TYPE_QUAL_CONST : 0) | \
447 ((VOLATILE_P) ? TYPE_QUAL_VOLATILE : 0))
450 extern int in_alignof
;
451 extern int in_sizeof
;
452 extern int in_typeof
;
454 extern struct c_switch
*c_switch_stack
;
456 extern tree
require_complete_type (tree
);
457 extern int same_translation_unit_p (tree
, tree
);
458 extern int comptypes (tree
, tree
);
459 extern bool c_mark_addressable (tree
);
460 extern void c_incomplete_type_error (tree
, tree
);
461 extern tree
c_type_promotes_to (tree
);
462 extern tree
composite_type (tree
, tree
);
463 extern tree
build_component_ref (tree
, tree
);
464 extern tree
build_indirect_ref (tree
, const char *);
465 extern tree
build_array_ref (tree
, tree
);
466 extern tree
build_external_ref (tree
, int, location_t
);
467 extern void pop_maybe_used (bool);
468 extern struct c_expr
c_expr_sizeof_expr (struct c_expr
);
469 extern struct c_expr
c_expr_sizeof_type (struct c_type_name
*);
470 extern struct c_expr
parser_build_binary_op (enum tree_code
, struct c_expr
,
472 extern tree
build_conditional_expr (tree
, tree
, tree
);
473 extern tree
build_compound_expr (tree
, tree
);
474 extern tree
c_cast_expr (struct c_type_name
*, tree
);
475 extern tree
build_c_cast (tree
, tree
);
476 extern tree
build_modify_expr (tree
, enum tree_code
, tree
);
477 extern void store_init_value (tree
, tree
);
478 extern void error_init (const char *);
479 extern void pedwarn_init (const char *);
480 extern void maybe_warn_string_init (tree
, struct c_expr
);
481 extern void start_init (tree
, tree
, int);
482 extern void finish_init (void);
483 extern void really_start_incremental_init (tree
);
484 extern void push_init_level (int);
485 extern struct c_expr
pop_init_level (int);
486 extern void set_init_index (tree
, tree
);
487 extern void set_init_label (tree
);
488 extern void process_init_element (struct c_expr
);
489 extern tree
build_compound_literal (tree
, tree
);
490 extern tree
c_start_case (tree
);
491 extern void c_finish_case (tree
);
492 extern tree
build_asm_expr (tree
, tree
, tree
, tree
, bool);
493 extern tree
build_asm_stmt (tree
, tree
);
494 extern tree
c_convert_parm_for_inlining (tree
, tree
, tree
, int);
495 extern int c_types_compatible_p (tree
, tree
);
496 extern tree
c_begin_compound_stmt (bool);
497 extern tree
c_end_compound_stmt (tree
, bool);
498 extern void c_finish_if_stmt (location_t
, tree
, tree
, tree
, bool);
499 extern void c_finish_loop (location_t
, tree
, tree
, tree
, tree
, tree
, bool);
500 extern tree
c_begin_stmt_expr (void);
501 extern tree
c_finish_stmt_expr (tree
);
502 extern tree
c_process_expr_stmt (tree
);
503 extern tree
c_finish_expr_stmt (tree
);
504 extern tree
c_finish_return (tree
);
505 extern tree
c_finish_bc_stmt (tree
*, bool);
506 extern tree
c_finish_goto_label (tree
);
507 extern tree
c_finish_goto_ptr (tree
);
509 /* Set to 0 at beginning of a function definition, set to 1 if
510 a return statement that specifies a return value is seen. */
512 extern int current_function_returns_value
;
514 /* Set to 0 at beginning of a function definition, set to 1 if
515 a return statement with no argument is seen. */
517 extern int current_function_returns_null
;
519 /* Set to 0 at beginning of a function definition, set to 1 if
520 a call to a noreturn function is seen. */
522 extern int current_function_returns_abnormally
;
524 /* Nonzero means we are reading code that came from a system header file. */
526 extern int system_header_p
;
528 /* True means global_bindings_p should return false even if the scope stack
529 says we are in file scope. */
531 extern bool c_override_global_bindings_to_false
;
533 /* True means we've initialized exception handling. */
534 extern bool c_eh_initialized_p
;
537 extern void c_finish_incomplete_decl (tree
);
538 extern void c_write_global_declarations (void);
540 /* In order for the format checking to accept the C frontend
541 diagnostic framework extensions, you must include this file before
542 toplev.h, not after. */
543 #define GCC_DIAG_STYLE __gcc_cdiag__
544 #if GCC_VERSION >= 3005
545 #define ATTRIBUTE_GCC_CDIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m ,n))) ATTRIBUTE_NONNULL(m)
547 #define ATTRIBUTE_GCC_CDIAG(m, n) ATTRIBUTE_NONNULL(m)
550 extern void pedwarn_c90 (const char *, ...) ATTRIBUTE_GCC_CDIAG(1,2);
551 extern void pedwarn_c99 (const char *, ...) ATTRIBUTE_GCC_CDIAG(1,2);
553 #endif /* ! GCC_C_TREE_H */