]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/semantics.c
Daily bump.
[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"
ad321293
MM
34
35/* There routines provide a modular interface to perform many parsing
36 operations. They may therefore be used during actual parsing, or
37 during template instantiation, which may be regarded as a
38 degenerate form of parsing. Since the current g++ parser is
39 lacking in several respects, and will be reimplemented, we are
40 attempting to move most code that is not directly related to
41 parsing into this file; that will make implementing the new parser
42 much easier since it will be able to make use of these routines. */
43
44/* When parsing a template, LAST_TREE contains the last statement
45 parsed. These are chained together through the TREE_CHAIN field,
46 but often need to be re-organized since the parse is performed
47 bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of
48 STMT. */
49
50#define RECHAIN_STMTS(stmt, substmt, last) \
51 do { \
52 substmt = last; \
53 TREE_CHAIN (stmt) = NULL_TREE; \
54 last_tree = stmt; \
55 } while (0)
56
57#define RECHAIN_STMTS_FROM_LAST(stmt, substmt) \
58 RECHAIN_STMTS (stmt, substmt, last_tree)
59
60#define RECHAIN_STMTS_FROM_CHAIN(stmt, substmt) \
61 RECHAIN_STMTS (stmt, substmt, TREE_CHAIN (stmt))
62
63/* Finish an expression-statement, whose EXPRESSION is as indicated. */
64
65void
66finish_expr_stmt (expr)
67 tree expr;
68{
ce4a0391 69 if (expr != NULL_TREE)
ad321293 70 {
ce4a0391
MM
71 if (!processing_template_decl)
72 {
73 emit_line_note (input_filename, lineno);
74 /* Do default conversion if safe and possibly important,
75 in case within ({...}). */
76 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
77 && lvalue_p (expr))
78 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
79 expr = default_conversion (expr);
80 }
81
82 cplus_expand_expr_stmt (expr);
83 clear_momentary ();
ad321293 84 }
ce4a0391 85
ad321293
MM
86 finish_stmt ();
87}
88
89/* Begin an if-statement. Returns a newly created IF_STMT if
90 appropriate. */
91
92tree
93begin_if_stmt ()
94{
95 tree r;
96
97 if (processing_template_decl)
98 {
99 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
100 add_tree (r);
101 }
102 else
103 r = NULL_TREE;
104
105 do_pushlevel ();
106
107 return r;
108}
109
110/* Process the COND of an if-statement, which may be given by
111 IF_STMT. */
112
113void
114finish_if_stmt_cond (cond, if_stmt)
115 tree cond;
116 tree if_stmt;
117{
118 if (processing_template_decl)
119 {
120 if (last_tree != if_stmt)
121 RECHAIN_STMTS_FROM_LAST (if_stmt, IF_COND (if_stmt));
122 else
ecfa9fcc 123 IF_COND (if_stmt) = copy_to_permanent (cond);
ad321293
MM
124 }
125 else
126 {
127 emit_line_note (input_filename, lineno);
128 expand_start_cond (condition_conversion (cond), 0);
129 }
130}
131
132/* Finish the then-clause of an if-statement, which may be given by
133 IF_STMT. */
134
135tree
136finish_then_clause (if_stmt)
137 tree if_stmt;
138{
139 if (processing_template_decl)
140 {
141 RECHAIN_STMTS_FROM_CHAIN (if_stmt,
142 THEN_CLAUSE (if_stmt));
143 last_tree = if_stmt;
144 return if_stmt;
145 }
146 else
147 return NULL_TREE;
148}
149
150/* Begin the else-clause of an if-statement. */
151
152void
153begin_else_clause ()
154{
155 if (!processing_template_decl)
156 expand_start_else ();
157}
158
159/* Finish the else-clause of an if-statement, which may be given by
160 IF_STMT. */
161
162void
163finish_else_clause (if_stmt)
164 tree if_stmt;
165{
166 if (processing_template_decl)
167 RECHAIN_STMTS_FROM_CHAIN (if_stmt, ELSE_CLAUSE (if_stmt));
168}
169
170/* Finsh an if-statement. */
171
172void
173finish_if_stmt ()
174{
175 if (!processing_template_decl)
176 expand_end_cond ();
177
178 do_poplevel ();
179 finish_stmt ();
180}
181
182/* Begin a while-statement. Returns a newly created WHILE_STMT if
183 appropriate. */
184
185tree
186begin_while_stmt ()
187{
188 tree r;
189
190 if (processing_template_decl)
191 {
192 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
193 add_tree (r);
194 }
195 else
196 {
197 emit_nop ();
198 emit_line_note (input_filename, lineno);
199 expand_start_loop (1);
200 r = NULL_TREE;
201 }
202
203 do_pushlevel ();
204
205 return r;
206}
207
208/* Process the COND of an if-statement, which may be given by
209 WHILE_STMT. */
210
211void
212finish_while_stmt_cond (cond, while_stmt)
213 tree cond;
214 tree while_stmt;
215{
216 if (processing_template_decl)
217 {
218 if (last_tree != while_stmt)
219 RECHAIN_STMTS_FROM_LAST (while_stmt,
220 WHILE_COND (while_stmt));
221 else
ecfa9fcc 222 TREE_OPERAND (while_stmt, 0) = copy_to_permanent (cond);
ad321293
MM
223 }
224 else
225 {
226 emit_line_note (input_filename, lineno);
227 expand_exit_loop_if_false (0, condition_conversion (cond));
228 }
229
230 /* If COND wasn't a declaration, clear out the
231 block we made for it and start a new one here so the
232 optimization in expand_end_loop will work. */
233 if (getdecls () == NULL_TREE)
234 {
235 do_poplevel ();
236 do_pushlevel ();
237 }
238}
239
240/* Finish a while-statement, which may be given by WHILE_STMT. */
241
242void
243finish_while_stmt (while_stmt)
244 tree while_stmt;
245{
246 do_poplevel ();
247
248 if (processing_template_decl)
249 RECHAIN_STMTS_FROM_CHAIN (while_stmt, WHILE_BODY (while_stmt));
250 else
251 expand_end_loop ();
252 finish_stmt ();
253}
254
255/* Begin a do-statement. Returns a newly created DO_STMT if
256 appropriate. */
257
258tree
259begin_do_stmt ()
260{
261 if (processing_template_decl)
262 {
263 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
264 add_tree (r);
265 return r;
266 }
267 else
268 {
269 emit_nop ();
270 emit_line_note (input_filename, lineno);
271 expand_start_loop_continue_elsewhere (1);
272 return NULL_TREE;
273 }
274}
275
276/* Finish the body of a do-statement, which may be given by DO_STMT. */
277
278void
279finish_do_body (do_stmt)
280 tree do_stmt;
281{
282 if (processing_template_decl)
283 RECHAIN_STMTS_FROM_CHAIN (do_stmt, DO_BODY (do_stmt));
284 else
285 expand_loop_continue_here ();
286}
287
288/* Finish a do-statement, which may be given by DO_STMT, and whose
289 COND is as indicated. */
290
291void
292finish_do_stmt (cond, do_stmt)
293 tree cond;
294 tree do_stmt;
295{
296 if (processing_template_decl)
ecfa9fcc 297 DO_COND (do_stmt) = copy_to_permanent (cond);
ad321293
MM
298 else
299 {
300 emit_line_note (input_filename, lineno);
301 expand_exit_loop_if_false (0, condition_conversion (cond));
302 expand_end_loop ();
303 }
304
305 clear_momentary ();
306 finish_stmt ();
307}
308
309/* Finish a return-statement. The EXPRESSION returned, if any, is as
310 indicated. */
311
312void
313finish_return_stmt (expr)
314 tree expr;
315{
316 emit_line_note (input_filename, lineno);
317 c_expand_return (expr);
318 finish_stmt ();
319}
320
321/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
322
323tree
324begin_for_stmt ()
325{
326 tree r;
327
328 if (processing_template_decl)
329 {
330 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
331 NULL_TREE, NULL_TREE);
332 add_tree (r);
333 }
334 else
335 r = NULL_TREE;
336
337 if (flag_new_for_scope > 0)
338 {
339 do_pushlevel ();
340 note_level_for_for ();
341 }
342
343 return r;
344}
345
346/* Finish the for-init-statement of a for-statement, which may be
347 given by FOR_STMT. */
348
349void
350finish_for_init_stmt (for_stmt)
351 tree for_stmt;
352{
353 if (processing_template_decl)
354 {
355 if (last_tree != for_stmt)
356 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_INIT_STMT (for_stmt));
357 }
358 else
359 {
360 emit_nop ();
361 emit_line_note (input_filename, lineno);
362 expand_start_loop_continue_elsewhere (1);
363 }
364
365 do_pushlevel ();
366}
367
368/* Finish the COND of a for-statement, which may be given by
369 FOR_STMT. */
370
371void
372finish_for_cond (cond, for_stmt)
373 tree cond;
374 tree for_stmt;
375{
376 if (processing_template_decl)
377 {
378 if (last_tree != for_stmt)
379 RECHAIN_STMTS_FROM_LAST (for_stmt, FOR_COND (for_stmt));
380 else
ecfa9fcc 381 FOR_COND (for_stmt) = copy_to_permanent (cond);
ad321293
MM
382 }
383 else
384 {
385 emit_line_note (input_filename, lineno);
1dcf683e
MM
386 if (cond)
387 expand_exit_loop_if_false (0, condition_conversion (cond));
ad321293
MM
388 }
389
390 /* If the cond wasn't a declaration, clear out the
391 block we made for it and start a new one here so the
392 optimization in expand_end_loop will work. */
393 if (getdecls () == NULL_TREE)
394 {
395 do_poplevel ();
396 do_pushlevel ();
397 }
398}
399
400/* Finish the increment-EXPRESSION in a for-statement, which may be
401 given by FOR_STMT. */
402
403void
404finish_for_expr (expr, for_stmt)
405 tree expr;
406 tree for_stmt;
407{
408 if (processing_template_decl)
409 FOR_EXPR (for_stmt) = expr;
410
411 /* Don't let the tree nodes for EXPR be discarded
412 by clear_momentary during the parsing of the next stmt. */
413 push_momentary ();
414}
415
416/* Finish the body of a for-statement, which may be given by
417 FOR_STMT. The increment-EXPR for the loop must be
418 provided. */
419
420void
421finish_for_stmt (expr, for_stmt)
422 tree expr;
423 tree for_stmt;
424{
425 /* Pop the scope for the body of the loop. */
426 do_poplevel ();
427
428 if (processing_template_decl)
429 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_BODY (for_stmt));
430 else
431 {
432 emit_line_note (input_filename, lineno);
433 expand_loop_continue_here ();
434 if (expr)
435 cplus_expand_expr_stmt (expr);
436 expand_end_loop ();
437 }
438
439 pop_momentary ();
440
441 if (flag_new_for_scope > 0)
442 do_poplevel ();
443
444 finish_stmt ();
445}
446
447/* Finish a break-statement. */
448
449void
450finish_break_stmt ()
451{
452 emit_line_note (input_filename, lineno);
453 if (processing_template_decl)
454 add_tree (build_min_nt (BREAK_STMT));
455 else if ( ! expand_exit_something ())
8251199e 456 cp_error ("break statement not within loop or switch");
ad321293
MM
457}
458
459/* Finish a continue-statement. */
460
461void
462finish_continue_stmt ()
463{
464 emit_line_note (input_filename, lineno);
465 if (processing_template_decl)
466 add_tree (build_min_nt (CONTINUE_STMT));
467 else if (! expand_continue_loop (0))
8251199e 468 cp_error ("continue statement not within a loop");
ad321293
MM
469}
470
471/* Begin a switch-statement. */
472
473void
474begin_switch_stmt ()
475{
476 do_pushlevel ();
477}
478
479/* Finish the cond of a switch-statement. Returns a new
480 SWITCH_STMT if appropriate. */
481
482tree
483finish_switch_cond (cond)
484 tree cond;
485{
486 tree r;
487
488 if (processing_template_decl)
489 {
490 r = build_min_nt (SWITCH_STMT, cond, NULL_TREE);
491 add_tree (r);
492 }
0db982be 493 else if (cond != error_mark_node)
ad321293
MM
494 {
495 emit_line_note (input_filename, lineno);
496 c_expand_start_case (cond);
497 r = NULL_TREE;
498 }
0db982be
ML
499 else
500 {
501 /* The code is in error, but we don't want expand_end_case to
502 crash. */
503 c_expand_start_case (boolean_false_node);
504 r = NULL_TREE;
505 }
506
ad321293
MM
507 push_switch ();
508
509 /* Don't let the tree nodes for COND be discarded by
510 clear_momentary during the parsing of the next stmt. */
511 push_momentary ();
512
513 return r;
514}
515
516/* Finish the body of a switch-statement, which may be given by
517 SWITCH_STMT. The COND to switch on is indicated. */
518
519void
520finish_switch_stmt (cond, switch_stmt)
521 tree cond;
522 tree switch_stmt;
523{
524 if (processing_template_decl)
525 RECHAIN_STMTS_FROM_CHAIN (switch_stmt, SWITCH_BODY (switch_stmt));
526 else
527 expand_end_case (cond);
528 pop_momentary ();
529 pop_switch ();
530 do_poplevel ();
531 finish_stmt ();
532}
533
534/* Finish a case-label. */
535
536void
537finish_case_label (low_value, high_value)
538 tree low_value;
539 tree high_value;
540{
541 do_case (low_value, high_value);
542}
543
544
545/* Finish a goto-statement. */
546
547void
548finish_goto_stmt (destination)
549 tree destination;
550{
551 if (processing_template_decl)
552 add_tree (build_min_nt (GOTO_STMT, destination));
553 else
554 {
555 emit_line_note (input_filename, lineno);
556
557 if (TREE_CODE (destination) == IDENTIFIER_NODE)
558 {
559 tree decl = lookup_label (destination);
560 TREE_USED (decl) = 1;
561 expand_goto (decl);
562 }
563 else
564 expand_computed_goto (destination);
565 }
566}
567
568/* Begin a try-block. Returns a newly-created TRY_BLOCK if
569 appropriate. */
570
571tree
572begin_try_block ()
573{
574 if (processing_template_decl)
575 {
576 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
577 NULL_TREE);
578 add_tree (r);
579 return r;
580 }
581 else
582 {
583 emit_line_note (input_filename, lineno);
584 expand_start_try_stmts ();
585 return NULL_TREE;
586 }
587}
588
0dde4175
JM
589/* Likewise, for a function-try-block. */
590
591tree
592begin_function_try_block ()
593{
594 if (processing_template_decl)
595 {
596 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
597 NULL_TREE);
598 add_tree (r);
599 return r;
600 }
601 else
602 {
603 if (! current_function_parms_stored)
604 store_parm_decls ();
605 expand_start_early_try_stmts ();
606 return NULL_TREE;
607 }
608}
609
ad321293
MM
610/* Finish a try-block, which may be given by TRY_BLOCK. */
611
612void
613finish_try_block (try_block)
614 tree try_block;
615{
616 if (processing_template_decl)
617 RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block));
618 else
9a0d1e1b
AM
619 {
620 expand_start_all_catch ();
9a0d1e1b 621 }
ad321293
MM
622}
623
0dde4175
JM
624/* Likewise, for a function-try-block. */
625
626void
627finish_function_try_block (try_block)
628 tree try_block;
629{
630 if (processing_template_decl)
631 RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block));
632 else
633 {
634 end_protect_partials ();
635 expand_start_all_catch ();
636 in_function_try_handler = 1;
637 }
638}
639
ad321293
MM
640/* Finish a handler-sequence for a try-block, which may be given by
641 TRY_BLOCK. */
642
643void
644finish_handler_sequence (try_block)
645 tree try_block;
646{
647 if (processing_template_decl)
648 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
649 else
9a0d1e1b 650 {
9a0d1e1b
AM
651 expand_end_all_catch ();
652 }
ad321293
MM
653}
654
0dde4175
JM
655/* Likewise, for a function-try-block. */
656
657void
658finish_function_handler_sequence (try_block)
659 tree try_block;
660{
661 if (processing_template_decl)
662 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
663 else
664 {
665 in_function_try_handler = 0;
666 expand_end_all_catch ();
667 }
668}
669
ad321293
MM
670/* Begin a handler. Returns a HANDLER if appropriate. */
671
672tree
673begin_handler ()
674{
675 tree r;
676
677 if (processing_template_decl)
678 {
679 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
680 add_tree (r);
681 }
682 else
683 r = NULL_TREE;
684
685 do_pushlevel ();
686
687 return r;
688}
689
690/* Finish the handler-parameters for a handler, which may be given by
691 HANDLER. */
692
693void
694finish_handler_parms (handler)
695 tree handler;
696{
697 if (processing_template_decl)
698 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_PARMS (handler));
699}
700
701/* Finish a handler, which may be given by HANDLER. */
702
703void
704finish_handler (handler)
705 tree handler;
706{
707 if (processing_template_decl)
708 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_BODY (handler));
709 else
710 expand_end_catch_block ();
711
712 do_poplevel ();
713}
714
715/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
716 compound-statement does not define a scope. Returns a new
717 COMPOUND_STMT if appropriate. */
718
719tree
720begin_compound_stmt (has_no_scope)
721 int has_no_scope;
722{
723 tree r;
724
725 if (processing_template_decl)
726 {
727 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
728 add_tree (r);
729 if (has_no_scope)
730 COMPOUND_STMT_NO_SCOPE (r) = 1;
731 }
732 else
733 r = NULL_TREE;
734
735 if (!has_no_scope)
736 do_pushlevel ();
737
738 return r;
739}
740
741
742/* Finish a compound-statement, which may be given by COMPOUND_STMT.
743 If HAS_NO_SCOPE is non-zero, the compound statement does not define
744 a scope. */
745
746tree
747finish_compound_stmt (has_no_scope, compound_stmt)
748 int has_no_scope;
749 tree compound_stmt;
750{
751 tree r;
752
753 if (!has_no_scope)
754 r = do_poplevel ();
755 else
756 r = NULL_TREE;
757
758 if (processing_template_decl)
759 RECHAIN_STMTS_FROM_CHAIN (compound_stmt,
760 COMPOUND_BODY (compound_stmt));
761
762 finish_stmt ();
763
764 return r;
765}
766
767/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
768 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
769 CLOBBERS. */
770
771void
772finish_asm_stmt (cv_qualifier, string, output_operands,
3ebc5c52 773 input_operands, clobbers)
ad321293
MM
774 tree cv_qualifier;
775 tree string;
776 tree output_operands;
777 tree input_operands;
778 tree clobbers;
779{
780 if (TREE_CHAIN (string))
3ebc5c52
MM
781 {
782 if (processing_template_decl)
783 {
784 /* We need to build the combined string on the permanent
785 obstack so that we can use it during instantiations. */
786 push_obstacks_nochange ();
787 end_temporary_allocation ();
788 }
789
790 string = combine_strings (string);
791
792 if (processing_template_decl)
793 pop_obstacks ();
794 }
ad321293 795
f71f87f9
MM
796 if (cv_qualifier != NULL_TREE
797 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
798 {
799 cp_warning ("%s qualifier ignored on asm",
800 IDENTIFIER_POINTER (cv_qualifier));
801 cv_qualifier = NULL_TREE;
802 }
803
ad321293
MM
804 if (processing_template_decl)
805 {
806 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
807 output_operands, input_operands,
808 clobbers);
809 add_tree (r);
810 }
811 else
812 {
813 emit_line_note (input_filename, lineno);
6e9438cf
AG
814 if (output_operands != NULL_TREE || input_operands != NULL_TREE
815 || clobbers != NULL_TREE)
816 {
7dc5bd62
MM
817 tree t;
818
7dc5bd62
MM
819 for (t = input_operands; t; t = TREE_CHAIN (t))
820 TREE_VALUE (t) = decay_conversion (TREE_VALUE (t));
821
6e9438cf
AG
822 c_expand_asm_operands (string, output_operands,
823 input_operands,
824 clobbers,
f71f87f9 825 cv_qualifier != NULL_TREE,
6e9438cf
AG
826 input_filename, lineno);
827 }
828 else
f71f87f9 829 expand_asm (string);
a64c757e 830
ad321293
MM
831 finish_stmt ();
832 }
833}
b4c4a9ec 834
f01b0acb
MM
835/* Finish a label with the indicated NAME. */
836
837void
838finish_label_stmt (name)
839 tree name;
840{
841 tree decl;
842
843 if (processing_template_decl)
844 {
845 push_obstacks_nochange ();
846 end_temporary_allocation ();
847 decl = build_decl (LABEL_DECL, name, void_type_node);
848 pop_obstacks ();
849 DECL_SOURCE_LINE (decl) = lineno;
850 DECL_SOURCE_FILE (decl) = input_filename;
851 add_tree (decl);
852 }
853 else
854 {
855 decl = define_label (input_filename, lineno, name);
856 if (decl)
857 expand_label (decl);
858 }
859}
860
b4c4a9ec
MM
861/* Finish a parenthesized expression EXPR. */
862
863tree
864finish_parenthesized_expr (expr)
865 tree expr;
866{
867 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
868 /* This inhibits warnings in truthvalue_conversion. */
869 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
870
871 return expr;
872}
873
b69b1501
MM
874/* Begin a statement-expression. The value returned must be passed to
875 finish_stmt_expr. */
b4c4a9ec
MM
876
877tree
878begin_stmt_expr ()
879{
880 keep_next_level ();
b69b1501
MM
881 /* If we're processing_template_decl, then the upcoming compound
882 statement will be chained onto the tree structure, starting at
883 last_tree. We return last_tree so that we can later unhook the
884 compound statement. */
885 return processing_template_decl ? last_tree : expand_start_stmt_expr();
b4c4a9ec
MM
886}
887
888/* Finish a statement-expression. RTL_EXPR should be the value
889 returned by the previous begin_stmt_expr; EXPR is the
890 statement-expression. Returns an expression representing the
891 statement-expression. */
892
893tree
894finish_stmt_expr (rtl_expr, expr)
895 tree rtl_expr;
896 tree expr;
897{
898 tree result;
899
900 if (!processing_template_decl)
901 {
902 rtl_expr = expand_end_stmt_expr (rtl_expr);
903 /* The statements have side effects, so the group does. */
904 TREE_SIDE_EFFECTS (rtl_expr) = 1;
905 }
906
907 if (TREE_CODE (expr) == BLOCK)
908 {
909 /* Make a BIND_EXPR for the BLOCK already made. */
910 if (processing_template_decl)
61cd552e
MM
911 result = build_min_nt (BIND_EXPR, NULL_TREE, last_tree,
912 NULL_TREE);
b4c4a9ec
MM
913 else
914 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
915 NULL_TREE, rtl_expr, expr);
916
917 /* Remove the block from the tree at this point.
918 It gets put back at the proper place
919 when the BIND_EXPR is expanded. */
920 delete_block (expr);
921 }
922 else
923 result = expr;
b69b1501
MM
924
925 if (processing_template_decl)
926 {
927 /* Remove the compound statement from the tree structure; it is
928 now saved in the BIND_EXPR. */
929 last_tree = rtl_expr;
930 TREE_CHAIN (last_tree) = NULL_TREE;
931 }
b4c4a9ec
MM
932
933 return result;
934}
935
936/* Finish a call to FN with ARGS. Returns a representation of the
937 call. */
938
939tree
a759e627 940finish_call_expr (fn, args, koenig)
b4c4a9ec
MM
941 tree fn;
942 tree args;
a759e627 943 int koenig;
b4c4a9ec 944{
a759e627
ML
945 tree result;
946
947 if (koenig)
03d82991
JM
948 {
949 if (TREE_CODE (fn) == BIT_NOT_EXPR)
950 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
951 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
e13a4123 952 fn = do_identifier (fn, 2, args);
03d82991 953 }
a759e627 954 result = build_x_function_call (fn, args, current_class_ref);
b4c4a9ec
MM
955
956 if (TREE_CODE (result) == CALL_EXPR
66543169
NS
957 && (! TREE_TYPE (result)
958 || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE))
b4c4a9ec
MM
959 result = require_complete_type (result);
960
961 return result;
962}
963
964/* Finish a call to a postfix increment or decrement or EXPR. (Which
965 is indicated by CODE, which should be POSTINCREMENT_EXPR or
966 POSTDECREMENT_EXPR.) */
967
968tree
969finish_increment_expr (expr, code)
970 tree expr;
971 enum tree_code code;
972{
973 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
974 a COMPONENT_REF). This way if we've got, say, a reference to a
975 static member that's being operated on, we don't end up trying to
976 find a member operator for the class it's in. */
977
978 if (TREE_CODE (expr) == OFFSET_REF)
979 expr = resolve_offset_ref (expr);
980 return build_x_unary_op (code, expr);
981}
982
983/* Finish a use of `this'. Returns an expression for `this'. */
984
985tree
986finish_this_expr ()
987{
988 tree result;
989
990 if (current_class_ptr)
991 {
992#ifdef WARNING_ABOUT_CCD
993 TREE_USED (current_class_ptr) = 1;
994#endif
995 result = current_class_ptr;
996 }
997 else if (current_function_decl
998 && DECL_STATIC_FUNCTION_P (current_function_decl))
999 {
8251199e 1000 error ("`this' is unavailable for static member functions");
b4c4a9ec
MM
1001 result = error_mark_node;
1002 }
1003 else
1004 {
1005 if (current_function_decl)
8251199e 1006 error ("invalid use of `this' in non-member function");
b4c4a9ec 1007 else
8251199e 1008 error ("invalid use of `this' at top level");
b4c4a9ec
MM
1009 result = error_mark_node;
1010 }
1011
1012 return result;
1013}
1014
1015/* Finish a member function call using OBJECT and ARGS as arguments to
1016 FN. Returns an expression for the call. */
1017
1018tree
1019finish_object_call_expr (fn, object, args)
1020 tree fn;
1021 tree object;
1022 tree args;
1023{
1024#if 0
1025 /* This is a future direction of this code, but because
1026 build_x_function_call cannot always undo what is done in
1027 build_component_ref entirely yet, we cannot do this. */
1028
1029 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
1030 return finish_call_expr (real_fn, args);
1031#else
c68c56f7
MM
1032 if (TREE_CODE (fn) == TYPE_DECL)
1033 {
1034 if (processing_template_decl)
1035 /* This can happen on code like:
1036
1037 class X;
1038 template <class T> void f(T t) {
1039 t.X();
1040 }
1041
1042 We just grab the underlying IDENTIFIER. */
1043 fn = DECL_NAME (fn);
1044 else
1045 {
8251199e 1046 cp_error ("calling type `%T' like a method", fn);
c68c56f7
MM
1047 return error_mark_node;
1048 }
1049 }
1050
b4c4a9ec
MM
1051 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
1052#endif
1053}
1054
1055/* Finish a qualified member function call using OBJECT and ARGS as
1056 arguments to FN. Returns an expressino for the call. */
1057
1058tree
1059finish_qualified_object_call_expr (fn, object, args)
1060 tree fn;
1061 tree object;
1062 tree args;
1063{
6eabb241
MM
1064 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
1065 TREE_OPERAND (fn, 1), args);
b4c4a9ec
MM
1066}
1067
1068/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
1069 being the scope, if any, of DESTRUCTOR. Returns an expression for
1070 the call. */
1071
1072tree
1073finish_pseudo_destructor_call_expr (object, scope, destructor)
1074 tree object;
1075 tree scope;
1076 tree destructor;
1077{
1078 if (scope && scope != destructor)
8251199e 1079 cp_error ("destructor specifier `%T::~%T()' must have matching names",
b4c4a9ec
MM
1080 scope, destructor);
1081
1082 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
1083 && (TREE_CODE (TREE_TYPE (object)) !=
1084 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
8251199e 1085 cp_error ("`%E' is not of type `%T'", object, destructor);
b4c4a9ec
MM
1086
1087 return cp_convert (void_type_node, object);
1088}
1089
1090/* Finish a call to a globally qualified member function FN using
1091 ARGS. Returns an expression for the call. */
1092
1093tree
75d587eb 1094finish_qualified_call_expr (fn, args)
b4c4a9ec
MM
1095 tree fn;
1096 tree args;
1097{
1098 if (processing_template_decl)
1099 return build_min_nt (CALL_EXPR, copy_to_permanent (fn), args,
1100 NULL_TREE);
1101 else
1102 return build_member_call (TREE_OPERAND (fn, 0),
1103 TREE_OPERAND (fn, 1),
1104 args);
1105}
1106
1107/* Finish an expression taking the address of LABEL. Returns an
1108 expression for the address. */
1109
1110tree
1111finish_label_address_expr (label)
1112 tree label;
1113{
1114 tree result;
1115
1116 label = lookup_label (label);
1117 if (label == NULL_TREE)
1118 result = null_pointer_node;
1119 else
1120 {
1121 TREE_USED (label) = 1;
1122 result = build1 (ADDR_EXPR, ptr_type_node, label);
1123 TREE_CONSTANT (result) = 1;
1124 }
1125
1126 return result;
1127}
1128
ce4a0391
MM
1129/* Finish an expression of the form CODE EXPR. */
1130
1131tree
1132finish_unary_op_expr (code, expr)
1133 enum tree_code code;
1134 tree expr;
1135{
1136 tree result = build_x_unary_op (code, expr);
1137 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1138 TREE_NEGATED_INT (result) = 1;
1139 overflow_warning (result);
1140 return result;
1141}
1142
1143/* Finish an id-expression. */
1144
1145tree
1146finish_id_expr (expr)
1147 tree expr;
1148{
1149 if (TREE_CODE (expr) == IDENTIFIER_NODE)
a759e627 1150 expr = do_identifier (expr, 1, NULL_TREE);
ce4a0391
MM
1151
1152 return expr;
1153}
1154
1155/* Begin a new-placement. */
1156
1157int
1158begin_new_placement ()
1159{
1160 /* The arguments to a placement new might be passed to a
1161 deallocation function, in the event that the allocation throws an
1162 exception. Since we don't expand exception handlers until the
1163 end of a function, we must make sure the arguments stay around
1164 that long. */
1165 return suspend_momentary ();
1166}
1167
1168/* Finish a new-placement. The ARGS are the placement arguments. The
1169 COOKIE is the value returned by the previous call to
1170 begin_new_placement. */
1171
1172tree
1173finish_new_placement (args, cookie)
1174 tree args;
1175 int cookie;
1176{
1177 resume_momentary (cookie);
1178 return args;
1179}
1180
b4c4a9ec
MM
1181/* Begin a function defniition declared with DECL_SPECS and
1182 DECLARATOR. Returns non-zero if the function-declaration is
1183 legal. */
1184
1185int
1186begin_function_definition (decl_specs, declarator)
1187 tree decl_specs;
1188 tree declarator;
1189{
1190 tree specs;
1191 tree attrs;
1192 split_specs_attrs (decl_specs, &specs, &attrs);
1193 if (!start_function (specs, declarator, attrs, 0))
1194 return 0;
1195
1196 reinit_parse_for_function ();
39c01e4c
MM
1197 /* The things we're about to see are not directly qualified by any
1198 template headers we've seen thus far. */
1199 reset_specialization ();
1200
b4c4a9ec
MM
1201 return 1;
1202}
1203
1204/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1205 a SCOPE_REF. */
1206
1207tree
1208begin_constructor_declarator (scope, name)
1209 tree scope;
1210 tree name;
1211{
1212 tree result = build_parse_node (SCOPE_REF, scope, name);
830fcda8 1213 enter_scope_of (result);
b4c4a9ec
MM
1214 return result;
1215}
1216
ce4a0391
MM
1217/* Finish an init-declarator. Returns a DECL. */
1218
1219tree
1220finish_declarator (declarator, declspecs, attributes,
1221 prefix_attributes, initialized)
1222 tree declarator;
1223 tree declspecs;
1224 tree attributes;
1225 tree prefix_attributes;
1226 int initialized;
1227{
1228 return start_decl (declarator, declspecs, initialized, attributes,
1229 prefix_attributes);
1230}
1231
8014a339 1232/* Finish a translation unit. */
ce4a0391
MM
1233
1234void
1235finish_translation_unit ()
1236{
1237 /* In case there were missing closebraces,
1238 get us back to the global binding level. */
1239 while (! toplevel_bindings_p ())
1240 poplevel (0, 0, 0);
1241 while (current_namespace != global_namespace)
1242 pop_namespace ();
1243 finish_file ();
1244}
1245
b4c4a9ec
MM
1246/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1247 Returns the parameter. */
1248
1249tree
1250finish_template_type_parm (aggr, identifier)
1251 tree aggr;
1252 tree identifier;
1253{
6eabb241 1254 if (aggr != class_type_node)
b4c4a9ec 1255 {
8251199e 1256 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1257 aggr = class_type_node;
1258 }
1259
1260 return build_tree_list (aggr, identifier);
1261}
1262
1263/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1264 Returns the parameter. */
1265
1266tree
1267finish_template_template_parm (aggr, identifier)
1268 tree aggr;
1269 tree identifier;
1270{
1271 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1272 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1273 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1274 DECL_TEMPLATE_RESULT (tmpl) = decl;
1275 SET_DECL_ARTIFICIAL (decl);
1276 end_template_decl ();
1277
1278 return finish_template_type_parm (aggr, tmpl);
1279}
ce4a0391
MM
1280
1281/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1282 non-zero, the parameter list was terminated by a `...'. */
1283
1284tree
1285finish_parmlist (parms, ellipsis)
1286 tree parms;
1287 int ellipsis;
1288{
1289 if (!ellipsis)
1290 chainon (parms, void_list_node);
1291 /* We mark the PARMS as a parmlist so that declarator processing can
1292 disambiguate certain constructs. */
1293 if (parms != NULL_TREE)
1294 TREE_PARMLIST (parms) = 1;
1295
1296 return parms;
1297}
1298
1299/* Begin a class definition, as indicated by T. */
1300
1301tree
1302begin_class_definition (t)
1303 tree t;
1304{
ce4a0391
MM
1305 push_obstacks_nochange ();
1306 end_temporary_allocation ();
1307
1308 if (t == error_mark_node
1309 || ! IS_AGGR_TYPE (t))
1310 {
830fcda8 1311 t = make_lang_type (RECORD_TYPE);
ce4a0391
MM
1312 pushtag (make_anon_name (), t, 0);
1313 }
830fcda8
JM
1314
1315 /* In a definition of a member class template, we will get here with an
1316 implicit typename, a TYPENAME_TYPE with a type. */
1317 if (TREE_CODE (t) == TYPENAME_TYPE)
1318 t = TREE_TYPE (t);
4c571114
MM
1319
1320 /* If we generated a partial instantiation of this type, but now
1321 we're seeing a real definition, we're actually looking at a
1322 partial specialization. Consider:
1323
1324 template <class T, class U>
1325 struct Y {};
1326
1327 template <class T>
1328 struct X {};
1329
1330 template <class T, class U>
1331 void f()
1332 {
1333 typename X<Y<T, U> >::A a;
1334 }
1335
1336 template <class T, class U>
1337 struct X<Y<T, U> >
1338 {
1339 };
1340
1341 We have to undo the effects of the previous partial
1342 instantiation. */
1343 if (PARTIAL_INSTANTIATION_P (t))
1344 {
1345 if (!pedantic)
1346 {
1347 /* Unfortunately, when we're not in pedantic mode, we
1348 attempt to actually fill in some of the fields of the
1349 partial instantiation, in order to support the implicit
1350 typename extension. Clear those fields now, in
1351 preparation for the definition here. The fields cleared
1352 here must match those set in instantiate_class_template.
1353 Look for a comment mentioning begin_class_definition
1354 there. */
1355 TYPE_BINFO_BASETYPES (t) = NULL_TREE;
1356 TYPE_FIELDS (t) = NULL_TREE;
1357 TYPE_METHODS (t) = NULL_TREE;
1358 CLASSTYPE_TAGS (t) = NULL_TREE;
1359 TYPE_SIZE (t) = NULL_TREE;
1360 }
830fcda8 1361
4c571114
MM
1362 /* This isn't a partial instantiation any more. */
1363 PARTIAL_INSTANTIATION_P (t) = 0;
1364 }
1365 /* If this type was already complete, and we see another definition,
1366 that's an error. */
1367 else if (TYPE_SIZE (t))
ce4a0391 1368 duplicate_tag_error (t);
4c571114 1369
b4f70b3d
NS
1370 /* Update the location of the decl. */
1371 DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename;
1372 DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno;
1373
4c571114 1374 if (TYPE_BEING_DEFINED (t))
ce4a0391
MM
1375 {
1376 t = make_lang_type (TREE_CODE (t));
1377 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 1378 }
ff350acd 1379 maybe_process_partial_specialization (t);
8f032717 1380 pushclass (t, 1);
ce4a0391 1381 TYPE_BEING_DEFINED (t) = 1;
ce4a0391
MM
1382 /* Reset the interface data, at the earliest possible
1383 moment, as it might have been set via a class foo;
1384 before. */
6eabb241
MM
1385 {
1386 tree name = TYPE_IDENTIFIER (t);
1387
1388 if (! ANON_AGGRNAME_P (name))
1389 {
1390 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1391 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1392 (t, interface_unknown);
1393 }
1394
1395 /* Only leave this bit clear if we know this
1396 class is part of an interface-only specification. */
1397 if (! CLASSTYPE_INTERFACE_KNOWN (t)
1398 || ! CLASSTYPE_INTERFACE_ONLY (t))
1399 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1;
1400 }
ce4a0391 1401#if 0
830fcda8
JM
1402 tmp = TYPE_IDENTIFIER ($<ttype>0);
1403 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1404 overload_template_name (tmp, 1);
ce4a0391
MM
1405#endif
1406 reset_specialization();
1407
1408 /* In case this is a local class within a template
1409 function, we save the current tree structure so
1410 that we can get it back later. */
1411 begin_tree ();
1412
b7975aed
MM
1413 /* Make a declaration for this class in its own scope. */
1414 build_self_reference ();
1415
830fcda8 1416 return t;
ce4a0391
MM
1417}
1418
61a127b3
MM
1419/* Finish the member declaration given by DECL. */
1420
1421void
1422finish_member_declaration (decl)
1423 tree decl;
1424{
1425 if (decl == error_mark_node || decl == NULL_TREE)
1426 return;
1427
1428 if (decl == void_type_node)
1429 /* The COMPONENT was a friend, not a member, and so there's
1430 nothing for us to do. */
1431 return;
1432
1433 /* We should see only one DECL at a time. */
1434 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1435
1436 /* Set up access control for DECL. */
1437 TREE_PRIVATE (decl)
1438 = (current_access_specifier == access_private_node);
1439 TREE_PROTECTED (decl)
1440 = (current_access_specifier == access_protected_node);
1441 if (TREE_CODE (decl) == TEMPLATE_DECL)
1442 {
1443 TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl);
1444 TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl);
1445 }
1446
1447 /* Mark the DECL as a member of the current class. */
1448 if (TREE_CODE (decl) == FUNCTION_DECL
1449 || DECL_FUNCTION_TEMPLATE_P (decl))
1450 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1451 finish_struct. Presumably it is already set as the function is
1452 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1453 DECL_CLASS_CONTEXT (decl) = current_class_type;
61a127b3
MM
1454 else
1455 DECL_CONTEXT (decl) = current_class_type;
1456
1457 /* Put functions on the TYPE_METHODS list and everything else on the
1458 TYPE_FIELDS list. Note that these are built up in reverse order.
1459 We reverse them (to obtain declaration order) in finish_struct. */
1460 if (TREE_CODE (decl) == FUNCTION_DECL
1461 || DECL_FUNCTION_TEMPLATE_P (decl))
1462 {
1463 /* We also need to add this function to the
1464 CLASSTYPE_METHOD_VEC. */
1465 add_method (current_class_type, 0, decl);
1466
1467 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1468 TYPE_METHODS (current_class_type) = decl;
1469 }
1470 else
1471 {
1472 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1473 go at the beginning. The reason is that lookup_field_1
1474 searches the list in order, and we want a field name to
1475 override a type name so that the "struct stat hack" will
1476 work. In particular:
1477
1478 struct S { enum E { }; int E } s;
1479 s.E = 3;
1480
1481 is legal. In addition, the FIELD_DECLs must be maintained in
1482 declaration order so that class layout works as expected.
1483 However, we don't need that order until class layout, so we
1484 save a little time by putting FIELD_DECLs on in reverse order
1485 here, and then reversing them in finish_struct_1. (We could
1486 also keep a pointer to the correct insertion points in the
1487 list.) */
1488
1489 if (TREE_CODE (decl) == TYPE_DECL)
1490 TYPE_FIELDS (current_class_type)
1491 = chainon (TYPE_FIELDS (current_class_type), decl);
1492 else
1493 {
1494 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1495 TYPE_FIELDS (current_class_type) = decl;
1496 }
8f032717
MM
1497
1498 /* Enter the DECL into the scope of the class. */
1499 if (TREE_CODE (decl) != USING_DECL)
1500 pushdecl_class_level (decl);
61a127b3
MM
1501 }
1502}
1503
1504/* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1505 the definition is immediately followed by a semicolon. Returns the
1506 type. */
ce4a0391
MM
1507
1508tree
fbdd0024 1509finish_class_definition (t, attributes, semi, pop_scope_p)
ce4a0391 1510 tree t;
ce4a0391
MM
1511 tree attributes;
1512 int semi;
fbdd0024 1513 int pop_scope_p;
ce4a0391 1514{
ce4a0391
MM
1515 /* finish_struct nukes this anyway; if finish_exception does too,
1516 then it can go. */
1517 if (semi)
1518 note_got_semicolon (t);
1519
dc8263bc
JM
1520 /* If we got any attributes in class_head, xref_tag will stick them in
1521 TREE_TYPE of the type. Grab them now. */
1522 attributes = chainon (TREE_TYPE (t), attributes);
1523 TREE_TYPE (t) = NULL_TREE;
1524
ce4a0391
MM
1525 if (TREE_CODE (t) == ENUMERAL_TYPE)
1526 ;
1527 else
1528 {
9f33663b 1529 t = finish_struct (t, attributes);
ce4a0391
MM
1530 if (semi)
1531 note_got_semicolon (t);
1532 }
1533
1534 pop_obstacks ();
1535
1536 if (! semi)
1537 check_for_missing_semicolon (t);
fbdd0024
MM
1538 if (pop_scope_p)
1539 pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t)));
ce4a0391
MM
1540 if (current_scope () == current_function_decl)
1541 do_pending_defargs ();
1542
1543 return t;
1544}
1545
1546/* Finish processing the default argument expressions cached during
1547 the processing of a class definition. */
1548
1549void
51632249 1550begin_inline_definitions ()
ce4a0391
MM
1551{
1552 if (pending_inlines
1553 && current_scope () == current_function_decl)
1554 do_pending_inlines ();
1555}
1556
1557/* Finish processing the inline function definitions cached during the
1558 processing of a class definition. */
1559
1560void
51632249 1561finish_inline_definitions ()
ce4a0391
MM
1562{
1563 if (current_class_type == NULL_TREE)
1564 clear_inline_text_obstack ();
1565
1566 /* Undo the begin_tree in begin_class_definition. */
1567 end_tree ();
1568}
35acd3f2
MM
1569
1570/* Finish processing the declaration of a member class template
1571 TYPES whose template parameters are given by PARMS. */
1572
1573tree
61a127b3 1574finish_member_class_template (types)
35acd3f2
MM
1575 tree types;
1576{
36a117a5
MM
1577 tree t;
1578
1579 /* If there are declared, but undefined, partial specializations
1580 mixed in with the typespecs they will not yet have passed through
1581 maybe_process_partial_specialization, so we do that here. */
1582 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1583 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1584 maybe_process_partial_specialization (TREE_VALUE (t));
1585
35acd3f2 1586 note_list_got_semicolon (types);
61a127b3 1587 grok_x_components (types);
35acd3f2
MM
1588 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1589 /* The component was in fact a friend declaration. We avoid
1590 finish_member_template_decl performing certain checks by
1591 unsetting TYPES. */
1592 types = NULL_TREE;
61a127b3
MM
1593
1594 finish_member_template_decl (types);
1595
35acd3f2
MM
1596 /* As with other component type declarations, we do
1597 not store the new DECL on the list of
1598 component_decls. */
1599 return NULL_TREE;
1600}
36a117a5
MM
1601
1602/* Finish processsing a complete template declaration. The PARMS are
1603 the template parameters. */
1604
1605void
1606finish_template_decl (parms)
1607 tree parms;
1608{
1609 if (parms)
1610 end_template_decl ();
1611 else
1612 end_specialization ();
1613}
1614
1615/* Finish processing a a template-id (which names a type) of the form
1616 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1617 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1618 the scope of template-id indicated. */
1619
1620tree
1621finish_template_type (name, args, entering_scope)
1622 tree name;
1623 tree args;
1624 int entering_scope;
1625{
1626 tree decl;
1627
1628 decl = lookup_template_class (name, args,
1629 NULL_TREE, NULL_TREE, entering_scope);
1630 if (decl != error_mark_node)
1631 decl = TYPE_STUB_DECL (decl);
1632
1633 return decl;
1634}
648f19f6
MM
1635
1636/* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1637 namespace scope or a class scope. */
1638
1639void
1640enter_scope_of (sr)
1641 tree sr;
1642{
1643 tree scope = TREE_OPERAND (sr, 0);
1644
1645 if (TREE_CODE (scope) == NAMESPACE_DECL)
1646 {
1647 push_decl_namespace (scope);
1648 TREE_COMPLEXITY (sr) = -1;
1649 }
1650 else if (scope != current_class_type)
1651 {
830fcda8
JM
1652 if (TREE_CODE (scope) == TYPENAME_TYPE)
1653 {
1654 /* In a declarator for a template class member, the scope will
1655 get here as an implicit typename, a TYPENAME_TYPE with a type. */
1656 scope = TREE_TYPE (scope);
1657 TREE_OPERAND (sr, 0) = scope;
1658 }
648f19f6
MM
1659 push_nested_class (scope, 3);
1660 TREE_COMPLEXITY (sr) = current_class_depth;
1661 }
1662}
ea6021e8
MM
1663
1664/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
1665 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
1666 BASE_CLASS, or NULL_TREE if an error occurred. The
1667 ACCESSS_SPECIFIER is one of
1668 access_{default,public,protected_private}[_virtual]_node.*/
1669
1670tree
6eabb241 1671finish_base_specifier (access_specifier, base_class)
ea6021e8
MM
1672 tree access_specifier;
1673 tree base_class;
ea6021e8
MM
1674{
1675 tree type;
1676 tree result;
1677
1678 if (base_class == NULL_TREE)
1679 {
8251199e 1680 error ("invalid base class");
ea6021e8
MM
1681 type = error_mark_node;
1682 }
1683 else
1684 type = TREE_TYPE (base_class);
6eabb241 1685
ea6021e8
MM
1686 if (! is_aggr_type (type, 1))
1687 result = NULL_TREE;
ea6021e8
MM
1688 else
1689 result = build_tree_list (access_specifier, type);
1690
1691 return result;
1692}
61a127b3
MM
1693
1694/* Called when multiple declarators are processed. If that is not
1695 premitted in this context, an error is issued. */
1696
1697void
1698check_multiple_declarators ()
1699{
1700 /* [temp]
1701
1702 In a template-declaration, explicit specialization, or explicit
1703 instantiation the init-declarator-list in the declaration shall
1704 contain at most one declarator.
1705
1706 We don't just use PROCESSING_TEMPLATE_DECL for the first
1707 condition since that would disallow the perfectly legal code,
1708 like `template <class T> struct S { int i, j; };'. */
1709 tree scope = current_scope ();
1710
1711 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
1712 /* It's OK to write `template <class T> void f() { int i, j;}'. */
1713 return;
1714
1715 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
1716 || processing_explicit_instantiation
1717 || processing_specialization)
1718 cp_error ("multiple declarators in template declaration");
1719}
1720
b894fc05
JM
1721tree
1722finish_typeof (expr)
1723 tree expr;
1724{
1725 if (processing_template_decl)
1726 {
1727 tree t;
1728
1729 push_obstacks_nochange ();
1730 end_temporary_allocation ();
1731
1732 t = make_lang_type (TYPEOF_TYPE);
b894fc05
JM
1733 TYPE_FIELDS (t) = expr;
1734
1735 pop_obstacks ();
1736
1737 return t;
1738 }
1739
1740 return TREE_TYPE (expr);
1741}
This page took 0.433186 seconds and 5 git commands to generate.