]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/semantics.c
typeck.c (build_c_cast): Don't decay arrays and functions to pointer type when conver...
[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{
69 if (!processing_template_decl)
70 {
71 emit_line_note (input_filename, lineno);
72 /* Do default conversion if safe and possibly important,
73 in case within ({...}). */
74 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
75 && lvalue_p (expr))
76 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
77 expr = default_conversion (expr);
78 }
79
80 cplus_expand_expr_stmt (expr);
81 clear_momentary ();
82 finish_stmt ();
83}
84
85/* Begin an if-statement. Returns a newly created IF_STMT if
86 appropriate. */
87
88tree
89begin_if_stmt ()
90{
91 tree r;
92
93 if (processing_template_decl)
94 {
95 r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
96 add_tree (r);
97 }
98 else
99 r = NULL_TREE;
100
101 do_pushlevel ();
102
103 return r;
104}
105
106/* Process the COND of an if-statement, which may be given by
107 IF_STMT. */
108
109void
110finish_if_stmt_cond (cond, if_stmt)
111 tree cond;
112 tree if_stmt;
113{
114 if (processing_template_decl)
115 {
116 if (last_tree != if_stmt)
117 RECHAIN_STMTS_FROM_LAST (if_stmt, IF_COND (if_stmt));
118 else
119 IF_COND (if_stmt) = cond;
120 }
121 else
122 {
123 emit_line_note (input_filename, lineno);
124 expand_start_cond (condition_conversion (cond), 0);
125 }
126}
127
128/* Finish the then-clause of an if-statement, which may be given by
129 IF_STMT. */
130
131tree
132finish_then_clause (if_stmt)
133 tree if_stmt;
134{
135 if (processing_template_decl)
136 {
137 RECHAIN_STMTS_FROM_CHAIN (if_stmt,
138 THEN_CLAUSE (if_stmt));
139 last_tree = if_stmt;
140 return if_stmt;
141 }
142 else
143 return NULL_TREE;
144}
145
146/* Begin the else-clause of an if-statement. */
147
148void
149begin_else_clause ()
150{
151 if (!processing_template_decl)
152 expand_start_else ();
153}
154
155/* Finish the else-clause of an if-statement, which may be given by
156 IF_STMT. */
157
158void
159finish_else_clause (if_stmt)
160 tree if_stmt;
161{
162 if (processing_template_decl)
163 RECHAIN_STMTS_FROM_CHAIN (if_stmt, ELSE_CLAUSE (if_stmt));
164}
165
166/* Finsh an if-statement. */
167
168void
169finish_if_stmt ()
170{
171 if (!processing_template_decl)
172 expand_end_cond ();
173
174 do_poplevel ();
175 finish_stmt ();
176}
177
178/* Begin a while-statement. Returns a newly created WHILE_STMT if
179 appropriate. */
180
181tree
182begin_while_stmt ()
183{
184 tree r;
185
186 if (processing_template_decl)
187 {
188 r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE);
189 add_tree (r);
190 }
191 else
192 {
193 emit_nop ();
194 emit_line_note (input_filename, lineno);
195 expand_start_loop (1);
196 r = NULL_TREE;
197 }
198
199 do_pushlevel ();
200
201 return r;
202}
203
204/* Process the COND of an if-statement, which may be given by
205 WHILE_STMT. */
206
207void
208finish_while_stmt_cond (cond, while_stmt)
209 tree cond;
210 tree while_stmt;
211{
212 if (processing_template_decl)
213 {
214 if (last_tree != while_stmt)
215 RECHAIN_STMTS_FROM_LAST (while_stmt,
216 WHILE_COND (while_stmt));
217 else
218 TREE_OPERAND (while_stmt, 0) = cond;
219 }
220 else
221 {
222 emit_line_note (input_filename, lineno);
223 expand_exit_loop_if_false (0, condition_conversion (cond));
224 }
225
226 /* If COND wasn't a declaration, clear out the
227 block we made for it and start a new one here so the
228 optimization in expand_end_loop will work. */
229 if (getdecls () == NULL_TREE)
230 {
231 do_poplevel ();
232 do_pushlevel ();
233 }
234}
235
236/* Finish a while-statement, which may be given by WHILE_STMT. */
237
238void
239finish_while_stmt (while_stmt)
240 tree while_stmt;
241{
242 do_poplevel ();
243
244 if (processing_template_decl)
245 RECHAIN_STMTS_FROM_CHAIN (while_stmt, WHILE_BODY (while_stmt));
246 else
247 expand_end_loop ();
248 finish_stmt ();
249}
250
251/* Begin a do-statement. Returns a newly created DO_STMT if
252 appropriate. */
253
254tree
255begin_do_stmt ()
256{
257 if (processing_template_decl)
258 {
259 tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE);
260 add_tree (r);
261 return r;
262 }
263 else
264 {
265 emit_nop ();
266 emit_line_note (input_filename, lineno);
267 expand_start_loop_continue_elsewhere (1);
268 return NULL_TREE;
269 }
270}
271
272/* Finish the body of a do-statement, which may be given by DO_STMT. */
273
274void
275finish_do_body (do_stmt)
276 tree do_stmt;
277{
278 if (processing_template_decl)
279 RECHAIN_STMTS_FROM_CHAIN (do_stmt, DO_BODY (do_stmt));
280 else
281 expand_loop_continue_here ();
282}
283
284/* Finish a do-statement, which may be given by DO_STMT, and whose
285 COND is as indicated. */
286
287void
288finish_do_stmt (cond, do_stmt)
289 tree cond;
290 tree do_stmt;
291{
292 if (processing_template_decl)
293 DO_COND (do_stmt) = cond;
294 else
295 {
296 emit_line_note (input_filename, lineno);
297 expand_exit_loop_if_false (0, condition_conversion (cond));
298 expand_end_loop ();
299 }
300
301 clear_momentary ();
302 finish_stmt ();
303}
304
305/* Finish a return-statement. The EXPRESSION returned, if any, is as
306 indicated. */
307
308void
309finish_return_stmt (expr)
310 tree expr;
311{
312 emit_line_note (input_filename, lineno);
313 c_expand_return (expr);
314 finish_stmt ();
315}
316
317/* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
318
319tree
320begin_for_stmt ()
321{
322 tree r;
323
324 if (processing_template_decl)
325 {
326 r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE,
327 NULL_TREE, NULL_TREE);
328 add_tree (r);
329 }
330 else
331 r = NULL_TREE;
332
333 if (flag_new_for_scope > 0)
334 {
335 do_pushlevel ();
336 note_level_for_for ();
337 }
338
339 return r;
340}
341
342/* Finish the for-init-statement of a for-statement, which may be
343 given by FOR_STMT. */
344
345void
346finish_for_init_stmt (for_stmt)
347 tree for_stmt;
348{
349 if (processing_template_decl)
350 {
351 if (last_tree != for_stmt)
352 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_INIT_STMT (for_stmt));
353 }
354 else
355 {
356 emit_nop ();
357 emit_line_note (input_filename, lineno);
358 expand_start_loop_continue_elsewhere (1);
359 }
360
361 do_pushlevel ();
362}
363
364/* Finish the COND of a for-statement, which may be given by
365 FOR_STMT. */
366
367void
368finish_for_cond (cond, for_stmt)
369 tree cond;
370 tree for_stmt;
371{
372 if (processing_template_decl)
373 {
374 if (last_tree != for_stmt)
375 RECHAIN_STMTS_FROM_LAST (for_stmt, FOR_COND (for_stmt));
376 else
377 FOR_COND (for_stmt) = cond;
378 }
379 else
380 {
381 emit_line_note (input_filename, lineno);
382 if (cond)
383 expand_exit_loop_if_false (0, cond);
384 }
385
386 /* If the cond wasn't a declaration, clear out the
387 block we made for it and start a new one here so the
388 optimization in expand_end_loop will work. */
389 if (getdecls () == NULL_TREE)
390 {
391 do_poplevel ();
392 do_pushlevel ();
393 }
394}
395
396/* Finish the increment-EXPRESSION in a for-statement, which may be
397 given by FOR_STMT. */
398
399void
400finish_for_expr (expr, for_stmt)
401 tree expr;
402 tree for_stmt;
403{
404 if (processing_template_decl)
405 FOR_EXPR (for_stmt) = expr;
406
407 /* Don't let the tree nodes for EXPR be discarded
408 by clear_momentary during the parsing of the next stmt. */
409 push_momentary ();
410}
411
412/* Finish the body of a for-statement, which may be given by
413 FOR_STMT. The increment-EXPR for the loop must be
414 provided. */
415
416void
417finish_for_stmt (expr, for_stmt)
418 tree expr;
419 tree for_stmt;
420{
421 /* Pop the scope for the body of the loop. */
422 do_poplevel ();
423
424 if (processing_template_decl)
425 RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_BODY (for_stmt));
426 else
427 {
428 emit_line_note (input_filename, lineno);
429 expand_loop_continue_here ();
430 if (expr)
431 cplus_expand_expr_stmt (expr);
432 expand_end_loop ();
433 }
434
435 pop_momentary ();
436
437 if (flag_new_for_scope > 0)
438 do_poplevel ();
439
440 finish_stmt ();
441}
442
443/* Finish a break-statement. */
444
445void
446finish_break_stmt ()
447{
448 emit_line_note (input_filename, lineno);
449 if (processing_template_decl)
450 add_tree (build_min_nt (BREAK_STMT));
451 else if ( ! expand_exit_something ())
452 cp_error ("break statement not within loop or switch");
453}
454
455/* Finish a continue-statement. */
456
457void
458finish_continue_stmt ()
459{
460 emit_line_note (input_filename, lineno);
461 if (processing_template_decl)
462 add_tree (build_min_nt (CONTINUE_STMT));
463 else if (! expand_continue_loop (0))
464 cp_error ("continue statement not within a loop");
465}
466
467/* Begin a switch-statement. */
468
469void
470begin_switch_stmt ()
471{
472 do_pushlevel ();
473}
474
475/* Finish the cond of a switch-statement. Returns a new
476 SWITCH_STMT if appropriate. */
477
478tree
479finish_switch_cond (cond)
480 tree cond;
481{
482 tree r;
483
484 if (processing_template_decl)
485 {
486 r = build_min_nt (SWITCH_STMT, cond, NULL_TREE);
487 add_tree (r);
488 }
489 else
490 {
491 emit_line_note (input_filename, lineno);
492 c_expand_start_case (cond);
493 r = NULL_TREE;
494 }
495 push_switch ();
496
497 /* Don't let the tree nodes for COND be discarded by
498 clear_momentary during the parsing of the next stmt. */
499 push_momentary ();
500
501 return r;
502}
503
504/* Finish the body of a switch-statement, which may be given by
505 SWITCH_STMT. The COND to switch on is indicated. */
506
507void
508finish_switch_stmt (cond, switch_stmt)
509 tree cond;
510 tree switch_stmt;
511{
512 if (processing_template_decl)
513 RECHAIN_STMTS_FROM_CHAIN (switch_stmt, SWITCH_BODY (switch_stmt));
514 else
515 expand_end_case (cond);
516 pop_momentary ();
517 pop_switch ();
518 do_poplevel ();
519 finish_stmt ();
520}
521
522/* Finish a case-label. */
523
524void
525finish_case_label (low_value, high_value)
526 tree low_value;
527 tree high_value;
528{
529 do_case (low_value, high_value);
530}
531
532
533/* Finish a goto-statement. */
534
535void
536finish_goto_stmt (destination)
537 tree destination;
538{
539 if (processing_template_decl)
540 add_tree (build_min_nt (GOTO_STMT, destination));
541 else
542 {
543 emit_line_note (input_filename, lineno);
544
545 if (TREE_CODE (destination) == IDENTIFIER_NODE)
546 {
547 tree decl = lookup_label (destination);
548 TREE_USED (decl) = 1;
549 expand_goto (decl);
550 }
551 else
552 expand_computed_goto (destination);
553 }
554}
555
556/* Begin a try-block. Returns a newly-created TRY_BLOCK if
557 appropriate. */
558
559tree
560begin_try_block ()
561{
562 if (processing_template_decl)
563 {
564 tree r = build_min_nt (TRY_BLOCK, NULL_TREE,
565 NULL_TREE);
566 add_tree (r);
567 return r;
568 }
569 else
570 {
571 emit_line_note (input_filename, lineno);
572 expand_start_try_stmts ();
573 return NULL_TREE;
574 }
575}
576
577/* Finish a try-block, which may be given by TRY_BLOCK. */
578
579void
580finish_try_block (try_block)
581 tree try_block;
582{
583 if (processing_template_decl)
584 RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block));
585 else
586 expand_start_all_catch ();
587}
588
589/* Finish a handler-sequence for a try-block, which may be given by
590 TRY_BLOCK. */
591
592void
593finish_handler_sequence (try_block)
594 tree try_block;
595{
596 if (processing_template_decl)
597 RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block));
598 else
599 expand_end_all_catch ();
600}
601
602/* Begin a handler. Returns a HANDLER if appropriate. */
603
604tree
605begin_handler ()
606{
607 tree r;
608
609 if (processing_template_decl)
610 {
611 r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE);
612 add_tree (r);
613 }
614 else
615 r = NULL_TREE;
616
617 do_pushlevel ();
618
619 return r;
620}
621
622/* Finish the handler-parameters for a handler, which may be given by
623 HANDLER. */
624
625void
626finish_handler_parms (handler)
627 tree handler;
628{
629 if (processing_template_decl)
630 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_PARMS (handler));
631}
632
633/* Finish a handler, which may be given by HANDLER. */
634
635void
636finish_handler (handler)
637 tree handler;
638{
639 if (processing_template_decl)
640 RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_BODY (handler));
641 else
642 expand_end_catch_block ();
643
644 do_poplevel ();
645}
646
647/* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the
648 compound-statement does not define a scope. Returns a new
649 COMPOUND_STMT if appropriate. */
650
651tree
652begin_compound_stmt (has_no_scope)
653 int has_no_scope;
654{
655 tree r;
656
657 if (processing_template_decl)
658 {
659 r = build_min_nt (COMPOUND_STMT, NULL_TREE);
660 add_tree (r);
661 if (has_no_scope)
662 COMPOUND_STMT_NO_SCOPE (r) = 1;
663 }
664 else
665 r = NULL_TREE;
666
667 if (!has_no_scope)
668 do_pushlevel ();
669
670 return r;
671}
672
673
674/* Finish a compound-statement, which may be given by COMPOUND_STMT.
675 If HAS_NO_SCOPE is non-zero, the compound statement does not define
676 a scope. */
677
678tree
679finish_compound_stmt (has_no_scope, compound_stmt)
680 int has_no_scope;
681 tree compound_stmt;
682{
683 tree r;
684
685 if (!has_no_scope)
686 r = do_poplevel ();
687 else
688 r = NULL_TREE;
689
690 if (processing_template_decl)
691 RECHAIN_STMTS_FROM_CHAIN (compound_stmt,
692 COMPOUND_BODY (compound_stmt));
693
694 finish_stmt ();
695
696 return r;
697}
698
699/* Finish an asm-statement, whose components are a CV_QUALIFIER, a
700 STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some
701 CLOBBERS. */
702
703void
704finish_asm_stmt (cv_qualifier, string, output_operands,
705 input_operands, clobbers)
706 tree cv_qualifier;
707 tree string;
708 tree output_operands;
709 tree input_operands;
710 tree clobbers;
711{
712 if (TREE_CHAIN (string))
e6f1275f 713 string = combine_strings (string);
ad321293
MM
714
715 if (processing_template_decl)
716 {
717 tree r = build_min_nt (ASM_STMT, cv_qualifier, string,
718 output_operands, input_operands,
719 clobbers);
720 add_tree (r);
721 }
722 else
723 {
724 emit_line_note (input_filename, lineno);
e6f1275f
JM
725 if (output_operands != NULL_TREE || input_operands != NULL_TREE
726 || clobbers != NULL_TREE)
ad321293
MM
727 {
728 if (cv_qualifier != NULL_TREE
729 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
730 cp_warning ("%s qualifier ignored on asm",
731 IDENTIFIER_POINTER (cv_qualifier));
732
733 c_expand_asm_operands (string, output_operands,
734 input_operands,
735 clobbers,
736 cv_qualifier
737 == ridpointers[(int) RID_VOLATILE],
738 input_filename, lineno);
739 }
740 else
741 {
742 if (cv_qualifier != NULL_TREE)
743 cp_warning ("%s qualifier ignored on asm",
744 IDENTIFIER_POINTER (cv_qualifier));
745 expand_asm (string);
746 }
747
748 finish_stmt ();
749 }
750}
b4c4a9ec
MM
751
752/* Finish a parenthesized expression EXPR. */
753
754tree
755finish_parenthesized_expr (expr)
756 tree expr;
757{
758 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr))))
759 /* This inhibits warnings in truthvalue_conversion. */
760 C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK);
761
762 return expr;
763}
764
b69b1501
MM
765/* Begin a statement-expression. The value returned must be passed to
766 finish_stmt_expr. */
b4c4a9ec
MM
767
768tree
769begin_stmt_expr ()
770{
771 keep_next_level ();
b69b1501
MM
772 /* If we're processing_template_decl, then the upcoming compound
773 statement will be chained onto the tree structure, starting at
774 last_tree. We return last_tree so that we can later unhook the
775 compound statement. */
776 return processing_template_decl ? last_tree : expand_start_stmt_expr();
b4c4a9ec
MM
777}
778
779/* Finish a statement-expression. RTL_EXPR should be the value
780 returned by the previous begin_stmt_expr; EXPR is the
781 statement-expression. Returns an expression representing the
782 statement-expression. */
783
784tree
785finish_stmt_expr (rtl_expr, expr)
786 tree rtl_expr;
787 tree expr;
788{
789 tree result;
790
791 if (!processing_template_decl)
792 {
793 rtl_expr = expand_end_stmt_expr (rtl_expr);
794 /* The statements have side effects, so the group does. */
795 TREE_SIDE_EFFECTS (rtl_expr) = 1;
796 }
797
798 if (TREE_CODE (expr) == BLOCK)
799 {
800 /* Make a BIND_EXPR for the BLOCK already made. */
801 if (processing_template_decl)
802 result = build (BIND_EXPR, NULL_TREE,
803 NULL_TREE, last_tree, expr);
804 else
805 result = build (BIND_EXPR, TREE_TYPE (rtl_expr),
806 NULL_TREE, rtl_expr, expr);
807
808 /* Remove the block from the tree at this point.
809 It gets put back at the proper place
810 when the BIND_EXPR is expanded. */
811 delete_block (expr);
812 }
813 else
814 result = expr;
b69b1501
MM
815
816 if (processing_template_decl)
817 {
818 /* Remove the compound statement from the tree structure; it is
819 now saved in the BIND_EXPR. */
820 last_tree = rtl_expr;
821 TREE_CHAIN (last_tree) = NULL_TREE;
822 }
b4c4a9ec
MM
823
824 return result;
825}
826
827/* Finish a call to FN with ARGS. Returns a representation of the
828 call. */
829
830tree
831finish_call_expr (fn, args)
832 tree fn;
833 tree args;
834{
835 tree result = build_x_function_call (fn, args, current_class_ref);
836
837 if (TREE_CODE (result) == CALL_EXPR
838 && TREE_TYPE (result) != void_type_node)
839 result = require_complete_type (result);
840
841 return result;
842}
843
844/* Finish a call to a postfix increment or decrement or EXPR. (Which
845 is indicated by CODE, which should be POSTINCREMENT_EXPR or
846 POSTDECREMENT_EXPR.) */
847
848tree
849finish_increment_expr (expr, code)
850 tree expr;
851 enum tree_code code;
852{
853 /* If we get an OFFSET_REF, turn it into what it really means (e.g.,
854 a COMPONENT_REF). This way if we've got, say, a reference to a
855 static member that's being operated on, we don't end up trying to
856 find a member operator for the class it's in. */
857
858 if (TREE_CODE (expr) == OFFSET_REF)
859 expr = resolve_offset_ref (expr);
860 return build_x_unary_op (code, expr);
861}
862
863/* Finish a use of `this'. Returns an expression for `this'. */
864
865tree
866finish_this_expr ()
867{
868 tree result;
869
870 if (current_class_ptr)
871 {
872#ifdef WARNING_ABOUT_CCD
873 TREE_USED (current_class_ptr) = 1;
874#endif
875 result = current_class_ptr;
876 }
877 else if (current_function_decl
878 && DECL_STATIC_FUNCTION_P (current_function_decl))
879 {
880 error ("`this' is unavailable for static member functions");
881 result = error_mark_node;
882 }
883 else
884 {
885 if (current_function_decl)
886 error ("invalid use of `this' in non-member function");
887 else
888 error ("invalid use of `this' at top level");
889 result = error_mark_node;
890 }
891
892 return result;
893}
894
895/* Finish a member function call using OBJECT and ARGS as arguments to
896 FN. Returns an expression for the call. */
897
898tree
899finish_object_call_expr (fn, object, args)
900 tree fn;
901 tree object;
902 tree args;
903{
904#if 0
905 /* This is a future direction of this code, but because
906 build_x_function_call cannot always undo what is done in
907 build_component_ref entirely yet, we cannot do this. */
908
909 tree real_fn = build_component_ref (object, fn, NULL_TREE, 1);
910 return finish_call_expr (real_fn, args);
911#else
912 return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL);
913#endif
914}
915
916/* Finish a qualified member function call using OBJECT and ARGS as
917 arguments to FN. Returns an expressino for the call. */
918
919tree
920finish_qualified_object_call_expr (fn, object, args)
921 tree fn;
922 tree object;
923 tree args;
924{
925 if (IS_SIGNATURE (TREE_OPERAND (fn, 0)))
926 {
927 warning ("signature name in scope resolution ignored");
928 return finish_object_call_expr (TREE_OPERAND (fn, 1), object, args);
929 }
930 else
931 return build_scoped_method_call (object, TREE_OPERAND (fn, 0),
932 TREE_OPERAND (fn, 1), args);
933}
934
935/* Finish a pseudo-destructor call expression of OBJECT, with SCOPE
936 being the scope, if any, of DESTRUCTOR. Returns an expression for
937 the call. */
938
939tree
940finish_pseudo_destructor_call_expr (object, scope, destructor)
941 tree object;
942 tree scope;
943 tree destructor;
944{
945 if (scope && scope != destructor)
946 cp_error ("destructor specifier `%T::~%T()' must have matching names",
947 scope, destructor);
948
949 if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor))
950 && (TREE_CODE (TREE_TYPE (object)) !=
951 TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor)))))
952 cp_error ("`%E' is not of type `%T'", object, destructor);
953
954 return cp_convert (void_type_node, object);
955}
956
957/* Finish a call to a globally qualified member function FN using
958 ARGS. Returns an expression for the call. */
959
960tree
961finish_globally_qualified_member_call_expr (fn, args)
962 tree fn;
963 tree args;
964{
965 if (processing_template_decl)
966 return build_min_nt (CALL_EXPR, copy_to_permanent (fn), args,
967 NULL_TREE);
968 else
969 return build_member_call (TREE_OPERAND (fn, 0),
970 TREE_OPERAND (fn, 1),
971 args);
972}
973
974/* Finish an expression taking the address of LABEL. Returns an
975 expression for the address. */
976
977tree
978finish_label_address_expr (label)
979 tree label;
980{
981 tree result;
982
983 label = lookup_label (label);
984 if (label == NULL_TREE)
985 result = null_pointer_node;
986 else
987 {
988 TREE_USED (label) = 1;
989 result = build1 (ADDR_EXPR, ptr_type_node, label);
990 TREE_CONSTANT (result) = 1;
991 }
992
993 return result;
994}
995
996/* Begin a function defniition declared with DECL_SPECS and
997 DECLARATOR. Returns non-zero if the function-declaration is
998 legal. */
999
1000int
1001begin_function_definition (decl_specs, declarator)
1002 tree decl_specs;
1003 tree declarator;
1004{
1005 tree specs;
1006 tree attrs;
1007 split_specs_attrs (decl_specs, &specs, &attrs);
1008 if (!start_function (specs, declarator, attrs, 0))
1009 return 0;
1010
1011 reinit_parse_for_function ();
1012 return 1;
1013}
1014
1015/* Begin a constructor declarator of the form `SCOPE::NAME'. Returns
1016 a SCOPE_REF. */
1017
1018tree
1019begin_constructor_declarator (scope, name)
1020 tree scope;
1021 tree name;
1022{
1023 tree result = build_parse_node (SCOPE_REF, scope, name);
1024
1025 if (scope != current_class_type)
1026 {
1027 push_nested_class (scope, 3);
1028 TREE_COMPLEXITY (result) = current_class_depth;
1029 }
1030
1031 return result;
1032}
1033
1034/* Finish a template type parameter, specified as AGGR IDENTIFIER.
1035 Returns the parameter. */
1036
1037tree
1038finish_template_type_parm (aggr, identifier)
1039 tree aggr;
1040 tree identifier;
1041{
1042 if (aggr == signature_type_node)
1043 sorry ("signature as template type parameter");
1044 else if (aggr != class_type_node)
1045 {
1046 pedwarn ("template type parameters must use the keyword `class' or `typename'");
1047 aggr = class_type_node;
1048 }
1049
1050 return build_tree_list (aggr, identifier);
1051}
1052
1053/* Finish a template template parameter, specified as AGGR IDENTIFIER.
1054 Returns the parameter. */
1055
1056tree
1057finish_template_template_parm (aggr, identifier)
1058 tree aggr;
1059 tree identifier;
1060{
1061 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
1062 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
1063 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
1064 DECL_TEMPLATE_RESULT (tmpl) = decl;
1065 SET_DECL_ARTIFICIAL (decl);
1066 end_template_decl ();
1067
1068 return finish_template_type_parm (aggr, tmpl);
1069}