]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
improve ChangeLog message
[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
4c571114 6 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
ad321293
MM
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
9
10 This file is part of GNU CC.
11
12 GNU CC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
16
17 GNU CC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with GNU CC; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26
27#include "config.h"
8d052bc7 28#include "system.h"
ad321293
MM
29#include "tree.h"
30#include "cp-tree.h"
31#include "except.h"
32#include "lex.h"
12027a89 33#include "toplev.h"
84df082b 34#include "flags.h"
ad321293
MM
35
36/* There routines provide a modular interface to perform many parsing
37 operations. They may therefore be used during actual parsing, or
38 during template instantiation, which may be regarded as a
39 degenerate form of parsing. Since the current g++ parser is
40 lacking in several respects, and will be reimplemented, we are
41 attempting to move most code that is not directly related to
42 parsing into this file; that will make implementing the new parser
43 much easier since it will be able to make use of these routines. */
44
527f0080 45static tree expand_cond PROTO((tree));
ed5511d9 46static tree maybe_convert_cond PROTO((tree));
558475f0 47
6f80451c
MM
48/* Record the fact that STMT was the last statement added to the
49 statement tree. */
50
51#define SET_LAST_STMT(stmt) \
52 (current_stmt_tree->x_last_stmt = (stmt))
53
ad321293
MM
54/* When parsing a template, LAST_TREE contains the last statement
55 parsed. These are chained together through the TREE_CHAIN field,
56 but often need to be re-organized since the parse is performed
57 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
58 STMT. */
59
cb39191d
MM
60#define RECHAIN_STMTS(stmt, substmt) \
61 do { \
62 substmt = TREE_CHAIN (stmt); \
63 TREE_CHAIN (stmt) = NULL_TREE; \
6f80451c 64 SET_LAST_STMT (stmt); \
ad321293
MM
65 } while (0)
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
MM
82 } while (0)
83
a7e4cfa0 84/* T is a statement. Add it to the statement-tree. */
ad321293 85
a7e4cfa0
MM
86void
87add_tree (t)
88 tree t;
89{
90 /* Add T to the statement-tree. */
6f80451c
MM
91 TREE_CHAIN (last_tree) = t;
92 SET_LAST_STMT (t);
a7e4cfa0
MM
93
94 /* When we expand a statement-tree, we must know whether or not the
95 statements are full-expresions. We record that fact here. */
96 if (building_stmt_tree ())
97 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p;
98}
99
ed5511d9
MM
100/* COND is the condition-expression for an if, while, etc.,
101 statement. Convert it to a boolean value, if appropriate. */
102
103static tree
104maybe_convert_cond (cond)
105 tree cond;
106{
107 /* Empty conditions remain empty. */
108 if (!cond)
109 return NULL_TREE;
110
111 /* Wait until we instantiate templates before doing conversion. */
112 if (processing_template_decl)
113 return cond;
114
115 /* Do the conversion. */
116 cond = convert_from_reference (cond);
117 return condition_conversion (cond);
118}
119
9bfadf57 120/* Finish an expression-statement, whose EXPRESSION is as indicated. */
a7e4cfa0 121
9bfadf57
MM
122void
123finish_expr_stmt (expr)
ad321293
MM
124 tree expr;
125{
ce4a0391 126 if (expr != NULL_TREE)
ad321293 127 {
558475f0
MM
128 if (building_stmt_tree ())
129 add_tree (build_min_nt (EXPR_STMT, expr));
130 else
ce4a0391
MM
131 {
132 emit_line_note (input_filename, lineno);
133 /* Do default conversion if safe and possibly important,
134 in case within ({...}). */
02cac427
NS
135 if (!stmts_are_full_exprs_p &&
136 ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
137 && lvalue_p (expr))
138 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
ce4a0391 139 expr = default_conversion (expr);
f1dedc31
MM
140
141 if (stmts_are_full_exprs_p)
142 expand_start_target_temps ();
143
558475f0 144 cplus_expand_expr_stmt (expr);
558475f0 145
f1dedc31 146 if (stmts_are_full_exprs_p)
f31c0a32 147 expand_end_target_temps ();
f1dedc31 148 }
ad321293 149 }
ce4a0391 150
ad321293 151 finish_stmt ();
558475f0
MM
152
153 /* This was an expression-statement, so we save the type of the
154 expression. */
155 last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE;
ad321293
MM
156}
157
158/* Begin an if-statement. Returns a newly created IF_STMT if
159 appropriate. */
160
161tree
162begin_if_stmt ()
163{
164 tree r;
165
9bfadf57
MM
166 do_pushlevel ();
167
558475f0 168 if (building_stmt_tree ())
ad321293
MM
169 {
170 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
171 add_tree (r);
172 }
173 else
174 r = NULL_TREE;
175
ad321293
MM
176 return r;
177}
178
179/* Process the COND of an if-statement, which may be given by
180 IF_STMT. */
181
182void
183finish_if_stmt_cond (cond, if_stmt)
184 tree cond;
185 tree if_stmt;
186{
ed5511d9
MM
187 cond = maybe_convert_cond (cond);
188
558475f0 189 if (building_stmt_tree ())
a7e4cfa0 190 FINISH_COND (cond, if_stmt, IF_COND (if_stmt));
ad321293
MM
191 else
192 {
193 emit_line_note (input_filename, lineno);
ed5511d9 194 expand_start_cond (cond, 0);
ad321293
MM
195 }
196}
197
198/* Finish the then-clause of an if-statement, which may be given by
199 IF_STMT. */
200
201tree
202finish_then_clause (if_stmt)
203 tree if_stmt;
204{
558475f0 205 if (building_stmt_tree ())
ad321293 206 {
cb39191d 207 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
6f80451c 208 SET_LAST_STMT (if_stmt);
ad321293
MM
209 return if_stmt;
210 }
211 else
212 return NULL_TREE;
213}
214
215/* Begin the else-clause of an if-statement. */
216
217void
218begin_else_clause ()
219{
558475f0 220 if (!building_stmt_tree ())
ad321293
MM
221 expand_start_else ();
222}
223
224/* Finish the else-clause of an if-statement, which may be given by
225 IF_STMT. */
226
227void
228finish_else_clause (if_stmt)
229 tree if_stmt;
230{
558475f0 231 if (building_stmt_tree ())
cb39191d 232 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
ad321293
MM
233}
234
235/* Finsh an if-statement. */
236
237void
238finish_if_stmt ()
239{
558475f0 240 if (!building_stmt_tree ())
ad321293
MM
241 expand_end_cond ();
242
243 do_poplevel ();
244 finish_stmt ();
245}
246
247/* Begin a while-statement. Returns a newly created WHILE_STMT if
248 appropriate. */
249
250tree
251begin_while_stmt ()
252{
253 tree r;
254
558475f0 255 if (building_stmt_tree ())
ad321293
MM
256 {
257 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
258 add_tree (r);
259 }
260 else
261 {
262 emit_nop ();
263 emit_line_note (input_filename, lineno);
264 expand_start_loop (1);
265 r = NULL_TREE;
266 }
267
268 do_pushlevel ();
269
270 return r;
271}
272
273/* Process the COND of an if-statement, which may be given by
274 WHILE_STMT. */
275
276void
277finish_while_stmt_cond (cond, while_stmt)
278 tree cond;
279 tree while_stmt;
280{
ed5511d9
MM
281 cond = maybe_convert_cond (cond);
282
558475f0 283 if (building_stmt_tree ())
a7e4cfa0 284 FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
ad321293
MM
285 else
286 {
287 emit_line_note (input_filename, lineno);
ed5511d9 288 expand_exit_loop_if_false (0, cond);
ad321293
MM
289 }
290
291 /* If COND wasn't a declaration, clear out the
292 block we made for it and start a new one here so the
293 optimization in expand_end_loop will work. */
294 if (getdecls () == NULL_TREE)
295 {
296 do_poplevel ();
297 do_pushlevel ();
298 }
299}
300
301/* Finish a while-statement, which may be given by WHILE_STMT. */
302
303void
304finish_while_stmt (while_stmt)
305 tree while_stmt;
306{
307 do_poplevel ();
308
558475f0 309 if (building_stmt_tree ())
cb39191d 310 RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt));
ad321293
MM
311 else
312 expand_end_loop ();
313 finish_stmt ();
314}
315
316/* Begin a do-statement. Returns a newly created DO_STMT if
317 appropriate. */
318
319tree
320begin_do_stmt ()
321{
558475f0 322 if (building_stmt_tree ())
ad321293
MM
323 {
324 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
325 add_tree (r);
326 return r;
327 }
328 else
329 {
330 emit_nop ();
331 emit_line_note (input_filename, lineno);
332 expand_start_loop_continue_elsewhere (1);
333 return NULL_TREE;
334 }
335}
336
337/* Finish the body of a do-statement, which may be given by DO_STMT. */
338
339void
340finish_do_body (do_stmt)
341 tree do_stmt;
342{
558475f0 343 if (building_stmt_tree ())
cb39191d 344 RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt));
ad321293
MM
345 else
346 expand_loop_continue_here ();
347}
348
349/* Finish a do-statement, which may be given by DO_STMT, and whose
350 COND is as indicated. */
351
352void
353finish_do_stmt (cond, do_stmt)
354 tree cond;
355 tree do_stmt;
356{
ed5511d9
MM
357 cond = maybe_convert_cond (cond);
358
558475f0 359 if (building_stmt_tree ())
2a1e9fdd 360 DO_COND (do_stmt) = cond;
ad321293
MM
361 else
362 {
363 emit_line_note (input_filename, lineno);
ed5511d9 364 expand_exit_loop_if_false (0, cond);
ad321293
MM
365 expand_end_loop ();
366 }
367
ad321293
MM
368 finish_stmt ();
369}
370
371/* Finish a return-statement. The EXPRESSION returned, if any, is as
372 indicated. */
373
374void
375finish_return_stmt (expr)
376 tree expr;
377{
efee38a9
MM
378 if (doing_semantic_analysis_p () && !processing_template_decl)
379 expr = check_return_expr (expr);
380
381 if (doing_semantic_analysis_p () && !processing_template_decl)
382 {
383 if (DECL_CONSTRUCTOR_P (current_function_decl) && ctor_label)
384 {
385 /* Even returns without a value in a constructor must return
386 `this'. We accomplish this by sending all returns in a
387 constructor to the CTOR_LABEL; finish_function emits code to
388 return a value there. When we finally generate the real
389 return statement, CTOR_LABEL is no longer set, and we fall
390 through into the normal return-processing code below. */
391 finish_goto_stmt (ctor_label);
392 return;
393 }
394 else if (DECL_DESTRUCTOR_P (current_function_decl))
395 {
396 /* Similarly, all destructors must run destructors for
397 base-classes before returning. So, all returns in a
398 destructor get sent to the DTOR_LABEL; finsh_function emits
399 code to return a value there. */
400 finish_goto_stmt (dtor_label);
401 return;
402 }
403 }
404
558475f0
MM
405 if (building_stmt_tree ())
406 add_tree (build_min_nt (RETURN_STMT, expr));
407 else
408 {
409 emit_line_note (input_filename, lineno);
410 c_expand_return (expr);
411 }
412
ad321293
MM
413 finish_stmt ();
414}
415
416/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
417
418tree
419begin_for_stmt ()
420{
421 tree r;
422
558475f0 423 if (building_stmt_tree ())
ad321293
MM
424 {
425 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
426 NULL_TREE, NULL_TREE);
427 add_tree (r);
428 }
429 else
430 r = NULL_TREE;
431
432 if (flag_new_for_scope > 0)
433 {
434 do_pushlevel ();
435 note_level_for_for ();
436 }
437
438 return r;
439}
440
441/* Finish the for-init-statement of a for-statement, which may be
442 given by FOR_STMT. */
443
444void
445finish_for_init_stmt (for_stmt)
446 tree for_stmt;
447{
558475f0 448 if (building_stmt_tree ())
ad321293
MM
449 {
450 if (last_tree != for_stmt)
cb39191d 451 RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt));
ad321293
MM
452 }
453 else
454 {
455 emit_nop ();
456 emit_line_note (input_filename, lineno);
457 expand_start_loop_continue_elsewhere (1);
458 }
459
460 do_pushlevel ();
461}
462
463/* Finish the COND of a for-statement, which may be given by
464 FOR_STMT. */
465
466void
467finish_for_cond (cond, for_stmt)
468 tree cond;
469 tree for_stmt;
470{
ed5511d9
MM
471 cond = maybe_convert_cond (cond);
472
558475f0 473 if (building_stmt_tree ())
a7e4cfa0 474 FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
ad321293
MM
475 else
476 {
477 emit_line_note (input_filename, lineno);
1dcf683e 478 if (cond)
ed5511d9 479 expand_exit_loop_if_false (0, cond);
ad321293
MM
480 }
481
482 /* If the cond wasn't a declaration, clear out the
483 block we made for it and start a new one here so the
484 optimization in expand_end_loop will work. */
485 if (getdecls () == NULL_TREE)
486 {
487 do_poplevel ();
488 do_pushlevel ();
489 }
490}
491
492/* Finish the increment-EXPRESSION in a for-statement, which may be
493 given by FOR_STMT. */
494
495void
496finish_for_expr (expr, for_stmt)
497 tree expr;
498 tree for_stmt;
499{
558475f0 500 if (building_stmt_tree ())
2a1e9fdd 501 FOR_EXPR (for_stmt) = expr;
ad321293
MM
502}
503
504/* Finish the body of a for-statement, which may be given by
505 FOR_STMT. The increment-EXPR for the loop must be
506 provided. */
507
508void
509finish_for_stmt (expr, for_stmt)
510 tree expr;
511 tree for_stmt;
512{
513 /* Pop the scope for the body of the loop. */
514 do_poplevel ();
515
558475f0 516 if (building_stmt_tree ())
cb39191d 517 RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt));
ad321293
MM
518 else
519 {
520 emit_line_note (input_filename, lineno);
521 expand_loop_continue_here ();
522 if (expr)
f1dedc31 523 finish_expr_stmt (expr);
ad321293
MM
524 expand_end_loop ();
525 }
526
ad321293
MM
527 if (flag_new_for_scope > 0)
528 do_poplevel ();
529
530 finish_stmt ();
531}
532
533/* Finish a break-statement. */
534
535void
536finish_break_stmt ()
537{
538 emit_line_note (input_filename, lineno);
558475f0 539 if (building_stmt_tree ())
ad321293
MM
540 add_tree (build_min_nt (BREAK_STMT));
541 else if ( ! expand_exit_something ())
8251199e 542 cp_error ("break statement not within loop or switch");
ad321293
MM
543}
544
545/* Finish a continue-statement. */
546
547void
548finish_continue_stmt ()
549{
550 emit_line_note (input_filename, lineno);
558475f0 551 if (building_stmt_tree ())
ad321293
MM
552 add_tree (build_min_nt (CONTINUE_STMT));
553 else if (! expand_continue_loop (0))
8251199e 554 cp_error ("continue statement not within a loop");
ad321293
MM
555}
556
527f0080
MM
557/* Begin a switch-statement. Returns a new SWITCH_STMT if
558 appropriate. */
ad321293 559
527f0080 560tree
ad321293
MM
561begin_switch_stmt ()
562{
527f0080
MM
563 tree r;
564
565 if (building_stmt_tree ())
566 {
567 r = build_min_nt (SWITCH_STMT, NULL_TREE, NULL_TREE);
568 add_tree (r);
569 }
570 else
571 r = NULL_TREE;
572
ad321293 573 do_pushlevel ();
527f0080
MM
574
575 return r;
ad321293
MM
576}
577
527f0080 578/* Finish the cond of a switch-statement. */
ad321293 579
527f0080
MM
580void
581finish_switch_cond (cond, switch_stmt)
ad321293 582 tree cond;
527f0080 583 tree switch_stmt;
ad321293 584{
558475f0 585 if (building_stmt_tree ())
527f0080 586 FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt));
0db982be 587 else if (cond != error_mark_node)
ad321293
MM
588 {
589 emit_line_note (input_filename, lineno);
590 c_expand_start_case (cond);
ad321293 591 }
0db982be 592 else
527f0080
MM
593 /* The code is in error, but we don't want expand_end_case to
594 crash. */
595 c_expand_start_case (boolean_false_node);
0db982be 596
ad321293 597 push_switch ();
ad321293
MM
598}
599
600/* Finish the body of a switch-statement, which may be given by
601 SWITCH_STMT. The COND to switch on is indicated. */
602
603void
604finish_switch_stmt (cond, switch_stmt)
605 tree cond;
606 tree switch_stmt;
607{
558475f0 608 if (building_stmt_tree ())
cb39191d 609 RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
ad321293
MM
610 else
611 expand_end_case (cond);
ad321293
MM
612 pop_switch ();
613 do_poplevel ();
614 finish_stmt ();
615}
616
617/* Finish a case-label. */
618
619void
620finish_case_label (low_value, high_value)
621 tree low_value;
622 tree high_value;
623{
558475f0
MM
624 if (building_stmt_tree ())
625 {
b35d4555
MM
626 /* Add a representation for the case label to the statement
627 tree. */
558475f0 628 add_tree (build_min_nt (CASE_LABEL, low_value, high_value));
b35d4555
MM
629 /* And warn about crossing initializations, etc. */
630 if (!processing_template_decl)
631 define_case_label ();
558475f0
MM
632 return;
633 }
634
ad321293
MM
635 do_case (low_value, high_value);
636}
637
ad321293
MM
638/* Finish a goto-statement. */
639
640void
641finish_goto_stmt (destination)
642 tree destination;
643{
3fa56191
MM
644 if (TREE_CODE (destination) == IDENTIFIER_NODE)
645 destination = lookup_label (destination);
646
88848bde
MM
647 /* We warn about unused labels with -Wunused. That means we have to
648 mark the used labels as used. */
649 if (TREE_CODE (destination) == LABEL_DECL)
650 TREE_USED (destination) = 1;
651
558475f0 652 if (building_stmt_tree ())
ad321293
MM
653 add_tree (build_min_nt (GOTO_STMT, destination));
654 else
655 {
656 emit_line_note (input_filename, lineno);
657
3fa56191 658 if (TREE_CODE (destination) == LABEL_DECL)
ad321293 659 {
b35d4555 660 label_rtx (destination);
3fa56191 661 expand_goto (destination);
ad321293
MM
662 }
663 else
664 expand_computed_goto (destination);
665 }
666}
667
668/* Begin a try-block. Returns a newly-created TRY_BLOCK if
669 appropriate. */
670
671tree
672begin_try_block ()
673{
558475f0 674 if (building_stmt_tree ())
ad321293
MM
675 {
676 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
677 NULL_TREE);
678 add_tree (r);
679 return r;
680 }
681 else
682 {
683 emit_line_note (input_filename, lineno);
684 expand_start_try_stmts ();
685 return NULL_TREE;
686 }
687}
688
0dde4175
JM
689/* Likewise, for a function-try-block. */
690
691tree
692begin_function_try_block ()
693{
558475f0 694 if (building_stmt_tree ())
0dde4175
JM
695 {
696 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
697 NULL_TREE);
62409b39 698 FN_TRY_BLOCK_P (r) = 1;
0dde4175
JM
699 add_tree (r);
700 return r;
701 }
702 else
703 {
704 if (! current_function_parms_stored)
705 store_parm_decls ();
706 expand_start_early_try_stmts ();
707 return NULL_TREE;
708 }
709}
710
ad321293
MM
711/* Finish a try-block, which may be given by TRY_BLOCK. */
712
713void
714finish_try_block (try_block)
715 tree try_block;
716{
558475f0 717 if (building_stmt_tree ())
cb39191d 718 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
ad321293 719 else
558475f0 720 expand_start_all_catch ();
ad321293
MM
721}
722
efa8eda3
MM
723/* Finish the body of a cleanup try-block, which may be given by
724 TRY_BLOCK. */
725
62409b39
MM
726void
727finish_cleanup_try_block (try_block)
728 tree try_block;
729{
730 if (building_stmt_tree ())
731 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
732}
733
f1dedc31
MM
734/* Finish an implicitly generated try-block, with a cleanup is given
735 by CLEANUP. */
736
737void
738finish_cleanup (cleanup, try_block)
739 tree cleanup;
740 tree try_block;
741{
742 if (building_stmt_tree ())
743 {
2a1e9fdd 744 TRY_HANDLERS (try_block) = cleanup;
f1dedc31
MM
745 CLEANUP_P (try_block) = 1;
746 }
747 else
748 expand_eh_region_end (protect_with_terminate (cleanup));
749}
750
0dde4175
JM
751/* Likewise, for a function-try-block. */
752
753void
754finish_function_try_block (try_block)
f1dedc31 755 tree try_block;
0dde4175 756{
558475f0 757 if (building_stmt_tree ())
62409b39
MM
758 {
759 if (TREE_CHAIN (try_block)
760 && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER)
761 {
762 /* Chain the compound statement after the CTOR_INITIALIZER. */
763 TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree;
764 /* And make the CTOR_INITIALIZER the body of the try-block. */
765 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
766 }
767 else
768 RECHAIN_STMTS (try_block, TRY_STMTS (try_block));
769 }
0dde4175
JM
770 else
771 {
772 end_protect_partials ();
773 expand_start_all_catch ();
0dde4175 774 }
b35d4555
MM
775
776 in_function_try_handler = 1;
0dde4175
JM
777}
778
ad321293
MM
779/* Finish a handler-sequence for a try-block, which may be given by
780 TRY_BLOCK. */
781
782void
783finish_handler_sequence (try_block)
784 tree try_block;
785{
558475f0 786 if (building_stmt_tree ())
cb39191d 787 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
ad321293 788 else
f1dedc31 789 expand_end_all_catch ();
ad321293
MM
790}
791
0dde4175
JM
792/* Likewise, for a function-try-block. */
793
794void
795finish_function_handler_sequence (try_block)
796 tree try_block;
797{
b35d4555
MM
798 in_function_try_handler = 0;
799
558475f0 800 if (building_stmt_tree ())
cb39191d 801 RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block));
0dde4175 802 else
b35d4555 803 expand_end_all_catch ();
0dde4175
JM
804}
805
ad321293
MM
806/* Begin a handler. Returns a HANDLER if appropriate. */
807
808tree
809begin_handler ()
810{
811 tree r;
812
558475f0 813 if (building_stmt_tree ())
ad321293
MM
814 {
815 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
816 add_tree (r);
817 }
818 else
819 r = NULL_TREE;
820
821 do_pushlevel ();
822
823 return r;
824}
825
826/* Finish the handler-parameters for a handler, which may be given by
b35d4555
MM
827 HANDLER. DECL is the declaration for the catch parameter, or NULL
828 if this is a `catch (...)' clause. */
ad321293 829
b35d4555
MM
830tree
831finish_handler_parms (decl, handler)
832 tree decl;
ad321293 833 tree handler;
b35d4555
MM
834{
835 tree blocks = NULL_TREE;
836
837 if (processing_template_decl)
838 {
839 if (decl)
840 {
841 decl = pushdecl (decl);
842 decl = push_template_decl (decl);
843 add_decl_stmt (decl);
844 RECHAIN_STMTS (handler, HANDLER_PARMS (handler));
845 }
846 }
847 else if (building_stmt_tree ())
848 blocks = expand_start_catch_block (decl);
849
850 return blocks;
851}
852
853/* Note the beginning of a handler for TYPE. This function is called
854 at the point to which control should be transferred when an
855 appropriately-typed exception is thrown. */
856
857void
858begin_catch_block (type)
859 tree type;
ad321293 860{
558475f0 861 if (building_stmt_tree ())
b35d4555
MM
862 add_tree (build (START_CATCH_STMT, type));
863 else
864 start_catch_handler (type);
ad321293
MM
865}
866
b35d4555
MM
867/* Finish a handler, which may be given by HANDLER. The BLOCKs are
868 the return value from the matching call to finish_handler_parms. */
ad321293
MM
869
870void
b35d4555
MM
871finish_handler (blocks, handler)
872 tree blocks;
ad321293
MM
873 tree handler;
874{
b35d4555
MM
875 if (!processing_template_decl)
876 {
877 if (building_stmt_tree ())
878 expand_end_catch_block (blocks);
879
880 if (!building_stmt_tree ())
881 {
882 /* Fall to outside the try statement when done executing
883 handler and we fall off end of handler. This is jump
884 Lresume in the documentation. */
885 expand_goto (top_label_entry (&caught_return_label_stack));
886 end_catch_handler ();
887 }
888 }
889
558475f0 890 if (building_stmt_tree ())
cb39191d 891 RECHAIN_STMTS (handler, HANDLER_BODY (handler));
ad321293
MM
892
893 do_poplevel ();
894}
895
896/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
897 compound-statement does not define a scope. Returns a new
898 COMPOUND_STMT if appropriate. */
899
900tree
901begin_compound_stmt (has_no_scope)
902 int has_no_scope;
903{
904 tree r;
905
558475f0 906 if (building_stmt_tree ())
ad321293
MM
907 {
908 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
909 add_tree (r);
910 if (has_no_scope)
911 COMPOUND_STMT_NO_SCOPE (r) = 1;
912 }
913 else
914 r = NULL_TREE;
915
558475f0
MM
916 last_expr_type = NULL_TREE;
917
ad321293
MM
918 if (!has_no_scope)
919 do_pushlevel ();
f1dedc31
MM
920 else
921 /* Normally, we try hard to keep the BLOCK for a
922 statement-expression. But, if it's a statement-expression with
923 a scopeless block, there's nothing to keep, and we don't want
924 to accidentally keep a block *inside* the scopeless block. */
925 keep_next_level (0);
ad321293 926
24bef158
MM
927 /* If this is the outermost block of the function, declare the
928 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
6f80451c
MM
929 if (current_function
930 && !current_function_name_declared
9bfadf57
MM
931 && !processing_template_decl
932 && !has_no_scope)
24bef158
MM
933 {
934 declare_function_name ();
935 current_function_name_declared = 1;
936 }
937
ad321293
MM
938 return r;
939}
940
941
942/* Finish a compound-statement, which may be given by COMPOUND_STMT.
943 If HAS_NO_SCOPE is non-zero, the compound statement does not define
944 a scope. */
945
946tree
947finish_compound_stmt (has_no_scope, compound_stmt)
948 int has_no_scope;
949 tree compound_stmt;
950{
951 tree r;
558475f0 952 tree t;
ad321293
MM
953
954 if (!has_no_scope)
955 r = do_poplevel ();
956 else
957 r = NULL_TREE;
958
558475f0 959 if (building_stmt_tree ())
cb39191d 960 RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt));
ad321293 961
cb39191d 962 /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since
558475f0
MM
963 the precise purpose of that variable is store the type of the
964 last expression statement within the last compound statement, we
965 preserve the value. */
966 t = last_expr_type;
ad321293 967 finish_stmt ();
558475f0 968 last_expr_type = t;
ad321293
MM
969
970 return r;
971}
972
973/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
974 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
975 CLOBBERS. */
976
977void
978finish_asm_stmt (cv_qualifier, string, output_operands,
3ebc5c52 979 input_operands, clobbers)
ad321293
MM
980 tree cv_qualifier;
981 tree string;
982 tree output_operands;
983 tree input_operands;
984 tree clobbers;
985{
986 if (TREE_CHAIN (string))
3ebc5c52 987 {
558475f0 988 if (building_stmt_tree ())
9188c363
MM
989 /* We need to build the combined string on the permanent
990 obstack so that we can use it during instantiations. */
991 push_permanent_obstack ();
3ebc5c52
MM
992
993 string = combine_strings (string);
994
558475f0 995 if (building_stmt_tree ())
3ebc5c52
MM
996 pop_obstacks ();
997 }
ad321293 998
f71f87f9
MM
999 if (cv_qualifier != NULL_TREE
1000 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
1001 {
1002 cp_warning ("%s qualifier ignored on asm",
1003 IDENTIFIER_POINTER (cv_qualifier));
1004 cv_qualifier = NULL_TREE;
1005 }
1006
558475f0 1007 if (building_stmt_tree ())
ad321293
MM
1008 {
1009 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
1010 output_operands, input_operands,
1011 clobbers);
1012 add_tree (r);
1013 }
1014 else
1015 {
1016 emit_line_note (input_filename, lineno);
6e9438cf
AG
1017 if (output_operands != NULL_TREE || input_operands != NULL_TREE
1018 || clobbers != NULL_TREE)
1019 {
7dc5bd62
MM
1020 tree t;
1021
7dc5bd62
MM
1022 for (t = input_operands; t; t = TREE_CHAIN (t))
1023 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
1024
6e9438cf
AG
1025 c_expand_asm_operands (string, output_operands,
1026 input_operands,
1027 clobbers,
f71f87f9 1028 cv_qualifier != NULL_TREE,
6e9438cf
AG
1029 input_filename, lineno);
1030 }
1031 else
f71f87f9 1032 expand_asm (string);
a64c757e 1033
ad321293
MM
1034 finish_stmt ();
1035 }
1036}
b4c4a9ec 1037
f01b0acb
MM
1038/* Finish a label with the indicated NAME. */
1039
1040void
1041finish_label_stmt (name)
1042 tree name;
1043{
3fa56191 1044 tree decl = define_label (input_filename, lineno, name);
f01b0acb 1045
558475f0 1046 if (building_stmt_tree ())
acef433b 1047 add_tree (build_min_nt (LABEL_STMT, decl));
3fa56191
MM
1048 else if (decl)
1049 expand_label (decl);
f01b0acb
MM
1050}
1051
acef433b
MM
1052/* Finish a series of declarations for local labels. G++ allows users
1053 to declare "local" labels, i.e., labels with scope. This extension
1054 is useful when writing code involving statement-expressions. */
1055
1056void
1057finish_label_decl (name)
1058 tree name;
1059{
1060 tree decl = declare_local_label (name);
1061 if (building_stmt_tree ())
1062 add_decl_stmt (decl);
1063}
1064
9188c363
MM
1065/* Create a declaration statement for the declaration given by the
1066 DECL. */
1067
1068void
1069add_decl_stmt (decl)
1070 tree decl;
1071{
1072 tree decl_stmt;
1073
1074 /* We need the type to last until instantiation time. */
9188c363
MM
1075 decl_stmt = build_min_nt (DECL_STMT, decl);
1076 add_tree (decl_stmt);
1077}
1078
f1dedc31
MM
1079/* We're in a constructor, and have just constructed a a subobject of
1080 *THIS. CLEANUP is code to run if an exception is thrown before the
1081 end of the current function is reached. */
1082
1083void
1084finish_subobject (cleanup)
1085 tree cleanup;
1086{
1087 if (building_stmt_tree ())
1088 {
1089 tree r = build_min_nt (SUBOBJECT, cleanup);
1090 add_tree (r);
1091 }
1092 else
1093 add_partial_entry (cleanup);
1094}
1095
24bef158
MM
1096/* When DECL goes out of scope, make sure that CLEANUP is executed. */
1097
1098void
1099finish_decl_cleanup (decl, cleanup)
1100 tree decl;
1101 tree cleanup;
1102{
1103 if (building_stmt_tree ())
1104 add_tree (build_min_nt (CLEANUP_STMT, decl, cleanup));
b35d4555
MM
1105 else if (!decl
1106 || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
24bef158
MM
1107 expand_decl_cleanup (decl, cleanup);
1108}
1109
558475f0
MM
1110/* Bind a name and initialization to the return value of
1111 the current function. */
1112
1113void
1114finish_named_return_value (return_id, init)
1115 tree return_id, init;
1116{
1117 tree decl = DECL_RESULT (current_function_decl);
1118
1119 if (pedantic)
1120 /* Give this error as many times as there are occurrences,
1121 so that users can use Emacs compilation buffers to find
1122 and fix all such places. */
1123 pedwarn ("ANSI C++ does not permit named return values");
1124
1125 if (return_id != NULL_TREE)
1126 {
1127 if (DECL_NAME (decl) == NULL_TREE)
1128 {
1129 DECL_NAME (decl) = return_id;
1130 DECL_ASSEMBLER_NAME (decl) = return_id;
1131 }
1132 else
1133 {
1134 cp_error ("return identifier `%D' already in place", return_id);
1135 return;
1136 }
1137 }
1138
1139 /* Can't let this happen for constructors. */
1140 if (DECL_CONSTRUCTOR_P (current_function_decl))
1141 {
1142 error ("can't redefine default return value for constructors");
1143 return;
1144 }
1145
1146 /* If we have a named return value, put that in our scope as well. */
1147 if (DECL_NAME (decl) != NULL_TREE)
1148 {
1149 /* Let `cp_finish_decl' know that this initializer is ok. */
1150 DECL_INITIAL (decl) = init;
b35d4555
MM
1151 if (doing_semantic_analysis_p ())
1152 pushdecl (decl);
558475f0
MM
1153
1154 if (building_stmt_tree ())
2a1e9fdd 1155 add_tree (build_min_nt (RETURN_INIT, return_id, init));
558475f0
MM
1156 else
1157 {
1158 cp_finish_decl (decl, init, NULL_TREE, 0, 0);
1159 store_return_init (decl);
1160 }
1161 }
1162}
1163
1164/* Cache the value of this class's main virtual function table pointer
1165 in a register variable. This will save one indirection if a
1166 more than one virtual function call is made this function. */
1167
1168void
1169setup_vtbl_ptr ()
1170{
9bfadf57
MM
1171 my_friendly_assert (doing_semantic_analysis_p (), 19990919);
1172
1173 /* If we've already done this, there's no need to do it again. */
1174 if (vtbls_set_up_p)
1175 return;
1176
1177 if (DECL_CONSTRUCTOR_P (current_function_decl))
558475f0 1178 {
9bfadf57 1179 if (processing_template_decl)
558475f0
MM
1180 add_tree (build_min_nt
1181 (CTOR_INITIALIZER,
1182 current_member_init_list, current_base_init_list));
1183 else
9bfadf57
MM
1184 finish_expr_stmt (emit_base_init (current_class_type));
1185 }
1186 else if (DECL_DESTRUCTOR_P (current_function_decl)
1187 && !processing_template_decl)
1188 {
1189 tree binfo = TYPE_BINFO (current_class_type);
1190 tree if_stmt;
1191 tree compound_stmt;
1192
1193 /* If the dtor is empty, and we know there is not possible way we
1194 could use any vtable entries, before they are possibly set by
1195 a base class dtor, we don't have to setup the vtables, as we
1196 know that any base class dtoring will set up any vtables it
1197 needs. We avoid MI, because one base class dtor can do a
1198 virtual dispatch to an overridden function that would need to
1199 have a non-related vtable set up, we cannot avoid setting up
1200 vtables in that case. We could change this to see if there is
1201 just one vtable. */
1202 if_stmt = begin_if_stmt ();
1203
1204 /* If it is not safe to avoid setting up the vtables, then
1205 someone will change the condition to be boolean_true_node.
1206 (Actually, for now, we do not have code to set the condition
1207 appropriate, so we just assume that we always need to
1208 initialize the vtables.) */
1209 finish_if_stmt_cond (boolean_true_node, if_stmt);
1210 current_vcalls_possible_p = &IF_COND (if_stmt);
1211 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
1212
1213 /* Make all virtual function table pointers in non-virtual base
1214 classes point to CURRENT_CLASS_TYPE's virtual function
1215 tables. */
1216 expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr);
1217
1218 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
1219 expand_indirect_vtbls_init (binfo, current_class_ref,
1220 current_class_ptr);
1221
1222 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
1223 finish_then_clause (if_stmt);
1224 finish_if_stmt ();
558475f0 1225 }
f1dedc31
MM
1226
1227 /* Always keep the BLOCK node associated with the outermost pair of
9bfadf57 1228 curly braces of a function. These are needed for correct
f1dedc31
MM
1229 operation of dwarfout.c. */
1230 keep_next_level (1);
9bfadf57
MM
1231
1232 /* The virtual function tables are set up now. */
1233 vtbls_set_up_p = 1;
558475f0
MM
1234}
1235
8f471b0d
MM
1236/* Add a scope-statement to the statement-tree. BEGIN_P indicates
1237 whether this statements opens or closes a scope. PARTIAL_P is true
1238 for a partial scope, i.e, the scope that begins after a label when
1239 an object that needs a cleanup is created. */
1240
1241void
1242add_scope_stmt (begin_p, partial_p)
1243 int begin_p;
1244 int partial_p;
1245{
1246 tree ss;
1247
1248 /* Build the statement. */
1249 ss = build_min_nt (SCOPE_STMT);
1250 SCOPE_BEGIN_P (ss) = begin_p;
1251 SCOPE_PARTIAL_P (ss) = partial_p;
1252
1253 /* If we're finishing a scope, figure out whether the scope was
1254 really necessary. */
1255 if (!begin_p)
1256 {
1257 SCOPE_NULLIFIED_P (ss) = !kept_level_p ();
1258 SCOPE_NULLIFIED_P (TREE_VALUE (current_scope_stmt_stack))
1259 = SCOPE_NULLIFIED_P (ss);
1260 }
1261
1262 /* Keep the scope stack up to date. */
1263 if (begin_p)
1264 current_scope_stmt_stack
1265 = tree_cons (NULL_TREE, ss, current_scope_stmt_stack);
1266 else
1267 current_scope_stmt_stack = TREE_CHAIN (current_scope_stmt_stack);
1268
1269 /* Add the new statement to the statement-tree. */
1270 add_tree (ss);
1271}
1272
558475f0
MM
1273/* Begin a new scope. */
1274
b35d4555 1275void
558475f0
MM
1276do_pushlevel ()
1277{
1278 if (!building_stmt_tree ())
1279 {
1280 emit_line_note (input_filename, lineno);
1281 clear_last_expr ();
1282 }
f1dedc31 1283 if (stmts_are_full_exprs_p)
b35d4555
MM
1284 {
1285 pushlevel (0);
1286 if (!building_stmt_tree ()
1287 && !current_function->x_whole_function_mode_p)
1288 expand_start_bindings (0);
1289 else if (building_stmt_tree () && !processing_template_decl)
8f471b0d 1290 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
b35d4555 1291 }
f1dedc31 1292}
558475f0
MM
1293
1294/* Finish a scope. */
1295
b35d4555 1296tree
558475f0
MM
1297do_poplevel ()
1298{
b35d4555 1299 tree t = NULL_TREE;
558475f0 1300
f1dedc31 1301 if (stmts_are_full_exprs_p)
b35d4555
MM
1302 {
1303 if (!building_stmt_tree ()
1304 && !current_function->x_whole_function_mode_p)
1305 expand_end_bindings (getdecls (), kept_level_p (), 0);
1306 else if (building_stmt_tree () && !processing_template_decl)
1307 {
8f471b0d 1308 add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
b35d4555
MM
1309
1310 /* When not in function-at-a-time mode, expand_end_bindings
1311 will warn about unused variables. But, in
1312 function-at-a-time mode expand_end_bindings is not passed
1313 the list of variables in the current scope, and therefore
1314 no warning is emitted. So, we explicitly warn here. */
1315 warn_about_unused_variables (getdecls ());
1316 }
1317
1318 t = poplevel (kept_level_p (), 1, 0);
1319 }
558475f0
MM
1320 return t;
1321}
1322
b4c4a9ec
MM
1323/* Finish a parenthesized expression EXPR. */
1324
1325tree
1326finish_parenthesized_expr (expr)
1327 tree expr;
1328{
1329 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
1330 /* This inhibits warnings in truthvalue_conversion. */
1331 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
1332
1333 return expr;
1334}
1335
b69b1501
MM
1336/* Begin a statement-expression. The value returned must be passed to
1337 finish_stmt_expr. */
b4c4a9ec
MM
1338
1339tree
1340begin_stmt_expr ()
1341{
6f80451c
MM
1342 /* If we're outside a function, we won't have a statement-tree to
1343 work with. But, if we see a statement-expression we need to
1344 create one. */
1345 if (!current_function && !last_tree)
1346 begin_stmt_tree (&scope_chain->x_saved_tree);
1347
f1dedc31 1348 keep_next_level (1);
558475f0 1349 /* If we're building a statement tree, then the upcoming compound
b69b1501
MM
1350 statement will be chained onto the tree structure, starting at
1351 last_tree. We return last_tree so that we can later unhook the
1352 compound statement. */
558475f0 1353 return building_stmt_tree () ? last_tree : expand_start_stmt_expr();
b4c4a9ec
MM
1354}
1355
1356/* Finish a statement-expression. RTL_EXPR should be the value
1357 returned by the previous begin_stmt_expr; EXPR is the
1358 statement-expression. Returns an expression representing the
1359 statement-expression. */
1360
1361tree
5ba57b55 1362finish_stmt_expr (rtl_expr)
b4c4a9ec 1363 tree rtl_expr;
b4c4a9ec
MM
1364{
1365 tree result;
1366
558475f0 1367 if (!building_stmt_tree ())
c557501d 1368 rtl_expr = expand_end_stmt_expr (rtl_expr);
b4c4a9ec 1369
558475f0 1370 if (building_stmt_tree ())
b69b1501 1371 {
f1dedc31
MM
1372 /* If the last thing in the statement-expression was not an
1373 expression-statement, then it has type `void'. */
1374 if (!last_expr_type)
1375 last_expr_type = void_type_node;
1376 result = build_min (STMT_EXPR, last_expr_type, last_tree);
1377 TREE_SIDE_EFFECTS (result) = 1;
1378
b69b1501 1379 /* Remove the compound statement from the tree structure; it is
558475f0 1380 now saved in the STMT_EXPR. */
6f80451c 1381 SET_LAST_STMT (rtl_expr);
b69b1501
MM
1382 TREE_CHAIN (last_tree) = NULL_TREE;
1383 }
5ba57b55 1384 else
f1dedc31
MM
1385 result = rtl_expr;
1386
6f80451c
MM
1387 /* If we created a statement-tree for this statement-expression,
1388 remove it now. */
1389 if (!current_function
1390 && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE)
1391 finish_stmt_tree (&scope_chain->x_saved_tree);
1392
b4c4a9ec
MM
1393 return result;
1394}
1395
1396/* Finish a call to FN with ARGS. Returns a representation of the
1397 call. */
1398
1399tree
a759e627 1400finish_call_expr (fn, args, koenig)
b4c4a9ec
MM
1401 tree fn;
1402 tree args;
a759e627 1403 int koenig;
b4c4a9ec 1404{
a759e627
ML
1405 tree result;
1406
1407 if (koenig)
03d82991
JM
1408 {
1409 if (TREE_CODE (fn) == BIT_NOT_EXPR)
1410 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
1411 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
e13a4123 1412 fn = do_identifier (fn, 2, args);
03d82991 1413 }
a759e627 1414 result = build_x_function_call (fn, args, current_class_ref);
b4c4a9ec
MM
1415
1416 if (TREE_CODE (result) == CALL_EXPR
66543169
NS
1417 && (! TREE_TYPE (result)
1418 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
b4c4a9ec
MM
1419 result = require_complete_type (result);
1420
1421 return result;
1422}
1423
1424/* Finish a call to a postfix increment or decrement or EXPR. (Which
1425 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1426 POSTDECREMENT_EXPR.) */
1427
1428tree
1429finish_increment_expr (expr, code)
1430 tree expr;
1431 enum tree_code code;
1432{
1433 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
1434 a COMPONENT_REF). This way if we've got, say, a reference to a
1435 static member that's being operated on, we don't end up trying to
1436 find a member operator for the class it's in. */
1437
1438 if (TREE_CODE (expr) == OFFSET_REF)
1439 expr = resolve_offset_ref (expr);
1440 return build_x_unary_op (code, expr);
1441}
1442
1443/* Finish a use of `this'. Returns an expression for `this'. */
1444
1445tree
1446finish_this_expr ()
1447{
1448 tree result;
1449
1450 if (current_class_ptr)
1451 {
1452#ifdef WARNING_ABOUT_CCD
1453 TREE_USED (current_class_ptr) = 1;
1454#endif
1455 result = current_class_ptr;
1456 }
1457 else if (current_function_decl
1458 && DECL_STATIC_FUNCTION_P (current_function_decl))
1459 {
8251199e 1460 error ("`this' is unavailable for static member functions");
b4c4a9ec
MM
1461 result = error_mark_node;
1462 }
1463 else
1464 {
1465 if (current_function_decl)
8251199e 1466 error ("invalid use of `this' in non-member function");
b4c4a9ec 1467 else
8251199e 1468 error ("invalid use of `this' at top level");
b4c4a9ec
MM
1469 result = error_mark_node;
1470 }
1471
1472 return result;
1473}
1474
1475/* Finish a member function call using OBJECT and ARGS as arguments to
1476 FN. Returns an expression for the call. */
1477
1478tree
1479finish_object_call_expr (fn, object, args)
1480 tree fn;
1481 tree object;
1482 tree args;
1483{
1484#if 0
1485 /* This is a future direction of this code, but because
1486 build_x_function_call cannot always undo what is done in
1487 build_component_ref entirely yet, we cannot do this. */
1488
1489 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1490 return finish_call_expr (real_fn, args);
1491#else
c219b878 1492 if (DECL_DECLARES_TYPE_P (fn))
c68c56f7
MM
1493 {
1494 if (processing_template_decl)
1495 /* This can happen on code like:
1496
1497 class X;
1498 template <class T> void f(T t) {
1499 t.X();
1500 }
1501
1502 We just grab the underlying IDENTIFIER. */
1503 fn = DECL_NAME (fn);
1504 else
1505 {
8251199e 1506 cp_error ("calling type `%T' like a method", fn);
c68c56f7
MM
1507 return error_mark_node;
1508 }
1509 }
1510
b4c4a9ec
MM
1511 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1512#endif
1513}
1514
1515/* Finish a qualified member function call using OBJECT and ARGS as
1516 arguments to FN. Returns an expressino for the call. */
1517
1518tree
1519finish_qualified_object_call_expr (fn, object, args)
1520 tree fn;
1521 tree object;
1522 tree args;
1523{
6eabb241
MM
1524 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1525 TREE_OPERAND (fn, 1), args);
b4c4a9ec
MM
1526}
1527
1528/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1529 being the scope, if any, of DESTRUCTOR. Returns an expression for
1530 the call. */
1531
1532tree
1533finish_pseudo_destructor_call_expr (object, scope, destructor)
1534 tree object;
1535 tree scope;
1536 tree destructor;
1537{
40242ccf
MM
1538 if (processing_template_decl)
1539 return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor);
1540
b4c4a9ec 1541 if (scope && scope != destructor)
8251199e 1542 cp_error ("destructor specifier `%T::~%T()' must have matching names",
b4c4a9ec
MM
1543 scope, destructor);
1544
1545 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1546 && (TREE_CODE (TREE_TYPE (object)) !=
1547 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
8251199e 1548 cp_error ("`%E' is not of type `%T'", object, destructor);
b4c4a9ec
MM
1549
1550 return cp_convert (void_type_node, object);
1551}
1552
1553/* Finish a call to a globally qualified member function FN using
1554 ARGS. Returns an expression for the call. */
1555
1556tree
75d587eb 1557finish_qualified_call_expr (fn, args)
b4c4a9ec
MM
1558 tree fn;
1559 tree args;
1560{
1561 if (processing_template_decl)
2a1e9fdd 1562 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
b4c4a9ec
MM
1563 else
1564 return build_member_call (TREE_OPERAND (fn, 0),
1565 TREE_OPERAND (fn, 1),
1566 args);
1567}
1568
1569/* Finish an expression taking the address of LABEL. Returns an
1570 expression for the address. */
1571
1572tree
1573finish_label_address_expr (label)
1574 tree label;
1575{
1576 tree result;
1577
1578 label = lookup_label (label);
1579 if (label == NULL_TREE)
1580 result = null_pointer_node;
1581 else
1582 {
1583 TREE_USED (label) = 1;
1584 result = build1 (ADDR_EXPR, ptr_type_node, label);
1585 TREE_CONSTANT (result) = 1;
1586 }
1587
1588 return result;
1589}
1590
ce4a0391
MM
1591/* Finish an expression of the form CODE EXPR. */
1592
1593tree
1594finish_unary_op_expr (code, expr)
1595 enum tree_code code;
1596 tree expr;
1597{
1598 tree result = build_x_unary_op (code, expr);
1599 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1600 TREE_NEGATED_INT (result) = 1;
1601 overflow_warning (result);
1602 return result;
1603}
1604
1605/* Finish an id-expression. */
1606
1607tree
1608finish_id_expr (expr)
1609 tree expr;
1610{
1611 if (TREE_CODE (expr) == IDENTIFIER_NODE)
a759e627 1612 expr = do_identifier (expr, 1, NULL_TREE);
ce4a0391
MM
1613
1614 return expr;
1615}
1616
1617/* Begin a new-placement. */
1618
1619int
1620begin_new_placement ()
1621{
1622 /* The arguments to a placement new might be passed to a
1623 deallocation function, in the event that the allocation throws an
1624 exception. Since we don't expand exception handlers until the
1625 end of a function, we must make sure the arguments stay around
1626 that long. */
1627 return suspend_momentary ();
1628}
1629
1630/* Finish a new-placement. The ARGS are the placement arguments. The
1631 COOKIE is the value returned by the previous call to
1632 begin_new_placement. */
1633
1634tree
1635finish_new_placement (args, cookie)
1636 tree args;
1637 int cookie;
1638{
1639 resume_momentary (cookie);
1640 return args;
1641}
1642
b4c4a9ec
MM
1643/* Begin a function defniition declared with DECL_SPECS and
1644 DECLARATOR. Returns non-zero if the function-declaration is
1645 legal. */
1646
1647int
1648begin_function_definition (decl_specs, declarator)
1649 tree decl_specs;
1650 tree declarator;
1651{
1652 tree specs;
1653 tree attrs;
1654 split_specs_attrs (decl_specs, &specs, &attrs);
a8f73d4b 1655 if (!start_function (specs, declarator, attrs, SF_DEFAULT))
b4c4a9ec
MM
1656 return 0;
1657
1658 reinit_parse_for_function ();
39c01e4c
MM
1659 /* The things we're about to see are not directly qualified by any
1660 template headers we've seen thus far. */
1661 reset_specialization ();
1662
b4c4a9ec
MM
1663 return 1;
1664}
1665
1666/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1667 a SCOPE_REF. */
1668
1669tree
1670begin_constructor_declarator (scope, name)
1671 tree scope;
1672 tree name;
1673{
1674 tree result = build_parse_node (SCOPE_REF, scope, name);
830fcda8 1675 enter_scope_of (result);
b4c4a9ec
MM
1676 return result;
1677}
1678
ce4a0391
MM
1679/* Finish an init-declarator. Returns a DECL. */
1680
1681tree
1682finish_declarator (declarator, declspecs, attributes,
1683 prefix_attributes, initialized)
1684 tree declarator;
1685 tree declspecs;
1686 tree attributes;
1687 tree prefix_attributes;
1688 int initialized;
1689{
1690 return start_decl (declarator, declspecs, initialized, attributes,
1691 prefix_attributes);
1692}
1693
8014a339 1694/* Finish a translation unit. */
ce4a0391
MM
1695
1696void
1697finish_translation_unit ()
1698{
1699 /* In case there were missing closebraces,
1700 get us back to the global binding level. */
273a708f 1701 pop_everything ();
ce4a0391
MM
1702 while (current_namespace != global_namespace)
1703 pop_namespace ();
1704 finish_file ();
1705}
1706
b4c4a9ec
MM
1707/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1708 Returns the parameter. */
1709
1710tree
1711finish_template_type_parm (aggr, identifier)
1712 tree aggr;
1713 tree identifier;
1714{
6eabb241 1715 if (aggr != class_type_node)
b4c4a9ec 1716 {
8251199e 1717 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1718 aggr = class_type_node;
1719 }
1720
1721 return build_tree_list (aggr, identifier);
1722}
1723
1724/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1725 Returns the parameter. */
1726
1727tree
1728finish_template_template_parm (aggr, identifier)
1729 tree aggr;
1730 tree identifier;
1731{
1732 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1733 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1734 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1735 DECL_TEMPLATE_RESULT (tmpl) = decl;
1736 SET_DECL_ARTIFICIAL (decl);
1737 end_template_decl ();
1738
1739 return finish_template_type_parm (aggr, tmpl);
1740}
ce4a0391
MM
1741
1742/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1743 non-zero, the parameter list was terminated by a `...'. */
1744
1745tree
1746finish_parmlist (parms, ellipsis)
1747 tree parms;
1748 int ellipsis;
1749{
1750 if (!ellipsis)
1751 chainon (parms, void_list_node);
1752 /* We mark the PARMS as a parmlist so that declarator processing can
1753 disambiguate certain constructs. */
1754 if (parms != NULL_TREE)
1755 TREE_PARMLIST (parms) = 1;
1756
1757 return parms;
1758}
1759
1760/* Begin a class definition, as indicated by T. */
1761
1762tree
1763begin_class_definition (t)
1764 tree t;
1765{
9188c363
MM
1766 push_permanent_obstack ();
1767
ce4a0391
MM
1768 if (t == error_mark_node
1769 || ! IS_AGGR_TYPE (t))
1770 {
830fcda8 1771 t = make_lang_type (RECORD_TYPE);
ce4a0391
MM
1772 pushtag (make_anon_name (), t, 0);
1773 }
830fcda8
JM
1774
1775 /* In a definition of a member class template, we will get here with an
1776 implicit typename, a TYPENAME_TYPE with a type. */
1777 if (TREE_CODE (t) == TYPENAME_TYPE)
1778 t = TREE_TYPE (t);
4c571114
MM
1779
1780 /* If we generated a partial instantiation of this type, but now
1781 we're seeing a real definition, we're actually looking at a
1782 partial specialization. Consider:
1783
1784 template <class T, class U>
1785 struct Y {};
1786
1787 template <class T>
1788 struct X {};
1789
1790 template <class T, class U>
1791 void f()
1792 {
1793 typename X<Y<T, U> >::A a;
1794 }
1795
1796 template <class T, class U>
1797 struct X<Y<T, U> >
1798 {
1799 };
1800
1801 We have to undo the effects of the previous partial
1802 instantiation. */
1803 if (PARTIAL_INSTANTIATION_P (t))
1804 {
1805 if (!pedantic)
1806 {
1807 /* Unfortunately, when we're not in pedantic mode, we
1808 attempt to actually fill in some of the fields of the
1809 partial instantiation, in order to support the implicit
1810 typename extension. Clear those fields now, in
1811 preparation for the definition here. The fields cleared
1812 here must match those set in instantiate_class_template.
1813 Look for a comment mentioning begin_class_definition
1814 there. */
1815 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1816 TYPE_FIELDS (t) = NULL_TREE;
1817 TYPE_METHODS (t) = NULL_TREE;
1818 CLASSTYPE_TAGS (t) = NULL_TREE;
1819 TYPE_SIZE (t) = NULL_TREE;
1820 }
830fcda8 1821
4c571114
MM
1822 /* This isn't a partial instantiation any more. */
1823 PARTIAL_INSTANTIATION_P (t) = 0;
1824 }
1825 /* If this type was already complete, and we see another definition,
1826 that's an error. */
1827 else if (TYPE_SIZE (t))
ce4a0391 1828 duplicate_tag_error (t);
4c571114 1829
b4f70b3d
NS
1830 /* Update the location of the decl. */
1831 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1832 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1833
4c571114 1834 if (TYPE_BEING_DEFINED (t))
ce4a0391
MM
1835 {
1836 t = make_lang_type (TREE_CODE (t));
1837 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 1838 }
ff350acd 1839 maybe_process_partial_specialization (t);
8f032717 1840 pushclass (t, 1);
ce4a0391 1841 TYPE_BEING_DEFINED (t) = 1;
ce4a0391
MM
1842 /* Reset the interface data, at the earliest possible
1843 moment, as it might have been set via a class foo;
1844 before. */
6eabb241
MM
1845 {
1846 tree name = TYPE_IDENTIFIER (t);
1847
1848 if (! ANON_AGGRNAME_P (name))
1849 {
1850 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1851 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1852 (t, interface_unknown);
1853 }
1854
1855 /* Only leave this bit clear if we know this
1856 class is part of an interface-only specification. */
1857 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1858 || ! CLASSTYPE_INTERFACE_ONLY (t))
1859 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1860 }
ce4a0391 1861#if 0
830fcda8
JM
1862 tmp = TYPE_IDENTIFIER ($<ttype>0);
1863 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1864 overload_template_name (tmp, 1);
ce4a0391
MM
1865#endif
1866 reset_specialization();
1867
b7975aed
MM
1868 /* Make a declaration for this class in its own scope. */
1869 build_self_reference ();
1870
830fcda8 1871 return t;
ce4a0391
MM
1872}
1873
61a127b3
MM
1874/* Finish the member declaration given by DECL. */
1875
1876void
1877finish_member_declaration (decl)
1878 tree decl;
1879{
1880 if (decl == error_mark_node || decl == NULL_TREE)
1881 return;
1882
1883 if (decl == void_type_node)
1884 /* The COMPONENT was a friend, not a member, and so there's
1885 nothing for us to do. */
1886 return;
1887
1888 /* We should see only one DECL at a time. */
1889 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1890
1891 /* Set up access control for DECL. */
1892 TREE_PRIVATE (decl)
1893 = (current_access_specifier == access_private_node);
1894 TREE_PROTECTED (decl)
1895 = (current_access_specifier == access_protected_node);
1896 if (TREE_CODE (decl) == TEMPLATE_DECL)
1897 {
1898 TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl);
1899 TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl);
1900 }
1901
1902 /* Mark the DECL as a member of the current class. */
1903 if (TREE_CODE (decl) == FUNCTION_DECL
1904 || DECL_FUNCTION_TEMPLATE_P (decl))
1905 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1906 finish_struct. Presumably it is already set as the function is
1907 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1908 DECL_CLASS_CONTEXT (decl) = current_class_type;
61a127b3
MM
1909 else
1910 DECL_CONTEXT (decl) = current_class_type;
1911
1912 /* Put functions on the TYPE_METHODS list and everything else on the
1913 TYPE_FIELDS list. Note that these are built up in reverse order.
1914 We reverse them (to obtain declaration order) in finish_struct. */
1915 if (TREE_CODE (decl) == FUNCTION_DECL
1916 || DECL_FUNCTION_TEMPLATE_P (decl))
1917 {
1918 /* We also need to add this function to the
1919 CLASSTYPE_METHOD_VEC. */
1920 add_method (current_class_type, 0, decl);
1921
1922 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1923 TYPE_METHODS (current_class_type) = decl;
1924 }
1925 else
1926 {
1927 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1928 go at the beginning. The reason is that lookup_field_1
1929 searches the list in order, and we want a field name to
1930 override a type name so that the "struct stat hack" will
1931 work. In particular:
1932
1933 struct S { enum E { }; int E } s;
1934 s.E = 3;
1935
1936 is legal. In addition, the FIELD_DECLs must be maintained in
1937 declaration order so that class layout works as expected.
1938 However, we don't need that order until class layout, so we
1939 save a little time by putting FIELD_DECLs on in reverse order
1940 here, and then reversing them in finish_struct_1. (We could
1941 also keep a pointer to the correct insertion points in the
1942 list.) */
1943
1944 if (TREE_CODE (decl) == TYPE_DECL)
1945 TYPE_FIELDS (current_class_type)
1946 = chainon (TYPE_FIELDS (current_class_type), decl);
1947 else
1948 {
1949 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1950 TYPE_FIELDS (current_class_type) = decl;
1951 }
8f032717
MM
1952
1953 /* Enter the DECL into the scope of the class. */
1954 if (TREE_CODE (decl) != USING_DECL)
1955 pushdecl_class_level (decl);
61a127b3
MM
1956 }
1957}
1958
1959/* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1960 the definition is immediately followed by a semicolon. Returns the
1961 type. */
ce4a0391
MM
1962
1963tree
fbdd0024 1964finish_class_definition (t, attributes, semi, pop_scope_p)
ce4a0391 1965 tree t;
ce4a0391
MM
1966 tree attributes;
1967 int semi;
fbdd0024 1968 int pop_scope_p;
ce4a0391 1969{
ce4a0391
MM
1970 /* finish_struct nukes this anyway; if finish_exception does too,
1971 then it can go. */
1972 if (semi)
1973 note_got_semicolon (t);
1974
dc8263bc
JM
1975 /* If we got any attributes in class_head, xref_tag will stick them in
1976 TREE_TYPE of the type. Grab them now. */
1977 attributes = chainon (TREE_TYPE (t), attributes);
1978 TREE_TYPE (t) = NULL_TREE;
1979
ce4a0391
MM
1980 if (TREE_CODE (t) == ENUMERAL_TYPE)
1981 ;
1982 else
1983 {
9f33663b 1984 t = finish_struct (t, attributes);
ce4a0391
MM
1985 if (semi)
1986 note_got_semicolon (t);
1987 }
1988
1989 pop_obstacks ();
1990
1991 if (! semi)
1992 check_for_missing_semicolon (t);
fbdd0024
MM
1993 if (pop_scope_p)
1994 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
ce4a0391
MM
1995 if (current_scope () == current_function_decl)
1996 do_pending_defargs ();
1997
1998 return t;
1999}
2000
2001/* Finish processing the default argument expressions cached during
2002 the processing of a class definition. */
2003
2004void
51632249 2005begin_inline_definitions ()
ce4a0391
MM
2006{
2007 if (pending_inlines
2008 && current_scope () == current_function_decl)
2009 do_pending_inlines ();
2010}
2011
2012/* Finish processing the inline function definitions cached during the
2013 processing of a class definition. */
2014
2015void
51632249 2016finish_inline_definitions ()
ce4a0391
MM
2017{
2018 if (current_class_type == NULL_TREE)
2019 clear_inline_text_obstack ();
ce4a0391 2020}
35acd3f2
MM
2021
2022/* Finish processing the declaration of a member class template
2023 TYPES whose template parameters are given by PARMS. */
2024
2025tree
61a127b3 2026finish_member_class_template (types)
35acd3f2
MM
2027 tree types;
2028{
36a117a5
MM
2029 tree t;
2030
2031 /* If there are declared, but undefined, partial specializations
2032 mixed in with the typespecs they will not yet have passed through
2033 maybe_process_partial_specialization, so we do that here. */
2034 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
2035 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
2036 maybe_process_partial_specialization (TREE_VALUE (t));
2037
35acd3f2 2038 note_list_got_semicolon (types);
61a127b3 2039 grok_x_components (types);
35acd3f2
MM
2040 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
2041 /* The component was in fact a friend declaration. We avoid
2042 finish_member_template_decl performing certain checks by
2043 unsetting TYPES. */
2044 types = NULL_TREE;
61a127b3
MM
2045
2046 finish_member_template_decl (types);
2047
35acd3f2
MM
2048 /* As with other component type declarations, we do
2049 not store the new DECL on the list of
2050 component_decls. */
2051 return NULL_TREE;
2052}
36a117a5
MM
2053
2054/* Finish processsing a complete template declaration. The PARMS are
2055 the template parameters. */
2056
2057void
2058finish_template_decl (parms)
2059 tree parms;
2060{
2061 if (parms)
2062 end_template_decl ();
2063 else
2064 end_specialization ();
2065}
2066
2067/* Finish processing a a template-id (which names a type) of the form
2068 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2069 template-id. If ENTERING_SCOPE is non-zero we are about to enter
2070 the scope of template-id indicated. */
2071
2072tree
2073finish_template_type (name, args, entering_scope)
2074 tree name;
2075 tree args;
2076 int entering_scope;
2077{
2078 tree decl;
2079
2080 decl = lookup_template_class (name, args,
2081 NULL_TREE, NULL_TREE, entering_scope);
2082 if (decl != error_mark_node)
2083 decl = TYPE_STUB_DECL (decl);
2084
2085 return decl;
2086}
648f19f6
MM
2087
2088/* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
2089 namespace scope or a class scope. */
2090
2091void
2092enter_scope_of (sr)
2093 tree sr;
2094{
2095 tree scope = TREE_OPERAND (sr, 0);
2096
2097 if (TREE_CODE (scope) == NAMESPACE_DECL)
2098 {
2099 push_decl_namespace (scope);
2100 TREE_COMPLEXITY (sr) = -1;
2101 }
2102 else if (scope != current_class_type)
2103 {
830fcda8
JM
2104 if (TREE_CODE (scope) == TYPENAME_TYPE)
2105 {
2106 /* In a declarator for a template class member, the scope will
2107 get here as an implicit typename, a TYPENAME_TYPE with a type. */
2108 scope = TREE_TYPE (scope);
2109 TREE_OPERAND (sr, 0) = scope;
2110 }
648f19f6
MM
2111 push_nested_class (scope, 3);
2112 TREE_COMPLEXITY (sr) = current_class_depth;
2113 }
2114}
ea6021e8
MM
2115
2116/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2117 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2118 BASE_CLASS, or NULL_TREE if an error occurred. The
2119 ACCESSS_SPECIFIER is one of
2120 access_{default,public,protected_private}[_virtual]_node.*/
2121
2122tree
6eabb241 2123finish_base_specifier (access_specifier, base_class)
ea6021e8
MM
2124 tree access_specifier;
2125 tree base_class;
ea6021e8
MM
2126{
2127 tree type;
2128 tree result;
2129
2130 if (base_class == NULL_TREE)
2131 {
8251199e 2132 error ("invalid base class");
ea6021e8
MM
2133 type = error_mark_node;
2134 }
2135 else
2136 type = TREE_TYPE (base_class);
6eabb241 2137
ea6021e8
MM
2138 if (! is_aggr_type (type, 1))
2139 result = NULL_TREE;
ea6021e8
MM
2140 else
2141 result = build_tree_list (access_specifier, type);
2142
2143 return result;
2144}
61a127b3
MM
2145
2146/* Called when multiple declarators are processed. If that is not
2147 premitted in this context, an error is issued. */
2148
2149void
2150check_multiple_declarators ()
2151{
2152 /* [temp]
2153
2154 In a template-declaration, explicit specialization, or explicit
2155 instantiation the init-declarator-list in the declaration shall
2156 contain at most one declarator.
2157
2158 We don't just use PROCESSING_TEMPLATE_DECL for the first
2159 condition since that would disallow the perfectly legal code,
2160 like `template <class T> struct S { int i, j; };'. */
2161 tree scope = current_scope ();
2162
2163 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
2164 /* It's OK to write `template <class T> void f() { int i, j;}'. */
2165 return;
2166
2167 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
2168 || processing_explicit_instantiation
2169 || processing_specialization)
2170 cp_error ("multiple declarators in template declaration");
2171}
2172
b894fc05
JM
2173tree
2174finish_typeof (expr)
2175 tree expr;
2176{
2177 if (processing_template_decl)
2178 {
2179 tree t;
2180
9188c363 2181 push_permanent_obstack ();
b894fc05 2182 t = make_lang_type (TYPEOF_TYPE);
b894fc05 2183 TYPE_FIELDS (t) = expr;
b894fc05
JM
2184 pop_obstacks ();
2185
2186 return t;
2187 }
2188
2189 return TREE_TYPE (expr);
2190}
558475f0 2191
6f80451c 2192/* Create an empty statement tree rooted at T. */
558475f0
MM
2193
2194void
6f80451c
MM
2195begin_stmt_tree (t)
2196 tree *t;
558475f0
MM
2197{
2198 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
2199 what follows. We remove the extraneous statement in
2200 finish_stmt_tree. */
6f80451c
MM
2201 *t = build_nt (EXPR_STMT, void_zero_node);
2202 SET_LAST_STMT (*t);
558475f0
MM
2203 last_expr_type = NULL_TREE;
2204}
2205
6f80451c 2206/* Finish the statement tree rooted at T. */
558475f0
MM
2207
2208void
6f80451c
MM
2209finish_stmt_tree (t)
2210 tree *t;
558475f0 2211{
a7e4cfa0
MM
2212 tree stmt;
2213
2214 /* Remove the fake extra statement added in begin_stmt_tree. */
6f80451c
MM
2215 stmt = TREE_CHAIN (*t);
2216 *t = stmt;
2217 SET_LAST_STMT (NULL_TREE);
a7e4cfa0 2218
6f80451c
MM
2219 if (current_function)
2220 {
2221 /* The line-number recorded in the outermost statement in a function
2222 is the line number of the end of the function. */
2223 STMT_LINENO (stmt) = lineno;
2224 STMT_LINENO_FOR_FN_P (stmt) = 1;
2225 }
a7e4cfa0
MM
2226}
2227
2228/* We're about to expand T, a statement. Set up appropriate context
2229 for the substitution. */
2230
2231void
2232prep_stmt (t)
2233 tree t;
2234{
2235 if (!STMT_LINENO_FOR_FN_P (t))
2236 lineno = STMT_LINENO (t);
2237 stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
558475f0
MM
2238}
2239
527f0080
MM
2240/* Some statements, like for-statements or if-statements, require a
2241 condition. This condition can be a declaration. If T is such a
2242 declaration it is processed, and an expression appropriate to use
2243 as the condition is returned. Otherwise, T itself is returned. */
2244
2245static tree
2246expand_cond (t)
2247 tree t;
2248{
ed5511d9 2249 if (t && TREE_CODE (t) == TREE_LIST)
527f0080 2250 {
ed5511d9
MM
2251 expand_stmt (TREE_PURPOSE (t));
2252 return TREE_VALUE (t);
527f0080
MM
2253 }
2254 else
2255 return t;
2256}
2257
62409b39
MM
2258/* Generate RTL for the statement T, and its substatements, and any
2259 other statements at its nesting level. */
558475f0
MM
2260
2261tree
2262expand_stmt (t)
2263 tree t;
2264{
47d7090e 2265 tree rval = NULL_TREE;
a7e4cfa0 2266
62409b39
MM
2267 while (t && t != error_mark_node)
2268 {
2269 int saved_stmts_are_full_exprs_p;
558475f0 2270
62409b39
MM
2271 /* Assume we'll have nothing to return. */
2272 rval = NULL_TREE;
a7e4cfa0 2273
62409b39
MM
2274 /* Set up context appropriately for handling this statement. */
2275 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p;
2276 prep_stmt (t);
a7e4cfa0 2277
62409b39
MM
2278 switch (TREE_CODE (t))
2279 {
2280 case RETURN_STMT:
2281 finish_return_stmt (RETURN_EXPR (t));
2282 break;
558475f0 2283
62409b39 2284 case EXPR_STMT:
9bfadf57 2285 finish_expr_stmt (EXPR_STMT_EXPR (t));
62409b39 2286 break;
558475f0 2287
62409b39 2288 case DECL_STMT:
acef433b 2289 {
62409b39
MM
2290 tree decl;
2291 int i = suspend_momentary ();
2292
2293 emit_line_note (input_filename, lineno);
2294 decl = DECL_STMT_DECL (t);
b35d4555
MM
2295 /* If this is a declaration for an automatic local
2296 variable, initialize it. Note that we might also see a
2297 declaration for a namespace-scope object (declared with
9ed9e79a
MM
2298 `extern'). We don't have to handle the initialization
2299 of those objects here; they can only be declarations,
2300 rather than definitions. */
b35d4555
MM
2301 if (TREE_CODE (decl) == VAR_DECL
2302 && !TREE_STATIC (decl)
2303 && !DECL_EXTERNAL (decl))
0fa5e05c
MM
2304 {
2305 /* Let the back-end know about this variable. */
2306 if (!ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
2307 emit_local_var (decl);
2308 else
2309 expand_anon_union_decl (decl, NULL_TREE,
2310 DECL_ANON_UNION_ELEMS (decl));
2311 }
9ed9e79a 2312 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
f3010146 2313 make_rtl_for_local_static (decl);
b35d4555 2314
62409b39 2315 resume_momentary (i);
acef433b 2316 }
62409b39 2317 break;
558475f0 2318
24bef158
MM
2319 case CLEANUP_STMT:
2320 finish_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
2321 break;
2322
b35d4555
MM
2323 case START_CATCH_STMT:
2324 begin_catch_block (TREE_TYPE (t));
2325 break;
2326
62409b39
MM
2327 case FOR_STMT:
2328 {
2329 tree tmp;
2330
2331 begin_for_stmt ();
2332 expand_stmt (FOR_INIT_STMT (t));
2333 finish_for_init_stmt (NULL_TREE);
2334 finish_for_cond (expand_cond (FOR_COND (t)), NULL_TREE);
2335 tmp = FOR_EXPR (t);
2336 finish_for_expr (tmp, NULL_TREE);
2337 expand_stmt (FOR_BODY (t));
2338 finish_for_stmt (tmp, NULL_TREE);
2339 }
2340 break;
558475f0 2341
62409b39
MM
2342 case WHILE_STMT:
2343 {
2344 begin_while_stmt ();
2345 finish_while_stmt_cond (expand_cond (WHILE_COND (t)), NULL_TREE);
2346 expand_stmt (WHILE_BODY (t));
2347 finish_while_stmt (NULL_TREE);
2348 }
2349 break;
558475f0 2350
62409b39
MM
2351 case DO_STMT:
2352 {
2353 begin_do_stmt ();
2354 expand_stmt (DO_BODY (t));
2355 finish_do_body (NULL_TREE);
2356 finish_do_stmt (DO_COND (t), NULL_TREE);
2357 }
2358 break;
527f0080 2359
62409b39
MM
2360 case IF_STMT:
2361 begin_if_stmt ();
2362 finish_if_stmt_cond (expand_cond (IF_COND (t)), NULL_TREE);
2363 if (THEN_CLAUSE (t))
2364 {
2365 expand_stmt (THEN_CLAUSE (t));
2366 finish_then_clause (NULL_TREE);
2367 }
2368 if (ELSE_CLAUSE (t))
2369 {
2370 begin_else_clause ();
2371 expand_stmt (ELSE_CLAUSE (t));
2372 finish_else_clause (NULL_TREE);
2373 }
2374 finish_if_stmt ();
2375 break;
558475f0 2376
62409b39
MM
2377 case COMPOUND_STMT:
2378 begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
2379 expand_stmt (COMPOUND_BODY (t));
2380 rval = finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t),
2381 NULL_TREE);
2382 break;
558475f0 2383
62409b39
MM
2384 case BREAK_STMT:
2385 finish_break_stmt ();
2386 break;
558475f0 2387
62409b39
MM
2388 case CONTINUE_STMT:
2389 finish_continue_stmt ();
2390 break;
558475f0 2391
62409b39
MM
2392 case SWITCH_STMT:
2393 {
2394 tree cond;
558475f0 2395
62409b39
MM
2396 begin_switch_stmt ();
2397 cond = expand_cond (SWITCH_COND (t));
2398 finish_switch_cond (cond, NULL_TREE);
2399 expand_stmt (SWITCH_BODY (t));
2400 finish_switch_stmt (cond, NULL_TREE);
2401 }
2402 break;
2403
2404 case CASE_LABEL:
2405 finish_case_label (CASE_LOW (t), CASE_HIGH (t));
2406 break;
2407
2408 case LABEL_STMT:
b35d4555 2409 expand_label (LABEL_STMT_LABEL (t));
62409b39
MM
2410 break;
2411
2412 case GOTO_STMT:
b35d4555 2413 finish_goto_stmt (GOTO_DESTINATION (t));
62409b39
MM
2414 break;
2415
2416 case ASM_STMT:
2417 finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS
2418 (t), ASM_INPUTS (t), ASM_CLOBBERS (t));
2419 break;
2420
2421 case TRY_BLOCK:
2422 if (CLEANUP_P (t))
2423 {
2424 expand_eh_region_start ();
2425 expand_stmt (TRY_STMTS (t));
2426 finish_cleanup_try_block (NULL_TREE);
2427 finish_cleanup (TRY_HANDLERS (t), NULL_TREE);
2428 }
2429 else
2430 {
b35d4555
MM
2431 if (FN_TRY_BLOCK_P (t))
2432 begin_function_try_block ();
2433 else
2434 begin_try_block ();
2435
62409b39 2436 expand_stmt (TRY_STMTS (t));
b35d4555
MM
2437
2438 if (FN_TRY_BLOCK_P (t))
2439 {
2440 finish_function_try_block (NULL_TREE);
2441 expand_stmt (TRY_HANDLERS (t));
2442 finish_function_handler_sequence (NULL_TREE);
2443 }
2444 else
2445 {
2446 finish_try_block (NULL_TREE);
2447 expand_stmt (TRY_HANDLERS (t));
2448 finish_handler_sequence (NULL_TREE);
2449 }
62409b39
MM
2450 }
2451 break;
2452
2453 case HANDLER:
2454 begin_handler ();
62409b39 2455 expand_stmt (HANDLER_BODY (t));
b35d4555 2456 finish_handler (NULL_TREE, NULL_TREE);
62409b39
MM
2457 break;
2458
2459 case SUBOBJECT:
2460 finish_subobject (SUBOBJECT_CLEANUP (t));
2461 break;
2462
b35d4555
MM
2463 case SCOPE_STMT:
2464 if (SCOPE_BEGIN_P (t))
2465 expand_start_bindings (2 * SCOPE_NULLIFIED_P (t));
2466 else if (SCOPE_END_P (t))
8f471b0d
MM
2467 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t),
2468 SCOPE_PARTIAL_P (t));
b35d4555
MM
2469 break;
2470
b35d4555
MM
2471 case RETURN_INIT:
2472 /* Clear this out so that finish_named_return_value can set it
2473 again. */
2474 DECL_NAME (DECL_RESULT (current_function_decl)) = NULL_TREE;
2475 finish_named_return_value (TREE_OPERAND (t, 0),
2476 TREE_OPERAND (t, 1));
2477 break;
2478
62409b39
MM
2479 default:
2480 my_friendly_abort (19990810);
2481 break;
f1dedc31 2482 }
558475f0 2483
62409b39
MM
2484 /* Restore saved state. */
2485 stmts_are_full_exprs_p = saved_stmts_are_full_exprs_p;
558475f0 2486
62409b39
MM
2487 /* Go on to the next statement in this scope. */
2488 t = TREE_CHAIN (t);
558475f0
MM
2489 }
2490
a7e4cfa0 2491 return rval;
558475f0
MM
2492}
2493
2494/* Generate RTL for FN. */
2495
2496void
2497expand_body (fn)
2498 tree fn;
2499{
62409b39
MM
2500 int saved_lineno;
2501 char *saved_input_filename;
558475f0 2502
62409b39
MM
2503 /* When the parser calls us after finishing the body of a template
2504 function, we don't really want to expand the body. When we're
2505 processing an in-class definition of an inline function,
2506 PROCESSING_TEMPLATE_DECL will no longer be set here, so we have
2507 to look at the function itself. */
2508 if (processing_template_decl
2509 || (DECL_LANG_SPECIFIC (fn)
2510 && DECL_TEMPLATE_INFO (fn)
2511 && uses_template_parms (DECL_TI_ARGS (fn))))
2512 return;
2513
84df082b
MM
2514 /* There's no reason to do any of the work here if we're only doing
2515 semantic analysis; this code just generates RTL. */
2516 if (flag_syntax_only)
2517 return;
2518
62409b39 2519 /* Save the current file name and line number. When we expand the
84df082b 2520 body of the function, we'll set LINENO and INPUT_FILENAME so that
62409b39
MM
2521 error-mesages come out in the right places. */
2522 saved_lineno = lineno;
2523 saved_input_filename = input_filename;
2524 lineno = DECL_SOURCE_LINE (fn);
2525 input_filename = DECL_SOURCE_FILE (fn);
2526
a8f73d4b 2527 start_function (NULL_TREE, fn, NULL_TREE, SF_PRE_PARSED | SF_EXPAND);
558475f0
MM
2528 store_parm_decls ();
2529
24bef158
MM
2530 /* We don't need to redeclare __FUNCTION__, __PRETTY_FUNCTION__, or
2531 any of the other magic variables we set up when starting a
2532 function body. */
2533 current_function_name_declared = 1;
2534
558475f0 2535 /* Expand the body. */
b35d4555 2536 expand_stmt (DECL_SAVED_TREE (fn));
558475f0 2537
62409b39
MM
2538 /* Statements should always be full-expressions at the outermost set
2539 of curly braces for a function. */
2540 my_friendly_assert (stmts_are_full_exprs_p, 19990831);
2541
2542 /* The outermost statement for a function contains the line number
2543 recorded when we finished processing the function. */
2544 lineno = STMT_LINENO (DECL_SAVED_TREE (fn));
2545
2546 /* Generate code for the function. */
fdfcc44c 2547 finish_function (lineno, 0);
62409b39
MM
2548
2549 /* And restore the current source position. */
2550 lineno = saved_lineno;
2551 input_filename = saved_input_filename;
558475f0 2552}