00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "config.h"
00037 #include "system.h"
00038 #include "coretypes.h"
00039 #include "tm.h"
00040 #include "tree.h"
00041 #include "cp-tree.h"
00042 #include "c-common.h"
00043 #include "tree-inline.h"
00044 #include "tree-mudflap.h"
00045 #include "except.h"
00046 #include "toplev.h"
00047 #include "flags.h"
00048 #include "rtl.h"
00049 #include "expr.h"
00050 #include "output.h"
00051 #include "timevar.h"
00052 #include "debug.h"
00053 #include "diagnostic.h"
00054 #include "cgraph.h"
00055 #include "tree-iterator.h"
00056 #include "vec.h"
00057 #include "target.h"
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 static tree maybe_convert_cond (tree);
00069 #ifndef KEY
00070 static
00071 #endif
00072 tree simplify_aggr_init_exprs_r (tree *, int *, void *);
00073 static void emit_associated_thunks (tree);
00074 static tree finalize_nrv_r (tree *, int *, void *);
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 typedef struct deferred_access GTY(())
00129 {
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 tree deferred_access_checks;
00148
00149
00150 enum deferring_kind deferring_access_checks_kind;
00151
00152 } deferred_access;
00153 DEF_VEC_GC_O (deferred_access);
00154
00155
00156 static GTY(()) VEC (deferred_access) *deferred_access_stack;
00157 static GTY(()) unsigned deferred_access_no_check;
00158
00159
00160
00161
00162 void
00163 push_deferring_access_checks (deferring_kind deferring)
00164 {
00165
00166
00167 if (deferred_access_no_check || deferring == dk_no_check)
00168 deferred_access_no_check++;
00169 else
00170 {
00171 deferred_access *ptr;
00172
00173 ptr = VEC_safe_push (deferred_access, deferred_access_stack, NULL);
00174 ptr->deferred_access_checks = NULL_TREE;
00175 ptr->deferring_access_checks_kind = deferring;
00176 }
00177 }
00178
00179
00180
00181
00182 void
00183 resume_deferring_access_checks (void)
00184 {
00185 if (!deferred_access_no_check)
00186 VEC_last (deferred_access, deferred_access_stack)
00187 ->deferring_access_checks_kind = dk_deferred;
00188 }
00189
00190
00191
00192 void
00193 stop_deferring_access_checks (void)
00194 {
00195 if (!deferred_access_no_check)
00196 VEC_last (deferred_access, deferred_access_stack)
00197 ->deferring_access_checks_kind = dk_no_deferred;
00198 }
00199
00200
00201
00202
00203 void
00204 pop_deferring_access_checks (void)
00205 {
00206 if (deferred_access_no_check)
00207 deferred_access_no_check--;
00208 else
00209 VEC_pop (deferred_access, deferred_access_stack);
00210 }
00211
00212
00213
00214
00215
00216
00217 tree
00218 get_deferred_access_checks (void)
00219 {
00220 if (deferred_access_no_check)
00221 return NULL;
00222 else
00223 return (VEC_last (deferred_access, deferred_access_stack)
00224 ->deferred_access_checks);
00225 }
00226
00227
00228
00229
00230
00231 void
00232 pop_to_parent_deferring_access_checks (void)
00233 {
00234 if (deferred_access_no_check)
00235 deferred_access_no_check--;
00236 else
00237 {
00238 tree checks;
00239 deferred_access *ptr;
00240
00241 checks = (VEC_last (deferred_access, deferred_access_stack)
00242 ->deferred_access_checks);
00243
00244 VEC_pop (deferred_access, deferred_access_stack);
00245 ptr = VEC_last (deferred_access, deferred_access_stack);
00246 if (ptr->deferring_access_checks_kind == dk_no_deferred)
00247 {
00248
00249 for (; checks; checks = TREE_CHAIN (checks))
00250 enforce_access (TREE_PURPOSE (checks),
00251 TREE_VALUE (checks));
00252 }
00253 else
00254 {
00255
00256 tree next;
00257 tree original = ptr->deferred_access_checks;
00258
00259 for (; checks; checks = next)
00260 {
00261 tree probe;
00262
00263 next = TREE_CHAIN (checks);
00264
00265 for (probe = original; probe; probe = TREE_CHAIN (probe))
00266 if (TREE_VALUE (probe) == TREE_VALUE (checks)
00267 && TREE_PURPOSE (probe) == TREE_PURPOSE (checks))
00268 goto found;
00269
00270 TREE_CHAIN (checks) = ptr->deferred_access_checks;
00271 ptr->deferred_access_checks = checks;
00272 found:;
00273 }
00274 }
00275 }
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 void
00295 perform_deferred_access_checks (void)
00296 {
00297 tree deferred_check;
00298
00299 for (deferred_check = get_deferred_access_checks ();
00300 deferred_check;
00301 deferred_check = TREE_CHAIN (deferred_check))
00302
00303 enforce_access (TREE_PURPOSE (deferred_check),
00304 TREE_VALUE (deferred_check));
00305 }
00306
00307
00308
00309
00310 void
00311 perform_or_defer_access_check (tree binfo, tree decl)
00312 {
00313 tree check;
00314 deferred_access *ptr;
00315
00316
00317
00318 if (deferred_access_no_check)
00319 return;
00320
00321 gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
00322
00323 ptr = VEC_last (deferred_access, deferred_access_stack);
00324
00325
00326 if (ptr->deferring_access_checks_kind == dk_no_deferred)
00327 {
00328 enforce_access (binfo, decl);
00329 return;
00330 }
00331
00332
00333 for (check = ptr->deferred_access_checks;
00334 check;
00335 check = TREE_CHAIN (check))
00336 if (TREE_VALUE (check) == decl && TREE_PURPOSE (check) == binfo)
00337 return;
00338
00339 ptr->deferred_access_checks
00340 = tree_cons (binfo, decl, ptr->deferred_access_checks);
00341 }
00342
00343
00344
00345
00346
00347 int
00348 stmts_are_full_exprs_p (void)
00349 {
00350 return current_stmt_tree ()->stmts_are_full_exprs_p;
00351 }
00352
00353
00354
00355
00356
00357 stmt_tree
00358 current_stmt_tree (void)
00359 {
00360 return (cfun
00361 ? &cfun->language->base.x_stmt_tree
00362 : &scope_chain->x_stmt_tree);
00363 }
00364
00365
00366
00367 static tree
00368 maybe_cleanup_point_expr (tree expr)
00369 {
00370 if (!processing_template_decl && stmts_are_full_exprs_p ())
00371 expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
00372 return expr;
00373 }
00374
00375
00376
00377
00378
00379
00380 static tree
00381 maybe_cleanup_point_expr_void (tree expr)
00382 {
00383 if (!processing_template_decl && stmts_are_full_exprs_p ())
00384 expr = fold_build_cleanup_point_expr (void_type_node, expr);
00385 return expr;
00386 }
00387
00388
00389
00390
00391
00392 void
00393 add_decl_expr (tree decl)
00394 {
00395 tree r = build_stmt (DECL_EXPR, decl);
00396 if (DECL_INITIAL (decl)
00397 || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
00398 r = maybe_cleanup_point_expr_void (r);
00399 add_stmt (r);
00400 }
00401
00402
00403
00404
00405
00406 int
00407 anon_aggr_type_p (tree node)
00408 {
00409 return ANON_AGGR_TYPE_P (node);
00410 }
00411
00412
00413
00414 static tree
00415 do_poplevel (tree stmt_list)
00416 {
00417 tree block = NULL;
00418
00419 if (stmts_are_full_exprs_p ())
00420 block = poplevel (kept_level_p (), 1, 0);
00421
00422 stmt_list = pop_stmt_list (stmt_list);
00423
00424 if (!processing_template_decl)
00425 {
00426 stmt_list = c_build_bind_expr (block, stmt_list);
00427
00428 }
00429
00430 return stmt_list;
00431 }
00432
00433
00434
00435 static tree
00436 do_pushlevel (scope_kind sk)
00437 {
00438 tree ret = push_stmt_list ();
00439 if (stmts_are_full_exprs_p ())
00440 begin_scope (sk, NULL);
00441 return ret;
00442 }
00443
00444
00445
00446
00447
00448 void
00449 push_cleanup (tree decl, tree cleanup, bool eh_only)
00450 {
00451 tree stmt = build_stmt (CLEANUP_STMT, NULL, cleanup, decl);
00452 CLEANUP_EH_ONLY (stmt) = eh_only;
00453 add_stmt (stmt);
00454 CLEANUP_BODY (stmt) = push_stmt_list ();
00455 }
00456
00457
00458
00459
00460
00461
00462 static void
00463 begin_cond (tree *cond_p)
00464 {
00465 if (processing_template_decl)
00466 *cond_p = push_stmt_list ();
00467 }
00468
00469
00470
00471 static void
00472 finish_cond (tree *cond_p, tree expr)
00473 {
00474 if (processing_template_decl)
00475 {
00476 tree cond = pop_stmt_list (*cond_p);
00477 if (TREE_CODE (cond) == DECL_EXPR)
00478 expr = cond;
00479 }
00480 *cond_p = expr;
00481 }
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 static void
00494 simplify_loop_decl_cond (tree *cond_p, tree body)
00495 {
00496 tree cond, if_stmt;
00497
00498 if (!TREE_SIDE_EFFECTS (body))
00499 return;
00500
00501 cond = *cond_p;
00502 *cond_p = boolean_true_node;
00503
00504 if_stmt = begin_if_stmt ();
00505 cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0);
00506 finish_if_stmt_cond (cond, if_stmt);
00507 finish_break_stmt ();
00508 finish_then_clause (if_stmt);
00509 finish_if_stmt (if_stmt);
00510 }
00511
00512
00513
00514 tree
00515 finish_goto_stmt (tree destination)
00516 {
00517 if (TREE_CODE (destination) == IDENTIFIER_NODE)
00518 destination = lookup_label (destination);
00519
00520
00521
00522 if (TREE_CODE (destination) == LABEL_DECL)
00523 TREE_USED (destination) = 1;
00524 else
00525 {
00526
00527 if (!processing_template_decl)
00528 destination = decay_conversion (destination);
00529
00530
00531
00532
00533 DECL_UNINLINABLE (current_function_decl) = 1;
00534 }
00535
00536 check_goto (destination);
00537
00538 return add_stmt (build_stmt (GOTO_EXPR, destination));
00539 }
00540
00541
00542
00543
00544 static tree
00545 maybe_convert_cond (tree cond)
00546 {
00547
00548 if (!cond)
00549 return NULL_TREE;
00550
00551
00552 if (processing_template_decl)
00553 return cond;
00554
00555
00556 cond = convert_from_reference (cond);
00557 return condition_conversion (cond);
00558 }
00559
00560
00561
00562 tree
00563 finish_expr_stmt (tree expr)
00564 {
00565 tree r = NULL_TREE;
00566
00567 if (expr != NULL_TREE)
00568 {
00569 if (!processing_template_decl)
00570 {
00571 if (warn_sequence_point)
00572 verify_sequence_points (expr);
00573 expr = convert_to_void (expr, "statement");
00574 }
00575 else if (!type_dependent_expression_p (expr))
00576 convert_to_void (build_non_dependent_expr (expr), "statement");
00577
00578
00579
00580 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
00581 {
00582 if (TREE_CODE (expr) != EXPR_STMT)
00583 expr = build_stmt (EXPR_STMT, expr);
00584 expr = maybe_cleanup_point_expr_void (expr);
00585 }
00586
00587 r = add_stmt (expr);
00588 }
00589
00590 finish_stmt ();
00591
00592 return r;
00593 }
00594
00595
00596
00597
00598
00599 tree
00600 begin_if_stmt (void)
00601 {
00602 tree r, scope;
00603 scope = do_pushlevel (sk_block);
00604 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
00605 TREE_CHAIN (r) = scope;
00606 begin_cond (&IF_COND (r));
00607 return r;
00608 }
00609
00610
00611
00612
00613 void
00614 finish_if_stmt_cond (tree cond, tree if_stmt)
00615 {
00616 finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond));
00617 add_stmt (if_stmt);
00618 THEN_CLAUSE (if_stmt) = push_stmt_list ();
00619 }
00620
00621
00622
00623
00624 tree
00625 finish_then_clause (tree if_stmt)
00626 {
00627 THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
00628 return if_stmt;
00629 }
00630
00631
00632
00633 void
00634 begin_else_clause (tree if_stmt)
00635 {
00636 ELSE_CLAUSE (if_stmt) = push_stmt_list ();
00637 }
00638
00639
00640
00641
00642 void
00643 finish_else_clause (tree if_stmt)
00644 {
00645 ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
00646 }
00647
00648
00649
00650 void
00651 finish_if_stmt (tree if_stmt)
00652 {
00653 tree scope = TREE_CHAIN (if_stmt);
00654 TREE_CHAIN (if_stmt) = NULL;
00655 add_stmt (do_poplevel (scope));
00656 finish_stmt ();
00657 }
00658
00659
00660
00661
00662 tree
00663 begin_while_stmt (void)
00664 {
00665 tree r;
00666 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
00667 add_stmt (r);
00668 WHILE_BODY (r) = do_pushlevel (sk_block);
00669 begin_cond (&WHILE_COND (r));
00670 return r;
00671 }
00672
00673
00674
00675
00676 void
00677 finish_while_stmt_cond (tree cond, tree while_stmt)
00678 {
00679 finish_cond (&WHILE_COND (while_stmt), maybe_convert_cond (cond));
00680 simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
00681 }
00682
00683
00684
00685 void
00686 finish_while_stmt (tree while_stmt)
00687 {
00688 WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
00689 finish_stmt ();
00690 }
00691
00692
00693
00694
00695 tree
00696 begin_do_stmt (void)
00697 {
00698 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
00699 add_stmt (r);
00700 DO_BODY (r) = push_stmt_list ();
00701 return r;
00702 }
00703
00704
00705
00706 void
00707 finish_do_body (tree do_stmt)
00708 {
00709 DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
00710 }
00711
00712
00713
00714
00715 void
00716 finish_do_stmt (tree cond, tree do_stmt)
00717 {
00718 cond = maybe_convert_cond (cond);
00719 DO_COND (do_stmt) = cond;
00720 finish_stmt ();
00721 }
00722
00723
00724
00725
00726 tree
00727 finish_return_stmt (tree expr)
00728 {
00729 tree r;
00730 bool no_warning;
00731
00732 expr = check_return_expr (expr, &no_warning);
00733 if (!processing_template_decl)
00734 {
00735 if (DECL_DESTRUCTOR_P (current_function_decl)
00736 || (DECL_CONSTRUCTOR_P (current_function_decl)
00737 && targetm.cxx.cdtor_returns_this ()))
00738 {
00739
00740
00741
00742
00743 return finish_goto_stmt (cdtor_label);
00744 }
00745 }
00746
00747 r = build_stmt (RETURN_EXPR, expr);
00748 TREE_NO_WARNING (r) |= no_warning;
00749 r = maybe_cleanup_point_expr_void (r);
00750 r = add_stmt (r);
00751 finish_stmt ();
00752
00753 return r;
00754 }
00755
00756
00757
00758 tree
00759 begin_for_stmt (void)
00760 {
00761 tree r;
00762
00763 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
00764 NULL_TREE, NULL_TREE);
00765
00766 if (flag_new_for_scope > 0)
00767 TREE_CHAIN (r) = do_pushlevel (sk_for);
00768
00769 if (processing_template_decl)
00770 FOR_INIT_STMT (r) = push_stmt_list ();
00771
00772 return r;
00773 }
00774
00775
00776
00777
00778 void
00779 finish_for_init_stmt (tree for_stmt)
00780 {
00781 if (processing_template_decl)
00782 FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
00783 add_stmt (for_stmt);
00784 FOR_BODY (for_stmt) = do_pushlevel (sk_block);
00785 begin_cond (&FOR_COND (for_stmt));
00786 }
00787
00788
00789
00790
00791 void
00792 finish_for_cond (tree cond, tree for_stmt)
00793 {
00794 finish_cond (&FOR_COND (for_stmt), maybe_convert_cond (cond));
00795 simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
00796 }
00797
00798
00799
00800
00801 void
00802 finish_for_expr (tree expr, tree for_stmt)
00803 {
00804 if (!expr)
00805 return;
00806
00807
00808 if (type_unknown_p (expr))
00809 {
00810 cxx_incomplete_type_error (expr, TREE_TYPE (expr));
00811 expr = error_mark_node;
00812 }
00813 if (!processing_template_decl)
00814 {
00815 if (warn_sequence_point)
00816 verify_sequence_points (expr);
00817 expr = convert_to_void (expr, "3rd expression in for");
00818 }
00819 else if (!type_dependent_expression_p (expr))
00820 convert_to_void (build_non_dependent_expr (expr), "3rd expression in for");
00821 expr = maybe_cleanup_point_expr_void (expr);
00822 FOR_EXPR (for_stmt) = expr;
00823 }
00824
00825
00826
00827
00828
00829 void
00830 finish_for_stmt (tree for_stmt)
00831 {
00832 FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
00833
00834
00835 if (flag_new_for_scope > 0)
00836 {
00837 tree scope = TREE_CHAIN (for_stmt);
00838 TREE_CHAIN (for_stmt) = NULL;
00839 add_stmt (do_poplevel (scope));
00840 }
00841
00842 finish_stmt ();
00843 }
00844
00845
00846
00847 tree
00848 finish_break_stmt (void)
00849 {
00850 return add_stmt (build_break_stmt ());
00851 }
00852
00853
00854
00855 tree
00856 finish_continue_stmt (void)
00857 {
00858 return add_stmt (build_continue_stmt ());
00859 }
00860
00861
00862
00863
00864 tree
00865 begin_switch_stmt (void)
00866 {
00867 tree r, scope;
00868
00869 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
00870
00871 scope = do_pushlevel (sk_block);
00872 TREE_CHAIN (r) = scope;
00873 begin_cond (&SWITCH_STMT_COND (r));
00874
00875 return r;
00876 }
00877
00878
00879
00880 void
00881 finish_switch_cond (tree cond, tree switch_stmt)
00882 {
00883 tree orig_type = NULL;
00884 if (!processing_template_decl)
00885 {
00886 tree index;
00887
00888
00889 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
00890 if (cond == NULL_TREE)
00891 {
00892 error ("switch quantity not an integer");
00893 cond = error_mark_node;
00894 }
00895 orig_type = TREE_TYPE (cond);
00896 if (cond != error_mark_node)
00897 {
00898
00899
00900
00901 cond = perform_integral_promotions (cond);
00902 cond = maybe_cleanup_point_expr (cond);
00903 }
00904
00905 if (cond != error_mark_node)
00906 {
00907 index = get_unwidened (cond, NULL_TREE);
00908
00909
00910
00911
00912 if (TYPE_UNSIGNED (TREE_TYPE (cond))
00913 == TYPE_UNSIGNED (TREE_TYPE (index)))
00914 cond = index;
00915 }
00916 }
00917 finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
00918 SWITCH_STMT_TYPE (switch_stmt) = orig_type;
00919 add_stmt (switch_stmt);
00920 push_switch (switch_stmt);
00921 SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
00922 }
00923
00924
00925
00926
00927 void
00928 finish_switch_stmt (tree switch_stmt)
00929 {
00930 tree scope;
00931
00932 SWITCH_STMT_BODY (switch_stmt) =
00933 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
00934 pop_switch ();
00935 finish_stmt ();
00936
00937 scope = TREE_CHAIN (switch_stmt);
00938 TREE_CHAIN (switch_stmt) = NULL;
00939 add_stmt (do_poplevel (scope));
00940 }
00941
00942
00943
00944
00945 tree
00946 begin_try_block (void)
00947 {
00948 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
00949 add_stmt (r);
00950 TRY_STMTS (r) = push_stmt_list ();
00951 return r;
00952 }
00953
00954
00955
00956 tree
00957 begin_function_try_block (void)
00958 {
00959 tree r = begin_try_block ();
00960 FN_TRY_BLOCK_P (r) = 1;
00961 return r;
00962 }
00963
00964
00965
00966 void
00967 finish_try_block (tree try_block)
00968 {
00969 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
00970 TRY_HANDLERS (try_block) = push_stmt_list ();
00971 }
00972
00973
00974
00975
00976 void
00977 finish_cleanup_try_block (tree try_block)
00978 {
00979 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
00980 }
00981
00982
00983
00984
00985 void
00986 finish_cleanup (tree cleanup, tree try_block)
00987 {
00988 TRY_HANDLERS (try_block) = cleanup;
00989 CLEANUP_P (try_block) = 1;
00990 }
00991
00992
00993
00994 void
00995 finish_function_try_block (tree try_block)
00996 {
00997 finish_try_block (try_block);
00998
00999
01000 in_function_try_handler = 1;
01001 }
01002
01003
01004
01005
01006 void
01007 finish_handler_sequence (tree try_block)
01008 {
01009 TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
01010 check_handlers (TRY_HANDLERS (try_block));
01011 }
01012
01013
01014
01015 void
01016 finish_function_handler_sequence (tree try_block)
01017 {
01018 in_function_try_handler = 0;
01019 finish_handler_sequence (try_block);
01020 }
01021
01022
01023
01024 tree
01025 begin_handler (void)
01026 {
01027 tree r;
01028
01029 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
01030 add_stmt (r);
01031
01032
01033
01034 HANDLER_BODY (r) = do_pushlevel (sk_catch);
01035
01036 return r;
01037 }
01038
01039
01040
01041
01042
01043 void
01044 finish_handler_parms (tree decl, tree handler)
01045 {
01046 tree type = NULL_TREE;
01047 if (processing_template_decl)
01048 {
01049 if (decl)
01050 {
01051 decl = pushdecl (decl);
01052 decl = push_template_decl (decl);
01053 HANDLER_PARMS (handler) = decl;
01054 type = TREE_TYPE (decl);
01055 }
01056 }
01057 else
01058 type = expand_start_catch_block (decl);
01059
01060 HANDLER_TYPE (handler) = type;
01061 if (!processing_template_decl && type)
01062 mark_used (eh_type_info (type));
01063 }
01064
01065
01066
01067
01068 void
01069 finish_handler (tree handler)
01070 {
01071 if (!processing_template_decl)
01072 expand_end_catch_block ();
01073 HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
01074 }
01075
01076
01077
01078
01079
01080
01081
01082
01083 tree
01084 begin_compound_stmt (unsigned int flags)
01085 {
01086 tree r;
01087
01088 if (flags & BCS_NO_SCOPE)
01089 {
01090 r = push_stmt_list ();
01091 STATEMENT_LIST_NO_SCOPE (r) = 1;
01092
01093
01094
01095
01096
01097 keep_next_level (false);
01098 }
01099 else
01100 r = do_pushlevel (flags & BCS_TRY_BLOCK ? sk_try : sk_block);
01101
01102
01103
01104
01105
01106
01107
01108 if (processing_template_decl)
01109 {
01110 r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
01111 BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
01112 BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
01113 TREE_SIDE_EFFECTS (r) = 1;
01114 }
01115
01116 return r;
01117 }
01118
01119
01120
01121 void
01122 finish_compound_stmt (tree stmt)
01123 {
01124 if (TREE_CODE (stmt) == BIND_EXPR)
01125 BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
01126 else if (STATEMENT_LIST_NO_SCOPE (stmt))
01127 stmt = pop_stmt_list (stmt);
01128 else
01129 {
01130
01131
01132 objc_clear_super_receiver ();
01133
01134 stmt = do_poplevel (stmt);
01135 }
01136
01137
01138 add_stmt (stmt);
01139 finish_stmt ();
01140 }
01141
01142
01143
01144
01145
01146 tree
01147 finish_asm_stmt (int volatile_p, tree string, tree output_operands,
01148 tree input_operands, tree clobbers)
01149 {
01150 tree r;
01151 tree t;
01152
01153 if (!processing_template_decl)
01154 {
01155 int ninputs, noutputs;
01156 const char *constraint;
01157 const char **oconstraints;
01158 bool allows_mem, allows_reg, is_inout;
01159 tree operand;
01160 int i;
01161
01162 ninputs = list_length (input_operands);
01163 noutputs = list_length (output_operands);
01164 oconstraints = (const char **) alloca (noutputs * sizeof (char *));
01165
01166 string = resolve_asm_operand_names (string, output_operands,
01167 input_operands);
01168
01169 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
01170 {
01171 operand = TREE_VALUE (t);
01172
01173
01174
01175
01176
01177
01178
01179 STRIP_NOPS (operand);
01180
01181 if (!lvalue_or_else (operand, lv_asm))
01182 operand = error_mark_node;
01183
01184 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
01185 oconstraints[i] = constraint;
01186
01187 if (parse_output_constraint (&constraint, i, ninputs, noutputs,
01188 &allows_mem, &allows_reg, &is_inout))
01189 {
01190
01191
01192 if (!allows_reg && !cxx_mark_addressable (operand))
01193 operand = error_mark_node;
01194 }
01195 else
01196 operand = error_mark_node;
01197
01198 TREE_VALUE (t) = operand;
01199 }
01200
01201 for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
01202 {
01203 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
01204 operand = decay_conversion (TREE_VALUE (t));
01205
01206
01207
01208
01209
01210 if (TREE_TYPE (operand) == unknown_type_node)
01211 {
01212 error ("type of asm operand %qE could not be determined",
01213 TREE_VALUE (t));
01214 operand = error_mark_node;
01215 }
01216
01217 if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
01218 oconstraints, &allows_mem, &allows_reg))
01219 {
01220
01221
01222 if (!allows_reg && allows_mem)
01223 {
01224
01225
01226 STRIP_NOPS (operand);
01227 if (!cxx_mark_addressable (operand))
01228 operand = error_mark_node;
01229 }
01230 }
01231 else
01232 operand = error_mark_node;
01233
01234 TREE_VALUE (t) = operand;
01235 }
01236 }
01237
01238 r = build_stmt (ASM_EXPR, string,
01239 output_operands, input_operands,
01240 clobbers);
01241 ASM_VOLATILE_P (r) = volatile_p;
01242 r = maybe_cleanup_point_expr_void (r);
01243 return add_stmt (r);
01244 }
01245
01246
01247
01248 tree
01249 finish_label_stmt (tree name)
01250 {
01251 tree decl = define_label (input_location, name);
01252 return add_stmt (build_stmt (LABEL_EXPR, decl));
01253 }
01254
01255
01256
01257
01258
01259 void
01260 finish_label_decl (tree name)
01261 {
01262 tree decl = declare_local_label (name);
01263 add_decl_expr (decl);
01264 }
01265
01266
01267
01268 void
01269 finish_decl_cleanup (tree decl, tree cleanup)
01270 {
01271 push_cleanup (decl, cleanup, false);
01272 }
01273
01274
01275
01276 void
01277 finish_eh_cleanup (tree cleanup)
01278 {
01279 push_cleanup (NULL, cleanup, true);
01280 }
01281
01282
01283
01284
01285
01286 void
01287 finish_mem_initializers (tree mem_inits)
01288 {
01289
01290
01291 mem_inits = nreverse (mem_inits);
01292
01293 if (processing_template_decl)
01294 add_stmt (build_min_nt (CTOR_INITIALIZER, mem_inits));
01295 else
01296 emit_mem_initializers (mem_inits);
01297 }
01298
01299
01300
01301 tree
01302 finish_parenthesized_expr (tree expr)
01303 {
01304 if (EXPR_P (expr))
01305
01306 TREE_NO_WARNING (expr) = 1;
01307
01308 if (TREE_CODE (expr) == OFFSET_REF)
01309
01310
01311 PTRMEM_OK_P (expr) = 0;
01312
01313 if (TREE_CODE (expr) == STRING_CST)
01314 PAREN_STRING_LITERAL_P (expr) = 1;
01315
01316 return expr;
01317 }
01318
01319
01320
01321
01322 tree
01323 finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
01324 {
01325 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
01326
01327 if (!object)
01328 {
01329 if (current_function_decl
01330 && DECL_STATIC_FUNCTION_P (current_function_decl))
01331 cp_error_at ("invalid use of member %qD in static member function",
01332 decl);
01333 else
01334 cp_error_at ("invalid use of non-static data member %qD", decl);
01335 error ("from this location");
01336
01337 return error_mark_node;
01338 }
01339 TREE_USED (current_class_ptr) = 1;
01340 if (processing_template_decl && !qualifying_scope)
01341 {
01342 tree type = TREE_TYPE (decl);
01343
01344 if (TREE_CODE (type) == REFERENCE_TYPE)
01345 type = TREE_TYPE (type);
01346 else
01347 {
01348
01349 int quals = cp_type_quals (TREE_TYPE (current_class_ref));
01350
01351 if (DECL_MUTABLE_P (decl))
01352 quals &= ~TYPE_QUAL_CONST;
01353
01354 quals |= cp_type_quals (TREE_TYPE (decl));
01355 type = cp_build_qualified_type (type, quals);
01356 }
01357
01358 return build_min (COMPONENT_REF, type, object, decl, NULL_TREE);
01359 }
01360 else
01361 {
01362 tree access_type = TREE_TYPE (object);
01363 tree lookup_context = context_for_name_lookup (decl);
01364
01365 while (!DERIVED_FROM_P (lookup_context, access_type))
01366 {
01367 access_type = TYPE_CONTEXT (access_type);
01368 while (access_type && DECL_P (access_type))
01369 access_type = DECL_CONTEXT (access_type);
01370
01371 if (!access_type)
01372 {
01373 cp_error_at ("object missing in reference to %qD", decl);
01374 error ("from this location");
01375 return error_mark_node;
01376 }
01377 }
01378
01379
01380
01381
01382 if (processing_template_decl)
01383 return build_min (SCOPE_REF, TREE_TYPE (decl),
01384 qualifying_scope, DECL_NAME (decl));
01385
01386 perform_or_defer_access_check (TYPE_BINFO (access_type), decl);
01387
01388
01389
01390 if (qualifying_scope)
01391 {
01392 tree binfo = NULL_TREE;
01393 object = build_scoped_ref (object, qualifying_scope,
01394 &binfo);
01395 }
01396
01397 return build_class_member_access_expr (object, decl,
01398 NULL_TREE,
01399 false);
01400 }
01401 }
01402
01403
01404
01405
01406
01407
01408
01409 void
01410 check_accessibility_of_qualified_id (tree decl,
01411 tree object_type,
01412 tree nested_name_specifier)
01413 {
01414 tree scope;
01415 tree qualifying_type = NULL_TREE;
01416
01417
01418 if (deferred_access_no_check)
01419 return;
01420
01421
01422 scope = context_for_name_lookup (decl);
01423
01424 if (!TYPE_P (scope))
01425 return;
01426
01427 if (object_type
01428
01429
01430
01431
01432
01433
01434
01435
01436 && CLASS_TYPE_P (object_type)
01437 && DERIVED_FROM_P (scope, object_type))
01438
01439
01440 qualifying_type = object_type;
01441 else if (nested_name_specifier)
01442 {
01443
01444
01445
01446 if (DECL_NONSTATIC_MEMBER_P (decl)
01447 && current_class_ptr
01448 && DERIVED_FROM_P (scope, current_class_type))
01449 qualifying_type = current_class_type;
01450
01451
01452 else
01453 qualifying_type = nested_name_specifier;
01454 }
01455 else
01456
01457
01458 qualifying_type = currently_open_derived_class (scope);
01459
01460 if (qualifying_type && IS_AGGR_TYPE_CODE (TREE_CODE (qualifying_type)))
01461
01462
01463 perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl);
01464 }
01465
01466
01467
01468
01469
01470
01471
01472 tree
01473 finish_qualified_id_expr (tree qualifying_class, tree expr, bool done,
01474 bool address_p)
01475 {
01476 if (error_operand_p (expr))
01477 return error_mark_node;
01478
01479
01480
01481 if (address_p && done)
01482 {
01483 if (TREE_CODE (expr) == SCOPE_REF)
01484 expr = TREE_OPERAND (expr, 1);
01485 expr = build_offset_ref (qualifying_class, expr,
01486 true);
01487 return expr;
01488 }
01489
01490 if (TREE_CODE (expr) == FIELD_DECL)
01491 expr = finish_non_static_data_member (expr, current_class_ref,
01492 qualifying_class);
01493 else if (BASELINK_P (expr) && !processing_template_decl)
01494 {
01495 tree fns;
01496
01497
01498 fns = BASELINK_FUNCTIONS (expr);
01499 if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
01500 fns = TREE_OPERAND (fns, 0);
01501
01502
01503 if (!shared_member_p (fns)
01504 && current_class_type
01505 && DERIVED_FROM_P (qualifying_class, current_class_type))
01506 expr = (build_class_member_access_expr
01507 (maybe_dummy_object (qualifying_class, NULL),
01508 expr,
01509 BASELINK_ACCESS_BINFO (expr),
01510 false));
01511 else if (done)
01512
01513
01514 expr = build_offset_ref (qualifying_class, expr, false);
01515 }
01516
01517 return expr;
01518 }
01519
01520
01521
01522
01523 tree
01524 begin_stmt_expr (void)
01525 {
01526 return push_stmt_list ();
01527 }
01528
01529
01530
01531
01532
01533
01534 tree
01535 finish_stmt_expr_expr (tree expr, tree stmt_expr)
01536 {
01537 if (error_operand_p (expr))
01538 return error_mark_node;
01539
01540
01541
01542 if (expr)
01543 {
01544 tree type;
01545 type = TREE_TYPE (expr);
01546 if (!dependent_type_p (type) && !VOID_TYPE_P (type))
01547 {
01548 expr = decay_conversion (expr);
01549 if (error_operand_p (expr))
01550 return error_mark_node;
01551 type = TREE_TYPE (expr);
01552 }
01553
01554
01555 TREE_TYPE (stmt_expr) = type;
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569 if (!processing_template_decl && !VOID_TYPE_P (type))
01570 {
01571 tree target_expr;
01572 if (CLASS_TYPE_P (type)
01573 && !TYPE_HAS_TRIVIAL_INIT_REF (type))
01574 {
01575 target_expr = build_target_expr_with_type (expr, type);
01576 expr = TARGET_EXPR_INITIAL (target_expr);
01577 }
01578 else
01579 {
01580
01581
01582
01583
01584 target_expr = force_target_expr (type, expr);
01585 expr = TARGET_EXPR_INITIAL (target_expr);
01586 expr = build2 (INIT_EXPR,
01587 type,
01588 TARGET_EXPR_SLOT (target_expr),
01589 expr);
01590 }
01591 TARGET_EXPR_INITIAL (target_expr) = NULL_TREE;
01592
01593
01594
01595 TREE_TYPE (stmt_expr) = target_expr;
01596 }
01597 }
01598
01599
01600
01601 expr = finish_expr_stmt (expr);
01602
01603
01604
01605 if (expr && processing_template_decl)
01606 EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
01607
01608 return stmt_expr;
01609 }
01610
01611
01612
01613
01614
01615 tree
01616 finish_stmt_expr (tree stmt_expr, bool has_no_scope)
01617 {
01618 tree type;
01619 tree result;
01620
01621 if (error_operand_p (stmt_expr))
01622 return error_mark_node;
01623
01624 gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
01625
01626 type = TREE_TYPE (stmt_expr);
01627 result = pop_stmt_list (stmt_expr);
01628
01629 if (processing_template_decl)
01630 {
01631 result = build_min (STMT_EXPR, type, result);
01632 TREE_SIDE_EFFECTS (result) = 1;
01633 STMT_EXPR_NO_SCOPE (result) = has_no_scope;
01634 }
01635 else if (!TYPE_P (type))
01636 {
01637 gcc_assert (TREE_CODE (type) == TARGET_EXPR);
01638 TARGET_EXPR_INITIAL (type) = result;
01639 TREE_TYPE (result) = void_type_node;
01640 result = type;
01641 }
01642
01643 return result;
01644 }
01645
01646
01647
01648
01649
01650
01651 tree
01652 perform_koenig_lookup (tree fn, tree args)
01653 {
01654 tree identifier = NULL_TREE;
01655 tree functions = NULL_TREE;
01656
01657
01658 if (TREE_CODE (fn) == IDENTIFIER_NODE)
01659 identifier = fn;
01660 else if (is_overloaded_fn (fn))
01661 {
01662 functions = fn;
01663 identifier = DECL_NAME (get_first_fn (functions));
01664 }
01665 else if (DECL_P (fn))
01666 {
01667 functions = fn;
01668 identifier = DECL_NAME (fn);
01669 }
01670
01671
01672
01673
01674
01675 if (!any_type_dependent_arguments_p (args))
01676 {
01677 fn = lookup_arg_dependent (identifier, functions, args);
01678 if (!fn)
01679
01680 fn = unqualified_fn_lookup_error (identifier);
01681 }
01682 else
01683 fn = identifier;
01684
01685 return fn;
01686 }
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698 tree
01699 finish_call_expr (tree fn, tree args, bool disallow_virtual, bool koenig_p)
01700 {
01701 tree result;
01702 tree orig_fn;
01703 tree orig_args;
01704
01705 if (fn == error_mark_node || args == error_mark_node)
01706 return error_mark_node;
01707
01708
01709 gcc_assert (!args || TREE_CODE (args) == TREE_LIST);
01710
01711 orig_fn = fn;
01712 orig_args = args;
01713
01714 if (processing_template_decl)
01715 {
01716 if (type_dependent_expression_p (fn)
01717 || any_type_dependent_arguments_p (args))
01718 {
01719 result = build_nt (CALL_EXPR, fn, args, NULL_TREE);
01720 KOENIG_LOOKUP_P (result) = koenig_p;
01721 return result;
01722 }
01723 if (!BASELINK_P (fn)
01724 && TREE_CODE (fn) != PSEUDO_DTOR_EXPR
01725 && TREE_TYPE (fn) != unknown_type_node)
01726 fn = build_non_dependent_expr (fn);
01727 args = build_non_dependent_args (orig_args);
01728 }
01729
01730
01731
01732
01733 if (!BASELINK_P (fn) && is_overloaded_fn (fn))
01734 {
01735 tree f = fn;
01736
01737 if (TREE_CODE (f) == TEMPLATE_ID_EXPR)
01738 f = TREE_OPERAND (f, 0);
01739 f = get_first_fn (f);
01740 if (DECL_FUNCTION_MEMBER_P (f))
01741 {
01742 tree type = currently_open_derived_class (DECL_CONTEXT (f));
01743 if (!type)
01744 type = DECL_CONTEXT (f);
01745 fn = build_baselink (TYPE_BINFO (type),
01746 TYPE_BINFO (type),
01747 fn, NULL_TREE);
01748 }
01749 }
01750
01751 result = NULL_TREE;
01752 if (BASELINK_P (fn))
01753 {
01754 tree object;
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774 if (current_class_type
01775 && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
01776 current_class_type)
01777 && current_class_ref)
01778 object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
01779 NULL);
01780 else
01781 {
01782 tree representative_fn;
01783
01784 representative_fn = BASELINK_FUNCTIONS (fn);
01785 if (TREE_CODE (representative_fn) == TEMPLATE_ID_EXPR)
01786 representative_fn = TREE_OPERAND (representative_fn, 0);
01787 representative_fn = get_first_fn (representative_fn);
01788 object = build_dummy_object (DECL_CONTEXT (representative_fn));
01789 }
01790
01791 if (processing_template_decl)
01792 {
01793 if (type_dependent_expression_p (object))
01794 return build_nt (CALL_EXPR, orig_fn, orig_args, NULL_TREE);
01795 object = build_non_dependent_expr (object);
01796 }
01797
01798 result = build_new_method_call (object, fn, args, NULL_TREE,
01799 (disallow_virtual
01800 ? LOOKUP_NONVIRTUAL : 0));
01801 }
01802 else if (is_overloaded_fn (fn))
01803
01804 result = build_new_function_call (fn, args);
01805 else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
01806 {
01807 if (args)
01808 error ("arguments to destructor are not allowed");
01809
01810
01811 result = build1 (NOP_EXPR,
01812 void_type_node,
01813 TREE_OPERAND (fn, 0));
01814 TREE_SIDE_EFFECTS (result) = 1;
01815 }
01816 else if (CLASS_TYPE_P (TREE_TYPE (fn)))
01817
01818
01819 result = build_new_op (CALL_EXPR, LOOKUP_NORMAL, fn, args, NULL_TREE,
01820 NULL);
01821 if (!result)
01822
01823 result = build_function_call (fn, args);
01824
01825 if (processing_template_decl)
01826 {
01827 result = build3 (CALL_EXPR, TREE_TYPE (result), orig_fn,
01828 orig_args, NULL_TREE);
01829 KOENIG_LOOKUP_P (result) = koenig_p;
01830 }
01831 return result;
01832 }
01833
01834
01835
01836
01837
01838 tree
01839 finish_increment_expr (tree expr, enum tree_code code)
01840 {
01841 return build_x_unary_op (code, expr);
01842 }
01843
01844
01845
01846 tree
01847 finish_this_expr (void)
01848 {
01849 tree result;
01850
01851 if (current_class_ptr)
01852 {
01853 result = current_class_ptr;
01854 }
01855 else if (current_function_decl
01856 && DECL_STATIC_FUNCTION_P (current_function_decl))
01857 {
01858 error ("%<this%> is unavailable for static member functions");
01859 result = error_mark_node;
01860 }
01861 else
01862 {
01863 if (current_function_decl)
01864 error ("invalid use of %<this%> in non-member function");
01865 else
01866 error ("invalid use of %<this%> at top level");
01867 result = error_mark_node;
01868 }
01869
01870 return result;
01871 }
01872
01873
01874
01875
01876
01877
01878 tree
01879 finish_pseudo_destructor_expr (tree object, tree scope, tree destructor)
01880 {
01881 if (destructor == error_mark_node)
01882 return error_mark_node;
01883
01884 gcc_assert (TYPE_P (destructor));
01885
01886 if (!processing_template_decl)
01887 {
01888 if (scope == error_mark_node)
01889 {
01890 error ("invalid qualifying scope in pseudo-destructor name");
01891 return error_mark_node;
01892 }
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
01908 destructor))
01909 {
01910 error ("%qE is not of type %qT", object, destructor);
01911 return error_mark_node;
01912 }
01913 }
01914
01915 return build3 (PSEUDO_DTOR_EXPR, void_type_node, object, scope, destructor);
01916 }
01917
01918
01919
01920 tree
01921 finish_unary_op_expr (enum tree_code code, tree expr)
01922 {
01923 tree result = build_x_unary_op (code, expr);
01924
01925
01926
01927 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
01928 && TREE_CODE (result) == INTEGER_CST
01929 && !TYPE_UNSIGNED (TREE_TYPE (result))
01930 && INT_CST_LT (result, integer_zero_node))
01931 {
01932
01933
01934 result = copy_node (result);
01935 TREE_NEGATED_INT (result) = 1;
01936 }
01937 overflow_warning (result);
01938 return result;
01939 }
01940
01941
01942
01943
01944 tree
01945 finish_compound_literal (tree type, tree initializer_list)
01946 {
01947 tree compound_literal;
01948
01949
01950 compound_literal = build_constructor (NULL_TREE, initializer_list);
01951
01952 TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
01953 if (processing_template_decl)
01954 TREE_TYPE (compound_literal) = type;
01955 else
01956 {
01957
01958 compound_literal = digest_init (type, compound_literal, NULL);
01959
01960
01961
01962
01963
01964
01965 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
01966 cp_complete_array_type (&TREE_TYPE (compound_literal),
01967 compound_literal, 1);
01968 }
01969
01970 return compound_literal;
01971 }
01972
01973
01974
01975
01976 tree
01977 finish_fname (tree id)
01978 {
01979 tree decl;
01980
01981 decl = fname_decl (C_RID_CODE (id), id);
01982 if (processing_template_decl)
01983 decl = DECL_NAME (decl);
01984 return decl;
01985 }
01986
01987
01988
01989 void
01990 finish_translation_unit (void)
01991 {
01992
01993
01994 pop_everything ();
01995 while (current_namespace != global_namespace)
01996 pop_namespace ();
01997
01998
01999 finish_fname_decls ();
02000 }
02001
02002
02003
02004
02005 tree
02006 finish_template_type_parm (tree aggr, tree identifier)
02007 {
02008 if (aggr != class_type_node)
02009 {
02010 pedwarn ("template type parameters must use the keyword %<class%> or %<typename%>");
02011 aggr = class_type_node;
02012 }
02013
02014 return build_tree_list (aggr, identifier);
02015 }
02016
02017
02018
02019
02020 tree
02021 finish_template_template_parm (tree aggr, tree identifier)
02022 {
02023 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
02024 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
02025 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
02026 DECL_TEMPLATE_RESULT (tmpl) = decl;
02027 DECL_ARTIFICIAL (decl) = 1;
02028 end_template_decl ();
02029
02030 gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
02031
02032 return finish_template_type_parm (aggr, tmpl);
02033 }
02034
02035
02036
02037
02038
02039 tree
02040 check_template_template_default_arg (tree argument)
02041 {
02042 if (TREE_CODE (argument) != TEMPLATE_DECL
02043 && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
02044 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
02045 {
02046 if (TREE_CODE (argument) == TYPE_DECL)
02047 {
02048 tree t = TREE_TYPE (argument);
02049
02050
02051
02052 if (CLASSTYPE_TEMPLATE_INFO (t)
02053 && CLASSTYPE_TEMPLATE_INSTANTIATION (t))
02054 error ("invalid use of type %qT as a default value for a "
02055 "template template-parameter", t);
02056 else
02057 error ("invalid use of %qD as a default value for a template "
02058 "template-parameter", argument);
02059 }
02060 else
02061 error ("invalid default argument for a template template parameter");
02062 return error_mark_node;
02063 }
02064
02065 return argument;
02066 }
02067
02068
02069
02070 tree
02071 begin_class_definition (tree t)
02072 {
02073 if (t == error_mark_node)
02074 return error_mark_node;
02075
02076 if (processing_template_parmlist)
02077 {
02078 error ("definition of %q#T inside template parameter list", t);
02079 return error_mark_node;
02080 }
02081
02082
02083
02084
02085
02086
02087 else if (TREE_CODE (t) == TYPENAME_TYPE)
02088 {
02089 error ("invalid definition of qualified type %qT", t);
02090 t = error_mark_node;
02091 }
02092
02093 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
02094 {
02095 t = make_aggr_type (RECORD_TYPE);
02096 pushtag (make_anon_name (), t, ts_current);
02097 }
02098
02099
02100 DECL_SOURCE_LOCATION (TYPE_NAME (t)) = input_location;
02101
02102 if (TYPE_BEING_DEFINED (t))
02103 {
02104 t = make_aggr_type (TREE_CODE (t));
02105 pushtag (TYPE_IDENTIFIER (t), t, ts_current);
02106 }
02107 maybe_process_partial_specialization (t);
02108 pushclass (t);
02109 TYPE_BEING_DEFINED (t) = 1;
02110 if (flag_pack_struct)
02111 {
02112 tree v;
02113 TYPE_PACKED (t) = 1;
02114
02115
02116
02117 for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
02118 TYPE_PACKED (v) = 1;
02119 }
02120
02121
02122
02123 if (! TYPE_ANONYMOUS_P (t))
02124 {
02125 struct c_fileinfo *finfo = get_fileinfo (lbasename (input_filename));
02126 CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
02127 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
02128 (t, finfo->interface_unknown);
02129 }
02130 reset_specialization();
02131
02132
02133 build_self_reference ();
02134
02135 return t;
02136 }
02137
02138
02139
02140 void
02141 finish_member_declaration (tree decl)
02142 {
02143 if (decl == error_mark_node || decl == NULL_TREE)
02144 return;
02145
02146 if (decl == void_type_node)
02147
02148
02149 return;
02150
02151
02152 gcc_assert (TREE_CHAIN (decl) == NULL_TREE);
02153
02154
02155 TREE_PRIVATE (decl)
02156 = (current_access_specifier == access_private_node);
02157 TREE_PROTECTED (decl)
02158 = (current_access_specifier == access_protected_node);
02159 if (TREE_CODE (decl) == TEMPLATE_DECL)
02160 {
02161 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
02162 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
02163 }
02164
02165
02166 DECL_CONTEXT (decl) = current_class_type;
02167
02168
02169
02170
02171
02172 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
02173 SET_DECL_LANGUAGE (decl, lang_cplusplus);
02174
02175
02176
02177
02178 if (TREE_CODE (decl) == FUNCTION_DECL
02179 || DECL_FUNCTION_TEMPLATE_P (decl))
02180 {
02181
02182
02183 add_method (current_class_type, decl, NULL_TREE);
02184
02185 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
02186 TYPE_METHODS (current_class_type) = decl;
02187
02188 maybe_add_class_template_decl_list (current_class_type, decl,
02189 0);
02190 }
02191
02192 else if ((TREE_CODE (decl) == USING_DECL && TREE_TYPE (decl))
02193 || pushdecl_class_level (decl))
02194 {
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212 if (TREE_CODE (decl) == TYPE_DECL)
02213 TYPE_FIELDS (current_class_type)
02214 = chainon (TYPE_FIELDS (current_class_type), decl);
02215 else
02216 {
02217 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
02218 TYPE_FIELDS (current_class_type) = decl;
02219 }
02220
02221 maybe_add_class_template_decl_list (current_class_type, decl,
02222 0);
02223 }
02224
02225 if (pch_file)
02226 note_decl_for_pch (decl);
02227 }
02228
02229
02230
02231
02232
02233
02234 void
02235 note_decl_for_pch (tree decl)
02236 {
02237 gcc_assert (pch_file);
02238
02239
02240
02241
02242
02243
02244 if (TREE_CODE (decl) == FUNCTION_DECL
02245 && TREE_PUBLIC (decl)
02246 && DECL_DECLARED_INLINE_P (decl)
02247 && !DECL_IMPLICIT_INSTANTIATION (decl))
02248 {
02249 comdat_linkage (decl);
02250 DECL_INTERFACE_KNOWN (decl) = 1;
02251 }
02252
02253
02254
02255 if (TREE_CODE (decl) == VAR_DECL
02256 || TREE_CODE (decl) == FUNCTION_DECL)
02257 mangle_decl (decl);
02258 }
02259
02260
02261
02262
02263 void
02264 finish_template_decl (tree parms)
02265 {
02266 if (parms)
02267 end_template_decl ();
02268 else
02269 end_specialization ();
02270 }
02271
02272
02273
02274
02275
02276
02277 tree
02278 finish_template_type (tree name, tree args, int entering_scope)
02279 {
02280 tree decl;
02281
02282 decl = lookup_template_class (name, args,
02283 NULL_TREE, NULL_TREE, entering_scope,
02284 tf_error | tf_warning | tf_user);
02285 if (decl != error_mark_node)
02286 decl = TYPE_STUB_DECL (decl);
02287
02288 return decl;
02289 }
02290
02291
02292
02293
02294
02295
02296
02297
02298 tree
02299 finish_base_specifier (tree base, tree access, bool virtual_p)
02300 {
02301 tree result;
02302
02303 if (base == error_mark_node)
02304 {
02305 error ("invalid base-class specification");
02306 result = NULL_TREE;
02307 }
02308 else if (! is_aggr_type (base, 1))
02309 result = NULL_TREE;
02310 else
02311 {
02312 if (cp_type_quals (base) != 0)
02313 {
02314 error ("base class %qT has cv qualifiers", base);
02315 base = TYPE_MAIN_VARIANT (base);
02316 }
02317 result = build_tree_list (access, base);
02318 if (virtual_p)
02319 TREE_TYPE (result) = integer_type_node;
02320 }
02321
02322 return result;
02323 }
02324
02325
02326
02327
02328 void
02329 qualified_name_lookup_error (tree scope, tree name, tree decl)
02330 {
02331 if (scope == error_mark_node)
02332 ;
02333 else if (TYPE_P (scope))
02334 {
02335 if (!COMPLETE_TYPE_P (scope))
02336 error ("incomplete type %qT used in nested name specifier", scope);
02337 else if (TREE_CODE (decl) == TREE_LIST)
02338 {
02339 error ("reference to %<%T::%D%> is ambiguous", scope, name);
02340 print_candidates (decl);
02341 }
02342 else
02343 error ("%qD is not a member of %qT", name, scope);
02344 }
02345 else if (scope != global_namespace)
02346 error ("%qD is not a member of %qD", name, scope);
02347 else
02348 error ("%<::%D%> has not been declared", name);
02349 }
02350
02351
02352
02353
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378 tree
02379 finish_id_expression (tree id_expression,
02380 tree decl,
02381 tree scope,
02382 cp_id_kind *idk,
02383 tree *qualifying_class,
02384 bool integral_constant_expression_p,
02385 bool allow_non_integral_constant_expression_p,
02386 bool *non_integral_constant_expression_p,
02387 const char **error_msg)
02388 {
02389
02390 *idk = CP_ID_KIND_NONE;
02391 *error_msg = NULL;
02392
02393 if (id_expression == error_mark_node)
02394 return error_mark_node;
02395
02396
02397
02398 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
02399 || TREE_CODE (decl) == TYPE_DECL)
02400 ;
02401
02402 else
02403 {
02404 if (decl == error_mark_node)
02405 {
02406
02407 if (scope
02408 && (!TYPE_P (scope)
02409 || (!dependent_type_p (scope)
02410 && !(TREE_CODE (id_expression) == IDENTIFIER_NODE
02411 && IDENTIFIER_TYPENAME_P (id_expression)
02412 && dependent_type_p (TREE_TYPE (id_expression))))))
02413 {
02414
02415
02416
02417 qualified_name_lookup_error (scope, id_expression, decl);
02418 return error_mark_node;
02419 }
02420 else if (!scope)
02421 {
02422
02423 *idk = CP_ID_KIND_UNQUALIFIED;
02424 return id_expression;
02425 }
02426 else
02427 decl = id_expression;
02428 }
02429
02430
02431
02432 else
02433 decl = check_for_out_of_scope_variable (decl);
02434
02435
02436
02437
02438
02439 if (!scope && decl != error_mark_node)
02440 maybe_note_name_used_in_class (id_expression, decl);
02441 }
02442
02443
02444
02445 if (TREE_CODE (decl) == TEMPLATE_DECL
02446 && !DECL_FUNCTION_TEMPLATE_P (decl))
02447 {
02448 *error_msg = "missing template arguments";
02449 return error_mark_node;
02450 }
02451 else if (TREE_CODE (decl) == TYPE_DECL
02452 || TREE_CODE (decl) == NAMESPACE_DECL)
02453 {
02454 *error_msg = "expected primary-expression";
02455 return error_mark_node;
02456 }
02457
02458
02459
02460 if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
02461 || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
02462 {
02463 tree r;
02464
02465 *idk = CP_ID_KIND_NONE;
02466 if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
02467 decl = TEMPLATE_PARM_DECL (decl);
02468 r = convert_from_reference (DECL_INITIAL (decl));
02469
02470 if (integral_constant_expression_p
02471 && !dependent_type_p (TREE_TYPE (decl))
02472 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
02473 {
02474 if (!allow_non_integral_constant_expression_p)
02475 error ("template parameter %qD of type %qT is not allowed in "
02476 "an integral constant expression because it is not of "
02477 "integral or enumeration type", decl, TREE_TYPE (decl));
02478 *non_integral_constant_expression_p = true;
02479 }
02480 return r;
02481 }
02482
02483
02484 else if (TREE_CODE (decl) == CONST_DECL)
02485 {
02486 *idk = CP_ID_KIND_NONE;
02487 if (!processing_template_decl)
02488 return DECL_INITIAL (decl);
02489 return decl;
02490 }
02491 else
02492 {
02493 bool dependent_p;
02494
02495
02496
02497
02498 *idk = (scope
02499 ? CP_ID_KIND_QUALIFIED
02500 : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
02501 ? CP_ID_KIND_TEMPLATE_ID
02502 : CP_ID_KIND_UNQUALIFIED));
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515 dependent_p = false;
02516 if (!processing_template_decl)
02517
02518 ;
02519
02520
02521 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
02522 && (TREE_CODE (TREE_OPERAND (decl, 0))
02523 == IDENTIFIER_NODE))
02524 dependent_p = true;
02525
02526
02527 else if (!is_overloaded_fn (decl))
02528 dependent_p
02529 = dependent_type_p (TREE_TYPE (decl));
02530
02531
02532 else
02533 {
02534 tree fns = decl;
02535
02536 if (BASELINK_P (fns))
02537 fns = BASELINK_FUNCTIONS (fns);
02538
02539
02540
02541 if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
02542 {
02543 tree args = TREE_OPERAND (fns, 1);
02544 dependent_p = any_dependent_template_arguments_p (args);
02545
02546
02547 fns = TREE_OPERAND (fns, 0);
02548 }
02549
02550
02551
02552 while (fns && !dependent_p)
02553 {
02554 tree fn = OVL_CURRENT (fns);
02555
02556
02557
02558 if (TREE_CODE (fn) == FUNCTION_DECL
02559 && type_dependent_expression_p (fn))
02560 dependent_p = true;
02561 else if (TREE_CODE (fn) == TEMPLATE_DECL
02562 && dependent_template_p (fn))
02563 dependent_p = true;
02564
02565 fns = OVL_NEXT (fns);
02566 }
02567 }
02568
02569
02570
02571 if (dependent_p)
02572 {
02573
02574
02575 if (scope)
02576 {
02577 if (TYPE_P (scope))
02578 *qualifying_class = scope;
02579
02580
02581
02582 if (integral_constant_expression_p)
02583 *non_integral_constant_expression_p = true;
02584 if (TYPE_P (scope) && dependent_type_p (scope))
02585 return build_nt (SCOPE_REF, scope, id_expression);
02586 else if (TYPE_P (scope) && DECL_P (decl))
02587 return convert_from_reference
02588 (build2 (SCOPE_REF, TREE_TYPE (decl), scope, id_expression));
02589 else
02590 return convert_from_reference (decl);
02591 }
02592
02593
02594 if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR)
02595 return id_expression;
02596 *idk = CP_ID_KIND_UNQUALIFIED_DEPENDENT;
02597
02598
02599
02600 if (TREE_CODE (decl) == VAR_DECL
02601 || TREE_CODE (decl) == PARM_DECL)
02602 return convert_from_reference (decl);
02603
02604
02605 else if (TREE_CODE (decl) == FIELD_DECL)
02606 {
02607
02608
02609
02610 push_deferring_access_checks (dk_no_check);
02611 decl = finish_non_static_data_member
02612 (decl, current_class_ref,
02613 NULL_TREE);
02614 pop_deferring_access_checks ();
02615 return decl;
02616 }
02617 return id_expression;
02618 }
02619
02620
02621
02622
02623 if (integral_constant_expression_p
02624 && ! DECL_INTEGRAL_CONSTANT_VAR_P (decl)
02625 && ! builtin_valid_in_constant_expr_p (decl))
02626 {
02627 if (!allow_non_integral_constant_expression_p)
02628 {
02629 error ("%qD cannot appear in a constant-expression", decl);
02630 return error_mark_node;
02631 }
02632 *non_integral_constant_expression_p = true;
02633 }
02634
02635 if (TREE_CODE (decl) == NAMESPACE_DECL)
02636 {
02637 error ("use of namespace %qD as expression", decl);
02638 return error_mark_node;
02639 }
02640 else if (DECL_CLASS_TEMPLATE_P (decl))
02641 {
02642 error ("use of class template %qT as expression", decl);
02643 return error_mark_node;
02644 }
02645 else if (TREE_CODE (decl) == TREE_LIST)
02646 {
02647
02648 error ("request for member %qD is ambiguous in "
02649 "multiple inheritance lattice", id_expression);
02650 print_candidates (decl);
02651 return error_mark_node;
02652 }
02653
02654
02655
02656 if (TREE_CODE (decl) == VAR_DECL
02657 || TREE_CODE (decl) == PARM_DECL
02658 || TREE_CODE (decl) == RESULT_DECL)
02659 mark_used (decl);
02660
02661 if (scope)
02662 {
02663 decl = (adjust_result_of_qualified_name_lookup
02664 (decl, scope, current_class_type));
02665
02666 if (TREE_CODE (decl) == FUNCTION_DECL)
02667 mark_used (decl);
02668
02669 if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl))
02670 *qualifying_class = scope;
02671 else
02672 {
02673 tree r = convert_from_reference (decl);
02674
02675 if (processing_template_decl
02676 && TYPE_P (scope))
02677 r = build2 (SCOPE_REF, TREE_TYPE (r), scope, decl);
02678 decl = r;
02679 }
02680 }
02681 else if (TREE_CODE (decl) == FIELD_DECL)
02682 {
02683
02684
02685
02686 push_deferring_access_checks (dk_no_check);
02687 decl = finish_non_static_data_member (decl, current_class_ref,
02688 NULL_TREE);
02689 pop_deferring_access_checks ();
02690 }
02691 else if (is_overloaded_fn (decl))
02692 {
02693 tree first_fn = OVL_CURRENT (decl);
02694
02695 if (TREE_CODE (first_fn) == TEMPLATE_DECL)
02696 first_fn = DECL_TEMPLATE_RESULT (first_fn);
02697
02698 if (!really_overloaded_fn (decl))
02699 mark_used (first_fn);
02700
02701 if (TREE_CODE (first_fn) == FUNCTION_DECL
02702 && DECL_FUNCTION_MEMBER_P (first_fn)
02703 && !shared_member_p (decl))
02704 {
02705
02706 decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
02707 return finish_class_member_access_expr (decl, id_expression);
02708 }
02709 }
02710 else
02711 {
02712 if (TREE_CODE (decl) == VAR_DECL
02713 || TREE_CODE (decl) == PARM_DECL
02714 || TREE_CODE (decl) == RESULT_DECL)
02715 {
02716 tree context = decl_function_context (decl);
02717
02718 if (context != NULL_TREE && context != current_function_decl
02719 && ! TREE_STATIC (decl))
02720 {
02721 error (TREE_CODE (decl) == VAR_DECL
02722 ? "use of %<auto%> variable from containing function"
02723 : "use of parameter from containing function");
02724 cp_error_at (" %q#D declared here", decl);
02725 return error_mark_node;
02726 }
02727 }
02728
02729 if (DECL_P (decl) && DECL_NONLOCAL (decl)
02730 && DECL_CLASS_SCOPE_P (decl)
02731 && DECL_CONTEXT (decl) != current_class_type)
02732 {
02733 tree path;
02734
02735 path = currently_open_derived_class (DECL_CONTEXT (decl));
02736 perform_or_defer_access_check (TYPE_BINFO (path), decl);
02737 }
02738
02739 decl = convert_from_reference (decl);
02740 }
02741 }
02742
02743 if (TREE_DEPRECATED (decl))
02744 warn_deprecated_use (decl);
02745
02746 return decl;
02747 }
02748
02749
02750
02751
02752 tree
02753 finish_typeof (tree expr)
02754 {
02755 tree type;
02756
02757 if (type_dependent_expression_p (expr))
02758 {
02759 type = make_aggr_type (TYPEOF_TYPE);
02760 TYPEOF_TYPE_EXPR (type) = expr;
02761
02762 return type;
02763 }
02764
02765 type = TREE_TYPE (expr);
02766
02767 if (!type || type == unknown_type_node)
02768 {
02769 error ("type of %qE is unknown", expr);
02770 return error_mark_node;
02771 }
02772
02773 return type;
02774 }
02775
02776
02777
02778
02779 #ifndef KEY
02780 static
02781 #endif
02782 tree simplify_aggr_init_exprs_r (tree* tp,
02783 int* walk_subtrees,
02784 void* data ATTRIBUTE_UNUSED)
02785 {
02786
02787
02788
02789
02790
02791 if (TYPE_P (*tp))
02792 {
02793 *walk_subtrees = 0;
02794 return NULL_TREE;
02795 }
02796
02797 else if (TREE_CODE (*tp) != AGGR_INIT_EXPR)
02798 return NULL_TREE;
02799
02800 simplify_aggr_init_expr (tp);
02801
02802
02803 return NULL_TREE;
02804 }
02805
02806
02807
02808
02809
02810 void
02811 simplify_aggr_init_expr (tree *tp)
02812 {
02813 tree aggr_init_expr = *tp;
02814
02815
02816 tree fn = TREE_OPERAND (aggr_init_expr, 0);
02817 tree args = TREE_OPERAND (aggr_init_expr, 1);
02818 tree slot = TREE_OPERAND (aggr_init_expr, 2);
02819 tree type = TREE_TYPE (slot);
02820
02821 tree call_expr;
02822 enum style_t { ctor, arg, pcc } style;
02823
02824 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
02825 style = ctor;
02826 #ifdef PCC_STATIC_STRUCT_RETURN
02827 else if (1)
02828 style = pcc;
02829 #endif
02830 else
02831 {
02832 gcc_assert (TREE_ADDRESSABLE (type));
02833 style = arg;
02834 }
02835
02836 if (style == ctor || style == arg)
02837 {
02838
02839
02840 tree addr;
02841
02842 if (style == ctor)
02843 args = TREE_CHAIN (args);
02844
02845 cxx_mark_addressable (slot);
02846 addr = build1 (ADDR_EXPR, build_pointer_type (type), slot);
02847 if (style == arg)
02848 {
02849
02850 tree fntype = TREE_TYPE (TREE_TYPE (fn));
02851
02852 gcc_assert (TREE_CODE (fntype) == FUNCTION_TYPE
02853 || TREE_CODE (fntype) == METHOD_TYPE);
02854 addr = convert (build_pointer_type (TREE_TYPE (fntype)), addr);
02855 }
02856
02857 args = tree_cons (NULL_TREE, addr, args);
02858 }
02859
02860 call_expr = build3 (CALL_EXPR,
02861 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
02862 fn, args, NULL_TREE);
02863
02864 if (style == arg)
02865
02866
02867 CALL_EXPR_HAS_RETURN_SLOT_ADDR (call_expr) = 1;
02868 else if (style == pcc)
02869 {
02870
02871
02872
02873 push_deferring_access_checks (dk_no_check);
02874 call_expr = build_aggr_init (slot, call_expr,
02875 DIRECT_BIND | LOOKUP_ONLYCONVERTING);
02876 pop_deferring_access_checks ();
02877 }
02878
02879 *tp = call_expr;
02880 }
02881
02882
02883
02884 static void
02885 emit_associated_thunks (tree fn)
02886 {
02887
02888
02889
02890
02891
02892 if (DECL_VIRTUAL_P (fn))
02893 {
02894 tree thunk;
02895
02896 for (thunk = DECL_THUNKS (fn); thunk; thunk = TREE_CHAIN (thunk))
02897 {
02898 if (!THUNK_ALIAS (thunk))
02899 {
02900 use_thunk (thunk, 1);
02901 if (DECL_RESULT_THUNK_P (thunk))
02902 {
02903 tree probe;
02904
02905 for (probe = DECL_THUNKS (thunk);
02906 probe; probe = TREE_CHAIN (probe))
02907 use_thunk (probe, 1);
02908 }
02909 }
02910 else
02911 gcc_assert (!DECL_THUNKS (thunk));
02912 }
02913 }
02914 }
02915
02916
02917
02918 void
02919 expand_body (tree fn)
02920 {
02921 tree saved_function;
02922
02923
02924
02925 if (DECL_DECLARED_INLINE_P (fn))
02926 import_export_decl (fn);
02927
02928
02929
02930
02931
02932
02933 if (DECL_EXTERNAL (fn))
02934 return;
02935
02936
02937 saved_function = current_function_decl;
02938
02939
02940 emit_associated_thunks (fn);
02941
02942
02943
02944
02945 gcc_assert (function_depth == 0);
02946
02947 tree_rest_of_compilation (fn);
02948
02949 current_function_decl = saved_function;
02950
02951 if (DECL_CLONED_FUNCTION_P (fn))
02952 {
02953
02954
02955
02956
02957 tree probe;
02958
02959 for (probe = TREE_CHAIN (DECL_CLONED_FUNCTION (fn));
02960 probe && DECL_CLONED_FUNCTION_P (probe);
02961 probe = TREE_CHAIN (probe))
02962 {
02963 tree parms;
02964
02965 for (parms = DECL_ARGUMENTS (probe);
02966 parms; parms = TREE_CHAIN (parms))
02967 TREE_USED (parms) = 1;
02968 }
02969 }
02970 }
02971
02972
02973
02974 void
02975 expand_or_defer_fn (tree fn)
02976 {
02977
02978
02979 if (processing_template_decl)
02980 {
02981
02982
02983
02984
02985
02986
02987 if (!function_depth)
02988 ggc_collect ();
02989 return;
02990 }
02991
02992 #ifdef KEY
02993
02994
02995
02996
02997 if (!flag_spin_file)
02998 #endif
02999
03000 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
03001 simplify_aggr_init_exprs_r,
03002 NULL);
03003
03004
03005
03006 if (maybe_clone_body (fn))
03007 {
03008
03009
03010 TREE_ASM_WRITTEN (fn) = 1;
03011 return;
03012 }
03013
03014
03015
03016
03017 if (DECL_STATIC_CONSTRUCTOR (fn))
03018 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
03019
03020
03021
03022
03023 if (DECL_STATIC_DESTRUCTOR (fn))
03024 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
03025
03026
03027
03028
03029
03030 if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn))
03031 {
03032 if (!at_eof)
03033 {
03034 DECL_EXTERNAL (fn) = 1;
03035 DECL_NOT_REALLY_EXTERN (fn) = 1;
03036 note_vague_linkage_fn (fn);
03037 }
03038 else
03039 import_export_decl (fn);
03040
03041
03042
03043
03044 if (flag_keep_inline_functions && DECL_DECLARED_INLINE_P (fn))
03045 mark_needed (fn);
03046 }
03047
03048
03049
03050 if (flag_syntax_only)
03051 return;
03052
03053 function_depth++;
03054
03055
03056 cgraph_finalize_function (fn, function_depth > 1);
03057
03058 function_depth--;
03059 }
03060
03061 struct nrv_data
03062 {
03063 tree var;
03064 tree result;
03065 htab_t visited;
03066 };
03067
03068
03069
03070 static tree
03071 finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
03072 {
03073 struct nrv_data *dp = (struct nrv_data *)data;
03074 void **slot;
03075
03076
03077
03078 if (TYPE_P (*tp))
03079 *walk_subtrees = 0;
03080
03081
03082
03083 else if (TREE_CODE (*tp) == RETURN_EXPR)
03084 TREE_OPERAND (*tp, 0) = dp->result;
03085
03086
03087 else if (TREE_CODE (*tp) == CLEANUP_STMT
03088 && CLEANUP_DECL (*tp) == dp->var)
03089 CLEANUP_EH_ONLY (*tp) = 1;
03090
03091
03092 else if (TREE_CODE (*tp) == DECL_EXPR
03093 && DECL_EXPR_DECL (*tp) == dp->var)
03094 {
03095 tree init;
03096 if (DECL_INITIAL (dp->var)
03097 && DECL_INITIAL (dp->var) != error_mark_node)
03098 {
03099 init = build2 (INIT_EXPR, void_type_node, dp->result,
03100 DECL_INITIAL (dp->var));
03101 DECL_INITIAL (dp->var) = error_mark_node;
03102 }
03103 else
03104 init = build_empty_stmt ();
03105 SET_EXPR_LOCUS (init, EXPR_LOCUS (*tp));
03106 *tp = init;
03107 }
03108
03109 else if (*tp == dp->var)
03110 *tp = dp->result;
03111
03112
03113
03114
03115 slot = htab_find_slot (dp->visited, *tp, INSERT);
03116 if (*slot)
03117 *walk_subtrees = 0;
03118 else
03119 *slot = *tp;
03120
03121
03122 return NULL_TREE;
03123 }
03124
03125
03126
03127
03128
03129
03130 void
03131 finalize_nrv (tree *tp, tree var, tree result)
03132 {
03133 struct nrv_data data;
03134
03135 #ifdef KEY
03136 if (flag_spin_file)
03137 DECL_NAMED_RETURN_OBJECT(current_function_decl) = var;
03138 #endif
03139
03140
03141 DECL_NAME (result) = DECL_NAME (var);
03142 DECL_ARTIFICIAL (result) = DECL_ARTIFICIAL (var);
03143 DECL_IGNORED_P (result) = DECL_IGNORED_P (var);
03144 DECL_SOURCE_LOCATION (result) = DECL_SOURCE_LOCATION (var);
03145 DECL_ABSTRACT_ORIGIN (result) = DECL_ABSTRACT_ORIGIN (var);
03146
03147 TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
03148
03149 data.var = var;
03150 data.result = result;
03151 data.visited = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
03152 walk_tree (tp, finalize_nrv_r, &data, 0);
03153 htab_delete (data.visited);
03154 }
03155
03156
03157
03158 void
03159 init_cp_semantics (void)
03160 {
03161 }
03162
03163 #include "gt-cp-semantics.h"