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