]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
* g++.old-deja/g++.pt/crash59.C: New test.
[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
d569399b 6 Copyright (C) 1998, 1999, 2000 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
153void
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
ae499cce 174 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
9bfadf57
MM
199void
200finish_expr_stmt (expr)
ad321293
MM
201 tree expr;
202{
ce4a0391 203 if (expr != NULL_TREE)
ad321293 204 {
35b1567d 205 if (!processing_template_decl
f2c5f623 206 && !(stmts_are_full_exprs_p ())
35b1567d
BC
207 && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
208 && lvalue_p (expr))
209 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
210 expr = default_conversion (expr);
211
f2c5f623 212 if (stmts_are_full_exprs_p ())
35b1567d
BC
213 expr = convert_to_void (expr, "statement");
214
215 if (!processing_template_decl)
216 expr = break_out_cleanups (expr);
217
ae499cce 218 add_stmt (build_stmt (EXPR_STMT, expr));
35b1567d 219 }
364460b6 220
35b1567d 221 finish_stmt ();
558475f0 222
35b1567d
BC
223 /* This was an expression-statement, so we save the type of the
224 expression. */
225 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
226}
227
35b1567d 228
ad321293
MM
229/* Begin an if-statement. Returns a newly created IF_STMT if
230 appropriate. */
231
232tree
233begin_if_stmt ()
234{
235 tree r;
9bfadf57 236 do_pushlevel ();
0dfdeca6 237 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
ae499cce 238 add_stmt (r);
ad321293
MM
239 return r;
240}
241
242/* Process the COND of an if-statement, which may be given by
243 IF_STMT. */
244
245void
246finish_if_stmt_cond (cond, if_stmt)
247 tree cond;
248 tree if_stmt;
249{
ed5511d9 250 cond = maybe_convert_cond (cond);
35b1567d 251 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
ad321293
MM
252}
253
254/* Finish the then-clause of an if-statement, which may be given by
255 IF_STMT. */
256
257tree
258finish_then_clause (if_stmt)
259 tree if_stmt;
260{
35b1567d 261 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
ae499cce 262 last_tree = if_stmt;
35b1567d 263 return if_stmt;
ad321293
MM
264}
265
266/* Begin the else-clause of an if-statement. */
267
268void
269begin_else_clause ()
270{
ad321293
MM
271}
272
273/* Finish the else-clause of an if-statement, which may be given by
274 IF_STMT. */
275
276void
277finish_else_clause (if_stmt)
278 tree if_stmt;
279{
35b1567d 280 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
ad321293
MM
281}
282
283/* Finsh an if-statement. */
284
285void
286finish_if_stmt ()
287{
ad321293
MM
288 do_poplevel ();
289 finish_stmt ();
290}
291
35b1567d
BC
292void
293clear_out_block ()
294{
295 /* If COND wasn't a declaration, clear out the
296 block we made for it and start a new one here so the
297 optimization in expand_end_loop will work. */
298 if (getdecls () == NULL_TREE)
299 {
300 do_poplevel ();
301 do_pushlevel ();
302 }
303}
304
ad321293
MM
305/* Begin a while-statement. Returns a newly created WHILE_STMT if
306 appropriate. */
307
308tree
309begin_while_stmt ()
310{
311 tree r;
0dfdeca6 312 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
ae499cce 313 add_stmt (r);
ad321293 314 do_pushlevel ();
ad321293
MM
315 return r;
316}
317
27d26ee7 318/* Process the COND of a while-statement, which may be given by
ad321293
MM
319 WHILE_STMT. */
320
321void
322finish_while_stmt_cond (cond, while_stmt)
323 tree cond;
324 tree while_stmt;
325{
ed5511d9 326 cond = maybe_convert_cond (cond);
35b1567d
BC
327 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
328 clear_out_block ();
ad321293
MM
329}
330
331/* Finish a while-statement, which may be given by WHILE_STMT. */
332
333void
334finish_while_stmt (while_stmt)
335 tree while_stmt;
336{
337 do_poplevel ();
35b1567d 338 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
ad321293
MM
339 finish_stmt ();
340}
341
342/* Begin a do-statement. Returns a newly created DO_STMT if
343 appropriate. */
344
345tree
346begin_do_stmt ()
347{
0dfdeca6 348 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
ae499cce 349 add_stmt (r);
35b1567d 350 return r;
ad321293
MM
351}
352
353/* Finish the body of a do-statement, which may be given by DO_STMT. */
354
355void
356finish_do_body (do_stmt)
357 tree do_stmt;
358{
35b1567d 359 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
ad321293
MM
360}
361
362/* Finish a do-statement, which may be given by DO_STMT, and whose
363 COND is as indicated. */
364
365void
366finish_do_stmt (cond, do_stmt)
367 tree cond;
368 tree do_stmt;
369{
ed5511d9 370 cond = maybe_convert_cond (cond);
35b1567d
BC
371 DO_COND (do_stmt) = cond;
372 finish_stmt ();
373}
ed5511d9 374
ad321293
MM
375/* Finish a return-statement. The EXPRESSION returned, if any, is as
376 indicated. */
377
378void
379finish_return_stmt (expr)
380 tree expr;
381{
35b1567d 382 if (!processing_template_decl)
efee38a9 383 expr = check_return_expr (expr);
35b1567d 384 if (!processing_template_decl)
efee38a9
MM
385 {
386 if (DECL_CONSTRUCTOR_P (current_function_decl) && ctor_label)
387 {
388 /* Even returns without a value in a constructor must return
389 `this'. We accomplish this by sending all returns in a
390 constructor to the CTOR_LABEL; finish_function emits code to
391 return a value there. When we finally generate the real
392 return statement, CTOR_LABEL is no longer set, and we fall
393 through into the normal return-processing code below. */
394 finish_goto_stmt (ctor_label);
395 return;
396 }
397 else if (DECL_DESTRUCTOR_P (current_function_decl))
398 {
399 /* Similarly, all destructors must run destructors for
400 base-classes before returning. So, all returns in a
401 destructor get sent to the DTOR_LABEL; finsh_function emits
402 code to return a value there. */
403 finish_goto_stmt (dtor_label);
404 return;
405 }
406 }
ae499cce 407 add_stmt (build_stmt (RETURN_STMT, expr));
35b1567d
BC
408 finish_stmt ();
409}
efee38a9 410
ad321293
MM
411/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
412
413tree
414begin_for_stmt ()
415{
416 tree r;
417
0dfdeca6
BC
418 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
419 NULL_TREE, NULL_TREE);
f2c5f623 420 NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0;
ae499cce 421 add_stmt (r);
f2c5f623 422 if (NEW_FOR_SCOPE_P (r))
ad321293
MM
423 {
424 do_pushlevel ();
425 note_level_for_for ();
426 }
427
428 return r;
429}
430
431/* Finish the for-init-statement of a for-statement, which may be
432 given by FOR_STMT. */
433
434void
435finish_for_init_stmt (for_stmt)
436 tree for_stmt;
437{
35b1567d
BC
438 if (last_tree != for_stmt)
439 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
ad321293
MM
440 do_pushlevel ();
441}
442
443/* Finish the COND of a for-statement, which may be given by
444 FOR_STMT. */
445
446void
447finish_for_cond (cond, for_stmt)
448 tree cond;
449 tree for_stmt;
450{
ed5511d9 451 cond = maybe_convert_cond (cond);
35b1567d
BC
452 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
453 clear_out_block ();
ad321293
MM
454}
455
456/* Finish the increment-EXPRESSION in a for-statement, which may be
457 given by FOR_STMT. */
458
459void
460finish_for_expr (expr, for_stmt)
461 tree expr;
462 tree for_stmt;
463{
35b1567d 464 FOR_EXPR (for_stmt) = expr;
ad321293
MM
465}
466
467/* Finish the body of a for-statement, which may be given by
468 FOR_STMT. The increment-EXPR for the loop must be
469 provided. */
470
471void
35b1567d 472finish_for_stmt (for_stmt)
ad321293
MM
473 tree for_stmt;
474{
475 /* Pop the scope for the body of the loop. */
476 do_poplevel ();
35b1567d 477 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
f2c5f623 478 if (NEW_FOR_SCOPE_P (for_stmt))
ad321293 479 do_poplevel ();
ad321293
MM
480 finish_stmt ();
481}
482
483/* Finish a break-statement. */
484
485void
486finish_break_stmt ()
487{
56cb9733 488 add_stmt (build_break_stmt ());
35b1567d
BC
489}
490
ad321293
MM
491/* Finish a continue-statement. */
492
493void
494finish_continue_stmt ()
495{
56cb9733 496 add_stmt (build_continue_stmt ());
ad321293
MM
497}
498
35b1567d
BC
499/* Begin a switch-statement. Returns a new SWITCH_STMT if
500 appropriate. */
501
502tree
503begin_switch_stmt ()
504{
505 tree r;
0dfdeca6 506 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE);
ae499cce 507 add_stmt (r);
35b1567d 508 do_pushlevel ();
527f0080 509 return r;
ad321293
MM
510}
511
527f0080 512/* Finish the cond of a switch-statement. */
ad321293 513
527f0080
MM
514void
515finish_switch_cond (cond, switch_stmt)
ad321293 516 tree cond;
527f0080 517 tree switch_stmt;
ad321293 518{
35b1567d 519 if (!processing_template_decl)
373eb3b3 520 {
56cb9733
MM
521 tree type;
522 tree index;
523
35b1567d
BC
524 /* Convert the condition to an integer or enumeration type. */
525 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, 1);
526 if (cond == NULL_TREE)
373eb3b3 527 {
35b1567d
BC
528 error ("switch quantity not an integer");
529 cond = error_mark_node;
530 }
531 if (cond != error_mark_node)
532 {
35b1567d 533 cond = default_conversion (cond);
2bb5d995 534 cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond));
373eb3b3 535 }
56cb9733
MM
536
537 type = TREE_TYPE (cond);
538 index = get_unwidened (cond, NULL_TREE);
539 /* We can't strip a conversion from a signed type to an unsigned,
540 because if we did, int_fits_type_p would do the wrong thing
541 when checking case values for being in range,
542 and it's too hard to do the right thing. */
543 if (TREE_UNSIGNED (TREE_TYPE (cond))
544 == TREE_UNSIGNED (TREE_TYPE (index)))
545 cond = index;
ad321293 546 }
35b1567d 547 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
56cb9733 548 push_switch (switch_stmt);
ad321293
MM
549}
550
551/* Finish the body of a switch-statement, which may be given by
552 SWITCH_STMT. The COND to switch on is indicated. */
553
554void
35b1567d 555finish_switch_stmt (switch_stmt)
ad321293
MM
556 tree switch_stmt;
557{
35b1567d 558 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
ad321293
MM
559 pop_switch ();
560 do_poplevel ();
561 finish_stmt ();
562}
563
35b1567d 564/* Generate the RTL for T, which is a TRY_BLOCK. */
6625cdb5 565
54f7877c
MM
566static void
567genrtl_try_block (t)
35b1567d
BC
568 tree t;
569{
570 if (CLEANUP_P (t))
571 {
572 expand_eh_region_start ();
573 expand_stmt (TRY_STMTS (t));
574 expand_eh_region_end (protect_with_terminate (TRY_HANDLERS (t)));
46e8c075 575 }
ad321293
MM
576 else
577 {
f444e36b
MM
578 if (!FN_TRY_BLOCK_P (t))
579 emit_line_note (input_filename, lineno);
580 expand_start_try_stmts ();
35b1567d
BC
581
582 expand_stmt (TRY_STMTS (t));
ad321293 583
35b1567d 584 if (FN_TRY_BLOCK_P (t))
ad321293 585 {
35b1567d
BC
586 end_protect_partials ();
587 expand_start_all_catch ();
588 in_function_try_handler = 1;
589 expand_stmt (TRY_HANDLERS (t));
590 in_function_try_handler = 0;
591 expand_end_all_catch ();
592 }
593 else
594 {
595 expand_start_all_catch ();
596 expand_stmt (TRY_HANDLERS (t));
597 expand_end_all_catch ();
ad321293 598 }
ad321293
MM
599 }
600}
601
602/* Begin a try-block. Returns a newly-created TRY_BLOCK if
603 appropriate. */
604
605tree
606begin_try_block ()
607{
0dfdeca6 608 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
ae499cce 609 add_stmt (r);
35b1567d 610 return r;
ad321293
MM
611}
612
0dde4175
JM
613/* Likewise, for a function-try-block. */
614
615tree
616begin_function_try_block ()
617{
0dfdeca6 618 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
35b1567d 619 FN_TRY_BLOCK_P (r) = 1;
ae499cce 620 add_stmt (r);
35b1567d 621 return r;
0dde4175
JM
622}
623
ad321293
MM
624/* Finish a try-block, which may be given by TRY_BLOCK. */
625
626void
627finish_try_block (try_block)
628 tree try_block;
629{
35b1567d 630 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
ad321293
MM
631}
632
efa8eda3
MM
633/* Finish the body of a cleanup try-block, which may be given by
634 TRY_BLOCK. */
635
62409b39
MM
636void
637finish_cleanup_try_block (try_block)
638 tree try_block;
639{
35b1567d 640 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
62409b39
MM
641}
642
f1dedc31
MM
643/* Finish an implicitly generated try-block, with a cleanup is given
644 by CLEANUP. */
645
646void
647finish_cleanup (cleanup, try_block)
648 tree cleanup;
649 tree try_block;
650{
35b1567d
BC
651 TRY_HANDLERS (try_block) = cleanup;
652 CLEANUP_P (try_block) = 1;
f1dedc31
MM
653}
654
0dde4175
JM
655/* Likewise, for a function-try-block. */
656
657void
658finish_function_try_block (try_block)
f1dedc31 659 tree try_block;
0dde4175 660{
35b1567d
BC
661 if (TREE_CHAIN (try_block)
662 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
62409b39 663 {
35b1567d
BC
664 /* Chain the compound statement after the CTOR_INITIALIZER. */
665 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
666 /* And make the CTOR_INITIALIZER the body of the try-block. */
667 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
62409b39 668 }
0dde4175 669 else
35b1567d 670 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
b35d4555 671 in_function_try_handler = 1;
0dde4175
JM
672}
673
ad321293
MM
674/* Finish a handler-sequence for a try-block, which may be given by
675 TRY_BLOCK. */
676
677void
678finish_handler_sequence (try_block)
679 tree try_block;
680{
35b1567d
BC
681 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
682 check_handlers (TRY_HANDLERS (try_block));
ad321293
MM
683}
684
0dde4175
JM
685/* Likewise, for a function-try-block. */
686
687void
688finish_function_handler_sequence (try_block)
689 tree try_block;
690{
b35d4555 691 in_function_try_handler = 0;
35b1567d
BC
692 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
693 check_handlers (TRY_HANDLERS (try_block));
694}
695
696/* Generate the RTL for T, which is a HANDLER. */
b35d4555 697
54f7877c 698static void
35b1567d
BC
699genrtl_handler (t)
700 tree t;
701{
702 genrtl_do_pushlevel ();
703 expand_stmt (HANDLER_BODY (t));
704 if (!processing_template_decl)
2bc9f1d1 705 {
35b1567d
BC
706 /* Fall to outside the try statement when done executing
707 handler and we fall off end of handler. This is jump
708 Lresume in the documentation. */
709 expand_goto (top_label_entry (&caught_return_label_stack));
710 end_catch_handler ();
2bc9f1d1 711 }
0dde4175
JM
712}
713
ad321293
MM
714/* Begin a handler. Returns a HANDLER if appropriate. */
715
716tree
717begin_handler ()
718{
719 tree r;
0dfdeca6 720 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
ae499cce 721 add_stmt (r);
ad321293 722 do_pushlevel ();
ad321293
MM
723 return r;
724}
725
726/* Finish the handler-parameters for a handler, which may be given by
b35d4555
MM
727 HANDLER. DECL is the declaration for the catch parameter, or NULL
728 if this is a `catch (...)' clause. */
ad321293 729
b35d4555
MM
730tree
731finish_handler_parms (decl, handler)
732 tree decl;
ad321293 733 tree handler;
b35d4555
MM
734{
735 tree blocks = NULL_TREE;
736
737 if (processing_template_decl)
738 {
739 if (decl)
740 {
741 decl = pushdecl (decl);
742 decl = push_template_decl (decl);
743 add_decl_stmt (decl);
744 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
745 }
746 }
35b1567d 747 else
b35d4555
MM
748 blocks = expand_start_catch_block (decl);
749
35b1567d
BC
750 if (decl)
751 TREE_TYPE (handler) = TREE_TYPE (decl);
752
753 return blocks;
754}
755
756/* Generate the RTL for a CATCH_BLOCK. */
757
54f7877c 758static void
35b1567d
BC
759genrtl_catch_block (type)
760 tree type;
761{
762 start_catch_handler (type);
763}
764
765/* Note the beginning of a handler for TYPE. This function is called
766 at the point to which control should be transferred when an
767 appropriately-typed exception is thrown. */
768
769void
770begin_catch_block (type)
771 tree type;
772{
ae499cce 773 add_stmt (build (START_CATCH_STMT, type));
35b1567d
BC
774}
775
776/* Finish a handler, which may be given by HANDLER. The BLOCKs are
777 the return value from the matching call to finish_handler_parms. */
778
779void
780finish_handler (blocks, handler)
781 tree blocks;
782 tree handler;
783{
784 if (!processing_template_decl)
785 expand_end_catch_block (blocks);
786 do_poplevel ();
787 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
788}
789
790/* Generate the RTL for T, which is a CTOR_STMT. */
791
54f7877c 792static void
35b1567d
BC
793genrtl_ctor_stmt (t)
794 tree t;
795{
796 if (CTOR_BEGIN_P (t))
797 begin_protect_partials ();
798 else
799 /* After this point, any exceptions will cause the
800 destructor to be executed, so we no longer need to worry
801 about destroying the various subobjects ourselves. */
802 end_protect_partials ();
803}
804
ad321293
MM
805/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
806 compound-statement does not define a scope. Returns a new
807 COMPOUND_STMT if appropriate. */
808
809tree
810begin_compound_stmt (has_no_scope)
811 int has_no_scope;
812{
813 tree r;
6625cdb5 814 int is_try = 0;
ad321293 815
0dfdeca6 816 r = build_stmt (COMPOUND_STMT, NULL_TREE);
35b1567d
BC
817
818 if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK)
819 is_try = 1;
820
ae499cce 821 add_stmt (r);
35b1567d
BC
822 if (has_no_scope)
823 COMPOUND_STMT_NO_SCOPE (r) = 1;
ad321293 824
558475f0
MM
825 last_expr_type = NULL_TREE;
826
ad321293 827 if (!has_no_scope)
6625cdb5
JM
828 {
829 do_pushlevel ();
830 if (is_try)
0dfdeca6 831 note_level_for_eh ();
6625cdb5 832 }
f1dedc31
MM
833 else
834 /* Normally, we try hard to keep the BLOCK for a
835 statement-expression. But, if it's a statement-expression with
836 a scopeless block, there's nothing to keep, and we don't want
837 to accidentally keep a block *inside* the scopeless block. */
838 keep_next_level (0);
ad321293 839
24bef158
MM
840 /* If this is the outermost block of the function, declare the
841 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
01d939e8 842 if (cfun
8f17b5c5 843 && !function_name_declared_p
9bfadf57 844 && !has_no_scope)
24bef158 845 {
8f17b5c5 846 function_name_declared_p = 1;
2ce07e2d 847 declare_function_name ();
24bef158
MM
848 }
849
ad321293
MM
850 return r;
851}
852
ad321293
MM
853/* Finish a compound-statement, which may be given by COMPOUND_STMT.
854 If HAS_NO_SCOPE is non-zero, the compound statement does not define
855 a scope. */
856
857tree
858finish_compound_stmt (has_no_scope, compound_stmt)
859 int has_no_scope;
860 tree compound_stmt;
861{
862 tree r;
558475f0 863 tree t;
ad321293
MM
864
865 if (!has_no_scope)
866 r = do_poplevel ();
867 else
868 r = NULL_TREE;
869
35b1567d 870 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
ad321293 871
cb39191d 872 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
558475f0
MM
873 the precise purpose of that variable is store the type of the
874 last expression statement within the last compound statement, we
875 preserve the value. */
876 t = last_expr_type;
ad321293 877 finish_stmt ();
558475f0 878 last_expr_type = t;
ad321293
MM
879
880 return r;
881}
882
35b1567d
BC
883/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
884 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
885 CLOBBERS. */
7dc5bd62 886
35b1567d
BC
887void
888finish_asm_stmt (cv_qualifier, string, output_operands,
889 input_operands, clobbers)
890 tree cv_qualifier;
891 tree string;
892 tree output_operands;
893 tree input_operands;
894 tree clobbers;
895{
896 tree r;
abfc8a36
MM
897 tree t;
898
35b1567d
BC
899 if (TREE_CHAIN (string))
900 string = combine_strings (string);
901
902 if (cv_qualifier != NULL_TREE
903 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
904 {
905 cp_warning ("%s qualifier ignored on asm",
906 IDENTIFIER_POINTER (cv_qualifier));
907 cv_qualifier = NULL_TREE;
ad321293 908 }
35b1567d 909
abfc8a36
MM
910 if (!processing_template_decl)
911 for (t = input_operands; t; t = TREE_CHAIN (t))
912 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
913
0dfdeca6
BC
914 r = build_stmt (ASM_STMT, cv_qualifier, string,
915 output_operands, input_operands,
916 clobbers);
ae499cce 917 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
BC
977{
978 tree decl;
35b1567d
BC
979
980 decl = DECL_RESULT (current_function_decl);
35b1567d 981
44835fdd 982 emit_local_var (decl);
35b1567d 983
44835fdd
MM
984 /* If this named return value comes in a register, put it in a
985 pseudo-register. */
986 if (DECL_REGISTER (decl))
35b1567d 987 {
44835fdd
MM
988 original_result_rtx = DECL_RTL (decl);
989 /* Note that the mode of the old DECL_RTL may be wider than the
990 mode of DECL_RESULT, depending on the calling conventions for
991 the processor. For example, on the Alpha, a 32-bit integer
992 is returned in a DImode register -- the DECL_RESULT has
993 SImode but the DECL_RTL for the DECL_RESULT has DImode. So,
994 here, we use the mode the back-end has already assigned for
995 the return value. */
996 DECL_RTL (decl) = gen_reg_rtx (GET_MODE (original_result_rtx));
997 if (TREE_ADDRESSABLE (decl))
998 put_var_into_stack (decl);
35b1567d 999 }
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
1433 arguments to FN. Returns an expressino for the call. */
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
MM
1539
1540 return expr;
1541}
1542
70adf8a9
JM
1543static tree current_type_lookups;
1544
1545/* Perform deferred access control for types used in the type of a
1546 declaration. */
1547
1f51a992 1548static void
70adf8a9
JM
1549deferred_type_access_control ()
1550{
1f51a992 1551 tree lookup = type_lookups;
70adf8a9
JM
1552
1553 if (lookup == error_mark_node)
1554 return;
1555
1556 for (; lookup; lookup = TREE_CHAIN (lookup))
1557 enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup));
1558}
1559
70adf8a9 1560void
1f51a992
JM
1561decl_type_access_control (decl)
1562 tree decl;
70adf8a9 1563{
1f51a992 1564 tree save_fn;
70adf8a9 1565
1f51a992
JM
1566 if (type_lookups == error_mark_node)
1567 return;
1568
1569 save_fn = current_function_decl;
1570
1571 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
1572 current_function_decl = decl;
70adf8a9 1573
70adf8a9 1574 deferred_type_access_control ();
1f51a992
JM
1575
1576 current_function_decl = save_fn;
1577
1578 /* Now strip away the checks for the current declarator; they were
1579 added to type_lookups after typed_declspecs saved the copy that
1580 ended up in current_type_lookups. */
1581 type_lookups = current_type_lookups;
1582}
1583
1584void
1585save_type_access_control (lookups)
1586 tree lookups;
1587{
1588 current_type_lookups = lookups;
1589}
70adf8a9
JM
1590
1591/* Begin a function definition declared with DECL_SPECS and
b4c4a9ec
MM
1592 DECLARATOR. Returns non-zero if the function-declaration is
1593 legal. */
1594
1595int
1f51a992 1596begin_function_definition (decl_specs, declarator)
b4c4a9ec
MM
1597 tree decl_specs;
1598 tree declarator;
1599{
1600 tree specs;
1601 tree attrs;
70adf8a9 1602
b4c4a9ec 1603 split_specs_attrs (decl_specs, &specs, &attrs);
a8f73d4b 1604 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
b4c4a9ec 1605 return 0;
1f51a992
JM
1606
1607 deferred_type_access_control ();
1608 type_lookups = error_mark_node;
1609
39c01e4c
MM
1610 /* The things we're about to see are not directly qualified by any
1611 template headers we've seen thus far. */
1612 reset_specialization ();
1613
b4c4a9ec
MM
1614 return 1;
1615}
1616
1617/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1618 a SCOPE_REF. */
1619
1620tree
1621begin_constructor_declarator (scope, name)
1622 tree scope;
1623 tree name;
1624{
1625 tree result = build_parse_node (SCOPE_REF, scope, name);
830fcda8 1626 enter_scope_of (result);
b4c4a9ec
MM
1627 return result;
1628}
1629
ce4a0391
MM
1630/* Finish an init-declarator. Returns a DECL. */
1631
1632tree
1633finish_declarator (declarator, declspecs, attributes,
1634 prefix_attributes, initialized)
1635 tree declarator;
1636 tree declspecs;
1637 tree attributes;
1638 tree prefix_attributes;
1639 int initialized;
1640{
1641 return start_decl (declarator, declspecs, initialized, attributes,
1642 prefix_attributes);
1643}
1644
8014a339 1645/* Finish a translation unit. */
ce4a0391
MM
1646
1647void
1648finish_translation_unit ()
1649{
1650 /* In case there were missing closebraces,
1651 get us back to the global binding level. */
273a708f 1652 pop_everything ();
ce4a0391
MM
1653 while (current_namespace != global_namespace)
1654 pop_namespace ();
1655 finish_file ();
1656}
1657
b4c4a9ec
MM
1658/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1659 Returns the parameter. */
1660
1661tree
1662finish_template_type_parm (aggr, identifier)
1663 tree aggr;
1664 tree identifier;
1665{
6eabb241 1666 if (aggr != class_type_node)
b4c4a9ec 1667 {
8251199e 1668 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1669 aggr = class_type_node;
1670 }
1671
1672 return build_tree_list (aggr, identifier);
1673}
1674
1675/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1676 Returns the parameter. */
1677
1678tree
1679finish_template_template_parm (aggr, identifier)
1680 tree aggr;
1681 tree identifier;
1682{
1683 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1684 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1685 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1686 DECL_TEMPLATE_RESULT (tmpl) = decl;
c727aa5e 1687 DECL_ARTIFICIAL (decl) = 1;
b4c4a9ec
MM
1688 end_template_decl ();
1689
1690 return finish_template_type_parm (aggr, tmpl);
1691}
ce4a0391
MM
1692
1693/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1694 non-zero, the parameter list was terminated by a `...'. */
1695
1696tree
1697finish_parmlist (parms, ellipsis)
1698 tree parms;
1699 int ellipsis;
1700{
1701 if (!ellipsis)
1702 chainon (parms, void_list_node);
1703 /* We mark the PARMS as a parmlist so that declarator processing can
1704 disambiguate certain constructs. */
1705 if (parms != NULL_TREE)
1706 TREE_PARMLIST (parms) = 1;
1707
1708 return parms;
1709}
1710
1711/* Begin a class definition, as indicated by T. */
1712
1713tree
1714begin_class_definition (t)
1715 tree t;
1716{
ce4a0391
MM
1717 if (t == error_mark_node
1718 || ! IS_AGGR_TYPE (t))
1719 {
33848bb0 1720 t = make_aggr_type (RECORD_TYPE);
ce4a0391
MM
1721 pushtag (make_anon_name (), t, 0);
1722 }
830fcda8
JM
1723
1724 /* In a definition of a member class template, we will get here with an
1725 implicit typename, a TYPENAME_TYPE with a type. */
1726 if (TREE_CODE (t) == TYPENAME_TYPE)
1727 t = TREE_TYPE (t);
4c571114
MM
1728
1729 /* If we generated a partial instantiation of this type, but now
1730 we're seeing a real definition, we're actually looking at a
1731 partial specialization. Consider:
1732
1733 template <class T, class U>
1734 struct Y {};
1735
1736 template <class T>
1737 struct X {};
1738
1739 template <class T, class U>
1740 void f()
1741 {
1742 typename X<Y<T, U> >::A a;
1743 }
1744
1745 template <class T, class U>
1746 struct X<Y<T, U> >
1747 {
1748 };
1749
1750 We have to undo the effects of the previous partial
1751 instantiation. */
1752 if (PARTIAL_INSTANTIATION_P (t))
1753 {
1754 if (!pedantic)
1755 {
1756 /* Unfortunately, when we're not in pedantic mode, we
1757 attempt to actually fill in some of the fields of the
1758 partial instantiation, in order to support the implicit
1759 typename extension. Clear those fields now, in
1760 preparation for the definition here. The fields cleared
1761 here must match those set in instantiate_class_template.
1762 Look for a comment mentioning begin_class_definition
1763 there. */
1764 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1765 TYPE_FIELDS (t) = NULL_TREE;
1766 TYPE_METHODS (t) = NULL_TREE;
1767 CLASSTYPE_TAGS (t) = NULL_TREE;
1ddd4323 1768 CLASSTYPE_VBASECLASSES (t) = NULL_TREE;
4c571114
MM
1769 TYPE_SIZE (t) = NULL_TREE;
1770 }
830fcda8 1771
4c571114
MM
1772 /* This isn't a partial instantiation any more. */
1773 PARTIAL_INSTANTIATION_P (t) = 0;
1774 }
1775 /* If this type was already complete, and we see another definition,
1776 that's an error. */
d0f062fb 1777 else if (COMPLETE_TYPE_P (t))
ce4a0391 1778 duplicate_tag_error (t);
4c571114 1779
b4f70b3d
NS
1780 /* Update the location of the decl. */
1781 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1782 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1783
4c571114 1784 if (TYPE_BEING_DEFINED (t))
ce4a0391 1785 {
33848bb0 1786 t = make_aggr_type (TREE_CODE (t));
ce4a0391 1787 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 1788 }
ff350acd 1789 maybe_process_partial_specialization (t);
8f032717 1790 pushclass (t, 1);
ce4a0391 1791 TYPE_BEING_DEFINED (t) = 1;
55760a0c 1792 TYPE_PACKED (t) = flag_pack_struct;
ce4a0391
MM
1793 /* Reset the interface data, at the earliest possible
1794 moment, as it might have been set via a class foo;
1795 before. */
6eabb241
MM
1796 {
1797 tree name = TYPE_IDENTIFIER (t);
1798
1799 if (! ANON_AGGRNAME_P (name))
1800 {
1801 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1802 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1803 (t, interface_unknown);
1804 }
1805
1806 /* Only leave this bit clear if we know this
1807 class is part of an interface-only specification. */
1808 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1809 || ! CLASSTYPE_INTERFACE_ONLY (t))
1810 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
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)
1856 DECL_LANGUAGE (decl) = lang_cplusplus;
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)));
ce4a0391
MM
1939 if (current_scope () == current_function_decl)
1940 do_pending_defargs ();
1941
1942 return t;
1943}
1944
1945/* Finish processing the default argument expressions cached during
1946 the processing of a class definition. */
1947
1948void
51632249 1949begin_inline_definitions ()
ce4a0391 1950{
0e5921e8 1951 if (current_scope () == current_function_decl)
ce4a0391
MM
1952 do_pending_inlines ();
1953}
1954
1955/* Finish processing the inline function definitions cached during the
1956 processing of a class definition. */
1957
1958void
51632249 1959finish_inline_definitions ()
ce4a0391
MM
1960{
1961 if (current_class_type == NULL_TREE)
1962 clear_inline_text_obstack ();
ce4a0391 1963}
35acd3f2
MM
1964
1965/* Finish processing the declaration of a member class template
1966 TYPES whose template parameters are given by PARMS. */
1967
1968tree
61a127b3 1969finish_member_class_template (types)
35acd3f2
MM
1970 tree types;
1971{
36a117a5
MM
1972 tree t;
1973
1974 /* If there are declared, but undefined, partial specializations
1975 mixed in with the typespecs they will not yet have passed through
1976 maybe_process_partial_specialization, so we do that here. */
1977 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1978 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1979 maybe_process_partial_specialization (TREE_VALUE (t));
1980
35acd3f2 1981 note_list_got_semicolon (types);
61a127b3 1982 grok_x_components (types);
35acd3f2
MM
1983 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1984 /* The component was in fact a friend declaration. We avoid
1985 finish_member_template_decl performing certain checks by
1986 unsetting TYPES. */
1987 types = NULL_TREE;
61a127b3
MM
1988
1989 finish_member_template_decl (types);
1990
35acd3f2
MM
1991 /* As with other component type declarations, we do
1992 not store the new DECL on the list of
1993 component_decls. */
1994 return NULL_TREE;
1995}
36a117a5
MM
1996
1997/* Finish processsing a complete template declaration. The PARMS are
1998 the template parameters. */
1999
2000void
2001finish_template_decl (parms)
2002 tree parms;
2003{
2004 if (parms)
2005 end_template_decl ();
2006 else
2007 end_specialization ();
2008}
2009
2010/* Finish processing a a template-id (which names a type) of the form
2011 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2012 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2013 the scope of template-id indicated. */
2014
2015tree
2016finish_template_type (name, args, entering_scope)
2017 tree name;
2018 tree args;
2019 int entering_scope;
2020{
2021 tree decl;
2022
2023 decl = lookup_template_class (name, args,
2024 NULL_TREE, NULL_TREE, entering_scope);
2025 if (decl != error_mark_node)
2026 decl = TYPE_STUB_DECL (decl);
2027
2028 return decl;
2029}
648f19f6
MM
2030
2031/* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2032 namespace scope or a class scope. */
2033
2034void
2035enter_scope_of (sr)
2036 tree sr;
2037{
2038 tree scope = TREE_OPERAND (sr, 0);
2039
2040 if (TREE_CODE (scope) == NAMESPACE_DECL)
2041 {
2042 push_decl_namespace (scope);
2043 TREE_COMPLEXITY (sr) = -1;
2044 }
2045 else if (scope != current_class_type)
2046 {
830fcda8
JM
2047 if (TREE_CODE (scope) == TYPENAME_TYPE)
2048 {
2049 /* In a declarator for a template class member, the scope will
2050 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2051 scope = TREE_TYPE (scope);
2052 TREE_OPERAND (sr, 0) = scope;
2053 }
648f19f6
MM
2054 push_nested_class (scope, 3);
2055 TREE_COMPLEXITY (sr) = current_class_depth;
2056 }
2057}
ea6021e8
MM
2058
2059/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2060 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2061 BASE_CLASS, or NULL_TREE if an error occurred. The
2062 ACCESSS_SPECIFIER is one of
2063 access_{default,public,protected_private}[_virtual]_node.*/
2064
2065tree
6eabb241 2066finish_base_specifier (access_specifier, base_class)
ea6021e8
MM
2067 tree access_specifier;
2068 tree base_class;
ea6021e8
MM
2069{
2070 tree type;
2071 tree result;
2072
2073 if (base_class == NULL_TREE)
2074 {
8251199e 2075 error ("invalid base class");
ea6021e8
MM
2076 type = error_mark_node;
2077 }
2078 else
2079 type = TREE_TYPE (base_class);
6eabb241 2080
ea6021e8
MM
2081 if (! is_aggr_type (type, 1))
2082 result = NULL_TREE;
ea6021e8
MM
2083 else
2084 result = build_tree_list (access_specifier, type);
2085
2086 return result;
2087}
61a127b3
MM
2088
2089/* Called when multiple declarators are processed. If that is not
2090 premitted in this context, an error is issued. */
2091
2092void
2093check_multiple_declarators ()
2094{
2095 /* [temp]
2096
2097 In a template-declaration, explicit specialization, or explicit
2098 instantiation the init-declarator-list in the declaration shall
2099 contain at most one declarator.
2100
2101 We don't just use PROCESSING_TEMPLATE_DECL for the first
2102 condition since that would disallow the perfectly legal code,
2103 like `template <class T> struct S { int i, j; };'. */
2104 tree scope = current_scope ();
2105
2106 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2107 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2108 return;
2109
2110 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2111 || processing_explicit_instantiation
2112 || processing_specialization)
2113 cp_error ("multiple declarators in template declaration");
2114}
2115
b894fc05
JM
2116tree
2117finish_typeof (expr)
2118 tree expr;
2119{
2120 if (processing_template_decl)
2121 {
2122 tree t;
2123
33848bb0 2124 t = make_aggr_type (TYPEOF_TYPE);
b894fc05 2125 TYPE_FIELDS (t) = expr;
b894fc05
JM
2126
2127 return t;
2128 }
2129
2130 return TREE_TYPE (expr);
2131}
558475f0 2132
62409b39
MM
2133/* Generate RTL for the statement T, and its substatements, and any
2134 other statements at its nesting level. */
558475f0 2135
54f7877c
MM
2136static void
2137cp_expand_stmt (t)
558475f0
MM
2138 tree t;
2139{
54f7877c 2140 switch (TREE_CODE (t))
62409b39 2141 {
54f7877c
MM
2142 case CLEANUP_STMT:
2143 genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2144 break;
558475f0 2145
54f7877c
MM
2146 case START_CATCH_STMT:
2147 genrtl_catch_block (TREE_TYPE (t));
2148 break;
a7e4cfa0 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
54f7877c
MM
2158 case HANDLER:
2159 genrtl_handler (t);
2160 break;
558475f0 2161
54f7877c
MM
2162 case SUBOBJECT:
2163 genrtl_subobject (SUBOBJECT_CLEANUP (t));
2164 break;
2165
54f7877c
MM
2166 case RETURN_INIT:
2167 genrtl_named_return_value ();
2168 break;
2169
2170 default:
2171 my_friendly_abort (19990810);
2172 break;
2173 }
558475f0
MM
2174}
2175
3eb24f73
MM
2176/* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2177 will equivalent CALL_EXPRs. */
2178
2179static tree
2180simplify_aggr_init_exprs_r (tp, walk_subtrees, data)
2181 tree *tp;
2182 int *walk_subtrees ATTRIBUTE_UNUSED;
2183 void *data ATTRIBUTE_UNUSED;
2184{
2185 tree aggr_init_expr;
2186 tree call_expr;
2187 tree fn;
2188 tree args;
2189 tree slot;
2190 tree type;
2191 tree call_type;
2192 int copy_from_buffer_p;
2193
3eb24f73 2194 aggr_init_expr = *tp;
22e92ac3
MM
2195 /* We don't need to walk into types; there's nothing in a type that
2196 needs simplification. (And, furthermore, there are places we
2197 actively don't want to go. For example, we don't want to wander
2198 into the default arguments for a FUNCTION_DECL that appears in a
2199 CALL_EXPR.) */
2200 if (TYPE_P (aggr_init_expr))
2201 {
2202 *walk_subtrees = 0;
2203 return NULL_TREE;
2204 }
2205 /* Only AGGR_INIT_EXPRs are interesting. */
2206 else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR)
3eb24f73
MM
2207 return NULL_TREE;
2208
2209 /* Form an appropriate CALL_EXPR. */
2210 fn = TREE_OPERAND (aggr_init_expr, 0);
2211 args = TREE_OPERAND (aggr_init_expr, 1);
2212 slot = TREE_OPERAND (aggr_init_expr, 2);
2213 type = TREE_TYPE (aggr_init_expr);
2214 call_type = type;
2215 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
2216 {
2217 /* Replace the first argument with the address of the third
2218 argument to the AGGR_INIT_EXPR. */
2219 call_type = build_pointer_type (type);
2220 mark_addressable (slot);
2221 args = tree_cons (NULL_TREE, build1 (ADDR_EXPR, call_type, slot),
2222 TREE_CHAIN (args));
2223 }
2224 call_expr = build (CALL_EXPR, call_type, fn, args, NULL_TREE);
2225 TREE_SIDE_EFFECTS (call_expr) = 1;
2226
2227 /* If we're using the non-reentrant PCC calling convention, then we
2228 need to copy the returned value out of the static buffer into the
2229 SLOT. */
2230 copy_from_buffer_p = 0;
2231#ifdef PCC_STATIC_STRUCT_RETURN
2232 if (!AGGR_INIT_VIA_CTOR_P (aggr_init_expr) && aggregate_value_p (type))
2233 {
2234 int old_ac;
2235
2236 flag_access_control = 0;
2237 call_expr = build_aggr_init (slot, call_expr, LOOKUP_ONLYCONVERTING);
2238 flag_access_control = old_ac;
2239 copy_from_buffer_p = 1;
2240 }
2241#endif
2242
2243 /* If this AGGR_INIT_EXPR indicates the value returned by a
2244 function, then we want to use the value of the initialized
2245 location as the result. */
2246 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr) || copy_from_buffer_p)
2247 {
2248 call_expr = build (COMPOUND_EXPR, type,
2249 call_expr, slot);
2250 TREE_SIDE_EFFECTS (call_expr) = 1;
2251 }
2252
2253 /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */
2254 TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr);
2255 *tp = call_expr;
2256
2257 /* Keep iterating. */
2258 return NULL_TREE;
2259}
2260
31f8e4f3
MM
2261/* Emit all thunks to FN that should be emitted when FN is emitted. */
2262
2263static void
2264emit_associated_thunks (fn)
2265 tree fn;
2266{
2267 /* When we use vcall offsets, we emit thunks with the virtual
2268 functions to which they thunk. The whole point of vcall offsets
2269 is so that you can know statically the entire set of thunks that
2270 will ever be needed for a given virtual function, thereby
2271 enabling you to output all the thunks with the function itself. */
2272 if (vcall_offsets_in_vtable_p () && DECL_VIRTUAL_P (fn))
2273 {
2274 tree binfo;
2275 tree v;
2276
2277 for (binfo = TYPE_BINFO (DECL_CONTEXT (fn));
2278 binfo;
2279 binfo = TREE_CHAIN (binfo))
2280 for (v = BINFO_VIRTUALS (binfo); v; v = TREE_CHAIN (v))
2281 if (BV_FN (v) == fn
2282 && (!integer_zerop (BV_DELTA (v))
2283 || BV_VCALL_INDEX (v)))
2284 {
2285 tree thunk;
2286 tree vcall_index;
2287
2288 if (BV_USE_VCALL_INDEX_P (v))
2289 {
2290 vcall_index = BV_VCALL_INDEX (v);
2291 my_friendly_assert (vcall_index != NULL_TREE, 20000621);
2292 }
2293 else
2294 vcall_index = NULL_TREE;
2295
2296 thunk = make_thunk (build1 (ADDR_EXPR,
2297 vfunc_ptr_type_node,
2298 fn),
2299 BV_DELTA (v),
2300 vcall_index,
2301 /*generate_with_vtable_p=*/0);
2302 use_thunk (thunk, /*emit_p=*/1);
2303 }
2304 }
2305}
2306
558475f0
MM
2307/* Generate RTL for FN. */
2308
2309void
2310expand_body (fn)
2311 tree fn;
2312{
62409b39 2313 int saved_lineno;
3b304f5b 2314 const char *saved_input_filename;
558475f0 2315
62409b39
MM
2316 /* When the parser calls us after finishing the body of a template
2317 function, we don't really want to expand the body. When we're
2318 processing an in-class definition of an inline function,
2319 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2320 to look at the function itself. */
2321 if (processing_template_decl
2322 || (DECL_LANG_SPECIFIC (fn)
2323 && DECL_TEMPLATE_INFO (fn)
2324 && uses_template_parms (DECL_TI_ARGS (fn))))
d658cd4c
MM
2325 {
2326 /* Normally, collection only occurs in rest_of_compilation. So,
2327 if we don't collect here, we never collect junk generated
2328 during the processing of templates until we hit a
2329 non-template function. */
2330 ggc_collect ();
2331 return;
2332 }
62409b39 2333
3eb24f73 2334 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
ee94fce6
MM
2335 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
2336 simplify_aggr_init_exprs_r,
2337 NULL);
3eb24f73 2338
db9b2174
MM
2339 /* If this is a constructor or destructor body, we have to clone it
2340 under the new ABI. */
2341 if (maybe_clone_body (fn))
2342 {
2343 /* We don't want to process FN again, so pretend we've written
2344 it out, even though we haven't. */
2345 TREE_ASM_WRITTEN (fn) = 1;
2346 return;
2347 }
2348
84df082b
MM
2349 /* There's no reason to do any of the work here if we're only doing
2350 semantic analysis; this code just generates RTL. */
2351 if (flag_syntax_only)
2352 return;
2353
21b0c6dc
MM
2354 /* If possible, avoid generating RTL for this function. Instead,
2355 just record it as an inline function, and wait until end-of-file
2356 to decide whether to write it out or not. */
56e770bf
MM
2357 if (/* We have to generate RTL if it's not an inline function. */
2358 (DECL_INLINE (fn) || DECL_COMDAT (fn))
21b0c6dc
MM
2359 /* Or if we have to keep all inline functions anyhow. */
2360 && !flag_keep_inline_functions
2361 /* Or if we actually have a reference to the function. */
2362 && !DECL_NEEDED_P (fn)
21b0c6dc 2363 /* Or if this is a nested function. */
4f1c5b7d 2364 && !decl_function_context (fn))
21b0c6dc
MM
2365 {
2366 /* Give the function RTL now so that we can assign it to a
2367 function pointer, etc. */
2368 make_function_rtl (fn);
2369 /* Set DECL_EXTERNAL so that assemble_external will be called as
2370 necessary. We'll clear it again in finish_file. */
2371 if (!DECL_EXTERNAL (fn))
2372 {
2373 DECL_NOT_REALLY_EXTERN (fn) = 1;
2374 DECL_EXTERNAL (fn) = 1;
2375 }
2376 /* Remember this function. In finish_file we'll decide if
2377 we actually need to write this function out. */
56e770bf 2378 defer_fn (fn);
de23a892
MM
2379 /* Let the back-end know that this funtion exists. */
2380 note_deferral_of_defined_inline_function (fn);
21b0c6dc
MM
2381 return;
2382 }
2383
31f8e4f3
MM
2384 /* Emit any thunks that should be emitted at the same time as FN. */
2385 emit_associated_thunks (fn);
2386
297a5329 2387 timevar_push (TV_INTEGRATION);
ea11ca7e 2388
46e8c075
MM
2389 /* Optimize the body of the function before expanding it. */
2390 optimize_function (fn);
2391
297a5329
JM
2392 timevar_pop (TV_INTEGRATION);
2393 timevar_push (TV_EXPAND);
2394
62409b39 2395 /* Save the current file name and line number. When we expand the
84df082b 2396 body of the function, we'll set LINENO and INPUT_FILENAME so that
62409b39
MM
2397 error-mesages come out in the right places. */
2398 saved_lineno = lineno;
2399 saved_input_filename = input_filename;
2400 lineno = DECL_SOURCE_LINE (fn);
2401 input_filename = DECL_SOURCE_FILE (fn);
2402
f444e36b 2403 genrtl_start_function (fn);
6462c441 2404 current_function_is_thunk = DECL_THUNK_P (fn);
558475f0 2405
24bef158
MM
2406 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2407 any of the other magic variables we set up when starting a
2408 function body. */
8f17b5c5 2409 function_name_declared_p = 1;
24bef158 2410
558475f0 2411 /* Expand the body. */
b35d4555 2412 expand_stmt (DECL_SAVED_TREE (fn));
558475f0 2413
62409b39
MM
2414 /* Statements should always be full-expressions at the outermost set
2415 of curly braces for a function. */
f2c5f623 2416 my_friendly_assert (stmts_are_full_exprs_p (), 19990831);
62409b39
MM
2417
2418 /* The outermost statement for a function contains the line number
2419 recorded when we finished processing the function. */
2420 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2421
2422 /* Generate code for the function. */
f444e36b 2423 genrtl_finish_function (fn);
62409b39 2424
46e8c075
MM
2425 /* If possible, obliterate the body of the function so that it can
2426 be garbage collected. */
2427 if (flag_dump_translation_unit)
2428 /* Keep the body; we're going to dump it. */
2429 ;
2430 else if (DECL_INLINE (fn) && flag_inline_trees)
2431 /* We might need the body of this function so that we can expand
2432 it inline somewhere else. */
2433 ;
2434 else
2435 /* We don't need the body; blow it away. */
d658cd4c
MM
2436 DECL_SAVED_TREE (fn) = NULL_TREE;
2437
62409b39
MM
2438 /* And restore the current source position. */
2439 lineno = saved_lineno;
2440 input_filename = saved_input_filename;
f12eef58 2441 extract_interface_info ();
ea11ca7e
JM
2442
2443 timevar_pop (TV_EXPAND);
558475f0 2444}
54f7877c 2445
f444e36b
MM
2446/* Start generating the RTL for FN. */
2447
2448static void
2449genrtl_start_function (fn)
2450 tree fn;
2451{
2452 tree parm;
2453
2454 /* Tell everybody what function we're processing. */
2455 current_function_decl = fn;
2456 /* Get the RTL machinery going for this function. */
2457 init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
2458 /* Let everybody know that we're expanding this function, not doing
2459 semantic analysis. */
2460 expanding_p = 1;
2461
2462 /* Even though we're inside a function body, we still don't want to
2463 call expand_expr to calculate the size of a variable-sized array.
2464 We haven't necessarily assigned RTL to all variables yet, so it's
2465 not safe to try to expand expressions involving them. */
2466 immediate_size_expand = 0;
2467 cfun->x_dont_save_pending_sizes_p = 1;
2468
2469 /* Let the user know we're compiling this function. */
2470 announce_function (fn);
2471
2472 /* Initialize the per-function data. */
2473 my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911);
2474 if (DECL_SAVED_FUNCTION_DATA (fn))
2475 {
2476 /* If we already parsed this function, and we're just expanding it
2477 now, restore saved state. */
2478 *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
2479
2480 /* This function is being processed in whole-function mode; we
2481 already did semantic analysis. */
2482 cfun->x_whole_function_mode_p = 1;
2483
2484 /* If we decided that we didn't want to inline this function,
2485 make sure the back-end knows that. */
2486 if (!current_function_cannot_inline)
2487 current_function_cannot_inline = cp_function_chain->cannot_inline;
2488
2489 /* We don't need the saved data anymore. */
2490 free (DECL_SAVED_FUNCTION_DATA (fn));
2491 DECL_SAVED_FUNCTION_DATA (fn) = NULL;
2492 }
2493
2494 /* Tell the cross-reference machinery that we're defining this
2495 function. */
2496 GNU_xref_function (fn, DECL_ARGUMENTS (fn));
2497
2498 /* Keep track of how many functions we're presently expanding. */
2499 ++function_depth;
2500
2501 /* Create a binding level for the parameters. */
2502 expand_start_bindings (2);
2503 /* Clear out any previously saved instructions for this function, in
2504 case it was defined more than once. */
2505 DECL_SAVED_INSNS (fn) = NULL;
2506 /* Go through the PARM_DECLs for this function to see if any need
2507 cleanups. */
2508 for (parm = DECL_ARGUMENTS (fn); parm; parm = TREE_CHAIN (parm))
2509 if (TREE_TYPE (parm) != error_mark_node
2510 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (parm)))
2511 {
2512 expand_function_start (fn, /*parms_have_cleanups=*/1);
2513 break;
2514 }
2515 if (!parm)
2516 expand_function_start (fn, /*parms_have_cleanups=*/0);
2517 /* If this function is `main'. */
2518 if (DECL_MAIN_P (fn))
2519 expand_main_function ();
2520 /* Create a binding contour which can be used to catch
2521 cleanup-generated temporaries. */
2522 expand_start_bindings (2);
2523}
2524
2525/* Finish generating the RTL for FN. */
2526
2527static void
2528genrtl_finish_function (fn)
2529 tree fn;
2530{
2531 int returns_null;
2532 int returns_value;
2533 tree no_return_label = NULL_TREE;
2534
2535#if 0
2536 if (write_symbols != NO_DEBUG)
2537 {
2538 /* Keep this code around in case we later want to control debug info
2539 based on whether a type is "used". (jason 1999-11-11) */
2540
2541 tree ttype = target_type (fntype);
2542 tree parmdecl;
2543
2544 if (IS_AGGR_TYPE (ttype))
2545 /* Let debugger know it should output info for this type. */
2546 note_debug_info_needed (ttype);
2547
2548 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
2549 {
2550 ttype = target_type (TREE_TYPE (parmdecl));
2551 if (IS_AGGR_TYPE (ttype))
2552 /* Let debugger know it should output info for this type. */
2553 note_debug_info_needed (ttype);
2554 }
2555 }
2556#endif
2557
2558 /* Clean house because we will need to reorder insns here. */
2559 do_pending_stack_adjust ();
2560
2561 if (!dtor_label && !DECL_CONSTRUCTOR_P (fn)
2562 && return_label != NULL_RTX
2563 && current_function_return_value == NULL_TREE
2564 && ! DECL_NAME (DECL_RESULT (current_function_decl)))
2565 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
2566
2567 if (flag_exceptions)
2568 expand_exception_blocks ();
2569
2570 /* If this function is supposed to return a value, ensure that
2571 we do not fall into the cleanups by mistake. The end of our
2572 function will look like this:
2573
2574 user code (may have return stmt somewhere)
2575 goto no_return_label
2576 cleanup_label:
2577 cleanups
2578 goto return_label
2579 no_return_label:
2580 NOTE_INSN_FUNCTION_END
2581 return_label:
2582 things for return
2583
2584 If the user omits a return stmt in the USER CODE section, we
2585 will have a control path which reaches NOTE_INSN_FUNCTION_END.
2586 Otherwise, we won't. */
2587 if (no_return_label)
2588 {
2589 DECL_CONTEXT (no_return_label) = fn;
2590 DECL_INITIAL (no_return_label) = error_mark_node;
2591 DECL_SOURCE_FILE (no_return_label) = input_filename;
2592 DECL_SOURCE_LINE (no_return_label) = lineno;
2593 expand_goto (no_return_label);
2594 }
2595
2596 if (cleanup_label)
2597 {
2598 /* Remove the binding contour which is used to catch
2599 cleanup-generated temporaries. */
2600 expand_end_bindings (0, 0, 0);
2601 poplevel (0, 0, 0);
2602
2603 /* Emit label at beginning of cleanup code for parameters. */
2604 emit_label (cleanup_label);
2605 }
2606
2607 /* Get return value into register if that's where it's supposed to
2608 be. */
2609 if (original_result_rtx)
2610 fixup_result_decl (DECL_RESULT (fn), original_result_rtx);
2611
2612 /* Finish building code that will trigger warnings if users forget
2613 to make their functions return values. */
2614 if (no_return_label || cleanup_label)
2615 emit_jump (return_label);
2616 if (no_return_label)
2617 {
2618 /* We don't need to call `expand_*_return' here because we don't
2619 need any cleanups here--this path of code is only for error
2620 checking purposes. */
2621 expand_label (no_return_label);
2622 }
2623
2624 /* We hard-wired immediate_size_expand to zero in start_function.
2625 Expand_function_end will decrement this variable. So, we set the
2626 variable to one here, so that after the decrement it will remain
2627 zero. */
2628 immediate_size_expand = 1;
2629
2630 /* Generate rtl for function exit. */
2631 expand_function_end (input_filename, lineno, 1);
2632
2633 /* So we can tell if jump_optimize sets it to 1. */
2634 can_reach_end = 0;
2635
2636 /* Before we call rest_of_compilation (which will pop the
2637 CURRENT_FUNCTION), we must save these values. */
2638 returns_null = current_function_returns_null;
2639 returns_value = current_function_returns_value;
2640
2641 /* If this is a nested function (like a template instantiation that
2642 we're compiling in the midst of compiling something else), push a
2643 new GC context. That will keep local variables on the stack from
2644 being collected while we're doing the compilation of this
2645 function. */
2646 if (function_depth > 1)
2647 ggc_push_context ();
2648
2649 /* Run the optimizers and output the assembler code for this
2650 function. */
2651 rest_of_compilation (fn);
2652
2653 /* Undo the call to ggc_push_context above. */
2654 if (function_depth > 1)
2655 ggc_pop_context ();
2656
2657 if (DECL_SAVED_INSNS (fn) && ! TREE_ASM_WRITTEN (fn))
2658 {
2659 /* Set DECL_EXTERNAL so that assemble_external will be called as
2660 necessary. We'll clear it again in finish_file. */
2661 if (! DECL_EXTERNAL (fn))
2662 DECL_NOT_REALLY_EXTERN (fn) = 1;
2663 DECL_EXTERNAL (fn) = 1;
2664 defer_fn (fn);
2665 }
2666
2667#if 0
2668 /* Keep this code around in case we later want to control debug info
2669 based on whether a type is "used". (jason 1999-11-11) */
2670
2671 if (ctype && TREE_ASM_WRITTEN (fn))
2672 note_debug_info_needed (ctype);
2673#endif
2674
2675 /* If this function is marked with the constructor attribute, add it
2676 to the list of functions to be called along with constructors
2677 from static duration objects. */
2678 if (DECL_STATIC_CONSTRUCTOR (fn))
2679 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
2680
2681 /* If this function is marked with the destructor attribute, add it
2682 to the list of functions to be called along with destructors from
2683 static duration objects. */
2684 if (DECL_STATIC_DESTRUCTOR (fn))
2685 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
2686
2687 if (DECL_NAME (DECL_RESULT (fn)))
2688 returns_value |= can_reach_end;
2689 else
2690 returns_null |= can_reach_end;
2691
2692 if (TREE_THIS_VOLATILE (fn) && returns_null)
2693 warning ("`noreturn' function does return");
2694 else if (returns_null
2695 && TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != VOID_TYPE)
2696 {
2697 /* Always complain if there's just no return statement. */
2698 if (!returns_value)
2699 warning ("no return statement in function returning non-void");
2700 else if (warn_return_type || pedantic)
2701 /* If this function returns non-void and control can drop through,
2702 complain. */
2703 warning ("control reaches end of non-void function");
2704 }
2705
2706 --function_depth;
2707
2708 if (!DECL_SAVED_INSNS (fn)
2709 && !(flag_inline_trees && DECL_INLINE (fn)))
2710 {
2711 tree t;
2712
2713 /* Stop pointing to the local nodes about to be freed. */
2714 /* But DECL_INITIAL must remain nonzero so we know this
2715 was an actual function definition. */
2716 DECL_INITIAL (fn) = error_mark_node;
2717 for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t))
2718 DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX;
2719 }
2720
2721 /* Let the error reporting routines know that we're outside a
2722 function. For a nested function, this value is used in
2723 pop_cp_function_context and then reset via pop_function_context. */
2724 current_function_decl = NULL_TREE;
2725}
2726
54f7877c
MM
2727/* Perform initialization related to this module. */
2728
2729void
2730init_cp_semantics ()
2731{
2732 lang_expand_stmt = cp_expand_stmt;
2733}