]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
cris.c (cris_target_asm_function_prologue): Cast uses of PIC_OFFSET_TABLE_REGNUM...
[thirdparty/gcc.git] / gcc / cp / semantics.c
CommitLineData
ad321293
MM
1/* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
5
a4200657 6 Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
ad321293
MM
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
9
10 This file is part of GNU CC.
11
12 GNU CC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
16
17 GNU CC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with GNU CC; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26
27#include "config.h"
8d052bc7 28#include "system.h"
ad321293
MM
29#include "tree.h"
30#include "cp-tree.h"
25af8512 31#include "tree-inline.h"
ad321293
MM
32#include "except.h"
33#include "lex.h"
12027a89 34#include "toplev.h"
84df082b 35#include "flags.h"
d658cd4c 36#include "ggc.h"
d9b2d9da 37#include "rtl.h"
d6684bc8 38#include "expr.h"
225ff119 39#include "output.h"
ea11ca7e 40#include "timevar.h"
2b85879e 41#include "debug.h"
ad321293
MM
42
43/* There routines provide a modular interface to perform many parsing
44 operations. They may therefore be used during actual parsing, or
45 during template instantiation, which may be regarded as a
46 degenerate form of parsing. Since the current g++ parser is
47 lacking in several respects, and will be reimplemented, we are
48 attempting to move most code that is not directly related to
49 parsing into this file; that will make implementing the new parser
50 much easier since it will be able to make use of these routines. */
51
158991b7
KG
52static tree maybe_convert_cond PARAMS ((tree));
53static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *));
c2e407f1 54static void deferred_type_access_control PARAMS ((void));
31f8e4f3 55static void emit_associated_thunks PARAMS ((tree));
54f7877c 56static void genrtl_try_block PARAMS ((tree));
52a11cbf 57static void genrtl_eh_spec_block PARAMS ((tree));
54f7877c 58static void genrtl_handler PARAMS ((tree));
54f7877c
MM
59static void genrtl_ctor_stmt PARAMS ((tree));
60static void genrtl_subobject PARAMS ((tree));
54f7877c
MM
61static void genrtl_named_return_value PARAMS ((void));
62static void cp_expand_stmt PARAMS ((tree));
f444e36b
MM
63static void genrtl_start_function PARAMS ((tree));
64static void genrtl_finish_function PARAMS ((tree));
b850de4f 65static tree clear_decl_rtl PARAMS ((tree *, int *, void *));
558475f0 66
527f0080
MM
67/* Finish processing the COND, the SUBSTMT condition for STMT. */
68
c3af729a 69#define FINISH_COND(COND, STMT, SUBSTMT) \
ed5511d9 70 do { \
c3af729a 71 if (last_tree != (STMT)) \
ed5511d9 72 { \
c3af729a
GS
73 RECHAIN_STMTS (STMT, SUBSTMT); \
74 if (!processing_template_decl) \
75 { \
76 (COND) = build_tree_list (SUBSTMT, COND); \
77 (SUBSTMT) = (COND); \
78 } \
ed5511d9
MM
79 } \
80 else \
c3af729a 81 (SUBSTMT) = (COND); \
527f0080 82 } while (0)
35b1567d 83
f2c5f623
BC
84/* Returns non-zero if the current statement is a full expression,
85 i.e. temporaries created during that statement should be destroyed
86 at the end of the statement. */
35b1567d 87
f2c5f623
BC
88int
89stmts_are_full_exprs_p ()
90{
ae499cce
MM
91 return current_stmt_tree ()->stmts_are_full_exprs_p;
92}
93
94/* Returns the stmt_tree (if any) to which statements are currently
95 being added. If there is no active statement-tree, NULL is
96 returned. */
97
98stmt_tree
99current_stmt_tree ()
100{
101 return (cfun
102 ? &cfun->language->x_stmt_tree
103 : &scope_chain->x_stmt_tree);
f2c5f623 104}
35b1567d 105
f2c5f623
BC
106/* Nonzero if TYPE is an anonymous union or struct type. We have to use a
107 flag for this because "A union for which objects or pointers are
108 declared is not an anonymous union" [class.union]. */
35b1567d 109
f2c5f623
BC
110int
111anon_aggr_type_p (node)
112 tree node;
35b1567d 113{
f2c5f623 114 return (CLASS_TYPE_P (node) && TYPE_LANG_SPECIFIC(node)->anon_aggr);
35b1567d
BC
115}
116
f2c5f623 117/* Finish a scope. */
35b1567d
BC
118
119tree
f2c5f623 120do_poplevel ()
35b1567d
BC
121{
122 tree block = NULL_TREE;
123
f2c5f623 124 if (stmts_are_full_exprs_p ())
35b1567d 125 {
50e60bc3 126 tree scope_stmts = NULL_TREE;
f2c5f623
BC
127
128 if (!processing_template_decl)
129 scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
35b1567d
BC
130
131 block = poplevel (kept_level_p (), 1, 0);
132 if (block && !processing_template_decl)
133 {
134 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
135 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
136 }
137 }
138
139 return block;
140}
141
f2c5f623 142/* Begin a new scope. */
35b1567d
BC
143
144void
f2c5f623 145do_pushlevel ()
35b1567d 146{
f2c5f623 147 if (stmts_are_full_exprs_p ())
35b1567d 148 {
f2c5f623
BC
149 pushlevel (0);
150 if (!processing_template_decl)
151 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
35b1567d
BC
152 }
153}
154
35b1567d
BC
155/* Finish a goto-statement. */
156
3e4d04a1 157tree
35b1567d
BC
158finish_goto_stmt (destination)
159 tree destination;
160{
161 if (TREE_CODE (destination) == IDENTIFIER_NODE)
162 destination = lookup_label (destination);
163
164 /* We warn about unused labels with -Wunused. That means we have to
165 mark the used labels as used. */
166 if (TREE_CODE (destination) == LABEL_DECL)
167 TREE_USED (destination) = 1;
168
169 if (TREE_CODE (destination) != LABEL_DECL)
170 /* We don't inline calls to functions with computed gotos.
171 Those functions are typically up to some funny business,
172 and may be depending on the labels being at particular
173 addresses, or some such. */
174 DECL_UNINLINABLE (current_function_decl) = 1;
175
176 check_goto (destination);
177
3e4d04a1 178 return add_stmt (build_stmt (GOTO_STMT, destination));
35b1567d
BC
179}
180
ed5511d9
MM
181/* COND is the condition-expression for an if, while, etc.,
182 statement. Convert it to a boolean value, if appropriate. */
183
f2c5f623 184tree
ed5511d9
MM
185maybe_convert_cond (cond)
186 tree cond;
187{
188 /* Empty conditions remain empty. */
189 if (!cond)
190 return NULL_TREE;
191
192 /* Wait until we instantiate templates before doing conversion. */
193 if (processing_template_decl)
194 return cond;
195
196 /* Do the conversion. */
197 cond = convert_from_reference (cond);
198 return condition_conversion (cond);
199}
200
9bfadf57 201/* Finish an expression-statement, whose EXPRESSION is as indicated. */
a7e4cfa0 202
3e4d04a1 203tree
9bfadf57 204finish_expr_stmt (expr)
ad321293
MM
205 tree expr;
206{
3e4d04a1
RH
207 tree r = NULL_TREE;
208
ce4a0391 209 if (expr != NULL_TREE)
ad321293 210 {
35b1567d 211 if (!processing_template_decl
f2c5f623 212 && !(stmts_are_full_exprs_p ())
35b1567d
BC
213 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
214 && lvalue_p (expr))
215 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
216 expr = default_conversion (expr);
217
f2c5f623 218 if (stmts_are_full_exprs_p ())
35b1567d
BC
219 expr = convert_to_void (expr, "statement");
220
3e4d04a1 221 r = add_stmt (build_stmt (EXPR_STMT, expr));
35b1567d 222 }
364460b6 223
35b1567d 224 finish_stmt ();
558475f0 225
35b1567d
BC
226 /* This was an expression-statement, so we save the type of the
227 expression. */
228 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
3e4d04a1
RH
229
230 return r;
35b1567d
BC
231}
232
35b1567d 233
ad321293
MM
234/* Begin an if-statement. Returns a newly created IF_STMT if
235 appropriate. */
236
237tree
238begin_if_stmt ()
239{
240 tree r;
9bfadf57 241 do_pushlevel ();
0dfdeca6 242 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
ae499cce 243 add_stmt (r);
ad321293
MM
244 return r;
245}
246
247/* Process the COND of an if-statement, which may be given by
248 IF_STMT. */
249
250void
251finish_if_stmt_cond (cond, if_stmt)
252 tree cond;
253 tree if_stmt;
254{
ed5511d9 255 cond = maybe_convert_cond (cond);
35b1567d 256 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
ad321293
MM
257}
258
259/* Finish the then-clause of an if-statement, which may be given by
260 IF_STMT. */
261
262tree
263finish_then_clause (if_stmt)
264 tree if_stmt;
265{
35b1567d 266 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
ae499cce 267 last_tree = if_stmt;
35b1567d 268 return if_stmt;
ad321293
MM
269}
270
271/* Begin the else-clause of an if-statement. */
272
273void
274begin_else_clause ()
275{
ad321293
MM
276}
277
278/* Finish the else-clause of an if-statement, which may be given by
279 IF_STMT. */
280
281void
282finish_else_clause (if_stmt)
283 tree if_stmt;
284{
35b1567d 285 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
ad321293
MM
286}
287
dfbb4f34 288/* Finish an if-statement. */
ad321293
MM
289
290void
291finish_if_stmt ()
292{
ad321293
MM
293 do_poplevel ();
294 finish_stmt ();
295}
296
35b1567d
BC
297void
298clear_out_block ()
299{
300 /* If COND wasn't a declaration, clear out the
301 block we made for it and start a new one here so the
302 optimization in expand_end_loop will work. */
303 if (getdecls () == NULL_TREE)
304 {
305 do_poplevel ();
306 do_pushlevel ();
307 }
308}
309
ad321293
MM
310/* Begin a while-statement. Returns a newly created WHILE_STMT if
311 appropriate. */
312
313tree
314begin_while_stmt ()
315{
316 tree r;
0dfdeca6 317 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
ae499cce 318 add_stmt (r);
ad321293 319 do_pushlevel ();
ad321293
MM
320 return r;
321}
322
27d26ee7 323/* Process the COND of a while-statement, which may be given by
ad321293
MM
324 WHILE_STMT. */
325
326void
327finish_while_stmt_cond (cond, while_stmt)
328 tree cond;
329 tree while_stmt;
330{
ed5511d9 331 cond = maybe_convert_cond (cond);
35b1567d
BC
332 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
333 clear_out_block ();
ad321293
MM
334}
335
336/* Finish a while-statement, which may be given by WHILE_STMT. */
337
338void
339finish_while_stmt (while_stmt)
340 tree while_stmt;
341{
342 do_poplevel ();
35b1567d 343 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
ad321293
MM
344 finish_stmt ();
345}
346
347/* Begin a do-statement. Returns a newly created DO_STMT if
348 appropriate. */
349
350tree
351begin_do_stmt ()
352{
0dfdeca6 353 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
ae499cce 354 add_stmt (r);
35b1567d 355 return r;
ad321293
MM
356}
357
358/* Finish the body of a do-statement, which may be given by DO_STMT. */
359
360void
361finish_do_body (do_stmt)
362 tree do_stmt;
363{
35b1567d 364 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
ad321293
MM
365}
366
367/* Finish a do-statement, which may be given by DO_STMT, and whose
368 COND is as indicated. */
369
370void
371finish_do_stmt (cond, do_stmt)
372 tree cond;
373 tree do_stmt;
374{
ed5511d9 375 cond = maybe_convert_cond (cond);
35b1567d
BC
376 DO_COND (do_stmt) = cond;
377 finish_stmt ();
378}
ed5511d9 379
ad321293
MM
380/* Finish a return-statement. The EXPRESSION returned, if any, is as
381 indicated. */
382
3e4d04a1 383tree
ad321293
MM
384finish_return_stmt (expr)
385 tree expr;
386{
3e4d04a1
RH
387 tree r;
388
35b1567d 389 if (!processing_template_decl)
efee38a9 390 expr = check_return_expr (expr);
35b1567d 391 if (!processing_template_decl)
efee38a9 392 {
a0de9d20 393 if (DECL_DESTRUCTOR_P (current_function_decl))
efee38a9
MM
394 {
395 /* Similarly, all destructors must run destructors for
396 base-classes before returning. So, all returns in a
dfbb4f34 397 destructor get sent to the DTOR_LABEL; finish_function emits
efee38a9 398 code to return a value there. */
3e4d04a1 399 return finish_goto_stmt (dtor_label);
efee38a9
MM
400 }
401 }
3e4d04a1 402 r = add_stmt (build_stmt (RETURN_STMT, expr));
35b1567d 403 finish_stmt ();
3e4d04a1
RH
404
405 return r;
35b1567d 406}
efee38a9 407
ad321293
MM
408/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
409
410tree
411begin_for_stmt ()
412{
413 tree r;
414
0dfdeca6
BC
415 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
416 NULL_TREE, NULL_TREE);
f2c5f623 417 NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0;
ae499cce 418 add_stmt (r);
f2c5f623 419 if (NEW_FOR_SCOPE_P (r))
ad321293
MM
420 {
421 do_pushlevel ();
422 note_level_for_for ();
423 }
424
425 return r;
426}
427
428/* Finish the for-init-statement of a for-statement, which may be
429 given by FOR_STMT. */
430
431void
432finish_for_init_stmt (for_stmt)
433 tree for_stmt;
434{
35b1567d
BC
435 if (last_tree != for_stmt)
436 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
ad321293
MM
437 do_pushlevel ();
438}
439
440/* Finish the COND of a for-statement, which may be given by
441 FOR_STMT. */
442
443void
444finish_for_cond (cond, for_stmt)
445 tree cond;
446 tree for_stmt;
447{
ed5511d9 448 cond = maybe_convert_cond (cond);
35b1567d
BC
449 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
450 clear_out_block ();
ad321293
MM
451}
452
453/* Finish the increment-EXPRESSION in a for-statement, which may be
454 given by FOR_STMT. */
455
456void
457finish_for_expr (expr, for_stmt)
458 tree expr;
459 tree for_stmt;
460{
35b1567d 461 FOR_EXPR (for_stmt) = expr;
ad321293
MM
462}
463
464/* Finish the body of a for-statement, which may be given by
465 FOR_STMT. The increment-EXPR for the loop must be
466 provided. */
467
468void
35b1567d 469finish_for_stmt (for_stmt)
ad321293
MM
470 tree for_stmt;
471{
472 /* Pop the scope for the body of the loop. */
473 do_poplevel ();
35b1567d 474 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
f2c5f623 475 if (NEW_FOR_SCOPE_P (for_stmt))
ad321293 476 do_poplevel ();
ad321293
MM
477 finish_stmt ();
478}
479
480/* Finish a break-statement. */
481
3e4d04a1 482tree
ad321293
MM
483finish_break_stmt ()
484{
3e4d04a1 485 return add_stmt (build_break_stmt ());
35b1567d
BC
486}
487
ad321293
MM
488/* Finish a continue-statement. */
489
3e4d04a1 490tree
ad321293
MM
491finish_continue_stmt ()
492{
3e4d04a1 493 return add_stmt (build_continue_stmt ());
ad321293
MM
494}
495
35b1567d
BC
496/* Begin a switch-statement. Returns a new SWITCH_STMT if
497 appropriate. */
498
499tree
500begin_switch_stmt ()
501{
502 tree r;
6f9fdf4d 503 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
ae499cce 504 add_stmt (r);
35b1567d 505 do_pushlevel ();
527f0080 506 return r;
ad321293
MM
507}
508
527f0080 509/* Finish the cond of a switch-statement. */
ad321293 510
527f0080
MM
511void
512finish_switch_cond (cond, switch_stmt)
ad321293 513 tree cond;
527f0080 514 tree switch_stmt;
ad321293 515{
6f9fdf4d 516 tree orig_type = NULL;
35b1567d 517 if (!processing_template_decl)
373eb3b3 518 {
56cb9733
MM
519 tree index;
520
35b1567d
BC
521 /* Convert the condition to an integer or enumeration type. */
522 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
523 if (cond == NULL_TREE)
373eb3b3 524 {
35b1567d
BC
525 error ("switch quantity not an integer");
526 cond = error_mark_node;
527 }
6f9fdf4d 528 orig_type = TREE_TYPE (cond);
35b1567d
BC
529 if (cond != error_mark_node)
530 {
35b1567d 531 cond = default_conversion (cond);
2bb5d995 532 cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
373eb3b3 533 }
56cb9733 534
25c8b645
JJ
535 if (cond != error_mark_node)
536 {
537 index = get_unwidened (cond, NULL_TREE);
538 /* We can't strip a conversion from a signed type to an unsigned,
539 because if we did, int_fits_type_p would do the wrong thing
540 when checking case values for being in range,
541 and it's too hard to do the right thing. */
542 if (TREE_UNSIGNED (TREE_TYPE (cond))
543 == TREE_UNSIGNED (TREE_TYPE (index)))
544 cond = index;
545 }
ad321293 546 }
35b1567d 547 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
6f9fdf4d 548 SWITCH_TYPE (switch_stmt) = orig_type;
56cb9733 549 push_switch (switch_stmt);
ad321293
MM
550}
551
552/* Finish the body of a switch-statement, which may be given by
553 SWITCH_STMT. The COND to switch on is indicated. */
554
555void
35b1567d 556finish_switch_stmt (switch_stmt)
ad321293
MM
557 tree switch_stmt;
558{
35b1567d 559 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
ad321293
MM
560 pop_switch ();
561 do_poplevel ();
562 finish_stmt ();
563}
564
35b1567d 565/* Generate the RTL for T, which is a TRY_BLOCK. */
6625cdb5 566
54f7877c
MM
567static void
568genrtl_try_block (t)
35b1567d
BC
569 tree t;
570{
571 if (CLEANUP_P (t))
572 {
573 expand_eh_region_start ();
574 expand_stmt (TRY_STMTS (t));
52a11cbf 575 expand_eh_region_end_cleanup (TRY_HANDLERS (t));
46e8c075 576 }
ad321293
MM
577 else
578 {
f444e36b
MM
579 if (!FN_TRY_BLOCK_P (t))
580 emit_line_note (input_filename, lineno);
35b1567d 581
52a11cbf 582 expand_eh_region_start ();
35b1567d 583 expand_stmt (TRY_STMTS (t));
ad321293 584
35b1567d 585 if (FN_TRY_BLOCK_P (t))
ad321293 586 {
35b1567d
BC
587 expand_start_all_catch ();
588 in_function_try_handler = 1;
589 expand_stmt (TRY_HANDLERS (t));
590 in_function_try_handler = 0;
591 expand_end_all_catch ();
592 }
593 else
594 {
595 expand_start_all_catch ();
596 expand_stmt (TRY_HANDLERS (t));
597 expand_end_all_catch ();
ad321293 598 }
ad321293
MM
599 }
600}
601
52a11cbf
RH
602/* Generate the RTL for T, which is an EH_SPEC_BLOCK. */
603
604static void
605genrtl_eh_spec_block (t)
606 tree t;
607{
608 expand_eh_region_start ();
609 expand_stmt (EH_SPEC_STMTS (t));
610 expand_eh_region_end_allowed (EH_SPEC_RAISES (t),
611 build_call (call_unexpected_node,
612 tree_cons (NULL_TREE,
613 build_exc_ptr (),
614 NULL_TREE)));
615}
616
ad321293
MM
617/* Begin a try-block. Returns a newly-created TRY_BLOCK if
618 appropriate. */
619
620tree
621begin_try_block ()
622{
0dfdeca6 623 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
ae499cce 624 add_stmt (r);
35b1567d 625 return r;
ad321293
MM
626}
627
0dde4175
JM
628/* Likewise, for a function-try-block. */
629
630tree
631begin_function_try_block ()
632{
0dfdeca6 633 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
35b1567d 634 FN_TRY_BLOCK_P (r) = 1;
ae499cce 635 add_stmt (r);
35b1567d 636 return r;
0dde4175
JM
637}
638
ad321293
MM
639/* Finish a try-block, which may be given by TRY_BLOCK. */
640
641void
642finish_try_block (try_block)
643 tree try_block;
644{
35b1567d 645 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
ad321293
MM
646}
647
efa8eda3
MM
648/* Finish the body of a cleanup try-block, which may be given by
649 TRY_BLOCK. */
650
62409b39
MM
651void
652finish_cleanup_try_block (try_block)
653 tree try_block;
654{
35b1567d 655 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
62409b39
MM
656}
657
f1dedc31
MM
658/* Finish an implicitly generated try-block, with a cleanup is given
659 by CLEANUP. */
660
661void
662finish_cleanup (cleanup, try_block)
663 tree cleanup;
664 tree try_block;
665{
35b1567d
BC
666 TRY_HANDLERS (try_block) = cleanup;
667 CLEANUP_P (try_block) = 1;
f1dedc31
MM
668}
669
0dde4175
JM
670/* Likewise, for a function-try-block. */
671
672void
673finish_function_try_block (try_block)
a0de9d20 674 tree try_block;
0dde4175 675{
35b1567d
BC
676 if (TREE_CHAIN (try_block)
677 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
62409b39 678 {
35b1567d
BC
679 /* Chain the compound statement after the CTOR_INITIALIZER. */
680 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
681 /* And make the CTOR_INITIALIZER the body of the try-block. */
682 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
62409b39 683 }
0dde4175 684 else
35b1567d 685 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
b35d4555 686 in_function_try_handler = 1;
0dde4175
JM
687}
688
ad321293
MM
689/* Finish a handler-sequence for a try-block, which may be given by
690 TRY_BLOCK. */
691
692void
693finish_handler_sequence (try_block)
694 tree try_block;
695{
35b1567d
BC
696 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
697 check_handlers (TRY_HANDLERS (try_block));
ad321293
MM
698}
699
0dde4175
JM
700/* Likewise, for a function-try-block. */
701
702void
703finish_function_handler_sequence (try_block)
704 tree try_block;
705{
b35d4555 706 in_function_try_handler = 0;
35b1567d
BC
707 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
708 check_handlers (TRY_HANDLERS (try_block));
709}
710
711/* Generate the RTL for T, which is a HANDLER. */
b35d4555 712
54f7877c 713static void
35b1567d
BC
714genrtl_handler (t)
715 tree t;
716{
717 genrtl_do_pushlevel ();
1a6025b4
JM
718 if (!processing_template_decl)
719 expand_start_catch (HANDLER_TYPE (t));
35b1567d
BC
720 expand_stmt (HANDLER_BODY (t));
721 if (!processing_template_decl)
52a11cbf 722 expand_end_catch ();
0dde4175
JM
723}
724
ad321293
MM
725/* Begin a handler. Returns a HANDLER if appropriate. */
726
727tree
728begin_handler ()
729{
730 tree r;
0dfdeca6 731 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
ae499cce 732 add_stmt (r);
1a6025b4
JM
733 /* Create a binding level for the eh_info and the exception object
734 cleanup. */
ad321293 735 do_pushlevel ();
1a6025b4 736 note_level_for_catch ();
ad321293
MM
737 return r;
738}
739
740/* Finish the handler-parameters for a handler, which may be given by
b35d4555
MM
741 HANDLER. DECL is the declaration for the catch parameter, or NULL
742 if this is a `catch (...)' clause. */
ad321293 743
1a6025b4 744void
b35d4555
MM
745finish_handler_parms (decl, handler)
746 tree decl;
ad321293 747 tree handler;
b35d4555 748{
1a6025b4 749 tree type = NULL_TREE;
b35d4555
MM
750 if (processing_template_decl)
751 {
752 if (decl)
753 {
754 decl = pushdecl (decl);
755 decl = push_template_decl (decl);
756 add_decl_stmt (decl);
757 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
1a6025b4 758 type = TREE_TYPE (decl);
b35d4555
MM
759 }
760 }
35b1567d 761 else
1a6025b4 762 type = expand_start_catch_block (decl);
35b1567d 763
1a6025b4 764 HANDLER_TYPE (handler) = type;
35b1567d
BC
765}
766
767/* Finish a handler, which may be given by HANDLER. The BLOCKs are
768 the return value from the matching call to finish_handler_parms. */
769
770void
1a6025b4 771finish_handler (handler)
35b1567d
BC
772 tree handler;
773{
774 if (!processing_template_decl)
1a6025b4 775 expand_end_catch_block ();
35b1567d
BC
776 do_poplevel ();
777 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
778}
779
780/* Generate the RTL for T, which is a CTOR_STMT. */
781
54f7877c 782static void
35b1567d
BC
783genrtl_ctor_stmt (t)
784 tree t;
785{
786 if (CTOR_BEGIN_P (t))
787 begin_protect_partials ();
788 else
789 /* After this point, any exceptions will cause the
790 destructor to be executed, so we no longer need to worry
791 about destroying the various subobjects ourselves. */
792 end_protect_partials ();
793}
794
ad321293
MM
795/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
796 compound-statement does not define a scope. Returns a new
797 COMPOUND_STMT if appropriate. */
798
799tree
800begin_compound_stmt (has_no_scope)
801 int has_no_scope;
802{
803 tree r;
6625cdb5 804 int is_try = 0;
ad321293 805
0dfdeca6 806 r = build_stmt (COMPOUND_STMT, NULL_TREE);
35b1567d
BC
807
808 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
809 is_try = 1;
810
ae499cce 811 add_stmt (r);
35b1567d
BC
812 if (has_no_scope)
813 COMPOUND_STMT_NO_SCOPE (r) = 1;
ad321293 814
558475f0
MM
815 last_expr_type = NULL_TREE;
816
ad321293 817 if (!has_no_scope)
6625cdb5
JM
818 {
819 do_pushlevel ();
820 if (is_try)
826840d9 821 note_level_for_try ();
6625cdb5 822 }
f1dedc31
MM
823 else
824 /* Normally, we try hard to keep the BLOCK for a
825 statement-expression. But, if it's a statement-expression with
826 a scopeless block, there's nothing to keep, and we don't want
827 to accidentally keep a block *inside* the scopeless block. */
828 keep_next_level (0);
ad321293
MM
829
830 return r;
831}
832
ad321293
MM
833/* Finish a compound-statement, which may be given by COMPOUND_STMT.
834 If HAS_NO_SCOPE is non-zero, the compound statement does not define
835 a scope. */
836
837tree
838finish_compound_stmt (has_no_scope, compound_stmt)
839 int has_no_scope;
840 tree compound_stmt;
841{
842 tree r;
558475f0 843 tree t;
ad321293
MM
844
845 if (!has_no_scope)
846 r = do_poplevel ();
847 else
848 r = NULL_TREE;
849
35b1567d 850 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
ad321293 851
cb39191d 852 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
558475f0
MM
853 the precise purpose of that variable is store the type of the
854 last expression statement within the last compound statement, we
855 preserve the value. */
856 t = last_expr_type;
ad321293 857 finish_stmt ();
558475f0 858 last_expr_type = t;
ad321293
MM
859
860 return r;
861}
862
35b1567d
BC
863/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
864 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
865 CLOBBERS. */
7dc5bd62 866
3e4d04a1 867tree
35b1567d
BC
868finish_asm_stmt (cv_qualifier, string, output_operands,
869 input_operands, clobbers)
870 tree cv_qualifier;
871 tree string;
872 tree output_operands;
873 tree input_operands;
874 tree clobbers;
875{
876 tree r;
abfc8a36
MM
877 tree t;
878
a23c9413
NB
879 if (TREE_CHAIN (string))
880 string = combine_strings (string);
881
35b1567d
BC
882 if (cv_qualifier != NULL_TREE
883 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
884 {
33bd39a2 885 warning ("%s qualifier ignored on asm",
35b1567d
BC
886 IDENTIFIER_POINTER (cv_qualifier));
887 cv_qualifier = NULL_TREE;
ad321293 888 }
35b1567d 889
abfc8a36 890 if (!processing_template_decl)
40b18c0a
MM
891 {
892 int i;
893 int ninputs;
894 int noutputs;
895
896 for (t = input_operands; t; t = TREE_CHAIN (t))
897 {
898 tree converted_operand
899 = decay_conversion (TREE_VALUE (t));
900
901 /* If the type of the operand hasn't been determined (e.g.,
902 because it involves an overloaded function), then issue
903 an error message. There's no context available to
904 resolve the overloading. */
905 if (TREE_TYPE (converted_operand) == unknown_type_node)
906 {
33bd39a2 907 error ("type of asm operand `%E' could not be determined",
40b18c0a
MM
908 TREE_VALUE (t));
909 converted_operand = error_mark_node;
910 }
911 TREE_VALUE (t) = converted_operand;
912 }
913
914 ninputs = list_length (input_operands);
915 noutputs = list_length (output_operands);
916
917 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
918 {
919 bool allows_mem;
920 bool allows_reg;
921 bool is_inout;
922 const char *constraint;
923 tree operand;
924
84b72302 925 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
40b18c0a
MM
926 operand = TREE_VALUE (output_operands);
927
928 if (!parse_output_constraint (&constraint,
929 i, ninputs, noutputs,
930 &allows_mem,
931 &allows_reg,
932 &is_inout))
933 {
934 /* By marking the type as erroneous, we will not try to
935 process this operand again in expand_asm_operands. */
936 TREE_TYPE (operand) = error_mark_node;
937 continue;
938 }
939
940 /* If the operand is a DECL that is going to end up in
941 memory, assume it is addressable. This is a bit more
942 conservative than it would ideally be; the exact test is
943 buried deep in expand_asm_operands and depends on the
944 DECL_RTL for the OPERAND -- which we don't have at this
945 point. */
946 if (!allows_reg && DECL_P (operand))
dffd7eb6 947 cxx_mark_addressable (operand);
40b18c0a
MM
948 }
949 }
abfc8a36 950
0dfdeca6
BC
951 r = build_stmt (ASM_STMT, cv_qualifier, string,
952 output_operands, input_operands,
953 clobbers);
3e4d04a1 954 return add_stmt (r);
ad321293 955}
b4c4a9ec 956
f01b0acb
MM
957/* Finish a label with the indicated NAME. */
958
959void
960finish_label_stmt (name)
961 tree name;
962{
3fa56191 963 tree decl = define_label (input_filename, lineno, name);
ae499cce 964 add_stmt (build_stmt (LABEL_STMT, decl));
f01b0acb
MM
965}
966
acef433b
MM
967/* Finish a series of declarations for local labels. G++ allows users
968 to declare "local" labels, i.e., labels with scope. This extension
969 is useful when writing code involving statement-expressions. */
970
971void
972finish_label_decl (name)
973 tree name;
974{
975 tree decl = declare_local_label (name);
35b1567d 976 add_decl_stmt (decl);
acef433b
MM
977}
978
35b1567d
BC
979/* Generate the RTL for a SUBOBJECT. */
980
54f7877c 981static void
35b1567d
BC
982genrtl_subobject (cleanup)
983 tree cleanup;
984{
985 add_partial_entry (cleanup);
9188c363
MM
986}
987
f1dedc31
MM
988/* We're in a constructor, and have just constructed a a subobject of
989 *THIS. CLEANUP is code to run if an exception is thrown before the
990 end of the current function is reached. */
991
992void
993finish_subobject (cleanup)
994 tree cleanup;
995{
0dfdeca6 996 tree r = build_stmt (SUBOBJECT, cleanup);
ae499cce 997 add_stmt (r);
35b1567d
BC
998}
999
24bef158
MM
1000/* When DECL goes out of scope, make sure that CLEANUP is executed. */
1001
1002void
1003finish_decl_cleanup (decl, cleanup)
1004 tree decl;
1005 tree cleanup;
1006{
ae499cce 1007 add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup));
35b1567d
BC
1008}
1009
1010/* Generate the RTL for a RETURN_INIT. */
1011
54f7877c 1012static void
44835fdd 1013genrtl_named_return_value ()
35b1567d 1014{
156ce211 1015 tree decl = DECL_RESULT (current_function_decl);
35b1567d 1016
44835fdd
MM
1017 /* If this named return value comes in a register, put it in a
1018 pseudo-register. */
1019 if (DECL_REGISTER (decl))
35b1567d 1020 {
44835fdd
MM
1021 /* Note that the mode of the old DECL_RTL may be wider than the
1022 mode of DECL_RESULT, depending on the calling conventions for
1023 the processor. For example, on the Alpha, a 32-bit integer
1024 is returned in a DImode register -- the DECL_RESULT has
1025 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
1026 here, we use the mode the back-end has already assigned for
1027 the return value. */
19e7881c 1028 SET_DECL_RTL (decl, gen_reg_rtx (GET_MODE (DECL_RTL (decl))));
44835fdd
MM
1029 if (TREE_ADDRESSABLE (decl))
1030 put_var_into_stack (decl);
35b1567d 1031 }
156ce211
RH
1032
1033 emit_local_var (decl);
24bef158
MM
1034}
1035
558475f0
MM
1036/* Bind a name and initialization to the return value of
1037 the current function. */
1038
1039void
1040finish_named_return_value (return_id, init)
1041 tree return_id, init;
1042{
1043 tree decl = DECL_RESULT (current_function_decl);
1044
44835fdd
MM
1045 /* Give this error as many times as there are occurrences, so that
1046 users can use Emacs compilation buffers to find and fix all such
1047 places. */
558475f0 1048 if (pedantic)
cab1f180 1049 pedwarn ("ISO C++ does not permit named return values");
44835fdd 1050 cp_deprecated ("the named return value extension");
558475f0
MM
1051
1052 if (return_id != NULL_TREE)
1053 {
1054 if (DECL_NAME (decl) == NULL_TREE)
92643fea 1055 DECL_NAME (decl) = return_id;
558475f0
MM
1056 else
1057 {
33bd39a2 1058 error ("return identifier `%D' already in place", return_id);
558475f0
MM
1059 return;
1060 }
1061 }
1062
1063 /* Can't let this happen for constructors. */
1064 if (DECL_CONSTRUCTOR_P (current_function_decl))
1065 {
1066 error ("can't redefine default return value for constructors");
1067 return;
1068 }
1069
1070 /* If we have a named return value, put that in our scope as well. */
1071 if (DECL_NAME (decl) != NULL_TREE)
1072 {
1073 /* Let `cp_finish_decl' know that this initializer is ok. */
1074 DECL_INITIAL (decl) = init;
b35d4555
MM
1075 if (doing_semantic_analysis_p ())
1076 pushdecl (decl);
44835fdd
MM
1077 if (!processing_template_decl)
1078 {
1079 cp_finish_decl (decl, init, NULL_TREE, 0);
ae499cce 1080 add_stmt (build_stmt (RETURN_INIT, NULL_TREE, NULL_TREE));
44835fdd
MM
1081 }
1082 else
ae499cce 1083 add_stmt (build_stmt (RETURN_INIT, return_id, init));
558475f0 1084 }
f0ad3f46
MM
1085
1086 /* Don't use tree-inlining for functions with named return values.
1087 That doesn't work properly because we don't do any translation of
1088 the RETURN_INITs when they are copied. */
1089 DECL_UNINLINABLE (current_function_decl) = 1;
558475f0
MM
1090}
1091
bf3428d0
MM
1092/* The INIT_LIST is a list of mem-initializers, in the order they were
1093 written by the user. The TREE_VALUE of each node is a list of
1094 initializers for a particular subobject. The TREE_PURPOSE is a
1095 FIELD_DECL is the initializer is for a non-static data member, and
1096 a class type if the initializer is for a base class. */
1097
1098void
1099finish_mem_initializers (init_list)
1100 tree init_list;
1101{
1102 tree member_init_list;
1103 tree base_init_list;
1104 tree last_base_warned_about;
1105 tree next;
1106 tree init;
1107
1108 member_init_list = NULL_TREE;
1109 base_init_list = NULL_TREE;
1110 last_base_warned_about = NULL_TREE;
1111
1112 for (init = init_list; init; init = next)
1113 {
1114 next = TREE_CHAIN (init);
1115 if (TREE_CODE (TREE_PURPOSE (init)) == FIELD_DECL)
1116 {
1117 TREE_CHAIN (init) = member_init_list;
1118 member_init_list = init;
1119
1120 /* We're running through the initializers from right to left
1121 as we process them here. So, if we see a data member
1122 initializer after we see a base initializer, that
aba649ba 1123 actually means that the base initializer preceded the
bf3428d0
MM
1124 data member initializer. */
1125 if (warn_reorder && last_base_warned_about != base_init_list)
1126 {
1127 tree base;
1128
1129 for (base = base_init_list;
1130 base != last_base_warned_about;
1131 base = TREE_CHAIN (base))
1132 {
33bd39a2 1133 warning ("base initializer for `%T'",
bf3428d0
MM
1134 TREE_PURPOSE (base));
1135 warning (" will be re-ordered to precede member initializations");
1136 }
1137
1138 last_base_warned_about = base_init_list;
1139 }
1140 }
1141 else
1142 {
1143 TREE_CHAIN (init) = base_init_list;
1144 base_init_list = init;
1145 }
1146 }
1147
a0de9d20
JM
1148 if (processing_template_decl)
1149 add_stmt (build_min_nt (CTOR_INITIALIZER,
1150 member_init_list, base_init_list));
cdd2559c
JM
1151 else
1152 emit_base_init (member_init_list, base_init_list);
558475f0
MM
1153}
1154
8f17b5c5 1155/* Returns the stack of SCOPE_STMTs for the current function. */
35b1567d 1156
8f17b5c5
MM
1157tree *
1158current_scope_stmt_stack ()
8f471b0d 1159{
8f17b5c5 1160 return &cfun->language->x_scope_stmt_stack;
8f471b0d
MM
1161}
1162
b4c4a9ec
MM
1163/* Finish a parenthesized expression EXPR. */
1164
1165tree
1166finish_parenthesized_expr (expr)
1167 tree expr;
1168{
1169 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1170 /* This inhibits warnings in truthvalue_conversion. */
1171 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1172
19420d00
NS
1173 if (TREE_CODE (expr) == OFFSET_REF)
1174 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1175 enclosed in parentheses. */
1176 PTRMEM_OK_P (expr) = 0;
b4c4a9ec
MM
1177 return expr;
1178}
1179
b69b1501
MM
1180/* Begin a statement-expression. The value returned must be passed to
1181 finish_stmt_expr. */
b4c4a9ec
MM
1182
1183tree
1184begin_stmt_expr ()
1185{
6f80451c
MM
1186 /* If we're outside a function, we won't have a statement-tree to
1187 work with. But, if we see a statement-expression we need to
1188 create one. */
01d939e8 1189 if (! cfun && !last_tree)
6f80451c
MM
1190 begin_stmt_tree (&scope_chain->x_saved_tree);
1191
f1dedc31 1192 keep_next_level (1);
558475f0 1193 /* If we're building a statement tree, then the upcoming compound
b69b1501
MM
1194 statement will be chained onto the tree structure, starting at
1195 last_tree. We return last_tree so that we can later unhook the
1196 compound statement. */
35b1567d
BC
1197 return last_tree;
1198}
1199
596fd31c
MM
1200/* Used when beginning a statement-expression outside function scope.
1201 For example, when handling a file-scope initializer, we use this
1202 function. */
35b1567d 1203
596fd31c
MM
1204tree
1205begin_global_stmt_expr ()
35b1567d 1206{
596fd31c
MM
1207 if (! cfun && !last_tree)
1208 begin_stmt_tree (&scope_chain->x_saved_tree);
35b1567d 1209
596fd31c
MM
1210 keep_next_level (1);
1211
b0ca54af 1212 return (last_tree != NULL_TREE) ? last_tree : expand_start_stmt_expr();
596fd31c
MM
1213}
1214
1215/* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */
1216
1217tree
1218finish_global_stmt_expr (stmt_expr)
1219 tree stmt_expr;
1220{
1221 stmt_expr = expand_end_stmt_expr (stmt_expr);
35b1567d
BC
1222
1223 if (! cfun
1224 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1225 finish_stmt_tree (&scope_chain->x_saved_tree);
1226
596fd31c 1227 return stmt_expr;
b4c4a9ec
MM
1228}
1229
1230/* Finish a statement-expression. RTL_EXPR should be the value
1231 returned by the previous begin_stmt_expr; EXPR is the
1232 statement-expression. Returns an expression representing the
1233 statement-expression. */
1234
1235tree
5ba57b55 1236finish_stmt_expr (rtl_expr)
b4c4a9ec 1237 tree rtl_expr;
b4c4a9ec
MM
1238{
1239 tree result;
1240
35b1567d
BC
1241 /* If the last thing in the statement-expression was not an
1242 expression-statement, then it has type `void'. */
1243 if (!last_expr_type)
1244 last_expr_type = void_type_node;
1245 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1246 TREE_SIDE_EFFECTS (result) = 1;
1247
1248 /* Remove the compound statement from the tree structure; it is
1249 now saved in the STMT_EXPR. */
ae499cce 1250 last_tree = rtl_expr;
35b1567d 1251 TREE_CHAIN (last_tree) = NULL_TREE;
f1dedc31 1252
6f80451c
MM
1253 /* If we created a statement-tree for this statement-expression,
1254 remove it now. */
01d939e8 1255 if (! cfun
6f80451c
MM
1256 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1257 finish_stmt_tree (&scope_chain->x_saved_tree);
1258
b4c4a9ec
MM
1259 return result;
1260}
1261
1262/* Finish a call to FN with ARGS. Returns a representation of the
1263 call. */
1264
1265tree
a759e627 1266finish_call_expr (fn, args, koenig)
b4c4a9ec
MM
1267 tree fn;
1268 tree args;
a759e627 1269 int koenig;
b4c4a9ec 1270{
a759e627
ML
1271 tree result;
1272
1273 if (koenig)
03d82991
JM
1274 {
1275 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1276 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1277 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
e13a4123 1278 fn = do_identifier (fn, 2, args);
03d82991 1279 }
a759e627 1280 result = build_x_function_call (fn, args, current_class_ref);
b4c4a9ec
MM
1281
1282 if (TREE_CODE (result) == CALL_EXPR
66543169
NS
1283 && (! TREE_TYPE (result)
1284 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
b4c4a9ec
MM
1285 result = require_complete_type (result);
1286
1287 return result;
1288}
1289
1290/* Finish a call to a postfix increment or decrement or EXPR. (Which
1291 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1292 POSTDECREMENT_EXPR.) */
1293
1294tree
1295finish_increment_expr (expr, code)
1296 tree expr;
1297 enum tree_code code;
1298{
1299 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1300 a COMPONENT_REF). This way if we've got, say, a reference to a
1301 static member that's being operated on, we don't end up trying to
1302 find a member operator for the class it's in. */
1303
1304 if (TREE_CODE (expr) == OFFSET_REF)
1305 expr = resolve_offset_ref (expr);
1306 return build_x_unary_op (code, expr);
1307}
1308
1309/* Finish a use of `this'. Returns an expression for `this'. */
1310
1311tree
1312finish_this_expr ()
1313{
1314 tree result;
1315
1316 if (current_class_ptr)
1317 {
b4c4a9ec
MM
1318 result = current_class_ptr;
1319 }
1320 else if (current_function_decl
1321 && DECL_STATIC_FUNCTION_P (current_function_decl))
1322 {
8251199e 1323 error ("`this' is unavailable for static member functions");
b4c4a9ec
MM
1324 result = error_mark_node;
1325 }
1326 else
1327 {
1328 if (current_function_decl)
8251199e 1329 error ("invalid use of `this' in non-member function");
b4c4a9ec 1330 else
8251199e 1331 error ("invalid use of `this' at top level");
b4c4a9ec
MM
1332 result = error_mark_node;
1333 }
1334
1335 return result;
1336}
1337
1338/* Finish a member function call using OBJECT and ARGS as arguments to
1339 FN. Returns an expression for the call. */
1340
1341tree
1342finish_object_call_expr (fn, object, args)
1343 tree fn;
1344 tree object;
1345 tree args;
1346{
1347#if 0
1348 /* This is a future direction of this code, but because
1349 build_x_function_call cannot always undo what is done in
1350 build_component_ref entirely yet, we cannot do this. */
1351
1352 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1353 return finish_call_expr (real_fn, args);
1354#else
c219b878 1355 if (DECL_DECLARES_TYPE_P (fn))
c68c56f7
MM
1356 {
1357 if (processing_template_decl)
1358 /* This can happen on code like:
1359
1360 class X;
1361 template <class T> void f(T t) {
1362 t.X();
1363 }
1364
1365 We just grab the underlying IDENTIFIER. */
1366 fn = DECL_NAME (fn);
1367 else
1368 {
33bd39a2 1369 error ("calling type `%T' like a method", fn);
c68c56f7
MM
1370 return error_mark_node;
1371 }
1372 }
1373
b4c4a9ec
MM
1374 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1375#endif
1376}
1377
1378/* Finish a qualified member function call using OBJECT and ARGS as
509fc277 1379 arguments to FN. Returns an expression for the call. */
b4c4a9ec
MM
1380
1381tree
1382finish_qualified_object_call_expr (fn, object, args)
1383 tree fn;
1384 tree object;
1385 tree args;
1386{
6eabb241
MM
1387 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1388 TREE_OPERAND (fn, 1), args);
b4c4a9ec
MM
1389}
1390
1391/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1392 being the scope, if any, of DESTRUCTOR. Returns an expression for
1393 the call. */
1394
1395tree
1396finish_pseudo_destructor_call_expr (object, scope, destructor)
1397 tree object;
1398 tree scope;
1399 tree destructor;
1400{
40242ccf
MM
1401 if (processing_template_decl)
1402 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1403
b4c4a9ec 1404 if (scope && scope != destructor)
33bd39a2 1405 error ("destructor specifier `%T::~%T()' must have matching names",
b4c4a9ec
MM
1406 scope, destructor);
1407
1408 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1409 && (TREE_CODE (TREE_TYPE (object)) !=
1410 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
33bd39a2 1411 error ("`%E' is not of type `%T'", object, destructor);
b4c4a9ec
MM
1412
1413 return cp_convert (void_type_node, object);
1414}
1415
1416/* Finish a call to a globally qualified member function FN using
1417 ARGS. Returns an expression for the call. */
1418
1419tree
75d587eb 1420finish_qualified_call_expr (fn, args)
b4c4a9ec
MM
1421 tree fn;
1422 tree args;
1423{
1424 if (processing_template_decl)
2a1e9fdd 1425 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
b4c4a9ec
MM
1426 else
1427 return build_member_call (TREE_OPERAND (fn, 0),
1428 TREE_OPERAND (fn, 1),
1429 args);
1430}
1431
ce4a0391
MM
1432/* Finish an expression of the form CODE EXPR. */
1433
1434tree
1435finish_unary_op_expr (code, expr)
1436 enum tree_code code;
1437 tree expr;
1438{
1439 tree result = build_x_unary_op (code, expr);
7c355bca
ML
1440 /* Inside a template, build_x_unary_op does not fold the
1441 expression. So check whether the result is folded before
1442 setting TREE_NEGATED_INT. */
1443 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
88b4335f
NS
1444 && TREE_CODE (result) == INTEGER_CST
1445 && !TREE_UNSIGNED (TREE_TYPE (result))
1446 && INT_CST_LT (result, integer_zero_node))
ce4a0391
MM
1447 TREE_NEGATED_INT (result) = 1;
1448 overflow_warning (result);
1449 return result;
1450}
1451
1452/* Finish an id-expression. */
1453
1454tree
1455finish_id_expr (expr)
1456 tree expr;
1457{
1458 if (TREE_CODE (expr) == IDENTIFIER_NODE)
a759e627 1459 expr = do_identifier (expr, 1, NULL_TREE);
ce4a0391 1460
3d7e9ba4
NS
1461 if (TREE_TYPE (expr) == error_mark_node)
1462 expr = error_mark_node;
ce4a0391
MM
1463 return expr;
1464}
1465
70adf8a9
JM
1466static tree current_type_lookups;
1467
1468/* Perform deferred access control for types used in the type of a
1469 declaration. */
1470
1f51a992 1471static void
70adf8a9
JM
1472deferred_type_access_control ()
1473{
1f51a992 1474 tree lookup = type_lookups;
70adf8a9
JM
1475
1476 if (lookup == error_mark_node)
1477 return;
1478
1479 for (; lookup; lookup = TREE_CHAIN (lookup))
1480 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1481}
1482
70adf8a9 1483void
1f51a992
JM
1484decl_type_access_control (decl)
1485 tree decl;
70adf8a9 1486{
1f51a992 1487 tree save_fn;
70adf8a9 1488
1f51a992
JM
1489 if (type_lookups == error_mark_node)
1490 return;
1491
1492 save_fn = current_function_decl;
1493
1494 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1495 current_function_decl = decl;
70adf8a9 1496
70adf8a9 1497 deferred_type_access_control ();
1f51a992
JM
1498
1499 current_function_decl = save_fn;
1500
1501 /* Now strip away the checks for the current declarator; they were
1502 added to type_lookups after typed_declspecs saved the copy that
1503 ended up in current_type_lookups. */
1504 type_lookups = current_type_lookups;
1505}
1506
1507void
1508save_type_access_control (lookups)
1509 tree lookups;
1510{
ab04e34b 1511 current_type_lookups = lookups;
788bf0e3
NS
1512}
1513
1514/* Reset the deferred access control. */
1515
1516void
1517reset_type_access_control ()
1518{
1519 type_lookups = NULL_TREE;
1520 current_type_lookups = NULL_TREE;
1f51a992 1521}
70adf8a9
JM
1522
1523/* Begin a function definition declared with DECL_SPECS and
b4c4a9ec
MM
1524 DECLARATOR. Returns non-zero if the function-declaration is
1525 legal. */
1526
1527int
1f51a992 1528begin_function_definition (decl_specs, declarator)
b4c4a9ec
MM
1529 tree decl_specs;
1530 tree declarator;
1531{
1532 tree specs;
1533 tree attrs;
70adf8a9 1534
b4c4a9ec 1535 split_specs_attrs (decl_specs, &specs, &attrs);
a8f73d4b 1536 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
b4c4a9ec 1537 return 0;
1f51a992
JM
1538
1539 deferred_type_access_control ();
1540 type_lookups = error_mark_node;
1541
39c01e4c
MM
1542 /* The things we're about to see are not directly qualified by any
1543 template headers we've seen thus far. */
1544 reset_specialization ();
1545
b4c4a9ec
MM
1546 return 1;
1547}
1548
1549/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1550 a SCOPE_REF. */
1551
1552tree
1553begin_constructor_declarator (scope, name)
1554 tree scope;
1555 tree name;
1556{
718b8ea5 1557 tree result = build_nt (SCOPE_REF, scope, name);
830fcda8 1558 enter_scope_of (result);
b4c4a9ec
MM
1559 return result;
1560}
1561
ce4a0391
MM
1562/* Finish an init-declarator. Returns a DECL. */
1563
1564tree
1565finish_declarator (declarator, declspecs, attributes,
1566 prefix_attributes, initialized)
1567 tree declarator;
1568 tree declspecs;
1569 tree attributes;
1570 tree prefix_attributes;
1571 int initialized;
1572{
1573 return start_decl (declarator, declspecs, initialized, attributes,
1574 prefix_attributes);
1575}
1576
8014a339 1577/* Finish a translation unit. */
ce4a0391
MM
1578
1579void
1580finish_translation_unit ()
1581{
1582 /* In case there were missing closebraces,
1583 get us back to the global binding level. */
273a708f 1584 pop_everything ();
ce4a0391
MM
1585 while (current_namespace != global_namespace)
1586 pop_namespace ();
0ba8a114
NS
1587
1588 /* Do file scope __FUNCTION__ et al. */
1589 finish_fname_decls ();
1590
ce4a0391
MM
1591 finish_file ();
1592}
1593
b4c4a9ec
MM
1594/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1595 Returns the parameter. */
1596
1597tree
1598finish_template_type_parm (aggr, identifier)
1599 tree aggr;
1600 tree identifier;
1601{
6eabb241 1602 if (aggr != class_type_node)
b4c4a9ec 1603 {
8251199e 1604 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1605 aggr = class_type_node;
1606 }
1607
1608 return build_tree_list (aggr, identifier);
1609}
1610
1611/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1612 Returns the parameter. */
1613
1614tree
1615finish_template_template_parm (aggr, identifier)
1616 tree aggr;
1617 tree identifier;
1618{
1619 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1620 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1621 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1622 DECL_TEMPLATE_RESULT (tmpl) = decl;
c727aa5e 1623 DECL_ARTIFICIAL (decl) = 1;
b4c4a9ec
MM
1624 end_template_decl ();
1625
b37bf5bd
NS
1626 my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110);
1627
b4c4a9ec
MM
1628 return finish_template_type_parm (aggr, tmpl);
1629}
ce4a0391
MM
1630
1631/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1632 non-zero, the parameter list was terminated by a `...'. */
1633
1634tree
1635finish_parmlist (parms, ellipsis)
1636 tree parms;
1637 int ellipsis;
1638{
5cce22b6
NS
1639 if (parms)
1640 {
1641 /* We mark the PARMS as a parmlist so that declarator processing can
1642 disambiguate certain constructs. */
1643 TREE_PARMLIST (parms) = 1;
1644 /* We do not append void_list_node here, but leave it to grokparms
1645 to do that. */
1646 PARMLIST_ELLIPSIS_P (parms) = ellipsis;
1647 }
ce4a0391
MM
1648 return parms;
1649}
1650
1651/* Begin a class definition, as indicated by T. */
1652
1653tree
1654begin_class_definition (t)
1655 tree t;
1656{
7437519c
ZW
1657 if (t == error_mark_node)
1658 return error_mark_node;
1659
788bf0e3
NS
1660 /* Check the bases are accessible. */
1661 decl_type_access_control (TYPE_NAME (t));
1662 reset_type_access_control ();
1663
522d6614
NS
1664 if (processing_template_parmlist)
1665 {
33bd39a2 1666 error ("definition of `%#T' inside template parameter list", t);
522d6614
NS
1667 return error_mark_node;
1668 }
47ee8904
MM
1669
1670 /* In a definition of a member class template, we will get here with
1671 an implicit typename. */
1672 if (IMPLICIT_TYPENAME_P (t))
1673 t = TREE_TYPE (t);
1674 /* A non-implicit typename comes from code like:
1675
1676 template <typename T> struct A {
1677 template <typename U> struct A<T>::B ...
1678
1679 This is erroneous. */
1680 else if (TREE_CODE (t) == TYPENAME_TYPE)
1681 {
33bd39a2 1682 error ("invalid definition of qualified type `%T'", t);
47ee8904
MM
1683 t = error_mark_node;
1684 }
1685
1686 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
ce4a0391 1687 {
33848bb0 1688 t = make_aggr_type (RECORD_TYPE);
ce4a0391
MM
1689 pushtag (make_anon_name (), t, 0);
1690 }
830fcda8 1691
4c571114
MM
1692 /* If we generated a partial instantiation of this type, but now
1693 we're seeing a real definition, we're actually looking at a
1694 partial specialization. Consider:
1695
1696 template <class T, class U>
1697 struct Y {};
1698
1699 template <class T>
1700 struct X {};
1701
1702 template <class T, class U>
1703 void f()
1704 {
1705 typename X<Y<T, U> >::A a;
1706 }
1707
1708 template <class T, class U>
1709 struct X<Y<T, U> >
1710 {
1711 };
1712
1713 We have to undo the effects of the previous partial
1714 instantiation. */
1715 if (PARTIAL_INSTANTIATION_P (t))
1716 {
1717 if (!pedantic)
1718 {
1719 /* Unfortunately, when we're not in pedantic mode, we
1720 attempt to actually fill in some of the fields of the
1721 partial instantiation, in order to support the implicit
1722 typename extension. Clear those fields now, in
1723 preparation for the definition here. The fields cleared
1724 here must match those set in instantiate_class_template.
1725 Look for a comment mentioning begin_class_definition
1726 there. */
1727 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1728 TYPE_FIELDS (t) = NULL_TREE;
1729 TYPE_METHODS (t) = NULL_TREE;
1730 CLASSTYPE_TAGS (t) = NULL_TREE;
1ddd4323 1731 CLASSTYPE_VBASECLASSES (t) = NULL_TREE;
4c571114
MM
1732 TYPE_SIZE (t) = NULL_TREE;
1733 }
830fcda8 1734
4c571114
MM
1735 /* This isn't a partial instantiation any more. */
1736 PARTIAL_INSTANTIATION_P (t) = 0;
1737 }
1738 /* If this type was already complete, and we see another definition,
1739 that's an error. */
d0f062fb 1740 else if (COMPLETE_TYPE_P (t))
ce4a0391 1741 duplicate_tag_error (t);
4c571114 1742
b4f70b3d
NS
1743 /* Update the location of the decl. */
1744 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1745 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1746
4c571114 1747 if (TYPE_BEING_DEFINED (t))
ce4a0391 1748 {
33848bb0 1749 t = make_aggr_type (TREE_CODE (t));
ce4a0391 1750 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 1751 }
ff350acd 1752 maybe_process_partial_specialization (t);
8f032717 1753 pushclass (t, 1);
ce4a0391 1754 TYPE_BEING_DEFINED (t) = 1;
55760a0c 1755 TYPE_PACKED (t) = flag_pack_struct;
ce4a0391
MM
1756 /* Reset the interface data, at the earliest possible
1757 moment, as it might have been set via a class foo;
1758 before. */
1951a1b6
JM
1759 if (! TYPE_ANONYMOUS_P (t))
1760 {
1761 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1762 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1763 (t, interface_unknown);
1764 }
ce4a0391
MM
1765 reset_specialization();
1766
b7975aed
MM
1767 /* Make a declaration for this class in its own scope. */
1768 build_self_reference ();
1769
830fcda8 1770 return t;
ce4a0391
MM
1771}
1772
61a127b3
MM
1773/* Finish the member declaration given by DECL. */
1774
1775void
1776finish_member_declaration (decl)
1777 tree decl;
1778{
1779 if (decl == error_mark_node || decl == NULL_TREE)
1780 return;
1781
1782 if (decl == void_type_node)
1783 /* The COMPONENT was a friend, not a member, and so there's
1784 nothing for us to do. */
1785 return;
1786
1787 /* We should see only one DECL at a time. */
1788 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1789
1790 /* Set up access control for DECL. */
1791 TREE_PRIVATE (decl)
1792 = (current_access_specifier == access_private_node);
1793 TREE_PROTECTED (decl)
1794 = (current_access_specifier == access_protected_node);
1795 if (TREE_CODE (decl) == TEMPLATE_DECL)
1796 {
17aec3eb
RK
1797 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
1798 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
61a127b3
MM
1799 }
1800
1801 /* Mark the DECL as a member of the current class. */
4f1c5b7d 1802 DECL_CONTEXT (decl) = current_class_type;
61a127b3 1803
421844e7
MM
1804 /* [dcl.link]
1805
1806 A C language linkage is ignored for the names of class members
1807 and the member function type of class member functions. */
1808 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
5d2ed28c 1809 SET_DECL_LANGUAGE (decl, lang_cplusplus);
421844e7 1810
61a127b3
MM
1811 /* Put functions on the TYPE_METHODS list and everything else on the
1812 TYPE_FIELDS list. Note that these are built up in reverse order.
1813 We reverse them (to obtain declaration order) in finish_struct. */
1814 if (TREE_CODE (decl) == FUNCTION_DECL
1815 || DECL_FUNCTION_TEMPLATE_P (decl))
1816 {
1817 /* We also need to add this function to the
1818 CLASSTYPE_METHOD_VEC. */
452a394b 1819 add_method (current_class_type, decl, /*error_p=*/0);
61a127b3
MM
1820
1821 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1822 TYPE_METHODS (current_class_type) = decl;
1823 }
1824 else
1825 {
1826 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1827 go at the beginning. The reason is that lookup_field_1
1828 searches the list in order, and we want a field name to
1829 override a type name so that the "struct stat hack" will
1830 work. In particular:
1831
1832 struct S { enum E { }; int E } s;
1833 s.E = 3;
1834
1835 is legal. In addition, the FIELD_DECLs must be maintained in
1836 declaration order so that class layout works as expected.
1837 However, we don't need that order until class layout, so we
1838 save a little time by putting FIELD_DECLs on in reverse order
1839 here, and then reversing them in finish_struct_1. (We could
1840 also keep a pointer to the correct insertion points in the
1841 list.) */
1842
1843 if (TREE_CODE (decl) == TYPE_DECL)
1844 TYPE_FIELDS (current_class_type)
1845 = chainon (TYPE_FIELDS (current_class_type), decl);
1846 else
1847 {
1848 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1849 TYPE_FIELDS (current_class_type) = decl;
1850 }
8f032717
MM
1851
1852 /* Enter the DECL into the scope of the class. */
1853 if (TREE_CODE (decl) != USING_DECL)
1854 pushdecl_class_level (decl);
61a127b3
MM
1855 }
1856}
1857
1858/* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1859 the definition is immediately followed by a semicolon. Returns the
1860 type. */
ce4a0391
MM
1861
1862tree
fbdd0024 1863finish_class_definition (t, attributes, semi, pop_scope_p)
ce4a0391 1864 tree t;
ce4a0391
MM
1865 tree attributes;
1866 int semi;
fbdd0024 1867 int pop_scope_p;
ce4a0391 1868{
7437519c
ZW
1869 if (t == error_mark_node)
1870 return error_mark_node;
1871
ce4a0391
MM
1872 /* finish_struct nukes this anyway; if finish_exception does too,
1873 then it can go. */
1874 if (semi)
1875 note_got_semicolon (t);
1876
dc8263bc
JM
1877 /* If we got any attributes in class_head, xref_tag will stick them in
1878 TREE_TYPE of the type. Grab them now. */
a588fe25
JM
1879 attributes = chainon (TYPE_ATTRIBUTES (t), attributes);
1880 TYPE_ATTRIBUTES (t) = NULL_TREE;
dc8263bc 1881
ce4a0391
MM
1882 if (TREE_CODE (t) == ENUMERAL_TYPE)
1883 ;
1884 else
1885 {
9f33663b 1886 t = finish_struct (t, attributes);
ce4a0391
MM
1887 if (semi)
1888 note_got_semicolon (t);
1889 }
1890
ce4a0391
MM
1891 if (! semi)
1892 check_for_missing_semicolon (t);
fbdd0024
MM
1893 if (pop_scope_p)
1894 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
ce4a0391
MM
1895 if (current_scope () == current_function_decl)
1896 do_pending_defargs ();
1897
1898 return t;
1899}
1900
1901/* Finish processing the default argument expressions cached during
1902 the processing of a class definition. */
1903
1904void
51632249 1905begin_inline_definitions ()
ce4a0391 1906{
0e5921e8 1907 if (current_scope () == current_function_decl)
ce4a0391
MM
1908 do_pending_inlines ();
1909}
1910
1911/* Finish processing the inline function definitions cached during the
1912 processing of a class definition. */
1913
1914void
51632249 1915finish_inline_definitions ()
ce4a0391
MM
1916{
1917 if (current_class_type == NULL_TREE)
1918 clear_inline_text_obstack ();
ce4a0391 1919}
35acd3f2
MM
1920
1921/* Finish processing the declaration of a member class template
1922 TYPES whose template parameters are given by PARMS. */
1923
1924tree
61a127b3 1925finish_member_class_template (types)
35acd3f2
MM
1926 tree types;
1927{
36a117a5
MM
1928 tree t;
1929
1930 /* If there are declared, but undefined, partial specializations
1931 mixed in with the typespecs they will not yet have passed through
1932 maybe_process_partial_specialization, so we do that here. */
1933 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1934 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1935 maybe_process_partial_specialization (TREE_VALUE (t));
1936
35acd3f2 1937 note_list_got_semicolon (types);
61a127b3 1938 grok_x_components (types);
35acd3f2
MM
1939 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1940 /* The component was in fact a friend declaration. We avoid
1941 finish_member_template_decl performing certain checks by
1942 unsetting TYPES. */
1943 types = NULL_TREE;
61a127b3
MM
1944
1945 finish_member_template_decl (types);
1946
35acd3f2
MM
1947 /* As with other component type declarations, we do
1948 not store the new DECL on the list of
1949 component_decls. */
1950 return NULL_TREE;
1951}
36a117a5 1952
306ef644 1953/* Finish processing a complete template declaration. The PARMS are
36a117a5
MM
1954 the template parameters. */
1955
1956void
1957finish_template_decl (parms)
1958 tree parms;
1959{
1960 if (parms)
1961 end_template_decl ();
1962 else
1963 end_specialization ();
1964}
1965
509fc277 1966/* Finish processing a template-id (which names a type) of the form
36a117a5
MM
1967 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1968 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1969 the scope of template-id indicated. */
1970
1971tree
1972finish_template_type (name, args, entering_scope)
1973 tree name;
1974 tree args;
1975 int entering_scope;
1976{
1977 tree decl;
1978
1979 decl = lookup_template_class (name, args,
f9c244b8
NS
1980 NULL_TREE, NULL_TREE,
1981 entering_scope, /*complain=*/1);
36a117a5
MM
1982 if (decl != error_mark_node)
1983 decl = TYPE_STUB_DECL (decl);
1984
1985 return decl;
1986}
648f19f6
MM
1987
1988/* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1989 namespace scope or a class scope. */
1990
1991void
1992enter_scope_of (sr)
1993 tree sr;
1994{
1995 tree scope = TREE_OPERAND (sr, 0);
1996
1997 if (TREE_CODE (scope) == NAMESPACE_DECL)
1998 {
1999 push_decl_namespace (scope);
2000 TREE_COMPLEXITY (sr) = -1;
2001 }
2002 else if (scope != current_class_type)
2003 {
830fcda8
JM
2004 if (TREE_CODE (scope) == TYPENAME_TYPE)
2005 {
2006 /* In a declarator for a template class member, the scope will
2007 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2008 scope = TREE_TYPE (scope);
2009 TREE_OPERAND (sr, 0) = scope;
2010 }
648f19f6
MM
2011 push_nested_class (scope, 3);
2012 TREE_COMPLEXITY (sr) = current_class_depth;
2013 }
2014}
ea6021e8
MM
2015
2016/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2017 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2018 BASE_CLASS, or NULL_TREE if an error occurred. The
aba649ba 2019 ACCESS_SPECIFIER is one of
ea6021e8
MM
2020 access_{default,public,protected_private}[_virtual]_node.*/
2021
2022tree
6eabb241 2023finish_base_specifier (access_specifier, base_class)
ea6021e8
MM
2024 tree access_specifier;
2025 tree base_class;
ea6021e8 2026{
ea6021e8
MM
2027 tree result;
2028
acb044ee
GDR
2029 if (base_class == error_mark_node)
2030 {
2031 error ("invalid base-class specification");
2032 result = NULL_TREE;
2033 }
2034 else if (! is_aggr_type (base_class, 1))
ea6021e8 2035 result = NULL_TREE;
ea6021e8 2036 else
bb92901d 2037 {
89d684bb 2038 if (cp_type_quals (base_class) != 0)
bb92901d 2039 {
33bd39a2 2040 error ("base class `%T' has cv qualifiers", base_class);
bb92901d
NS
2041 base_class = TYPE_MAIN_VARIANT (base_class);
2042 }
2043 result = build_tree_list (access_specifier, base_class);
2044 }
ea6021e8
MM
2045
2046 return result;
2047}
61a127b3
MM
2048
2049/* Called when multiple declarators are processed. If that is not
2050 premitted in this context, an error is issued. */
2051
2052void
2053check_multiple_declarators ()
2054{
2055 /* [temp]
2056
2057 In a template-declaration, explicit specialization, or explicit
2058 instantiation the init-declarator-list in the declaration shall
2059 contain at most one declarator.
2060
2061 We don't just use PROCESSING_TEMPLATE_DECL for the first
2062 condition since that would disallow the perfectly legal code,
2063 like `template <class T> struct S { int i, j; };'. */
2064 tree scope = current_scope ();
2065
2066 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2067 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2068 return;
2069
2070 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2071 || processing_explicit_instantiation
2072 || processing_specialization)
33bd39a2 2073 error ("multiple declarators in template declaration");
61a127b3
MM
2074}
2075
0213a355
JM
2076/* Implement the __typeof keyword: Return the type of EXPR, suitable for
2077 use as a type-specifier. */
2078
b894fc05
JM
2079tree
2080finish_typeof (expr)
2081 tree expr;
2082{
2083 if (processing_template_decl)
2084 {
2085 tree t;
2086
33848bb0 2087 t = make_aggr_type (TYPEOF_TYPE);
b894fc05 2088 TYPE_FIELDS (t) = expr;
b894fc05
JM
2089
2090 return t;
2091 }
2092
12fa82db
MM
2093 if (TREE_CODE (expr) == OFFSET_REF)
2094 expr = resolve_offset_ref (expr);
2095
b894fc05
JM
2096 return TREE_TYPE (expr);
2097}
558475f0 2098
0213a355
JM
2099/* Compute the value of the `sizeof' operator. */
2100
2101tree
2102finish_sizeof (t)
2103 tree t;
2104{
2105 if (processing_template_decl)
78a40378 2106 return build_min_nt (SIZEOF_EXPR, t);
0213a355
JM
2107
2108 return TYPE_P (t) ? c_sizeof (t) : expr_sizeof (t);
2109}
2110
2111/* Implement the __alignof keyword: Return the minimum required
2112 alignment of T, measured in bytes. */
2113
2114tree
2115finish_alignof (t)
2116 tree t;
2117{
2118 if (processing_template_decl)
78a40378 2119 return build_min_nt (ALIGNOF_EXPR, t);
0213a355
JM
2120
2121 return TYPE_P (t) ? c_alignof (t) : c_alignof_expr (t);
2122}
2123
62409b39
MM
2124/* Generate RTL for the statement T, and its substatements, and any
2125 other statements at its nesting level. */
558475f0 2126
54f7877c
MM
2127static void
2128cp_expand_stmt (t)
558475f0
MM
2129 tree t;
2130{
54f7877c 2131 switch (TREE_CODE (t))
62409b39 2132 {
54f7877c
MM
2133 case CTOR_STMT:
2134 genrtl_ctor_stmt (t);
2135 break;
a7e4cfa0 2136
54f7877c
MM
2137 case TRY_BLOCK:
2138 genrtl_try_block (t);
2139 break;
558475f0 2140
52a11cbf
RH
2141 case EH_SPEC_BLOCK:
2142 genrtl_eh_spec_block (t);
2143 break;
2144
54f7877c
MM
2145 case HANDLER:
2146 genrtl_handler (t);
2147 break;
558475f0 2148
54f7877c
MM
2149 case SUBOBJECT:
2150 genrtl_subobject (SUBOBJECT_CLEANUP (t));
2151 break;
2152
54f7877c
MM
2153 case RETURN_INIT:
2154 genrtl_named_return_value ();
2155 break;
2156
9da99f7d
NS
2157 case USING_STMT:
2158 break;
2159
54f7877c 2160 default:
a98facb0 2161 abort ();
54f7877c
MM
2162 break;
2163 }
558475f0
MM
2164}
2165
3eb24f73
MM
2166/* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2167 will equivalent CALL_EXPRs. */
2168
2169static tree
2170simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2171 tree *tp;
2172 int *walk_subtrees ATTRIBUTE_UNUSED;
2173 void *data ATTRIBUTE_UNUSED;
2174{
2175 tree aggr_init_expr;
2176 tree call_expr;
2177 tree fn;
2178 tree args;
2179 tree slot;
2180 tree type;
3eb24f73
MM
2181 int copy_from_buffer_p;
2182
3eb24f73 2183 aggr_init_expr = *tp;
22e92ac3
MM
2184 /* We don't need to walk into types; there's nothing in a type that
2185 needs simplification. (And, furthermore, there are places we
2186 actively don't want to go. For example, we don't want to wander
2187 into the default arguments for a FUNCTION_DECL that appears in a
2188 CALL_EXPR.) */
2189 if (TYPE_P (aggr_init_expr))
2190 {
2191 *walk_subtrees = 0;
2192 return NULL_TREE;
2193 }
2194 /* Only AGGR_INIT_EXPRs are interesting. */
2195 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
3eb24f73
MM
2196 return NULL_TREE;
2197
2198 /* Form an appropriate CALL_EXPR. */
2199 fn = TREE_OPERAND (aggr_init_expr, 0);
2200 args = TREE_OPERAND (aggr_init_expr, 1);
2201 slot = TREE_OPERAND (aggr_init_expr, 2);
2202 type = TREE_TYPE (aggr_init_expr);
3eb24f73
MM
2203 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2204 {
2205 /* Replace the first argument with the address of the third
2206 argument to the AGGR_INIT_EXPR. */
dffd7eb6 2207 cxx_mark_addressable (slot);
b850de4f
MM
2208 args = tree_cons (NULL_TREE,
2209 build1 (ADDR_EXPR,
2210 build_pointer_type (TREE_TYPE (slot)),
2211 slot),
3eb24f73
MM
2212 TREE_CHAIN (args));
2213 }
b850de4f
MM
2214 call_expr = build (CALL_EXPR,
2215 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
2216 fn, args, NULL_TREE);
3eb24f73
MM
2217 TREE_SIDE_EFFECTS (call_expr) = 1;
2218
2219 /* If we're using the non-reentrant PCC calling convention, then we
2220 need to copy the returned value out of the static buffer into the
2221 SLOT. */
2222 copy_from_buffer_p = 0;
2223#ifdef PCC_STATIC_STRUCT_RETURN
2224 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2225 {
41251458 2226 int old_ac = flag_access_control;
3eb24f73
MM
2227
2228 flag_access_control = 0;
46af705a
JDA
2229 call_expr = build_aggr_init (slot, call_expr,
2230 DIRECT_BIND | LOOKUP_ONLYCONVERTING);
3eb24f73
MM
2231 flag_access_control = old_ac;
2232 copy_from_buffer_p = 1;
2233 }
2234#endif
2235
2236 /* If this AGGR_INIT_EXPR indicates the value returned by a
2237 function, then we want to use the value of the initialized
2238 location as the result. */
2239 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2240 {
2241 call_expr = build (COMPOUND_EXPR, type,
2242 call_expr, slot);
2243 TREE_SIDE_EFFECTS (call_expr) = 1;
2244 }
2245
2246 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2247 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2248 *tp = call_expr;
2249
2250 /* Keep iterating. */
2251 return NULL_TREE;
2252}
2253
31f8e4f3
MM
2254/* Emit all thunks to FN that should be emitted when FN is emitted. */
2255
2256static void
2257emit_associated_thunks (fn)
2258 tree fn;
2259{
2260 /* When we use vcall offsets, we emit thunks with the virtual
2261 functions to which they thunk. The whole point of vcall offsets
2262 is so that you can know statically the entire set of thunks that
2263 will ever be needed for a given virtual function, thereby
2264 enabling you to output all the thunks with the function itself. */
3461fba7 2265 if (DECL_VIRTUAL_P (fn))
31f8e4f3
MM
2266 {
2267 tree binfo;
2268 tree v;
2269
2270 for (binfo = TYPE_BINFO (DECL_CONTEXT (fn));
2271 binfo;
2272 binfo = TREE_CHAIN (binfo))
2273 for (v = BINFO_VIRTUALS (binfo); v; v = TREE_CHAIN (v))
2274 if (BV_FN (v) == fn
2275 && (!integer_zerop (BV_DELTA (v))
d0cd8b44 2276 || BV_USE_VCALL_INDEX_P (v)))
31f8e4f3
MM
2277 {
2278 tree thunk;
2279 tree vcall_index;
2280
2281 if (BV_USE_VCALL_INDEX_P (v))
2282 {
2283 vcall_index = BV_VCALL_INDEX (v);
2284 my_friendly_assert (vcall_index != NULL_TREE, 20000621);
2285 }
2286 else
2287 vcall_index = NULL_TREE;
2288
2289 thunk = make_thunk (build1 (ADDR_EXPR,
2290 vfunc_ptr_type_node,
2291 fn),
2292 BV_DELTA (v),
d0cd8b44 2293 vcall_index);
31f8e4f3
MM
2294 use_thunk (thunk, /*emit_p=*/1);
2295 }
2296 }
2297}
2298
558475f0
MM
2299/* Generate RTL for FN. */
2300
2301void
2302expand_body (fn)
2303 tree fn;
2304{
62409b39 2305 int saved_lineno;
3b304f5b 2306 const char *saved_input_filename;
558475f0 2307
62409b39
MM
2308 /* When the parser calls us after finishing the body of a template
2309 function, we don't really want to expand the body. When we're
2310 processing an in-class definition of an inline function,
2311 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2312 to look at the function itself. */
2313 if (processing_template_decl
2314 || (DECL_LANG_SPECIFIC (fn)
2315 && DECL_TEMPLATE_INFO (fn)
2316 && uses_template_parms (DECL_TI_ARGS (fn))))
d658cd4c
MM
2317 {
2318 /* Normally, collection only occurs in rest_of_compilation. So,
2319 if we don't collect here, we never collect junk generated
2320 during the processing of templates until we hit a
2321 non-template function. */
2322 ggc_collect ();
2323 return;
2324 }
62409b39 2325
3eb24f73 2326 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
ee94fce6
MM
2327 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2328 simplify_aggr_init_exprs_r,
2329 NULL);
3eb24f73 2330
3461fba7
NS
2331 /* If this is a constructor or destructor body, we have to clone
2332 it. */
db9b2174
MM
2333 if (maybe_clone_body (fn))
2334 {
2335 /* We don't want to process FN again, so pretend we've written
2336 it out, even though we haven't. */
2337 TREE_ASM_WRITTEN (fn) = 1;
2338 return;
2339 }
2340
84df082b
MM
2341 /* There's no reason to do any of the work here if we're only doing
2342 semantic analysis; this code just generates RTL. */
2343 if (flag_syntax_only)
2344 return;
2345
21b0c6dc
MM
2346 /* If possible, avoid generating RTL for this function. Instead,
2347 just record it as an inline function, and wait until end-of-file
2348 to decide whether to write it out or not. */
56e770bf
MM
2349 if (/* We have to generate RTL if it's not an inline function. */
2350 (DECL_INLINE (fn) || DECL_COMDAT (fn))
4f8e1232 2351 /* Or if we have to emit code for inline functions anyhow. */
21b0c6dc
MM
2352 && !flag_keep_inline_functions
2353 /* Or if we actually have a reference to the function. */
4f8e1232 2354 && !DECL_NEEDED_P (fn))
21b0c6dc 2355 {
21b0c6dc
MM
2356 /* Set DECL_EXTERNAL so that assemble_external will be called as
2357 necessary. We'll clear it again in finish_file. */
2358 if (!DECL_EXTERNAL (fn))
2359 {
2360 DECL_NOT_REALLY_EXTERN (fn) = 1;
2361 DECL_EXTERNAL (fn) = 1;
2362 }
2363 /* Remember this function. In finish_file we'll decide if
2364 we actually need to write this function out. */
56e770bf 2365 defer_fn (fn);
aba649ba 2366 /* Let the back-end know that this function exists. */
2b85879e 2367 (*debug_hooks->deferred_inline_function) (fn);
21b0c6dc
MM
2368 return;
2369 }
2370
92788413
MM
2371 /* Compute the appropriate object-file linkage for inline
2372 functions. */
79065db2 2373 if (DECL_DECLARED_INLINE_P (fn))
92788413
MM
2374 import_export_decl (fn);
2375
4f8e1232
MM
2376 /* If FN is external, then there's no point in generating RTL for
2377 it. This situation can arise with an inline function under
83662e2b 2378 `-fexternal-templates'; we instantiate the function, even though
4f8e1232
MM
2379 we're not planning on emitting it, in case we get a chance to
2380 inline it. */
2381 if (DECL_EXTERNAL (fn))
2382 return;
2383
297a5329 2384 timevar_push (TV_INTEGRATION);
ea11ca7e 2385
6be77748
NS
2386 /* Optimize the body of the function before expanding it. */
2387 optimize_function (fn);
46e8c075 2388
297a5329
JM
2389 timevar_pop (TV_INTEGRATION);
2390 timevar_push (TV_EXPAND);
2391
62409b39 2392 /* Save the current file name and line number. When we expand the
84df082b 2393 body of the function, we'll set LINENO and INPUT_FILENAME so that
62409b39
MM
2394 error-mesages come out in the right places. */
2395 saved_lineno = lineno;
2396 saved_input_filename = input_filename;
2397 lineno = DECL_SOURCE_LINE (fn);
2398 input_filename = DECL_SOURCE_FILE (fn);
2399
f444e36b 2400 genrtl_start_function (fn);
6462c441 2401 current_function_is_thunk = DECL_THUNK_P (fn);
558475f0 2402
558475f0 2403 /* Expand the body. */
b35d4555 2404 expand_stmt (DECL_SAVED_TREE (fn));
558475f0 2405
62409b39
MM
2406 /* Statements should always be full-expressions at the outermost set
2407 of curly braces for a function. */
f2c5f623 2408 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
62409b39
MM
2409
2410 /* The outermost statement for a function contains the line number
2411 recorded when we finished processing the function. */
2412 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2413
2414 /* Generate code for the function. */
f444e36b 2415 genrtl_finish_function (fn);
62409b39 2416
46e8c075
MM
2417 /* If possible, obliterate the body of the function so that it can
2418 be garbage collected. */
b7442fb5 2419 if (dump_enabled_p (TDI_all))
46e8c075
MM
2420 /* Keep the body; we're going to dump it. */
2421 ;
2422 else if (DECL_INLINE (fn) && flag_inline_trees)
2423 /* We might need the body of this function so that we can expand
2424 it inline somewhere else. */
2425 ;
2426 else
2427 /* We don't need the body; blow it away. */
d658cd4c
MM
2428 DECL_SAVED_TREE (fn) = NULL_TREE;
2429
62409b39
MM
2430 /* And restore the current source position. */
2431 lineno = saved_lineno;
2432 input_filename = saved_input_filename;
f12eef58 2433 extract_interface_info ();
ea11ca7e
JM
2434
2435 timevar_pop (TV_EXPAND);
14691f8d
RH
2436
2437 /* Emit any thunks that should be emitted at the same time as FN. */
2438 emit_associated_thunks (fn);
558475f0 2439}
54f7877c 2440
07b2f2fd
JM
2441/* Helper function for walk_tree, used by finish_function to override all
2442 the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return
2443 value optimization. */
0d97bf4c 2444
07b2f2fd 2445tree
0d97bf4c
JM
2446nullify_returns_r (tp, walk_subtrees, data)
2447 tree *tp;
2448 int *walk_subtrees;
07b2f2fd 2449 void *data;
0d97bf4c 2450{
07b2f2fd
JM
2451 tree nrv = (tree) data;
2452
2453 /* No need to walk into types. There wouldn't be any need to walk into
2454 non-statements, except that we have to consider STMT_EXPRs. */
0d97bf4c
JM
2455 if (TYPE_P (*tp))
2456 *walk_subtrees = 0;
2457 else if (TREE_CODE (*tp) == RETURN_STMT)
07b2f2fd
JM
2458 RETURN_EXPR (*tp) = NULL_TREE;
2459 else if (TREE_CODE (*tp) == CLEANUP_STMT
2460 && CLEANUP_DECL (*tp) == nrv)
2461 CLEANUP_EXPR (*tp) = NULL_TREE;
0d97bf4c
JM
2462
2463 /* Keep iterating. */
2464 return NULL_TREE;
2465}
2466
f444e36b
MM
2467/* Start generating the RTL for FN. */
2468
2469static void
2470genrtl_start_function (fn)
2471 tree fn;
2472{
f444e36b
MM
2473 /* Tell everybody what function we're processing. */
2474 current_function_decl = fn;
2475 /* Get the RTL machinery going for this function. */
2476 init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
2477 /* Let everybody know that we're expanding this function, not doing
2478 semantic analysis. */
2479 expanding_p = 1;
2480
2481 /* Even though we're inside a function body, we still don't want to
2482 call expand_expr to calculate the size of a variable-sized array.
2483 We haven't necessarily assigned RTL to all variables yet, so it's
2484 not safe to try to expand expressions involving them. */
2485 immediate_size_expand = 0;
2486 cfun->x_dont_save_pending_sizes_p = 1;
2487
2488 /* Let the user know we're compiling this function. */
2489 announce_function (fn);
2490
2491 /* Initialize the per-function data. */
2492 my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911);
2493 if (DECL_SAVED_FUNCTION_DATA (fn))
2494 {
2495 /* If we already parsed this function, and we're just expanding it
2496 now, restore saved state. */
2497 *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
2498
2499 /* This function is being processed in whole-function mode; we
2500 already did semantic analysis. */
2501 cfun->x_whole_function_mode_p = 1;
2502
2503 /* If we decided that we didn't want to inline this function,
2504 make sure the back-end knows that. */
2505 if (!current_function_cannot_inline)
2506 current_function_cannot_inline = cp_function_chain->cannot_inline;
2507
2508 /* We don't need the saved data anymore. */
2509 free (DECL_SAVED_FUNCTION_DATA (fn));
2510 DECL_SAVED_FUNCTION_DATA (fn) = NULL;
2511 }
2512
f444e36b
MM
2513 /* Keep track of how many functions we're presently expanding. */
2514 ++function_depth;
2515
2516 /* Create a binding level for the parameters. */
a0de9d20 2517 expand_function_start (fn, /*parms_have_cleanups=*/0);
f444e36b
MM
2518 /* If this function is `main'. */
2519 if (DECL_MAIN_P (fn))
2520 expand_main_function ();
0d97bf4c 2521
07b2f2fd
JM
2522 /* Give our named return value the same RTL as our RESULT_DECL. */
2523 if (current_function_return_value)
2524 COPY_DECL_RTL (DECL_RESULT (fn), current_function_return_value);
f444e36b
MM
2525}
2526
2527/* Finish generating the RTL for FN. */
2528
2529static void
2530genrtl_finish_function (fn)
2531 tree fn;
2532{
4f8e1232 2533 tree t;
f444e36b
MM
2534
2535#if 0
2536 if (write_symbols != NO_DEBUG)
2537 {
2538 /* Keep this code around in case we later want to control debug info
2539 based on whether a type is "used". (jason 1999-11-11) */
2540
2541 tree ttype = target_type (fntype);
2542 tree parmdecl;
2543
2544 if (IS_AGGR_TYPE (ttype))
2545 /* Let debugger know it should output info for this type. */
2546 note_debug_info_needed (ttype);
2547
2548 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
2549 {
2550 ttype = target_type (TREE_TYPE (parmdecl));
2551 if (IS_AGGR_TYPE (ttype))
2552 /* Let debugger know it should output info for this type. */
2553 note_debug_info_needed (ttype);
2554 }
2555 }
2556#endif
2557
2558 /* Clean house because we will need to reorder insns here. */
2559 do_pending_stack_adjust ();
2560
a0de9d20
JM
2561 /* If we have a named return value, we need to force a return so that
2562 the return register is USEd. */
2563 if (DECL_NAME (DECL_RESULT (fn)))
e6fe680d 2564 emit_jump (return_label);
f444e36b
MM
2565
2566 /* We hard-wired immediate_size_expand to zero in start_function.
2567 Expand_function_end will decrement this variable. So, we set the
2568 variable to one here, so that after the decrement it will remain
2569 zero. */
2570 immediate_size_expand = 1;
2571
2572 /* Generate rtl for function exit. */
f21add07 2573 expand_function_end (input_filename, lineno, 0);
f444e36b 2574
f444e36b
MM
2575 /* If this is a nested function (like a template instantiation that
2576 we're compiling in the midst of compiling something else), push a
2577 new GC context. That will keep local variables on the stack from
2578 being collected while we're doing the compilation of this
2579 function. */
2580 if (function_depth > 1)
2581 ggc_push_context ();
2582
b850de4f
MM
2583 /* There's no need to defer outputting this function any more; we
2584 know we want to output it. */
2585 DECL_DEFER_OUTPUT (fn) = 0;
2586
f444e36b
MM
2587 /* Run the optimizers and output the assembler code for this
2588 function. */
2589 rest_of_compilation (fn);
2590
2591 /* Undo the call to ggc_push_context above. */
2592 if (function_depth > 1)
2593 ggc_pop_context ();
2594
f444e36b
MM
2595#if 0
2596 /* Keep this code around in case we later want to control debug info
2597 based on whether a type is "used". (jason 1999-11-11) */
2598
2599 if (ctype && TREE_ASM_WRITTEN (fn))
2600 note_debug_info_needed (ctype);
2601#endif
2602
2603 /* If this function is marked with the constructor attribute, add it
2604 to the list of functions to be called along with constructors
2605 from static duration objects. */
2606 if (DECL_STATIC_CONSTRUCTOR (fn))
2607 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
2608
2609 /* If this function is marked with the destructor attribute, add it
2610 to the list of functions to be called along with destructors from
2611 static duration objects. */
2612 if (DECL_STATIC_DESTRUCTOR (fn))
2613 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
2614
f444e36b
MM
2615 --function_depth;
2616
4f8e1232
MM
2617 /* In C++, we should never be saving RTL for the function. */
2618 my_friendly_assert (!DECL_SAVED_INSNS (fn), 20010903);
b850de4f 2619
4f8e1232
MM
2620 /* Since we don't need the RTL for this function anymore, stop
2621 pointing to it. That's especially important for LABEL_DECLs,
2622 since you can reach all the instructions in the function from the
2623 CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the
2624 BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static
2625 local variables. */
2626 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2627 clear_decl_rtl,
2628 NULL);
f444e36b 2629
4f8e1232
MM
2630 /* Clear out the RTL for the arguments. */
2631 for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t))
2632 {
2633 SET_DECL_RTL (t, NULL_RTX);
2634 DECL_INCOMING_RTL (t) = NULL_RTX;
b850de4f 2635 }
4f8e1232
MM
2636
2637 if (!(flag_inline_trees && DECL_INLINE (fn)))
2638 /* DECL_INITIAL must remain nonzero so we know this was an
2639 actual function definition. */
2640 DECL_INITIAL (fn) = error_mark_node;
b850de4f 2641
f444e36b
MM
2642 /* Let the error reporting routines know that we're outside a
2643 function. For a nested function, this value is used in
2644 pop_cp_function_context and then reset via pop_function_context. */
2645 current_function_decl = NULL_TREE;
2646}
2647
b850de4f
MM
2648/* Clear out the DECL_RTL for the non-static variables in BLOCK and
2649 its sub-blocks. */
2650
2651static tree
2652clear_decl_rtl (tp, walk_subtrees, data)
2653 tree *tp;
2654 int *walk_subtrees ATTRIBUTE_UNUSED;
2655 void *data ATTRIBUTE_UNUSED;
2656{
2657 if (nonstatic_local_decl_p (*tp))
2658 SET_DECL_RTL (*tp, NULL_RTX);
2659
2660 return NULL_TREE;
2661}
2662
54f7877c
MM
2663/* Perform initialization related to this module. */
2664
2665void
2666init_cp_semantics ()
2667{
2668 lang_expand_stmt = cp_expand_stmt;
2669}