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