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