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