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