]>
Commit | Line | Data |
---|---|---|
ad321293 MM |
1 | /* Perform the semantic phase of parsing, i.e., the process of |
2 | building tree structure, checking semantic consistency, and | |
3 | building RTL. These routines are used both during actual parsing | |
4 | and during the instantiation of template functions. | |
5 | ||
4c571114 | 6 | Copyright (C) 1998, 1999 Free Software Foundation, Inc. |
ad321293 MM |
7 | Written by Mark Mitchell (mmitchell@usa.net) based on code found |
8 | formerly in parse.y and pt.c. | |
9 | ||
10 | This file is part of GNU CC. | |
11 | ||
12 | GNU CC is free software; you can redistribute it and/or modify it | |
13 | under the terms of the GNU General Public License as published by | |
14 | the Free Software Foundation; either version 2, or (at your option) | |
15 | any later version. | |
16 | ||
17 | GNU CC is distributed in the hope that it will be useful, but | |
18 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | General Public License for more details. | |
21 | ||
22 | You should have received a copy of the GNU General Public License | |
23 | along with GNU CC; see the file COPYING. If not, write to the Free | |
24 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
25 | 02111-1307, USA. */ | |
26 | ||
27 | #include "config.h" | |
8d052bc7 | 28 | #include "system.h" |
ad321293 MM |
29 | #include "tree.h" |
30 | #include "cp-tree.h" | |
31 | #include "except.h" | |
32 | #include "lex.h" | |
12027a89 | 33 | #include "toplev.h" |
ad321293 MM |
34 | |
35 | /* There routines provide a modular interface to perform many parsing | |
36 | operations. They may therefore be used during actual parsing, or | |
37 | during template instantiation, which may be regarded as a | |
38 | degenerate form of parsing. Since the current g++ parser is | |
39 | lacking in several respects, and will be reimplemented, we are | |
40 | attempting to move most code that is not directly related to | |
41 | parsing into this file; that will make implementing the new parser | |
42 | much easier since it will be able to make use of these routines. */ | |
43 | ||
558475f0 | 44 | static void expand_stmts PROTO((tree)); |
f1dedc31 MM |
45 | static void do_pushlevel PROTO((void)); |
46 | static tree do_poplevel PROTO((void)); | |
558475f0 MM |
47 | |
48 | /* Non-zero if we should generate RTL for functions that we process. | |
49 | When this is zero, we just accumulate tree structure, without | |
50 | interacting with the back end. */ | |
51 | int expanding_p = 1; | |
52 | ||
f1dedc31 MM |
53 | /* Non-zero if we should treat statements as full expressions. In |
54 | particular, this variable is no-zero if at the end of a statement | |
55 | we should destroy any temporaries created during that statement. | |
56 | Similarly, if, at the end of a block, we should destroy any local | |
57 | variables in this block. Normally, this variable is non-zero, | |
58 | since those are the normal semantics of C++. | |
59 | ||
60 | However, in order to represent aggregate initialization code as | |
61 | tree structure, we use statement-expressions. The statements | |
62 | within the statement expression should not result in cleanups being | |
63 | run until the entire enclosing statement is complete. */ | |
64 | int stmts_are_full_exprs_p = 1; | |
65 | ||
558475f0 MM |
66 | /* The type of the last expression-statement we have seen. This is |
67 | required because the type of a statement-expression is the type of | |
68 | the last expression statement. */ | |
69 | tree last_expr_type; | |
70 | ||
ad321293 MM |
71 | /* When parsing a template, LAST_TREE contains the last statement |
72 | parsed. These are chained together through the TREE_CHAIN field, | |
73 | but often need to be re-organized since the parse is performed | |
74 | bottom-up. This macro makes LAST_TREE the indicated SUBSTMT of | |
75 | STMT. */ | |
76 | ||
77 | #define RECHAIN_STMTS(stmt, substmt, last) \ | |
78 | do { \ | |
79 | substmt = last; \ | |
80 | TREE_CHAIN (stmt) = NULL_TREE; \ | |
81 | last_tree = stmt; \ | |
82 | } while (0) | |
83 | ||
84 | #define RECHAIN_STMTS_FROM_LAST(stmt, substmt) \ | |
85 | RECHAIN_STMTS (stmt, substmt, last_tree) | |
86 | ||
87 | #define RECHAIN_STMTS_FROM_CHAIN(stmt, substmt) \ | |
88 | RECHAIN_STMTS (stmt, substmt, TREE_CHAIN (stmt)) | |
89 | ||
90 | /* Finish an expression-statement, whose EXPRESSION is as indicated. */ | |
91 | ||
92 | void | |
93 | finish_expr_stmt (expr) | |
94 | tree expr; | |
95 | { | |
ce4a0391 | 96 | if (expr != NULL_TREE) |
ad321293 | 97 | { |
558475f0 MM |
98 | if (building_stmt_tree ()) |
99 | add_tree (build_min_nt (EXPR_STMT, expr)); | |
100 | else | |
ce4a0391 MM |
101 | { |
102 | emit_line_note (input_filename, lineno); | |
103 | /* Do default conversion if safe and possibly important, | |
104 | in case within ({...}). */ | |
105 | if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE | |
106 | && lvalue_p (expr)) | |
107 | || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE) | |
108 | expr = default_conversion (expr); | |
f1dedc31 MM |
109 | |
110 | if (stmts_are_full_exprs_p) | |
111 | expand_start_target_temps (); | |
112 | ||
558475f0 | 113 | cplus_expand_expr_stmt (expr); |
558475f0 | 114 | |
f1dedc31 MM |
115 | if (stmts_are_full_exprs_p) |
116 | { | |
117 | expand_end_target_temps (); | |
118 | clear_momentary (); | |
119 | } | |
120 | } | |
ad321293 | 121 | } |
ce4a0391 | 122 | |
ad321293 | 123 | finish_stmt (); |
558475f0 MM |
124 | |
125 | /* This was an expression-statement, so we save the type of the | |
126 | expression. */ | |
127 | last_expr_type = expr ? TREE_TYPE (expr) : NULL_TREE; | |
ad321293 MM |
128 | } |
129 | ||
130 | /* Begin an if-statement. Returns a newly created IF_STMT if | |
131 | appropriate. */ | |
132 | ||
133 | tree | |
134 | begin_if_stmt () | |
135 | { | |
136 | tree r; | |
137 | ||
558475f0 | 138 | if (building_stmt_tree ()) |
ad321293 MM |
139 | { |
140 | r = build_min_nt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE); | |
141 | add_tree (r); | |
142 | } | |
143 | else | |
144 | r = NULL_TREE; | |
145 | ||
146 | do_pushlevel (); | |
147 | ||
148 | return r; | |
149 | } | |
150 | ||
151 | /* Process the COND of an if-statement, which may be given by | |
152 | IF_STMT. */ | |
153 | ||
154 | void | |
155 | finish_if_stmt_cond (cond, if_stmt) | |
156 | tree cond; | |
157 | tree if_stmt; | |
158 | { | |
558475f0 | 159 | if (building_stmt_tree ()) |
ad321293 MM |
160 | { |
161 | if (last_tree != if_stmt) | |
162 | RECHAIN_STMTS_FROM_LAST (if_stmt, IF_COND (if_stmt)); | |
163 | else | |
ecfa9fcc | 164 | IF_COND (if_stmt) = copy_to_permanent (cond); |
ad321293 MM |
165 | } |
166 | else | |
167 | { | |
168 | emit_line_note (input_filename, lineno); | |
169 | expand_start_cond (condition_conversion (cond), 0); | |
170 | } | |
171 | } | |
172 | ||
173 | /* Finish the then-clause of an if-statement, which may be given by | |
174 | IF_STMT. */ | |
175 | ||
176 | tree | |
177 | finish_then_clause (if_stmt) | |
178 | tree if_stmt; | |
179 | { | |
558475f0 | 180 | if (building_stmt_tree ()) |
ad321293 MM |
181 | { |
182 | RECHAIN_STMTS_FROM_CHAIN (if_stmt, | |
183 | THEN_CLAUSE (if_stmt)); | |
184 | last_tree = if_stmt; | |
185 | return if_stmt; | |
186 | } | |
187 | else | |
188 | return NULL_TREE; | |
189 | } | |
190 | ||
191 | /* Begin the else-clause of an if-statement. */ | |
192 | ||
193 | void | |
194 | begin_else_clause () | |
195 | { | |
558475f0 | 196 | if (!building_stmt_tree ()) |
ad321293 MM |
197 | expand_start_else (); |
198 | } | |
199 | ||
200 | /* Finish the else-clause of an if-statement, which may be given by | |
201 | IF_STMT. */ | |
202 | ||
203 | void | |
204 | finish_else_clause (if_stmt) | |
205 | tree if_stmt; | |
206 | { | |
558475f0 | 207 | if (building_stmt_tree ()) |
ad321293 MM |
208 | RECHAIN_STMTS_FROM_CHAIN (if_stmt, ELSE_CLAUSE (if_stmt)); |
209 | } | |
210 | ||
211 | /* Finsh an if-statement. */ | |
212 | ||
213 | void | |
214 | finish_if_stmt () | |
215 | { | |
558475f0 | 216 | if (!building_stmt_tree ()) |
ad321293 MM |
217 | expand_end_cond (); |
218 | ||
219 | do_poplevel (); | |
220 | finish_stmt (); | |
221 | } | |
222 | ||
223 | /* Begin a while-statement. Returns a newly created WHILE_STMT if | |
224 | appropriate. */ | |
225 | ||
226 | tree | |
227 | begin_while_stmt () | |
228 | { | |
229 | tree r; | |
230 | ||
558475f0 | 231 | if (building_stmt_tree ()) |
ad321293 MM |
232 | { |
233 | r = build_min_nt (WHILE_STMT, NULL_TREE, NULL_TREE); | |
234 | add_tree (r); | |
235 | } | |
236 | else | |
237 | { | |
238 | emit_nop (); | |
239 | emit_line_note (input_filename, lineno); | |
240 | expand_start_loop (1); | |
241 | r = NULL_TREE; | |
242 | } | |
243 | ||
244 | do_pushlevel (); | |
245 | ||
246 | return r; | |
247 | } | |
248 | ||
249 | /* Process the COND of an if-statement, which may be given by | |
250 | WHILE_STMT. */ | |
251 | ||
252 | void | |
253 | finish_while_stmt_cond (cond, while_stmt) | |
254 | tree cond; | |
255 | tree while_stmt; | |
256 | { | |
558475f0 | 257 | if (building_stmt_tree ()) |
ad321293 MM |
258 | { |
259 | if (last_tree != while_stmt) | |
558475f0 | 260 | RECHAIN_STMTS_FROM_LAST (while_stmt, WHILE_COND (while_stmt)); |
ad321293 | 261 | else |
ecfa9fcc | 262 | TREE_OPERAND (while_stmt, 0) = copy_to_permanent (cond); |
ad321293 MM |
263 | } |
264 | else | |
265 | { | |
266 | emit_line_note (input_filename, lineno); | |
267 | expand_exit_loop_if_false (0, condition_conversion (cond)); | |
268 | } | |
269 | ||
270 | /* If COND wasn't a declaration, clear out the | |
271 | block we made for it and start a new one here so the | |
272 | optimization in expand_end_loop will work. */ | |
273 | if (getdecls () == NULL_TREE) | |
274 | { | |
275 | do_poplevel (); | |
276 | do_pushlevel (); | |
277 | } | |
278 | } | |
279 | ||
280 | /* Finish a while-statement, which may be given by WHILE_STMT. */ | |
281 | ||
282 | void | |
283 | finish_while_stmt (while_stmt) | |
284 | tree while_stmt; | |
285 | { | |
286 | do_poplevel (); | |
287 | ||
558475f0 | 288 | if (building_stmt_tree ()) |
ad321293 MM |
289 | RECHAIN_STMTS_FROM_CHAIN (while_stmt, WHILE_BODY (while_stmt)); |
290 | else | |
291 | expand_end_loop (); | |
292 | finish_stmt (); | |
293 | } | |
294 | ||
295 | /* Begin a do-statement. Returns a newly created DO_STMT if | |
296 | appropriate. */ | |
297 | ||
298 | tree | |
299 | begin_do_stmt () | |
300 | { | |
558475f0 | 301 | if (building_stmt_tree ()) |
ad321293 MM |
302 | { |
303 | tree r = build_min_nt (DO_STMT, NULL_TREE, NULL_TREE); | |
304 | add_tree (r); | |
305 | return r; | |
306 | } | |
307 | else | |
308 | { | |
309 | emit_nop (); | |
310 | emit_line_note (input_filename, lineno); | |
311 | expand_start_loop_continue_elsewhere (1); | |
312 | return NULL_TREE; | |
313 | } | |
314 | } | |
315 | ||
316 | /* Finish the body of a do-statement, which may be given by DO_STMT. */ | |
317 | ||
318 | void | |
319 | finish_do_body (do_stmt) | |
320 | tree do_stmt; | |
321 | { | |
558475f0 | 322 | if (building_stmt_tree ()) |
ad321293 MM |
323 | RECHAIN_STMTS_FROM_CHAIN (do_stmt, DO_BODY (do_stmt)); |
324 | else | |
325 | expand_loop_continue_here (); | |
326 | } | |
327 | ||
328 | /* Finish a do-statement, which may be given by DO_STMT, and whose | |
329 | COND is as indicated. */ | |
330 | ||
331 | void | |
332 | finish_do_stmt (cond, do_stmt) | |
333 | tree cond; | |
334 | tree do_stmt; | |
335 | { | |
558475f0 | 336 | if (building_stmt_tree ()) |
ecfa9fcc | 337 | DO_COND (do_stmt) = copy_to_permanent (cond); |
ad321293 MM |
338 | else |
339 | { | |
340 | emit_line_note (input_filename, lineno); | |
341 | expand_exit_loop_if_false (0, condition_conversion (cond)); | |
342 | expand_end_loop (); | |
343 | } | |
344 | ||
345 | clear_momentary (); | |
346 | finish_stmt (); | |
347 | } | |
348 | ||
349 | /* Finish a return-statement. The EXPRESSION returned, if any, is as | |
350 | indicated. */ | |
351 | ||
352 | void | |
353 | finish_return_stmt (expr) | |
354 | tree expr; | |
355 | { | |
558475f0 MM |
356 | if (building_stmt_tree ()) |
357 | add_tree (build_min_nt (RETURN_STMT, expr)); | |
358 | else | |
359 | { | |
360 | emit_line_note (input_filename, lineno); | |
361 | c_expand_return (expr); | |
362 | } | |
363 | ||
ad321293 MM |
364 | finish_stmt (); |
365 | } | |
366 | ||
367 | /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */ | |
368 | ||
369 | tree | |
370 | begin_for_stmt () | |
371 | { | |
372 | tree r; | |
373 | ||
558475f0 | 374 | if (building_stmt_tree ()) |
ad321293 MM |
375 | { |
376 | r = build_min_nt (FOR_STMT, NULL_TREE, NULL_TREE, | |
377 | NULL_TREE, NULL_TREE); | |
378 | add_tree (r); | |
379 | } | |
380 | else | |
381 | r = NULL_TREE; | |
382 | ||
383 | if (flag_new_for_scope > 0) | |
384 | { | |
385 | do_pushlevel (); | |
386 | note_level_for_for (); | |
387 | } | |
388 | ||
389 | return r; | |
390 | } | |
391 | ||
392 | /* Finish the for-init-statement of a for-statement, which may be | |
393 | given by FOR_STMT. */ | |
394 | ||
395 | void | |
396 | finish_for_init_stmt (for_stmt) | |
397 | tree for_stmt; | |
398 | { | |
558475f0 | 399 | if (building_stmt_tree ()) |
ad321293 MM |
400 | { |
401 | if (last_tree != for_stmt) | |
402 | RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_INIT_STMT (for_stmt)); | |
403 | } | |
404 | else | |
405 | { | |
406 | emit_nop (); | |
407 | emit_line_note (input_filename, lineno); | |
408 | expand_start_loop_continue_elsewhere (1); | |
409 | } | |
410 | ||
411 | do_pushlevel (); | |
412 | } | |
413 | ||
414 | /* Finish the COND of a for-statement, which may be given by | |
415 | FOR_STMT. */ | |
416 | ||
417 | void | |
418 | finish_for_cond (cond, for_stmt) | |
419 | tree cond; | |
420 | tree for_stmt; | |
421 | { | |
558475f0 | 422 | if (building_stmt_tree ()) |
ad321293 MM |
423 | { |
424 | if (last_tree != for_stmt) | |
425 | RECHAIN_STMTS_FROM_LAST (for_stmt, FOR_COND (for_stmt)); | |
426 | else | |
ecfa9fcc | 427 | FOR_COND (for_stmt) = copy_to_permanent (cond); |
ad321293 MM |
428 | } |
429 | else | |
430 | { | |
431 | emit_line_note (input_filename, lineno); | |
1dcf683e MM |
432 | if (cond) |
433 | expand_exit_loop_if_false (0, condition_conversion (cond)); | |
ad321293 MM |
434 | } |
435 | ||
436 | /* If the cond wasn't a declaration, clear out the | |
437 | block we made for it and start a new one here so the | |
438 | optimization in expand_end_loop will work. */ | |
439 | if (getdecls () == NULL_TREE) | |
440 | { | |
441 | do_poplevel (); | |
442 | do_pushlevel (); | |
443 | } | |
444 | } | |
445 | ||
446 | /* Finish the increment-EXPRESSION in a for-statement, which may be | |
447 | given by FOR_STMT. */ | |
448 | ||
449 | void | |
450 | finish_for_expr (expr, for_stmt) | |
451 | tree expr; | |
452 | tree for_stmt; | |
453 | { | |
558475f0 MM |
454 | if (building_stmt_tree ()) |
455 | FOR_EXPR (for_stmt) = copy_to_permanent (expr); | |
ad321293 MM |
456 | |
457 | /* Don't let the tree nodes for EXPR be discarded | |
458 | by clear_momentary during the parsing of the next stmt. */ | |
459 | push_momentary (); | |
460 | } | |
461 | ||
462 | /* Finish the body of a for-statement, which may be given by | |
463 | FOR_STMT. The increment-EXPR for the loop must be | |
464 | provided. */ | |
465 | ||
466 | void | |
467 | finish_for_stmt (expr, for_stmt) | |
468 | tree expr; | |
469 | tree for_stmt; | |
470 | { | |
471 | /* Pop the scope for the body of the loop. */ | |
472 | do_poplevel (); | |
473 | ||
558475f0 | 474 | if (building_stmt_tree ()) |
ad321293 MM |
475 | RECHAIN_STMTS_FROM_CHAIN (for_stmt, FOR_BODY (for_stmt)); |
476 | else | |
477 | { | |
478 | emit_line_note (input_filename, lineno); | |
479 | expand_loop_continue_here (); | |
480 | if (expr) | |
f1dedc31 | 481 | finish_expr_stmt (expr); |
ad321293 MM |
482 | expand_end_loop (); |
483 | } | |
484 | ||
485 | pop_momentary (); | |
486 | ||
487 | if (flag_new_for_scope > 0) | |
488 | do_poplevel (); | |
489 | ||
490 | finish_stmt (); | |
491 | } | |
492 | ||
493 | /* Finish a break-statement. */ | |
494 | ||
495 | void | |
496 | finish_break_stmt () | |
497 | { | |
498 | emit_line_note (input_filename, lineno); | |
558475f0 | 499 | if (building_stmt_tree ()) |
ad321293 MM |
500 | add_tree (build_min_nt (BREAK_STMT)); |
501 | else if ( ! expand_exit_something ()) | |
8251199e | 502 | cp_error ("break statement not within loop or switch"); |
ad321293 MM |
503 | } |
504 | ||
505 | /* Finish a continue-statement. */ | |
506 | ||
507 | void | |
508 | finish_continue_stmt () | |
509 | { | |
510 | emit_line_note (input_filename, lineno); | |
558475f0 | 511 | if (building_stmt_tree ()) |
ad321293 MM |
512 | add_tree (build_min_nt (CONTINUE_STMT)); |
513 | else if (! expand_continue_loop (0)) | |
8251199e | 514 | cp_error ("continue statement not within a loop"); |
ad321293 MM |
515 | } |
516 | ||
517 | /* Begin a switch-statement. */ | |
518 | ||
519 | void | |
520 | begin_switch_stmt () | |
521 | { | |
522 | do_pushlevel (); | |
523 | } | |
524 | ||
525 | /* Finish the cond of a switch-statement. Returns a new | |
526 | SWITCH_STMT if appropriate. */ | |
527 | ||
528 | tree | |
529 | finish_switch_cond (cond) | |
530 | tree cond; | |
531 | { | |
532 | tree r; | |
533 | ||
558475f0 | 534 | if (building_stmt_tree ()) |
ad321293 MM |
535 | { |
536 | r = build_min_nt (SWITCH_STMT, cond, NULL_TREE); | |
537 | add_tree (r); | |
538 | } | |
0db982be | 539 | else if (cond != error_mark_node) |
ad321293 MM |
540 | { |
541 | emit_line_note (input_filename, lineno); | |
542 | c_expand_start_case (cond); | |
543 | r = NULL_TREE; | |
544 | } | |
0db982be ML |
545 | else |
546 | { | |
547 | /* The code is in error, but we don't want expand_end_case to | |
548 | crash. */ | |
549 | c_expand_start_case (boolean_false_node); | |
550 | r = NULL_TREE; | |
551 | } | |
552 | ||
ad321293 MM |
553 | push_switch (); |
554 | ||
555 | /* Don't let the tree nodes for COND be discarded by | |
556 | clear_momentary during the parsing of the next stmt. */ | |
557 | push_momentary (); | |
558 | ||
559 | return r; | |
560 | } | |
561 | ||
562 | /* Finish the body of a switch-statement, which may be given by | |
563 | SWITCH_STMT. The COND to switch on is indicated. */ | |
564 | ||
565 | void | |
566 | finish_switch_stmt (cond, switch_stmt) | |
567 | tree cond; | |
568 | tree switch_stmt; | |
569 | { | |
558475f0 | 570 | if (building_stmt_tree ()) |
ad321293 MM |
571 | RECHAIN_STMTS_FROM_CHAIN (switch_stmt, SWITCH_BODY (switch_stmt)); |
572 | else | |
573 | expand_end_case (cond); | |
574 | pop_momentary (); | |
575 | pop_switch (); | |
576 | do_poplevel (); | |
577 | finish_stmt (); | |
578 | } | |
579 | ||
580 | /* Finish a case-label. */ | |
581 | ||
582 | void | |
583 | finish_case_label (low_value, high_value) | |
584 | tree low_value; | |
585 | tree high_value; | |
586 | { | |
558475f0 MM |
587 | if (building_stmt_tree ()) |
588 | { | |
589 | add_tree (build_min_nt (CASE_LABEL, low_value, high_value)); | |
590 | return; | |
591 | } | |
592 | ||
ad321293 MM |
593 | do_case (low_value, high_value); |
594 | } | |
595 | ||
ad321293 MM |
596 | /* Finish a goto-statement. */ |
597 | ||
598 | void | |
599 | finish_goto_stmt (destination) | |
600 | tree destination; | |
601 | { | |
3fa56191 MM |
602 | if (TREE_CODE (destination) == IDENTIFIER_NODE) |
603 | destination = lookup_label (destination); | |
604 | ||
558475f0 | 605 | if (building_stmt_tree ()) |
ad321293 MM |
606 | add_tree (build_min_nt (GOTO_STMT, destination)); |
607 | else | |
608 | { | |
609 | emit_line_note (input_filename, lineno); | |
610 | ||
3fa56191 | 611 | if (TREE_CODE (destination) == LABEL_DECL) |
ad321293 | 612 | { |
3fa56191 MM |
613 | TREE_USED (destination) = 1; |
614 | expand_goto (destination); | |
ad321293 MM |
615 | } |
616 | else | |
617 | expand_computed_goto (destination); | |
618 | } | |
619 | } | |
620 | ||
621 | /* Begin a try-block. Returns a newly-created TRY_BLOCK if | |
622 | appropriate. */ | |
623 | ||
624 | tree | |
625 | begin_try_block () | |
626 | { | |
558475f0 | 627 | if (building_stmt_tree ()) |
ad321293 MM |
628 | { |
629 | tree r = build_min_nt (TRY_BLOCK, NULL_TREE, | |
630 | NULL_TREE); | |
631 | add_tree (r); | |
632 | return r; | |
633 | } | |
634 | else | |
635 | { | |
636 | emit_line_note (input_filename, lineno); | |
637 | expand_start_try_stmts (); | |
638 | return NULL_TREE; | |
639 | } | |
640 | } | |
641 | ||
0dde4175 JM |
642 | /* Likewise, for a function-try-block. */ |
643 | ||
644 | tree | |
645 | begin_function_try_block () | |
646 | { | |
558475f0 | 647 | if (building_stmt_tree ()) |
0dde4175 JM |
648 | { |
649 | tree r = build_min_nt (TRY_BLOCK, NULL_TREE, | |
650 | NULL_TREE); | |
651 | add_tree (r); | |
652 | return r; | |
653 | } | |
654 | else | |
655 | { | |
656 | if (! current_function_parms_stored) | |
657 | store_parm_decls (); | |
658 | expand_start_early_try_stmts (); | |
659 | return NULL_TREE; | |
660 | } | |
661 | } | |
662 | ||
ad321293 MM |
663 | /* Finish a try-block, which may be given by TRY_BLOCK. */ |
664 | ||
665 | void | |
666 | finish_try_block (try_block) | |
667 | tree try_block; | |
668 | { | |
558475f0 | 669 | if (building_stmt_tree ()) |
ad321293 MM |
670 | RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block)); |
671 | else | |
558475f0 | 672 | expand_start_all_catch (); |
ad321293 MM |
673 | } |
674 | ||
f1dedc31 MM |
675 | /* Finish an implicitly generated try-block, with a cleanup is given |
676 | by CLEANUP. */ | |
677 | ||
678 | void | |
679 | finish_cleanup (cleanup, try_block) | |
680 | tree cleanup; | |
681 | tree try_block; | |
682 | { | |
683 | if (building_stmt_tree ()) | |
684 | { | |
685 | TRY_HANDLERS (try_block) = copy_to_permanent (cleanup); | |
686 | CLEANUP_P (try_block) = 1; | |
687 | } | |
688 | else | |
689 | expand_eh_region_end (protect_with_terminate (cleanup)); | |
690 | } | |
691 | ||
0dde4175 JM |
692 | /* Likewise, for a function-try-block. */ |
693 | ||
694 | void | |
695 | finish_function_try_block (try_block) | |
f1dedc31 | 696 | tree try_block; |
0dde4175 | 697 | { |
558475f0 | 698 | if (building_stmt_tree ()) |
0dde4175 JM |
699 | RECHAIN_STMTS_FROM_LAST (try_block, TRY_STMTS (try_block)); |
700 | else | |
701 | { | |
702 | end_protect_partials (); | |
703 | expand_start_all_catch (); | |
704 | in_function_try_handler = 1; | |
705 | } | |
706 | } | |
707 | ||
ad321293 MM |
708 | /* Finish a handler-sequence for a try-block, which may be given by |
709 | TRY_BLOCK. */ | |
710 | ||
711 | void | |
712 | finish_handler_sequence (try_block) | |
713 | tree try_block; | |
714 | { | |
558475f0 | 715 | if (building_stmt_tree ()) |
ad321293 MM |
716 | RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block)); |
717 | else | |
f1dedc31 | 718 | expand_end_all_catch (); |
ad321293 MM |
719 | } |
720 | ||
0dde4175 JM |
721 | /* Likewise, for a function-try-block. */ |
722 | ||
723 | void | |
724 | finish_function_handler_sequence (try_block) | |
725 | tree try_block; | |
726 | { | |
558475f0 | 727 | if (building_stmt_tree ()) |
0dde4175 JM |
728 | RECHAIN_STMTS_FROM_CHAIN (try_block, TRY_HANDLERS (try_block)); |
729 | else | |
730 | { | |
731 | in_function_try_handler = 0; | |
732 | expand_end_all_catch (); | |
733 | } | |
734 | } | |
735 | ||
ad321293 MM |
736 | /* Begin a handler. Returns a HANDLER if appropriate. */ |
737 | ||
738 | tree | |
739 | begin_handler () | |
740 | { | |
741 | tree r; | |
742 | ||
558475f0 | 743 | if (building_stmt_tree ()) |
ad321293 MM |
744 | { |
745 | r = build_min_nt (HANDLER, NULL_TREE, NULL_TREE); | |
746 | add_tree (r); | |
747 | } | |
748 | else | |
749 | r = NULL_TREE; | |
750 | ||
751 | do_pushlevel (); | |
752 | ||
753 | return r; | |
754 | } | |
755 | ||
756 | /* Finish the handler-parameters for a handler, which may be given by | |
757 | HANDLER. */ | |
758 | ||
759 | void | |
760 | finish_handler_parms (handler) | |
761 | tree handler; | |
762 | { | |
558475f0 | 763 | if (building_stmt_tree ()) |
ad321293 MM |
764 | RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_PARMS (handler)); |
765 | } | |
766 | ||
767 | /* Finish a handler, which may be given by HANDLER. */ | |
768 | ||
769 | void | |
770 | finish_handler (handler) | |
771 | tree handler; | |
772 | { | |
558475f0 | 773 | if (building_stmt_tree ()) |
ad321293 MM |
774 | RECHAIN_STMTS_FROM_CHAIN (handler, HANDLER_BODY (handler)); |
775 | else | |
776 | expand_end_catch_block (); | |
777 | ||
778 | do_poplevel (); | |
779 | } | |
780 | ||
781 | /* Begin a compound-statement. If HAS_NO_SCOPE is non-zero, the | |
782 | compound-statement does not define a scope. Returns a new | |
783 | COMPOUND_STMT if appropriate. */ | |
784 | ||
785 | tree | |
786 | begin_compound_stmt (has_no_scope) | |
787 | int has_no_scope; | |
788 | { | |
789 | tree r; | |
790 | ||
558475f0 | 791 | if (building_stmt_tree ()) |
ad321293 MM |
792 | { |
793 | r = build_min_nt (COMPOUND_STMT, NULL_TREE); | |
794 | add_tree (r); | |
795 | if (has_no_scope) | |
796 | COMPOUND_STMT_NO_SCOPE (r) = 1; | |
797 | } | |
798 | else | |
799 | r = NULL_TREE; | |
800 | ||
558475f0 MM |
801 | last_expr_type = NULL_TREE; |
802 | ||
ad321293 MM |
803 | if (!has_no_scope) |
804 | do_pushlevel (); | |
f1dedc31 MM |
805 | else |
806 | /* Normally, we try hard to keep the BLOCK for a | |
807 | statement-expression. But, if it's a statement-expression with | |
808 | a scopeless block, there's nothing to keep, and we don't want | |
809 | to accidentally keep a block *inside* the scopeless block. */ | |
810 | keep_next_level (0); | |
ad321293 MM |
811 | |
812 | return r; | |
813 | } | |
814 | ||
815 | ||
816 | /* Finish a compound-statement, which may be given by COMPOUND_STMT. | |
817 | If HAS_NO_SCOPE is non-zero, the compound statement does not define | |
818 | a scope. */ | |
819 | ||
820 | tree | |
821 | finish_compound_stmt (has_no_scope, compound_stmt) | |
822 | int has_no_scope; | |
823 | tree compound_stmt; | |
824 | { | |
825 | tree r; | |
558475f0 | 826 | tree t; |
ad321293 MM |
827 | |
828 | if (!has_no_scope) | |
829 | r = do_poplevel (); | |
830 | else | |
831 | r = NULL_TREE; | |
832 | ||
558475f0 | 833 | if (building_stmt_tree ()) |
ad321293 MM |
834 | RECHAIN_STMTS_FROM_CHAIN (compound_stmt, |
835 | COMPOUND_BODY (compound_stmt)); | |
836 | ||
558475f0 MM |
837 | /* When we call finish_stmt we will lost LAST_EXPR_TYPE. But, since |
838 | the precise purpose of that variable is store the type of the | |
839 | last expression statement within the last compound statement, we | |
840 | preserve the value. */ | |
841 | t = last_expr_type; | |
ad321293 | 842 | finish_stmt (); |
558475f0 | 843 | last_expr_type = t; |
ad321293 MM |
844 | |
845 | return r; | |
846 | } | |
847 | ||
848 | /* Finish an asm-statement, whose components are a CV_QUALIFIER, a | |
849 | STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some | |
850 | CLOBBERS. */ | |
851 | ||
852 | void | |
853 | finish_asm_stmt (cv_qualifier, string, output_operands, | |
3ebc5c52 | 854 | input_operands, clobbers) |
ad321293 MM |
855 | tree cv_qualifier; |
856 | tree string; | |
857 | tree output_operands; | |
858 | tree input_operands; | |
859 | tree clobbers; | |
860 | { | |
861 | if (TREE_CHAIN (string)) | |
3ebc5c52 | 862 | { |
558475f0 | 863 | if (building_stmt_tree ()) |
9188c363 MM |
864 | /* We need to build the combined string on the permanent |
865 | obstack so that we can use it during instantiations. */ | |
866 | push_permanent_obstack (); | |
3ebc5c52 MM |
867 | |
868 | string = combine_strings (string); | |
869 | ||
558475f0 | 870 | if (building_stmt_tree ()) |
3ebc5c52 MM |
871 | pop_obstacks (); |
872 | } | |
ad321293 | 873 | |
f71f87f9 MM |
874 | if (cv_qualifier != NULL_TREE |
875 | && cv_qualifier != ridpointers[(int) RID_VOLATILE]) | |
876 | { | |
877 | cp_warning ("%s qualifier ignored on asm", | |
878 | IDENTIFIER_POINTER (cv_qualifier)); | |
879 | cv_qualifier = NULL_TREE; | |
880 | } | |
881 | ||
558475f0 | 882 | if (building_stmt_tree ()) |
ad321293 MM |
883 | { |
884 | tree r = build_min_nt (ASM_STMT, cv_qualifier, string, | |
885 | output_operands, input_operands, | |
886 | clobbers); | |
887 | add_tree (r); | |
888 | } | |
889 | else | |
890 | { | |
891 | emit_line_note (input_filename, lineno); | |
6e9438cf AG |
892 | if (output_operands != NULL_TREE || input_operands != NULL_TREE |
893 | || clobbers != NULL_TREE) | |
894 | { | |
7dc5bd62 MM |
895 | tree t; |
896 | ||
7dc5bd62 MM |
897 | for (t = input_operands; t; t = TREE_CHAIN (t)) |
898 | TREE_VALUE (t) = decay_conversion (TREE_VALUE (t)); | |
899 | ||
6e9438cf AG |
900 | c_expand_asm_operands (string, output_operands, |
901 | input_operands, | |
902 | clobbers, | |
f71f87f9 | 903 | cv_qualifier != NULL_TREE, |
6e9438cf AG |
904 | input_filename, lineno); |
905 | } | |
906 | else | |
f71f87f9 | 907 | expand_asm (string); |
a64c757e | 908 | |
ad321293 MM |
909 | finish_stmt (); |
910 | } | |
911 | } | |
b4c4a9ec | 912 | |
f01b0acb MM |
913 | /* Finish a label with the indicated NAME. */ |
914 | ||
915 | void | |
916 | finish_label_stmt (name) | |
917 | tree name; | |
918 | { | |
3fa56191 | 919 | tree decl = define_label (input_filename, lineno, name); |
f01b0acb | 920 | |
558475f0 | 921 | if (building_stmt_tree ()) |
3fa56191 MM |
922 | add_tree (decl); |
923 | else if (decl) | |
924 | expand_label (decl); | |
f01b0acb MM |
925 | } |
926 | ||
9188c363 MM |
927 | /* Create a declaration statement for the declaration given by the |
928 | DECL. */ | |
929 | ||
930 | void | |
931 | add_decl_stmt (decl) | |
932 | tree decl; | |
933 | { | |
934 | tree decl_stmt; | |
935 | ||
936 | /* We need the type to last until instantiation time. */ | |
937 | TREE_TYPE (decl) = copy_to_permanent (TREE_TYPE (decl)); | |
938 | decl_stmt = build_min_nt (DECL_STMT, decl); | |
939 | add_tree (decl_stmt); | |
940 | } | |
941 | ||
f1dedc31 MM |
942 | /* We're in a constructor, and have just constructed a a subobject of |
943 | *THIS. CLEANUP is code to run if an exception is thrown before the | |
944 | end of the current function is reached. */ | |
945 | ||
946 | void | |
947 | finish_subobject (cleanup) | |
948 | tree cleanup; | |
949 | { | |
950 | if (building_stmt_tree ()) | |
951 | { | |
952 | tree r = build_min_nt (SUBOBJECT, cleanup); | |
953 | add_tree (r); | |
954 | } | |
955 | else | |
956 | add_partial_entry (cleanup); | |
957 | } | |
958 | ||
558475f0 MM |
959 | /* Bind a name and initialization to the return value of |
960 | the current function. */ | |
961 | ||
962 | void | |
963 | finish_named_return_value (return_id, init) | |
964 | tree return_id, init; | |
965 | { | |
966 | tree decl = DECL_RESULT (current_function_decl); | |
967 | ||
968 | if (pedantic) | |
969 | /* Give this error as many times as there are occurrences, | |
970 | so that users can use Emacs compilation buffers to find | |
971 | and fix all such places. */ | |
972 | pedwarn ("ANSI C++ does not permit named return values"); | |
973 | ||
974 | if (return_id != NULL_TREE) | |
975 | { | |
976 | if (DECL_NAME (decl) == NULL_TREE) | |
977 | { | |
978 | DECL_NAME (decl) = return_id; | |
979 | DECL_ASSEMBLER_NAME (decl) = return_id; | |
980 | } | |
981 | else | |
982 | { | |
983 | cp_error ("return identifier `%D' already in place", return_id); | |
984 | return; | |
985 | } | |
986 | } | |
987 | ||
988 | /* Can't let this happen for constructors. */ | |
989 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
990 | { | |
991 | error ("can't redefine default return value for constructors"); | |
992 | return; | |
993 | } | |
994 | ||
995 | /* If we have a named return value, put that in our scope as well. */ | |
996 | if (DECL_NAME (decl) != NULL_TREE) | |
997 | { | |
998 | /* Let `cp_finish_decl' know that this initializer is ok. */ | |
999 | DECL_INITIAL (decl) = init; | |
1000 | pushdecl (decl); | |
1001 | ||
1002 | if (building_stmt_tree ()) | |
1003 | add_tree (build_min_nt (RETURN_INIT, return_id, | |
1004 | copy_to_permanent (init))); | |
1005 | else | |
1006 | { | |
1007 | cp_finish_decl (decl, init, NULL_TREE, 0, 0); | |
1008 | store_return_init (decl); | |
1009 | } | |
1010 | } | |
1011 | } | |
1012 | ||
1013 | /* Cache the value of this class's main virtual function table pointer | |
1014 | in a register variable. This will save one indirection if a | |
1015 | more than one virtual function call is made this function. */ | |
1016 | ||
1017 | void | |
1018 | setup_vtbl_ptr () | |
1019 | { | |
1020 | extern tree base_init_expr; | |
1021 | ||
1022 | if (base_init_expr == 0 | |
1023 | && DECL_CONSTRUCTOR_P (current_function_decl)) | |
1024 | { | |
1025 | if (building_stmt_tree ()) | |
1026 | add_tree (build_min_nt | |
1027 | (CTOR_INITIALIZER, | |
1028 | current_member_init_list, current_base_init_list)); | |
1029 | else | |
f1dedc31 | 1030 | emit_base_init (current_class_type); |
558475f0 | 1031 | } |
f1dedc31 MM |
1032 | |
1033 | /* Always keep the BLOCK node associated with the outermost pair of | |
1034 | curley braces of a function. These are needed for correct | |
1035 | operation of dwarfout.c. */ | |
1036 | keep_next_level (1); | |
558475f0 MM |
1037 | } |
1038 | ||
1039 | /* Begin a new scope. */ | |
1040 | ||
f1dedc31 | 1041 | static void |
558475f0 MM |
1042 | do_pushlevel () |
1043 | { | |
1044 | if (!building_stmt_tree ()) | |
1045 | { | |
1046 | emit_line_note (input_filename, lineno); | |
1047 | clear_last_expr (); | |
1048 | } | |
558475f0 | 1049 | push_momentary (); |
f1dedc31 MM |
1050 | if (stmts_are_full_exprs_p) |
1051 | pushlevel (0); | |
1052 | if (!building_stmt_tree () && stmts_are_full_exprs_p) | |
558475f0 | 1053 | expand_start_bindings (0); |
f1dedc31 | 1054 | } |
558475f0 MM |
1055 | |
1056 | /* Finish a scope. */ | |
1057 | ||
f1dedc31 | 1058 | static tree |
558475f0 MM |
1059 | do_poplevel () |
1060 | { | |
1061 | tree t; | |
1062 | ||
f1dedc31 | 1063 | if (!building_stmt_tree () && stmts_are_full_exprs_p) |
558475f0 | 1064 | expand_end_bindings (getdecls (), kept_level_p (), 0); |
f1dedc31 MM |
1065 | if (stmts_are_full_exprs_p) |
1066 | t = poplevel (kept_level_p (), 1, 0); | |
38c7331a MM |
1067 | else |
1068 | t = NULL_TREE; | |
558475f0 MM |
1069 | pop_momentary (); |
1070 | return t; | |
1071 | } | |
1072 | ||
b4c4a9ec MM |
1073 | /* Finish a parenthesized expression EXPR. */ |
1074 | ||
1075 | tree | |
1076 | finish_parenthesized_expr (expr) | |
1077 | tree expr; | |
1078 | { | |
1079 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr)))) | |
1080 | /* This inhibits warnings in truthvalue_conversion. */ | |
1081 | C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK); | |
1082 | ||
1083 | return expr; | |
1084 | } | |
1085 | ||
b69b1501 MM |
1086 | /* Begin a statement-expression. The value returned must be passed to |
1087 | finish_stmt_expr. */ | |
b4c4a9ec MM |
1088 | |
1089 | tree | |
1090 | begin_stmt_expr () | |
1091 | { | |
f1dedc31 | 1092 | keep_next_level (1); |
558475f0 | 1093 | /* If we're building a statement tree, then the upcoming compound |
b69b1501 MM |
1094 | statement will be chained onto the tree structure, starting at |
1095 | last_tree. We return last_tree so that we can later unhook the | |
1096 | compound statement. */ | |
558475f0 | 1097 | return building_stmt_tree () ? last_tree : expand_start_stmt_expr(); |
b4c4a9ec MM |
1098 | } |
1099 | ||
1100 | /* Finish a statement-expression. RTL_EXPR should be the value | |
1101 | returned by the previous begin_stmt_expr; EXPR is the | |
1102 | statement-expression. Returns an expression representing the | |
1103 | statement-expression. */ | |
1104 | ||
1105 | tree | |
1106 | finish_stmt_expr (rtl_expr, expr) | |
1107 | tree rtl_expr; | |
1108 | tree expr; | |
1109 | { | |
1110 | tree result; | |
1111 | ||
558475f0 | 1112 | if (!building_stmt_tree ()) |
b4c4a9ec MM |
1113 | { |
1114 | rtl_expr = expand_end_stmt_expr (rtl_expr); | |
1115 | /* The statements have side effects, so the group does. */ | |
1116 | TREE_SIDE_EFFECTS (rtl_expr) = 1; | |
1117 | } | |
1118 | ||
558475f0 | 1119 | if (building_stmt_tree ()) |
b69b1501 | 1120 | { |
f1dedc31 MM |
1121 | /* If the last thing in the statement-expression was not an |
1122 | expression-statement, then it has type `void'. */ | |
1123 | if (!last_expr_type) | |
1124 | last_expr_type = void_type_node; | |
1125 | result = build_min (STMT_EXPR, last_expr_type, last_tree); | |
1126 | TREE_SIDE_EFFECTS (result) = 1; | |
1127 | ||
b69b1501 | 1128 | /* Remove the compound statement from the tree structure; it is |
558475f0 | 1129 | now saved in the STMT_EXPR. */ |
b69b1501 MM |
1130 | last_tree = rtl_expr; |
1131 | TREE_CHAIN (last_tree) = NULL_TREE; | |
1132 | } | |
f1dedc31 MM |
1133 | else if (expr && TREE_CODE (expr) == BLOCK) |
1134 | { | |
1135 | result = build (BIND_EXPR, TREE_TYPE (rtl_expr), | |
1136 | NULL_TREE, rtl_expr, expr); | |
1137 | delete_block (expr); | |
1138 | } | |
1139 | else | |
1140 | result = rtl_expr; | |
1141 | ||
1142 | if (expr && TREE_CODE (expr) == BLOCK) | |
1143 | /* Remove the block from the tree at this point. It gets put back | |
1144 | at the proper place when the STMT_EXPR or BIND_EXPR is | |
1145 | expanded. */ | |
1146 | delete_block (expr); | |
1147 | ||
b4c4a9ec MM |
1148 | return result; |
1149 | } | |
1150 | ||
1151 | /* Finish a call to FN with ARGS. Returns a representation of the | |
1152 | call. */ | |
1153 | ||
1154 | tree | |
a759e627 | 1155 | finish_call_expr (fn, args, koenig) |
b4c4a9ec MM |
1156 | tree fn; |
1157 | tree args; | |
a759e627 | 1158 | int koenig; |
b4c4a9ec | 1159 | { |
a759e627 ML |
1160 | tree result; |
1161 | ||
1162 | if (koenig) | |
03d82991 JM |
1163 | { |
1164 | if (TREE_CODE (fn) == BIT_NOT_EXPR) | |
1165 | fn = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND (fn, 0)); | |
1166 | else if (TREE_CODE (fn) != TEMPLATE_ID_EXPR) | |
e13a4123 | 1167 | fn = do_identifier (fn, 2, args); |
03d82991 | 1168 | } |
a759e627 | 1169 | result = build_x_function_call (fn, args, current_class_ref); |
b4c4a9ec MM |
1170 | |
1171 | if (TREE_CODE (result) == CALL_EXPR | |
66543169 NS |
1172 | && (! TREE_TYPE (result) |
1173 | || TREE_CODE (TREE_TYPE (result)) != VOID_TYPE)) | |
b4c4a9ec MM |
1174 | result = require_complete_type (result); |
1175 | ||
1176 | return result; | |
1177 | } | |
1178 | ||
1179 | /* Finish a call to a postfix increment or decrement or EXPR. (Which | |
1180 | is indicated by CODE, which should be POSTINCREMENT_EXPR or | |
1181 | POSTDECREMENT_EXPR.) */ | |
1182 | ||
1183 | tree | |
1184 | finish_increment_expr (expr, code) | |
1185 | tree expr; | |
1186 | enum tree_code code; | |
1187 | { | |
1188 | /* If we get an OFFSET_REF, turn it into what it really means (e.g., | |
1189 | a COMPONENT_REF). This way if we've got, say, a reference to a | |
1190 | static member that's being operated on, we don't end up trying to | |
1191 | find a member operator for the class it's in. */ | |
1192 | ||
1193 | if (TREE_CODE (expr) == OFFSET_REF) | |
1194 | expr = resolve_offset_ref (expr); | |
1195 | return build_x_unary_op (code, expr); | |
1196 | } | |
1197 | ||
1198 | /* Finish a use of `this'. Returns an expression for `this'. */ | |
1199 | ||
1200 | tree | |
1201 | finish_this_expr () | |
1202 | { | |
1203 | tree result; | |
1204 | ||
1205 | if (current_class_ptr) | |
1206 | { | |
1207 | #ifdef WARNING_ABOUT_CCD | |
1208 | TREE_USED (current_class_ptr) = 1; | |
1209 | #endif | |
1210 | result = current_class_ptr; | |
1211 | } | |
1212 | else if (current_function_decl | |
1213 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1214 | { | |
8251199e | 1215 | error ("`this' is unavailable for static member functions"); |
b4c4a9ec MM |
1216 | result = error_mark_node; |
1217 | } | |
1218 | else | |
1219 | { | |
1220 | if (current_function_decl) | |
8251199e | 1221 | error ("invalid use of `this' in non-member function"); |
b4c4a9ec | 1222 | else |
8251199e | 1223 | error ("invalid use of `this' at top level"); |
b4c4a9ec MM |
1224 | result = error_mark_node; |
1225 | } | |
1226 | ||
1227 | return result; | |
1228 | } | |
1229 | ||
1230 | /* Finish a member function call using OBJECT and ARGS as arguments to | |
1231 | FN. Returns an expression for the call. */ | |
1232 | ||
1233 | tree | |
1234 | finish_object_call_expr (fn, object, args) | |
1235 | tree fn; | |
1236 | tree object; | |
1237 | tree args; | |
1238 | { | |
1239 | #if 0 | |
1240 | /* This is a future direction of this code, but because | |
1241 | build_x_function_call cannot always undo what is done in | |
1242 | build_component_ref entirely yet, we cannot do this. */ | |
1243 | ||
1244 | tree real_fn = build_component_ref (object, fn, NULL_TREE, 1); | |
1245 | return finish_call_expr (real_fn, args); | |
1246 | #else | |
c68c56f7 MM |
1247 | if (TREE_CODE (fn) == TYPE_DECL) |
1248 | { | |
1249 | if (processing_template_decl) | |
1250 | /* This can happen on code like: | |
1251 | ||
1252 | class X; | |
1253 | template <class T> void f(T t) { | |
1254 | t.X(); | |
1255 | } | |
1256 | ||
1257 | We just grab the underlying IDENTIFIER. */ | |
1258 | fn = DECL_NAME (fn); | |
1259 | else | |
1260 | { | |
8251199e | 1261 | cp_error ("calling type `%T' like a method", fn); |
c68c56f7 MM |
1262 | return error_mark_node; |
1263 | } | |
1264 | } | |
1265 | ||
b4c4a9ec MM |
1266 | return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL); |
1267 | #endif | |
1268 | } | |
1269 | ||
1270 | /* Finish a qualified member function call using OBJECT and ARGS as | |
1271 | arguments to FN. Returns an expressino for the call. */ | |
1272 | ||
1273 | tree | |
1274 | finish_qualified_object_call_expr (fn, object, args) | |
1275 | tree fn; | |
1276 | tree object; | |
1277 | tree args; | |
1278 | { | |
6eabb241 MM |
1279 | return build_scoped_method_call (object, TREE_OPERAND (fn, 0), |
1280 | TREE_OPERAND (fn, 1), args); | |
b4c4a9ec MM |
1281 | } |
1282 | ||
1283 | /* Finish a pseudo-destructor call expression of OBJECT, with SCOPE | |
1284 | being the scope, if any, of DESTRUCTOR. Returns an expression for | |
1285 | the call. */ | |
1286 | ||
1287 | tree | |
1288 | finish_pseudo_destructor_call_expr (object, scope, destructor) | |
1289 | tree object; | |
1290 | tree scope; | |
1291 | tree destructor; | |
1292 | { | |
40242ccf MM |
1293 | if (processing_template_decl) |
1294 | return build_min_nt (PSEUDO_DTOR_EXPR, object, scope, destructor); | |
1295 | ||
b4c4a9ec | 1296 | if (scope && scope != destructor) |
8251199e | 1297 | cp_error ("destructor specifier `%T::~%T()' must have matching names", |
b4c4a9ec MM |
1298 | scope, destructor); |
1299 | ||
1300 | if ((scope == NULL_TREE || IDENTIFIER_GLOBAL_VALUE (destructor)) | |
1301 | && (TREE_CODE (TREE_TYPE (object)) != | |
1302 | TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (destructor))))) | |
8251199e | 1303 | cp_error ("`%E' is not of type `%T'", object, destructor); |
b4c4a9ec MM |
1304 | |
1305 | return cp_convert (void_type_node, object); | |
1306 | } | |
1307 | ||
1308 | /* Finish a call to a globally qualified member function FN using | |
1309 | ARGS. Returns an expression for the call. */ | |
1310 | ||
1311 | tree | |
75d587eb | 1312 | finish_qualified_call_expr (fn, args) |
b4c4a9ec MM |
1313 | tree fn; |
1314 | tree args; | |
1315 | { | |
1316 | if (processing_template_decl) | |
1317 | return build_min_nt (CALL_EXPR, copy_to_permanent (fn), args, | |
1318 | NULL_TREE); | |
1319 | else | |
1320 | return build_member_call (TREE_OPERAND (fn, 0), | |
1321 | TREE_OPERAND (fn, 1), | |
1322 | args); | |
1323 | } | |
1324 | ||
1325 | /* Finish an expression taking the address of LABEL. Returns an | |
1326 | expression for the address. */ | |
1327 | ||
1328 | tree | |
1329 | finish_label_address_expr (label) | |
1330 | tree label; | |
1331 | { | |
1332 | tree result; | |
1333 | ||
1334 | label = lookup_label (label); | |
1335 | if (label == NULL_TREE) | |
1336 | result = null_pointer_node; | |
1337 | else | |
1338 | { | |
1339 | TREE_USED (label) = 1; | |
1340 | result = build1 (ADDR_EXPR, ptr_type_node, label); | |
1341 | TREE_CONSTANT (result) = 1; | |
1342 | } | |
1343 | ||
1344 | return result; | |
1345 | } | |
1346 | ||
ce4a0391 MM |
1347 | /* Finish an expression of the form CODE EXPR. */ |
1348 | ||
1349 | tree | |
1350 | finish_unary_op_expr (code, expr) | |
1351 | enum tree_code code; | |
1352 | tree expr; | |
1353 | { | |
1354 | tree result = build_x_unary_op (code, expr); | |
1355 | if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST) | |
1356 | TREE_NEGATED_INT (result) = 1; | |
1357 | overflow_warning (result); | |
1358 | return result; | |
1359 | } | |
1360 | ||
1361 | /* Finish an id-expression. */ | |
1362 | ||
1363 | tree | |
1364 | finish_id_expr (expr) | |
1365 | tree expr; | |
1366 | { | |
1367 | if (TREE_CODE (expr) == IDENTIFIER_NODE) | |
a759e627 | 1368 | expr = do_identifier (expr, 1, NULL_TREE); |
ce4a0391 MM |
1369 | |
1370 | return expr; | |
1371 | } | |
1372 | ||
1373 | /* Begin a new-placement. */ | |
1374 | ||
1375 | int | |
1376 | begin_new_placement () | |
1377 | { | |
1378 | /* The arguments to a placement new might be passed to a | |
1379 | deallocation function, in the event that the allocation throws an | |
1380 | exception. Since we don't expand exception handlers until the | |
1381 | end of a function, we must make sure the arguments stay around | |
1382 | that long. */ | |
1383 | return suspend_momentary (); | |
1384 | } | |
1385 | ||
1386 | /* Finish a new-placement. The ARGS are the placement arguments. The | |
1387 | COOKIE is the value returned by the previous call to | |
1388 | begin_new_placement. */ | |
1389 | ||
1390 | tree | |
1391 | finish_new_placement (args, cookie) | |
1392 | tree args; | |
1393 | int cookie; | |
1394 | { | |
1395 | resume_momentary (cookie); | |
1396 | return args; | |
1397 | } | |
1398 | ||
b4c4a9ec MM |
1399 | /* Begin a function defniition declared with DECL_SPECS and |
1400 | DECLARATOR. Returns non-zero if the function-declaration is | |
1401 | legal. */ | |
1402 | ||
1403 | int | |
1404 | begin_function_definition (decl_specs, declarator) | |
1405 | tree decl_specs; | |
1406 | tree declarator; | |
1407 | { | |
1408 | tree specs; | |
1409 | tree attrs; | |
1410 | split_specs_attrs (decl_specs, &specs, &attrs); | |
1411 | if (!start_function (specs, declarator, attrs, 0)) | |
1412 | return 0; | |
1413 | ||
1414 | reinit_parse_for_function (); | |
39c01e4c MM |
1415 | /* The things we're about to see are not directly qualified by any |
1416 | template headers we've seen thus far. */ | |
1417 | reset_specialization (); | |
1418 | ||
b4c4a9ec MM |
1419 | return 1; |
1420 | } | |
1421 | ||
1422 | /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns | |
1423 | a SCOPE_REF. */ | |
1424 | ||
1425 | tree | |
1426 | begin_constructor_declarator (scope, name) | |
1427 | tree scope; | |
1428 | tree name; | |
1429 | { | |
1430 | tree result = build_parse_node (SCOPE_REF, scope, name); | |
830fcda8 | 1431 | enter_scope_of (result); |
b4c4a9ec MM |
1432 | return result; |
1433 | } | |
1434 | ||
ce4a0391 MM |
1435 | /* Finish an init-declarator. Returns a DECL. */ |
1436 | ||
1437 | tree | |
1438 | finish_declarator (declarator, declspecs, attributes, | |
1439 | prefix_attributes, initialized) | |
1440 | tree declarator; | |
1441 | tree declspecs; | |
1442 | tree attributes; | |
1443 | tree prefix_attributes; | |
1444 | int initialized; | |
1445 | { | |
1446 | return start_decl (declarator, declspecs, initialized, attributes, | |
1447 | prefix_attributes); | |
1448 | } | |
1449 | ||
8014a339 | 1450 | /* Finish a translation unit. */ |
ce4a0391 MM |
1451 | |
1452 | void | |
1453 | finish_translation_unit () | |
1454 | { | |
1455 | /* In case there were missing closebraces, | |
1456 | get us back to the global binding level. */ | |
1457 | while (! toplevel_bindings_p ()) | |
1458 | poplevel (0, 0, 0); | |
1459 | while (current_namespace != global_namespace) | |
1460 | pop_namespace (); | |
1461 | finish_file (); | |
1462 | } | |
1463 | ||
b4c4a9ec MM |
1464 | /* Finish a template type parameter, specified as AGGR IDENTIFIER. |
1465 | Returns the parameter. */ | |
1466 | ||
1467 | tree | |
1468 | finish_template_type_parm (aggr, identifier) | |
1469 | tree aggr; | |
1470 | tree identifier; | |
1471 | { | |
6eabb241 | 1472 | if (aggr != class_type_node) |
b4c4a9ec | 1473 | { |
8251199e | 1474 | pedwarn ("template type parameters must use the keyword `class' or `typename'"); |
b4c4a9ec MM |
1475 | aggr = class_type_node; |
1476 | } | |
1477 | ||
1478 | return build_tree_list (aggr, identifier); | |
1479 | } | |
1480 | ||
1481 | /* Finish a template template parameter, specified as AGGR IDENTIFIER. | |
1482 | Returns the parameter. */ | |
1483 | ||
1484 | tree | |
1485 | finish_template_template_parm (aggr, identifier) | |
1486 | tree aggr; | |
1487 | tree identifier; | |
1488 | { | |
1489 | tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE); | |
1490 | tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); | |
1491 | DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; | |
1492 | DECL_TEMPLATE_RESULT (tmpl) = decl; | |
1493 | SET_DECL_ARTIFICIAL (decl); | |
1494 | end_template_decl (); | |
1495 | ||
1496 | return finish_template_type_parm (aggr, tmpl); | |
1497 | } | |
ce4a0391 MM |
1498 | |
1499 | /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is | |
1500 | non-zero, the parameter list was terminated by a `...'. */ | |
1501 | ||
1502 | tree | |
1503 | finish_parmlist (parms, ellipsis) | |
1504 | tree parms; | |
1505 | int ellipsis; | |
1506 | { | |
1507 | if (!ellipsis) | |
1508 | chainon (parms, void_list_node); | |
1509 | /* We mark the PARMS as a parmlist so that declarator processing can | |
1510 | disambiguate certain constructs. */ | |
1511 | if (parms != NULL_TREE) | |
1512 | TREE_PARMLIST (parms) = 1; | |
1513 | ||
1514 | return parms; | |
1515 | } | |
1516 | ||
1517 | /* Begin a class definition, as indicated by T. */ | |
1518 | ||
1519 | tree | |
1520 | begin_class_definition (t) | |
1521 | tree t; | |
1522 | { | |
9188c363 MM |
1523 | push_permanent_obstack (); |
1524 | ||
ce4a0391 MM |
1525 | if (t == error_mark_node |
1526 | || ! IS_AGGR_TYPE (t)) | |
1527 | { | |
830fcda8 | 1528 | t = make_lang_type (RECORD_TYPE); |
ce4a0391 MM |
1529 | pushtag (make_anon_name (), t, 0); |
1530 | } | |
830fcda8 JM |
1531 | |
1532 | /* In a definition of a member class template, we will get here with an | |
1533 | implicit typename, a TYPENAME_TYPE with a type. */ | |
1534 | if (TREE_CODE (t) == TYPENAME_TYPE) | |
1535 | t = TREE_TYPE (t); | |
4c571114 MM |
1536 | |
1537 | /* If we generated a partial instantiation of this type, but now | |
1538 | we're seeing a real definition, we're actually looking at a | |
1539 | partial specialization. Consider: | |
1540 | ||
1541 | template <class T, class U> | |
1542 | struct Y {}; | |
1543 | ||
1544 | template <class T> | |
1545 | struct X {}; | |
1546 | ||
1547 | template <class T, class U> | |
1548 | void f() | |
1549 | { | |
1550 | typename X<Y<T, U> >::A a; | |
1551 | } | |
1552 | ||
1553 | template <class T, class U> | |
1554 | struct X<Y<T, U> > | |
1555 | { | |
1556 | }; | |
1557 | ||
1558 | We have to undo the effects of the previous partial | |
1559 | instantiation. */ | |
1560 | if (PARTIAL_INSTANTIATION_P (t)) | |
1561 | { | |
1562 | if (!pedantic) | |
1563 | { | |
1564 | /* Unfortunately, when we're not in pedantic mode, we | |
1565 | attempt to actually fill in some of the fields of the | |
1566 | partial instantiation, in order to support the implicit | |
1567 | typename extension. Clear those fields now, in | |
1568 | preparation for the definition here. The fields cleared | |
1569 | here must match those set in instantiate_class_template. | |
1570 | Look for a comment mentioning begin_class_definition | |
1571 | there. */ | |
1572 | TYPE_BINFO_BASETYPES (t) = NULL_TREE; | |
1573 | TYPE_FIELDS (t) = NULL_TREE; | |
1574 | TYPE_METHODS (t) = NULL_TREE; | |
1575 | CLASSTYPE_TAGS (t) = NULL_TREE; | |
1576 | TYPE_SIZE (t) = NULL_TREE; | |
1577 | } | |
830fcda8 | 1578 | |
4c571114 MM |
1579 | /* This isn't a partial instantiation any more. */ |
1580 | PARTIAL_INSTANTIATION_P (t) = 0; | |
1581 | } | |
1582 | /* If this type was already complete, and we see another definition, | |
1583 | that's an error. */ | |
1584 | else if (TYPE_SIZE (t)) | |
ce4a0391 | 1585 | duplicate_tag_error (t); |
4c571114 | 1586 | |
b4f70b3d NS |
1587 | /* Update the location of the decl. */ |
1588 | DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename; | |
1589 | DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno; | |
1590 | ||
4c571114 | 1591 | if (TYPE_BEING_DEFINED (t)) |
ce4a0391 MM |
1592 | { |
1593 | t = make_lang_type (TREE_CODE (t)); | |
1594 | pushtag (TYPE_IDENTIFIER (t), t, 0); | |
ce4a0391 | 1595 | } |
ff350acd | 1596 | maybe_process_partial_specialization (t); |
8f032717 | 1597 | pushclass (t, 1); |
ce4a0391 | 1598 | TYPE_BEING_DEFINED (t) = 1; |
ce4a0391 MM |
1599 | /* Reset the interface data, at the earliest possible |
1600 | moment, as it might have been set via a class foo; | |
1601 | before. */ | |
6eabb241 MM |
1602 | { |
1603 | tree name = TYPE_IDENTIFIER (t); | |
1604 | ||
1605 | if (! ANON_AGGRNAME_P (name)) | |
1606 | { | |
1607 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
1608 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X | |
1609 | (t, interface_unknown); | |
1610 | } | |
1611 | ||
1612 | /* Only leave this bit clear if we know this | |
1613 | class is part of an interface-only specification. */ | |
1614 | if (! CLASSTYPE_INTERFACE_KNOWN (t) | |
1615 | || ! CLASSTYPE_INTERFACE_ONLY (t)) | |
1616 | CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 1; | |
1617 | } | |
ce4a0391 | 1618 | #if 0 |
830fcda8 JM |
1619 | tmp = TYPE_IDENTIFIER ($<ttype>0); |
1620 | if (tmp && IDENTIFIER_TEMPLATE (tmp)) | |
1621 | overload_template_name (tmp, 1); | |
ce4a0391 MM |
1622 | #endif |
1623 | reset_specialization(); | |
1624 | ||
1625 | /* In case this is a local class within a template | |
1626 | function, we save the current tree structure so | |
1627 | that we can get it back later. */ | |
1628 | begin_tree (); | |
1629 | ||
b7975aed MM |
1630 | /* Make a declaration for this class in its own scope. */ |
1631 | build_self_reference (); | |
1632 | ||
830fcda8 | 1633 | return t; |
ce4a0391 MM |
1634 | } |
1635 | ||
61a127b3 MM |
1636 | /* Finish the member declaration given by DECL. */ |
1637 | ||
1638 | void | |
1639 | finish_member_declaration (decl) | |
1640 | tree decl; | |
1641 | { | |
1642 | if (decl == error_mark_node || decl == NULL_TREE) | |
1643 | return; | |
1644 | ||
1645 | if (decl == void_type_node) | |
1646 | /* The COMPONENT was a friend, not a member, and so there's | |
1647 | nothing for us to do. */ | |
1648 | return; | |
1649 | ||
1650 | /* We should see only one DECL at a time. */ | |
1651 | my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0); | |
1652 | ||
1653 | /* Set up access control for DECL. */ | |
1654 | TREE_PRIVATE (decl) | |
1655 | = (current_access_specifier == access_private_node); | |
1656 | TREE_PROTECTED (decl) | |
1657 | = (current_access_specifier == access_protected_node); | |
1658 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
1659 | { | |
1660 | TREE_PRIVATE (DECL_RESULT (decl)) = TREE_PRIVATE (decl); | |
1661 | TREE_PROTECTED (DECL_RESULT (decl)) = TREE_PROTECTED (decl); | |
1662 | } | |
1663 | ||
1664 | /* Mark the DECL as a member of the current class. */ | |
1665 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1666 | || DECL_FUNCTION_TEMPLATE_P (decl)) | |
1667 | /* Historically, DECL_CONTEXT was not set for a FUNCTION_DECL in | |
1668 | finish_struct. Presumably it is already set as the function is | |
1669 | parsed. Perhaps DECL_CLASS_CONTEXT is already set, too? */ | |
1670 | DECL_CLASS_CONTEXT (decl) = current_class_type; | |
61a127b3 MM |
1671 | else |
1672 | DECL_CONTEXT (decl) = current_class_type; | |
1673 | ||
1674 | /* Put functions on the TYPE_METHODS list and everything else on the | |
1675 | TYPE_FIELDS list. Note that these are built up in reverse order. | |
1676 | We reverse them (to obtain declaration order) in finish_struct. */ | |
1677 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1678 | || DECL_FUNCTION_TEMPLATE_P (decl)) | |
1679 | { | |
1680 | /* We also need to add this function to the | |
1681 | CLASSTYPE_METHOD_VEC. */ | |
1682 | add_method (current_class_type, 0, decl); | |
1683 | ||
1684 | TREE_CHAIN (decl) = TYPE_METHODS (current_class_type); | |
1685 | TYPE_METHODS (current_class_type) = decl; | |
1686 | } | |
1687 | else | |
1688 | { | |
1689 | /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields | |
1690 | go at the beginning. The reason is that lookup_field_1 | |
1691 | searches the list in order, and we want a field name to | |
1692 | override a type name so that the "struct stat hack" will | |
1693 | work. In particular: | |
1694 | ||
1695 | struct S { enum E { }; int E } s; | |
1696 | s.E = 3; | |
1697 | ||
1698 | is legal. In addition, the FIELD_DECLs must be maintained in | |
1699 | declaration order so that class layout works as expected. | |
1700 | However, we don't need that order until class layout, so we | |
1701 | save a little time by putting FIELD_DECLs on in reverse order | |
1702 | here, and then reversing them in finish_struct_1. (We could | |
1703 | also keep a pointer to the correct insertion points in the | |
1704 | list.) */ | |
1705 | ||
1706 | if (TREE_CODE (decl) == TYPE_DECL) | |
1707 | TYPE_FIELDS (current_class_type) | |
1708 | = chainon (TYPE_FIELDS (current_class_type), decl); | |
1709 | else | |
1710 | { | |
1711 | TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type); | |
1712 | TYPE_FIELDS (current_class_type) = decl; | |
1713 | } | |
8f032717 MM |
1714 | |
1715 | /* Enter the DECL into the scope of the class. */ | |
1716 | if (TREE_CODE (decl) != USING_DECL) | |
1717 | pushdecl_class_level (decl); | |
61a127b3 MM |
1718 | } |
1719 | } | |
1720 | ||
1721 | /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI, | |
1722 | the definition is immediately followed by a semicolon. Returns the | |
1723 | type. */ | |
ce4a0391 MM |
1724 | |
1725 | tree | |
fbdd0024 | 1726 | finish_class_definition (t, attributes, semi, pop_scope_p) |
ce4a0391 | 1727 | tree t; |
ce4a0391 MM |
1728 | tree attributes; |
1729 | int semi; | |
fbdd0024 | 1730 | int pop_scope_p; |
ce4a0391 | 1731 | { |
ce4a0391 MM |
1732 | /* finish_struct nukes this anyway; if finish_exception does too, |
1733 | then it can go. */ | |
1734 | if (semi) | |
1735 | note_got_semicolon (t); | |
1736 | ||
dc8263bc JM |
1737 | /* If we got any attributes in class_head, xref_tag will stick them in |
1738 | TREE_TYPE of the type. Grab them now. */ | |
1739 | attributes = chainon (TREE_TYPE (t), attributes); | |
1740 | TREE_TYPE (t) = NULL_TREE; | |
1741 | ||
ce4a0391 MM |
1742 | if (TREE_CODE (t) == ENUMERAL_TYPE) |
1743 | ; | |
1744 | else | |
1745 | { | |
9f33663b | 1746 | t = finish_struct (t, attributes); |
ce4a0391 MM |
1747 | if (semi) |
1748 | note_got_semicolon (t); | |
1749 | } | |
1750 | ||
1751 | pop_obstacks (); | |
1752 | ||
1753 | if (! semi) | |
1754 | check_for_missing_semicolon (t); | |
fbdd0024 MM |
1755 | if (pop_scope_p) |
1756 | pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t))); | |
ce4a0391 MM |
1757 | if (current_scope () == current_function_decl) |
1758 | do_pending_defargs (); | |
1759 | ||
1760 | return t; | |
1761 | } | |
1762 | ||
1763 | /* Finish processing the default argument expressions cached during | |
1764 | the processing of a class definition. */ | |
1765 | ||
1766 | void | |
51632249 | 1767 | begin_inline_definitions () |
ce4a0391 MM |
1768 | { |
1769 | if (pending_inlines | |
1770 | && current_scope () == current_function_decl) | |
1771 | do_pending_inlines (); | |
1772 | } | |
1773 | ||
1774 | /* Finish processing the inline function definitions cached during the | |
1775 | processing of a class definition. */ | |
1776 | ||
1777 | void | |
51632249 | 1778 | finish_inline_definitions () |
ce4a0391 MM |
1779 | { |
1780 | if (current_class_type == NULL_TREE) | |
1781 | clear_inline_text_obstack (); | |
1782 | ||
1783 | /* Undo the begin_tree in begin_class_definition. */ | |
1784 | end_tree (); | |
1785 | } | |
35acd3f2 MM |
1786 | |
1787 | /* Finish processing the declaration of a member class template | |
1788 | TYPES whose template parameters are given by PARMS. */ | |
1789 | ||
1790 | tree | |
61a127b3 | 1791 | finish_member_class_template (types) |
35acd3f2 MM |
1792 | tree types; |
1793 | { | |
36a117a5 MM |
1794 | tree t; |
1795 | ||
1796 | /* If there are declared, but undefined, partial specializations | |
1797 | mixed in with the typespecs they will not yet have passed through | |
1798 | maybe_process_partial_specialization, so we do that here. */ | |
1799 | for (t = types; t != NULL_TREE; t = TREE_CHAIN (t)) | |
1800 | if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t)))) | |
1801 | maybe_process_partial_specialization (TREE_VALUE (t)); | |
1802 | ||
35acd3f2 | 1803 | note_list_got_semicolon (types); |
61a127b3 | 1804 | grok_x_components (types); |
35acd3f2 MM |
1805 | if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type) |
1806 | /* The component was in fact a friend declaration. We avoid | |
1807 | finish_member_template_decl performing certain checks by | |
1808 | unsetting TYPES. */ | |
1809 | types = NULL_TREE; | |
61a127b3 MM |
1810 | |
1811 | finish_member_template_decl (types); | |
1812 | ||
35acd3f2 MM |
1813 | /* As with other component type declarations, we do |
1814 | not store the new DECL on the list of | |
1815 | component_decls. */ | |
1816 | return NULL_TREE; | |
1817 | } | |
36a117a5 MM |
1818 | |
1819 | /* Finish processsing a complete template declaration. The PARMS are | |
1820 | the template parameters. */ | |
1821 | ||
1822 | void | |
1823 | finish_template_decl (parms) | |
1824 | tree parms; | |
1825 | { | |
1826 | if (parms) | |
1827 | end_template_decl (); | |
1828 | else | |
1829 | end_specialization (); | |
1830 | } | |
1831 | ||
1832 | /* Finish processing a a template-id (which names a type) of the form | |
1833 | NAME < ARGS >. Return the TYPE_DECL for the type named by the | |
1834 | template-id. If ENTERING_SCOPE is non-zero we are about to enter | |
1835 | the scope of template-id indicated. */ | |
1836 | ||
1837 | tree | |
1838 | finish_template_type (name, args, entering_scope) | |
1839 | tree name; | |
1840 | tree args; | |
1841 | int entering_scope; | |
1842 | { | |
1843 | tree decl; | |
1844 | ||
1845 | decl = lookup_template_class (name, args, | |
1846 | NULL_TREE, NULL_TREE, entering_scope); | |
1847 | if (decl != error_mark_node) | |
1848 | decl = TYPE_STUB_DECL (decl); | |
1849 | ||
1850 | return decl; | |
1851 | } | |
648f19f6 MM |
1852 | |
1853 | /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a | |
1854 | namespace scope or a class scope. */ | |
1855 | ||
1856 | void | |
1857 | enter_scope_of (sr) | |
1858 | tree sr; | |
1859 | { | |
1860 | tree scope = TREE_OPERAND (sr, 0); | |
1861 | ||
1862 | if (TREE_CODE (scope) == NAMESPACE_DECL) | |
1863 | { | |
1864 | push_decl_namespace (scope); | |
1865 | TREE_COMPLEXITY (sr) = -1; | |
1866 | } | |
1867 | else if (scope != current_class_type) | |
1868 | { | |
830fcda8 JM |
1869 | if (TREE_CODE (scope) == TYPENAME_TYPE) |
1870 | { | |
1871 | /* In a declarator for a template class member, the scope will | |
1872 | get here as an implicit typename, a TYPENAME_TYPE with a type. */ | |
1873 | scope = TREE_TYPE (scope); | |
1874 | TREE_OPERAND (sr, 0) = scope; | |
1875 | } | |
648f19f6 MM |
1876 | push_nested_class (scope, 3); |
1877 | TREE_COMPLEXITY (sr) = current_class_depth; | |
1878 | } | |
1879 | } | |
ea6021e8 MM |
1880 | |
1881 | /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. | |
1882 | Return a TREE_LIST containing the ACCESS_SPECIFIER and the | |
1883 | BASE_CLASS, or NULL_TREE if an error occurred. The | |
1884 | ACCESSS_SPECIFIER is one of | |
1885 | access_{default,public,protected_private}[_virtual]_node.*/ | |
1886 | ||
1887 | tree | |
6eabb241 | 1888 | finish_base_specifier (access_specifier, base_class) |
ea6021e8 MM |
1889 | tree access_specifier; |
1890 | tree base_class; | |
ea6021e8 MM |
1891 | { |
1892 | tree type; | |
1893 | tree result; | |
1894 | ||
1895 | if (base_class == NULL_TREE) | |
1896 | { | |
8251199e | 1897 | error ("invalid base class"); |
ea6021e8 MM |
1898 | type = error_mark_node; |
1899 | } | |
1900 | else | |
1901 | type = TREE_TYPE (base_class); | |
6eabb241 | 1902 | |
ea6021e8 MM |
1903 | if (! is_aggr_type (type, 1)) |
1904 | result = NULL_TREE; | |
ea6021e8 MM |
1905 | else |
1906 | result = build_tree_list (access_specifier, type); | |
1907 | ||
1908 | return result; | |
1909 | } | |
61a127b3 MM |
1910 | |
1911 | /* Called when multiple declarators are processed. If that is not | |
1912 | premitted in this context, an error is issued. */ | |
1913 | ||
1914 | void | |
1915 | check_multiple_declarators () | |
1916 | { | |
1917 | /* [temp] | |
1918 | ||
1919 | In a template-declaration, explicit specialization, or explicit | |
1920 | instantiation the init-declarator-list in the declaration shall | |
1921 | contain at most one declarator. | |
1922 | ||
1923 | We don't just use PROCESSING_TEMPLATE_DECL for the first | |
1924 | condition since that would disallow the perfectly legal code, | |
1925 | like `template <class T> struct S { int i, j; };'. */ | |
1926 | tree scope = current_scope (); | |
1927 | ||
1928 | if (scope && TREE_CODE (scope) == FUNCTION_DECL) | |
1929 | /* It's OK to write `template <class T> void f() { int i, j;}'. */ | |
1930 | return; | |
1931 | ||
1932 | if (PROCESSING_REAL_TEMPLATE_DECL_P () | |
1933 | || processing_explicit_instantiation | |
1934 | || processing_specialization) | |
1935 | cp_error ("multiple declarators in template declaration"); | |
1936 | } | |
1937 | ||
b894fc05 JM |
1938 | tree |
1939 | finish_typeof (expr) | |
1940 | tree expr; | |
1941 | { | |
1942 | if (processing_template_decl) | |
1943 | { | |
1944 | tree t; | |
1945 | ||
9188c363 | 1946 | push_permanent_obstack (); |
b894fc05 | 1947 | t = make_lang_type (TYPEOF_TYPE); |
b894fc05 | 1948 | TYPE_FIELDS (t) = expr; |
b894fc05 JM |
1949 | pop_obstacks (); |
1950 | ||
1951 | return t; | |
1952 | } | |
1953 | ||
1954 | return TREE_TYPE (expr); | |
1955 | } | |
558475f0 MM |
1956 | |
1957 | /* Create an empty statement tree for FN. */ | |
1958 | ||
1959 | void | |
1960 | begin_stmt_tree (fn) | |
1961 | tree fn; | |
1962 | { | |
1963 | /* We create a trivial EXPR_STMT so that last_tree is never NULL in | |
1964 | what follows. We remove the extraneous statement in | |
1965 | finish_stmt_tree. */ | |
1966 | DECL_SAVED_TREE (fn) = build_nt (EXPR_STMT, void_zero_node); | |
1967 | last_tree = DECL_SAVED_TREE (fn); | |
1968 | last_expr_type = NULL_TREE; | |
1969 | } | |
1970 | ||
1971 | /* Finish the statement tree for FN. */ | |
1972 | ||
1973 | void | |
1974 | finish_stmt_tree (fn) | |
1975 | tree fn; | |
1976 | { | |
1977 | DECL_SAVED_TREE (fn) = TREE_CHAIN (DECL_SAVED_TREE (fn)); | |
1978 | } | |
1979 | ||
1980 | /* Generate RTL for the chain of statements T. */ | |
1981 | ||
1982 | static void | |
1983 | expand_stmts (t) | |
1984 | tree t; | |
1985 | { | |
1986 | while (t) | |
1987 | { | |
1988 | expand_stmt (t); | |
1989 | t = TREE_CHAIN (t); | |
1990 | } | |
1991 | } | |
1992 | ||
1993 | /* Generate RTL for the statement T, and its substatements. */ | |
1994 | ||
1995 | tree | |
1996 | expand_stmt (t) | |
1997 | tree t; | |
1998 | { | |
1999 | if (t == NULL_TREE || t == error_mark_node) | |
2000 | return NULL_TREE; | |
2001 | ||
2002 | switch (TREE_CODE (t)) | |
2003 | { | |
2004 | case RETURN_STMT: | |
2005 | lineno = STMT_LINENO (t); | |
2006 | finish_return_stmt (RETURN_EXPR (t)); | |
2007 | break; | |
2008 | ||
2009 | case EXPR_STMT: | |
2010 | lineno = STMT_LINENO (t); | |
2011 | finish_expr_stmt (EXPR_STMT_EXPR (t)); | |
2012 | break; | |
2013 | ||
2014 | case DECL_STMT: | |
2015 | { | |
2016 | tree decl; | |
2017 | int i = suspend_momentary (); | |
2018 | ||
2019 | lineno = STMT_LINENO (t); | |
2020 | emit_line_note (input_filename, lineno); | |
2021 | decl = DECL_STMT_DECL (t); | |
2022 | /* We need to clear DECL_CONTEXT so that maybe_push_decl | |
2023 | will push it into the current scope. */ | |
2024 | if (DECL_CONTEXT (decl) == current_function_decl) | |
2025 | DECL_CONTEXT (decl) = NULL_TREE; | |
2026 | /* If we marked this variable as dead when we processed it | |
2027 | before, we must undo that now. The variable has been | |
2028 | resuscitated. */ | |
2029 | if (TREE_CODE (decl) == VAR_DECL) | |
2030 | DECL_DEAD_FOR_LOCAL (decl) = 0; | |
2031 | maybe_push_decl (decl); | |
2032 | cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0, 0); | |
2033 | resume_momentary (i); | |
2034 | } | |
2035 | break; | |
2036 | ||
2037 | case FOR_STMT: | |
2038 | { | |
2039 | tree tmp; | |
2040 | ||
2041 | lineno = STMT_LINENO (t); | |
2042 | begin_for_stmt (); | |
2043 | for (tmp = FOR_INIT_STMT (t); tmp; tmp = TREE_CHAIN (tmp)) | |
2044 | expand_stmt (tmp); | |
2045 | finish_for_init_stmt (NULL_TREE); | |
2046 | finish_for_cond (FOR_COND (t), NULL_TREE); | |
2047 | tmp = FOR_EXPR (t); | |
2048 | finish_for_expr (tmp, NULL_TREE); | |
2049 | expand_stmt (FOR_BODY (t)); | |
2050 | finish_for_stmt (tmp, NULL_TREE); | |
2051 | } | |
2052 | break; | |
2053 | ||
2054 | case WHILE_STMT: | |
2055 | { | |
2056 | lineno = STMT_LINENO (t); | |
2057 | begin_while_stmt (); | |
2058 | finish_while_stmt_cond (WHILE_COND (t), NULL_TREE); | |
2059 | expand_stmt (WHILE_BODY (t)); | |
2060 | finish_while_stmt (NULL_TREE); | |
2061 | } | |
2062 | break; | |
2063 | ||
2064 | case DO_STMT: | |
2065 | { | |
2066 | lineno = STMT_LINENO (t); | |
2067 | begin_do_stmt (); | |
2068 | expand_stmt (DO_BODY (t)); | |
2069 | finish_do_body (NULL_TREE); | |
2070 | finish_do_stmt (DO_COND (t), NULL_TREE); | |
2071 | } | |
2072 | break; | |
2073 | ||
2074 | case IF_STMT: | |
2075 | lineno = STMT_LINENO (t); | |
2076 | begin_if_stmt (); | |
2077 | finish_if_stmt_cond (IF_COND (t), NULL_TREE); | |
2078 | if (THEN_CLAUSE (t)) | |
2079 | { | |
2080 | expand_stmt (THEN_CLAUSE (t)); | |
2081 | finish_then_clause (NULL_TREE); | |
2082 | } | |
2083 | if (ELSE_CLAUSE (t)) | |
2084 | { | |
2085 | begin_else_clause (); | |
2086 | expand_stmt (ELSE_CLAUSE (t)); | |
2087 | finish_else_clause (NULL_TREE); | |
2088 | } | |
2089 | finish_if_stmt (); | |
2090 | break; | |
2091 | ||
2092 | case COMPOUND_STMT: | |
2093 | lineno = STMT_LINENO (t); | |
2094 | begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t)); | |
2095 | expand_stmts (COMPOUND_BODY (t)); | |
2096 | return finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t), | |
2097 | NULL_TREE); | |
2098 | ||
2099 | case BREAK_STMT: | |
2100 | lineno = STMT_LINENO (t); | |
2101 | finish_break_stmt (); | |
2102 | break; | |
2103 | ||
2104 | case CONTINUE_STMT: | |
2105 | lineno = STMT_LINENO (t); | |
2106 | finish_continue_stmt (); | |
2107 | break; | |
2108 | ||
2109 | case SWITCH_STMT: | |
2110 | lineno = STMT_LINENO (t); | |
2111 | begin_switch_stmt (); | |
2112 | finish_switch_cond (SWITCH_COND (t)); | |
2113 | if (TREE_OPERAND (t, 1)) | |
2114 | expand_stmt (SWITCH_BODY (t)); | |
2115 | finish_switch_stmt (SWITCH_COND (t), NULL_TREE); | |
2116 | break; | |
2117 | ||
2118 | case CASE_LABEL: | |
2119 | finish_case_label (CASE_LOW (t), CASE_HIGH (t)); | |
2120 | break; | |
2121 | ||
2122 | case LABEL_DECL: | |
3fa56191 MM |
2123 | input_filename = DECL_SOURCE_FILE (t); |
2124 | lineno = DECL_SOURCE_LINE (t); | |
2125 | finish_label_stmt (DECL_NAME (t)); | |
558475f0 MM |
2126 | break; |
2127 | ||
2128 | case GOTO_STMT: | |
2129 | lineno = STMT_LINENO (t); | |
2130 | finish_goto_stmt (GOTO_DESTINATION (t)); | |
2131 | break; | |
2132 | ||
2133 | case ASM_STMT: | |
2134 | lineno = STMT_LINENO (t); | |
2135 | finish_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), ASM_OUTPUTS | |
2136 | (t), ASM_INPUTS (t), ASM_CLOBBERS (t)); | |
2137 | break; | |
2138 | ||
2139 | case TRY_BLOCK: | |
2140 | lineno = STMT_LINENO (t); | |
f1dedc31 MM |
2141 | if (CLEANUP_P (t)) |
2142 | { | |
2143 | expand_eh_region_start (); | |
2144 | expand_stmt (TRY_STMTS (t)); | |
2145 | finish_cleanup (TRY_HANDLERS (t), NULL_TREE); | |
2146 | } | |
2147 | else | |
2148 | { | |
2149 | begin_try_block (); | |
2150 | expand_stmt (TRY_STMTS (t)); | |
2151 | finish_try_block (NULL_TREE); | |
2152 | expand_stmts (TRY_HANDLERS (t)); | |
2153 | finish_handler_sequence (NULL_TREE); | |
2154 | } | |
558475f0 MM |
2155 | break; |
2156 | ||
2157 | case HANDLER: | |
2158 | lineno = STMT_LINENO (t); | |
2159 | begin_handler (); | |
2160 | if (HANDLER_PARMS (t)) | |
2161 | { | |
2162 | tree d = HANDLER_PARMS (t); | |
2163 | expand_start_catch_block (TREE_OPERAND (d, 1), | |
2164 | TREE_OPERAND (d, 0)); | |
2165 | } | |
2166 | else | |
2167 | expand_start_catch_block (NULL_TREE, NULL_TREE); | |
2168 | finish_handler_parms (NULL_TREE); | |
2169 | expand_stmt (HANDLER_BODY (t)); | |
2170 | finish_handler (NULL_TREE); | |
2171 | break; | |
2172 | ||
f1dedc31 MM |
2173 | case SUBOBJECT: |
2174 | lineno = STMT_LINENO (t); | |
2175 | finish_subobject (SUBOBJECT_CLEANUP (t)); | |
2176 | break; | |
2177 | ||
558475f0 MM |
2178 | default: |
2179 | my_friendly_abort (19990810); | |
2180 | break; | |
2181 | } | |
2182 | ||
2183 | return NULL_TREE; | |
2184 | } | |
2185 | ||
2186 | /* Generate RTL for FN. */ | |
2187 | ||
2188 | void | |
2189 | expand_body (fn) | |
2190 | tree fn; | |
2191 | { | |
2192 | int saved_expanding_p; | |
2193 | int nested; | |
2194 | tree t; | |
2195 | tree try_block; | |
2196 | ||
2197 | /* Remember whether we're already processing a function definition | |
2198 | so that we can tell finish_function. */ | |
2199 | nested = in_function_p (); | |
2200 | ||
2201 | /* Let the compiler know that now is the time to really generate | |
2202 | actualy RTL. */ | |
2203 | saved_expanding_p = expanding_p; | |
2204 | expanding_p = 1; | |
2205 | ||
2206 | start_function (NULL_TREE, fn, NULL_TREE, 1); | |
2207 | store_parm_decls (); | |
2208 | ||
2209 | /* There are a few things that we do not handle recursively. For | |
2210 | example, a function try-block is handled differently from an | |
2211 | ordinary try-block, so we must handle it here. */ | |
2212 | t = DECL_SAVED_TREE (fn); | |
2213 | try_block = NULL_TREE; | |
2214 | if (t && TREE_CODE (t) == TRY_BLOCK) | |
2215 | { | |
2216 | try_block = t; | |
2217 | begin_function_try_block (); | |
2218 | t = TRY_STMTS (try_block); | |
2219 | } | |
2220 | ||
2221 | if (t && TREE_CODE (t) == RETURN_INIT) | |
2222 | { | |
2223 | /* Clear this out so that finish_named_return_value can set it | |
2224 | again. */ | |
2225 | DECL_NAME (DECL_RESULT (fn)) = NULL_TREE; | |
2226 | finish_named_return_value (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1)); | |
2227 | t = TREE_CHAIN (t); | |
2228 | } | |
2229 | ||
2230 | if (t && TREE_CODE (t) == CTOR_INITIALIZER) | |
2231 | { | |
2232 | current_member_init_list = TREE_OPERAND (t, 0); | |
2233 | current_base_init_list = TREE_OPERAND (t, 1); | |
2234 | t = TREE_CHAIN (t); | |
2235 | } | |
2236 | ||
2237 | /* If this is a constructor, we need to initialize our members and | |
2238 | base-classes. */ | |
2239 | setup_vtbl_ptr (); | |
2240 | ||
558475f0 MM |
2241 | /* Expand the body. */ |
2242 | expand_stmt (t); | |
2243 | ||
2244 | /* If there was a function try-block, expand the handlers. */ | |
2245 | if (try_block) | |
2246 | { | |
2247 | finish_function_try_block (NULL_TREE); | |
2248 | { | |
2249 | tree handler = TRY_HANDLERS (try_block); | |
2250 | for (; handler; handler = TREE_CHAIN (handler)) | |
2251 | expand_stmt (handler); | |
2252 | } | |
2253 | finish_function_handler_sequence (NULL_TREE); | |
2254 | } | |
2255 | ||
2256 | finish_function (lineno, 0, nested); | |
2257 | ||
2258 | /* Restore EXPANDING_P. */ | |
2259 | expanding_p = saved_expanding_p; | |
2260 | } |