First cut of changes to utilize the new exception handling model
[official-gcc.git] / gcc / cp / semantics.c
blob25016423365ca2464dbe947a27c3736a203cf7db
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.
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.
10 This file is part of GNU CC.
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.
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.
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. */
27 #include "config.h"
28 #include "system.h"
29 #include "tree.h"
30 #include "cp-tree.h"
31 #include "except.h"
32 #include "lex.h"
33 #include "toplev.h"
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. */
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. */
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)
57 #define RECHAIN_STMTS_FROM_LAST(stmt, substmt) \
58 RECHAIN_STMTS (stmt, substmt, last_tree)
60 #define RECHAIN_STMTS_FROM_CHAIN(stmt, substmt) \
61 RECHAIN_STMTS (stmt, substmt, TREE_CHAIN (stmt))
63 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
65 void
66 finish_expr_stmt (expr)
67 tree expr;
69 if (expr != NULL_TREE)
71 if (!processing_template_decl)
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);
82 cplus_expand_expr_stmt (expr);
83 clear_momentary ();
86 finish_stmt ();
89 /* Begin an if-statement. Returns a newly created IF_STMT if
90 appropriate. */
92 tree
93 begin_if_stmt ()
95 tree r;
97 if (processing_template_decl)
99 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
100 add_tree (r);
102 else
103 r = NULL_TREE;
105 do_pushlevel ();
107 return r;
110 /* Process the COND of an if-statement, which may be given by
111 IF_STMT. */
113 void
114 finish_if_stmt_cond (cond, if_stmt)
115 tree cond;
116 tree if_stmt;
118 if (processing_template_decl)
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;
125 else
127 emit_line_note (input_filename, lineno);
128 expand_start_cond (condition_conversion (cond), 0);
132 /* Finish the then-clause of an if-statement, which may be given by
133 IF_STMT. */
135 tree
136 finish_then_clause (if_stmt)
137 tree if_stmt;
139 if (processing_template_decl)
141 RECHAIN_STMTS_FROM_CHAIN (if_stmt,
142 THEN_CLAUSE (if_stmt));
143 last_tree = if_stmt;
144 return if_stmt;
146 else
147 return NULL_TREE;
150 /* Begin the else-clause of an if-statement. */
152 void
153 begin_else_clause ()
155 if (!processing_template_decl)
156 expand_start_else ();
159 /* Finish the else-clause of an if-statement, which may be given by
160 IF_STMT. */
162 void
163 finish_else_clause (if_stmt)
164 tree if_stmt;
166 if (processing_template_decl)
167 RECHAIN_STMTS_FROM_CHAIN (if_stmt, ELSE_CLAUSE (if_stmt));
170 /* Finsh an if-statement. */
172 void
173 finish_if_stmt ()
175 if (!processing_template_decl)
176 expand_end_cond ();
178 do_poplevel ();
179 finish_stmt ();
182 /* Begin a while-statement. Returns a newly created WHILE_STMT if
183 appropriate. */
185 tree
186 begin_while_stmt ()
188 tree r;
190 if (processing_template_decl)
192 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
193 add_tree (r);
195 else
197 emit_nop ();
198 emit_line_note (input_filename, lineno);
199 expand_start_loop (1);
200 r = NULL_TREE;
203 do_pushlevel ();
205 return r;
208 /* Process the COND of an if-statement, which may be given by
209 WHILE_STMT. */
211 void
212 finish_while_stmt_cond (cond, while_stmt)
213 tree cond;
214 tree while_stmt;
216 if (processing_template_decl)
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;
224 else
226 emit_line_note (input_filename, lineno);
227 expand_exit_loop_if_false (0, condition_conversion (cond));
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)
235 do_poplevel ();
236 do_pushlevel ();
240 /* Finish a while-statement, which may be given by WHILE_STMT. */
242 void
243 finish_while_stmt (while_stmt)
244 tree while_stmt;
246 do_poplevel ();
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 ();
255 /* Begin a do-statement. Returns a newly created DO_STMT if
256 appropriate. */
258 tree
259 begin_do_stmt ()
261 if (processing_template_decl)
263 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
264 add_tree (r);
265 return r;
267 else
269 emit_nop ();
270 emit_line_note (input_filename, lineno);
271 expand_start_loop_continue_elsewhere (1);
272 return NULL_TREE;
276 /* Finish the body of a do-statement, which may be given by DO_STMT. */
278 void
279 finish_do_body (do_stmt)
280 tree do_stmt;
282 if (processing_template_decl)
283 RECHAIN_STMTS_FROM_CHAIN (do_stmt, DO_BODY (do_stmt));
284 else
285 expand_loop_continue_here ();
288 /* Finish a do-statement, which may be given by DO_STMT, and whose
289 COND is as indicated. */
291 void
292 finish_do_stmt (cond, do_stmt)
293 tree cond;
294 tree do_stmt;
296 if (processing_template_decl)
297 DO_COND (do_stmt) = cond;
298 else
300 emit_line_note (input_filename, lineno);
301 expand_exit_loop_if_false (0, condition_conversion (cond));
302 expand_end_loop ();
305 clear_momentary ();
306 finish_stmt ();
309 /* Finish a return-statement. The EXPRESSION returned, if any, is as
310 indicated. */
312 void
313 finish_return_stmt (expr)
314 tree expr;
316 emit_line_note (input_filename, lineno);
317 c_expand_return (expr);
318 finish_stmt ();
321 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
323 tree
324 begin_for_stmt ()
326 tree r;
328 if (processing_template_decl)
330 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
331 NULL_TREE, NULL_TREE);
332 add_tree (r);
334 else
335 r = NULL_TREE;
337 if (flag_new_for_scope > 0)
339 do_pushlevel ();
340 note_level_for_for ();
343 return r;
346 /* Finish the for-init-statement of a for-statement, which may be
347 given by FOR_STMT. */
349 void
350 finish_for_init_stmt (for_stmt)
351 tree for_stmt;
353 if (processing_template_decl)
355 if (last_tree != for_stmt)
356 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_INIT_STMT (for_stmt));
358 else
360 emit_nop ();
361 emit_line_note (input_filename, lineno);
362 expand_start_loop_continue_elsewhere (1);
365 do_pushlevel ();
368 /* Finish the COND of a for-statement, which may be given by
369 FOR_STMT. */
371 void
372 finish_for_cond (cond, for_stmt)
373 tree cond;
374 tree for_stmt;
376 if (processing_template_decl)
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;
383 else
385 emit_line_note (input_filename, lineno);
386 if (cond)
387 expand_exit_loop_if_false (0, cond);
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)
395 do_poplevel ();
396 do_pushlevel ();
400 /* Finish the increment-EXPRESSION in a for-statement, which may be
401 given by FOR_STMT. */
403 void
404 finish_for_expr (expr, for_stmt)
405 tree expr;
406 tree for_stmt;
408 if (processing_template_decl)
409 FOR_EXPR (for_stmt) = expr;
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 ();
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. */
420 void
421 finish_for_stmt (expr, for_stmt)
422 tree expr;
423 tree for_stmt;
425 /* Pop the scope for the body of the loop. */
426 do_poplevel ();
428 if (processing_template_decl)
429 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_BODY (for_stmt));
430 else
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 ();
439 pop_momentary ();
441 if (flag_new_for_scope > 0)
442 do_poplevel ();
444 finish_stmt ();
447 /* Finish a break-statement. */
449 void
450 finish_break_stmt ()
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");
459 /* Finish a continue-statement. */
461 void
462 finish_continue_stmt ()
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");
471 /* Begin a switch-statement. */
473 void
474 begin_switch_stmt ()
476 do_pushlevel ();
479 /* Finish the cond of a switch-statement. Returns a new
480 SWITCH_STMT if appropriate. */
482 tree
483 finish_switch_cond (cond)
484 tree cond;
486 tree r;
488 if (processing_template_decl)
490 r = build_min_nt (SWITCH_STMT, cond, NULL_TREE);
491 add_tree (r);
493 else
495 emit_line_note (input_filename, lineno);
496 c_expand_start_case (cond);
497 r = NULL_TREE;
499 push_switch ();
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 ();
505 return r;
508 /* Finish the body of a switch-statement, which may be given by
509 SWITCH_STMT. The COND to switch on is indicated. */
511 void
512 finish_switch_stmt (cond, switch_stmt)
513 tree cond;
514 tree switch_stmt;
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 ();
526 /* Finish a case-label. */
528 void
529 finish_case_label (low_value, high_value)
530 tree low_value;
531 tree high_value;
533 do_case (low_value, high_value);
537 /* Finish a goto-statement. */
539 void
540 finish_goto_stmt (destination)
541 tree destination;
543 if (processing_template_decl)
544 add_tree (build_min_nt (GOTO_STMT, destination));
545 else
547 emit_line_note (input_filename, lineno);
549 if (TREE_CODE (destination) == IDENTIFIER_NODE)
551 tree decl = lookup_label (destination);
552 TREE_USED (decl) = 1;
553 expand_goto (decl);
555 else
556 expand_computed_goto (destination);
560 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
561 appropriate. */
563 tree
564 begin_try_block ()
566 if (processing_template_decl)
568 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
569 NULL_TREE);
570 add_tree (r);
571 return r;
573 else
575 emit_line_note (input_filename, lineno);
576 expand_start_try_stmts ();
577 return NULL_TREE;
581 /* Finish a try-block, which may be given by TRY_BLOCK. */
583 void
584 finish_try_block (try_block)
585 tree try_block;
587 if (processing_template_decl)
588 RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block));
589 else
591 expand_start_all_catch ();
592 expand_start_catch (NULL);
596 /* Finish a handler-sequence for a try-block, which may be given by
597 TRY_BLOCK. */
599 void
600 finish_handler_sequence (try_block)
601 tree try_block;
603 if (processing_template_decl)
604 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
605 else
607 expand_end_catch ();
608 expand_end_all_catch ();
612 /* Begin a handler. Returns a HANDLER if appropriate. */
614 tree
615 begin_handler ()
617 tree r;
619 if (processing_template_decl)
621 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
622 add_tree (r);
624 else
625 r = NULL_TREE;
627 do_pushlevel ();
629 return r;
632 /* Finish the handler-parameters for a handler, which may be given by
633 HANDLER. */
635 void
636 finish_handler_parms (handler)
637 tree handler;
639 if (processing_template_decl)
640 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_PARMS (handler));
643 /* Finish a handler, which may be given by HANDLER. */
645 void
646 finish_handler (handler)
647 tree handler;
649 if (processing_template_decl)
650 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_BODY (handler));
651 else
652 expand_end_catch_block ();
654 do_poplevel ();
657 /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
658 compound-statement does not define a scope. Returns a new
659 COMPOUND_STMT if appropriate. */
661 tree
662 begin_compound_stmt (has_no_scope)
663 int has_no_scope;
665 tree r;
667 if (processing_template_decl)
669 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
670 add_tree (r);
671 if (has_no_scope)
672 COMPOUND_STMT_NO_SCOPE (r) = 1;
674 else
675 r = NULL_TREE;
677 if (!has_no_scope)
678 do_pushlevel ();
680 return r;
684 /* Finish a compound-statement, which may be given by COMPOUND_STMT.
685 If HAS_NO_SCOPE is non-zero, the compound statement does not define
686 a scope. */
688 tree
689 finish_compound_stmt (has_no_scope, compound_stmt)
690 int has_no_scope;
691 tree compound_stmt;
693 tree r;
695 if (!has_no_scope)
696 r = do_poplevel ();
697 else
698 r = NULL_TREE;
700 if (processing_template_decl)
701 RECHAIN_STMTS_FROM_CHAIN (compound_stmt,
702 COMPOUND_BODY (compound_stmt));
704 finish_stmt ();
706 return r;
709 /* Finish an asm-statement, whose components are a CV_QUALIFIER, a
710 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
711 CLOBBERS. */
713 void
714 finish_asm_stmt (cv_qualifier, string, output_operands,
715 input_operands, clobbers)
716 tree cv_qualifier;
717 tree string;
718 tree output_operands;
719 tree input_operands;
720 tree clobbers;
722 if (TREE_CHAIN (string))
723 string = combine_strings (string);
725 if (processing_template_decl)
727 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
728 output_operands, input_operands,
729 clobbers);
730 add_tree (r);
732 else
734 emit_line_note (input_filename, lineno);
735 if (output_operands != NULL_TREE || input_operands != NULL_TREE
736 || clobbers != NULL_TREE)
738 if (cv_qualifier != NULL_TREE
739 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
740 cp_warning ("%s qualifier ignored on asm",
741 IDENTIFIER_POINTER (cv_qualifier));
743 c_expand_asm_operands (string, output_operands,
744 input_operands,
745 clobbers,
746 cv_qualifier
747 == ridpointers[(int) RID_VOLATILE],
748 input_filename, lineno);
750 else
752 if (cv_qualifier != NULL_TREE)
753 cp_warning ("%s qualifier ignored on asm",
754 IDENTIFIER_POINTER (cv_qualifier));
755 expand_asm (string);
758 finish_stmt ();
762 /* Finish a parenthesized expression EXPR. */
764 tree
765 finish_parenthesized_expr (expr)
766 tree expr;
768 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
769 /* This inhibits warnings in truthvalue_conversion. */
770 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
772 return expr;
775 /* Begin a statement-expression. The value returned must be passed to
776 finish_stmt_expr. */
778 tree
779 begin_stmt_expr ()
781 keep_next_level ();
782 /* If we're processing_template_decl, then the upcoming compound
783 statement will be chained onto the tree structure, starting at
784 last_tree. We return last_tree so that we can later unhook the
785 compound statement. */
786 return processing_template_decl ? last_tree : expand_start_stmt_expr();
789 /* Finish a statement-expression. RTL_EXPR should be the value
790 returned by the previous begin_stmt_expr; EXPR is the
791 statement-expression. Returns an expression representing the
792 statement-expression. */
794 tree
795 finish_stmt_expr (rtl_expr, expr)
796 tree rtl_expr;
797 tree expr;
799 tree result;
801 if (!processing_template_decl)
803 rtl_expr = expand_end_stmt_expr (rtl_expr);
804 /* The statements have side effects, so the group does. */
805 TREE_SIDE_EFFECTS (rtl_expr) = 1;
808 if (TREE_CODE (expr) == BLOCK)
810 /* Make a BIND_EXPR for the BLOCK already made. */
811 if (processing_template_decl)
812 result = build (BIND_EXPR, NULL_TREE,
813 NULL_TREE, last_tree, expr);
814 else
815 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
816 NULL_TREE, rtl_expr, expr);
818 /* Remove the block from the tree at this point.
819 It gets put back at the proper place
820 when the BIND_EXPR is expanded. */
821 delete_block (expr);
823 else
824 result = expr;
826 if (processing_template_decl)
828 /* Remove the compound statement from the tree structure; it is
829 now saved in the BIND_EXPR. */
830 last_tree = rtl_expr;
831 TREE_CHAIN (last_tree) = NULL_TREE;
834 return result;
837 /* Finish a call to FN with ARGS. Returns a representation of the
838 call. */
840 tree
841 finish_call_expr (fn, args)
842 tree fn;
843 tree args;
845 tree result = build_x_function_call (fn, args, current_class_ref);
847 if (TREE_CODE (result) == CALL_EXPR
848 && TREE_TYPE (result) != void_type_node)
849 result = require_complete_type (result);
851 return result;
854 /* Finish a call to a postfix increment or decrement or EXPR. (Which
855 is indicated by CODE, which should be POSTINCREMENT_EXPR or
856 POSTDECREMENT_EXPR.) */
858 tree
859 finish_increment_expr (expr, code)
860 tree expr;
861 enum tree_code code;
863 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
864 a COMPONENT_REF). This way if we've got, say, a reference to a
865 static member that's being operated on, we don't end up trying to
866 find a member operator for the class it's in. */
868 if (TREE_CODE (expr) == OFFSET_REF)
869 expr = resolve_offset_ref (expr);
870 return build_x_unary_op (code, expr);
873 /* Finish a use of `this'. Returns an expression for `this'. */
875 tree
876 finish_this_expr ()
878 tree result;
880 if (current_class_ptr)
882 #ifdef WARNING_ABOUT_CCD
883 TREE_USED (current_class_ptr) = 1;
884 #endif
885 result = current_class_ptr;
887 else if (current_function_decl
888 && DECL_STATIC_FUNCTION_P (current_function_decl))
890 error ("`this' is unavailable for static member functions");
891 result = error_mark_node;
893 else
895 if (current_function_decl)
896 error ("invalid use of `this' in non-member function");
897 else
898 error ("invalid use of `this' at top level");
899 result = error_mark_node;
902 return result;
905 /* Finish a member function call using OBJECT and ARGS as arguments to
906 FN. Returns an expression for the call. */
908 tree
909 finish_object_call_expr (fn, object, args)
910 tree fn;
911 tree object;
912 tree args;
914 #if 0
915 /* This is a future direction of this code, but because
916 build_x_function_call cannot always undo what is done in
917 build_component_ref entirely yet, we cannot do this. */
919 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
920 return finish_call_expr (real_fn, args);
921 #else
922 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
923 #endif
926 /* Finish a qualified member function call using OBJECT and ARGS as
927 arguments to FN. Returns an expressino for the call. */
929 tree
930 finish_qualified_object_call_expr (fn, object, args)
931 tree fn;
932 tree object;
933 tree args;
935 if (IS_SIGNATURE (TREE_OPERAND (fn, 0)))
937 warning ("signature name in scope resolution ignored");
938 return finish_object_call_expr (TREE_OPERAND (fn, 1), object, args);
940 else
941 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
942 TREE_OPERAND (fn, 1), args);
945 /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
946 being the scope, if any, of DESTRUCTOR. Returns an expression for
947 the call. */
949 tree
950 finish_pseudo_destructor_call_expr (object, scope, destructor)
951 tree object;
952 tree scope;
953 tree destructor;
955 if (scope && scope != destructor)
956 cp_error ("destructor specifier `%T::~%T()' must have matching names",
957 scope, destructor);
959 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
960 && (TREE_CODE (TREE_TYPE (object)) !=
961 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
962 cp_error ("`%E' is not of type `%T'", object, destructor);
964 return cp_convert (void_type_node, object);
967 /* Finish a call to a globally qualified member function FN using
968 ARGS. Returns an expression for the call. */
970 tree
971 finish_globally_qualified_member_call_expr (fn, args)
972 tree fn;
973 tree args;
975 if (processing_template_decl)
976 return build_min_nt (CALL_EXPR, copy_to_permanent (fn), args,
977 NULL_TREE);
978 else
979 return build_member_call (TREE_OPERAND (fn, 0),
980 TREE_OPERAND (fn, 1),
981 args);
984 /* Finish an expression taking the address of LABEL. Returns an
985 expression for the address. */
987 tree
988 finish_label_address_expr (label)
989 tree label;
991 tree result;
993 label = lookup_label (label);
994 if (label == NULL_TREE)
995 result = null_pointer_node;
996 else
998 TREE_USED (label) = 1;
999 result = build1 (ADDR_EXPR, ptr_type_node, label);
1000 TREE_CONSTANT (result) = 1;
1003 return result;
1006 /* Finish an expression of the form CODE EXPR. */
1008 tree
1009 finish_unary_op_expr (code, expr)
1010 enum tree_code code;
1011 tree expr;
1013 tree result = build_x_unary_op (code, expr);
1014 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST)
1015 TREE_NEGATED_INT (result) = 1;
1016 overflow_warning (result);
1017 return result;
1020 /* Finish an id-expression. */
1022 tree
1023 finish_id_expr (expr)
1024 tree expr;
1026 if (TREE_CODE (expr) == IDENTIFIER_NODE)
1027 expr = do_identifier (expr, 1);
1029 return expr;
1032 /* Begin a new-placement. */
1035 begin_new_placement ()
1037 /* The arguments to a placement new might be passed to a
1038 deallocation function, in the event that the allocation throws an
1039 exception. Since we don't expand exception handlers until the
1040 end of a function, we must make sure the arguments stay around
1041 that long. */
1042 return suspend_momentary ();
1045 /* Finish a new-placement. The ARGS are the placement arguments. The
1046 COOKIE is the value returned by the previous call to
1047 begin_new_placement. */
1049 tree
1050 finish_new_placement (args, cookie)
1051 tree args;
1052 int cookie;
1054 resume_momentary (cookie);
1055 return args;
1058 /* Begin a function defniition declared with DECL_SPECS and
1059 DECLARATOR. Returns non-zero if the function-declaration is
1060 legal. */
1063 begin_function_definition (decl_specs, declarator)
1064 tree decl_specs;
1065 tree declarator;
1067 tree specs;
1068 tree attrs;
1069 split_specs_attrs (decl_specs, &specs, &attrs);
1070 if (!start_function (specs, declarator, attrs, 0))
1071 return 0;
1073 reinit_parse_for_function ();
1074 return 1;
1077 /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1078 a SCOPE_REF. */
1080 tree
1081 begin_constructor_declarator (scope, name)
1082 tree scope;
1083 tree name;
1085 tree result = build_parse_node (SCOPE_REF, scope, name);
1087 if (scope != current_class_type)
1089 push_nested_class (scope, 3);
1090 TREE_COMPLEXITY (result) = current_class_depth;
1093 return result;
1096 /* Finish an init-declarator. Returns a DECL. */
1098 tree
1099 finish_declarator (declarator, declspecs, attributes,
1100 prefix_attributes, initialized)
1101 tree declarator;
1102 tree declspecs;
1103 tree attributes;
1104 tree prefix_attributes;
1105 int initialized;
1107 return start_decl (declarator, declspecs, initialized, attributes,
1108 prefix_attributes);
1111 /* Finish a transltation unit. */
1113 void
1114 finish_translation_unit ()
1116 /* In case there were missing closebraces,
1117 get us back to the global binding level. */
1118 while (! toplevel_bindings_p ())
1119 poplevel (0, 0, 0);
1120 while (current_namespace != global_namespace)
1121 pop_namespace ();
1122 finish_file ();
1125 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
1126 Returns the parameter. */
1128 tree
1129 finish_template_type_parm (aggr, identifier)
1130 tree aggr;
1131 tree identifier;
1133 if (aggr == signature_type_node)
1134 sorry ("signature as template type parameter");
1135 else if (aggr != class_type_node)
1137 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1138 aggr = class_type_node;
1141 return build_tree_list (aggr, identifier);
1144 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
1145 Returns the parameter. */
1147 tree
1148 finish_template_template_parm (aggr, identifier)
1149 tree aggr;
1150 tree identifier;
1152 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1153 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1154 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1155 DECL_TEMPLATE_RESULT (tmpl) = decl;
1156 SET_DECL_ARTIFICIAL (decl);
1157 end_template_decl ();
1159 return finish_template_type_parm (aggr, tmpl);
1162 /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is
1163 non-zero, the parameter list was terminated by a `...'. */
1165 tree
1166 finish_parmlist (parms, ellipsis)
1167 tree parms;
1168 int ellipsis;
1170 if (!ellipsis)
1171 chainon (parms, void_list_node);
1172 /* We mark the PARMS as a parmlist so that declarator processing can
1173 disambiguate certain constructs. */
1174 if (parms != NULL_TREE)
1175 TREE_PARMLIST (parms) = 1;
1177 return parms;
1180 /* Begin a class definition, as indicated by T. */
1182 tree
1183 begin_class_definition (t)
1184 tree t;
1186 tree new_type = t;
1188 push_obstacks_nochange ();
1189 end_temporary_allocation ();
1191 if (t == error_mark_node
1192 || ! IS_AGGR_TYPE (t))
1194 t = new_type = make_lang_type (RECORD_TYPE);
1195 pushtag (make_anon_name (), t, 0);
1197 if (TYPE_SIZE (t))
1198 duplicate_tag_error (t);
1199 if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
1201 t = make_lang_type (TREE_CODE (t));
1202 pushtag (TYPE_IDENTIFIER (t), t, 0);
1203 new_type = t;
1205 if (processing_template_decl && TYPE_CONTEXT (t)
1206 && TREE_CODE (TYPE_CONTEXT (t)) != NAMESPACE_DECL
1207 && ! current_class_type)
1208 push_template_decl (TYPE_STUB_DECL (t));
1209 pushclass (t, 0);
1210 TYPE_BEING_DEFINED (t) = 1;
1211 if (IS_AGGR_TYPE (t) && CLASSTYPE_USE_TEMPLATE (t))
1213 if (CLASSTYPE_IMPLICIT_INSTANTIATION (t)
1214 && TYPE_SIZE (t) == NULL_TREE)
1216 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (t);
1217 if (processing_template_decl)
1218 push_template_decl (TYPE_MAIN_DECL (t));
1220 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (t))
1221 cp_error ("specialization after instantiation of `%T'", t);
1223 /* Reset the interface data, at the earliest possible
1224 moment, as it might have been set via a class foo;
1225 before. */
1226 /* Don't change signatures. */
1227 if (! IS_SIGNATURE (t))
1229 extern tree pending_vtables;
1230 int needs_writing;
1231 tree name = TYPE_IDENTIFIER (t);
1233 if (! ANON_AGGRNAME_P (name))
1235 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
1236 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
1237 (t, interface_unknown);
1240 /* Record how to set the access of this class's
1241 virtual functions. If write_virtuals == 2 or 3, then
1242 inline virtuals are ``extern inline''. */
1243 switch (write_virtuals)
1245 case 0:
1246 case 1:
1247 needs_writing = 1;
1248 break;
1249 case 2:
1250 needs_writing = !! value_member (name, pending_vtables);
1251 break;
1252 case 3:
1253 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
1254 && CLASSTYPE_INTERFACE_KNOWN (t);
1255 break;
1256 default:
1257 needs_writing = 0;
1259 CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
1261 #if 0
1262 t = TYPE_IDENTIFIER ($<ttype>0);
1263 if (t && IDENTIFIER_TEMPLATE (t))
1264 overload_template_name (t, 1);
1265 #endif
1266 reset_specialization();
1268 /* In case this is a local class within a template
1269 function, we save the current tree structure so
1270 that we can get it back later. */
1271 begin_tree ();
1273 return new_type;
1276 /* Finish a class definition T, with the indicated COMPONENTS, and
1277 with the indicate ATTRIBUTES. If SEMI, the definition is
1278 immediately followed by a semicolon. Returns the type. */
1280 tree
1281 finish_class_definition (t, components, attributes, semi)
1282 tree t;
1283 tree components;
1284 tree attributes;
1285 int semi;
1287 #if 0
1288 /* Need to rework class nesting in the presence of nested classes,
1289 etc. */
1290 shadow_tag (CLASSTYPE_AS_LIST (t)); */
1291 #endif
1293 /* finish_struct nukes this anyway; if finish_exception does too,
1294 then it can go. */
1295 if (semi)
1296 note_got_semicolon (t);
1298 if (TREE_CODE (t) == ENUMERAL_TYPE)
1300 else
1302 t = finish_struct (t, components, attributes, semi);
1303 if (semi)
1304 note_got_semicolon (t);
1307 pop_obstacks ();
1309 if (! semi)
1310 check_for_missing_semicolon (t);
1311 if (current_scope () == current_function_decl)
1312 do_pending_defargs ();
1314 return t;
1317 /* Finish processing the default argument expressions cached during
1318 the processing of a class definition. */
1320 void
1321 finish_default_args ()
1323 if (pending_inlines
1324 && current_scope () == current_function_decl)
1325 do_pending_inlines ();
1328 /* Finish processing the inline function definitions cached during the
1329 processing of a class definition. */
1331 void
1332 begin_inline_definitions ()
1334 if (current_class_type == NULL_TREE)
1335 clear_inline_text_obstack ();
1337 /* Undo the begin_tree in begin_class_definition. */
1338 end_tree ();