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