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