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