2011-07-21 François Dumont <francois.cppdevs@free.fr>
[official-gcc.git] / gcc / c-family / c-common.h
blob13aae0f3ecc5a92d9e8622b7486fb2c615a0a404
1 /* Definitions for c-common.c.
2 Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_C_COMMON_H
23 #define GCC_C_COMMON_H
25 #include "splay-tree.h"
26 #include "cpplib.h"
27 #include "ggc.h"
29 /* In order for the format checking to accept the C frontend
30 diagnostic framework extensions, you must include this file before
31 diagnostic-core.h, not after. The C front end formats are a subset of those
32 for C++, so they are the appropriate set to use in common code;
33 cp-tree.h overrides this for C++. */
34 #if defined(GCC_DIAGNOSTIC_CORE_H)
35 #error \
36 In order for the format checking to accept the C front end diagnostic \
37 framework extensions, you must include this file before diagnostic-core.h \
38 never after.
39 #endif
40 #ifndef GCC_DIAG_STYLE
41 #define GCC_DIAG_STYLE __gcc_cdiag__
42 #endif
43 #include "diagnostic-core.h"
45 /* Usage of TREE_LANG_FLAG_?:
46 0: TREE_NEGATED_INT (in INTEGER_CST).
47 IDENTIFIER_MARKED (used by search routines).
48 DECL_PRETTY_FUNCTION_P (in VAR_DECL)
49 C_MAYBE_CONST_EXPR_INT_OPERANDS (in C_MAYBE_CONST_EXPR, for C)
50 1: C_DECLARED_LABEL_FLAG (in LABEL_DECL)
51 STATEMENT_LIST_STMT_EXPR (in STATEMENT_LIST)
52 C_MAYBE_CONST_EXPR_NON_CONST (in C_MAYBE_CONST_EXPR, for C)
53 2: unused
54 3: STATEMENT_LIST_HAS_LABEL (in STATEMENT_LIST)
55 4: unused
58 /* Reserved identifiers. This is the union of all the keywords for C,
59 C++, and Objective-C. All the type modifiers have to be in one
60 block at the beginning, because they are used as mask bits. There
61 are 27 type modifiers; if we add many more we will have to redesign
62 the mask mechanism. */
64 enum rid
66 /* Modifiers: */
67 /* C, in empirical order of frequency. */
68 RID_STATIC = 0,
69 RID_UNSIGNED, RID_LONG, RID_CONST, RID_EXTERN,
70 RID_REGISTER, RID_TYPEDEF, RID_SHORT, RID_INLINE,
71 RID_VOLATILE, RID_SIGNED, RID_AUTO, RID_RESTRICT,
73 /* C extensions */
74 RID_COMPLEX, RID_THREAD, RID_SAT,
76 /* C++ */
77 RID_FRIEND, RID_VIRTUAL, RID_EXPLICIT, RID_EXPORT, RID_MUTABLE,
79 /* ObjC ("PQ" reserved words - they do not appear after a '@' and
80 are keywords only in specific contexts) */
81 RID_IN, RID_OUT, RID_INOUT, RID_BYCOPY, RID_BYREF, RID_ONEWAY,
83 /* ObjC ("PATTR" reserved words - they do not appear after a '@'
84 and are keywords only as property attributes) */
85 RID_GETTER, RID_SETTER,
86 RID_READONLY, RID_READWRITE,
87 RID_ASSIGN, RID_RETAIN, RID_COPY,
88 RID_NONATOMIC,
90 /* C (reserved and imaginary types not implemented, so any use is a
91 syntax error) */
92 RID_IMAGINARY,
94 /* C */
95 RID_INT, RID_CHAR, RID_FLOAT, RID_DOUBLE, RID_VOID,
96 RID_INT128,
97 RID_ENUM, RID_STRUCT, RID_UNION, RID_IF, RID_ELSE,
98 RID_WHILE, RID_DO, RID_FOR, RID_SWITCH, RID_CASE,
99 RID_DEFAULT, RID_BREAK, RID_CONTINUE, RID_RETURN, RID_GOTO,
100 RID_SIZEOF,
102 /* C extensions */
103 RID_ASM, RID_TYPEOF, RID_ALIGNOF, RID_ATTRIBUTE, RID_VA_ARG,
104 RID_EXTENSION, RID_IMAGPART, RID_REALPART, RID_LABEL, RID_CHOOSE_EXPR,
105 RID_TYPES_COMPATIBLE_P,
106 RID_DFLOAT32, RID_DFLOAT64, RID_DFLOAT128,
107 RID_FRACT, RID_ACCUM,
109 /* This means to warn that this is a C++ keyword, and then treat it
110 as a normal identifier. */
111 RID_CXX_COMPAT_WARN,
113 /* Too many ways of getting the name of a function as a string */
114 RID_FUNCTION_NAME, RID_PRETTY_FUNCTION_NAME, RID_C99_FUNCTION_NAME,
116 /* C++ (some of these are keywords in Objective-C as well, but only
117 if they appear after a '@') */
118 RID_BOOL, RID_WCHAR, RID_CLASS,
119 RID_PUBLIC, RID_PRIVATE, RID_PROTECTED,
120 RID_TEMPLATE, RID_NULL, RID_CATCH,
121 RID_DELETE, RID_FALSE, RID_NAMESPACE,
122 RID_NEW, RID_OFFSETOF, RID_OPERATOR,
123 RID_THIS, RID_THROW, RID_TRUE,
124 RID_TRY, RID_TYPENAME, RID_TYPEID,
125 RID_USING, RID_CHAR16, RID_CHAR32,
127 /* casts */
128 RID_CONSTCAST, RID_DYNCAST, RID_REINTCAST, RID_STATCAST,
130 /* C++ extensions */
131 RID_HAS_NOTHROW_ASSIGN, RID_HAS_NOTHROW_CONSTRUCTOR,
132 RID_HAS_NOTHROW_COPY, RID_HAS_TRIVIAL_ASSIGN,
133 RID_HAS_TRIVIAL_CONSTRUCTOR, RID_HAS_TRIVIAL_COPY,
134 RID_HAS_TRIVIAL_DESTRUCTOR, RID_HAS_VIRTUAL_DESTRUCTOR,
135 RID_IS_ABSTRACT, RID_IS_BASE_OF,
136 RID_IS_CONVERTIBLE_TO, RID_IS_CLASS,
137 RID_IS_EMPTY, RID_IS_ENUM,
138 RID_IS_LITERAL_TYPE, RID_IS_POD,
139 RID_IS_POLYMORPHIC, RID_IS_STD_LAYOUT,
140 RID_IS_TRIVIAL, RID_IS_UNION,
141 RID_UNDERLYING_TYPE,
143 /* C++0x */
144 RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT,
146 /* Objective-C ("AT" reserved words - they are only keywords when
147 they follow '@') */
148 RID_AT_ENCODE, RID_AT_END,
149 RID_AT_CLASS, RID_AT_ALIAS, RID_AT_DEFS,
150 RID_AT_PRIVATE, RID_AT_PROTECTED, RID_AT_PUBLIC, RID_AT_PACKAGE,
151 RID_AT_PROTOCOL, RID_AT_SELECTOR,
152 RID_AT_THROW, RID_AT_TRY, RID_AT_CATCH,
153 RID_AT_FINALLY, RID_AT_SYNCHRONIZED,
154 RID_AT_OPTIONAL, RID_AT_REQUIRED, RID_AT_PROPERTY,
155 RID_AT_SYNTHESIZE, RID_AT_DYNAMIC,
156 RID_AT_INTERFACE,
157 RID_AT_IMPLEMENTATION,
159 /* Named address support, mapping the keyword to a particular named address
160 number. Named address space 0 is reserved for the generic address. If
161 there are more than 254 named addresses, the addr_space_t type will need
162 to be grown from an unsigned char to unsigned short. */
163 RID_ADDR_SPACE_0, /* generic address */
164 RID_ADDR_SPACE_1,
165 RID_ADDR_SPACE_2,
166 RID_ADDR_SPACE_3,
167 RID_ADDR_SPACE_4,
168 RID_ADDR_SPACE_5,
169 RID_ADDR_SPACE_6,
170 RID_ADDR_SPACE_7,
171 RID_ADDR_SPACE_8,
172 RID_ADDR_SPACE_9,
173 RID_ADDR_SPACE_10,
174 RID_ADDR_SPACE_11,
175 RID_ADDR_SPACE_12,
176 RID_ADDR_SPACE_13,
177 RID_ADDR_SPACE_14,
178 RID_ADDR_SPACE_15,
180 RID_FIRST_ADDR_SPACE = RID_ADDR_SPACE_0,
181 RID_LAST_ADDR_SPACE = RID_ADDR_SPACE_15,
183 RID_MAX,
185 RID_FIRST_MODIFIER = RID_STATIC,
186 RID_LAST_MODIFIER = RID_ONEWAY,
188 RID_FIRST_CXX0X = RID_CONSTEXPR,
189 RID_LAST_CXX0X = RID_STATIC_ASSERT,
190 RID_FIRST_AT = RID_AT_ENCODE,
191 RID_LAST_AT = RID_AT_IMPLEMENTATION,
192 RID_FIRST_PQ = RID_IN,
193 RID_LAST_PQ = RID_ONEWAY,
194 RID_FIRST_PATTR = RID_GETTER,
195 RID_LAST_PATTR = RID_NONATOMIC
198 #define OBJC_IS_AT_KEYWORD(rid) \
199 ((unsigned int) (rid) >= (unsigned int) RID_FIRST_AT && \
200 (unsigned int) (rid) <= (unsigned int) RID_LAST_AT)
202 #define OBJC_IS_PQ_KEYWORD(rid) \
203 ((unsigned int) (rid) >= (unsigned int) RID_FIRST_PQ && \
204 (unsigned int) (rid) <= (unsigned int) RID_LAST_PQ)
206 #define OBJC_IS_PATTR_KEYWORD(rid) \
207 ((unsigned int) (rid) >= (unsigned int) RID_FIRST_PATTR && \
208 (unsigned int) (rid) <= (unsigned int) RID_LAST_PATTR)
210 /* OBJC_IS_CXX_KEYWORD recognizes the 'CXX_OBJC' keywords (such as
211 'class') which are shared in a subtle way between Objective-C and
212 C++. When the lexer is lexing in Objective-C/Objective-C++, if it
213 finds '@' followed by one of these identifiers (eg, '@class'), it
214 recognizes the whole as an Objective-C keyword. If the identifier
215 is found elsewhere, it follows the rules of the C/C++ language.
217 #define OBJC_IS_CXX_KEYWORD(rid) \
218 (rid == RID_CLASS \
219 || rid == RID_PUBLIC || rid == RID_PROTECTED || rid == RID_PRIVATE \
220 || rid == RID_TRY || rid == RID_THROW || rid == RID_CATCH)
222 /* The elements of `ridpointers' are identifier nodes for the reserved
223 type names and storage classes. It is indexed by a RID_... value. */
224 extern GTY ((length ("(int) RID_MAX"))) tree *ridpointers;
226 /* Standard named or nameless data types of the C compiler. */
228 enum c_tree_index
230 CTI_CHAR16_TYPE,
231 CTI_CHAR32_TYPE,
232 CTI_WCHAR_TYPE,
233 CTI_UNDERLYING_WCHAR_TYPE,
234 CTI_WINT_TYPE,
235 CTI_SIGNED_SIZE_TYPE, /* For format checking only. */
236 CTI_UNSIGNED_PTRDIFF_TYPE, /* For format checking only. */
237 CTI_INTMAX_TYPE,
238 CTI_UINTMAX_TYPE,
239 CTI_WIDEST_INT_LIT_TYPE,
240 CTI_WIDEST_UINT_LIT_TYPE,
242 /* Types for <stdint.h>, that may not be defined on all
243 targets. */
244 CTI_SIG_ATOMIC_TYPE,
245 CTI_INT8_TYPE,
246 CTI_INT16_TYPE,
247 CTI_INT32_TYPE,
248 CTI_INT64_TYPE,
249 CTI_UINT8_TYPE,
250 CTI_UINT16_TYPE,
251 CTI_UINT32_TYPE,
252 CTI_UINT64_TYPE,
253 CTI_INT_LEAST8_TYPE,
254 CTI_INT_LEAST16_TYPE,
255 CTI_INT_LEAST32_TYPE,
256 CTI_INT_LEAST64_TYPE,
257 CTI_UINT_LEAST8_TYPE,
258 CTI_UINT_LEAST16_TYPE,
259 CTI_UINT_LEAST32_TYPE,
260 CTI_UINT_LEAST64_TYPE,
261 CTI_INT_FAST8_TYPE,
262 CTI_INT_FAST16_TYPE,
263 CTI_INT_FAST32_TYPE,
264 CTI_INT_FAST64_TYPE,
265 CTI_UINT_FAST8_TYPE,
266 CTI_UINT_FAST16_TYPE,
267 CTI_UINT_FAST32_TYPE,
268 CTI_UINT_FAST64_TYPE,
269 CTI_INTPTR_TYPE,
270 CTI_UINTPTR_TYPE,
272 CTI_CHAR_ARRAY_TYPE,
273 CTI_CHAR16_ARRAY_TYPE,
274 CTI_CHAR32_ARRAY_TYPE,
275 CTI_WCHAR_ARRAY_TYPE,
276 CTI_INT_ARRAY_TYPE,
277 CTI_STRING_TYPE,
278 CTI_CONST_STRING_TYPE,
280 /* Type for boolean expressions (bool in C++, int in C). */
281 CTI_TRUTHVALUE_TYPE,
282 CTI_TRUTHVALUE_TRUE,
283 CTI_TRUTHVALUE_FALSE,
285 CTI_DEFAULT_FUNCTION_TYPE,
287 /* These are not types, but we have to look them up all the time. */
288 CTI_FUNCTION_NAME_DECL,
289 CTI_PRETTY_FUNCTION_NAME_DECL,
290 CTI_C99_FUNCTION_NAME_DECL,
291 CTI_SAVED_FUNCTION_NAME_DECLS,
293 CTI_VOID_ZERO,
295 CTI_NULL,
297 CTI_MAX
300 #define C_CPP_HASHNODE(id) \
301 (&(((struct c_common_identifier *) (id))->node))
302 #define C_RID_CODE(id) \
303 ((enum rid) (((struct c_common_identifier *) (id))->node.rid_code))
304 #define C_SET_RID_CODE(id, code) \
305 (((struct c_common_identifier *) (id))->node.rid_code = (unsigned char) code)
307 /* Identifier part common to the C front ends. Inherits from
308 tree_identifier, despite appearances. */
309 struct GTY(()) c_common_identifier {
310 struct tree_common common;
311 struct cpp_hashnode node;
314 /* An entry in the reserved keyword table. */
316 struct c_common_resword
318 const char *const word;
319 ENUM_BITFIELD(rid) const rid : 16;
320 const unsigned int disable : 16;
323 /* Extra cpp_ttype values for C++. */
325 /* A token type for keywords, as opposed to ordinary identifiers. */
326 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
328 /* A token type for template-ids. If a template-id is processed while
329 parsing tentatively, it is replaced with a CPP_TEMPLATE_ID token;
330 the value of the CPP_TEMPLATE_ID is whatever was returned by
331 cp_parser_template_id. */
332 #define CPP_TEMPLATE_ID ((enum cpp_ttype) (CPP_KEYWORD + 1))
334 /* A token type for nested-name-specifiers. If a
335 nested-name-specifier is processed while parsing tentatively, it is
336 replaced with a CPP_NESTED_NAME_SPECIFIER token; the value of the
337 CPP_NESTED_NAME_SPECIFIER is whatever was returned by
338 cp_parser_nested_name_specifier_opt. */
339 #define CPP_NESTED_NAME_SPECIFIER ((enum cpp_ttype) (CPP_TEMPLATE_ID + 1))
341 /* A token type for pre-parsed C++0x decltype. */
342 #define CPP_DECLTYPE ((enum cpp_ttype) (CPP_NESTED_NAME_SPECIFIER + 1))
344 /* The number of token types, including C++-specific ones. */
345 #define N_CP_TTYPES ((int) (CPP_DECLTYPE + 1))
347 /* Disable mask. Keywords are disabled if (reswords[i].disable &
348 mask) is _true_. Thus for keywords which are present in all
349 languages the disable field is zero. */
351 #define D_CONLY 0x001 /* C only (not in C++). */
352 #define D_CXXONLY 0x002 /* C++ only (not in C). */
353 #define D_C99 0x004 /* In C, C99 only. */
354 #define D_CXX0X 0x008 /* In C++, C++0X only. */
355 #define D_EXT 0x010 /* GCC extension. */
356 #define D_EXT89 0x020 /* GCC extension incorporated in C99. */
357 #define D_ASM 0x040 /* Disabled by -fno-asm. */
358 #define D_OBJC 0x080 /* In Objective C and neither C nor C++. */
359 #define D_CXX_OBJC 0x100 /* In Objective C, and C++, but not C. */
360 #define D_CXXWARN 0x200 /* In C warn with -Wcxx-compat. */
362 /* The reserved keyword table. */
363 extern const struct c_common_resword c_common_reswords[];
365 /* The number of items in the reserved keyword table. */
366 extern const unsigned int num_c_common_reswords;
368 #define char16_type_node c_global_trees[CTI_CHAR16_TYPE]
369 #define char32_type_node c_global_trees[CTI_CHAR32_TYPE]
370 #define wchar_type_node c_global_trees[CTI_WCHAR_TYPE]
371 #define underlying_wchar_type_node c_global_trees[CTI_UNDERLYING_WCHAR_TYPE]
372 #define wint_type_node c_global_trees[CTI_WINT_TYPE]
373 #define signed_size_type_node c_global_trees[CTI_SIGNED_SIZE_TYPE]
374 #define unsigned_ptrdiff_type_node c_global_trees[CTI_UNSIGNED_PTRDIFF_TYPE]
375 #define intmax_type_node c_global_trees[CTI_INTMAX_TYPE]
376 #define uintmax_type_node c_global_trees[CTI_UINTMAX_TYPE]
377 #define widest_integer_literal_type_node c_global_trees[CTI_WIDEST_INT_LIT_TYPE]
378 #define widest_unsigned_literal_type_node c_global_trees[CTI_WIDEST_UINT_LIT_TYPE]
380 #define sig_atomic_type_node c_global_trees[CTI_SIG_ATOMIC_TYPE]
381 #define int8_type_node c_global_trees[CTI_INT8_TYPE]
382 #define int16_type_node c_global_trees[CTI_INT16_TYPE]
383 #define int32_type_node c_global_trees[CTI_INT32_TYPE]
384 #define int64_type_node c_global_trees[CTI_INT64_TYPE]
385 #define uint8_type_node c_global_trees[CTI_UINT8_TYPE]
386 #define uint16_type_node c_global_trees[CTI_UINT16_TYPE]
387 #define c_uint32_type_node c_global_trees[CTI_UINT32_TYPE]
388 #define c_uint64_type_node c_global_trees[CTI_UINT64_TYPE]
389 #define int_least8_type_node c_global_trees[CTI_INT_LEAST8_TYPE]
390 #define int_least16_type_node c_global_trees[CTI_INT_LEAST16_TYPE]
391 #define int_least32_type_node c_global_trees[CTI_INT_LEAST32_TYPE]
392 #define int_least64_type_node c_global_trees[CTI_INT_LEAST64_TYPE]
393 #define uint_least8_type_node c_global_trees[CTI_UINT_LEAST8_TYPE]
394 #define uint_least16_type_node c_global_trees[CTI_UINT_LEAST16_TYPE]
395 #define uint_least32_type_node c_global_trees[CTI_UINT_LEAST32_TYPE]
396 #define uint_least64_type_node c_global_trees[CTI_UINT_LEAST64_TYPE]
397 #define int_fast8_type_node c_global_trees[CTI_INT_FAST8_TYPE]
398 #define int_fast16_type_node c_global_trees[CTI_INT_FAST16_TYPE]
399 #define int_fast32_type_node c_global_trees[CTI_INT_FAST32_TYPE]
400 #define int_fast64_type_node c_global_trees[CTI_INT_FAST64_TYPE]
401 #define uint_fast8_type_node c_global_trees[CTI_UINT_FAST8_TYPE]
402 #define uint_fast16_type_node c_global_trees[CTI_UINT_FAST16_TYPE]
403 #define uint_fast32_type_node c_global_trees[CTI_UINT_FAST32_TYPE]
404 #define uint_fast64_type_node c_global_trees[CTI_UINT_FAST64_TYPE]
405 #define intptr_type_node c_global_trees[CTI_INTPTR_TYPE]
406 #define uintptr_type_node c_global_trees[CTI_UINTPTR_TYPE]
408 #define truthvalue_type_node c_global_trees[CTI_TRUTHVALUE_TYPE]
409 #define truthvalue_true_node c_global_trees[CTI_TRUTHVALUE_TRUE]
410 #define truthvalue_false_node c_global_trees[CTI_TRUTHVALUE_FALSE]
412 #define char_array_type_node c_global_trees[CTI_CHAR_ARRAY_TYPE]
413 #define char16_array_type_node c_global_trees[CTI_CHAR16_ARRAY_TYPE]
414 #define char32_array_type_node c_global_trees[CTI_CHAR32_ARRAY_TYPE]
415 #define wchar_array_type_node c_global_trees[CTI_WCHAR_ARRAY_TYPE]
416 #define int_array_type_node c_global_trees[CTI_INT_ARRAY_TYPE]
417 #define string_type_node c_global_trees[CTI_STRING_TYPE]
418 #define const_string_type_node c_global_trees[CTI_CONST_STRING_TYPE]
420 #define default_function_type c_global_trees[CTI_DEFAULT_FUNCTION_TYPE]
422 #define function_name_decl_node c_global_trees[CTI_FUNCTION_NAME_DECL]
423 #define pretty_function_name_decl_node c_global_trees[CTI_PRETTY_FUNCTION_NAME_DECL]
424 #define c99_function_name_decl_node c_global_trees[CTI_C99_FUNCTION_NAME_DECL]
425 #define saved_function_name_decls c_global_trees[CTI_SAVED_FUNCTION_NAME_DECLS]
427 /* A node for `((void) 0)'. */
428 #define void_zero_node c_global_trees[CTI_VOID_ZERO]
430 /* The node for C++ `__null'. */
431 #define null_node c_global_trees[CTI_NULL]
433 extern GTY(()) tree c_global_trees[CTI_MAX];
435 /* In a RECORD_TYPE, a sorted array of the fields of the type, not a
436 tree for size reasons. */
437 struct GTY((variable_size)) sorted_fields_type {
438 int len;
439 tree GTY((length ("%h.len"))) elts[1];
442 /* Mark which labels are explicitly declared.
443 These may be shadowed, and may be referenced from nested functions. */
444 #define C_DECLARED_LABEL_FLAG(label) TREE_LANG_FLAG_1 (label)
446 typedef enum c_language_kind
448 clk_c = 0, /* C90, C94 or C99 */
449 clk_objc = 1, /* clk_c with ObjC features. */
450 clk_cxx = 2, /* ANSI/ISO C++ */
451 clk_objcxx = 3 /* clk_cxx with ObjC features. */
453 c_language_kind;
455 /* To test for a specific language use c_language, defined by each
456 front end. For "ObjC features" or "not C++" use the macros. */
457 extern c_language_kind c_language;
459 #define c_dialect_cxx() ((c_language & clk_cxx) != 0)
460 #define c_dialect_objc() ((c_language & clk_objc) != 0)
462 /* The various name of operator that appears in error messages. */
463 typedef enum ref_operator {
464 /* NULL */
465 RO_NULL,
466 /* array indexing */
467 RO_ARRAY_INDEXING,
468 /* unary * */
469 RO_UNARY_STAR,
470 /* -> */
471 RO_ARROW,
472 /* implicit conversion */
473 RO_IMPLICIT_CONVERSION
474 } ref_operator;
476 /* Information about a statement tree. */
478 struct GTY(()) stmt_tree_s {
479 /* A stack of statement lists being collected. */
480 VEC(tree,gc) *x_cur_stmt_list;
482 /* In C++, Nonzero if we should treat statements as full
483 expressions. In particular, this variable is no-zero if at the
484 end of a statement we should destroy any temporaries created
485 during that statement. Similarly, if, at the end of a block, we
486 should destroy any local variables in this block. Normally, this
487 variable is nonzero, since those are the normal semantics of
488 C++.
490 However, in order to represent aggregate initialization code as
491 tree structure, we use statement-expressions. The statements
492 within the statement expression should not result in cleanups
493 being run until the entire enclosing statement is complete.
495 This flag has no effect in C. */
496 int stmts_are_full_exprs_p;
499 typedef struct stmt_tree_s *stmt_tree;
501 /* Global state pertinent to the current function. Some C dialects
502 extend this structure with additional fields. */
504 struct GTY(()) c_language_function {
505 /* While we are parsing the function, this contains information
506 about the statement-tree that we are building. */
507 struct stmt_tree_s x_stmt_tree;
510 #define stmt_list_stack (current_stmt_tree ()->x_cur_stmt_list)
512 /* When building a statement-tree, this is the current statement list
513 being collected. We define it in this convoluted way, rather than
514 using VEC_last, because it must be an lvalue. */
516 #define cur_stmt_list \
517 (*(VEC_address (tree, stmt_list_stack) \
518 + VEC_length (tree, stmt_list_stack) - 1))
520 #define building_stmt_list_p() (!VEC_empty (tree, stmt_list_stack))
522 /* Language-specific hooks. */
524 /* If non-NULL, this function is called after a precompile header file
525 is loaded. */
526 extern void (*lang_post_pch_load) (void);
528 extern void push_file_scope (void);
529 extern void pop_file_scope (void);
530 extern stmt_tree current_stmt_tree (void);
531 extern tree push_stmt_list (void);
532 extern tree pop_stmt_list (tree);
533 extern tree add_stmt (tree);
534 extern void push_cleanup (tree, tree, bool);
535 extern tree pushdecl_top_level (tree);
536 extern tree pushdecl (tree);
537 extern tree build_modify_expr (location_t, tree, tree, enum tree_code,
538 location_t, tree, tree);
539 extern tree build_indirect_ref (location_t, tree, ref_operator);
541 extern int c_expand_decl (tree);
543 extern int field_decl_cmp (const void *, const void *);
544 extern void resort_sorted_fields (void *, void *, gt_pointer_operator,
545 void *);
546 extern bool has_c_linkage (const_tree decl);
548 /* Switches common to the C front ends. */
550 /* Nonzero means don't output line number information. */
552 extern char flag_no_line_commands;
554 /* Nonzero causes -E output not to be done, but directives such as
555 #define that have side effects are still obeyed. */
557 extern char flag_no_output;
559 /* Nonzero means dump macros in some fashion; contains the 'D', 'M',
560 'N' or 'U' of the command line switch. */
562 extern char flag_dump_macros;
564 /* Nonzero means pass #include lines through to the output. */
566 extern char flag_dump_includes;
568 /* Nonzero means process PCH files while preprocessing. */
570 extern bool flag_pch_preprocess;
572 /* The file name to which we should write a precompiled header, or
573 NULL if no header will be written in this compile. */
575 extern const char *pch_file;
577 /* Nonzero if an ISO standard was selected. It rejects macros in the
578 user's namespace. */
580 extern int flag_iso;
582 /* Warn about #pragma directives that are not recognized. */
584 extern int warn_unknown_pragmas; /* Tri state variable. */
586 /* Warn about format/argument anomalies in calls to formatted I/O functions
587 (*printf, *scanf, strftime, strfmon, etc.). */
589 extern int warn_format;
592 /* C/ObjC language option variables. */
595 /* Nonzero means allow type mismatches in conditional expressions;
596 just make their values `void'. */
598 extern int flag_cond_mismatch;
600 /* Nonzero means enable C89 Amendment 1 features. */
602 extern int flag_isoc94;
604 /* Nonzero means use the ISO C99 (or C1X) dialect of C. */
606 extern int flag_isoc99;
608 /* Nonzero means use the ISO C1X dialect of C. */
610 extern int flag_isoc1x;
612 /* Nonzero means that we have builtin functions, and main is an int. */
614 extern int flag_hosted;
616 /* ObjC language option variables. */
619 /* Tells the compiler that this is a special run. Do not perform any
620 compiling, instead we are to test some platform dependent features
621 and output a C header file with appropriate definitions. */
623 extern int print_struct_values;
625 /* Tells the compiler what is the constant string class for ObjC. */
627 extern const char *constant_string_class_name;
630 /* C++ language option variables. */
633 /* Nonzero means generate separate instantiation control files and
634 juggle them at link time. */
636 extern int flag_use_repository;
638 /* The supported C++ dialects. */
640 enum cxx_dialect {
641 /* C++98 */
642 cxx98,
643 /* Experimental features that are likely to become part of
644 C++0x. */
645 cxx0x
648 /* The C++ dialect being used. C++98 is the default. */
649 extern enum cxx_dialect cxx_dialect;
651 /* Maximum template instantiation depth. This limit is rather
652 arbitrary, but it exists to limit the time it takes to notice
653 excessively recursive template instantiations. */
655 extern int max_tinst_depth;
657 /* Nonzero means that we should not issue warnings about problems that
658 occur when the code is executed, because the code being processed
659 is not expected to be executed. This is set during parsing. This
660 is used for cases like sizeof() and "0 ? a : b". This is a count,
661 not a bool, because unexecuted expressions can nest. */
663 extern int c_inhibit_evaluation_warnings;
665 /* Whether lexing has been completed, so subsequent preprocessor
666 errors should use the compiler's input_location. */
668 extern bool done_lexing;
670 /* C types are partitioned into three subsets: object, function, and
671 incomplete types. */
672 #define C_TYPE_OBJECT_P(type) \
673 (TREE_CODE (type) != FUNCTION_TYPE && TYPE_SIZE (type))
675 #define C_TYPE_INCOMPLETE_P(type) \
676 (TREE_CODE (type) != FUNCTION_TYPE && TYPE_SIZE (type) == 0)
678 #define C_TYPE_FUNCTION_P(type) \
679 (TREE_CODE (type) == FUNCTION_TYPE)
681 /* For convenience we define a single macro to identify the class of
682 object or incomplete types. */
683 #define C_TYPE_OBJECT_OR_INCOMPLETE_P(type) \
684 (!C_TYPE_FUNCTION_P (type))
686 struct visibility_flags
688 unsigned inpragma : 1; /* True when in #pragma GCC visibility. */
689 unsigned inlines_hidden : 1; /* True when -finlineshidden in effect. */
692 /* Global visibility options. */
693 extern struct visibility_flags visibility_options;
695 /* Attribute table common to the C front ends. */
696 extern const struct attribute_spec c_common_attribute_table[];
697 extern const struct attribute_spec c_common_format_attribute_table[];
699 /* Pointer to function to lazily generate the VAR_DECL for __FUNCTION__ etc.
700 ID is the identifier to use, NAME is the string.
701 TYPE_DEP indicates whether it depends on type of the function or not
702 (i.e. __PRETTY_FUNCTION__). */
704 extern tree (*make_fname_decl) (location_t, tree, int);
706 /* In c-decl.c and cp/tree.c. FIXME. */
707 extern void c_register_addr_space (const char *str, addr_space_t as);
709 /* In c-common.c. */
710 extern bool in_late_binary_op;
711 extern const char *c_addr_space_name (addr_space_t as);
712 extern tree identifier_global_value (tree);
713 extern void record_builtin_type (enum rid, const char *, tree);
714 extern tree build_void_list_node (void);
715 extern void start_fname_decls (void);
716 extern void finish_fname_decls (void);
717 extern const char *fname_as_string (int);
718 extern tree fname_decl (location_t, unsigned, tree);
720 extern void check_function_arguments (const_tree, int, tree *);
721 extern void check_function_arguments_recurse (void (*)
722 (void *, tree,
723 unsigned HOST_WIDE_INT),
724 void *, tree,
725 unsigned HOST_WIDE_INT);
726 extern bool check_builtin_function_arguments (tree, int, tree *);
727 extern void check_function_format (tree, int, tree *);
728 extern void set_Wformat (int);
729 extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
730 extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
731 extern bool attribute_takes_identifier_p (const_tree);
732 extern bool c_common_handle_option (size_t, const char *, int, int, location_t,
733 const struct cl_option_handlers *);
734 extern bool default_handle_c_option (size_t, const char *, int);
735 extern tree c_common_type_for_mode (enum machine_mode, int);
736 extern tree c_common_type_for_size (unsigned int, int);
737 extern tree c_common_fixed_point_type_for_size (unsigned int, unsigned int,
738 int, int);
739 extern tree c_common_unsigned_type (tree);
740 extern tree c_common_signed_type (tree);
741 extern tree c_common_signed_or_unsigned_type (int, tree);
742 extern void c_common_init_ts (void);
743 extern tree c_build_bitfield_integer_type (unsigned HOST_WIDE_INT, int);
744 extern bool decl_with_nonnull_addr_p (const_tree);
745 extern tree c_fully_fold (tree, bool, bool *);
746 extern tree decl_constant_value_for_optimization (tree);
747 extern tree c_wrap_maybe_const (tree, bool);
748 extern tree c_save_expr (tree);
749 extern tree c_common_truthvalue_conversion (location_t, tree);
750 extern void c_apply_type_quals_to_decl (int, tree);
751 extern tree c_sizeof_or_alignof_type (location_t, tree, bool, int);
752 extern tree c_alignof_expr (location_t, tree);
753 /* Print an error message for invalid operands to arith operation CODE.
754 NOP_EXPR is used as a special case (see truthvalue_conversion). */
755 extern void binary_op_error (location_t, enum tree_code, tree, tree);
756 extern tree fix_string_type (tree);
757 extern void constant_expression_warning (tree);
758 extern void constant_expression_error (tree);
759 extern bool strict_aliasing_warning (tree, tree, tree);
760 extern void warnings_for_convert_and_check (tree, tree, tree);
761 extern tree convert_and_check (tree, tree);
762 extern void overflow_warning (location_t, tree);
763 extern void warn_logical_operator (location_t, enum tree_code, tree,
764 enum tree_code, tree, enum tree_code, tree);
765 extern void check_main_parameter_types (tree decl);
766 extern bool c_determine_visibility (tree);
767 extern bool same_scalar_type_ignoring_signedness (tree, tree);
768 extern void mark_valid_location_for_stdc_pragma (bool);
769 extern bool valid_location_for_stdc_pragma_p (void);
770 extern void set_float_const_decimal64 (void);
771 extern void clear_float_const_decimal64 (void);
772 extern bool float_const_decimal64_p (void);
774 extern bool keyword_begins_type_specifier (enum rid);
775 extern bool keyword_is_storage_class_specifier (enum rid);
776 extern bool keyword_is_type_qualifier (enum rid);
777 extern bool keyword_is_decl_specifier (enum rid);
779 #define c_sizeof(LOC, T) c_sizeof_or_alignof_type (LOC, T, true, 1)
780 #define c_alignof(LOC, T) c_sizeof_or_alignof_type (LOC, T, false, 1)
782 /* Subroutine of build_binary_op, used for certain operations. */
783 extern tree shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise);
785 /* Subroutine of build_binary_op, used for comparison operations.
786 See if the operands have both been converted from subword integer types
787 and, if so, perhaps change them both back to their original type. */
788 extern tree shorten_compare (tree *, tree *, tree *, enum tree_code *);
790 extern tree pointer_int_sum (location_t, enum tree_code, tree, tree);
792 /* Add qualifiers to a type, in the fashion for C. */
793 extern tree c_build_qualified_type (tree, int);
795 /* Build tree nodes and builtin functions common to both C and C++ language
796 frontends. */
797 extern void c_common_nodes_and_builtins (void);
799 extern void disable_builtin_function (const char *);
801 extern void set_compound_literal_name (tree decl);
803 extern tree build_va_arg (location_t, tree, tree);
805 extern const unsigned int c_family_lang_mask;
806 extern unsigned int c_common_option_lang_mask (void);
807 extern void c_common_initialize_diagnostics (diagnostic_context *);
808 extern bool c_common_complain_wrong_lang_p (const struct cl_option *);
809 extern void c_common_init_options_struct (struct gcc_options *);
810 extern void c_common_init_options (unsigned int, struct cl_decoded_option *);
811 extern bool c_common_post_options (const char **);
812 extern bool c_common_init (void);
813 extern void c_common_finish (void);
814 extern void c_common_parse_file (void);
815 extern alias_set_type c_common_get_alias_set (tree);
816 extern void c_register_builtin_type (tree, const char*);
817 extern bool c_promoting_integer_type_p (const_tree);
818 extern int self_promoting_args_p (const_tree);
819 extern tree strip_pointer_operator (tree);
820 extern tree strip_pointer_or_array_types (tree);
821 extern HOST_WIDE_INT c_common_to_target_charset (HOST_WIDE_INT);
823 /* This is the basic parsing function. */
824 extern void c_parse_file (void);
826 extern void warn_for_omitted_condop (location_t, tree);
828 /* These macros provide convenient access to the various _STMT nodes. */
830 /* Nonzero if a given STATEMENT_LIST represents the outermost binding
831 if a statement expression. */
832 #define STATEMENT_LIST_STMT_EXPR(NODE) \
833 TREE_LANG_FLAG_1 (STATEMENT_LIST_CHECK (NODE))
835 /* Nonzero if a label has been added to the statement list. */
836 #define STATEMENT_LIST_HAS_LABEL(NODE) \
837 TREE_LANG_FLAG_3 (STATEMENT_LIST_CHECK (NODE))
839 /* C_MAYBE_CONST_EXPR accessors. */
840 #define C_MAYBE_CONST_EXPR_PRE(NODE) \
841 TREE_OPERAND (C_MAYBE_CONST_EXPR_CHECK (NODE), 0)
842 #define C_MAYBE_CONST_EXPR_EXPR(NODE) \
843 TREE_OPERAND (C_MAYBE_CONST_EXPR_CHECK (NODE), 1)
844 #define C_MAYBE_CONST_EXPR_INT_OPERANDS(NODE) \
845 TREE_LANG_FLAG_0 (C_MAYBE_CONST_EXPR_CHECK (NODE))
846 #define C_MAYBE_CONST_EXPR_NON_CONST(NODE) \
847 TREE_LANG_FLAG_1 (C_MAYBE_CONST_EXPR_CHECK (NODE))
848 #define EXPR_INT_CONST_OPERANDS(EXPR) \
849 (INTEGRAL_TYPE_P (TREE_TYPE (EXPR)) \
850 && (TREE_CODE (EXPR) == INTEGER_CST \
851 || (TREE_CODE (EXPR) == C_MAYBE_CONST_EXPR \
852 && C_MAYBE_CONST_EXPR_INT_OPERANDS (EXPR))))
854 /* In a FIELD_DECL, nonzero if the decl was originally a bitfield. */
855 #define DECL_C_BIT_FIELD(NODE) \
856 (DECL_LANG_FLAG_4 (FIELD_DECL_CHECK (NODE)) == 1)
857 #define SET_DECL_C_BIT_FIELD(NODE) \
858 (DECL_LANG_FLAG_4 (FIELD_DECL_CHECK (NODE)) = 1)
859 #define CLEAR_DECL_C_BIT_FIELD(NODE) \
860 (DECL_LANG_FLAG_4 (FIELD_DECL_CHECK (NODE)) = 0)
862 extern tree do_case (location_t, tree, tree);
863 extern tree build_stmt (location_t, enum tree_code, ...);
864 extern tree build_real_imag_expr (location_t, enum tree_code, tree);
866 /* These functions must be defined by each front-end which implements
867 a variant of the C language. They are used in c-common.c. */
869 extern tree build_unary_op (location_t, enum tree_code, tree, int);
870 extern tree build_binary_op (location_t, enum tree_code, tree, tree, int);
871 extern tree perform_integral_promotions (tree);
873 /* These functions must be defined by each front-end which implements
874 a variant of the C language. They are used by port files. */
876 extern tree default_conversion (tree);
878 /* Given two integer or real types, return the type for their sum.
879 Given two compatible ANSI C types, returns the merged type. */
881 extern tree common_type (tree, tree);
883 extern tree decl_constant_value (tree);
885 /* Handle increment and decrement of boolean types. */
886 extern tree boolean_increment (enum tree_code, tree);
888 extern int case_compare (splay_tree_key, splay_tree_key);
890 extern tree c_add_case_label (location_t, splay_tree, tree, tree, tree, tree);
892 extern void c_do_switch_warnings (splay_tree, location_t, tree, tree);
894 extern tree build_function_call (location_t, tree, tree);
896 extern tree build_function_call_vec (location_t, tree,
897 VEC(tree,gc) *, VEC(tree,gc) *);
899 extern tree resolve_overloaded_builtin (location_t, tree, VEC(tree,gc) *);
901 extern tree finish_label_address_expr (tree, location_t);
903 /* Same function prototype, but the C and C++ front ends have
904 different implementations. Used in c-common.c. */
905 extern tree lookup_label (tree);
906 extern tree lookup_name (tree);
907 extern bool lvalue_p (const_tree);
909 extern bool vector_targets_convertible_p (const_tree t1, const_tree t2);
910 extern bool vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note);
912 extern rtx c_expand_expr (tree, rtx, enum machine_mode, int, rtx *);
914 extern void init_c_lex (void);
916 extern void c_cpp_builtins (cpp_reader *);
917 extern void c_cpp_builtins_optimize_pragma (cpp_reader *, tree, tree);
918 extern bool c_cpp_error (cpp_reader *, int, int, location_t, unsigned int,
919 const char *, va_list *)
920 ATTRIBUTE_GCC_DIAG(6,0);
922 extern bool parse_optimize_options (tree, bool);
924 /* Positive if an implicit `extern "C"' scope has just been entered;
925 negative if such a scope has just been exited. */
926 extern GTY(()) int pending_lang_change;
928 /* Information recorded about each file examined during compilation. */
930 struct c_fileinfo
932 int time; /* Time spent in the file. */
934 /* Flags used only by C++.
935 INTERFACE_ONLY nonzero means that we are in an "interface" section
936 of the compiler. INTERFACE_UNKNOWN nonzero means we cannot trust
937 the value of INTERFACE_ONLY. If INTERFACE_UNKNOWN is zero and
938 INTERFACE_ONLY is zero, it means that we are responsible for
939 exporting definitions that others might need. */
940 short interface_only;
941 short interface_unknown;
944 struct c_fileinfo *get_fileinfo (const char *);
945 extern void dump_time_statistics (void);
947 extern bool c_dump_tree (void *, tree);
949 extern void verify_sequence_points (tree);
951 extern tree fold_offsetof (tree, tree);
953 /* Places where an lvalue, or modifiable lvalue, may be required.
954 Used to select diagnostic messages in lvalue_error and
955 readonly_error. */
956 enum lvalue_use {
957 lv_assign,
958 lv_increment,
959 lv_decrement,
960 lv_addressof,
961 lv_asm
964 extern void readonly_error (tree, enum lvalue_use);
965 extern void lvalue_error (location_t, enum lvalue_use);
966 extern void invalid_indirection_error (location_t, tree, ref_operator);
968 extern int complete_array_type (tree *, tree, bool);
970 extern tree builtin_type_for_size (int, bool);
972 extern void c_common_mark_addressable_vec (tree);
974 extern void warn_array_subscript_with_type_char (tree);
975 extern void warn_about_parentheses (enum tree_code,
976 enum tree_code, tree,
977 enum tree_code, tree);
978 extern void warn_for_unused_label (tree label);
979 extern void warn_for_div_by_zero (location_t, tree divisor);
980 extern void warn_for_sign_compare (location_t,
981 tree orig_op0, tree orig_op1,
982 tree op0, tree op1,
983 tree result_type,
984 enum tree_code resultcode);
985 extern void do_warn_double_promotion (tree, tree, tree, const char *,
986 location_t);
987 extern void set_underlying_type (tree x);
988 extern VEC(tree,gc) *make_tree_vector (void);
989 extern void release_tree_vector (VEC(tree,gc) *);
990 extern VEC(tree,gc) *make_tree_vector_single (tree);
991 extern VEC(tree,gc) *make_tree_vector_from_list (tree);
992 extern VEC(tree,gc) *make_tree_vector_copy (const VEC(tree,gc) *);
994 /* In c-gimplify.c */
995 extern void c_genericize (tree);
996 extern int c_gimplify_expr (tree *, gimple_seq *, gimple_seq *);
997 extern tree c_build_bind_expr (location_t, tree, tree);
999 /* In c-pch.c */
1000 extern void pch_init (void);
1001 extern int c_common_valid_pch (cpp_reader *pfile, const char *name, int fd);
1002 extern void c_common_read_pch (cpp_reader *pfile, const char *name, int fd,
1003 const char *orig);
1004 extern void c_common_write_pch (void);
1005 extern void c_common_no_more_pch (void);
1006 extern void c_common_pch_pragma (cpp_reader *pfile, const char *);
1007 extern void c_common_print_pch_checksum (FILE *f);
1009 /* In *-checksum.c */
1010 extern const unsigned char executable_checksum[16];
1012 /* In c-cppbuiltin.c */
1013 extern void builtin_define_std (const char *macro);
1014 extern void builtin_define_with_value (const char *, const char *, int);
1015 extern void c_stddef_cpp_builtins (void);
1016 extern void fe_file_change (const struct line_map *);
1017 extern void c_parse_error (const char *, enum cpp_ttype, tree, unsigned char);
1019 /* In c-ppoutput.c */
1020 extern void init_pp_output (FILE *);
1021 extern void preprocess_file (cpp_reader *);
1022 extern void pp_file_change (const struct line_map *);
1023 extern void pp_dir_change (cpp_reader *, const char *);
1024 extern bool check_missing_format_attribute (tree, tree);
1026 /* In c-omp.c */
1027 extern tree c_finish_omp_master (location_t, tree);
1028 extern tree c_finish_omp_critical (location_t, tree, tree);
1029 extern tree c_finish_omp_ordered (location_t, tree);
1030 extern void c_finish_omp_barrier (location_t);
1031 extern tree c_finish_omp_atomic (location_t, enum tree_code, tree, tree);
1032 extern void c_finish_omp_flush (location_t);
1033 extern void c_finish_omp_taskwait (location_t);
1034 extern tree c_finish_omp_for (location_t, tree, tree, tree, tree, tree, tree);
1035 extern void c_split_parallel_clauses (location_t, tree, tree *, tree *);
1036 extern enum omp_clause_default_kind c_omp_predetermined_sharing (tree);
1038 /* Not in c-omp.c; provided by the front end. */
1039 extern bool c_omp_sharing_predetermined (tree);
1040 extern tree c_omp_remap_decl (tree, bool);
1041 extern void record_types_used_by_current_var_decl (tree);
1043 /* Return next tree in the chain for chain_next walking of tree nodes. */
1044 static inline tree
1045 c_tree_chain_next (tree t)
1047 /* TREE_CHAIN of a type is TYPE_STUB_DECL, which is different
1048 kind of object, never a long chain of nodes. Prefer
1049 TYPE_NEXT_VARIANT for types. */
1050 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPE_COMMON))
1051 return TYPE_NEXT_VARIANT (t);
1052 /* Otherwise, if there is TREE_CHAIN, return it. */
1053 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_COMMON))
1054 return TREE_CHAIN (t);
1055 return NULL;
1058 #endif /* ! GCC_C_COMMON_H */