]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
cp-tree.h (finish_unary_op_expr): New function.
[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);
386 if (cond)
387 expand_exit_loop_if_false (0, cond);
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 ())
456 cp_error ("break statement not within loop or switch");
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))
468 cp_error ("continue statement not within a loop");
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
590 expand_start_all_catch ();
591}
592
593/* Finish a handler-sequence for a try-block, which may be given by
594 TRY_BLOCK. */
595
596void
597finish_handler_sequence (try_block)
598 tree try_block;
599{
600 if (processing_template_decl)
601 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
602 else
603 expand_end_all_catch ();
604}
605
606/* Begin a handler. Returns a HANDLER if appropriate. */
607
608tree
609begin_handler ()
610{
611 tree r;
612
613 if (processing_template_decl)
614 {
615 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
616 add_tree (r);
617 }
618 else
619 r = NULL_TREE;
620
621 do_pushlevel ();
622
623 return r;
624}
625
626/* Finish the handler-parameters for a handler, which may be given by
627 HANDLER. */
628
629void
630finish_handler_parms (handler)
631 tree handler;
632{
633 if (processing_template_decl)
634 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_PARMS (handler));
635}
636
637/* Finish a handler, which may be given by HANDLER. */
638
639void
640finish_handler (handler)
641 tree handler;
642{
643 if (processing_template_decl)
644 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_BODY (handler));
645 else
646 expand_end_catch_block ();
647
648 do_poplevel ();
649}
650
651/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
652 compound-statement does not define a scope. Returns a new
653 COMPOUND_STMT if appropriate. */
654
655tree
656begin_compound_stmt (has_no_scope)
657 int has_no_scope;
658{
659 tree r;
660
661 if (processing_template_decl)
662 {
663 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
664 add_tree (r);
665 if (has_no_scope)
666 COMPOUND_STMT_NO_SCOPE (r) = 1;
667 }
668 else
669 r = NULL_TREE;
670
671 if (!has_no_scope)
672 do_pushlevel ();
673
674 return r;
675}
676
677
678/* Finish a compound-statement, which may be given by COMPOUND_STMT.
679 If HAS_NO_SCOPE is non-zero, the compound statement does not define
680 a scope. */
681
682tree
683finish_compound_stmt (has_no_scope, compound_stmt)
684 int has_no_scope;
685 tree compound_stmt;
686{
687 tree r;
688
689 if (!has_no_scope)
690 r = do_poplevel ();
691 else
692 r = NULL_TREE;
693
694 if (processing_template_decl)
695 RECHAIN_STMTS_FROM_CHAIN (compound_stmt,
696 COMPOUND_BODY (compound_stmt));
697
698 finish_stmt ();
699
700 return r;
701}
702
703/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
704 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
705 CLOBBERS. */
706
707void
708finish_asm_stmt (cv_qualifier, string, output_operands,
709 input_operands, clobbers)
710 tree cv_qualifier;
711 tree string;
712 tree output_operands;
713 tree input_operands;
714 tree clobbers;
715{
716 if (TREE_CHAIN (string))
e6f1275f 717 string = combine_strings (string);
ad321293
MM
718
719 if (processing_template_decl)
720 {
721 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
722 output_operands, input_operands,
723 clobbers);
724 add_tree (r);
725 }
726 else
727 {
728 emit_line_note (input_filename, lineno);
e6f1275f
JM
729 if (output_operands != NULL_TREE || input_operands != NULL_TREE
730 || clobbers != NULL_TREE)
ad321293
MM
731 {
732 if (cv_qualifier != NULL_TREE
733 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
734 cp_warning ("%s qualifier ignored on asm",
735 IDENTIFIER_POINTER (cv_qualifier));
736
737 c_expand_asm_operands (string, output_operands,
738 input_operands,
739 clobbers,
740 cv_qualifier
741 == ridpointers[(int) RID_VOLATILE],
742 input_filename, lineno);
743 }
744 else
745 {
746 if (cv_qualifier != NULL_TREE)
747 cp_warning ("%s qualifier ignored on asm",
748 IDENTIFIER_POINTER (cv_qualifier));
749 expand_asm (string);
750 }
751
752 finish_stmt ();
753 }
754}
b4c4a9ec
MM
755
756/* Finish a parenthesized expression EXPR. */
757
758tree
759finish_parenthesized_expr (expr)
760 tree expr;
761{
762 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
763 /* This inhibits warnings in truthvalue_conversion. */
764 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
765
766 return expr;
767}
768
b69b1501
MM
769/* Begin a statement-expression. The value returned must be passed to
770 finish_stmt_expr. */
b4c4a9ec
MM
771
772tree
773begin_stmt_expr ()
774{
775 keep_next_level ();
b69b1501
MM
776 /* If we're processing_template_decl, then the upcoming compound
777 statement will be chained onto the tree structure, starting at
778 last_tree. We return last_tree so that we can later unhook the
779 compound statement. */
780 return processing_template_decl ? last_tree : expand_start_stmt_expr();
b4c4a9ec
MM
781}
782
783/* Finish a statement-expression. RTL_EXPR should be the value
784 returned by the previous begin_stmt_expr; EXPR is the
785 statement-expression. Returns an expression representing the
786 statement-expression. */
787
788tree
789finish_stmt_expr (rtl_expr, expr)
790 tree rtl_expr;
791 tree expr;
792{
793 tree result;
794
795 if (!processing_template_decl)
796 {
797 rtl_expr = expand_end_stmt_expr (rtl_expr);
798 /* The statements have side effects, so the group does. */
799 TREE_SIDE_EFFECTS (rtl_expr) = 1;
800 }
801
802 if (TREE_CODE (expr) == BLOCK)
803 {
804 /* Make a BIND_EXPR for the BLOCK already made. */
805 if (processing_template_decl)
806 result = build (BIND_EXPR, NULL_TREE,
807 NULL_TREE, last_tree, expr);
808 else
809 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
810 NULL_TREE, rtl_expr, expr);
811
812 /* Remove the block from the tree at this point.
813 It gets put back at the proper place
814 when the BIND_EXPR is expanded. */
815 delete_block (expr);
816 }
817 else
818 result = expr;
b69b1501
MM
819
820 if (processing_template_decl)
821 {
822 /* Remove the compound statement from the tree structure; it is
823 now saved in the BIND_EXPR. */
824 last_tree = rtl_expr;
825 TREE_CHAIN (last_tree) = NULL_TREE;
826 }
b4c4a9ec
MM
827
828 return result;
829}
830
831/* Finish a call to FN with ARGS. Returns a representation of the
832 call. */
833
834tree
835finish_call_expr (fn, args)
836 tree fn;
837 tree args;
838{
839 tree result = build_x_function_call (fn, args, current_class_ref);
840
841 if (TREE_CODE (result) == CALL_EXPR
842 && TREE_TYPE (result) != void_type_node)
843 result = require_complete_type (result);
844
845 return result;
846}
847
848/* Finish a call to a postfix increment or decrement or EXPR. (Which
849 is indicated by CODE, which should be POSTINCREMENT_EXPR or
850 POSTDECREMENT_EXPR.) */
851
852tree
853finish_increment_expr (expr, code)
854 tree expr;
855 enum tree_code code;
856{
857 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
858 a COMPONENT_REF). This way if we've got, say, a reference to a
859 static member that's being operated on, we don't end up trying to
860 find a member operator for the class it's in. */
861
862 if (TREE_CODE (expr) == OFFSET_REF)
863 expr = resolve_offset_ref (expr);
864 return build_x_unary_op (code, expr);
865}
866
867/* Finish a use of `this'. Returns an expression for `this'. */
868
869tree
870finish_this_expr ()
871{
872 tree result;
873
874 if (current_class_ptr)
875 {
876#ifdef WARNING_ABOUT_CCD
877 TREE_USED (current_class_ptr) = 1;
878#endif
879 result = current_class_ptr;
880 }
881 else if (current_function_decl
882 && DECL_STATIC_FUNCTION_P (current_function_decl))
883 {
884 error ("`this' is unavailable for static member functions");
885 result = error_mark_node;
886 }
887 else
888 {
889 if (current_function_decl)
890 error ("invalid use of `this' in non-member function");
891 else
892 error ("invalid use of `this' at top level");
893 result = error_mark_node;
894 }
895
896 return result;
897}
898
899/* Finish a member function call using OBJECT and ARGS as arguments to
900 FN. Returns an expression for the call. */
901
902tree
903finish_object_call_expr (fn, object, args)
904 tree fn;
905 tree object;
906 tree args;
907{
908#if 0
909 /* This is a future direction of this code, but because
910 build_x_function_call cannot always undo what is done in
911 build_component_ref entirely yet, we cannot do this. */
912
913 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
914 return finish_call_expr (real_fn, args);
915#else
916 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
917#endif
918}
919
920/* Finish a qualified member function call using OBJECT and ARGS as
921 arguments to FN. Returns an expressino for the call. */
922
923tree
924finish_qualified_object_call_expr (fn, object, args)
925 tree fn;
926 tree object;
927 tree args;
928{
929 if (IS_SIGNATURE (TREE_OPERAND (fn, 0)))
930 {
931 warning ("signature name in scope resolution ignored");
932 return finish_object_call_expr (TREE_OPERAND (fn, 1), object, args);
933 }
934 else
935 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
936 TREE_OPERAND (fn, 1), args);
937}
938
939/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
940 being the scope, if any, of DESTRUCTOR. Returns an expression for
941 the call. */
942
943tree
944finish_pseudo_destructor_call_expr (object, scope, destructor)
945 tree object;
946 tree scope;
947 tree destructor;
948{
949 if (scope && scope != destructor)
950 cp_error ("destructor specifier `%T::~%T()' must have matching names",
951 scope, destructor);
952
953 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
954 && (TREE_CODE (TREE_TYPE (object)) !=
955 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
956 cp_error ("`%E' is not of type `%T'", object, destructor);
957
958 return cp_convert (void_type_node, object);
959}
960
961/* Finish a call to a globally qualified member function FN using
962 ARGS. Returns an expression for the call. */
963
964tree
965finish_globally_qualified_member_call_expr (fn, args)
966 tree fn;
967 tree args;
968{
969 if (processing_template_decl)
970 return build_min_nt (CALL_EXPR, copy_to_permanent (fn), args,
971 NULL_TREE);
972 else
973 return build_member_call (TREE_OPERAND (fn, 0),
974 TREE_OPERAND (fn, 1),
975 args);
976}
977
978/* Finish an expression taking the address of LABEL. Returns an
979 expression for the address. */
980
981tree
982finish_label_address_expr (label)
983 tree label;
984{
985 tree result;
986
987 label = lookup_label (label);
988 if (label == NULL_TREE)
989 result = null_pointer_node;
990 else
991 {
992 TREE_USED (label) = 1;
993 result = build1 (ADDR_EXPR, ptr_type_node, label);
994 TREE_CONSTANT (result) = 1;
995 }
996
997 return result;
998}
999
ce4a0391
MM
1000/* Finish an expression of the form CODE EXPR. */
1001
1002tree
1003finish_unary_op_expr (code, expr)
1004 enum tree_code code;
1005 tree expr;
1006{
1007 tree result = build_x_unary_op (code, expr);
1008 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1009 TREE_NEGATED_INT (result) = 1;
1010 overflow_warning (result);
1011 return result;
1012}
1013
1014/* Finish an id-expression. */
1015
1016tree
1017finish_id_expr (expr)
1018 tree expr;
1019{
1020 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1021 expr = do_identifier (expr, 1);
1022
1023 return expr;
1024}
1025
1026/* Begin a new-placement. */
1027
1028int
1029begin_new_placement ()
1030{
1031 /* The arguments to a placement new might be passed to a
1032 deallocation function, in the event that the allocation throws an
1033 exception. Since we don't expand exception handlers until the
1034 end of a function, we must make sure the arguments stay around
1035 that long. */
1036 return suspend_momentary ();
1037}
1038
1039/* Finish a new-placement. The ARGS are the placement arguments. The
1040 COOKIE is the value returned by the previous call to
1041 begin_new_placement. */
1042
1043tree
1044finish_new_placement (args, cookie)
1045 tree args;
1046 int cookie;
1047{
1048 resume_momentary (cookie);
1049 return args;
1050}
1051
b4c4a9ec
MM
1052/* Begin a function defniition declared with DECL_SPECS and
1053 DECLARATOR. Returns non-zero if the function-declaration is
1054 legal. */
1055
1056int
1057begin_function_definition (decl_specs, declarator)
1058 tree decl_specs;
1059 tree declarator;
1060{
1061 tree specs;
1062 tree attrs;
1063 split_specs_attrs (decl_specs, &specs, &attrs);
1064 if (!start_function (specs, declarator, attrs, 0))
1065 return 0;
1066
1067 reinit_parse_for_function ();
1068 return 1;
1069}
1070
1071/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1072 a SCOPE_REF. */
1073
1074tree
1075begin_constructor_declarator (scope, name)
1076 tree scope;
1077 tree name;
1078{
1079 tree result = build_parse_node (SCOPE_REF, scope, name);
1080
1081 if (scope != current_class_type)
1082 {
1083 push_nested_class (scope, 3);
1084 TREE_COMPLEXITY (result) = current_class_depth;
1085 }
1086
1087 return result;
1088}
1089
ce4a0391
MM
1090/* Finish an init-declarator. Returns a DECL. */
1091
1092tree
1093finish_declarator (declarator, declspecs, attributes,
1094 prefix_attributes, initialized)
1095 tree declarator;
1096 tree declspecs;
1097 tree attributes;
1098 tree prefix_attributes;
1099 int initialized;
1100{
1101 return start_decl (declarator, declspecs, initialized, attributes,
1102 prefix_attributes);
1103}
1104
1105/* Finish a transltation unit. */
1106
1107void
1108finish_translation_unit ()
1109{
1110 /* In case there were missing closebraces,
1111 get us back to the global binding level. */
1112 while (! toplevel_bindings_p ())
1113 poplevel (0, 0, 0);
1114 while (current_namespace != global_namespace)
1115 pop_namespace ();
1116 finish_file ();
1117}
1118
b4c4a9ec
MM
1119/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1120 Returns the parameter. */
1121
1122tree
1123finish_template_type_parm (aggr, identifier)
1124 tree aggr;
1125 tree identifier;
1126{
1127 if (aggr == signature_type_node)
1128 sorry ("signature as template type parameter");
1129 else if (aggr != class_type_node)
1130 {
1131 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1132 aggr = class_type_node;
1133 }
1134
1135 return build_tree_list (aggr, identifier);
1136}
1137
1138/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1139 Returns the parameter. */
1140
1141tree
1142finish_template_template_parm (aggr, identifier)
1143 tree aggr;
1144 tree identifier;
1145{
1146 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1147 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1148 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1149 DECL_TEMPLATE_RESULT (tmpl) = decl;
1150 SET_DECL_ARTIFICIAL (decl);
1151 end_template_decl ();
1152
1153 return finish_template_type_parm (aggr, tmpl);
1154}
ce4a0391
MM
1155
1156/* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1157 non-zero, the parameter list was terminated by a `...'. */
1158
1159tree
1160finish_parmlist (parms, ellipsis)
1161 tree parms;
1162 int ellipsis;
1163{
1164 if (!ellipsis)
1165 chainon (parms, void_list_node);
1166 /* We mark the PARMS as a parmlist so that declarator processing can
1167 disambiguate certain constructs. */
1168 if (parms != NULL_TREE)
1169 TREE_PARMLIST (parms) = 1;
1170
1171 return parms;
1172}
1173
1174/* Begin a class definition, as indicated by T. */
1175
1176tree
1177begin_class_definition (t)
1178 tree t;
1179{
1180 tree new_type = t;
1181
1182 push_obstacks_nochange ();
1183 end_temporary_allocation ();
1184
1185 if (t == error_mark_node
1186 || ! IS_AGGR_TYPE (t))
1187 {
1188 t = new_type = make_lang_type (RECORD_TYPE);
1189 pushtag (make_anon_name (), t, 0);
1190 }
1191 if (TYPE_SIZE (t))
1192 duplicate_tag_error (t);
1193 if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
1194 {
1195 t = make_lang_type (TREE_CODE (t));
1196 pushtag (TYPE_IDENTIFIER (t), t, 0);
1197 new_type = t;
1198 }
1199 if (processing_template_decl && TYPE_CONTEXT (t)
1200 && TREE_CODE (TYPE_CONTEXT (t)) != NAMESPACE_DECL
1201 && ! current_class_type)
1202 push_template_decl (TYPE_STUB_DECL (t));
1203 pushclass (t, 0);
1204 TYPE_BEING_DEFINED (t) = 1;
1205 if (IS_AGGR_TYPE (t) && CLASSTYPE_USE_TEMPLATE (t))
1206 {
1207 if (CLASSTYPE_IMPLICIT_INSTANTIATION (t)
1208 && TYPE_SIZE (t) == NULL_TREE)
1209 {
1210 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (t);
1211 if (processing_template_decl)
1212 push_template_decl (TYPE_MAIN_DECL (t));
1213 }
1214 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (t))
1215 cp_error ("specialization after instantiation of `%T'", t);
1216 }
1217 /* Reset the interface data, at the earliest possible
1218 moment, as it might have been set via a class foo;
1219 before. */
1220 /* Don't change signatures. */
1221 if (! IS_SIGNATURE (t))
1222 {
1223 extern tree pending_vtables;
1224 int needs_writing;
1225 tree name = TYPE_IDENTIFIER (t);
1226
1227 if (! ANON_AGGRNAME_P (name))
1228 {
1229 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1230 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1231 (t, interface_unknown);
1232 }
1233
1234 /* Record how to set the access of this class's
1235 virtual functions. If write_virtuals == 2 or 3, then
1236 inline virtuals are ``extern inline''. */
1237 switch (write_virtuals)
1238 {
1239 case 0:
1240 case 1:
1241 needs_writing = 1;
1242 break;
1243 case 2:
1244 needs_writing = !! value_member (name, pending_vtables);
1245 break;
1246 case 3:
1247 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
1248 && CLASSTYPE_INTERFACE_KNOWN (t);
1249 break;
1250 default:
1251 needs_writing = 0;
1252 }
1253 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
1254 }
1255#if 0
1256 t = TYPE_IDENTIFIER ($<ttype>0);
1257 if (t && IDENTIFIER_TEMPLATE (t))
1258 overload_template_name (t, 1);
1259#endif
1260 reset_specialization();
1261
1262 /* In case this is a local class within a template
1263 function, we save the current tree structure so
1264 that we can get it back later. */
1265 begin_tree ();
1266
1267 return new_type;
1268}
1269
1270/* Finish a class definition T, with the indicated COMPONENTS, and
1271 with the indicate ATTRIBUTES. If SEMI, the definition is
1272 immediately followed by a semicolon. Returns the type. */
1273
1274tree
1275finish_class_definition (t, components, attributes, semi)
1276 tree t;
1277 tree components;
1278 tree attributes;
1279 int semi;
1280{
1281#if 0
1282 /* Need to rework class nesting in the presence of nested classes,
1283 etc. */
1284 shadow_tag (CLASSTYPE_AS_LIST (t)); */
1285#endif
1286
1287 /* finish_struct nukes this anyway; if finish_exception does too,
1288 then it can go. */
1289 if (semi)
1290 note_got_semicolon (t);
1291
1292 if (TREE_CODE (t) == ENUMERAL_TYPE)
1293 ;
1294 else
1295 {
1296 t = finish_struct (t, components, attributes, semi);
1297 if (semi)
1298 note_got_semicolon (t);
1299 }
1300
1301 pop_obstacks ();
1302
1303 if (! semi)
1304 check_for_missing_semicolon (t);
1305 if (current_scope () == current_function_decl)
1306 do_pending_defargs ();
1307
1308 return t;
1309}
1310
1311/* Finish processing the default argument expressions cached during
1312 the processing of a class definition. */
1313
1314void
1315finish_default_args ()
1316{
1317 if (pending_inlines
1318 && current_scope () == current_function_decl)
1319 do_pending_inlines ();
1320}
1321
1322/* Finish processing the inline function definitions cached during the
1323 processing of a class definition. */
1324
1325void
1326begin_inline_definitions ()
1327{
1328 if (current_class_type == NULL_TREE)
1329 clear_inline_text_obstack ();
1330
1331 /* Undo the begin_tree in begin_class_definition. */
1332 end_tree ();
1333}