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