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