]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/c-semantics.c
* Makefile.in, alias.c, basic-block.h, bb-reorder.c, bitmap.c,
[thirdparty/gcc.git] / gcc / c-semantics.c
CommitLineData
5c3247a9 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).
efbe600e 4 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
5 Written by Benjamin Chelf (chelf@codesourcery.com).
5c3247a9 6
f12b58b3 7This file is part of GCC.
5c3247a9 8
f12b58b3 9GCC is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 2, or (at your option) any later
12version.
5c3247a9 13
f12b58b3 14GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17for more details.
5c3247a9 18
19You should have received a copy of the GNU General Public License
f12b58b3 20along with GCC; see the file COPYING. If not, write to the Free
21Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2202111-1307, USA. */
5c3247a9 23
24#include "config.h"
25#include "system.h"
26#include "tree.h"
27#include "function.h"
28#include "splay-tree.h"
29#include "varray.h"
30#include "c-common.h"
31#include "except.h"
32#include "toplev.h"
33#include "flags.h"
34#include "ggc.h"
35#include "rtl.h"
2ade676b 36#include "expr.h"
5c3247a9 37#include "output.h"
38#include "timevar.h"
39
41fb2c18 40/* If non-NULL, the address of a language-specific function for
41 expanding statements. */
42void (*lang_expand_stmt) PARAMS ((tree));
43
e41f0d80 44/* If non-NULL, the address of a language-specific function for
45 expanding a DECL_STMT. After the language-independent cases are
46 handled, this function will be called. If this function is not
47 defined, it is assumed that declarations other than those for
48 variables and labels do not require any RTL generation. */
49void (*lang_expand_decl_stmt) PARAMS ((tree));
50
a08e60ae 51/* Create an empty statement tree rooted at T. */
52
53void
54begin_stmt_tree (t)
55 tree *t;
56{
57 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
58 what follows. We remove the extraneous statement in
59 finish_stmt_tree. */
60 *t = build_nt (EXPR_STMT, void_zero_node);
61 last_tree = *t;
62 last_expr_type = NULL_TREE;
63}
64
65/* T is a statement. Add it to the statement-tree. */
66
225ec6aa 67tree
a08e60ae 68add_stmt (t)
69 tree t;
70{
71 /* Add T to the statement-tree. */
72 TREE_CHAIN (last_tree) = t;
73 last_tree = t;
65b7f83f 74
a08e60ae 75 /* When we expand a statement-tree, we must know whether or not the
65b7f83f 76 statements are full-expressions. We record that fact here. */
a08e60ae 77 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p ();
1f1fa73c 78
79 /* Keep track of the number of statements in this function. */
80 if (current_function_decl)
81 ++DECL_NUM_STMTS (current_function_decl);
82
225ec6aa 83 return t;
a08e60ae 84}
85
e41f0d80 86/* Create a declaration statement for the declaration given by the
87 DECL. */
88
89void
90add_decl_stmt (decl)
91 tree decl;
92{
93 tree decl_stmt;
94
95 /* We need the type to last until instantiation time. */
96 decl_stmt = build_stmt (DECL_STMT, decl);
97 add_stmt (decl_stmt);
98}
99
100/* Add a scope-statement to the statement-tree. BEGIN_P indicates
101 whether this statements opens or closes a scope. PARTIAL_P is true
102 for a partial scope, i.e, the scope that begins after a label when
103 an object that needs a cleanup is created. If BEGIN_P is nonzero,
104 returns a new TREE_LIST representing the top of the SCOPE_STMT
105 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
106 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
65b7f83f 107 and whose TREE_PURPOSE is the matching SCOPE_STMT with
e41f0d80 108 SCOPE_BEGIN_P set. */
109
110tree
111add_scope_stmt (begin_p, partial_p)
112 int begin_p;
113 int partial_p;
114{
dfb72f1f 115 tree *stack_ptr = current_scope_stmt_stack ();
e41f0d80 116 tree ss;
dfb72f1f 117 tree top = *stack_ptr;
e41f0d80 118
119 /* Build the statement. */
120 ss = build_stmt (SCOPE_STMT, NULL_TREE);
121 SCOPE_BEGIN_P (ss) = begin_p;
122 SCOPE_PARTIAL_P (ss) = partial_p;
123
124 /* Keep the scope stack up to date. */
125 if (begin_p)
126 {
dfb72f1f 127 top = tree_cons (ss, NULL_TREE, top);
128 *stack_ptr = top;
e41f0d80 129 }
130 else
131 {
e41f0d80 132 TREE_VALUE (top) = ss;
dfb72f1f 133 *stack_ptr = TREE_CHAIN (top);
e41f0d80 134 }
135
136 /* Add the new statement to the statement-tree. */
137 add_stmt (ss);
138
139 return top;
140}
141
a08e60ae 142/* Finish the statement tree rooted at T. */
143
144void
145finish_stmt_tree (t)
146 tree *t;
147{
148 tree stmt;
149
150 /* Remove the fake extra statement added in begin_stmt_tree. */
151 stmt = TREE_CHAIN (*t);
152 *t = stmt;
153 last_tree = NULL_TREE;
154
e41f0d80 155 if (cfun && stmt)
a08e60ae 156 {
157 /* The line-number recorded in the outermost statement in a function
158 is the line number of the end of the function. */
159 STMT_LINENO (stmt) = lineno;
160 STMT_LINENO_FOR_FN_P (stmt) = 1;
161 }
162}
163
389acd0a 164/* Build a generic statement based on the given type of node and
165 arguments. Similar to `build_nt', except that we set
7cad36f4 166 STMT_LINENO to be the current line number. */
167/* ??? This should be obsolete with the lineno_stmt productions
168 in the grammar. */
389acd0a 169
170tree
171build_stmt VPARAMS ((enum tree_code code, ...))
172{
173#ifndef ANSI_PROTOTYPES
174 enum tree_code code;
175#endif
176 va_list p;
177 register tree t;
178 register int length;
179 register int i;
180
181 VA_START (p, code);
182
183#ifndef ANSI_PROTOTYPES
184 code = va_arg (p, enum tree_code);
185#endif
186
187 t = make_node (code);
188 length = TREE_CODE_LENGTH (code);
7cad36f4 189 STMT_LINENO (t) = lineno;
389acd0a 190
191 for (i = 0; i < length; i++)
192 TREE_OPERAND (t, i) = va_arg (p, tree);
193
194 va_end (p);
195 return t;
196}
197
5c3247a9 198/* Some statements, like for-statements or if-statements, require a
199 condition. This condition can be a declaration. If T is such a
200 declaration it is processed, and an expression appropriate to use
201 as the condition is returned. Otherwise, T itself is returned. */
202
203tree
204expand_cond (t)
205 tree t;
206{
207 if (t && TREE_CODE (t) == TREE_LIST)
208 {
209 expand_stmt (TREE_PURPOSE (t));
210 return TREE_VALUE (t);
211 }
212 else
213 return t;
214}
215
216/* Create RTL for the local static variable DECL. */
217
218void
219make_rtl_for_local_static (decl)
220 tree decl;
221{
222 const char *asmspec = NULL;
223
224 /* If we inlined this variable, we could see it's declaration
225 again. */
5ef286c9 226 if (TREE_ASM_WRITTEN (decl))
5c3247a9 227 return;
228
2a472969 229 /* If the DECL_ASSEMBLER_NAME is not the same as the DECL_NAME, then
230 either we already created RTL for this DECL (and since it was a
c25509f2 231 local variable, its DECL_ASSEMBLER_NAME got hacked up to prevent
2a472969 232 clashes with other local statics with the same name by a previous
233 call to make_decl_rtl), or the user explicitly requested a
234 particular assembly name for this variable, using the GNU
235 extension for this purpose:
236
237 int i asm ("j");
238
239 There's no way to know which case we're in, here. But, it turns
240 out we're safe. If there's already RTL, then
241 rest_of_decl_compilation ignores the ASMSPEC parameter, so we
242 may as well not pass it in. If there isn't RTL, then we didn't
243 already create RTL, which means that the modification to
244 DECL_ASSEMBLER_NAME came only via the explicit extension. */
245 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
341ededf 246 && !DECL_RTL_SET_P (decl))
2a472969 247 asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5c3247a9 248
249 rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0);
250}
251
252/* Let the back-end know about DECL. */
253
254void
255emit_local_var (decl)
256 tree decl;
257{
258 /* Create RTL for this variable. */
0e8e37b2 259 if (!DECL_RTL_SET_P (decl))
5c3247a9 260 {
ace65efd 261 if (DECL_C_HARD_REGISTER (decl))
262 /* The user specified an assembler name for this variable.
263 Set that up now. */
5c3247a9 264 rest_of_decl_compilation
265 (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
266 /*top_level=*/0, /*at_end=*/0);
267 else
268 expand_decl (decl);
269 }
270
271 /* Actually do the initialization. */
272 if (stmts_are_full_exprs_p ())
273 expand_start_target_temps ();
274
275 expand_decl_init (decl);
276
277 if (stmts_are_full_exprs_p ())
278 expand_end_target_temps ();
279}
280
2c0e001b 281/* Helper for generating the RTL at the beginning of a scope. */
5c3247a9 282
283void
284genrtl_do_pushlevel ()
285{
286 emit_line_note (input_filename, lineno);
287 clear_last_expr ();
288}
289
2c0e001b 290/* Generate the RTL for DESTINATION, which is a GOTO_STMT. */
5c3247a9 291
292void
293genrtl_goto_stmt (destination)
294 tree destination;
295{
296 if (TREE_CODE (destination) == IDENTIFIER_NODE)
297 abort ();
298
299 /* We warn about unused labels with -Wunused. That means we have to
300 mark the used labels as used. */
301 if (TREE_CODE (destination) == LABEL_DECL)
302 TREE_USED (destination) = 1;
303
304 emit_line_note (input_filename, lineno);
305
306 if (TREE_CODE (destination) == LABEL_DECL)
307 {
308 label_rtx (destination);
309 expand_goto (destination);
310 }
311 else
312 expand_computed_goto (destination);
313}
314
2c0e001b 315/* Generate the RTL for EXPR, which is an EXPR_STMT. */
5c3247a9 316
317void
318genrtl_expr_stmt (expr)
319 tree expr;
320{
321 if (expr != NULL_TREE)
322 {
323 emit_line_note (input_filename, lineno);
324
325 if (stmts_are_full_exprs_p ())
326 expand_start_target_temps ();
327
e41f0d80 328 if (expr != error_mark_node)
329 expand_expr_stmt (expr);
5c3247a9 330
331 if (stmts_are_full_exprs_p ())
332 expand_end_target_temps ();
333 }
334}
335
2c0e001b 336/* Generate the RTL for T, which is a DECL_STMT. */
5c3247a9 337
338void
339genrtl_decl_stmt (t)
340 tree t;
341{
342 tree decl;
343 emit_line_note (input_filename, lineno);
344 decl = DECL_STMT_DECL (t);
345 /* If this is a declaration for an automatic local
346 variable, initialize it. Note that we might also see a
347 declaration for a namespace-scope object (declared with
348 `extern'). We don't have to handle the initialization
349 of those objects here; they can only be declarations,
350 rather than definitions. */
351 if (TREE_CODE (decl) == VAR_DECL
352 && !TREE_STATIC (decl)
353 && !DECL_EXTERNAL (decl))
354 {
355 /* Let the back-end know about this variable. */
356 if (!anon_aggr_type_p (TREE_TYPE (decl)))
357 emit_local_var (decl);
358 else
359 expand_anon_union_decl (decl, NULL_TREE,
360 DECL_ANON_UNION_ELEMS (decl));
361 }
362 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
65b7f83f 363 make_rtl_for_local_static (decl);
e41f0d80 364 else if (TREE_CODE (decl) == LABEL_DECL
365 && C_DECLARED_LABEL_FLAG (decl))
366 declare_nonlocal_label (decl);
367 else if (lang_expand_decl_stmt)
368 (*lang_expand_decl_stmt) (t);
5c3247a9 369}
370
2c0e001b 371/* Generate the RTL for T, which is an IF_STMT. */
5c3247a9 372
373void
374genrtl_if_stmt (t)
375 tree t;
376{
377 tree cond;
378 genrtl_do_pushlevel ();
379 cond = expand_cond (IF_COND (t));
380 emit_line_note (input_filename, lineno);
381 expand_start_cond (cond, 0);
382 if (THEN_CLAUSE (t))
383 expand_stmt (THEN_CLAUSE (t));
384 if (ELSE_CLAUSE (t))
385 {
386 expand_start_else ();
387 expand_stmt (ELSE_CLAUSE (t));
388 }
389 expand_end_cond ();
390}
391
2c0e001b 392/* Generate the RTL for T, which is a WHILE_STMT. */
5c3247a9 393
394void
395genrtl_while_stmt (t)
396 tree t;
397{
398 tree cond;
399 emit_nop ();
400 emit_line_note (input_filename, lineno);
401 expand_start_loop (1);
402 genrtl_do_pushlevel ();
403
404 cond = expand_cond (WHILE_COND (t));
405 emit_line_note (input_filename, lineno);
406 expand_exit_loop_if_false (0, cond);
c436c79b 407 genrtl_do_pushlevel ();
5c3247a9 408
409 expand_stmt (WHILE_BODY (t));
410
411 expand_end_loop ();
412}
413
2c0e001b 414/* Generate the RTL for T, which is a DO_STMT. */
5c3247a9 415
416void
417genrtl_do_stmt (t)
418 tree t;
419{
e0f54c0c 420 tree cond = DO_COND (t);
421
422 /* Recognize the common special-case of do { ... } while (0) and do
423 not emit the loop widgetry in this case. In particular this
424 avoids cluttering the rtl with dummy loop notes, which can affect
425 alignment of adjacent labels. */
d0447c3e 426 if (integer_zerop (cond))
7a9d5933 427 {
428 expand_start_null_loop ();
429 expand_stmt (DO_BODY (t));
430 expand_end_null_loop ();
431 }
e0f54c0c 432 else
433 {
434 emit_nop ();
435 emit_line_note (input_filename, lineno);
436 expand_start_loop_continue_elsewhere (1);
5c3247a9 437
e0f54c0c 438 expand_stmt (DO_BODY (t));
5c3247a9 439
e0f54c0c 440 expand_loop_continue_here ();
441 cond = expand_cond (cond);
442 emit_line_note (input_filename, lineno);
443 expand_exit_loop_if_false (0, cond);
444 expand_end_loop ();
445 }
5c3247a9 446}
447
2c0e001b 448/* Build the node for a return statement and return it. */
389acd0a 449
450tree
451build_return_stmt (expr)
452 tree expr;
453{
454 return (build_stmt (RETURN_STMT, expr));
455}
456
2c0e001b 457/* Generate the RTL for STMT, which is a RETURN_STMT. */
5c3247a9 458
459void
225ec6aa 460genrtl_return_stmt (stmt)
461 tree stmt;
5c3247a9 462{
80ac742d 463 tree expr;
464
4cfd9030 465 expr = RETURN_EXPR (stmt);
225ec6aa 466
5c3247a9 467 emit_line_note (input_filename, lineno);
225ec6aa 468 if (!expr)
469 expand_null_return ();
470 else
471 {
472 expand_start_target_temps ();
473 expand_return (expr);
474 expand_end_target_temps ();
475 }
5c3247a9 476}
477
2c0e001b 478/* Generate the RTL for T, which is a FOR_STMT. */
5c3247a9 479
480void
481genrtl_for_stmt (t)
482 tree t;
483{
5c3247a9 484 tree cond;
e41f0d80 485 const char *saved_filename;
486 int saved_lineno;
487
5c3247a9 488 if (NEW_FOR_SCOPE_P (t))
489 genrtl_do_pushlevel ();
490
491 expand_stmt (FOR_INIT_STMT (t));
492
e41f0d80 493 /* Expand the initialization. */
5c3247a9 494 emit_nop ();
495 emit_line_note (input_filename, lineno);
496 expand_start_loop_continue_elsewhere (1);
497 genrtl_do_pushlevel ();
498 cond = expand_cond (FOR_COND (t));
e41f0d80 499
500 /* Save the filename and line number so that we expand the FOR_EXPR
501 we can reset them back to the saved values. */
502 saved_filename = input_filename;
503 saved_lineno = lineno;
504
505 /* Expand the condition. */
5c3247a9 506 emit_line_note (input_filename, lineno);
507 if (cond)
508 expand_exit_loop_if_false (0, cond);
5c3247a9 509
e41f0d80 510 /* Expand the body. */
511 genrtl_do_pushlevel ();
5c3247a9 512 expand_stmt (FOR_BODY (t));
513
e41f0d80 514 /* Expand the increment expression. */
515 input_filename = saved_filename;
516 lineno = saved_lineno;
5c3247a9 517 emit_line_note (input_filename, lineno);
518 expand_loop_continue_here ();
e41f0d80 519 if (FOR_EXPR (t))
520 genrtl_expr_stmt (FOR_EXPR (t));
5c3247a9 521 expand_end_loop ();
522}
523
2c0e001b 524/* Build a break statement node and return it. */
389acd0a 525
526tree
527build_break_stmt ()
528{
529 return (build_stmt (BREAK_STMT));
530}
531
2c0e001b 532/* Generate the RTL for a BREAK_STMT. */
5c3247a9 533
534void
535genrtl_break_stmt ()
536{
537 emit_line_note (input_filename, lineno);
538 if ( ! expand_exit_something ())
539 error ("break statement not within loop or switch");
540}
541
2c0e001b 542/* Build a continue statement node and return it. */
389acd0a 543
544tree
545build_continue_stmt ()
546{
547 return (build_stmt (CONTINUE_STMT));
548}
549
2c0e001b 550/* Generate the RTL for a CONTINUE_STMT. */
5c3247a9 551
552void
553genrtl_continue_stmt ()
554{
555 emit_line_note (input_filename, lineno);
556 if (! expand_continue_loop (0))
557 error ("continue statement not within a loop");
558}
559
2c0e001b 560/* Generate the RTL for T, which is a SCOPE_STMT. */
5c3247a9 561
562void
563genrtl_scope_stmt (t)
564 tree t;
565{
da1ac2c9 566 tree block = SCOPE_STMT_BLOCK (t);
567
5c3247a9 568 if (!SCOPE_NO_CLEANUPS_P (t))
569 {
570 if (SCOPE_BEGIN_P (t))
da1ac2c9 571 expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t), block);
5c3247a9 572 else if (SCOPE_END_P (t))
573 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t), 0);
574 }
575 else if (!SCOPE_NULLIFIED_P (t))
576 {
577 rtx note = emit_note (NULL,
578 (SCOPE_BEGIN_P (t)
579 ? NOTE_INSN_BLOCK_BEG
580 : NOTE_INSN_BLOCK_END));
da1ac2c9 581 NOTE_BLOCK (note) = block;
582 }
583
584 /* If we're at the end of a scope that contains inlined nested
585 functions, we have to decide whether or not to write them out. */
586 if (block && SCOPE_END_P (t))
587 {
588 tree fn;
589
590 for (fn = BLOCK_VARS (block); fn; fn = TREE_CHAIN (fn))
591 {
592 if (TREE_CODE (fn) == FUNCTION_DECL
593 && DECL_CONTEXT (fn) == current_function_decl
594 && !TREE_ASM_WRITTEN (fn)
595 && TREE_ADDRESSABLE (fn))
596 {
597 push_function_context ();
598 output_inline_function (fn);
599 pop_function_context ();
600 }
601 }
5c3247a9 602 }
603}
604
2c0e001b 605/* Generate the RTL for T, which is a SWITCH_STMT. */
5c3247a9 606
607void
608genrtl_switch_stmt (t)
609 tree t;
610{
611 tree cond;
612 genrtl_do_pushlevel ();
613
614 cond = expand_cond (SWITCH_COND (t));
225ec6aa 615 if (cond == error_mark_node)
5c3247a9 616 /* The code is in error, but we don't want expand_end_case to
2c0e001b 617 crash. */
225ec6aa 618 cond = boolean_false_node;
5c3247a9 619
225ec6aa 620 emit_line_note (input_filename, lineno);
621 expand_start_case (1, cond, TREE_TYPE (cond), "switch statement");
5c3247a9 622 expand_stmt (SWITCH_BODY (t));
5c3247a9 623 expand_end_case (cond);
624}
625
2c0e001b 626/* Create a CASE_LABEL tree node and return it. */
389acd0a 627
628tree
225ec6aa 629build_case_label (low_value, high_value, label_decl)
389acd0a 630 tree low_value;
631 tree high_value;
225ec6aa 632 tree label_decl;
389acd0a 633{
225ec6aa 634 return build_stmt (CASE_LABEL, low_value, high_value, label_decl);
389acd0a 635}
636
637
2c0e001b 638/* Generate the RTL for a CASE_LABEL. */
5c3247a9 639
640void
225ec6aa 641genrtl_case_label (case_label)
642 tree case_label;
5c3247a9 643{
225ec6aa 644 tree duplicate;
e41f0d80 645 tree cleanup;
646
647 cleanup = last_cleanup_this_contour ();
648 if (cleanup)
649 {
650 static int explained = 0;
651 warning_with_decl (TREE_PURPOSE (cleanup),
652 "destructor needed for `%#D'");
653 warning ("where case label appears here");
654 if (!explained)
655 {
656 warning ("(enclose actions of previous case statements requiring destructors in their own scope.)");
657 explained = 1;
658 }
659 }
660
225ec6aa 661 add_case_node (CASE_LOW (case_label), CASE_HIGH (case_label),
662 CASE_LABEL_DECL (case_label), &duplicate);
5c3247a9 663}
664
2c0e001b 665/* Generate the RTL for T, which is a COMPOUND_STMT. */
5c3247a9 666
752e275b 667void
668genrtl_compound_stmt (t)
669 tree t;
5c3247a9 670{
634b7df0 671#ifdef ENABLE_CHECKING
672 struct nesting *n = current_nesting_level ();
673#endif
674
5c3247a9 675 expand_stmt (COMPOUND_BODY (t));
634b7df0 676
677#ifdef ENABLE_CHECKING
678 /* Make sure that we've pushed and popped the same number of levels. */
679 if (n != current_nesting_level ())
680 abort ();
681#endif
5c3247a9 682}
683
2c0e001b 684/* Generate the RTL for an ASM_STMT. */
5c3247a9 685
686void
687genrtl_asm_stmt (cv_qualifier, string, output_operands,
efbe600e 688 input_operands, clobbers, asm_input_p)
5c3247a9 689 tree cv_qualifier;
690 tree string;
691 tree output_operands;
692 tree input_operands;
693 tree clobbers;
efbe600e 694 int asm_input_p;
5c3247a9 695{
5c3247a9 696 if (cv_qualifier != NULL_TREE
697 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
698 {
699 warning ("%s qualifier ignored on asm",
700 IDENTIFIER_POINTER (cv_qualifier));
701 cv_qualifier = NULL_TREE;
702 }
703
704 emit_line_note (input_filename, lineno);
efbe600e 705 if (asm_input_p)
5c3247a9 706 expand_asm (string);
efbe600e 707 else
708 c_expand_asm_operands (string, output_operands, input_operands,
709 clobbers, cv_qualifier != NULL_TREE,
710 input_filename, lineno);
5c3247a9 711}
712
2c0e001b 713/* Generate the RTL for a DECL_CLEANUP. */
5c3247a9 714
715void
716genrtl_decl_cleanup (decl, cleanup)
717 tree decl;
718 tree cleanup;
719{
720 if (!decl || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
721 expand_decl_cleanup (decl, cleanup);
722}
723
41fb2c18 724/* We're about to expand T, a statement. Set up appropriate context
725 for the substitution. */
726
727void
728prep_stmt (t)
729 tree t;
730{
731 if (!STMT_LINENO_FOR_FN_P (t))
732 lineno = STMT_LINENO (t);
733 current_stmt_tree ()->stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
734}
735
752e275b 736/* Generate the RTL for the statement T, its substatements, and any
2c0e001b 737 other statements at its nesting level. */
752e275b 738
41fb2c18 739void
5c3247a9 740expand_stmt (t)
741 tree t;
742{
41fb2c18 743 while (t && t != error_mark_node)
744 {
745 int saved_stmts_are_full_exprs_p;
746
747 /* Set up context appropriately for handling this statement. */
748 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
749 prep_stmt (t);
750
751 switch (TREE_CODE (t))
752 {
753 case RETURN_STMT:
225ec6aa 754 genrtl_return_stmt (t);
41fb2c18 755 break;
756
757 case EXPR_STMT:
758 genrtl_expr_stmt (EXPR_STMT_EXPR (t));
759 break;
760
761 case DECL_STMT:
762 genrtl_decl_stmt (t);
763 break;
764
765 case FOR_STMT:
766 genrtl_for_stmt (t);
767 break;
768
769 case WHILE_STMT:
770 genrtl_while_stmt (t);
771 break;
772
773 case DO_STMT:
774 genrtl_do_stmt (t);
775 break;
776
777 case IF_STMT:
778 genrtl_if_stmt (t);
779 break;
780
781 case COMPOUND_STMT:
782 genrtl_compound_stmt (t);
783 break;
784
785 case BREAK_STMT:
786 genrtl_break_stmt ();
787 break;
788
789 case CONTINUE_STMT:
790 genrtl_continue_stmt ();
791 break;
792
793 case SWITCH_STMT:
794 genrtl_switch_stmt (t);
795 break;
796
797 case CASE_LABEL:
225ec6aa 798 genrtl_case_label (t);
41fb2c18 799 break;
800
801 case LABEL_STMT:
802 expand_label (LABEL_STMT_LABEL (t));
803 break;
804
805 case GOTO_STMT:
806 genrtl_goto_stmt (GOTO_DESTINATION (t));
807 break;
808
809 case ASM_STMT:
810 genrtl_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t),
efbe600e 811 ASM_OUTPUTS (t), ASM_INPUTS (t),
812 ASM_CLOBBERS (t), ASM_INPUT_P (t));
41fb2c18 813 break;
814
e41f0d80 815 case SCOPE_STMT:
816 genrtl_scope_stmt (t);
817 break;
818
41fb2c18 819 default:
820 if (lang_expand_stmt)
821 (*lang_expand_stmt) (t);
822 else
823 abort ();
824 break;
825 }
826
827 /* Restore saved state. */
b162c116 828 current_stmt_tree ()->stmts_are_full_exprs_p
829 = saved_stmts_are_full_exprs_p;
41fb2c18 830
831 /* Go on to the next statement in this scope. */
832 t = TREE_CHAIN (t);
833 }
5c3247a9 834}
752e275b 835