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