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