1 /* Definitions for c-common.c.
2 Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Usage of TREE_LANG_FLAG_?:
23 0: COMPOUND_STMT_NO_SCOPE (in COMPOUND_STMT).
24 TREE_NEGATED_INT (in INTEGER_CST).
25 IDENTIFIER_MARKED (used by search routines).
26 SCOPE_BEGIN_P (in SCOPE_STMT)
27 DECL_PRETTY_FUNCTION_P (in VAR_DECL)
28 NEW_FOR_SCOPE_P (in FOR_STMT)
29 1: C_DECLARED_LABEL_FLAG (in LABEL_DECL)
30 STMT_IS_FULL_EXPR_P (in _STMT)
31 2: STMT_LINENO_FOR_FN_P (in _STMT)
32 3: SCOPE_NO_CLEANUPS_P (in SCOPE_STMT)
33 4: SCOPE_PARTIAL_P (in SCOPE_STMT)
36 /* Reserved identifiers. */
48 /* The first seven are in the order of most frequently used,
49 as emiprically determined. */
51 RID_EXTERN = RID_FIRST_MODIFIER,
80 #define NORID RID_UNUSED
82 /* The elements of `ridpointers' are identifier nodes for the reserved
83 type names and storage classes. It is indexed by a RID_... value. */
84 extern tree *ridpointers;
86 /* Standard named or nameless data types of the C compiler. */
91 CTI_SIGNED_WCHAR_TYPE,
92 CTI_UNSIGNED_WCHAR_TYPE,
94 CTI_C_SIZE_TYPE, /* For format checking only. */
95 CTI_SIGNED_SIZE_TYPE, /* For format checking only. */
96 CTI_UNSIGNED_PTRDIFF_TYPE, /* For format checking only. */
97 CTI_WIDEST_INT_LIT_TYPE,
98 CTI_WIDEST_UINT_LIT_TYPE,
101 CTI_WCHAR_ARRAY_TYPE,
104 CTI_CONST_STRING_TYPE,
109 CTI_DEFAULT_FUNCTION_TYPE,
115 CTI_PTR_FTYPE_SIZETYPE,
117 CTI_G77_INTEGER_TYPE,
118 CTI_G77_UINTEGER_TYPE,
119 CTI_G77_LONGINT_TYPE,
120 CTI_G77_ULONGINT_TYPE,
122 /* These are not types, but we have to look them up all the time. */
124 CTI_PRETTY_FUNCTION_ID,
130 #define wchar_type_node c_global_trees[CTI_WCHAR_TYPE]
131 #define signed_wchar_type_node c_global_trees[CTI_SIGNED_WCHAR_TYPE]
132 #define unsigned_wchar_type_node c_global_trees[CTI_UNSIGNED_WCHAR_TYPE]
133 #define wint_type_node c_global_trees[CTI_WINT_TYPE]
134 #define c_size_type_node c_global_trees[CTI_C_SIZE_TYPE]
135 #define signed_size_type_node c_global_trees[CTI_SIGNED_SIZE_TYPE]
136 #define unsigned_ptrdiff_type_node c_global_trees[CTI_UNSIGNED_PTRDIFF_TYPE]
137 #define widest_integer_literal_type_node c_global_trees[CTI_WIDEST_INT_LIT_TYPE]
138 #define widest_unsigned_literal_type_node c_global_trees[CTI_WIDEST_UINT_LIT_TYPE]
140 #define boolean_type_node c_global_trees[CTI_BOOLEAN_TYPE]
141 #define boolean_true_node c_global_trees[CTI_BOOLEAN_TRUE]
142 #define boolean_false_node c_global_trees[CTI_BOOLEAN_FALSE]
144 #define char_array_type_node c_global_trees[CTI_CHAR_ARRAY_TYPE]
145 #define wchar_array_type_node c_global_trees[CTI_WCHAR_ARRAY_TYPE]
146 #define int_array_type_node c_global_trees[CTI_INT_ARRAY_TYPE]
147 #define string_type_node c_global_trees[CTI_STRING_TYPE]
148 #define const_string_type_node c_global_trees[CTI_CONST_STRING_TYPE]
150 #define default_function_type c_global_trees[CTI_DEFAULT_FUNCTION_TYPE]
151 #define void_list_node c_global_trees[CTI_VOID_LIST]
152 #define void_ftype c_global_trees[CTI_VOID_FTYPE]
153 #define void_ftype_ptr c_global_trees[CTI_VOID_FTYPE_PTR]
154 #define int_ftype_int c_global_trees[CTI_INT_FTYPE_INT]
155 #define ptr_ftype_sizetype c_global_trees[CTI_PTR_FTYPE_SIZETYPE]
157 /* g77 integer types, which which must be kept in sync with f/com.h */
158 #define g77_integer_type_node c_global_trees[CTI_G77_INTEGER_TYPE]
159 #define g77_uinteger_type_node c_global_trees[CTI_G77_UINTEGER_TYPE]
160 #define g77_longint_type_node c_global_trees[CTI_G77_LONGINT_TYPE]
161 #define g77_ulongint_type_node c_global_trees[CTI_G77_ULONGINT_TYPE]
163 #define function_id_node c_global_trees[CTI_FUNCTION_ID]
164 #define pretty_function_id_node c_global_trees[CTI_PRETTY_FUNCTION_ID]
165 #define func_id_node c_global_trees[CTI_FUNC_ID]
167 extern tree c_global_trees[CTI_MAX];
169 typedef enum c_language_kind
171 clk_c, /* A dialect of C: K&R C, ANSI/ISO C89, C2000,
173 clk_cplusplus, /* ANSI/ISO C++ */
174 clk_objective_c /* Objective C */
178 /* The variant of the C language being processed. Each C language
179 front-end defines this variable. */
181 extern c_language_kind c_language;
183 /* Nonzero means give string constants the type `const char *', rather
186 extern int flag_const_strings;
188 /* Warn about *printf or *scanf format/argument anomalies. */
190 extern int warn_format;
192 /* Nonzero means do some things the same way PCC does. */
194 extern int flag_traditional;
196 /* Nonzero means enable C89 Amendment 1 features, other than digraphs. */
198 extern int flag_isoc94;
200 /* Nonzero means use the ISO C99 dialect of C. */
202 extern int flag_isoc99;
204 /* Nonzero means accept digraphs. */
206 extern int flag_digraphs;
208 /* Nonzero means environment is hosted (i.e., not freestanding) */
210 extern int flag_hosted;
212 /* Nonzero means add default format_arg attributes for functions not
215 extern int flag_noniso_default_format_attributes;
217 /* Nonzero means warn about suggesting putting in ()'s. */
219 extern int warn_parentheses;
221 /* Warn if a type conversion is done that might have confusing results. */
223 extern int warn_conversion;
225 /* C types are partitioned into three subsets: object, function, and
227 #define C_TYPE_OBJECT_P(type) \
228 (TREE_CODE (type) != FUNCTION_TYPE && TYPE_SIZE (type))
230 #define C_TYPE_INCOMPLETE_P(type) \
231 (TREE_CODE (type) != FUNCTION_TYPE && TYPE_SIZE (type) == 0)
233 #define C_TYPE_FUNCTION_P(type) \
234 (TREE_CODE (type) == FUNCTION_TYPE)
236 /* For convenience we define a single macro to identify the class of
237 object or incomplete types. */
238 #define C_TYPE_OBJECT_OR_INCOMPLETE_P(type) \
239 (!C_TYPE_FUNCTION_P (type))
241 /* Record in each node resulting from a binary operator
242 what operator was specified for it. */
243 #define C_EXP_ORIGINAL_CODE(exp) ((enum tree_code) TREE_COMPLEXITY (exp))
245 /* Pointer to function to generate the VAR_DECL for __FUNCTION__ etc.
246 ID is the identifier to use, NAME is the string.
247 TYPE_DEP indicates whether it depends on type of the function or not
248 (i.e. __PRETTY_FUNCTION__). */
250 extern tree (*make_fname_decl) PARAMS ((tree, const char *, int));
252 extern void declare_function_name PARAMS ((void));
253 extern void decl_attributes PARAMS ((tree, tree, tree));
254 extern void init_function_format_info PARAMS ((void));
255 extern void check_function_format PARAMS ((tree, tree, tree));
256 extern void c_apply_type_quals_to_decl PARAMS ((int, tree));
257 /* Print an error message for invalid operands to arith operation CODE.
258 NOP_EXPR is used as a special case (see truthvalue_conversion). */
259 extern void binary_op_error PARAMS ((enum tree_code));
260 extern void c_expand_expr_stmt PARAMS ((tree));
261 extern void c_expand_start_cond PARAMS ((tree, int, int));
262 extern void c_expand_start_else PARAMS ((void));
263 extern void c_expand_end_cond PARAMS ((void));
264 /* Validate the expression after `case' and apply default promotions. */
265 extern tree check_case_value PARAMS ((tree));
266 /* Concatenate a list of STRING_CST nodes into one STRING_CST. */
267 extern tree combine_strings PARAMS ((tree));
268 extern void constant_expression_warning PARAMS ((tree));
269 extern tree convert_and_check PARAMS ((tree, tree));
270 extern void overflow_warning PARAMS ((tree));
271 extern void unsigned_conversion_warning PARAMS ((tree, tree));
273 /* Read the rest of the current #-directive line. */
275 extern char *get_directive_line PARAMS ((void));
276 #define GET_DIRECTIVE_LINE() get_directive_line ()
278 extern char *get_directive_line PARAMS ((FILE *));
279 #define GET_DIRECTIVE_LINE() get_directive_line (finput)
282 /* Subroutine of build_binary_op, used for comparison operations.
283 See if the operands have both been converted from subword integer types
284 and, if so, perhaps change them both back to their original type. */
285 extern tree shorten_compare PARAMS ((tree *, tree *, tree *, enum tree_code *));
286 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
287 or validate its data type for an `if' or `while' statement or ?..: exp. */
288 extern tree truthvalue_conversion PARAMS ((tree));
289 extern tree type_for_mode PARAMS ((enum machine_mode, int));
290 extern tree type_for_size PARAMS ((unsigned, int));
292 extern unsigned int min_precision PARAMS ((tree, int));
294 /* Add qualifiers to a type, in the fashion for C. */
295 extern tree c_build_qualified_type PARAMS ((tree, int));
297 /* Build tree nodes and builtin functions common to both C and C++ language
299 extern void c_common_nodes_and_builtins PARAMS ((int, int, int));
301 extern tree build_va_arg PARAMS ((tree, tree));
303 /* Nonzero if the type T promotes to itself.
304 ANSI C states explicitly the list of types that promote;
305 in particular, short promotes to int even if they have the same width. */
306 #define C_PROMOTING_INTEGER_TYPE_P(t) \
307 (TREE_CODE ((t)) == INTEGER_TYPE \
308 && (TYPE_MAIN_VARIANT (t) == char_type_node \
309 || TYPE_MAIN_VARIANT (t) == signed_char_type_node \
310 || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node \
311 || TYPE_MAIN_VARIANT (t) == short_integer_type_node \
312 || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node))
314 extern int self_promoting_args_p PARAMS ((tree));
315 extern tree simple_type_promotes_to PARAMS ((tree));
317 /* These macros provide convenient access to the various _STMT nodes
318 created when parsing template declarations. */
320 /* IF_STMT accessors. These give access to the condtion of the if
321 statement, the then block of the if statement, and the else block
322 of the if stsatement if it exists. */
323 #define IF_COND(NODE) TREE_OPERAND (IF_STMT_CHECK (NODE), 0)
324 #define THEN_CLAUSE(NODE) TREE_OPERAND (IF_STMT_CHECK (NODE), 1)
325 #define ELSE_CLAUSE(NODE) TREE_OPERAND (IF_STMT_CHECK (NODE), 2)
327 /* WHILE_STMT accessors. These give access to the condtion of the
328 while statement and the body of the while statement, respectively. */
329 #define WHILE_COND(NODE) TREE_OPERAND (WHILE_STMT_CHECK (NODE), 0)
330 #define WHILE_BODY(NODE) TREE_OPERAND (WHILE_STMT_CHECK (NODE), 1)
332 /* DO_STMT accessors. These give access to the condition of the do
333 statement and the body of the do statement, respectively. */
334 #define DO_COND(NODE) TREE_OPERAND (DO_STMT_CHECK (NODE), 0)
335 #define DO_BODY(NODE) TREE_OPERAND (DO_STMT_CHECK (NODE), 1)
337 /* RETURN_STMT accessor. This gives the expression associated with a
339 #define RETURN_EXPR(NODE) TREE_OPERAND (RETURN_STMT_CHECK (NODE), 0)
341 /* EXPR_STMT accessor. This gives the expression associated with an
342 expression statement. */
343 #define EXPR_STMT_EXPR(NODE) TREE_OPERAND (EXPR_STMT_CHECK (NODE), 0)
345 /* FOR_STMT accessors. These give access to the init statement,
346 condition, update expression, and body of the for statement,
348 #define FOR_INIT_STMT(NODE) TREE_OPERAND (FOR_STMT_CHECK (NODE), 0)
349 #define FOR_COND(NODE) TREE_OPERAND (FOR_STMT_CHECK (NODE), 1)
350 #define FOR_EXPR(NODE) TREE_OPERAND (FOR_STMT_CHECK (NODE), 2)
351 #define FOR_BODY(NODE) TREE_OPERAND (FOR_STMT_CHECK (NODE), 3)
353 /* SWITCH_STMT accessors. These give access to the condition and body
354 of the switch statement, respectively. */
355 #define SWITCH_COND(NODE) TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 0)
356 #define SWITCH_BODY(NODE) TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 1)
358 /* CASE_LABEL accessors. These give access to the high and low values
359 of a case label, respectively. */
360 #define CASE_LOW(NODE) TREE_OPERAND (CASE_LABEL_CHECK (NODE), 0)
361 #define CASE_HIGH(NODE) TREE_OPERAND (CASE_LABEL_CHECK (NODE), 1)
363 /* GOTO_STMT accessor. This gives access to the label associated with
365 #define GOTO_DESTINATION(NODE) TREE_OPERAND (GOTO_STMT_CHECK (NODE), 0)
367 /* COMPOUND_STMT accessor. This gives access to the TREE_LIST of
368 statements assocated with a compound statement. The result is the
369 first statement in the list. Succeeding nodes can be acccessed by
370 calling TREE_CHAIN on a node in the list. */
371 #define COMPOUND_BODY(NODE) TREE_OPERAND (COMPOUND_STMT_CHECK (NODE), 0)
373 /* ASM_STMT accessors. ASM_STRING returns a STRING_CST for the
374 instruction (e.g., "mov x, y"). ASM_OUTPUTS, ASM_INPUTS, and
375 ASM_CLOBBERS represent the outputs, inputs, and clobbers for the
377 #define ASM_CV_QUAL(NODE) TREE_OPERAND (ASM_STMT_CHECK (NODE), 0)
378 #define ASM_STRING(NODE) TREE_OPERAND (ASM_STMT_CHECK (NODE), 1)
379 #define ASM_OUTPUTS(NODE) TREE_OPERAND (ASM_STMT_CHECK (NODE), 2)
380 #define ASM_INPUTS(NODE) TREE_OPERAND (ASM_STMT_CHECK (NODE), 3)
381 #define ASM_CLOBBERS(NODE) TREE_OPERAND (ASM_STMT_CHECK (NODE), 4)
383 /* DECL_STMT accessor. This gives access to the DECL associated with
384 the given declaration statement. */
385 #define DECL_STMT_DECL(NODE) TREE_OPERAND (DECL_STMT_CHECK (NODE), 0)
387 /* STMT_EXPR accessor. */
388 #define STMT_EXPR_STMT(NODE) TREE_OPERAND (STMT_EXPR_CHECK (NODE), 0)
390 /* LABEL_STMT accessor. This gives access to the label associated with
391 the given label statement. */
392 #define LABEL_STMT_LABEL(NODE) TREE_OPERAND (LABEL_STMT_CHECK (NODE), 0)
394 /* Nonzero if this SCOPE_STMT is for the beginning of a scope. */
395 #define SCOPE_BEGIN_P(NODE) \
396 (TREE_LANG_FLAG_0 (SCOPE_STMT_CHECK (NODE)))
398 /* Nonzero if this SCOPE_STMT is for the end of a scope. */
399 #define SCOPE_END_P(NODE) \
400 (!SCOPE_BEGIN_P (SCOPE_STMT_CHECK (NODE)))
402 /* The BLOCK containing the declarations contained in this scope. */
403 #define SCOPE_STMT_BLOCK(NODE) \
404 (TREE_OPERAND (SCOPE_STMT_CHECK (NODE), 0))
406 /* Nonzero for a SCOPE_STMT if there were no variables in this scope. */
407 #define SCOPE_NULLIFIED_P(NODE) \
408 (SCOPE_STMT_BLOCK ((NODE)) == NULL_TREE)
410 /* Nonzero for a SCOPE_STMT which represents a lexical scope, but
411 which should be treated as non-existant from the point of view of
412 running cleanup actions. */
413 #define SCOPE_NO_CLEANUPS_P(NODE) \
414 (TREE_LANG_FLAG_3 (SCOPE_STMT_CHECK (NODE)))
416 /* Nonzero for a SCOPE_STMT if this statement is for a partial scope.
424 there is (implicitly) a new scope after `l', even though there are
425 no curly braces. In particular, when we hit the goto, we must
426 destroy s2 and then re-construct it. For the implicit scope,
427 SCOPE_PARTIAL_P will be set. */
428 #define SCOPE_PARTIAL_P(NODE) \
429 (TREE_LANG_FLAG_4 (SCOPE_STMT_CHECK (NODE)))
431 /* Nonzero for an ASM_STMT if the assembly statement is volatile. */
432 #define ASM_VOLATILE_P(NODE) \
433 (ASM_CV_QUAL (ASM_STMT_CHECK (NODE)) != NULL_TREE)
435 /* The line-number at which a statement began. But if
436 STMT_LINENO_FOR_FN_P does holds, then this macro gives the
437 line number for the end of the current function instead. */
438 #define STMT_LINENO(NODE) \
439 (TREE_COMPLEXITY ((NODE)))
441 /* If non-zero, the STMT_LINENO for NODE is the line at which the
443 #define STMT_LINENO_FOR_FN_P(NODE) \
444 (TREE_LANG_FLAG_2 ((NODE)))
446 /* Nonzero if we want the new ISO rules for pushing a new scope for `for'
447 initialization variables. */
448 #define NEW_FOR_SCOPE_P(NODE) (TREE_LANG_FLAG_0 (NODE))
450 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
453 C_DUMMY_TREE_CODE = LAST_AND_UNUSED_TREE_CODE,
454 #include "c-common.def"
460 extern void add_c_tree_codes PARAMS ((void));
461 extern void genrtl_do_pushlevel PARAMS ((void));
462 extern void genrtl_clear_out_block PARAMS ((void));
463 extern void genrtl_goto_stmt PARAMS ((tree));
464 extern void genrtl_expr_stmt PARAMS ((tree));
465 extern void genrtl_decl_stmt PARAMS ((tree));
466 extern void genrtl_if_stmt PARAMS ((tree));
467 extern void genrtl_while_stmt PARAMS ((tree));
468 extern void genrtl_do_stmt PARAMS ((tree));
469 extern void genrtl_return_stmt PARAMS ((tree));
470 extern void genrtl_for_stmt PARAMS ((tree));
471 extern void genrtl_break_stmt PARAMS ((void));
472 extern void genrtl_continue_stmt PARAMS ((void));
473 extern void genrtl_scope_stmt PARAMS ((tree));
474 extern void genrtl_switch_stmt PARAMS ((tree));
475 extern void genrtl_case_label PARAMS ((tree, tree));
476 extern void genrtl_compound_stmt PARAMS ((tree));
477 extern void genrtl_asm_stmt PARAMS ((tree, tree,
480 extern void genrtl_decl_cleanup PARAMS ((tree, tree));
481 extern int stmts_are_full_exprs_p PARAMS ((void));
482 typedef void (*expand_expr_stmt_fn) PARAMS ((tree));
483 extern expand_expr_stmt_fn lang_expand_expr_stmt;
484 extern int anon_aggr_type_p PARAMS ((tree));
486 /* For a VAR_DECL that is an anonymous union, these are the various
487 sub-variables that make up the anonymous union. */
488 #define DECL_ANON_UNION_ELEMS(NODE) DECL_ARGUMENTS ((NODE))
490 extern void emit_local_var PARAMS ((tree));
491 extern void make_rtl_for_local_static PARAMS ((tree));
492 extern tree expand_cond PARAMS ((tree));
493 extern tree expand_stmt PARAMS ((tree));
494 extern tree lang_expand_stmt PARAMS ((tree));
495 extern void c_expand_return PARAMS ((tree));
496 extern tree c_expand_start_case PARAMS ((tree));
497 extern void do_case PARAMS ((tree, tree));
498 extern tree build_stmt PARAMS ((enum tree_code, ...));
499 extern tree build_case_label PARAMS ((tree, tree));
500 extern tree build_continue_stmt PARAMS ((void));
501 extern tree build_break_stmt PARAMS ((void));
502 extern tree build_return_stmt PARAMS ((tree));
504 #define COMPOUND_STMT_NO_SCOPE(NODE) TREE_LANG_FLAG_0 (NODE)
506 extern void c_expand_asm_operands PARAMS ((tree, tree, tree, tree, int, const char *, int));
507 extern int current_function_name_declared PARAMS ((void));
508 extern void set_current_function_name_declared PARAMS ((int));
510 /* These functions must be defined by each front-end which implements
511 a variant of the C language. They are used in c-common.c. */
513 extern tree build_unary_op PARAMS ((enum tree_code,
515 extern tree build_binary_op PARAMS ((enum tree_code,
517 extern int lvalue_p PARAMS ((tree));
518 extern tree default_conversion PARAMS ((tree));
520 /* Given two integer or real types, return the type for their sum.
521 Given two compatible ANSI C types, returns the merged type. */
523 extern tree common_type PARAMS ((tree, tree));