1 /* This file contains the definitions and documentation for the common
2 tree codes used in the GNU C and C++ compilers (see c-common.def
3 for the standard codes).
4 Copyright (C) 2000 Free Software Foundation, Inc. Written by
5 Benjamin Chelf (chelf@codesourcery.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "splay-tree.h"
39 /* Build a generic statement based on the given type of node and
40 arguments. Similar to `build_nt', except that we set
41 TREE_COMPLEXITY to be the current line number. */
44 build_stmt VPARAMS ((enum tree_code code, ...))
46 #ifndef ANSI_PROTOTYPES
56 #ifndef ANSI_PROTOTYPES
57 code = va_arg (p, enum tree_code);
61 length = TREE_CODE_LENGTH (code);
62 TREE_COMPLEXITY (t) = lineno;
64 for (i = 0; i < length; i++)
65 TREE_OPERAND (t, i) = va_arg (p, tree);
71 /* Some statements, like for-statements or if-statements, require a
72 condition. This condition can be a declaration. If T is such a
73 declaration it is processed, and an expression appropriate to use
74 as the condition is returned. Otherwise, T itself is returned. */
80 if (t && TREE_CODE (t) == TREE_LIST)
82 expand_stmt (TREE_PURPOSE (t));
83 return TREE_VALUE (t);
89 /* Create RTL for the local static variable DECL. */
92 make_rtl_for_local_static (decl)
95 const char *asmspec = NULL;
97 /* If we inlined this variable, we could see it's declaration
99 if (TREE_ASM_WRITTEN (decl))
102 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
104 /* The only way this situaton can occur is if the
105 user specified a name for this DECL using the
106 `attribute' syntax. */
107 asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
108 DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl);
111 rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0);
114 /* Let the back-end know about DECL. */
117 emit_local_var (decl)
120 /* Create RTL for this variable. */
121 if (!DECL_RTL (decl))
123 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
124 /* The user must have specified an assembler name for this
125 variable. Set that up now. */
126 rest_of_decl_compilation
127 (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
128 /*top_level=*/0, /*at_end=*/0);
133 /* Actually do the initialization. */
134 if (stmts_are_full_exprs_p ())
135 expand_start_target_temps ();
137 expand_decl_init (decl);
139 if (stmts_are_full_exprs_p ())
140 expand_end_target_temps ();
143 /* Helper for generating the RTL at the beginning of a scope. */
146 genrtl_do_pushlevel ()
148 emit_line_note (input_filename, lineno);
152 /* Helper for generating the RTL. */
155 genrtl_clear_out_block ()
157 /* If COND wasn't a declaration, clear out the
158 block we made for it and start a new one here so the
159 optimization in expand_end_loop will work. */
160 if (getdecls () == NULL_TREE)
161 genrtl_do_pushlevel ();
164 /* Generate the RTL for DESTINATION, which is a GOTO_STMT. */
167 genrtl_goto_stmt (destination)
170 if (TREE_CODE (destination) == IDENTIFIER_NODE)
173 /* We warn about unused labels with -Wunused. That means we have to
174 mark the used labels as used. */
175 if (TREE_CODE (destination) == LABEL_DECL)
176 TREE_USED (destination) = 1;
178 emit_line_note (input_filename, lineno);
180 if (TREE_CODE (destination) == LABEL_DECL)
182 label_rtx (destination);
183 expand_goto (destination);
186 expand_computed_goto (destination);
189 /* Generate the RTL for EXPR, which is an EXPR_STMT. */
192 genrtl_expr_stmt (expr)
195 if (expr != NULL_TREE)
197 emit_line_note (input_filename, lineno);
199 if (stmts_are_full_exprs_p ())
200 expand_start_target_temps ();
202 lang_expand_expr_stmt (expr);
204 if (stmts_are_full_exprs_p ())
205 expand_end_target_temps ();
209 /* Generate the RTL for T, which is a DECL_STMT. */
216 emit_line_note (input_filename, lineno);
217 decl = DECL_STMT_DECL (t);
218 /* If this is a declaration for an automatic local
219 variable, initialize it. Note that we might also see a
220 declaration for a namespace-scope object (declared with
221 `extern'). We don't have to handle the initialization
222 of those objects here; they can only be declarations,
223 rather than definitions. */
224 if (TREE_CODE (decl) == VAR_DECL
225 && !TREE_STATIC (decl)
226 && !DECL_EXTERNAL (decl))
228 /* Let the back-end know about this variable. */
229 if (!anon_aggr_type_p (TREE_TYPE (decl)))
230 emit_local_var (decl);
232 expand_anon_union_decl (decl, NULL_TREE,
233 DECL_ANON_UNION_ELEMS (decl));
235 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
237 if (DECL_ARTIFICIAL (decl) && ! TREE_USED (decl))
238 /* Do not emit unused decls. This is not just an
239 optimization. We really do not want to emit
240 __PRETTY_FUNCTION__ etc, if they're never used. */
241 DECL_IGNORED_P (decl) = 1;
243 make_rtl_for_local_static (decl);
247 /* Generate the RTL for T, which is an IF_STMT. */
254 genrtl_do_pushlevel ();
255 cond = expand_cond (IF_COND (t));
256 emit_line_note (input_filename, lineno);
257 expand_start_cond (cond, 0);
259 expand_stmt (THEN_CLAUSE (t));
262 expand_start_else ();
263 expand_stmt (ELSE_CLAUSE (t));
268 /* Generate the RTL for T, which is a WHILE_STMT. */
271 genrtl_while_stmt (t)
276 emit_line_note (input_filename, lineno);
277 expand_start_loop (1);
278 genrtl_do_pushlevel ();
280 cond = expand_cond (WHILE_COND (t));
281 emit_line_note (input_filename, lineno);
282 expand_exit_loop_if_false (0, cond);
283 genrtl_clear_out_block ();
285 expand_stmt (WHILE_BODY (t));
290 /* Generate the RTL for T, which is a DO_STMT. */
298 emit_line_note (input_filename, lineno);
299 expand_start_loop_continue_elsewhere (1);
301 expand_stmt (DO_BODY (t));
303 expand_loop_continue_here ();
305 cond = expand_cond (DO_COND (t));
306 emit_line_note (input_filename, lineno);
307 expand_exit_loop_if_false (0, cond);
311 /* Build the node for a return statement and return it. */
314 build_return_stmt (expr)
317 return (build_stmt (RETURN_STMT, expr));
320 /* Generate the RTL for EXPR, which is a RETURN_STMT. */
323 genrtl_return_stmt (expr)
326 emit_line_note (input_filename, lineno);
327 c_expand_return (expr);
330 /* Generate the RTL for T, which is a FOR_STMT. */
338 if (NEW_FOR_SCOPE_P (t))
339 genrtl_do_pushlevel ();
341 expand_stmt (FOR_INIT_STMT (t));
344 emit_line_note (input_filename, lineno);
345 expand_start_loop_continue_elsewhere (1);
346 genrtl_do_pushlevel ();
347 cond = expand_cond (FOR_COND (t));
348 emit_line_note (input_filename, lineno);
350 expand_exit_loop_if_false (0, cond);
351 genrtl_clear_out_block ();
354 expand_stmt (FOR_BODY (t));
356 emit_line_note (input_filename, lineno);
357 expand_loop_continue_here ();
359 genrtl_expr_stmt (tmp);
363 /* Build a break statement node and return it. */
368 return (build_stmt (BREAK_STMT));
371 /* Generate the RTL for a BREAK_STMT. */
376 emit_line_note (input_filename, lineno);
377 if ( ! expand_exit_something ())
378 error ("break statement not within loop or switch");
381 /* Build a continue statement node and return it. */
384 build_continue_stmt ()
386 return (build_stmt (CONTINUE_STMT));
389 /* Generate the RTL for a CONTINUE_STMT. */
392 genrtl_continue_stmt ()
394 emit_line_note (input_filename, lineno);
395 if (! expand_continue_loop (0))
396 error ("continue statement not within a loop");
399 /* Generate the RTL for T, which is a SCOPE_STMT. */
402 genrtl_scope_stmt (t)
405 if (!SCOPE_NO_CLEANUPS_P (t))
407 if (SCOPE_BEGIN_P (t))
408 expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t),
409 SCOPE_STMT_BLOCK (t));
410 else if (SCOPE_END_P (t))
411 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t), 0);
413 else if (!SCOPE_NULLIFIED_P (t))
415 rtx note = emit_note (NULL,
417 ? NOTE_INSN_BLOCK_BEG
418 : NOTE_INSN_BLOCK_END));
419 NOTE_BLOCK (note) = SCOPE_STMT_BLOCK (t);
423 /* Generate the RTL for T, which is a SWITCH_STMT. */
426 genrtl_switch_stmt (t)
430 genrtl_do_pushlevel ();
432 cond = expand_cond (SWITCH_COND (t));
433 if (cond != error_mark_node)
435 emit_line_note (input_filename, lineno);
436 c_expand_start_case (cond);
439 /* The code is in error, but we don't want expand_end_case to
441 c_expand_start_case (boolean_false_node);
443 expand_stmt (SWITCH_BODY (t));
445 expand_end_case (cond);
448 /* Create a CASE_LABEL tree node and return it. */
451 build_case_label (low_value, high_value)
455 return build_stmt (CASE_LABEL, low_value, high_value);
459 /* Generate the RTL for a CASE_LABEL. */
462 genrtl_case_label (low_value, high_value)
466 do_case (low_value, high_value);
469 /* Generate the RTL for T, which is a COMPOUND_STMT. */
472 genrtl_compound_stmt (t)
475 /* If this is the outermost block of the function, declare the
476 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
478 && !current_function_name_declared ()
479 && !COMPOUND_STMT_NO_SCOPE (t))
481 set_current_function_name_declared (1);
482 declare_function_name ();
485 expand_stmt (COMPOUND_BODY (t));
488 /* Generate the RTL for an ASM_STMT. */
491 genrtl_asm_stmt (cv_qualifier, string, output_operands,
492 input_operands, clobbers)
495 tree output_operands;
499 if (TREE_CHAIN (string))
500 string = combine_strings (string);
502 if (cv_qualifier != NULL_TREE
503 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
505 warning ("%s qualifier ignored on asm",
506 IDENTIFIER_POINTER (cv_qualifier));
507 cv_qualifier = NULL_TREE;
510 emit_line_note (input_filename, lineno);
511 if (output_operands != NULL_TREE || input_operands != NULL_TREE
512 || clobbers != NULL_TREE)
513 c_expand_asm_operands (string, output_operands,
516 cv_qualifier != NULL_TREE,
517 input_filename, lineno);
522 /* Generate the RTL for a DECL_CLEANUP. */
525 genrtl_decl_cleanup (decl, cleanup)
529 if (!decl || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
530 expand_decl_cleanup (decl, cleanup);
533 /* Generate the RTL for the statement T, its substatements, and any
534 other statements at its nesting level. */
541 rval = lang_expand_stmt (t);