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