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