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