]>
Commit | Line | Data |
---|---|---|
1 | /* Perform the semantic phase of parsing, i.e., the process of | |
2 | building tree structure, checking semantic consistency, and | |
3 | building RTL. These routines are used both during actual parsing | |
4 | and during the instantiation of template functions. | |
5 | ||
6 | Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. | |
7 | Written by Mark Mitchell (mmitchell@usa.net) based on code found | |
8 | formerly in parse.y and pt.c. | |
9 | ||
10 | This file is part of GNU CC. | |
11 | ||
12 | GNU CC is free software; you can redistribute it and/or modify it | |
13 | under the terms of the GNU General Public License as published by | |
14 | the Free Software Foundation; either version 2, or (at your option) | |
15 | any later version. | |
16 | ||
17 | GNU CC is distributed in the hope that it will be useful, but | |
18 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | General Public License for more details. | |
21 | ||
22 | You should have received a copy of the GNU General Public License | |
23 | along with GNU CC; see the file COPYING. If not, write to the Free | |
24 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
25 | 02111-1307, USA. */ | |
26 | ||
27 | #include "config.h" | |
28 | #include "system.h" | |
29 | #include "coretypes.h" | |
30 | #include "tm.h" | |
31 | #include "tree.h" | |
32 | #include "cp-tree.h" | |
33 | #include "tree-inline.h" | |
34 | #include "except.h" | |
35 | #include "lex.h" | |
36 | #include "toplev.h" | |
37 | #include "flags.h" | |
38 | #include "ggc.h" | |
39 | #include "rtl.h" | |
40 | #include "expr.h" | |
41 | #include "output.h" | |
42 | #include "timevar.h" | |
43 | #include "debug.h" | |
44 | ||
45 | /* There routines provide a modular interface to perform many parsing | |
46 | operations. They may therefore be used during actual parsing, or | |
47 | during template instantiation, which may be regarded as a | |
48 | degenerate form of parsing. Since the current g++ parser is | |
49 | lacking in several respects, and will be reimplemented, we are | |
50 | attempting to move most code that is not directly related to | |
51 | parsing into this file; that will make implementing the new parser | |
52 | much easier since it will be able to make use of these routines. */ | |
53 | ||
54 | static tree maybe_convert_cond PARAMS ((tree)); | |
55 | static tree simplify_aggr_init_exprs_r PARAMS ((tree *, int *, void *)); | |
56 | static void deferred_type_access_control PARAMS ((void)); | |
57 | static void emit_associated_thunks PARAMS ((tree)); | |
58 | static void genrtl_try_block PARAMS ((tree)); | |
59 | static void genrtl_eh_spec_block PARAMS ((tree)); | |
60 | static void genrtl_handler PARAMS ((tree)); | |
61 | static void genrtl_named_return_value PARAMS ((void)); | |
62 | static void cp_expand_stmt PARAMS ((tree)); | |
63 | static void genrtl_start_function PARAMS ((tree)); | |
64 | static void genrtl_finish_function PARAMS ((tree)); | |
65 | static tree clear_decl_rtl PARAMS ((tree *, int *, void *)); | |
66 | ||
67 | /* Finish processing the COND, the SUBSTMT condition for STMT. */ | |
68 | ||
69 | #define FINISH_COND(COND, STMT, SUBSTMT) \ | |
70 | do { \ | |
71 | if (last_tree != (STMT)) \ | |
72 | { \ | |
73 | RECHAIN_STMTS (STMT, SUBSTMT); \ | |
74 | if (!processing_template_decl) \ | |
75 | { \ | |
76 | (COND) = build_tree_list (SUBSTMT, COND); \ | |
77 | (SUBSTMT) = (COND); \ | |
78 | } \ | |
79 | } \ | |
80 | else \ | |
81 | (SUBSTMT) = (COND); \ | |
82 | } while (0) | |
83 | ||
84 | /* Returns nonzero if the current statement is a full expression, | |
85 | i.e. temporaries created during that statement should be destroyed | |
86 | at the end of the statement. */ | |
87 | ||
88 | int | |
89 | stmts_are_full_exprs_p () | |
90 | { | |
91 | return current_stmt_tree ()->stmts_are_full_exprs_p; | |
92 | } | |
93 | ||
94 | /* Returns the stmt_tree (if any) to which statements are currently | |
95 | being added. If there is no active statement-tree, NULL is | |
96 | returned. */ | |
97 | ||
98 | stmt_tree | |
99 | current_stmt_tree () | |
100 | { | |
101 | return (cfun | |
102 | ? &cfun->language->base.x_stmt_tree | |
103 | : &scope_chain->x_stmt_tree); | |
104 | } | |
105 | ||
106 | /* Nonzero if TYPE is an anonymous union or struct type. We have to use a | |
107 | flag for this because "A union for which objects or pointers are | |
108 | declared is not an anonymous union" [class.union]. */ | |
109 | ||
110 | int | |
111 | anon_aggr_type_p (node) | |
112 | tree node; | |
113 | { | |
114 | return ANON_AGGR_TYPE_P (node); | |
115 | } | |
116 | ||
117 | /* Finish a scope. */ | |
118 | ||
119 | tree | |
120 | do_poplevel () | |
121 | { | |
122 | tree block = NULL_TREE; | |
123 | ||
124 | if (stmts_are_full_exprs_p ()) | |
125 | { | |
126 | tree scope_stmts = NULL_TREE; | |
127 | ||
128 | block = poplevel (kept_level_p (), 1, 0); | |
129 | if (!processing_template_decl) | |
130 | { | |
131 | /* This needs to come after the poplevel so that partial scopes | |
132 | are properly nested. */ | |
133 | scope_stmts = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); | |
134 | if (block) | |
135 | { | |
136 | SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block; | |
137 | SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block; | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
142 | return block; | |
143 | } | |
144 | ||
145 | /* Begin a new scope. */ | |
146 | ||
147 | void | |
148 | do_pushlevel () | |
149 | { | |
150 | if (stmts_are_full_exprs_p ()) | |
151 | { | |
152 | if (!processing_template_decl) | |
153 | add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0); | |
154 | pushlevel (0); | |
155 | } | |
156 | } | |
157 | ||
158 | /* Finish a goto-statement. */ | |
159 | ||
160 | tree | |
161 | finish_goto_stmt (destination) | |
162 | tree destination; | |
163 | { | |
164 | if (TREE_CODE (destination) == IDENTIFIER_NODE) | |
165 | destination = lookup_label (destination); | |
166 | ||
167 | /* We warn about unused labels with -Wunused. That means we have to | |
168 | mark the used labels as used. */ | |
169 | if (TREE_CODE (destination) == LABEL_DECL) | |
170 | TREE_USED (destination) = 1; | |
171 | ||
172 | if (TREE_CODE (destination) != LABEL_DECL) | |
173 | /* We don't inline calls to functions with computed gotos. | |
174 | Those functions are typically up to some funny business, | |
175 | and may be depending on the labels being at particular | |
176 | addresses, or some such. */ | |
177 | DECL_UNINLINABLE (current_function_decl) = 1; | |
178 | ||
179 | check_goto (destination); | |
180 | ||
181 | return add_stmt (build_stmt (GOTO_STMT, destination)); | |
182 | } | |
183 | ||
184 | /* COND is the condition-expression for an if, while, etc., | |
185 | statement. Convert it to a boolean value, if appropriate. */ | |
186 | ||
187 | tree | |
188 | maybe_convert_cond (cond) | |
189 | tree cond; | |
190 | { | |
191 | /* Empty conditions remain empty. */ | |
192 | if (!cond) | |
193 | return NULL_TREE; | |
194 | ||
195 | /* Wait until we instantiate templates before doing conversion. */ | |
196 | if (processing_template_decl) | |
197 | return cond; | |
198 | ||
199 | /* Do the conversion. */ | |
200 | cond = convert_from_reference (cond); | |
201 | return condition_conversion (cond); | |
202 | } | |
203 | ||
204 | /* Finish an expression-statement, whose EXPRESSION is as indicated. */ | |
205 | ||
206 | tree | |
207 | finish_expr_stmt (expr) | |
208 | tree expr; | |
209 | { | |
210 | tree r = NULL_TREE; | |
211 | tree expr_type = NULL_TREE;; | |
212 | ||
213 | if (expr != NULL_TREE) | |
214 | { | |
215 | if (!processing_template_decl | |
216 | && !(stmts_are_full_exprs_p ()) | |
217 | && ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE | |
218 | && lvalue_p (expr)) | |
219 | || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)) | |
220 | expr = default_conversion (expr); | |
221 | ||
222 | /* Remember the type of the expression. */ | |
223 | expr_type = TREE_TYPE (expr); | |
224 | ||
225 | if (stmts_are_full_exprs_p ()) | |
226 | expr = convert_to_void (expr, "statement"); | |
227 | ||
228 | r = add_stmt (build_stmt (EXPR_STMT, expr)); | |
229 | } | |
230 | ||
231 | finish_stmt (); | |
232 | ||
233 | /* This was an expression-statement, so we save the type of the | |
234 | expression. */ | |
235 | last_expr_type = expr_type; | |
236 | ||
237 | return r; | |
238 | } | |
239 | ||
240 | ||
241 | /* Begin an if-statement. Returns a newly created IF_STMT if | |
242 | appropriate. */ | |
243 | ||
244 | tree | |
245 | begin_if_stmt () | |
246 | { | |
247 | tree r; | |
248 | do_pushlevel (); | |
249 | r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE); | |
250 | add_stmt (r); | |
251 | return r; | |
252 | } | |
253 | ||
254 | /* Process the COND of an if-statement, which may be given by | |
255 | IF_STMT. */ | |
256 | ||
257 | void | |
258 | finish_if_stmt_cond (cond, if_stmt) | |
259 | tree cond; | |
260 | tree if_stmt; | |
261 | { | |
262 | cond = maybe_convert_cond (cond); | |
263 | FINISH_COND (cond, if_stmt, IF_COND (if_stmt)); | |
264 | } | |
265 | ||
266 | /* Finish the then-clause of an if-statement, which may be given by | |
267 | IF_STMT. */ | |
268 | ||
269 | tree | |
270 | finish_then_clause (if_stmt) | |
271 | tree if_stmt; | |
272 | { | |
273 | RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt)); | |
274 | return if_stmt; | |
275 | } | |
276 | ||
277 | /* Begin the else-clause of an if-statement. */ | |
278 | ||
279 | void | |
280 | begin_else_clause () | |
281 | { | |
282 | } | |
283 | ||
284 | /* Finish the else-clause of an if-statement, which may be given by | |
285 | IF_STMT. */ | |
286 | ||
287 | void | |
288 | finish_else_clause (if_stmt) | |
289 | tree if_stmt; | |
290 | { | |
291 | RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt)); | |
292 | } | |
293 | ||
294 | /* Finish an if-statement. */ | |
295 | ||
296 | void | |
297 | finish_if_stmt () | |
298 | { | |
299 | finish_stmt (); | |
300 | do_poplevel (); | |
301 | } | |
302 | ||
303 | /* Begin a while-statement. Returns a newly created WHILE_STMT if | |
304 | appropriate. */ | |
305 | ||
306 | tree | |
307 | begin_while_stmt () | |
308 | { | |
309 | tree r; | |
310 | r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE); | |
311 | add_stmt (r); | |
312 | do_pushlevel (); | |
313 | return r; | |
314 | } | |
315 | ||
316 | /* Process the COND of a while-statement, which may be given by | |
317 | WHILE_STMT. */ | |
318 | ||
319 | void | |
320 | finish_while_stmt_cond (cond, while_stmt) | |
321 | tree cond; | |
322 | tree while_stmt; | |
323 | { | |
324 | cond = maybe_convert_cond (cond); | |
325 | if (processing_template_decl) | |
326 | /* Don't mess with condition decls in a template. */ | |
327 | FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt)); | |
328 | else if (getdecls () == NULL_TREE) | |
329 | /* It was a simple condition; install it. */ | |
330 | WHILE_COND (while_stmt) = cond; | |
331 | else | |
332 | { | |
333 | /* If there was a declaration in the condition, we can't leave it | |
334 | there; transform | |
335 | while (A x = 42) { } | |
336 | to | |
337 | while (true) { A x = 42; if (!x) break; } */ | |
338 | tree if_stmt; | |
339 | WHILE_COND (while_stmt) = boolean_true_node; | |
340 | ||
341 | if_stmt = begin_if_stmt (); | |
342 | cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0); | |
343 | finish_if_stmt_cond (cond, if_stmt); | |
344 | finish_break_stmt (); | |
345 | finish_then_clause (if_stmt); | |
346 | finish_if_stmt (); | |
347 | } | |
348 | } | |
349 | ||
350 | /* Finish a while-statement, which may be given by WHILE_STMT. */ | |
351 | ||
352 | void | |
353 | finish_while_stmt (while_stmt) | |
354 | tree while_stmt; | |
355 | { | |
356 | do_poplevel (); | |
357 | RECHAIN_STMTS (while_stmt, WHILE_BODY (while_stmt)); | |
358 | finish_stmt (); | |
359 | } | |
360 | ||
361 | /* Begin a do-statement. Returns a newly created DO_STMT if | |
362 | appropriate. */ | |
363 | ||
364 | tree | |
365 | begin_do_stmt () | |
366 | { | |
367 | tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE); | |
368 | add_stmt (r); | |
369 | return r; | |
370 | } | |
371 | ||
372 | /* Finish the body of a do-statement, which may be given by DO_STMT. */ | |
373 | ||
374 | void | |
375 | finish_do_body (do_stmt) | |
376 | tree do_stmt; | |
377 | { | |
378 | RECHAIN_STMTS (do_stmt, DO_BODY (do_stmt)); | |
379 | } | |
380 | ||
381 | /* Finish a do-statement, which may be given by DO_STMT, and whose | |
382 | COND is as indicated. */ | |
383 | ||
384 | void | |
385 | finish_do_stmt (cond, do_stmt) | |
386 | tree cond; | |
387 | tree do_stmt; | |
388 | { | |
389 | cond = maybe_convert_cond (cond); | |
390 | DO_COND (do_stmt) = cond; | |
391 | finish_stmt (); | |
392 | } | |
393 | ||
394 | /* Finish a return-statement. The EXPRESSION returned, if any, is as | |
395 | indicated. */ | |
396 | ||
397 | tree | |
398 | finish_return_stmt (expr) | |
399 | tree expr; | |
400 | { | |
401 | tree r; | |
402 | ||
403 | expr = check_return_expr (expr); | |
404 | if (!processing_template_decl) | |
405 | { | |
406 | if (DECL_DESTRUCTOR_P (current_function_decl)) | |
407 | { | |
408 | /* Similarly, all destructors must run destructors for | |
409 | base-classes before returning. So, all returns in a | |
410 | destructor get sent to the DTOR_LABEL; finish_function emits | |
411 | code to return a value there. */ | |
412 | return finish_goto_stmt (dtor_label); | |
413 | } | |
414 | } | |
415 | r = add_stmt (build_stmt (RETURN_STMT, expr)); | |
416 | finish_stmt (); | |
417 | ||
418 | return r; | |
419 | } | |
420 | ||
421 | /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */ | |
422 | ||
423 | tree | |
424 | begin_for_stmt () | |
425 | { | |
426 | tree r; | |
427 | ||
428 | r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE, | |
429 | NULL_TREE, NULL_TREE); | |
430 | NEW_FOR_SCOPE_P (r) = flag_new_for_scope > 0; | |
431 | if (NEW_FOR_SCOPE_P (r)) | |
432 | { | |
433 | do_pushlevel (); | |
434 | note_level_for_for (); | |
435 | } | |
436 | add_stmt (r); | |
437 | ||
438 | return r; | |
439 | } | |
440 | ||
441 | /* Finish the for-init-statement of a for-statement, which may be | |
442 | given by FOR_STMT. */ | |
443 | ||
444 | void | |
445 | finish_for_init_stmt (for_stmt) | |
446 | tree for_stmt; | |
447 | { | |
448 | if (last_tree != for_stmt) | |
449 | RECHAIN_STMTS (for_stmt, FOR_INIT_STMT (for_stmt)); | |
450 | do_pushlevel (); | |
451 | } | |
452 | ||
453 | /* Finish the COND of a for-statement, which may be given by | |
454 | FOR_STMT. */ | |
455 | ||
456 | void | |
457 | finish_for_cond (cond, for_stmt) | |
458 | tree cond; | |
459 | tree for_stmt; | |
460 | { | |
461 | cond = maybe_convert_cond (cond); | |
462 | if (processing_template_decl) | |
463 | /* Don't mess with condition decls in a template. */ | |
464 | FINISH_COND (cond, for_stmt, FOR_COND (for_stmt)); | |
465 | else if (getdecls () == NULL_TREE) | |
466 | /* It was a simple condition; install it. */ | |
467 | FOR_COND (for_stmt) = cond; | |
468 | else | |
469 | { | |
470 | /* If there was a declaration in the condition, we can't leave it | |
471 | there; transform | |
472 | for (; A x = 42;) { } | |
473 | to | |
474 | for (;;) { A x = 42; if (!x) break; } */ | |
475 | tree if_stmt; | |
476 | FOR_COND (for_stmt) = NULL_TREE; | |
477 | ||
478 | if_stmt = begin_if_stmt (); | |
479 | cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0); | |
480 | finish_if_stmt_cond (cond, if_stmt); | |
481 | finish_break_stmt (); | |
482 | finish_then_clause (if_stmt); | |
483 | finish_if_stmt (); | |
484 | } | |
485 | } | |
486 | ||
487 | /* Finish the increment-EXPRESSION in a for-statement, which may be | |
488 | given by FOR_STMT. */ | |
489 | ||
490 | void | |
491 | finish_for_expr (expr, for_stmt) | |
492 | tree expr; | |
493 | tree for_stmt; | |
494 | { | |
495 | FOR_EXPR (for_stmt) = expr; | |
496 | } | |
497 | ||
498 | /* Finish the body of a for-statement, which may be given by | |
499 | FOR_STMT. The increment-EXPR for the loop must be | |
500 | provided. */ | |
501 | ||
502 | void | |
503 | finish_for_stmt (for_stmt) | |
504 | tree for_stmt; | |
505 | { | |
506 | /* Pop the scope for the body of the loop. */ | |
507 | do_poplevel (); | |
508 | RECHAIN_STMTS (for_stmt, FOR_BODY (for_stmt)); | |
509 | if (NEW_FOR_SCOPE_P (for_stmt)) | |
510 | do_poplevel (); | |
511 | finish_stmt (); | |
512 | } | |
513 | ||
514 | /* Finish a break-statement. */ | |
515 | ||
516 | tree | |
517 | finish_break_stmt () | |
518 | { | |
519 | return add_stmt (build_break_stmt ()); | |
520 | } | |
521 | ||
522 | /* Finish a continue-statement. */ | |
523 | ||
524 | tree | |
525 | finish_continue_stmt () | |
526 | { | |
527 | return add_stmt (build_continue_stmt ()); | |
528 | } | |
529 | ||
530 | /* Begin a switch-statement. Returns a new SWITCH_STMT if | |
531 | appropriate. */ | |
532 | ||
533 | tree | |
534 | begin_switch_stmt () | |
535 | { | |
536 | tree r; | |
537 | do_pushlevel (); | |
538 | r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE); | |
539 | add_stmt (r); | |
540 | return r; | |
541 | } | |
542 | ||
543 | /* Finish the cond of a switch-statement. */ | |
544 | ||
545 | void | |
546 | finish_switch_cond (cond, switch_stmt) | |
547 | tree cond; | |
548 | tree switch_stmt; | |
549 | { | |
550 | tree orig_type = NULL; | |
551 | if (!processing_template_decl) | |
552 | { | |
553 | tree index; | |
554 | ||
555 | /* Convert the condition to an integer or enumeration type. */ | |
556 | cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true); | |
557 | if (cond == NULL_TREE) | |
558 | { | |
559 | error ("switch quantity not an integer"); | |
560 | cond = error_mark_node; | |
561 | } | |
562 | orig_type = TREE_TYPE (cond); | |
563 | if (cond != error_mark_node) | |
564 | { | |
565 | cond = default_conversion (cond); | |
566 | cond = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (cond), cond)); | |
567 | } | |
568 | ||
569 | if (cond != error_mark_node) | |
570 | { | |
571 | index = get_unwidened (cond, NULL_TREE); | |
572 | /* We can't strip a conversion from a signed type to an unsigned, | |
573 | because if we did, int_fits_type_p would do the wrong thing | |
574 | when checking case values for being in range, | |
575 | and it's too hard to do the right thing. */ | |
576 | if (TREE_UNSIGNED (TREE_TYPE (cond)) | |
577 | == TREE_UNSIGNED (TREE_TYPE (index))) | |
578 | cond = index; | |
579 | } | |
580 | } | |
581 | FINISH_COND (cond, switch_stmt, SWITCH_COND (switch_stmt)); | |
582 | SWITCH_TYPE (switch_stmt) = orig_type; | |
583 | push_switch (switch_stmt); | |
584 | } | |
585 | ||
586 | /* Finish the body of a switch-statement, which may be given by | |
587 | SWITCH_STMT. The COND to switch on is indicated. */ | |
588 | ||
589 | void | |
590 | finish_switch_stmt (switch_stmt) | |
591 | tree switch_stmt; | |
592 | { | |
593 | RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt)); | |
594 | pop_switch (); | |
595 | finish_stmt (); | |
596 | do_poplevel (); | |
597 | } | |
598 | ||
599 | /* Generate the RTL for T, which is a TRY_BLOCK. */ | |
600 | ||
601 | static void | |
602 | genrtl_try_block (t) | |
603 | tree t; | |
604 | { | |
605 | if (CLEANUP_P (t)) | |
606 | { | |
607 | expand_eh_region_start (); | |
608 | expand_stmt (TRY_STMTS (t)); | |
609 | expand_eh_region_end_cleanup (TRY_HANDLERS (t)); | |
610 | } | |
611 | else | |
612 | { | |
613 | if (!FN_TRY_BLOCK_P (t)) | |
614 | emit_line_note (input_filename, lineno); | |
615 | ||
616 | expand_eh_region_start (); | |
617 | expand_stmt (TRY_STMTS (t)); | |
618 | ||
619 | if (FN_TRY_BLOCK_P (t)) | |
620 | { | |
621 | expand_start_all_catch (); | |
622 | in_function_try_handler = 1; | |
623 | expand_stmt (TRY_HANDLERS (t)); | |
624 | in_function_try_handler = 0; | |
625 | expand_end_all_catch (); | |
626 | } | |
627 | else | |
628 | { | |
629 | expand_start_all_catch (); | |
630 | expand_stmt (TRY_HANDLERS (t)); | |
631 | expand_end_all_catch (); | |
632 | } | |
633 | } | |
634 | } | |
635 | ||
636 | /* Generate the RTL for T, which is an EH_SPEC_BLOCK. */ | |
637 | ||
638 | static void | |
639 | genrtl_eh_spec_block (t) | |
640 | tree t; | |
641 | { | |
642 | expand_eh_region_start (); | |
643 | expand_stmt (EH_SPEC_STMTS (t)); | |
644 | expand_eh_region_end_allowed (EH_SPEC_RAISES (t), | |
645 | build_call (call_unexpected_node, | |
646 | tree_cons (NULL_TREE, | |
647 | build_exc_ptr (), | |
648 | NULL_TREE))); | |
649 | } | |
650 | ||
651 | /* Begin a try-block. Returns a newly-created TRY_BLOCK if | |
652 | appropriate. */ | |
653 | ||
654 | tree | |
655 | begin_try_block () | |
656 | { | |
657 | tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE); | |
658 | add_stmt (r); | |
659 | return r; | |
660 | } | |
661 | ||
662 | /* Likewise, for a function-try-block. */ | |
663 | ||
664 | tree | |
665 | begin_function_try_block () | |
666 | { | |
667 | tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE); | |
668 | FN_TRY_BLOCK_P (r) = 1; | |
669 | add_stmt (r); | |
670 | return r; | |
671 | } | |
672 | ||
673 | /* Finish a try-block, which may be given by TRY_BLOCK. */ | |
674 | ||
675 | void | |
676 | finish_try_block (try_block) | |
677 | tree try_block; | |
678 | { | |
679 | RECHAIN_STMTS (try_block, TRY_STMTS (try_block)); | |
680 | } | |
681 | ||
682 | /* Finish the body of a cleanup try-block, which may be given by | |
683 | TRY_BLOCK. */ | |
684 | ||
685 | void | |
686 | finish_cleanup_try_block (try_block) | |
687 | tree try_block; | |
688 | { | |
689 | RECHAIN_STMTS (try_block, TRY_STMTS (try_block)); | |
690 | } | |
691 | ||
692 | /* Finish an implicitly generated try-block, with a cleanup is given | |
693 | by CLEANUP. */ | |
694 | ||
695 | void | |
696 | finish_cleanup (cleanup, try_block) | |
697 | tree cleanup; | |
698 | tree try_block; | |
699 | { | |
700 | TRY_HANDLERS (try_block) = cleanup; | |
701 | CLEANUP_P (try_block) = 1; | |
702 | } | |
703 | ||
704 | /* Likewise, for a function-try-block. */ | |
705 | ||
706 | void | |
707 | finish_function_try_block (try_block) | |
708 | tree try_block; | |
709 | { | |
710 | if (TREE_CHAIN (try_block) | |
711 | && TREE_CODE (TREE_CHAIN (try_block)) == CTOR_INITIALIZER) | |
712 | { | |
713 | /* Chain the compound statement after the CTOR_INITIALIZER. */ | |
714 | TREE_CHAIN (TREE_CHAIN (try_block)) = last_tree; | |
715 | /* And make the CTOR_INITIALIZER the body of the try-block. */ | |
716 | RECHAIN_STMTS (try_block, TRY_STMTS (try_block)); | |
717 | } | |
718 | else | |
719 | RECHAIN_STMTS (try_block, TRY_STMTS (try_block)); | |
720 | in_function_try_handler = 1; | |
721 | } | |
722 | ||
723 | /* Finish a handler-sequence for a try-block, which may be given by | |
724 | TRY_BLOCK. */ | |
725 | ||
726 | void | |
727 | finish_handler_sequence (try_block) | |
728 | tree try_block; | |
729 | { | |
730 | RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block)); | |
731 | check_handlers (TRY_HANDLERS (try_block)); | |
732 | } | |
733 | ||
734 | /* Likewise, for a function-try-block. */ | |
735 | ||
736 | void | |
737 | finish_function_handler_sequence (try_block) | |
738 | tree try_block; | |
739 | { | |
740 | in_function_try_handler = 0; | |
741 | RECHAIN_STMTS (try_block, TRY_HANDLERS (try_block)); | |
742 | check_handlers (TRY_HANDLERS (try_block)); | |
743 | } | |
744 | ||
745 | /* Generate the RTL for T, which is a HANDLER. */ | |
746 | ||
747 | static void | |
748 | genrtl_handler (t) | |
749 | tree t; | |
750 | { | |
751 | genrtl_do_pushlevel (); | |
752 | if (!processing_template_decl) | |
753 | expand_start_catch (HANDLER_TYPE (t)); | |
754 | expand_stmt (HANDLER_BODY (t)); | |
755 | if (!processing_template_decl) | |
756 | expand_end_catch (); | |
757 | } | |
758 | ||
759 | /* Begin a handler. Returns a HANDLER if appropriate. */ | |
760 | ||
761 | tree | |
762 | begin_handler () | |
763 | { | |
764 | tree r; | |
765 | r = build_stmt (HANDLER, NULL_TREE, NULL_TREE); | |
766 | add_stmt (r); | |
767 | /* Create a binding level for the eh_info and the exception object | |
768 | cleanup. */ | |
769 | do_pushlevel (); | |
770 | note_level_for_catch (); | |
771 | return r; | |
772 | } | |
773 | ||
774 | /* Finish the handler-parameters for a handler, which may be given by | |
775 | HANDLER. DECL is the declaration for the catch parameter, or NULL | |
776 | if this is a `catch (...)' clause. */ | |
777 | ||
778 | void | |
779 | finish_handler_parms (decl, handler) | |
780 | tree decl; | |
781 | tree handler; | |
782 | { | |
783 | tree type = NULL_TREE; | |
784 | if (processing_template_decl) | |
785 | { | |
786 | if (decl) | |
787 | { | |
788 | decl = pushdecl (decl); | |
789 | decl = push_template_decl (decl); | |
790 | add_decl_stmt (decl); | |
791 | RECHAIN_STMTS (handler, HANDLER_PARMS (handler)); | |
792 | type = TREE_TYPE (decl); | |
793 | } | |
794 | } | |
795 | else | |
796 | type = expand_start_catch_block (decl); | |
797 | ||
798 | HANDLER_TYPE (handler) = type; | |
799 | } | |
800 | ||
801 | /* Finish a handler, which may be given by HANDLER. The BLOCKs are | |
802 | the return value from the matching call to finish_handler_parms. */ | |
803 | ||
804 | void | |
805 | finish_handler (handler) | |
806 | tree handler; | |
807 | { | |
808 | if (!processing_template_decl) | |
809 | expand_end_catch_block (); | |
810 | do_poplevel (); | |
811 | RECHAIN_STMTS (handler, HANDLER_BODY (handler)); | |
812 | } | |
813 | ||
814 | /* Begin a compound-statement. If HAS_NO_SCOPE is nonzero, the | |
815 | compound-statement does not define a scope. Returns a new | |
816 | COMPOUND_STMT if appropriate. */ | |
817 | ||
818 | tree | |
819 | begin_compound_stmt (has_no_scope) | |
820 | int has_no_scope; | |
821 | { | |
822 | tree r; | |
823 | int is_try = 0; | |
824 | ||
825 | r = build_stmt (COMPOUND_STMT, NULL_TREE); | |
826 | ||
827 | if (last_tree && TREE_CODE (last_tree) == TRY_BLOCK) | |
828 | is_try = 1; | |
829 | ||
830 | add_stmt (r); | |
831 | if (has_no_scope) | |
832 | COMPOUND_STMT_NO_SCOPE (r) = 1; | |
833 | ||
834 | last_expr_type = NULL_TREE; | |
835 | ||
836 | if (!has_no_scope) | |
837 | { | |
838 | do_pushlevel (); | |
839 | if (is_try) | |
840 | note_level_for_try (); | |
841 | } | |
842 | else | |
843 | /* Normally, we try hard to keep the BLOCK for a | |
844 | statement-expression. But, if it's a statement-expression with | |
845 | a scopeless block, there's nothing to keep, and we don't want | |
846 | to accidentally keep a block *inside* the scopeless block. */ | |
847 | keep_next_level (0); | |
848 | ||
849 | return r; | |
850 | } | |
851 | ||
852 | /* Finish a compound-statement, which may be given by COMPOUND_STMT. | |
853 | If HAS_NO_SCOPE is nonzero, the compound statement does not define | |
854 | a scope. */ | |
855 | ||
856 | tree | |
857 | finish_compound_stmt (has_no_scope, compound_stmt) | |
858 | int has_no_scope; | |
859 | tree compound_stmt; | |
860 | { | |
861 | tree r; | |
862 | tree t; | |
863 | ||
864 | if (!has_no_scope) | |
865 | r = do_poplevel (); | |
866 | else | |
867 | r = NULL_TREE; | |
868 | ||
869 | RECHAIN_STMTS (compound_stmt, COMPOUND_BODY (compound_stmt)); | |
870 | ||
871 | /* When we call finish_stmt we will lose LAST_EXPR_TYPE. But, since | |
872 | the precise purpose of that variable is store the type of the | |
873 | last expression statement within the last compound statement, we | |
874 | preserve the value. */ | |
875 | t = last_expr_type; | |
876 | finish_stmt (); | |
877 | last_expr_type = t; | |
878 | ||
879 | return r; | |
880 | } | |
881 | ||
882 | /* Finish an asm-statement, whose components are a CV_QUALIFIER, a | |
883 | STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, and some | |
884 | CLOBBERS. */ | |
885 | ||
886 | tree | |
887 | finish_asm_stmt (cv_qualifier, string, output_operands, | |
888 | input_operands, clobbers) | |
889 | tree cv_qualifier; | |
890 | tree string; | |
891 | tree output_operands; | |
892 | tree input_operands; | |
893 | tree clobbers; | |
894 | { | |
895 | tree r; | |
896 | tree t; | |
897 | ||
898 | if (cv_qualifier != NULL_TREE | |
899 | && cv_qualifier != ridpointers[(int) RID_VOLATILE]) | |
900 | { | |
901 | warning ("%s qualifier ignored on asm", | |
902 | IDENTIFIER_POINTER (cv_qualifier)); | |
903 | cv_qualifier = NULL_TREE; | |
904 | } | |
905 | ||
906 | if (!processing_template_decl) | |
907 | { | |
908 | int i; | |
909 | int ninputs; | |
910 | int noutputs; | |
911 | ||
912 | for (t = input_operands; t; t = TREE_CHAIN (t)) | |
913 | { | |
914 | tree converted_operand | |
915 | = decay_conversion (TREE_VALUE (t)); | |
916 | ||
917 | /* If the type of the operand hasn't been determined (e.g., | |
918 | because it involves an overloaded function), then issue | |
919 | an error message. There's no context available to | |
920 | resolve the overloading. */ | |
921 | if (TREE_TYPE (converted_operand) == unknown_type_node) | |
922 | { | |
923 | error ("type of asm operand `%E' could not be determined", | |
924 | TREE_VALUE (t)); | |
925 | converted_operand = error_mark_node; | |
926 | } | |
927 | TREE_VALUE (t) = converted_operand; | |
928 | } | |
929 | ||
930 | ninputs = list_length (input_operands); | |
931 | noutputs = list_length (output_operands); | |
932 | ||
933 | for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i) | |
934 | { | |
935 | bool allows_mem; | |
936 | bool allows_reg; | |
937 | bool is_inout; | |
938 | const char *constraint; | |
939 | tree operand; | |
940 | ||
941 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); | |
942 | operand = TREE_VALUE (t); | |
943 | ||
944 | if (!parse_output_constraint (&constraint, | |
945 | i, ninputs, noutputs, | |
946 | &allows_mem, | |
947 | &allows_reg, | |
948 | &is_inout)) | |
949 | { | |
950 | /* By marking this operand as erroneous, we will not try | |
951 | to process this operand again in expand_asm_operands. */ | |
952 | TREE_VALUE (t) = error_mark_node; | |
953 | continue; | |
954 | } | |
955 | ||
956 | /* If the operand is a DECL that is going to end up in | |
957 | memory, assume it is addressable. This is a bit more | |
958 | conservative than it would ideally be; the exact test is | |
959 | buried deep in expand_asm_operands and depends on the | |
960 | DECL_RTL for the OPERAND -- which we don't have at this | |
961 | point. */ | |
962 | if (!allows_reg && DECL_P (operand)) | |
963 | cxx_mark_addressable (operand); | |
964 | } | |
965 | } | |
966 | ||
967 | r = build_stmt (ASM_STMT, cv_qualifier, string, | |
968 | output_operands, input_operands, | |
969 | clobbers); | |
970 | return add_stmt (r); | |
971 | } | |
972 | ||
973 | /* Finish a label with the indicated NAME. */ | |
974 | ||
975 | tree | |
976 | finish_label_stmt (name) | |
977 | tree name; | |
978 | { | |
979 | tree decl = define_label (input_filename, lineno, name); | |
980 | return add_stmt (build_stmt (LABEL_STMT, decl)); | |
981 | } | |
982 | ||
983 | /* Finish a series of declarations for local labels. G++ allows users | |
984 | to declare "local" labels, i.e., labels with scope. This extension | |
985 | is useful when writing code involving statement-expressions. */ | |
986 | ||
987 | void | |
988 | finish_label_decl (name) | |
989 | tree name; | |
990 | { | |
991 | tree decl = declare_local_label (name); | |
992 | add_decl_stmt (decl); | |
993 | } | |
994 | ||
995 | /* When DECL goes out of scope, make sure that CLEANUP is executed. */ | |
996 | ||
997 | void | |
998 | finish_decl_cleanup (decl, cleanup) | |
999 | tree decl; | |
1000 | tree cleanup; | |
1001 | { | |
1002 | add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup)); | |
1003 | } | |
1004 | ||
1005 | /* If the current scope exits with an exception, run CLEANUP. */ | |
1006 | ||
1007 | void | |
1008 | finish_eh_cleanup (cleanup) | |
1009 | tree cleanup; | |
1010 | { | |
1011 | tree r = build_stmt (CLEANUP_STMT, NULL_TREE, cleanup); | |
1012 | CLEANUP_EH_ONLY (r) = 1; | |
1013 | add_stmt (r); | |
1014 | } | |
1015 | ||
1016 | /* Generate the RTL for a RETURN_INIT. */ | |
1017 | ||
1018 | static void | |
1019 | genrtl_named_return_value () | |
1020 | { | |
1021 | tree decl = DECL_RESULT (current_function_decl); | |
1022 | ||
1023 | /* If this named return value comes in a register, put it in a | |
1024 | pseudo-register. */ | |
1025 | if (DECL_REGISTER (decl)) | |
1026 | { | |
1027 | /* Note that the mode of the old DECL_RTL may be wider than the | |
1028 | mode of DECL_RESULT, depending on the calling conventions for | |
1029 | the processor. For example, on the Alpha, a 32-bit integer | |
1030 | is returned in a DImode register -- the DECL_RESULT has | |
1031 | SImode but the DECL_RTL for the DECL_RESULT has DImode. So, | |
1032 | here, we use the mode the back-end has already assigned for | |
1033 | the return value. */ | |
1034 | SET_DECL_RTL (decl, gen_reg_rtx (GET_MODE (DECL_RTL (decl)))); | |
1035 | if (TREE_ADDRESSABLE (decl)) | |
1036 | put_var_into_stack (decl); | |
1037 | } | |
1038 | ||
1039 | emit_local_var (decl); | |
1040 | } | |
1041 | ||
1042 | /* Bind a name and initialization to the return value of | |
1043 | the current function. */ | |
1044 | ||
1045 | void | |
1046 | finish_named_return_value (return_id, init) | |
1047 | tree return_id, init; | |
1048 | { | |
1049 | tree decl = DECL_RESULT (current_function_decl); | |
1050 | ||
1051 | /* Give this error as many times as there are occurrences, so that | |
1052 | users can use Emacs compilation buffers to find and fix all such | |
1053 | places. */ | |
1054 | if (pedantic) | |
1055 | pedwarn ("ISO C++ does not permit named return values"); | |
1056 | cp_deprecated ("the named return value extension"); | |
1057 | ||
1058 | if (return_id != NULL_TREE) | |
1059 | { | |
1060 | if (DECL_NAME (decl) == NULL_TREE) | |
1061 | DECL_NAME (decl) = return_id; | |
1062 | else | |
1063 | { | |
1064 | error ("return identifier `%D' already in place", return_id); | |
1065 | return; | |
1066 | } | |
1067 | } | |
1068 | ||
1069 | /* Can't let this happen for constructors. */ | |
1070 | if (DECL_CONSTRUCTOR_P (current_function_decl)) | |
1071 | { | |
1072 | error ("can't redefine default return value for constructors"); | |
1073 | return; | |
1074 | } | |
1075 | ||
1076 | /* If we have a named return value, put that in our scope as well. */ | |
1077 | if (DECL_NAME (decl) != NULL_TREE) | |
1078 | { | |
1079 | /* Let `cp_finish_decl' know that this initializer is ok. */ | |
1080 | DECL_INITIAL (decl) = init; | |
1081 | if (doing_semantic_analysis_p ()) | |
1082 | pushdecl (decl); | |
1083 | if (!processing_template_decl) | |
1084 | { | |
1085 | cp_finish_decl (decl, init, NULL_TREE, 0); | |
1086 | add_stmt (build_stmt (RETURN_INIT, NULL_TREE, NULL_TREE)); | |
1087 | } | |
1088 | else | |
1089 | add_stmt (build_stmt (RETURN_INIT, return_id, init)); | |
1090 | } | |
1091 | ||
1092 | /* Don't use tree-inlining for functions with named return values. | |
1093 | That doesn't work properly because we don't do any translation of | |
1094 | the RETURN_INITs when they are copied. */ | |
1095 | DECL_UNINLINABLE (current_function_decl) = 1; | |
1096 | } | |
1097 | ||
1098 | /* Begin processing a mem-initializer-list. */ | |
1099 | ||
1100 | void | |
1101 | begin_mem_initializers () | |
1102 | { | |
1103 | if (! DECL_CONSTRUCTOR_P (current_function_decl)) | |
1104 | error ("only constructors take base initializers"); | |
1105 | } | |
1106 | ||
1107 | /* The MEM_INITS is a list of mem-initializers, in reverse of the | |
1108 | order they were written by the user. Each node is as for | |
1109 | emit_mem_initializers. */ | |
1110 | ||
1111 | void | |
1112 | finish_mem_initializers (tree mem_inits) | |
1113 | { | |
1114 | /* Reorder the MEM_INITS so that they are in the order they appeared | |
1115 | in the source program. */ | |
1116 | mem_inits = nreverse (mem_inits); | |
1117 | ||
1118 | if (processing_template_decl) | |
1119 | add_stmt (build_min_nt (CTOR_INITIALIZER, mem_inits)); | |
1120 | else | |
1121 | emit_mem_initializers (mem_inits); | |
1122 | } | |
1123 | ||
1124 | /* Returns the stack of SCOPE_STMTs for the current function. */ | |
1125 | ||
1126 | tree * | |
1127 | current_scope_stmt_stack () | |
1128 | { | |
1129 | return &cfun->language->base.x_scope_stmt_stack; | |
1130 | } | |
1131 | ||
1132 | /* Finish a parenthesized expression EXPR. */ | |
1133 | ||
1134 | tree | |
1135 | finish_parenthesized_expr (expr) | |
1136 | tree expr; | |
1137 | { | |
1138 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr)))) | |
1139 | /* This inhibits warnings in c_common_truthvalue_conversion. */ | |
1140 | C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK); | |
1141 | ||
1142 | if (TREE_CODE (expr) == OFFSET_REF) | |
1143 | /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be | |
1144 | enclosed in parentheses. */ | |
1145 | PTRMEM_OK_P (expr) = 0; | |
1146 | return expr; | |
1147 | } | |
1148 | ||
1149 | /* Finish a reference to a non-static data member (DECL) that is not | |
1150 | preceded by `.' or `->'. */ | |
1151 | ||
1152 | tree | |
1153 | finish_non_static_data_member (tree decl, tree qualifying_scope) | |
1154 | { | |
1155 | my_friendly_assert (TREE_CODE (decl) == FIELD_DECL, 20020909); | |
1156 | ||
1157 | if (current_class_ptr == NULL_TREE) | |
1158 | { | |
1159 | if (current_function_decl | |
1160 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1161 | cp_error_at ("invalid use of member `%D' in static member function", | |
1162 | decl); | |
1163 | else | |
1164 | cp_error_at ("invalid use of non-static data member `%D'", decl); | |
1165 | error ("from this location"); | |
1166 | ||
1167 | return error_mark_node; | |
1168 | } | |
1169 | TREE_USED (current_class_ptr) = 1; | |
1170 | if (processing_template_decl) | |
1171 | return build_min_nt (COMPONENT_REF, current_class_ref, DECL_NAME (decl)); | |
1172 | else | |
1173 | { | |
1174 | tree access_type = current_class_type; | |
1175 | tree object = current_class_ref; | |
1176 | ||
1177 | while (!DERIVED_FROM_P (context_for_name_lookup (decl), access_type)) | |
1178 | { | |
1179 | access_type = TYPE_CONTEXT (access_type); | |
1180 | while (DECL_P (access_type)) | |
1181 | access_type = DECL_CONTEXT (access_type); | |
1182 | } | |
1183 | ||
1184 | enforce_access (access_type, decl); | |
1185 | ||
1186 | /* If the data member was named `C::M', convert `*this' to `C' | |
1187 | first. */ | |
1188 | if (qualifying_scope) | |
1189 | { | |
1190 | tree binfo = NULL_TREE; | |
1191 | object = build_scoped_ref (object, qualifying_scope, | |
1192 | &binfo); | |
1193 | } | |
1194 | ||
1195 | return build_class_member_access_expr (object, decl, | |
1196 | /*access_path=*/NULL_TREE, | |
1197 | /*preserve_reference=*/false); | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | /* Begin a statement-expression. The value returned must be passed to | |
1202 | finish_stmt_expr. */ | |
1203 | ||
1204 | tree | |
1205 | begin_stmt_expr () | |
1206 | { | |
1207 | /* If we're outside a function, we won't have a statement-tree to | |
1208 | work with. But, if we see a statement-expression we need to | |
1209 | create one. */ | |
1210 | if (! cfun && !last_tree) | |
1211 | begin_stmt_tree (&scope_chain->x_saved_tree); | |
1212 | ||
1213 | keep_next_level (1); | |
1214 | /* If we're building a statement tree, then the upcoming compound | |
1215 | statement will be chained onto the tree structure, starting at | |
1216 | last_tree. We return last_tree so that we can later unhook the | |
1217 | compound statement. */ | |
1218 | return last_tree; | |
1219 | } | |
1220 | ||
1221 | /* Used when beginning a statement-expression outside function scope. | |
1222 | For example, when handling a file-scope initializer, we use this | |
1223 | function. */ | |
1224 | ||
1225 | tree | |
1226 | begin_global_stmt_expr () | |
1227 | { | |
1228 | if (! cfun && !last_tree) | |
1229 | begin_stmt_tree (&scope_chain->x_saved_tree); | |
1230 | ||
1231 | keep_next_level (1); | |
1232 | ||
1233 | return last_tree ? last_tree : expand_start_stmt_expr(/*has_scope=*/1); | |
1234 | } | |
1235 | ||
1236 | /* Finish the STMT_EXPR last begun with begin_global_stmt_expr. */ | |
1237 | ||
1238 | tree | |
1239 | finish_global_stmt_expr (stmt_expr) | |
1240 | tree stmt_expr; | |
1241 | { | |
1242 | stmt_expr = expand_end_stmt_expr (stmt_expr); | |
1243 | ||
1244 | if (! cfun | |
1245 | && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE) | |
1246 | finish_stmt_tree (&scope_chain->x_saved_tree); | |
1247 | ||
1248 | return stmt_expr; | |
1249 | } | |
1250 | ||
1251 | /* Finish a statement-expression. RTL_EXPR should be the value | |
1252 | returned by the previous begin_stmt_expr; EXPR is the | |
1253 | statement-expression. Returns an expression representing the | |
1254 | statement-expression. */ | |
1255 | ||
1256 | tree | |
1257 | finish_stmt_expr (rtl_expr) | |
1258 | tree rtl_expr; | |
1259 | { | |
1260 | tree result; | |
1261 | ||
1262 | /* If the last thing in the statement-expression was not an | |
1263 | expression-statement, then it has type `void'. */ | |
1264 | if (!last_expr_type) | |
1265 | last_expr_type = void_type_node; | |
1266 | result = build_min (STMT_EXPR, last_expr_type, last_tree); | |
1267 | TREE_SIDE_EFFECTS (result) = 1; | |
1268 | ||
1269 | /* Remove the compound statement from the tree structure; it is | |
1270 | now saved in the STMT_EXPR. */ | |
1271 | last_tree = rtl_expr; | |
1272 | TREE_CHAIN (last_tree) = NULL_TREE; | |
1273 | ||
1274 | /* If we created a statement-tree for this statement-expression, | |
1275 | remove it now. */ | |
1276 | if (! cfun | |
1277 | && TREE_CHAIN (scope_chain->x_saved_tree) == NULL_TREE) | |
1278 | finish_stmt_tree (&scope_chain->x_saved_tree); | |
1279 | ||
1280 | return result; | |
1281 | } | |
1282 | ||
1283 | /* Generate an expression for `FN (ARGS)'. | |
1284 | ||
1285 | If DISALLOW_VIRTUAL is true, the call to FN will be not generated | |
1286 | as a virtual call, even if FN is virtual. (This flag is set when | |
1287 | encountering an expression where the function name is explicitly | |
1288 | qualified. For example a call to `X::f' never generates a virtual | |
1289 | call.) | |
1290 | ||
1291 | Returns code for the call. */ | |
1292 | ||
1293 | tree | |
1294 | finish_call_expr (tree fn, tree args, bool disallow_virtual) | |
1295 | { | |
1296 | if (fn == error_mark_node || args == error_mark_node) | |
1297 | return error_mark_node; | |
1298 | ||
1299 | if (processing_template_decl) | |
1300 | return build_nt (CALL_EXPR, fn, args, NULL_TREE); | |
1301 | ||
1302 | /* ARGS should be a list of arguments. */ | |
1303 | my_friendly_assert (!args || TREE_CODE (args) == TREE_LIST, | |
1304 | 20020712); | |
1305 | ||
1306 | /* A reference to a member function will appear as an overloaded | |
1307 | function (rather than a BASELINK) if an unqualified name was used | |
1308 | to refer to it. */ | |
1309 | if (!BASELINK_P (fn) && is_overloaded_fn (fn)) | |
1310 | { | |
1311 | tree f; | |
1312 | ||
1313 | if (TREE_CODE (fn) == TEMPLATE_ID_EXPR) | |
1314 | f = get_first_fn (TREE_OPERAND (fn, 0)); | |
1315 | else | |
1316 | f = get_first_fn (fn); | |
1317 | if (DECL_FUNCTION_MEMBER_P (f)) | |
1318 | { | |
1319 | tree type = currently_open_derived_class (DECL_CONTEXT (f)); | |
1320 | fn = build_baselink (TYPE_BINFO (type), | |
1321 | TYPE_BINFO (type), | |
1322 | fn, /*optype=*/NULL_TREE); | |
1323 | } | |
1324 | } | |
1325 | ||
1326 | if (BASELINK_P (fn)) | |
1327 | { | |
1328 | tree object; | |
1329 | ||
1330 | /* A call to a member function. From [over.call.func]: | |
1331 | ||
1332 | If the keyword this is in scope and refers to the class of | |
1333 | that member function, or a derived class thereof, then the | |
1334 | function call is transformed into a qualified function call | |
1335 | using (*this) as the postfix-expression to the left of the | |
1336 | . operator.... [Otherwise] a contrived object of type T | |
1337 | becomes the implied object argument. | |
1338 | ||
1339 | This paragraph is unclear about this situation: | |
1340 | ||
1341 | struct A { void f(); }; | |
1342 | struct B : public A {}; | |
1343 | struct C : public A { void g() { B::f(); }}; | |
1344 | ||
1345 | In particular, for `B::f', this paragraph does not make clear | |
1346 | whether "the class of that member function" refers to `A' or | |
1347 | to `B'. We believe it refers to `B'. */ | |
1348 | if (current_class_type | |
1349 | && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), | |
1350 | current_class_type) | |
1351 | && current_class_ref) | |
1352 | object = current_class_ref; | |
1353 | else | |
1354 | { | |
1355 | tree representative_fn; | |
1356 | ||
1357 | representative_fn = BASELINK_FUNCTIONS (fn); | |
1358 | if (TREE_CODE (representative_fn) == TEMPLATE_ID_EXPR) | |
1359 | representative_fn = TREE_OPERAND (representative_fn, 0); | |
1360 | representative_fn = get_first_fn (representative_fn); | |
1361 | object = build_dummy_object (DECL_CONTEXT (representative_fn)); | |
1362 | } | |
1363 | ||
1364 | return build_new_method_call (object, fn, args, NULL_TREE, | |
1365 | (disallow_virtual | |
1366 | ? LOOKUP_NONVIRTUAL : 0)); | |
1367 | } | |
1368 | else if (is_overloaded_fn (fn)) | |
1369 | /* A call to a namespace-scope function. */ | |
1370 | return build_new_function_call (fn, args); | |
1371 | else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR) | |
1372 | { | |
1373 | tree result; | |
1374 | ||
1375 | if (args) | |
1376 | error ("arguments to destructor are not allowed"); | |
1377 | /* Mark the pseudo-destructor call as having side-effects so | |
1378 | that we do not issue warnings about its use. */ | |
1379 | result = build1 (NOP_EXPR, | |
1380 | void_type_node, | |
1381 | TREE_OPERAND (fn, 0)); | |
1382 | TREE_SIDE_EFFECTS (result) = 1; | |
1383 | return result; | |
1384 | } | |
1385 | else if (CLASS_TYPE_P (TREE_TYPE (fn))) | |
1386 | { | |
1387 | /* If the "function" is really an object of class type, it might | |
1388 | have an overloaded `operator ()'. */ | |
1389 | tree result; | |
1390 | result = build_opfncall (CALL_EXPR, LOOKUP_NORMAL, fn, args, NULL_TREE); | |
1391 | if (result) | |
1392 | return result; | |
1393 | } | |
1394 | ||
1395 | /* A call where the function is unknown. */ | |
1396 | return build_function_call (fn, args); | |
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 | result = current_class_ptr; | |
1428 | } | |
1429 | else if (current_function_decl | |
1430 | && DECL_STATIC_FUNCTION_P (current_function_decl)) | |
1431 | { | |
1432 | error ("`this' is unavailable for static member functions"); | |
1433 | result = error_mark_node; | |
1434 | } | |
1435 | else | |
1436 | { | |
1437 | if (current_function_decl) | |
1438 | error ("invalid use of `this' in non-member function"); | |
1439 | else | |
1440 | error ("invalid use of `this' at top level"); | |
1441 | result = error_mark_node; | |
1442 | } | |
1443 | ||
1444 | return result; | |
1445 | } | |
1446 | ||
1447 | /* Finish a member function call using OBJECT and ARGS as arguments to | |
1448 | FN. Returns an expression for the call. */ | |
1449 | ||
1450 | tree | |
1451 | finish_object_call_expr (fn, object, args) | |
1452 | tree fn; | |
1453 | tree object; | |
1454 | tree args; | |
1455 | { | |
1456 | if (DECL_DECLARES_TYPE_P (fn)) | |
1457 | { | |
1458 | if (processing_template_decl) | |
1459 | /* This can happen on code like: | |
1460 | ||
1461 | class X; | |
1462 | template <class T> void f(T t) { | |
1463 | t.X(); | |
1464 | } | |
1465 | ||
1466 | We just grab the underlying IDENTIFIER. */ | |
1467 | fn = DECL_NAME (fn); | |
1468 | else | |
1469 | { | |
1470 | error ("calling type `%T' like a method", fn); | |
1471 | return error_mark_node; | |
1472 | } | |
1473 | } | |
1474 | ||
1475 | if (processing_template_decl) | |
1476 | return build_nt (CALL_EXPR, | |
1477 | build_nt (COMPONENT_REF, object, fn), | |
1478 | args); | |
1479 | ||
1480 | if (name_p (fn)) | |
1481 | return build_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL); | |
1482 | else | |
1483 | return build_new_method_call (object, fn, args, NULL_TREE, LOOKUP_NORMAL); | |
1484 | } | |
1485 | ||
1486 | /* Finish a qualified member function call using OBJECT and ARGS as | |
1487 | arguments to FN. Returns an expression for the call. */ | |
1488 | ||
1489 | tree | |
1490 | finish_qualified_object_call_expr (fn, object, args) | |
1491 | tree fn; | |
1492 | tree object; | |
1493 | tree args; | |
1494 | { | |
1495 | return build_scoped_method_call (object, TREE_OPERAND (fn, 0), | |
1496 | TREE_OPERAND (fn, 1), args); | |
1497 | } | |
1498 | ||
1499 | /* Finish a pseudo-destructor expression. If SCOPE is NULL, the | |
1500 | expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is | |
1501 | the TYPE for the type given. If SCOPE is non-NULL, the expression | |
1502 | was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */ | |
1503 | ||
1504 | tree | |
1505 | finish_pseudo_destructor_expr (object, scope, destructor) | |
1506 | tree object; | |
1507 | tree scope; | |
1508 | tree destructor; | |
1509 | { | |
1510 | if (destructor == error_mark_node) | |
1511 | return error_mark_node; | |
1512 | ||
1513 | my_friendly_assert (TYPE_P (destructor), 20010905); | |
1514 | ||
1515 | if (!processing_template_decl) | |
1516 | { | |
1517 | if (scope == error_mark_node) | |
1518 | { | |
1519 | error ("invalid qualifying scope in pseudo-destructor name"); | |
1520 | return error_mark_node; | |
1521 | } | |
1522 | ||
1523 | if (!same_type_p (TREE_TYPE (object), destructor)) | |
1524 | { | |
1525 | error ("`%E' is not of type `%T'", object, destructor); | |
1526 | return error_mark_node; | |
1527 | } | |
1528 | } | |
1529 | ||
1530 | return build (PSEUDO_DTOR_EXPR, void_type_node, object, scope, destructor); | |
1531 | } | |
1532 | ||
1533 | /* Finish an expression of the form CODE EXPR. */ | |
1534 | ||
1535 | tree | |
1536 | finish_unary_op_expr (code, expr) | |
1537 | enum tree_code code; | |
1538 | tree expr; | |
1539 | { | |
1540 | tree result = build_x_unary_op (code, expr); | |
1541 | /* Inside a template, build_x_unary_op does not fold the | |
1542 | expression. So check whether the result is folded before | |
1543 | setting TREE_NEGATED_INT. */ | |
1544 | if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST | |
1545 | && TREE_CODE (result) == INTEGER_CST | |
1546 | && !TREE_UNSIGNED (TREE_TYPE (result)) | |
1547 | && INT_CST_LT (result, integer_zero_node)) | |
1548 | TREE_NEGATED_INT (result) = 1; | |
1549 | overflow_warning (result); | |
1550 | return result; | |
1551 | } | |
1552 | ||
1553 | /* Finish a compound-literal expression. TYPE is the type to which | |
1554 | the INITIALIZER_LIST is being cast. */ | |
1555 | ||
1556 | tree | |
1557 | finish_compound_literal (type, initializer_list) | |
1558 | tree type; | |
1559 | tree initializer_list; | |
1560 | { | |
1561 | tree compound_literal; | |
1562 | ||
1563 | /* Build a CONSTRUCTOR for the INITIALIZER_LIST. */ | |
1564 | compound_literal = build_nt (CONSTRUCTOR, NULL_TREE, | |
1565 | initializer_list); | |
1566 | /* Mark it as a compound-literal. */ | |
1567 | TREE_HAS_CONSTRUCTOR (compound_literal) = 1; | |
1568 | if (processing_template_decl) | |
1569 | TREE_TYPE (compound_literal) = type; | |
1570 | else | |
1571 | { | |
1572 | /* Check the initialization. */ | |
1573 | compound_literal = digest_init (type, compound_literal, NULL); | |
1574 | /* If the TYPE was an array type with an unknown bound, then we can | |
1575 | figure out the dimension now. For example, something like: | |
1576 | ||
1577 | `(int []) { 2, 3 }' | |
1578 | ||
1579 | implies that the array has two elements. */ | |
1580 | if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) | |
1581 | complete_array_type (type, compound_literal, 1); | |
1582 | } | |
1583 | ||
1584 | return compound_literal; | |
1585 | } | |
1586 | ||
1587 | /* Return the declaration for the function-name variable indicated by | |
1588 | ID. */ | |
1589 | ||
1590 | tree | |
1591 | finish_fname (tree id) | |
1592 | { | |
1593 | tree decl; | |
1594 | ||
1595 | decl = fname_decl (C_RID_CODE (id), id); | |
1596 | if (processing_template_decl) | |
1597 | decl = build_min_nt (LOOKUP_EXPR, DECL_NAME (decl)); | |
1598 | return decl; | |
1599 | } | |
1600 | ||
1601 | static tree current_type_lookups; | |
1602 | ||
1603 | /* Perform deferred access control for types used in the type of a | |
1604 | declaration. */ | |
1605 | ||
1606 | static void | |
1607 | deferred_type_access_control () | |
1608 | { | |
1609 | tree lookup = type_lookups; | |
1610 | ||
1611 | if (lookup == error_mark_node) | |
1612 | return; | |
1613 | ||
1614 | for (; lookup; lookup = TREE_CHAIN (lookup)) | |
1615 | enforce_access (TREE_PURPOSE (lookup), TREE_VALUE (lookup)); | |
1616 | } | |
1617 | ||
1618 | void | |
1619 | decl_type_access_control (decl) | |
1620 | tree decl; | |
1621 | { | |
1622 | tree save_fn; | |
1623 | ||
1624 | if (type_lookups == error_mark_node) | |
1625 | return; | |
1626 | ||
1627 | save_fn = current_function_decl; | |
1628 | ||
1629 | if (decl && TREE_CODE (decl) == FUNCTION_DECL) | |
1630 | current_function_decl = decl; | |
1631 | ||
1632 | deferred_type_access_control (); | |
1633 | ||
1634 | current_function_decl = save_fn; | |
1635 | ||
1636 | /* Now strip away the checks for the current declarator; they were | |
1637 | added to type_lookups after typed_declspecs saved the copy that | |
1638 | ended up in current_type_lookups. */ | |
1639 | type_lookups = current_type_lookups; | |
1640 | } | |
1641 | ||
1642 | void | |
1643 | save_type_access_control (lookups) | |
1644 | tree lookups; | |
1645 | { | |
1646 | current_type_lookups = lookups; | |
1647 | } | |
1648 | ||
1649 | /* Reset the deferred access control. */ | |
1650 | ||
1651 | void | |
1652 | reset_type_access_control () | |
1653 | { | |
1654 | type_lookups = NULL_TREE; | |
1655 | current_type_lookups = NULL_TREE; | |
1656 | } | |
1657 | ||
1658 | /* Begin a function definition declared with DECL_SPECS, ATTRIBUTES, | |
1659 | and DECLARATOR. Returns nonzero if the function-declaration is | |
1660 | valid. */ | |
1661 | ||
1662 | int | |
1663 | begin_function_definition (decl_specs, attributes, declarator) | |
1664 | tree decl_specs; | |
1665 | tree attributes; | |
1666 | tree declarator; | |
1667 | { | |
1668 | if (!start_function (decl_specs, declarator, attributes, SF_DEFAULT)) | |
1669 | return 0; | |
1670 | ||
1671 | deferred_type_access_control (); | |
1672 | type_lookups = error_mark_node; | |
1673 | ||
1674 | /* The things we're about to see are not directly qualified by any | |
1675 | template headers we've seen thus far. */ | |
1676 | reset_specialization (); | |
1677 | ||
1678 | return 1; | |
1679 | } | |
1680 | ||
1681 | /* Begin a constructor declarator of the form `SCOPE::NAME'. Returns | |
1682 | a SCOPE_REF. */ | |
1683 | ||
1684 | tree | |
1685 | begin_constructor_declarator (scope, name) | |
1686 | tree scope; | |
1687 | tree name; | |
1688 | { | |
1689 | tree result = build_nt (SCOPE_REF, scope, name); | |
1690 | enter_scope_of (result); | |
1691 | return result; | |
1692 | } | |
1693 | ||
1694 | /* Finish an init-declarator. Returns a DECL. */ | |
1695 | ||
1696 | tree | |
1697 | finish_declarator (declarator, declspecs, attributes, | |
1698 | prefix_attributes, initialized) | |
1699 | tree declarator; | |
1700 | tree declspecs; | |
1701 | tree attributes; | |
1702 | tree prefix_attributes; | |
1703 | int initialized; | |
1704 | { | |
1705 | return start_decl (declarator, declspecs, initialized, attributes, | |
1706 | prefix_attributes); | |
1707 | } | |
1708 | ||
1709 | /* Finish a translation unit. */ | |
1710 | ||
1711 | void | |
1712 | finish_translation_unit () | |
1713 | { | |
1714 | /* In case there were missing closebraces, | |
1715 | get us back to the global binding level. */ | |
1716 | pop_everything (); | |
1717 | while (current_namespace != global_namespace) | |
1718 | pop_namespace (); | |
1719 | ||
1720 | /* Do file scope __FUNCTION__ et al. */ | |
1721 | finish_fname_decls (); | |
1722 | ||
1723 | finish_file (); | |
1724 | } | |
1725 | ||
1726 | /* Finish a template type parameter, specified as AGGR IDENTIFIER. | |
1727 | Returns the parameter. */ | |
1728 | ||
1729 | tree | |
1730 | finish_template_type_parm (aggr, identifier) | |
1731 | tree aggr; | |
1732 | tree identifier; | |
1733 | { | |
1734 | if (aggr != class_type_node) | |
1735 | { | |
1736 | pedwarn ("template type parameters must use the keyword `class' or `typename'"); | |
1737 | aggr = class_type_node; | |
1738 | } | |
1739 | ||
1740 | return build_tree_list (aggr, identifier); | |
1741 | } | |
1742 | ||
1743 | /* Finish a template template parameter, specified as AGGR IDENTIFIER. | |
1744 | Returns the parameter. */ | |
1745 | ||
1746 | tree | |
1747 | finish_template_template_parm (aggr, identifier) | |
1748 | tree aggr; | |
1749 | tree identifier; | |
1750 | { | |
1751 | tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE); | |
1752 | tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); | |
1753 | DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; | |
1754 | DECL_TEMPLATE_RESULT (tmpl) = decl; | |
1755 | DECL_ARTIFICIAL (decl) = 1; | |
1756 | end_template_decl (); | |
1757 | ||
1758 | my_friendly_assert (DECL_TEMPLATE_PARMS (tmpl), 20010110); | |
1759 | ||
1760 | return finish_template_type_parm (aggr, tmpl); | |
1761 | } | |
1762 | ||
1763 | /* ARGUMENT is the default-argument value for a template template | |
1764 | parameter. If ARGUMENT is invalid, issue error messages and return | |
1765 | the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ | |
1766 | ||
1767 | tree | |
1768 | check_template_template_default_arg (tree argument) | |
1769 | { | |
1770 | if (TREE_CODE (argument) != TEMPLATE_DECL | |
1771 | && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM | |
1772 | && TREE_CODE (argument) != TYPE_DECL | |
1773 | && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) | |
1774 | { | |
1775 | error ("invalid default template argument"); | |
1776 | return error_mark_node; | |
1777 | } | |
1778 | ||
1779 | return argument; | |
1780 | } | |
1781 | ||
1782 | /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is | |
1783 | nonzero, the parameter list was terminated by a `...'. */ | |
1784 | ||
1785 | tree | |
1786 | finish_parmlist (parms, ellipsis) | |
1787 | tree parms; | |
1788 | int ellipsis; | |
1789 | { | |
1790 | if (parms) | |
1791 | { | |
1792 | /* We mark the PARMS as a parmlist so that declarator processing can | |
1793 | disambiguate certain constructs. */ | |
1794 | TREE_PARMLIST (parms) = 1; | |
1795 | /* We do not append void_list_node here, but leave it to grokparms | |
1796 | to do that. */ | |
1797 | PARMLIST_ELLIPSIS_P (parms) = ellipsis; | |
1798 | } | |
1799 | return parms; | |
1800 | } | |
1801 | ||
1802 | /* Begin a class definition, as indicated by T. */ | |
1803 | ||
1804 | tree | |
1805 | begin_class_definition (t) | |
1806 | tree t; | |
1807 | { | |
1808 | if (t == error_mark_node) | |
1809 | return error_mark_node; | |
1810 | ||
1811 | /* Check the bases are accessible. */ | |
1812 | decl_type_access_control (TYPE_NAME (t)); | |
1813 | reset_type_access_control (); | |
1814 | ||
1815 | if (processing_template_parmlist) | |
1816 | { | |
1817 | error ("definition of `%#T' inside template parameter list", t); | |
1818 | return error_mark_node; | |
1819 | } | |
1820 | ||
1821 | /* In a definition of a member class template, we will get here with | |
1822 | an implicit typename. */ | |
1823 | if (IMPLICIT_TYPENAME_P (t)) | |
1824 | t = TREE_TYPE (t); | |
1825 | /* A non-implicit typename comes from code like: | |
1826 | ||
1827 | template <typename T> struct A { | |
1828 | template <typename U> struct A<T>::B ... | |
1829 | ||
1830 | This is erroneous. */ | |
1831 | else if (TREE_CODE (t) == TYPENAME_TYPE) | |
1832 | { | |
1833 | error ("invalid definition of qualified type `%T'", t); | |
1834 | t = error_mark_node; | |
1835 | } | |
1836 | ||
1837 | if (t == error_mark_node || ! IS_AGGR_TYPE (t)) | |
1838 | { | |
1839 | t = make_aggr_type (RECORD_TYPE); | |
1840 | pushtag (make_anon_name (), t, 0); | |
1841 | } | |
1842 | ||
1843 | /* If we generated a partial instantiation of this type, but now | |
1844 | we're seeing a real definition, we're actually looking at a | |
1845 | partial specialization. Consider: | |
1846 | ||
1847 | template <class T, class U> | |
1848 | struct Y {}; | |
1849 | ||
1850 | template <class T> | |
1851 | struct X {}; | |
1852 | ||
1853 | template <class T, class U> | |
1854 | void f() | |
1855 | { | |
1856 | typename X<Y<T, U> >::A a; | |
1857 | } | |
1858 | ||
1859 | template <class T, class U> | |
1860 | struct X<Y<T, U> > | |
1861 | { | |
1862 | }; | |
1863 | ||
1864 | We have to undo the effects of the previous partial | |
1865 | instantiation. */ | |
1866 | if (PARTIAL_INSTANTIATION_P (t)) | |
1867 | { | |
1868 | if (!pedantic) | |
1869 | { | |
1870 | /* Unfortunately, when we're not in pedantic mode, we | |
1871 | attempt to actually fill in some of the fields of the | |
1872 | partial instantiation, in order to support the implicit | |
1873 | typename extension. Clear those fields now, in | |
1874 | preparation for the definition here. The fields cleared | |
1875 | here must match those set in instantiate_class_template. | |
1876 | Look for a comment mentioning begin_class_definition | |
1877 | there. */ | |
1878 | TYPE_BINFO_BASETYPES (t) = NULL_TREE; | |
1879 | TYPE_FIELDS (t) = NULL_TREE; | |
1880 | TYPE_METHODS (t) = NULL_TREE; | |
1881 | CLASSTYPE_DECL_LIST (t) = NULL_TREE; | |
1882 | CLASSTYPE_TAGS (t) = NULL_TREE; | |
1883 | CLASSTYPE_VBASECLASSES (t) = NULL_TREE; | |
1884 | TYPE_SIZE (t) = NULL_TREE; | |
1885 | } | |
1886 | ||
1887 | /* This isn't a partial instantiation any more. */ | |
1888 | PARTIAL_INSTANTIATION_P (t) = 0; | |
1889 | } | |
1890 | /* If this type was already complete, and we see another definition, | |
1891 | that's an error. */ | |
1892 | else if (COMPLETE_TYPE_P (t)) | |
1893 | duplicate_tag_error (t); | |
1894 | ||
1895 | /* Update the location of the decl. */ | |
1896 | DECL_SOURCE_FILE (TYPE_NAME (t)) = input_filename; | |
1897 | DECL_SOURCE_LINE (TYPE_NAME (t)) = lineno; | |
1898 | ||
1899 | if (TYPE_BEING_DEFINED (t)) | |
1900 | { | |
1901 | t = make_aggr_type (TREE_CODE (t)); | |
1902 | pushtag (TYPE_IDENTIFIER (t), t, 0); | |
1903 | } | |
1904 | maybe_process_partial_specialization (t); | |
1905 | pushclass (t, 1); | |
1906 | TYPE_BEING_DEFINED (t) = 1; | |
1907 | TYPE_PACKED (t) = flag_pack_struct; | |
1908 | /* Reset the interface data, at the earliest possible | |
1909 | moment, as it might have been set via a class foo; | |
1910 | before. */ | |
1911 | if (! TYPE_ANONYMOUS_P (t)) | |
1912 | { | |
1913 | CLASSTYPE_INTERFACE_ONLY (t) = interface_only; | |
1914 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X | |
1915 | (t, interface_unknown); | |
1916 | } | |
1917 | reset_specialization(); | |
1918 | ||
1919 | /* Make a declaration for this class in its own scope. */ | |
1920 | build_self_reference (); | |
1921 | ||
1922 | return t; | |
1923 | } | |
1924 | ||
1925 | /* Finish the member declaration given by DECL. */ | |
1926 | ||
1927 | void | |
1928 | finish_member_declaration (decl) | |
1929 | tree decl; | |
1930 | { | |
1931 | if (decl == error_mark_node || decl == NULL_TREE) | |
1932 | return; | |
1933 | ||
1934 | if (decl == void_type_node) | |
1935 | /* The COMPONENT was a friend, not a member, and so there's | |
1936 | nothing for us to do. */ | |
1937 | return; | |
1938 | ||
1939 | /* We should see only one DECL at a time. */ | |
1940 | my_friendly_assert (TREE_CHAIN (decl) == NULL_TREE, 0); | |
1941 | ||
1942 | /* Set up access control for DECL. */ | |
1943 | TREE_PRIVATE (decl) | |
1944 | = (current_access_specifier == access_private_node); | |
1945 | TREE_PROTECTED (decl) | |
1946 | = (current_access_specifier == access_protected_node); | |
1947 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
1948 | { | |
1949 | TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); | |
1950 | TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); | |
1951 | } | |
1952 | ||
1953 | /* Mark the DECL as a member of the current class. */ | |
1954 | DECL_CONTEXT (decl) = current_class_type; | |
1955 | ||
1956 | /* [dcl.link] | |
1957 | ||
1958 | A C language linkage is ignored for the names of class members | |
1959 | and the member function type of class member functions. */ | |
1960 | if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c) | |
1961 | SET_DECL_LANGUAGE (decl, lang_cplusplus); | |
1962 | ||
1963 | maybe_add_class_template_decl_list (current_class_type, decl, /*friend_p=*/0); | |
1964 | ||
1965 | /* Put functions on the TYPE_METHODS list and everything else on the | |
1966 | TYPE_FIELDS list. Note that these are built up in reverse order. | |
1967 | We reverse them (to obtain declaration order) in finish_struct. */ | |
1968 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1969 | || DECL_FUNCTION_TEMPLATE_P (decl)) | |
1970 | { | |
1971 | /* We also need to add this function to the | |
1972 | CLASSTYPE_METHOD_VEC. */ | |
1973 | add_method (current_class_type, decl, /*error_p=*/0); | |
1974 | ||
1975 | TREE_CHAIN (decl) = TYPE_METHODS (current_class_type); | |
1976 | TYPE_METHODS (current_class_type) = decl; | |
1977 | } | |
1978 | else | |
1979 | { | |
1980 | /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields | |
1981 | go at the beginning. The reason is that lookup_field_1 | |
1982 | searches the list in order, and we want a field name to | |
1983 | override a type name so that the "struct stat hack" will | |
1984 | work. In particular: | |
1985 | ||
1986 | struct S { enum E { }; int E } s; | |
1987 | s.E = 3; | |
1988 | ||
1989 | is valid. In addition, the FIELD_DECLs must be maintained in | |
1990 | declaration order so that class layout works as expected. | |
1991 | However, we don't need that order until class layout, so we | |
1992 | save a little time by putting FIELD_DECLs on in reverse order | |
1993 | here, and then reversing them in finish_struct_1. (We could | |
1994 | also keep a pointer to the correct insertion points in the | |
1995 | list.) */ | |
1996 | ||
1997 | if (TREE_CODE (decl) == TYPE_DECL) | |
1998 | TYPE_FIELDS (current_class_type) | |
1999 | = chainon (TYPE_FIELDS (current_class_type), decl); | |
2000 | else | |
2001 | { | |
2002 | TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type); | |
2003 | TYPE_FIELDS (current_class_type) = decl; | |
2004 | } | |
2005 | ||
2006 | /* Enter the DECL into the scope of the class. */ | |
2007 | if (TREE_CODE (decl) != USING_DECL) | |
2008 | pushdecl_class_level (decl); | |
2009 | } | |
2010 | } | |
2011 | ||
2012 | /* Finish a class definition T with the indicate ATTRIBUTES. If SEMI, | |
2013 | the definition is immediately followed by a semicolon. Returns the | |
2014 | type. */ | |
2015 | ||
2016 | tree | |
2017 | finish_class_definition (t, attributes, semi, pop_scope_p) | |
2018 | tree t; | |
2019 | tree attributes; | |
2020 | int semi; | |
2021 | int pop_scope_p; | |
2022 | { | |
2023 | if (t == error_mark_node) | |
2024 | return error_mark_node; | |
2025 | ||
2026 | /* finish_struct nukes this anyway; if finish_exception does too, | |
2027 | then it can go. */ | |
2028 | if (semi) | |
2029 | note_got_semicolon (t); | |
2030 | ||
2031 | /* If we got any attributes in class_head, xref_tag will stick them in | |
2032 | TREE_TYPE of the type. Grab them now. */ | |
2033 | attributes = chainon (TYPE_ATTRIBUTES (t), attributes); | |
2034 | TYPE_ATTRIBUTES (t) = NULL_TREE; | |
2035 | ||
2036 | if (TREE_CODE (t) == ENUMERAL_TYPE) | |
2037 | ; | |
2038 | else | |
2039 | { | |
2040 | t = finish_struct (t, attributes); | |
2041 | if (semi) | |
2042 | note_got_semicolon (t); | |
2043 | } | |
2044 | ||
2045 | if (pop_scope_p) | |
2046 | pop_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (t))); | |
2047 | ||
2048 | return t; | |
2049 | } | |
2050 | ||
2051 | /* Finish processing the declaration of a member class template | |
2052 | TYPES whose template parameters are given by PARMS. */ | |
2053 | ||
2054 | tree | |
2055 | finish_member_class_template (types) | |
2056 | tree types; | |
2057 | { | |
2058 | tree t; | |
2059 | ||
2060 | /* If there are declared, but undefined, partial specializations | |
2061 | mixed in with the typespecs they will not yet have passed through | |
2062 | maybe_process_partial_specialization, so we do that here. */ | |
2063 | for (t = types; t != NULL_TREE; t = TREE_CHAIN (t)) | |
2064 | if (IS_AGGR_TYPE_CODE (TREE_CODE (TREE_VALUE (t)))) | |
2065 | maybe_process_partial_specialization (TREE_VALUE (t)); | |
2066 | ||
2067 | note_list_got_semicolon (types); | |
2068 | grok_x_components (types); | |
2069 | if (TYPE_CONTEXT (TREE_VALUE (types)) != current_class_type) | |
2070 | /* The component was in fact a friend declaration. We avoid | |
2071 | finish_member_template_decl performing certain checks by | |
2072 | unsetting TYPES. */ | |
2073 | types = NULL_TREE; | |
2074 | ||
2075 | finish_member_template_decl (types); | |
2076 | ||
2077 | /* As with other component type declarations, we do | |
2078 | not store the new DECL on the list of | |
2079 | component_decls. */ | |
2080 | return NULL_TREE; | |
2081 | } | |
2082 | ||
2083 | /* Finish processing a complete template declaration. The PARMS are | |
2084 | the template parameters. */ | |
2085 | ||
2086 | void | |
2087 | finish_template_decl (parms) | |
2088 | tree parms; | |
2089 | { | |
2090 | if (parms) | |
2091 | end_template_decl (); | |
2092 | else | |
2093 | end_specialization (); | |
2094 | } | |
2095 | ||
2096 | /* Finish processing a template-id (which names a type) of the form | |
2097 | NAME < ARGS >. Return the TYPE_DECL for the type named by the | |
2098 | template-id. If ENTERING_SCOPE is nonzero we are about to enter | |
2099 | the scope of template-id indicated. */ | |
2100 | ||
2101 | tree | |
2102 | finish_template_type (name, args, entering_scope) | |
2103 | tree name; | |
2104 | tree args; | |
2105 | int entering_scope; | |
2106 | { | |
2107 | tree decl; | |
2108 | ||
2109 | decl = lookup_template_class (name, args, | |
2110 | NULL_TREE, NULL_TREE, | |
2111 | entering_scope, /*complain=*/1); | |
2112 | if (decl != error_mark_node) | |
2113 | decl = TYPE_STUB_DECL (decl); | |
2114 | ||
2115 | return decl; | |
2116 | } | |
2117 | ||
2118 | /* SR is a SCOPE_REF node. Enter the scope of SR, whether it is a | |
2119 | namespace scope or a class scope. */ | |
2120 | ||
2121 | void | |
2122 | enter_scope_of (sr) | |
2123 | tree sr; | |
2124 | { | |
2125 | tree scope = TREE_OPERAND (sr, 0); | |
2126 | ||
2127 | if (TREE_CODE (scope) == NAMESPACE_DECL) | |
2128 | { | |
2129 | push_decl_namespace (scope); | |
2130 | TREE_COMPLEXITY (sr) = -1; | |
2131 | } | |
2132 | else if (scope != current_class_type) | |
2133 | { | |
2134 | if (TREE_CODE (scope) == TYPENAME_TYPE) | |
2135 | { | |
2136 | /* In a declarator for a template class member, the scope will | |
2137 | get here as an implicit typename, a TYPENAME_TYPE with a type. */ | |
2138 | scope = TREE_TYPE (scope); | |
2139 | TREE_OPERAND (sr, 0) = scope; | |
2140 | } | |
2141 | push_nested_class (scope, 3); | |
2142 | TREE_COMPLEXITY (sr) = current_class_depth; | |
2143 | } | |
2144 | } | |
2145 | ||
2146 | /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. | |
2147 | Return a TREE_LIST containing the ACCESS_SPECIFIER and the | |
2148 | BASE_CLASS, or NULL_TREE if an error occurred. The | |
2149 | ACCESS_SPECIFIER is one of | |
2150 | access_{default,public,protected_private}[_virtual]_node.*/ | |
2151 | ||
2152 | tree | |
2153 | finish_base_specifier (access_specifier, base_class) | |
2154 | tree access_specifier; | |
2155 | tree base_class; | |
2156 | { | |
2157 | tree result; | |
2158 | ||
2159 | if (base_class == error_mark_node) | |
2160 | { | |
2161 | error ("invalid base-class specification"); | |
2162 | result = NULL_TREE; | |
2163 | } | |
2164 | else if (! is_aggr_type (base_class, 1)) | |
2165 | result = NULL_TREE; | |
2166 | else | |
2167 | { | |
2168 | if (cp_type_quals (base_class) != 0) | |
2169 | { | |
2170 | error ("base class `%T' has cv qualifiers", base_class); | |
2171 | base_class = TYPE_MAIN_VARIANT (base_class); | |
2172 | } | |
2173 | result = build_tree_list (access_specifier, base_class); | |
2174 | } | |
2175 | ||
2176 | return result; | |
2177 | } | |
2178 | ||
2179 | /* Called when multiple declarators are processed. If that is not | |
2180 | premitted in this context, an error is issued. */ | |
2181 | ||
2182 | void | |
2183 | check_multiple_declarators () | |
2184 | { | |
2185 | /* [temp] | |
2186 | ||
2187 | In a template-declaration, explicit specialization, or explicit | |
2188 | instantiation the init-declarator-list in the declaration shall | |
2189 | contain at most one declarator. | |
2190 | ||
2191 | We don't just use PROCESSING_TEMPLATE_DECL for the first | |
2192 | condition since that would disallow the perfectly valid code, | |
2193 | like `template <class T> struct S { int i, j; };'. */ | |
2194 | if (at_function_scope_p ()) | |
2195 | /* It's OK to write `template <class T> void f() { int i, j;}'. */ | |
2196 | return; | |
2197 | ||
2198 | if (PROCESSING_REAL_TEMPLATE_DECL_P () | |
2199 | || processing_explicit_instantiation | |
2200 | || processing_specialization) | |
2201 | error ("multiple declarators in template declaration"); | |
2202 | } | |
2203 | ||
2204 | /* Implement the __typeof keyword: Return the type of EXPR, suitable for | |
2205 | use as a type-specifier. */ | |
2206 | ||
2207 | tree | |
2208 | finish_typeof (expr) | |
2209 | tree expr; | |
2210 | { | |
2211 | if (processing_template_decl) | |
2212 | { | |
2213 | tree t; | |
2214 | ||
2215 | t = make_aggr_type (TYPEOF_TYPE); | |
2216 | TYPE_FIELDS (t) = expr; | |
2217 | ||
2218 | return t; | |
2219 | } | |
2220 | ||
2221 | if (TREE_CODE (expr) == OFFSET_REF) | |
2222 | expr = resolve_offset_ref (expr); | |
2223 | ||
2224 | return TREE_TYPE (expr); | |
2225 | } | |
2226 | ||
2227 | /* Compute the value of the `sizeof' operator. */ | |
2228 | ||
2229 | tree | |
2230 | finish_sizeof (t) | |
2231 | tree t; | |
2232 | { | |
2233 | return TYPE_P (t) ? cxx_sizeof (t) : expr_sizeof (t); | |
2234 | } | |
2235 | ||
2236 | /* Implement the __alignof keyword: Return the minimum required | |
2237 | alignment of T, measured in bytes. */ | |
2238 | ||
2239 | tree | |
2240 | finish_alignof (t) | |
2241 | tree t; | |
2242 | { | |
2243 | if (processing_template_decl) | |
2244 | return build_min (ALIGNOF_EXPR, size_type_node, t); | |
2245 | ||
2246 | return TYPE_P (t) ? cxx_alignof (t) : c_alignof_expr (t); | |
2247 | } | |
2248 | ||
2249 | /* Generate RTL for the statement T, and its substatements, and any | |
2250 | other statements at its nesting level. */ | |
2251 | ||
2252 | static void | |
2253 | cp_expand_stmt (t) | |
2254 | tree t; | |
2255 | { | |
2256 | switch (TREE_CODE (t)) | |
2257 | { | |
2258 | case TRY_BLOCK: | |
2259 | genrtl_try_block (t); | |
2260 | break; | |
2261 | ||
2262 | case EH_SPEC_BLOCK: | |
2263 | genrtl_eh_spec_block (t); | |
2264 | break; | |
2265 | ||
2266 | case HANDLER: | |
2267 | genrtl_handler (t); | |
2268 | break; | |
2269 | ||
2270 | case RETURN_INIT: | |
2271 | genrtl_named_return_value (); | |
2272 | break; | |
2273 | ||
2274 | case USING_STMT: | |
2275 | break; | |
2276 | ||
2277 | default: | |
2278 | abort (); | |
2279 | break; | |
2280 | } | |
2281 | } | |
2282 | ||
2283 | /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs | |
2284 | will equivalent CALL_EXPRs. */ | |
2285 | ||
2286 | static tree | |
2287 | simplify_aggr_init_exprs_r (tp, walk_subtrees, data) | |
2288 | tree *tp; | |
2289 | int *walk_subtrees ATTRIBUTE_UNUSED; | |
2290 | void *data ATTRIBUTE_UNUSED; | |
2291 | { | |
2292 | tree aggr_init_expr; | |
2293 | tree call_expr; | |
2294 | tree fn; | |
2295 | tree args; | |
2296 | tree slot; | |
2297 | tree type; | |
2298 | enum style_t { ctor, arg, pcc } style; | |
2299 | ||
2300 | aggr_init_expr = *tp; | |
2301 | /* We don't need to walk into types; there's nothing in a type that | |
2302 | needs simplification. (And, furthermore, there are places we | |
2303 | actively don't want to go. For example, we don't want to wander | |
2304 | into the default arguments for a FUNCTION_DECL that appears in a | |
2305 | CALL_EXPR.) */ | |
2306 | if (TYPE_P (aggr_init_expr)) | |
2307 | { | |
2308 | *walk_subtrees = 0; | |
2309 | return NULL_TREE; | |
2310 | } | |
2311 | /* Only AGGR_INIT_EXPRs are interesting. */ | |
2312 | else if (TREE_CODE (aggr_init_expr) != AGGR_INIT_EXPR) | |
2313 | return NULL_TREE; | |
2314 | ||
2315 | /* Form an appropriate CALL_EXPR. */ | |
2316 | fn = TREE_OPERAND (aggr_init_expr, 0); | |
2317 | args = TREE_OPERAND (aggr_init_expr, 1); | |
2318 | slot = TREE_OPERAND (aggr_init_expr, 2); | |
2319 | type = TREE_TYPE (aggr_init_expr); | |
2320 | ||
2321 | if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) | |
2322 | style = ctor; | |
2323 | #ifdef PCC_STATIC_STRUCT_RETURN | |
2324 | else if (1) | |
2325 | style = pcc; | |
2326 | #endif | |
2327 | else if (TREE_ADDRESSABLE (type)) | |
2328 | style = arg; | |
2329 | else | |
2330 | /* We shouldn't build an AGGR_INIT_EXPR if we don't need any special | |
2331 | handling. See build_cplus_new. */ | |
2332 | abort (); | |
2333 | ||
2334 | if (style == ctor || style == arg) | |
2335 | { | |
2336 | /* Pass the address of the slot. If this is a constructor, we | |
2337 | replace the first argument; otherwise, we tack on a new one. */ | |
2338 | if (style == ctor) | |
2339 | args = TREE_CHAIN (args); | |
2340 | ||
2341 | cxx_mark_addressable (slot); | |
2342 | args = tree_cons (NULL_TREE, | |
2343 | build1 (ADDR_EXPR, | |
2344 | build_pointer_type (TREE_TYPE (slot)), | |
2345 | slot), | |
2346 | args); | |
2347 | } | |
2348 | ||
2349 | call_expr = build (CALL_EXPR, | |
2350 | TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), | |
2351 | fn, args, NULL_TREE); | |
2352 | TREE_SIDE_EFFECTS (call_expr) = 1; | |
2353 | ||
2354 | if (style == arg) | |
2355 | /* Tell the backend that we've added our return slot to the argument | |
2356 | list. */ | |
2357 | CALL_EXPR_HAS_RETURN_SLOT_ADDR (call_expr) = 1; | |
2358 | else if (style == pcc) | |
2359 | { | |
2360 | /* If we're using the non-reentrant PCC calling convention, then we | |
2361 | need to copy the returned value out of the static buffer into the | |
2362 | SLOT. */ | |
2363 | int old_ac = flag_access_control; | |
2364 | ||
2365 | flag_access_control = 0; | |
2366 | call_expr = build_aggr_init (slot, call_expr, | |
2367 | DIRECT_BIND | LOOKUP_ONLYCONVERTING); | |
2368 | flag_access_control = old_ac; | |
2369 | } | |
2370 | ||
2371 | /* We want to use the value of the initialized location as the | |
2372 | result. */ | |
2373 | call_expr = build (COMPOUND_EXPR, type, | |
2374 | call_expr, slot); | |
2375 | ||
2376 | /* Replace the AGGR_INIT_EXPR with the CALL_EXPR. */ | |
2377 | TREE_CHAIN (call_expr) = TREE_CHAIN (aggr_init_expr); | |
2378 | *tp = call_expr; | |
2379 | ||
2380 | /* Keep iterating. */ | |
2381 | return NULL_TREE; | |
2382 | } | |
2383 | ||
2384 | /* Emit all thunks to FN that should be emitted when FN is emitted. */ | |
2385 | ||
2386 | static void | |
2387 | emit_associated_thunks (fn) | |
2388 | tree fn; | |
2389 | { | |
2390 | /* When we use vcall offsets, we emit thunks with the virtual | |
2391 | functions to which they thunk. The whole point of vcall offsets | |
2392 | is so that you can know statically the entire set of thunks that | |
2393 | will ever be needed for a given virtual function, thereby | |
2394 | enabling you to output all the thunks with the function itself. */ | |
2395 | if (DECL_VIRTUAL_P (fn)) | |
2396 | { | |
2397 | tree thunk; | |
2398 | ||
2399 | for (thunk = DECL_THUNKS (fn); thunk; thunk = TREE_CHAIN (thunk)) | |
2400 | { | |
2401 | use_thunk (thunk, /*emit_p=*/1); | |
2402 | if (DECL_RESULT_THUNK_P (thunk)) | |
2403 | { | |
2404 | tree probe; | |
2405 | ||
2406 | for (probe = DECL_THUNKS (thunk); | |
2407 | probe; probe = TREE_CHAIN (probe)) | |
2408 | use_thunk (probe, /*emit_p=*/1); | |
2409 | } | |
2410 | } | |
2411 | } | |
2412 | } | |
2413 | ||
2414 | /* Generate RTL for FN. */ | |
2415 | ||
2416 | void | |
2417 | expand_body (fn) | |
2418 | tree fn; | |
2419 | { | |
2420 | int saved_lineno; | |
2421 | const char *saved_input_filename; | |
2422 | tree saved_function; | |
2423 | ||
2424 | /* When the parser calls us after finishing the body of a template | |
2425 | function, we don't really want to expand the body. When we're | |
2426 | processing an in-class definition of an inline function, | |
2427 | PROCESSING_TEMPLATE_DECL will no longer be set here, so we have | |
2428 | to look at the function itself. */ | |
2429 | if (processing_template_decl | |
2430 | || (DECL_LANG_SPECIFIC (fn) | |
2431 | && DECL_TEMPLATE_INFO (fn) | |
2432 | && uses_template_parms (DECL_TI_ARGS (fn)))) | |
2433 | { | |
2434 | /* Normally, collection only occurs in rest_of_compilation. So, | |
2435 | if we don't collect here, we never collect junk generated | |
2436 | during the processing of templates until we hit a | |
2437 | non-template function. */ | |
2438 | ggc_collect (); | |
2439 | return; | |
2440 | } | |
2441 | ||
2442 | /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */ | |
2443 | walk_tree_without_duplicates (&DECL_SAVED_TREE (fn), | |
2444 | simplify_aggr_init_exprs_r, | |
2445 | NULL); | |
2446 | ||
2447 | /* If this is a constructor or destructor body, we have to clone | |
2448 | it. */ | |
2449 | if (maybe_clone_body (fn)) | |
2450 | { | |
2451 | /* We don't want to process FN again, so pretend we've written | |
2452 | it out, even though we haven't. */ | |
2453 | TREE_ASM_WRITTEN (fn) = 1; | |
2454 | return; | |
2455 | } | |
2456 | ||
2457 | /* There's no reason to do any of the work here if we're only doing | |
2458 | semantic analysis; this code just generates RTL. */ | |
2459 | if (flag_syntax_only) | |
2460 | return; | |
2461 | ||
2462 | /* If possible, avoid generating RTL for this function. Instead, | |
2463 | just record it as an inline function, and wait until end-of-file | |
2464 | to decide whether to write it out or not. */ | |
2465 | if (/* We have to generate RTL if it's not an inline function. */ | |
2466 | (DECL_INLINE (fn) || DECL_COMDAT (fn)) | |
2467 | /* Or if we have to emit code for inline functions anyhow. */ | |
2468 | && !flag_keep_inline_functions | |
2469 | /* Or if we actually have a reference to the function. */ | |
2470 | && !DECL_NEEDED_P (fn)) | |
2471 | { | |
2472 | /* Set DECL_EXTERNAL so that assemble_external will be called as | |
2473 | necessary. We'll clear it again in finish_file. */ | |
2474 | if (!DECL_EXTERNAL (fn)) | |
2475 | { | |
2476 | DECL_NOT_REALLY_EXTERN (fn) = 1; | |
2477 | DECL_EXTERNAL (fn) = 1; | |
2478 | } | |
2479 | /* Remember this function. In finish_file we'll decide if | |
2480 | we actually need to write this function out. */ | |
2481 | defer_fn (fn); | |
2482 | /* Let the back-end know that this function exists. */ | |
2483 | (*debug_hooks->deferred_inline_function) (fn); | |
2484 | return; | |
2485 | } | |
2486 | ||
2487 | /* Compute the appropriate object-file linkage for inline | |
2488 | functions. */ | |
2489 | if (DECL_DECLARED_INLINE_P (fn)) | |
2490 | import_export_decl (fn); | |
2491 | ||
2492 | /* If FN is external, then there's no point in generating RTL for | |
2493 | it. This situation can arise with an inline function under | |
2494 | `-fexternal-templates'; we instantiate the function, even though | |
2495 | we're not planning on emitting it, in case we get a chance to | |
2496 | inline it. */ | |
2497 | if (DECL_EXTERNAL (fn)) | |
2498 | return; | |
2499 | ||
2500 | /* Save the current file name and line number. When we expand the | |
2501 | body of the function, we'll set LINENO and INPUT_FILENAME so that | |
2502 | error-mesages come out in the right places. */ | |
2503 | saved_lineno = lineno; | |
2504 | saved_input_filename = input_filename; | |
2505 | saved_function = current_function_decl; | |
2506 | lineno = DECL_SOURCE_LINE (fn); | |
2507 | input_filename = DECL_SOURCE_FILE (fn); | |
2508 | current_function_decl = fn; | |
2509 | ||
2510 | timevar_push (TV_INTEGRATION); | |
2511 | ||
2512 | /* Optimize the body of the function before expanding it. */ | |
2513 | optimize_function (fn); | |
2514 | ||
2515 | timevar_pop (TV_INTEGRATION); | |
2516 | timevar_push (TV_EXPAND); | |
2517 | ||
2518 | genrtl_start_function (fn); | |
2519 | current_function_is_thunk = DECL_THUNK_P (fn); | |
2520 | ||
2521 | /* Expand the body. */ | |
2522 | expand_stmt (DECL_SAVED_TREE (fn)); | |
2523 | ||
2524 | /* Statements should always be full-expressions at the outermost set | |
2525 | of curly braces for a function. */ | |
2526 | my_friendly_assert (stmts_are_full_exprs_p (), 19990831); | |
2527 | ||
2528 | /* The outermost statement for a function contains the line number | |
2529 | recorded when we finished processing the function. */ | |
2530 | lineno = STMT_LINENO (DECL_SAVED_TREE (fn)); | |
2531 | ||
2532 | /* Generate code for the function. */ | |
2533 | genrtl_finish_function (fn); | |
2534 | ||
2535 | /* If possible, obliterate the body of the function so that it can | |
2536 | be garbage collected. */ | |
2537 | if (dump_enabled_p (TDI_all)) | |
2538 | /* Keep the body; we're going to dump it. */ | |
2539 | ; | |
2540 | else if (DECL_INLINE (fn) && flag_inline_trees) | |
2541 | /* We might need the body of this function so that we can expand | |
2542 | it inline somewhere else. */ | |
2543 | ; | |
2544 | else | |
2545 | /* We don't need the body; blow it away. */ | |
2546 | DECL_SAVED_TREE (fn) = NULL_TREE; | |
2547 | ||
2548 | /* And restore the current source position. */ | |
2549 | current_function_decl = saved_function; | |
2550 | lineno = saved_lineno; | |
2551 | input_filename = saved_input_filename; | |
2552 | extract_interface_info (); | |
2553 | ||
2554 | timevar_pop (TV_EXPAND); | |
2555 | ||
2556 | /* Emit any thunks that should be emitted at the same time as FN. */ | |
2557 | emit_associated_thunks (fn); | |
2558 | } | |
2559 | ||
2560 | /* Helper function for walk_tree, used by finish_function to override all | |
2561 | the RETURN_STMTs and pertinent CLEANUP_STMTs for the named return | |
2562 | value optimization. */ | |
2563 | ||
2564 | tree | |
2565 | nullify_returns_r (tp, walk_subtrees, data) | |
2566 | tree *tp; | |
2567 | int *walk_subtrees; | |
2568 | void *data; | |
2569 | { | |
2570 | tree nrv = (tree) data; | |
2571 | ||
2572 | /* No need to walk into types. There wouldn't be any need to walk into | |
2573 | non-statements, except that we have to consider STMT_EXPRs. */ | |
2574 | if (TYPE_P (*tp)) | |
2575 | *walk_subtrees = 0; | |
2576 | else if (TREE_CODE (*tp) == RETURN_STMT) | |
2577 | RETURN_STMT_EXPR (*tp) = NULL_TREE; | |
2578 | else if (TREE_CODE (*tp) == CLEANUP_STMT | |
2579 | && CLEANUP_DECL (*tp) == nrv) | |
2580 | CLEANUP_EH_ONLY (*tp) = 1; | |
2581 | ||
2582 | /* Keep iterating. */ | |
2583 | return NULL_TREE; | |
2584 | } | |
2585 | ||
2586 | /* Start generating the RTL for FN. */ | |
2587 | ||
2588 | static void | |
2589 | genrtl_start_function (fn) | |
2590 | tree fn; | |
2591 | { | |
2592 | /* Tell everybody what function we're processing. */ | |
2593 | current_function_decl = fn; | |
2594 | /* Get the RTL machinery going for this function. */ | |
2595 | init_function_start (fn, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn)); | |
2596 | /* Let everybody know that we're expanding this function, not doing | |
2597 | semantic analysis. */ | |
2598 | expanding_p = 1; | |
2599 | ||
2600 | /* Even though we're inside a function body, we still don't want to | |
2601 | call expand_expr to calculate the size of a variable-sized array. | |
2602 | We haven't necessarily assigned RTL to all variables yet, so it's | |
2603 | not safe to try to expand expressions involving them. */ | |
2604 | immediate_size_expand = 0; | |
2605 | cfun->x_dont_save_pending_sizes_p = 1; | |
2606 | ||
2607 | /* Let the user know we're compiling this function. */ | |
2608 | announce_function (fn); | |
2609 | ||
2610 | /* Initialize the per-function data. */ | |
2611 | my_friendly_assert (!DECL_PENDING_INLINE_P (fn), 20000911); | |
2612 | if (DECL_SAVED_FUNCTION_DATA (fn)) | |
2613 | { | |
2614 | /* If we already parsed this function, and we're just expanding it | |
2615 | now, restore saved state. */ | |
2616 | *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn); | |
2617 | ||
2618 | /* This function is being processed in whole-function mode; we | |
2619 | already did semantic analysis. */ | |
2620 | cfun->x_whole_function_mode_p = 1; | |
2621 | ||
2622 | /* If we decided that we didn't want to inline this function, | |
2623 | make sure the back-end knows that. */ | |
2624 | if (!current_function_cannot_inline) | |
2625 | current_function_cannot_inline = cp_function_chain->cannot_inline; | |
2626 | ||
2627 | /* We don't need the saved data anymore. Unless this is an inline | |
2628 | function; we need the named return value info for | |
2629 | cp_copy_res_decl_for_inlining. */ | |
2630 | if (! DECL_INLINE (fn)) | |
2631 | DECL_SAVED_FUNCTION_DATA (fn) = NULL; | |
2632 | } | |
2633 | ||
2634 | /* Keep track of how many functions we're presently expanding. */ | |
2635 | ++function_depth; | |
2636 | ||
2637 | /* Create a binding level for the parameters. */ | |
2638 | expand_function_start (fn, /*parms_have_cleanups=*/0); | |
2639 | /* If this function is `main'. */ | |
2640 | if (DECL_MAIN_P (fn)) | |
2641 | expand_main_function (); | |
2642 | ||
2643 | /* Give our named return value the same RTL as our RESULT_DECL. */ | |
2644 | if (current_function_return_value) | |
2645 | COPY_DECL_RTL (DECL_RESULT (fn), current_function_return_value); | |
2646 | } | |
2647 | ||
2648 | /* Finish generating the RTL for FN. */ | |
2649 | ||
2650 | static void | |
2651 | genrtl_finish_function (fn) | |
2652 | tree fn; | |
2653 | { | |
2654 | tree t; | |
2655 | ||
2656 | #if 0 | |
2657 | if (write_symbols != NO_DEBUG) | |
2658 | { | |
2659 | /* Keep this code around in case we later want to control debug info | |
2660 | based on whether a type is "used". (jason 1999-11-11) */ | |
2661 | ||
2662 | tree ttype = target_type (fntype); | |
2663 | tree parmdecl; | |
2664 | ||
2665 | if (IS_AGGR_TYPE (ttype)) | |
2666 | /* Let debugger know it should output info for this type. */ | |
2667 | note_debug_info_needed (ttype); | |
2668 | ||
2669 | for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) | |
2670 | { | |
2671 | ttype = target_type (TREE_TYPE (parmdecl)); | |
2672 | if (IS_AGGR_TYPE (ttype)) | |
2673 | /* Let debugger know it should output info for this type. */ | |
2674 | note_debug_info_needed (ttype); | |
2675 | } | |
2676 | } | |
2677 | #endif | |
2678 | ||
2679 | /* Clean house because we will need to reorder insns here. */ | |
2680 | do_pending_stack_adjust (); | |
2681 | ||
2682 | /* If we have a named return value, we need to force a return so that | |
2683 | the return register is USEd. */ | |
2684 | if (DECL_NAME (DECL_RESULT (fn))) | |
2685 | emit_jump (return_label); | |
2686 | ||
2687 | /* We hard-wired immediate_size_expand to zero in start_function. | |
2688 | Expand_function_end will decrement this variable. So, we set the | |
2689 | variable to one here, so that after the decrement it will remain | |
2690 | zero. */ | |
2691 | immediate_size_expand = 1; | |
2692 | ||
2693 | /* Generate rtl for function exit. */ | |
2694 | expand_function_end (input_filename, lineno, 0); | |
2695 | ||
2696 | /* If this is a nested function (like a template instantiation that | |
2697 | we're compiling in the midst of compiling something else), push a | |
2698 | new GC context. That will keep local variables on the stack from | |
2699 | being collected while we're doing the compilation of this | |
2700 | function. */ | |
2701 | if (function_depth > 1) | |
2702 | ggc_push_context (); | |
2703 | ||
2704 | /* There's no need to defer outputting this function any more; we | |
2705 | know we want to output it. */ | |
2706 | DECL_DEFER_OUTPUT (fn) = 0; | |
2707 | ||
2708 | /* Run the optimizers and output the assembler code for this | |
2709 | function. */ | |
2710 | rest_of_compilation (fn); | |
2711 | ||
2712 | /* Undo the call to ggc_push_context above. */ | |
2713 | if (function_depth > 1) | |
2714 | ggc_pop_context (); | |
2715 | ||
2716 | #if 0 | |
2717 | /* Keep this code around in case we later want to control debug info | |
2718 | based on whether a type is "used". (jason 1999-11-11) */ | |
2719 | ||
2720 | if (ctype && TREE_ASM_WRITTEN (fn)) | |
2721 | note_debug_info_needed (ctype); | |
2722 | #endif | |
2723 | ||
2724 | /* If this function is marked with the constructor attribute, add it | |
2725 | to the list of functions to be called along with constructors | |
2726 | from static duration objects. */ | |
2727 | if (DECL_STATIC_CONSTRUCTOR (fn)) | |
2728 | static_ctors = tree_cons (NULL_TREE, fn, static_ctors); | |
2729 | ||
2730 | /* If this function is marked with the destructor attribute, add it | |
2731 | to the list of functions to be called along with destructors from | |
2732 | static duration objects. */ | |
2733 | if (DECL_STATIC_DESTRUCTOR (fn)) | |
2734 | static_dtors = tree_cons (NULL_TREE, fn, static_dtors); | |
2735 | ||
2736 | --function_depth; | |
2737 | ||
2738 | /* In C++, we should never be saving RTL for the function. */ | |
2739 | my_friendly_assert (!DECL_SAVED_INSNS (fn), 20010903); | |
2740 | ||
2741 | /* Since we don't need the RTL for this function anymore, stop | |
2742 | pointing to it. That's especially important for LABEL_DECLs, | |
2743 | since you can reach all the instructions in the function from the | |
2744 | CODE_LABEL stored in the DECL_RTL for the LABEL_DECL. Walk the | |
2745 | BLOCK-tree, clearing DECL_RTL for LABEL_DECLs and non-static | |
2746 | local variables. */ | |
2747 | walk_tree_without_duplicates (&DECL_SAVED_TREE (fn), | |
2748 | clear_decl_rtl, | |
2749 | NULL); | |
2750 | ||
2751 | /* Clear out the RTL for the arguments. */ | |
2752 | for (t = DECL_ARGUMENTS (fn); t; t = TREE_CHAIN (t)) | |
2753 | { | |
2754 | SET_DECL_RTL (t, NULL_RTX); | |
2755 | DECL_INCOMING_RTL (t) = NULL_RTX; | |
2756 | } | |
2757 | ||
2758 | if (!(flag_inline_trees && DECL_INLINE (fn))) | |
2759 | /* DECL_INITIAL must remain nonzero so we know this was an | |
2760 | actual function definition. */ | |
2761 | DECL_INITIAL (fn) = error_mark_node; | |
2762 | ||
2763 | /* Let the error reporting routines know that we're outside a | |
2764 | function. For a nested function, this value is used in | |
2765 | pop_cp_function_context and then reset via pop_function_context. */ | |
2766 | current_function_decl = NULL_TREE; | |
2767 | } | |
2768 | ||
2769 | /* Clear out the DECL_RTL for the non-static variables in BLOCK and | |
2770 | its sub-blocks. */ | |
2771 | ||
2772 | static tree | |
2773 | clear_decl_rtl (tp, walk_subtrees, data) | |
2774 | tree *tp; | |
2775 | int *walk_subtrees ATTRIBUTE_UNUSED; | |
2776 | void *data ATTRIBUTE_UNUSED; | |
2777 | { | |
2778 | if (nonstatic_local_decl_p (*tp)) | |
2779 | SET_DECL_RTL (*tp, NULL_RTX); | |
2780 | ||
2781 | return NULL_TREE; | |
2782 | } | |
2783 | ||
2784 | /* Perform initialization related to this module. */ | |
2785 | ||
2786 | void | |
2787 | init_cp_semantics () | |
2788 | { | |
2789 | lang_expand_stmt = cp_expand_stmt; | |
2790 | } |