]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
combine.c (num_sign_bit_copies): In NEG...
[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
6 Copyright (C) 1998 Free Software Foundation, Inc.
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
123 IF_COND (if_stmt) = cond;
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
222 TREE_OPERAND (while_stmt, 0) = cond;
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)
297 DO_COND (do_stmt) = cond;
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
381 FOR_COND (for_stmt) = cond;
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 }
493 else
494 {
495 emit_line_note (input_filename, lineno);
496 c_expand_start_case (cond);
497 r = NULL_TREE;
498 }
499 push_switch ();
500
501 /* Don't let the tree nodes for COND be discarded by
502 clear_momentary during the parsing of the next stmt. */
503 push_momentary ();
504
505 return r;
506}
507
508/* Finish the body of a switch-statement, which may be given by
509 SWITCH_STMT. The COND to switch on is indicated. */
510
511void
512finish_switch_stmt (cond, switch_stmt)
513 tree cond;
514 tree switch_stmt;
515{
516 if (processing_template_decl)
517 RECHAIN_STMTS_FROM_CHAIN (switch_stmt, SWITCH_BODY (switch_stmt));
518 else
519 expand_end_case (cond);
520 pop_momentary ();
521 pop_switch ();
522 do_poplevel ();
523 finish_stmt ();
524}
525
526/* Finish a case-label. */
527
528void
529finish_case_label (low_value, high_value)
530 tree low_value;
531 tree high_value;
532{
533 do_case (low_value, high_value);
534}
535
536
537/* Finish a goto-statement. */
538
539void
540finish_goto_stmt (destination)
541 tree destination;
542{
543 if (processing_template_decl)
544 add_tree (build_min_nt (GOTO_STMT, destination));
545 else
546 {
547 emit_line_note (input_filename, lineno);
548
549 if (TREE_CODE (destination) == IDENTIFIER_NODE)
550 {
551 tree decl = lookup_label (destination);
552 TREE_USED (decl) = 1;
553 expand_goto (decl);
554 }
555 else
556 expand_computed_goto (destination);
557 }
558}
559
560/* Begin a try-block. Returns a newly-created TRY_BLOCK if
561 appropriate. */
562
563tree
564begin_try_block ()
565{
566 if (processing_template_decl)
567 {
568 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
569 NULL_TREE);
570 add_tree (r);
571 return r;
572 }
573 else
574 {
575 emit_line_note (input_filename, lineno);
576 expand_start_try_stmts ();
577 return NULL_TREE;
578 }
579}
580
581/* Finish a try-block, which may be given by TRY_BLOCK. */
582
583void
584finish_try_block (try_block)
585 tree try_block;
586{
587 if (processing_template_decl)
588 RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block));
589 else
9a0d1e1b
AM
590 {
591 expand_start_all_catch ();
9a0d1e1b 592 }
ad321293
MM
593}
594
595/* Finish a handler-sequence for a try-block, which may be given by
596 TRY_BLOCK. */
597
598void
599finish_handler_sequence (try_block)
600 tree try_block;
601{
602 if (processing_template_decl)
603 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
604 else
9a0d1e1b 605 {
9a0d1e1b
AM
606 expand_end_all_catch ();
607 }
ad321293
MM
608}
609
610/* Begin a handler. Returns a HANDLER if appropriate. */
611
612tree
613begin_handler ()
614{
615 tree r;
616
617 if (processing_template_decl)
618 {
619 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
620 add_tree (r);
621 }
622 else
623 r = NULL_TREE;
624
625 do_pushlevel ();
626
627 return r;
628}
629
630/* Finish the handler-parameters for a handler, which may be given by
631 HANDLER. */
632
633void
634finish_handler_parms (handler)
635 tree handler;
636{
637 if (processing_template_decl)
638 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_PARMS (handler));
639}
640
641/* Finish a handler, which may be given by HANDLER. */
642
643void
644finish_handler (handler)
645 tree handler;
646{
647 if (processing_template_decl)
648 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_BODY (handler));
649 else
650 expand_end_catch_block ();
651
652 do_poplevel ();
653}
654
655/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
656 compound-statement does not define a scope. Returns a new
657 COMPOUND_STMT if appropriate. */
658
659tree
660begin_compound_stmt (has_no_scope)
661 int has_no_scope;
662{
663 tree r;
664
665 if (processing_template_decl)
666 {
667 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
668 add_tree (r);
669 if (has_no_scope)
670 COMPOUND_STMT_NO_SCOPE (r) = 1;
671 }
672 else
673 r = NULL_TREE;
674
675 if (!has_no_scope)
676 do_pushlevel ();
677
678 return r;
679}
680
681
682/* Finish a compound-statement, which may be given by COMPOUND_STMT.
683 If HAS_NO_SCOPE is non-zero, the compound statement does not define
684 a scope. */
685
686tree
687finish_compound_stmt (has_no_scope, compound_stmt)
688 int has_no_scope;
689 tree compound_stmt;
690{
691 tree r;
692
693 if (!has_no_scope)
694 r = do_poplevel ();
695 else
696 r = NULL_TREE;
697
698 if (processing_template_decl)
699 RECHAIN_STMTS_FROM_CHAIN (compound_stmt,
700 COMPOUND_BODY (compound_stmt));
701
702 finish_stmt ();
703
704 return r;
705}
706
707/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
708 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
709 CLOBBERS. */
710
711void
712finish_asm_stmt (cv_qualifier, string, output_operands,
713 input_operands, clobbers)
714 tree cv_qualifier;
715 tree string;
716 tree output_operands;
717 tree input_operands;
718 tree clobbers;
719{
720 if (TREE_CHAIN (string))
e6f1275f 721 string = combine_strings (string);
ad321293
MM
722
723 if (processing_template_decl)
724 {
725 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
726 output_operands, input_operands,
727 clobbers);
728 add_tree (r);
729 }
730 else
731 {
732 emit_line_note (input_filename, lineno);
6e9438cf
AG
733 if (output_operands != NULL_TREE || input_operands != NULL_TREE
734 || clobbers != NULL_TREE)
735 {
736 if (cv_qualifier != NULL_TREE
737 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
738 cp_warning ("%s qualifier ignored on asm",
739 IDENTIFIER_POINTER (cv_qualifier));
740
741 c_expand_asm_operands (string, output_operands,
742 input_operands,
743 clobbers,
744 cv_qualifier
745 == ridpointers[(int) RID_VOLATILE],
746 input_filename, lineno);
747 }
748 else
749 {
750 if (cv_qualifier != NULL_TREE)
751 cp_warning ("%s qualifier ignored on asm",
752 IDENTIFIER_POINTER (cv_qualifier));
753 expand_asm (string);
754 }
a64c757e 755
ad321293
MM
756 finish_stmt ();
757 }
758}
b4c4a9ec
MM
759
760/* Finish a parenthesized expression EXPR. */
761
762tree
763finish_parenthesized_expr (expr)
764 tree expr;
765{
766 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
767 /* This inhibits warnings in truthvalue_conversion. */
768 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
769
770 return expr;
771}
772
b69b1501
MM
773/* Begin a statement-expression. The value returned must be passed to
774 finish_stmt_expr. */
b4c4a9ec
MM
775
776tree
777begin_stmt_expr ()
778{
779 keep_next_level ();
b69b1501
MM
780 /* If we're processing_template_decl, then the upcoming compound
781 statement will be chained onto the tree structure, starting at
782 last_tree. We return last_tree so that we can later unhook the
783 compound statement. */
784 return processing_template_decl ? last_tree : expand_start_stmt_expr();
b4c4a9ec
MM
785}
786
787/* Finish a statement-expression. RTL_EXPR should be the value
788 returned by the previous begin_stmt_expr; EXPR is the
789 statement-expression. Returns an expression representing the
790 statement-expression. */
791
792tree
793finish_stmt_expr (rtl_expr, expr)
794 tree rtl_expr;
795 tree expr;
796{
797 tree result;
798
799 if (!processing_template_decl)
800 {
801 rtl_expr = expand_end_stmt_expr (rtl_expr);
802 /* The statements have side effects, so the group does. */
803 TREE_SIDE_EFFECTS (rtl_expr) = 1;
804 }
805
806 if (TREE_CODE (expr) == BLOCK)
807 {
808 /* Make a BIND_EXPR for the BLOCK already made. */
809 if (processing_template_decl)
810 result = build (BIND_EXPR, NULL_TREE,
811 NULL_TREE, last_tree, expr);
812 else
813 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
814 NULL_TREE, rtl_expr, expr);
815
816 /* Remove the block from the tree at this point.
817 It gets put back at the proper place
818 when the BIND_EXPR is expanded. */
819 delete_block (expr);
820 }
821 else
822 result = expr;
b69b1501
MM
823
824 if (processing_template_decl)
825 {
826 /* Remove the compound statement from the tree structure; it is
827 now saved in the BIND_EXPR. */
828 last_tree = rtl_expr;
829 TREE_CHAIN (last_tree) = NULL_TREE;
830 }
b4c4a9ec
MM
831
832 return result;
833}
834
835/* Finish a call to FN with ARGS. Returns a representation of the
836 call. */
837
838tree
a759e627 839finish_call_expr (fn, args, koenig)
b4c4a9ec
MM
840 tree fn;
841 tree args;
a759e627 842 int koenig;
b4c4a9ec 843{
a759e627
ML
844 tree result;
845
846 if (koenig)
03d82991
JM
847 {
848 if (TREE_CODE (fn) == BIT_NOT_EXPR)
849 fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0));
850 else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR)
e13a4123 851 fn = do_identifier (fn, 2, args);
03d82991 852 }
a759e627 853 result = build_x_function_call (fn, args, current_class_ref);
b4c4a9ec
MM
854
855 if (TREE_CODE (result) == CALL_EXPR
856 && TREE_TYPE (result) != void_type_node)
857 result = require_complete_type (result);
858
859 return result;
860}
861
862/* Finish a call to a postfix increment or decrement or EXPR. (Which
863 is indicated by CODE, which should be POSTINCREMENT_EXPR or
864 POSTDECREMENT_EXPR.) */
865
866tree
867finish_increment_expr (expr, code)
868 tree expr;
869 enum tree_code code;
870{
871 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
872 a COMPONENT_REF). This way if we've got, say, a reference to a
873 static member that's being operated on, we don't end up trying to
874 find a member operator for the class it's in. */
875
876 if (TREE_CODE (expr) == OFFSET_REF)
877 expr = resolve_offset_ref (expr);
878 return build_x_unary_op (code, expr);
879}
880
881/* Finish a use of `this'. Returns an expression for `this'. */
882
883tree
884finish_this_expr ()
885{
886 tree result;
887
888 if (current_class_ptr)
889 {
890#ifdef WARNING_ABOUT_CCD
891 TREE_USED (current_class_ptr) = 1;
892#endif
893 result = current_class_ptr;
894 }
895 else if (current_function_decl
896 && DECL_STATIC_FUNCTION_P (current_function_decl))
897 {
8251199e 898 error ("`this' is unavailable for static member functions");
b4c4a9ec
MM
899 result = error_mark_node;
900 }
901 else
902 {
903 if (current_function_decl)
8251199e 904 error ("invalid use of `this' in non-member function");
b4c4a9ec 905 else
8251199e 906 error ("invalid use of `this' at top level");
b4c4a9ec
MM
907 result = error_mark_node;
908 }
909
910 return result;
911}
912
913/* Finish a member function call using OBJECT and ARGS as arguments to
914 FN. Returns an expression for the call. */
915
916tree
917finish_object_call_expr (fn, object, args)
918 tree fn;
919 tree object;
920 tree args;
921{
922#if 0
923 /* This is a future direction of this code, but because
924 build_x_function_call cannot always undo what is done in
925 build_component_ref entirely yet, we cannot do this. */
926
927 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
928 return finish_call_expr (real_fn, args);
929#else
c68c56f7
MM
930 if (TREE_CODE (fn) == TYPE_DECL)
931 {
932 if (processing_template_decl)
933 /* This can happen on code like:
934
935 class X;
936 template <class T> void f(T t) {
937 t.X();
938 }
939
940 We just grab the underlying IDENTIFIER. */
941 fn = DECL_NAME (fn);
942 else
943 {
8251199e 944 cp_error ("calling type `%T' like a method", fn);
c68c56f7
MM
945 return error_mark_node;
946 }
947 }
948
b4c4a9ec
MM
949 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
950#endif
951}
952
953/* Finish a qualified member function call using OBJECT and ARGS as
954 arguments to FN. Returns an expressino for the call. */
955
956tree
957finish_qualified_object_call_expr (fn, object, args)
958 tree fn;
959 tree object;
960 tree args;
961{
962 if (IS_SIGNATURE (TREE_OPERAND (fn, 0)))
963 {
8251199e 964 warning ("signature name in scope resolution ignored");
b4c4a9ec
MM
965 return finish_object_call_expr (TREE_OPERAND (fn, 1), object, args);
966 }
967 else
968 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
969 TREE_OPERAND (fn, 1), args);
970}
971
972/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
973 being the scope, if any, of DESTRUCTOR. Returns an expression for
974 the call. */
975
976tree
977finish_pseudo_destructor_call_expr (object, scope, destructor)
978 tree object;
979 tree scope;
980 tree destructor;
981{
982 if (scope && scope != destructor)
8251199e 983 cp_error ("destructor specifier `%T::~%T()' must have matching names",
b4c4a9ec
MM
984 scope, destructor);
985
986 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
987 && (TREE_CODE (TREE_TYPE (object)) !=
988 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
8251199e 989 cp_error ("`%E' is not of type `%T'", object, destructor);
b4c4a9ec
MM
990
991 return cp_convert (void_type_node, object);
992}
993
994/* Finish a call to a globally qualified member function FN using
995 ARGS. Returns an expression for the call. */
996
997tree
75d587eb 998finish_qualified_call_expr (fn, args)
b4c4a9ec
MM
999 tree fn;
1000 tree args;
1001{
1002 if (processing_template_decl)
1003 return build_min_nt (CALL_EXPR, copy_to_permanent (fn), args,
1004 NULL_TREE);
1005 else
1006 return build_member_call (TREE_OPERAND (fn, 0),
1007 TREE_OPERAND (fn, 1),
1008 args);
1009}
1010
1011/* Finish an expression taking the address of LABEL. Returns an
1012 expression for the address. */
1013
1014tree
1015finish_label_address_expr (label)
1016 tree label;
1017{
1018 tree result;
1019
1020 label = lookup_label (label);
1021 if (label == NULL_TREE)
1022 result = null_pointer_node;
1023 else
1024 {
1025 TREE_USED (label) = 1;
1026 result = build1 (ADDR_EXPR, ptr_type_node, label);
1027 TREE_CONSTANT (result) = 1;
1028 }
1029
1030 return result;
1031}
1032
ce4a0391
MM
1033/* Finish an expression of the form CODE EXPR. */
1034
1035tree
1036finish_unary_op_expr (code, expr)
1037 enum tree_code code;
1038 tree expr;
1039{
1040 tree result = build_x_unary_op (code, expr);
1041 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1042 TREE_NEGATED_INT (result) = 1;
1043 overflow_warning (result);
1044 return result;
1045}
1046
1047/* Finish an id-expression. */
1048
1049tree
1050finish_id_expr (expr)
1051 tree expr;
1052{
1053 if (TREE_CODE (expr) == IDENTIFIER_NODE)
a759e627 1054 expr = do_identifier (expr, 1, NULL_TREE);
ce4a0391
MM
1055
1056 return expr;
1057}
1058
1059/* Begin a new-placement. */
1060
1061int
1062begin_new_placement ()
1063{
1064 /* The arguments to a placement new might be passed to a
1065 deallocation function, in the event that the allocation throws an
1066 exception. Since we don't expand exception handlers until the
1067 end of a function, we must make sure the arguments stay around
1068 that long. */
1069 return suspend_momentary ();
1070}
1071
1072/* Finish a new-placement. The ARGS are the placement arguments. The
1073 COOKIE is the value returned by the previous call to
1074 begin_new_placement. */
1075
1076tree
1077finish_new_placement (args, cookie)
1078 tree args;
1079 int cookie;
1080{
1081 resume_momentary (cookie);
1082 return args;
1083}
1084
b4c4a9ec
MM
1085/* Begin a function defniition declared with DECL_SPECS and
1086 DECLARATOR. Returns non-zero if the function-declaration is
1087 legal. */
1088
1089int
1090begin_function_definition (decl_specs, declarator)
1091 tree decl_specs;
1092 tree declarator;
1093{
1094 tree specs;
1095 tree attrs;
1096 split_specs_attrs (decl_specs, &specs, &attrs);
1097 if (!start_function (specs, declarator, attrs, 0))
1098 return 0;
1099
1100 reinit_parse_for_function ();
39c01e4c
MM
1101 /* The things we're about to see are not directly qualified by any
1102 template headers we've seen thus far. */
1103 reset_specialization ();
1104
b4c4a9ec
MM
1105 return 1;
1106}
1107
1108/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1109 a SCOPE_REF. */
1110
1111tree
1112begin_constructor_declarator (scope, name)
1113 tree scope;
1114 tree name;
1115{
1116 tree result = build_parse_node (SCOPE_REF, scope, name);
830fcda8 1117 enter_scope_of (result);
b4c4a9ec
MM
1118 return result;
1119}
1120
ce4a0391
MM
1121/* Finish an init-declarator. Returns a DECL. */
1122
1123tree
1124finish_declarator (declarator, declspecs, attributes,
1125 prefix_attributes, initialized)
1126 tree declarator;
1127 tree declspecs;
1128 tree attributes;
1129 tree prefix_attributes;
1130 int initialized;
1131{
1132 return start_decl (declarator, declspecs, initialized, attributes,
1133 prefix_attributes);
1134}
1135
8014a339 1136/* Finish a translation unit. */
ce4a0391
MM
1137
1138void
1139finish_translation_unit ()
1140{
1141 /* In case there were missing closebraces,
1142 get us back to the global binding level. */
1143 while (! toplevel_bindings_p ())
1144 poplevel (0, 0, 0);
1145 while (current_namespace != global_namespace)
1146 pop_namespace ();
1147 finish_file ();
1148}
1149
b4c4a9ec
MM
1150/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1151 Returns the parameter. */
1152
1153tree
1154finish_template_type_parm (aggr, identifier)
1155 tree aggr;
1156 tree identifier;
1157{
1158 if (aggr == signature_type_node)
1159 sorry ("signature as template type parameter");
1160 else if (aggr != class_type_node)
1161 {
8251199e 1162 pedwarn ("template type parameters must use the keyword `class' or `typename'");
b4c4a9ec
MM
1163 aggr = class_type_node;
1164 }
1165
1166 return build_tree_list (aggr, identifier);
1167}
1168
1169/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1170 Returns the parameter. */
1171
1172tree
1173finish_template_template_parm (aggr, identifier)
1174 tree aggr;
1175 tree identifier;
1176{
1177 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1178 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1179 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1180 DECL_TEMPLATE_RESULT (tmpl) = decl;
1181 SET_DECL_ARTIFICIAL (decl);
1182 end_template_decl ();
1183
1184 return finish_template_type_parm (aggr, tmpl);
1185}
ce4a0391
MM
1186
1187/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1188 non-zero, the parameter list was terminated by a `...'. */
1189
1190tree
1191finish_parmlist (parms, ellipsis)
1192 tree parms;
1193 int ellipsis;
1194{
1195 if (!ellipsis)
1196 chainon (parms, void_list_node);
1197 /* We mark the PARMS as a parmlist so that declarator processing can
1198 disambiguate certain constructs. */
1199 if (parms != NULL_TREE)
1200 TREE_PARMLIST (parms) = 1;
1201
1202 return parms;
1203}
1204
1205/* Begin a class definition, as indicated by T. */
1206
1207tree
1208begin_class_definition (t)
1209 tree t;
1210{
ce4a0391
MM
1211 push_obstacks_nochange ();
1212 end_temporary_allocation ();
1213
1214 if (t == error_mark_node
1215 || ! IS_AGGR_TYPE (t))
1216 {
830fcda8 1217 t = make_lang_type (RECORD_TYPE);
ce4a0391
MM
1218 pushtag (make_anon_name (), t, 0);
1219 }
830fcda8
JM
1220
1221 /* In a definition of a member class template, we will get here with an
1222 implicit typename, a TYPENAME_TYPE with a type. */
1223 if (TREE_CODE (t) == TYPENAME_TYPE)
1224 t = TREE_TYPE (t);
1225
ce4a0391
MM
1226 if (TYPE_SIZE (t))
1227 duplicate_tag_error (t);
1228 if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
1229 {
1230 t = make_lang_type (TREE_CODE (t));
1231 pushtag (TYPE_IDENTIFIER (t), t, 0);
ce4a0391 1232 }
ff350acd
JM
1233 maybe_process_partial_specialization (t);
1234 if (processing_template_decl
1235 && ! CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
1236 && TYPE_CONTEXT (t) && TYPE_P (TYPE_CONTEXT (t))
ce4a0391
MM
1237 && ! current_class_type)
1238 push_template_decl (TYPE_STUB_DECL (t));
1239 pushclass (t, 0);
1240 TYPE_BEING_DEFINED (t) = 1;
ce4a0391
MM
1241 /* Reset the interface data, at the earliest possible
1242 moment, as it might have been set via a class foo;
1243 before. */
1244 /* Don't change signatures. */
1245 if (! IS_SIGNATURE (t))
1246 {
ce4a0391
MM
1247 int needs_writing;
1248 tree name = TYPE_IDENTIFIER (t);
1249
1250 if (! ANON_AGGRNAME_P (name))
1251 {
1252 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1253 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1254 (t, interface_unknown);
1255 }
1256
1257 /* Record how to set the access of this class's
56ae6d77 1258 virtual functions. If write_virtuals == 3, then
ce4a0391 1259 inline virtuals are ``extern inline''. */
56ae6d77
JM
1260 if (write_virtuals == 3)
1261 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
1262 && CLASSTYPE_INTERFACE_KNOWN (t);
1263 else
1264 needs_writing = 1;
ce4a0391
MM
1265 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
1266 }
1267#if 0
830fcda8
JM
1268 tmp = TYPE_IDENTIFIER ($<ttype>0);
1269 if (tmp && IDENTIFIER_TEMPLATE (tmp))
1270 overload_template_name (tmp, 1);
ce4a0391
MM
1271#endif
1272 reset_specialization();
1273
1274 /* In case this is a local class within a template
1275 function, we save the current tree structure so
1276 that we can get it back later. */
1277 begin_tree ();
1278
830fcda8 1279 return t;
ce4a0391
MM
1280}
1281
61a127b3
MM
1282/* Finish the member declaration given by DECL. */
1283
1284void
1285finish_member_declaration (decl)
1286 tree decl;
1287{
1288 if (decl == error_mark_node || decl == NULL_TREE)
1289 return;
1290
1291 if (decl == void_type_node)
1292 /* The COMPONENT was a friend, not a member, and so there's
1293 nothing for us to do. */
1294 return;
1295
1296 /* We should see only one DECL at a time. */
1297 my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0);
1298
1299 /* Set up access control for DECL. */
1300 TREE_PRIVATE (decl)
1301 = (current_access_specifier == access_private_node);
1302 TREE_PROTECTED (decl)
1303 = (current_access_specifier == access_protected_node);
1304 if (TREE_CODE (decl) == TEMPLATE_DECL)
1305 {
1306 TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl);
1307 TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl);
1308 }
1309
1310 /* Mark the DECL as a member of the current class. */
1311 if (TREE_CODE (decl) == FUNCTION_DECL
1312 || DECL_FUNCTION_TEMPLATE_P (decl))
1313 /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in
1314 finish_struct. Presumably it is already set as the function is
1315 parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */
1316 DECL_CLASS_CONTEXT (decl) = current_class_type;
1317 else if (TREE_CODE (decl) == TYPE_DECL)
1318 /* Historically, DECL_CONTEXT was not set for a TYPE_DECL in
1319 finish_struct, so we do not do it here either. Perhaps we
1320 should, though. */
1321 ;
1322 else
1323 DECL_CONTEXT (decl) = current_class_type;
1324
1325 /* Put functions on the TYPE_METHODS list and everything else on the
1326 TYPE_FIELDS list. Note that these are built up in reverse order.
1327 We reverse them (to obtain declaration order) in finish_struct. */
1328 if (TREE_CODE (decl) == FUNCTION_DECL
1329 || DECL_FUNCTION_TEMPLATE_P (decl))
1330 {
1331 /* We also need to add this function to the
1332 CLASSTYPE_METHOD_VEC. */
1333 add_method (current_class_type, 0, decl);
1334
1335 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
1336 TYPE_METHODS (current_class_type) = decl;
1337 }
1338 else
1339 {
1340 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
1341 go at the beginning. The reason is that lookup_field_1
1342 searches the list in order, and we want a field name to
1343 override a type name so that the "struct stat hack" will
1344 work. In particular:
1345
1346 struct S { enum E { }; int E } s;
1347 s.E = 3;
1348
1349 is legal. In addition, the FIELD_DECLs must be maintained in
1350 declaration order so that class layout works as expected.
1351 However, we don't need that order until class layout, so we
1352 save a little time by putting FIELD_DECLs on in reverse order
1353 here, and then reversing them in finish_struct_1. (We could
1354 also keep a pointer to the correct insertion points in the
1355 list.) */
1356
1357 if (TREE_CODE (decl) == TYPE_DECL)
1358 TYPE_FIELDS (current_class_type)
1359 = chainon (TYPE_FIELDS (current_class_type), decl);
1360 else
1361 {
1362 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
1363 TYPE_FIELDS (current_class_type) = decl;
1364 }
1365 }
1366}
1367
1368/* Finish a class definition T with the indicate ATTRIBUTES. If SEMI,
1369 the definition is immediately followed by a semicolon. Returns the
1370 type. */
ce4a0391
MM
1371
1372tree
61a127b3 1373finish_class_definition (t, attributes, semi)
ce4a0391 1374 tree t;
ce4a0391
MM
1375 tree attributes;
1376 int semi;
1377{
1378#if 0
1379 /* Need to rework class nesting in the presence of nested classes,
1380 etc. */
1381 shadow_tag (CLASSTYPE_AS_LIST (t)); */
1382#endif
1383
1384 /* finish_struct nukes this anyway; if finish_exception does too,
1385 then it can go. */
1386 if (semi)
1387 note_got_semicolon (t);
1388
dc8263bc
JM
1389 /* If we got any attributes in class_head, xref_tag will stick them in
1390 TREE_TYPE of the type. Grab them now. */
1391 attributes = chainon (TREE_TYPE (t), attributes);
1392 TREE_TYPE (t) = NULL_TREE;
1393
ce4a0391
MM
1394 if (TREE_CODE (t) == ENUMERAL_TYPE)
1395 ;
1396 else
1397 {
61a127b3 1398 t = finish_struct (t, attributes, semi);
ce4a0391
MM
1399 if (semi)
1400 note_got_semicolon (t);
1401 }
1402
1403 pop_obstacks ();
1404
1405 if (! semi)
1406 check_for_missing_semicolon (t);
1407 if (current_scope () == current_function_decl)
1408 do_pending_defargs ();
1409
1410 return t;
1411}
1412
1413/* Finish processing the default argument expressions cached during
1414 the processing of a class definition. */
1415
1416void
1417finish_default_args ()
1418{
1419 if (pending_inlines
1420 && current_scope () == current_function_decl)
1421 do_pending_inlines ();
1422}
1423
1424/* Finish processing the inline function definitions cached during the
1425 processing of a class definition. */
1426
1427void
1428begin_inline_definitions ()
1429{
1430 if (current_class_type == NULL_TREE)
1431 clear_inline_text_obstack ();
1432
1433 /* Undo the begin_tree in begin_class_definition. */
1434 end_tree ();
1435}
35acd3f2
MM
1436
1437/* Finish processing the declaration of a member class template
1438 TYPES whose template parameters are given by PARMS. */
1439
1440tree
61a127b3 1441finish_member_class_template (types)
35acd3f2
MM
1442 tree types;
1443{
36a117a5
MM
1444 tree t;
1445
1446 /* If there are declared, but undefined, partial specializations
1447 mixed in with the typespecs they will not yet have passed through
1448 maybe_process_partial_specialization, so we do that here. */
1449 for (t = types; t != NULL_TREE; t = TREE_CHAIN (t))
1450 if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t))))
1451 maybe_process_partial_specialization (TREE_VALUE (t));
1452
35acd3f2 1453 note_list_got_semicolon (types);
61a127b3 1454 grok_x_components (types);
35acd3f2
MM
1455 if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type)
1456 /* The component was in fact a friend declaration. We avoid
1457 finish_member_template_decl performing certain checks by
1458 unsetting TYPES. */
1459 types = NULL_TREE;
61a127b3
MM
1460
1461 finish_member_template_decl (types);
1462
35acd3f2
MM
1463 /* As with other component type declarations, we do
1464 not store the new DECL on the list of
1465 component_decls. */
1466 return NULL_TREE;
1467}
36a117a5
MM
1468
1469/* Finish processsing a complete template declaration. The PARMS are
1470 the template parameters. */
1471
1472void
1473finish_template_decl (parms)
1474 tree parms;
1475{
1476 if (parms)
1477 end_template_decl ();
1478 else
1479 end_specialization ();
1480}
1481
1482/* Finish processing a a template-id (which names a type) of the form
1483 NAME < ARGS >. Return the TYPE_DECL for the type named by the
1484 template-id. If ENTERING_SCOPE is non-zero we are about to enter
1485 the scope of template-id indicated. */
1486
1487tree
1488finish_template_type (name, args, entering_scope)
1489 tree name;
1490 tree args;
1491 int entering_scope;
1492{
1493 tree decl;
1494
1495 decl = lookup_template_class (name, args,
1496 NULL_TREE, NULL_TREE, entering_scope);
1497 if (decl != error_mark_node)
1498 decl = TYPE_STUB_DECL (decl);
1499
1500 return decl;
1501}
648f19f6
MM
1502
1503/* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a
1504 namespace scope or a class scope. */
1505
1506void
1507enter_scope_of (sr)
1508 tree sr;
1509{
1510 tree scope = TREE_OPERAND (sr, 0);
1511
1512 if (TREE_CODE (scope) == NAMESPACE_DECL)
1513 {
1514 push_decl_namespace (scope);
1515 TREE_COMPLEXITY (sr) = -1;
1516 }
1517 else if (scope != current_class_type)
1518 {
830fcda8
JM
1519 if (TREE_CODE (scope) == TYPENAME_TYPE)
1520 {
1521 /* In a declarator for a template class member, the scope will
1522 get here as an implicit typename, a TYPENAME_TYPE with a type. */
1523 scope = TREE_TYPE (scope);
1524 TREE_OPERAND (sr, 0) = scope;
1525 }
648f19f6
MM
1526 push_nested_class (scope, 3);
1527 TREE_COMPLEXITY (sr) = current_class_depth;
1528 }
1529}
ea6021e8
MM
1530
1531/* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
1532 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
1533 BASE_CLASS, or NULL_TREE if an error occurred. The
1534 ACCESSS_SPECIFIER is one of
1535 access_{default,public,protected_private}[_virtual]_node.*/
1536
1537tree
1538finish_base_specifier (access_specifier, base_class,
1539 current_aggr_is_signature)
1540 tree access_specifier;
1541 tree base_class;
1542 int current_aggr_is_signature;
1543{
1544 tree type;
1545 tree result;
1546
1547 if (base_class == NULL_TREE)
1548 {
8251199e 1549 error ("invalid base class");
ea6021e8
MM
1550 type = error_mark_node;
1551 }
1552 else
1553 type = TREE_TYPE (base_class);
1554 if (current_aggr_is_signature && access_specifier)
8251199e 1555 error ("access and source specifiers not allowed in signature");
ea6021e8
MM
1556 if (! is_aggr_type (type, 1))
1557 result = NULL_TREE;
1558 else if (current_aggr_is_signature
1559 && (! type) && (! IS_SIGNATURE (type)))
1560 {
8251199e 1561 error ("class name not allowed as base signature");
ea6021e8
MM
1562 result = NULL_TREE;
1563 }
1564 else if (current_aggr_is_signature)
1565 {
1566 sorry ("signature inheritance, base type `%s' ignored",
1567 IDENTIFIER_POINTER (access_specifier));
1568 result = build_tree_list (access_public_node, type);
1569 }
1570 else if (type && IS_SIGNATURE (type))
1571 {
8251199e 1572 error ("signature name not allowed as base class");
ea6021e8
MM
1573 result = NULL_TREE;
1574 }
1575 else
1576 result = build_tree_list (access_specifier, type);
1577
1578 return result;
1579}
61a127b3
MM
1580
1581/* Called when multiple declarators are processed. If that is not
1582 premitted in this context, an error is issued. */
1583
1584void
1585check_multiple_declarators ()
1586{
1587 /* [temp]
1588
1589 In a template-declaration, explicit specialization, or explicit
1590 instantiation the init-declarator-list in the declaration shall
1591 contain at most one declarator.
1592
1593 We don't just use PROCESSING_TEMPLATE_DECL for the first
1594 condition since that would disallow the perfectly legal code,
1595 like `template <class T> struct S { int i, j; };'. */
1596 tree scope = current_scope ();
1597
1598 if (scope && TREE_CODE (scope) == FUNCTION_DECL)
1599 /* It's OK to write `template <class T> void f() { int i, j;}'. */
1600 return;
1601
1602 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
1603 || processing_explicit_instantiation
1604 || processing_specialization)
1605 cp_error ("multiple declarators in template declaration");
1606}
1607
b894fc05
JM
1608tree
1609finish_typeof (expr)
1610 tree expr;
1611{
1612 if (processing_template_decl)
1613 {
1614 tree t;
1615
1616 push_obstacks_nochange ();
1617 end_temporary_allocation ();
1618
1619 t = make_lang_type (TYPEOF_TYPE);
b894fc05
JM
1620 TYPE_FIELDS (t) = expr;
1621
1622 pop_obstacks ();
1623
1624 return t;
1625 }
1626
1627 return TREE_TYPE (expr);
1628}