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 #include "config.h"
00033 #include "system.h"
00034 #include "coretypes.h"
00035 #include "tm.h"
00036 #include "tree.h"
00037 #include "cp-tree.h"
00038 #include "c-common.h"
00039 #include "tree-inline.h"
00040 #include "tree-mudflap.h"
00041 #include "except.h"
00042 #include "toplev.h"
00043 #include "flags.h"
00044 #include "rtl.h"
00045 #include "expr.h"
00046 #include "output.h"
00047 #include "timevar.h"
00048 #include "debug.h"
00049 #include "diagnostic.h"
00050 #include "cgraph.h"
00051 #include "tree-iterator.h"
00052 #include "vec.h"
00053 #include "target.h"
00054
00055
00056
00057
00058
00059
00060 static tree maybe_convert_cond (tree);
00061 #ifndef KEY
00062 static
00063 #endif
00064 tree simplify_aggr_init_exprs_r (tree *, int *, void *);
00065 static void emit_associated_thunks (tree);
00066 static tree finalize_nrv_r (tree *, int *, void *);
00067
00068
00069
00070
00071
00072
00073
00074
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 typedef struct deferred_access GTY(())
00121 {
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 VEC (deferred_access_check,gc)* GTY(()) deferred_access_checks;
00136
00137
00138 enum deferring_kind deferring_access_checks_kind;
00139
00140 } deferred_access;
00141 DEF_VEC_O (deferred_access);
00142 DEF_VEC_ALLOC_O (deferred_access,gc);
00143
00144
00145 static GTY(()) VEC(deferred_access,gc) *deferred_access_stack;
00146 static GTY(()) unsigned deferred_access_no_check;
00147
00148
00149
00150
00151 void
00152 push_deferring_access_checks (deferring_kind deferring)
00153 {
00154
00155
00156 if (deferred_access_no_check || deferring == dk_no_check)
00157 deferred_access_no_check++;
00158 else
00159 {
00160 deferred_access *ptr;
00161
00162 ptr = VEC_safe_push (deferred_access, gc, deferred_access_stack, NULL);
00163 ptr->deferred_access_checks = NULL;
00164 ptr->deferring_access_checks_kind = deferring;
00165 }
00166 }
00167
00168
00169
00170
00171 void
00172 resume_deferring_access_checks (void)
00173 {
00174 if (!deferred_access_no_check)
00175 VEC_last (deferred_access, deferred_access_stack)
00176 ->deferring_access_checks_kind = dk_deferred;
00177 }
00178
00179
00180
00181 void
00182 stop_deferring_access_checks (void)
00183 {
00184 if (!deferred_access_no_check)
00185 VEC_last (deferred_access, deferred_access_stack)
00186 ->deferring_access_checks_kind = dk_no_deferred;
00187 }
00188
00189
00190
00191
00192 void
00193 pop_deferring_access_checks (void)
00194 {
00195 if (deferred_access_no_check)
00196 deferred_access_no_check--;
00197 else
00198 VEC_pop (deferred_access, deferred_access_stack);
00199 }
00200
00201
00202
00203
00204
00205
00206 VEC (deferred_access_check,gc)*
00207 get_deferred_access_checks (void)
00208 {
00209 if (deferred_access_no_check)
00210 return NULL;
00211 else
00212 return (VEC_last (deferred_access, deferred_access_stack)
00213 ->deferred_access_checks);
00214 }
00215
00216
00217
00218
00219
00220 void
00221 pop_to_parent_deferring_access_checks (void)
00222 {
00223 if (deferred_access_no_check)
00224 deferred_access_no_check--;
00225 else
00226 {
00227 VEC (deferred_access_check,gc) *checks;
00228 deferred_access *ptr;
00229
00230 checks = (VEC_last (deferred_access, deferred_access_stack)
00231 ->deferred_access_checks);
00232
00233 VEC_pop (deferred_access, deferred_access_stack);
00234 ptr = VEC_last (deferred_access, deferred_access_stack);
00235 if (ptr->deferring_access_checks_kind == dk_no_deferred)
00236 {
00237
00238 perform_access_checks (checks);
00239 }
00240 else
00241 {
00242
00243 int i, j;
00244 deferred_access_check *chk, *probe;
00245
00246 for (i = 0 ;
00247 VEC_iterate (deferred_access_check, checks, i, chk) ;
00248 ++i)
00249 {
00250 for (j = 0 ;
00251 VEC_iterate (deferred_access_check,
00252 ptr->deferred_access_checks, j, probe) ;
00253 ++j)
00254 {
00255 if (probe->binfo == chk->binfo &&
00256 probe->decl == chk->decl &&
00257 probe->diag_decl == chk->diag_decl)
00258 goto found;
00259 }
00260
00261 VEC_safe_push (deferred_access_check, gc,
00262 ptr->deferred_access_checks, chk);
00263 found:;
00264 }
00265 }
00266 }
00267 }
00268
00269
00270
00271
00272
00273 void
00274 perform_access_checks (VEC (deferred_access_check,gc)* checks)
00275 {
00276 int i;
00277 deferred_access_check *chk;
00278
00279 if (!checks)
00280 return;
00281
00282 for (i = 0 ; VEC_iterate (deferred_access_check, checks, i, chk) ; ++i)
00283 enforce_access (chk->binfo, chk->decl, chk->diag_decl);
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 void
00303 perform_deferred_access_checks (void)
00304 {
00305 perform_access_checks (get_deferred_access_checks ());
00306 }
00307
00308
00309
00310
00311 void
00312 perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl)
00313 {
00314 int i;
00315 deferred_access *ptr;
00316 deferred_access_check *chk;
00317 deferred_access_check *new_access;
00318
00319
00320
00321
00322 if (deferred_access_no_check)
00323 return;
00324
00325 gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
00326
00327 ptr = VEC_last (deferred_access, deferred_access_stack);
00328
00329
00330 if (ptr->deferring_access_checks_kind == dk_no_deferred)
00331 {
00332 enforce_access (binfo, decl, diag_decl);
00333 return;
00334 }
00335
00336
00337 for (i = 0 ;
00338 VEC_iterate (deferred_access_check,
00339 ptr->deferred_access_checks, i, chk) ;
00340 ++i)
00341 {
00342 if (chk->decl == decl && chk->binfo == binfo &&
00343 chk->diag_decl == diag_decl)
00344 {
00345 return;
00346 }
00347 }
00348
00349 new_access =
00350 VEC_safe_push (deferred_access_check, gc,
00351 ptr->deferred_access_checks, 0);
00352 new_access->binfo = binfo;
00353 new_access->decl = decl;
00354 new_access->diag_decl = diag_decl;
00355 }
00356
00357
00358
00359
00360
00361 int
00362 stmts_are_full_exprs_p (void)
00363 {
00364 return current_stmt_tree ()->stmts_are_full_exprs_p;
00365 }
00366
00367
00368
00369
00370
00371 tree
00372 add_stmt (tree t)
00373 {
00374 enum tree_code code = TREE_CODE (t);
00375
00376 if (EXPR_P (t) && code != LABEL_EXPR)
00377 {
00378 if (!EXPR_HAS_LOCATION (t))
00379 SET_EXPR_LOCATION (t, input_location);
00380
00381
00382
00383 STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
00384 }
00385
00386
00387
00388 append_to_statement_list_force (t, &cur_stmt_list);
00389
00390 return t;
00391 }
00392
00393
00394
00395
00396
00397 stmt_tree
00398 current_stmt_tree (void)
00399 {
00400 return (cfun
00401 ? &cfun->language->base.x_stmt_tree
00402 : &scope_chain->x_stmt_tree);
00403 }
00404
00405
00406
00407 static tree
00408 maybe_cleanup_point_expr (tree expr)
00409 {
00410 if (!processing_template_decl && stmts_are_full_exprs_p ())
00411 expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
00412 return expr;
00413 }
00414
00415
00416
00417
00418
00419
00420 static tree
00421 maybe_cleanup_point_expr_void (tree expr)
00422 {
00423 if (!processing_template_decl && stmts_are_full_exprs_p ())
00424 expr = fold_build_cleanup_point_expr (void_type_node, expr);
00425 return expr;
00426 }
00427
00428
00429
00430
00431
00432 void
00433 add_decl_expr (tree decl)
00434 {
00435 tree r = build_stmt (DECL_EXPR, decl);
00436 if (DECL_INITIAL (decl)
00437 || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
00438 r = maybe_cleanup_point_expr_void (r);
00439 add_stmt (r);
00440 }
00441
00442
00443
00444
00445
00446 int
00447 anon_aggr_type_p (tree node)
00448 {
00449 return ANON_AGGR_TYPE_P (node);
00450 }
00451
00452
00453
00454 tree
00455 do_poplevel (tree stmt_list)
00456 {
00457 tree block = NULL;
00458
00459 if (stmts_are_full_exprs_p ())
00460 block = poplevel (kept_level_p (), 1, 0);
00461
00462 stmt_list = pop_stmt_list (stmt_list);
00463
00464 if (!processing_template_decl)
00465 {
00466 stmt_list = c_build_bind_expr (block, stmt_list);
00467
00468 }
00469
00470 return stmt_list;
00471 }
00472
00473
00474
00475 static tree
00476 do_pushlevel (scope_kind sk)
00477 {
00478 tree ret = push_stmt_list ();
00479 if (stmts_are_full_exprs_p ())
00480 begin_scope (sk, NULL);
00481 return ret;
00482 }
00483
00484
00485
00486
00487
00488 void
00489 push_cleanup (tree decl, tree cleanup, bool eh_only)
00490 {
00491 tree stmt = build_stmt (CLEANUP_STMT, NULL, cleanup, decl);
00492 CLEANUP_EH_ONLY (stmt) = eh_only;
00493 add_stmt (stmt);
00494 CLEANUP_BODY (stmt) = push_stmt_list ();
00495 }
00496
00497
00498
00499
00500
00501
00502 static void
00503 begin_cond (tree *cond_p)
00504 {
00505 if (processing_template_decl)
00506 *cond_p = push_stmt_list ();
00507 }
00508
00509
00510
00511 static void
00512 finish_cond (tree *cond_p, tree expr)
00513 {
00514 if (processing_template_decl)
00515 {
00516 tree cond = pop_stmt_list (*cond_p);
00517 if (TREE_CODE (cond) == DECL_EXPR)
00518 expr = cond;
00519 }
00520 *cond_p = expr;
00521 }
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533 static void
00534 simplify_loop_decl_cond (tree *cond_p, tree body)
00535 {
00536 tree cond, if_stmt;
00537
00538 if (!TREE_SIDE_EFFECTS (body))
00539 return;
00540
00541 cond = *cond_p;
00542 *cond_p = boolean_true_node;
00543
00544 if_stmt = begin_if_stmt ();
00545 cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0);
00546 finish_if_stmt_cond (cond, if_stmt);
00547 finish_break_stmt ();
00548 finish_then_clause (if_stmt);
00549 finish_if_stmt (if_stmt);
00550 }
00551
00552
00553
00554 tree
00555 finish_goto_stmt (tree destination)
00556 {
00557 if (TREE_CODE (destination) == IDENTIFIER_NODE)
00558 destination = lookup_label (destination);
00559
00560
00561
00562 if (TREE_CODE (destination) == LABEL_DECL)
00563 TREE_USED (destination) = 1;
00564 else
00565 {
00566
00567 if (!processing_template_decl)
00568 destination = decay_conversion (destination);
00569
00570
00571
00572
00573 DECL_UNINLINABLE (current_function_decl) = 1;
00574 }
00575
00576 check_goto (destination);
00577
00578 return add_stmt (build_stmt (GOTO_EXPR, destination));
00579 }
00580
00581
00582
00583
00584 static tree
00585 maybe_convert_cond (tree cond)
00586 {
00587
00588 if (!cond)
00589 return NULL_TREE;
00590
00591
00592 if (processing_template_decl)
00593 return cond;
00594
00595
00596 cond = convert_from_reference (cond);
00597 return condition_conversion (cond);
00598 }
00599
00600
00601
00602 tree
00603 finish_expr_stmt (tree expr)
00604 {
00605 tree r = NULL_TREE;
00606
00607 if (expr != NULL_TREE)
00608 {
00609 if (!processing_template_decl)
00610 {
00611 if (warn_sequence_point)
00612 verify_sequence_points (expr);
00613 expr = convert_to_void (expr, "statement");
00614 }
00615 else if (!type_dependent_expression_p (expr))
00616 convert_to_void (build_non_dependent_expr (expr), "statement");
00617
00618
00619
00620 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
00621 {
00622 if (TREE_CODE (expr) != EXPR_STMT)
00623 expr = build_stmt (EXPR_STMT, expr);
00624 expr = maybe_cleanup_point_expr_void (expr);
00625 }
00626
00627 r = add_stmt (expr);
00628 }
00629
00630 finish_stmt ();
00631
00632 return r;
00633 }
00634
00635
00636
00637
00638
00639 tree
00640 begin_if_stmt (void)
00641 {
00642 tree r, scope;
00643 scope = do_pushlevel (sk_block);
00644 r = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
00645 TREE_CHAIN (r) = scope;
00646 begin_cond (&IF_COND (r));
00647 return r;
00648 }
00649
00650
00651
00652
00653 void
00654 finish_if_stmt_cond (tree cond, tree if_stmt)
00655 {
00656 finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond));
00657 add_stmt (if_stmt);
00658 THEN_CLAUSE (if_stmt) = push_stmt_list ();
00659 }
00660
00661
00662
00663
00664 tree
00665 finish_then_clause (tree if_stmt)
00666 {
00667 THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
00668 return if_stmt;
00669 }
00670
00671
00672
00673 void
00674 begin_else_clause (tree if_stmt)
00675 {
00676 ELSE_CLAUSE (if_stmt) = push_stmt_list ();
00677 }
00678
00679
00680
00681
00682 void
00683 finish_else_clause (tree if_stmt)
00684 {
00685 ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
00686 }
00687
00688
00689
00690 void
00691 finish_if_stmt (tree if_stmt)
00692 {
00693 tree scope = TREE_CHAIN (if_stmt);
00694 TREE_CHAIN (if_stmt) = NULL;
00695 add_stmt (do_poplevel (scope));
00696 finish_stmt ();
00697 empty_body_warning (THEN_CLAUSE (if_stmt), ELSE_CLAUSE (if_stmt));
00698 }
00699
00700
00701
00702
00703 tree
00704 begin_while_stmt (void)
00705 {
00706 tree r;
00707 r = build_stmt (WHILE_STMT, NULL_TREE, NULL_TREE);
00708 add_stmt (r);
00709 WHILE_BODY (r) = do_pushlevel (sk_block);
00710 begin_cond (&WHILE_COND (r));
00711 return r;
00712 }
00713
00714
00715
00716
00717 void
00718 finish_while_stmt_cond (tree cond, tree while_stmt)
00719 {
00720 finish_cond (&WHILE_COND (while_stmt), maybe_convert_cond (cond));
00721 simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
00722 }
00723
00724
00725
00726 void
00727 finish_while_stmt (tree while_stmt)
00728 {
00729 WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
00730 finish_stmt ();
00731 }
00732
00733
00734
00735
00736 tree
00737 begin_do_stmt (void)
00738 {
00739 tree r = build_stmt (DO_STMT, NULL_TREE, NULL_TREE);
00740 add_stmt (r);
00741 DO_BODY (r) = push_stmt_list ();
00742 return r;
00743 }
00744
00745
00746
00747 void
00748 finish_do_body (tree do_stmt)
00749 {
00750 DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
00751 }
00752
00753
00754
00755
00756 void
00757 finish_do_stmt (tree cond, tree do_stmt)
00758 {
00759 cond = maybe_convert_cond (cond);
00760 DO_COND (do_stmt) = cond;
00761 finish_stmt ();
00762 }
00763
00764
00765
00766
00767 tree
00768 finish_return_stmt (tree expr)
00769 {
00770 tree r;
00771 bool no_warning;
00772
00773 expr = check_return_expr (expr, &no_warning);
00774
00775 if (flag_openmp && !check_omp_return ())
00776 return error_mark_node;
00777 if (!processing_template_decl)
00778 {
00779 if (DECL_DESTRUCTOR_P (current_function_decl)
00780 || (DECL_CONSTRUCTOR_P (current_function_decl)
00781 && targetm.cxx.cdtor_returns_this ()))
00782 {
00783
00784
00785
00786
00787 return finish_goto_stmt (cdtor_label);
00788 }
00789 }
00790
00791 r = build_stmt (RETURN_EXPR, expr);
00792 TREE_NO_WARNING (r) |= no_warning;
00793 r = maybe_cleanup_point_expr_void (r);
00794 r = add_stmt (r);
00795 finish_stmt ();
00796
00797 return r;
00798 }
00799
00800
00801
00802 tree
00803 begin_for_stmt (void)
00804 {
00805 tree r;
00806
00807 r = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE,
00808 NULL_TREE, NULL_TREE);
00809
00810 if (flag_new_for_scope > 0)
00811 TREE_CHAIN (r) = do_pushlevel (sk_for);
00812
00813 if (processing_template_decl)
00814 FOR_INIT_STMT (r) = push_stmt_list ();
00815
00816 return r;
00817 }
00818
00819
00820
00821
00822 void
00823 finish_for_init_stmt (tree for_stmt)
00824 {
00825 if (processing_template_decl)
00826 FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
00827 add_stmt (for_stmt);
00828 FOR_BODY (for_stmt) = do_pushlevel (sk_block);
00829 begin_cond (&FOR_COND (for_stmt));
00830 }
00831
00832
00833
00834
00835 void
00836 finish_for_cond (tree cond, tree for_stmt)
00837 {
00838 finish_cond (&FOR_COND (for_stmt), maybe_convert_cond (cond));
00839 simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
00840 }
00841
00842
00843
00844
00845 void
00846 finish_for_expr (tree expr, tree for_stmt)
00847 {
00848 if (!expr)
00849 return;
00850
00851
00852 if (type_unknown_p (expr))
00853 {
00854 cxx_incomplete_type_error (expr, TREE_TYPE (expr));
00855 expr = error_mark_node;
00856 }
00857 if (!processing_template_decl)
00858 {
00859 if (warn_sequence_point)
00860 verify_sequence_points (expr);
00861 expr = convert_to_void (expr, "3rd expression in for");
00862 }
00863 else if (!type_dependent_expression_p (expr))
00864 convert_to_void (build_non_dependent_expr (expr), "3rd expression in for");
00865 expr = maybe_cleanup_point_expr_void (expr);
00866 FOR_EXPR (for_stmt) = expr;
00867 }
00868
00869
00870
00871
00872
00873 void
00874 finish_for_stmt (tree for_stmt)
00875 {
00876 FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
00877
00878
00879 if (flag_new_for_scope > 0)
00880 {
00881 tree scope = TREE_CHAIN (for_stmt);
00882 TREE_CHAIN (for_stmt) = NULL;
00883 add_stmt (do_poplevel (scope));
00884 }
00885
00886 finish_stmt ();
00887 }
00888
00889
00890
00891 tree
00892 finish_break_stmt (void)
00893 {
00894 return add_stmt (build_stmt (BREAK_STMT));
00895 }
00896
00897
00898
00899 tree
00900 finish_continue_stmt (void)
00901 {
00902 return add_stmt (build_stmt (CONTINUE_STMT));
00903 }
00904
00905
00906
00907
00908 tree
00909 begin_switch_stmt (void)
00910 {
00911 tree r, scope;
00912
00913 r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
00914
00915 scope = do_pushlevel (sk_block);
00916 TREE_CHAIN (r) = scope;
00917 begin_cond (&SWITCH_STMT_COND (r));
00918
00919 return r;
00920 }
00921
00922
00923
00924 void
00925 finish_switch_cond (tree cond, tree switch_stmt)
00926 {
00927 tree orig_type = NULL;
00928 if (!processing_template_decl)
00929 {
00930 tree index;
00931
00932
00933 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
00934 if (cond == NULL_TREE)
00935 {
00936 error ("switch quantity not an integer");
00937 cond = error_mark_node;
00938 }
00939 orig_type = TREE_TYPE (cond);
00940 if (cond != error_mark_node)
00941 {
00942
00943
00944
00945 cond = perform_integral_promotions (cond);
00946 cond = maybe_cleanup_point_expr (cond);
00947 }
00948
00949 if (cond != error_mark_node)
00950 {
00951 index = get_unwidened (cond, NULL_TREE);
00952
00953
00954
00955
00956 if (TYPE_UNSIGNED (TREE_TYPE (cond))
00957 == TYPE_UNSIGNED (TREE_TYPE (index)))
00958 cond = index;
00959 }
00960 }
00961 finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
00962 SWITCH_STMT_TYPE (switch_stmt) = orig_type;
00963 add_stmt (switch_stmt);
00964 push_switch (switch_stmt);
00965 SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
00966 }
00967
00968
00969
00970
00971 void
00972 finish_switch_stmt (tree switch_stmt)
00973 {
00974 tree scope;
00975
00976 SWITCH_STMT_BODY (switch_stmt) =
00977 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
00978 pop_switch ();
00979 finish_stmt ();
00980
00981 scope = TREE_CHAIN (switch_stmt);
00982 TREE_CHAIN (switch_stmt) = NULL;
00983 add_stmt (do_poplevel (scope));
00984 }
00985
00986
00987
00988
00989 tree
00990 begin_try_block (void)
00991 {
00992 tree r = build_stmt (TRY_BLOCK, NULL_TREE, NULL_TREE);
00993 add_stmt (r);
00994 TRY_STMTS (r) = push_stmt_list ();
00995 return r;
00996 }
00997
00998
00999
01000
01001
01002 tree
01003 begin_function_try_block (tree *compound_stmt)
01004 {
01005 tree r;
01006
01007
01008 *compound_stmt = begin_compound_stmt (0);
01009 r = begin_try_block ();
01010 FN_TRY_BLOCK_P (r) = 1;
01011 return r;
01012 }
01013
01014
01015
01016 void
01017 finish_try_block (tree try_block)
01018 {
01019 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
01020 TRY_HANDLERS (try_block) = push_stmt_list ();
01021 }
01022
01023
01024
01025
01026 void
01027 finish_cleanup_try_block (tree try_block)
01028 {
01029 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
01030 }
01031
01032
01033
01034
01035 void
01036 finish_cleanup (tree cleanup, tree try_block)
01037 {
01038 TRY_HANDLERS (try_block) = cleanup;
01039 CLEANUP_P (try_block) = 1;
01040 }
01041
01042
01043
01044 void
01045 finish_function_try_block (tree try_block)
01046 {
01047 finish_try_block (try_block);
01048
01049
01050 in_function_try_handler = 1;
01051 }
01052
01053
01054
01055
01056 void
01057 finish_handler_sequence (tree try_block)
01058 {
01059 TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
01060 check_handlers (TRY_HANDLERS (try_block));
01061 }
01062
01063
01064
01065
01066
01067 void
01068 finish_function_handler_sequence (tree try_block, tree compound_stmt)
01069 {
01070 in_function_try_handler = 0;
01071 finish_handler_sequence (try_block);
01072 finish_compound_stmt (compound_stmt);
01073 }
01074
01075
01076
01077 tree
01078 begin_handler (void)
01079 {
01080 tree r;
01081
01082 r = build_stmt (HANDLER, NULL_TREE, NULL_TREE);
01083 add_stmt (r);
01084
01085
01086
01087 HANDLER_BODY (r) = do_pushlevel (sk_catch);
01088
01089 return r;
01090 }
01091
01092
01093
01094
01095
01096 void
01097 finish_handler_parms (tree decl, tree handler)
01098 {
01099 tree type = NULL_TREE;
01100 if (processing_template_decl)
01101 {
01102 if (decl)
01103 {
01104 decl = pushdecl (decl);
01105 decl = push_template_decl (decl);
01106 HANDLER_PARMS (handler) = decl;
01107 type = TREE_TYPE (decl);
01108 }
01109 }
01110 else
01111 type = expand_start_catch_block (decl);
01112 HANDLER_TYPE (handler) = type;
01113 if (!processing_template_decl && type)
01114 mark_used (eh_type_info (type));
01115 }
01116
01117
01118
01119
01120 void
01121 finish_handler (tree handler)
01122 {
01123 if (!processing_template_decl)
01124 expand_end_catch_block ();
01125 HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
01126 }
01127
01128
01129
01130
01131
01132
01133
01134
01135 tree
01136 begin_compound_stmt (unsigned int flags)
01137 {
01138 tree r;
01139
01140 if (flags & BCS_NO_SCOPE)
01141 {
01142 r = push_stmt_list ();
01143 STATEMENT_LIST_NO_SCOPE (r) = 1;
01144
01145
01146
01147
01148
01149 keep_next_level (false);
01150 }
01151 else
01152 r = do_pushlevel (flags & BCS_TRY_BLOCK ? sk_try : sk_block);
01153
01154
01155
01156
01157
01158
01159
01160 if (processing_template_decl)
01161 {
01162 r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
01163 BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
01164 BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
01165 TREE_SIDE_EFFECTS (r) = 1;
01166 }
01167
01168 return r;
01169 }
01170
01171
01172
01173 void
01174 finish_compound_stmt (tree stmt)
01175 {
01176 if (TREE_CODE (stmt) == BIND_EXPR)
01177 BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
01178 else if (STATEMENT_LIST_NO_SCOPE (stmt))
01179 stmt = pop_stmt_list (stmt);
01180 else
01181 {
01182
01183
01184 objc_clear_super_receiver ();
01185
01186 stmt = do_poplevel (stmt);
01187 }
01188
01189
01190 add_stmt (stmt);
01191 finish_stmt ();
01192 }
01193
01194
01195
01196
01197
01198 tree
01199 finish_asm_stmt (int volatile_p, tree string, tree output_operands,
01200 tree input_operands, tree clobbers)
01201 {
01202 tree r;
01203 tree t;
01204 int ninputs = list_length (input_operands);
01205 int noutputs = list_length (output_operands);
01206
01207 if (!processing_template_decl)
01208 {
01209 const char *constraint;
01210 const char **oconstraints;
01211 bool allows_mem, allows_reg, is_inout;
01212 tree operand;
01213 int i;
01214
01215 oconstraints = (const char **) alloca (noutputs * sizeof (char *));
01216
01217 string = resolve_asm_operand_names (string, output_operands,
01218 input_operands);
01219
01220 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
01221 {
01222 operand = TREE_VALUE (t);
01223
01224
01225
01226
01227
01228
01229
01230 STRIP_NOPS (operand);
01231
01232 if (!lvalue_or_else (operand, lv_asm))
01233 operand = error_mark_node;
01234
01235 if (operand != error_mark_node
01236 && (TREE_READONLY (operand)
01237 || CP_TYPE_CONST_P (TREE_TYPE (operand))
01238
01239
01240 || TREE_CODE (TREE_TYPE (operand)) == FUNCTION_TYPE
01241 || TREE_CODE (TREE_TYPE (operand)) == METHOD_TYPE
01242
01243
01244 || (CLASS_TYPE_P (TREE_TYPE (operand))
01245 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
01246 readonly_error (operand, "assignment (via 'asm' output)", 0);
01247
01248 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
01249 oconstraints[i] = constraint;
01250
01251 if (parse_output_constraint (&constraint, i, ninputs, noutputs,
01252 &allows_mem, &allows_reg, &is_inout))
01253 {
01254
01255
01256 if (!allows_reg && !cxx_mark_addressable (operand))
01257 operand = error_mark_node;
01258 }
01259 else
01260 operand = error_mark_node;
01261
01262 TREE_VALUE (t) = operand;
01263 }
01264
01265 for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
01266 {
01267 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
01268 operand = decay_conversion (TREE_VALUE (t));
01269
01270
01271
01272
01273
01274 if (TREE_TYPE (operand) == unknown_type_node)
01275 {
01276 error ("type of asm operand %qE could not be determined",
01277 TREE_VALUE (t));
01278 operand = error_mark_node;
01279 }
01280
01281 if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
01282 oconstraints, &allows_mem, &allows_reg))
01283 {
01284
01285
01286 if (!allows_reg && allows_mem)
01287 {
01288
01289
01290 STRIP_NOPS (operand);
01291 if (!cxx_mark_addressable (operand))
01292 operand = error_mark_node;
01293 }
01294 }
01295 else
01296 operand = error_mark_node;
01297
01298 TREE_VALUE (t) = operand;
01299 }
01300 }
01301
01302 r = build_stmt (ASM_EXPR, string,
01303 output_operands, input_operands,
01304 clobbers);
01305 ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
01306 r = maybe_cleanup_point_expr_void (r);
01307 return add_stmt (r);
01308 }
01309
01310
01311
01312 tree
01313 finish_label_stmt (tree name)
01314 {
01315 tree decl = define_label (input_location, name);
01316
01317 if (decl == error_mark_node)
01318 return error_mark_node;
01319
01320 return add_stmt (build_stmt (LABEL_EXPR, decl));
01321 }
01322
01323
01324
01325
01326
01327 void
01328 finish_label_decl (tree name)
01329 {
01330 tree decl = declare_local_label (name);
01331 add_decl_expr (decl);
01332 }
01333
01334
01335
01336 void
01337 finish_decl_cleanup (tree decl, tree cleanup)
01338 {
01339 push_cleanup (decl, cleanup, false);
01340 }
01341
01342
01343
01344 void
01345 finish_eh_cleanup (tree cleanup)
01346 {
01347 push_cleanup (NULL, cleanup, true);
01348 }
01349
01350
01351
01352
01353
01354 void
01355 finish_mem_initializers (tree mem_inits)
01356 {
01357
01358
01359 mem_inits = nreverse (mem_inits);
01360
01361 if (processing_template_decl)
01362 add_stmt (build_min_nt (CTOR_INITIALIZER, mem_inits));
01363 else
01364 emit_mem_initializers (mem_inits);
01365 }
01366
01367
01368
01369 tree
01370 finish_parenthesized_expr (tree expr)
01371 {
01372 if (EXPR_P (expr))
01373
01374 TREE_NO_WARNING (expr) = 1;
01375
01376 if (TREE_CODE (expr) == OFFSET_REF)
01377
01378
01379 PTRMEM_OK_P (expr) = 0;
01380
01381 if (TREE_CODE (expr) == STRING_CST)
01382 PAREN_STRING_LITERAL_P (expr) = 1;
01383
01384 return expr;
01385 }
01386
01387
01388
01389
01390 tree
01391 finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
01392 {
01393 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
01394
01395 if (!object)
01396 {
01397 if (current_function_decl
01398 && DECL_STATIC_FUNCTION_P (current_function_decl))
01399 error ("invalid use of member %q+D in static member function", decl);
01400 else
01401 error ("invalid use of non-static data member %q+D", decl);
01402 error ("from this location");
01403
01404 return error_mark_node;
01405 }
01406 TREE_USED (current_class_ptr) = 1;
01407 if (processing_template_decl && !qualifying_scope)
01408 {
01409 tree type = TREE_TYPE (decl);
01410
01411 if (TREE_CODE (type) == REFERENCE_TYPE)
01412 type = TREE_TYPE (type);
01413 else
01414 {
01415
01416 int quals = cp_type_quals (TREE_TYPE (current_class_ref));
01417
01418 if (DECL_MUTABLE_P (decl))
01419 quals &= ~TYPE_QUAL_CONST;
01420
01421 quals |= cp_type_quals (TREE_TYPE (decl));
01422 type = cp_build_qualified_type (type, quals);
01423 }
01424
01425 return build_min (COMPONENT_REF, type, object, decl, NULL_TREE);
01426 }
01427 else
01428 {
01429 tree access_type = TREE_TYPE (object);
01430 tree lookup_context = context_for_name_lookup (decl);
01431
01432 while (!DERIVED_FROM_P (lookup_context, access_type))
01433 {
01434 access_type = TYPE_CONTEXT (access_type);
01435 while (access_type && DECL_P (access_type))
01436 access_type = DECL_CONTEXT (access_type);
01437
01438 if (!access_type)
01439 {
01440 error ("object missing in reference to %q+D", decl);
01441 error ("from this location");
01442 return error_mark_node;
01443 }
01444 }
01445
01446
01447
01448
01449 if (processing_template_decl)
01450 return build_qualified_name (TREE_TYPE (decl),
01451 qualifying_scope,
01452 DECL_NAME (decl),
01453 false);
01454
01455 perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
01456 decl);
01457
01458
01459
01460 if (qualifying_scope)
01461 {
01462 tree binfo = NULL_TREE;
01463 object = build_scoped_ref (object, qualifying_scope,
01464 &binfo);
01465 }
01466
01467 return build_class_member_access_expr (object, decl,
01468 NULL_TREE,
01469 false);
01470 }
01471 }
01472
01473
01474
01475
01476
01477
01478
01479 void
01480 check_accessibility_of_qualified_id (tree decl,
01481 tree object_type,
01482 tree nested_name_specifier)
01483 {
01484 tree scope;
01485 tree qualifying_type = NULL_TREE;
01486
01487
01488 if (deferred_access_no_check)
01489 return;
01490
01491
01492 scope = context_for_name_lookup (decl);
01493
01494 if (!TYPE_P (scope))
01495 return;
01496
01497 if (object_type
01498
01499
01500
01501
01502
01503
01504
01505
01506 && CLASS_TYPE_P (object_type)
01507 && DERIVED_FROM_P (scope, object_type))
01508
01509
01510 qualifying_type = object_type;
01511 else if (nested_name_specifier)
01512 {
01513
01514
01515
01516 if (DECL_NONSTATIC_MEMBER_P (decl)
01517 && current_class_ptr
01518 && DERIVED_FROM_P (scope, current_class_type))
01519 qualifying_type = current_class_type;
01520
01521
01522 else
01523 qualifying_type = nested_name_specifier;
01524 }
01525 else
01526
01527
01528 qualifying_type = currently_open_derived_class (scope);
01529
01530 if (qualifying_type
01531
01532
01533 && CLASS_TYPE_P (qualifying_type)
01534 && !dependent_type_p (qualifying_type))
01535 perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
01536 decl);
01537 }
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547 tree
01548 finish_qualified_id_expr (tree qualifying_class,
01549 tree expr,
01550 bool done,
01551 bool address_p,
01552 bool template_p,
01553 bool template_arg_p)
01554 {
01555 gcc_assert (TYPE_P (qualifying_class));
01556
01557 if (error_operand_p (expr))
01558 return error_mark_node;
01559
01560 if (DECL_P (expr) || BASELINK_P (expr))
01561 mark_used (expr);
01562
01563 if (template_p)
01564 check_template_keyword (expr);
01565
01566
01567
01568 if (address_p && done)
01569 {
01570 if (TREE_CODE (expr) == SCOPE_REF)
01571 expr = TREE_OPERAND (expr, 1);
01572 expr = build_offset_ref (qualifying_class, expr,
01573 true);
01574 return expr;
01575 }
01576
01577
01578
01579 if (template_arg_p)
01580
01581
01582 ;
01583 else if (TREE_CODE (expr) == FIELD_DECL)
01584 expr = finish_non_static_data_member (expr, current_class_ref,
01585 qualifying_class);
01586 else if (BASELINK_P (expr) && !processing_template_decl)
01587 {
01588 tree fns;
01589
01590
01591 fns = BASELINK_FUNCTIONS (expr);
01592 if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
01593 fns = TREE_OPERAND (fns, 0);
01594
01595
01596 if (!shared_member_p (fns)
01597 && current_class_type
01598 && DERIVED_FROM_P (qualifying_class, current_class_type))
01599 expr = (build_class_member_access_expr
01600 (maybe_dummy_object (qualifying_class, NULL),
01601 expr,
01602 BASELINK_ACCESS_BINFO (expr),
01603 false));
01604 else if (done)
01605
01606
01607 expr = build_offset_ref (qualifying_class, expr, false);
01608 }
01609
01610 return expr;
01611 }
01612
01613
01614
01615
01616 tree
01617 begin_stmt_expr (void)
01618 {
01619 return push_stmt_list ();
01620 }
01621
01622
01623
01624
01625
01626
01627 tree
01628 finish_stmt_expr_expr (tree expr, tree stmt_expr)
01629 {
01630 if (error_operand_p (expr))
01631 return error_mark_node;
01632
01633
01634
01635 if (expr)
01636 {
01637 tree type = TREE_TYPE (expr);
01638
01639 if (processing_template_decl)
01640 {
01641 expr = build_stmt (EXPR_STMT, expr);
01642 expr = add_stmt (expr);
01643
01644
01645 EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
01646 }
01647 else if (VOID_TYPE_P (type))
01648 {
01649
01650 expr = finish_expr_stmt (expr);
01651 }
01652 else
01653 {
01654
01655
01656
01657 expr = force_rvalue (expr);
01658 if (error_operand_p (expr))
01659 return error_mark_node;
01660
01661
01662 type = TREE_TYPE (expr);
01663
01664
01665
01666
01667 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
01668 expr = maybe_cleanup_point_expr (expr);
01669 add_stmt (expr);
01670 }
01671
01672
01673
01674 TREE_TYPE (stmt_expr) = type;
01675 }
01676
01677 return stmt_expr;
01678 }
01679
01680
01681
01682
01683
01684 tree
01685 finish_stmt_expr (tree stmt_expr, bool has_no_scope)
01686 {
01687 tree type;
01688 tree result;
01689
01690 if (error_operand_p (stmt_expr))
01691 return error_mark_node;
01692
01693 gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
01694
01695 type = TREE_TYPE (stmt_expr);
01696 result = pop_stmt_list (stmt_expr);
01697 TREE_TYPE (result) = type;
01698
01699 if (processing_template_decl)
01700 {
01701 result = build_min (STMT_EXPR, type, result);
01702 TREE_SIDE_EFFECTS (result) = 1;
01703 STMT_EXPR_NO_SCOPE (result) = has_no_scope;
01704 }
01705 else if (CLASS_TYPE_P (type))
01706 {
01707
01708
01709
01710
01711 result = force_target_expr (type, result);
01712 }
01713
01714 return result;
01715 }
01716
01717
01718
01719
01720
01721
01722 tree
01723 perform_koenig_lookup (tree fn, tree args)
01724 {
01725 tree identifier = NULL_TREE;
01726 tree functions = NULL_TREE;
01727
01728
01729 if (TREE_CODE (fn) == IDENTIFIER_NODE)
01730 identifier = fn;
01731 else if (is_overloaded_fn (fn))
01732 {
01733 functions = fn;
01734 identifier = DECL_NAME (get_first_fn (functions));
01735 }
01736 else if (DECL_P (fn))
01737 {
01738 functions = fn;
01739 identifier = DECL_NAME (fn);
01740 }
01741
01742
01743
01744
01745
01746 if (!any_type_dependent_arguments_p (args))
01747 {
01748 fn = lookup_arg_dependent (identifier, functions, args);
01749 if (!fn)
01750
01751 fn = unqualified_fn_lookup_error (identifier);
01752 }
01753
01754 return fn;
01755 }
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767 tree
01768 finish_call_expr (tree fn, tree args, bool disallow_virtual, bool koenig_p)
01769 {
01770 tree result;
01771 tree orig_fn;
01772 tree orig_args;
01773
01774 if (fn == error_mark_node || args == error_mark_node)
01775 return error_mark_node;
01776
01777
01778 gcc_assert (!args || TREE_CODE (args) == TREE_LIST);
01779 gcc_assert (!TYPE_P (fn));
01780
01781 orig_fn = fn;
01782 orig_args = args;
01783
01784 if (processing_template_decl)
01785 {
01786 if (type_dependent_expression_p (fn)
01787 || any_type_dependent_arguments_p (args))
01788 {
01789 result = build_nt (CALL_EXPR, fn, args, NULL_TREE);
01790 KOENIG_LOOKUP_P (result) = koenig_p;
01791 return result;
01792 }
01793 if (!BASELINK_P (fn)
01794 && TREE_CODE (fn) != PSEUDO_DTOR_EXPR
01795 && TREE_TYPE (fn) != unknown_type_node)
01796 fn = build_non_dependent_expr (fn);
01797 args = build_non_dependent_args (orig_args);
01798 }
01799
01800 if (is_overloaded_fn (fn))
01801 fn = baselink_for_fns (fn);
01802
01803 result = NULL_TREE;
01804 if (BASELINK_P (fn))
01805 {
01806 tree object;
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826 if (current_class_type
01827 && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
01828 current_class_type)
01829 && current_class_ref)
01830 object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
01831 NULL);
01832 else
01833 {
01834 tree representative_fn;
01835
01836 representative_fn = BASELINK_FUNCTIONS (fn);
01837 if (TREE_CODE (representative_fn) == TEMPLATE_ID_EXPR)
01838 representative_fn = TREE_OPERAND (representative_fn, 0);
01839 representative_fn = get_first_fn (representative_fn);
01840 object = build_dummy_object (DECL_CONTEXT (representative_fn));
01841 }
01842
01843 if (processing_template_decl)
01844 {
01845 if (type_dependent_expression_p (object))
01846 return build_nt (CALL_EXPR, orig_fn, orig_args, NULL_TREE);
01847 object = build_non_dependent_expr (object);
01848 }
01849
01850 result = build_new_method_call (object, fn, args, NULL_TREE,
01851 (disallow_virtual
01852 ? LOOKUP_NONVIRTUAL : 0),
01853 NULL);
01854 }
01855 else if (is_overloaded_fn (fn))
01856 {
01857
01858 if (TREE_CODE (fn) == FUNCTION_DECL
01859 && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
01860 || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
01861 result = resolve_overloaded_builtin (fn, args);
01862
01863 if (!result)
01864
01865 result = build_new_function_call (fn, args, koenig_p);
01866 }
01867 else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
01868 {
01869 if (args)
01870 error ("arguments to destructor are not allowed");
01871
01872
01873 result = build1 (NOP_EXPR,
01874 void_type_node,
01875 TREE_OPERAND (fn, 0));
01876 TREE_SIDE_EFFECTS (result) = 1;
01877 }
01878 else if (CLASS_TYPE_P (TREE_TYPE (fn)))
01879
01880
01881 result = build_new_op (CALL_EXPR, LOOKUP_NORMAL, fn, args, NULL_TREE,
01882 NULL);
01883
01884 if (!result)
01885
01886 result = build_function_call (fn, args);
01887
01888 if (processing_template_decl)
01889 {
01890 result = build3 (CALL_EXPR, TREE_TYPE (result), orig_fn,
01891 orig_args, NULL_TREE);
01892 KOENIG_LOOKUP_P (result) = koenig_p;
01893 }
01894 return result;
01895 }
01896
01897
01898
01899
01900
01901 tree
01902 finish_increment_expr (tree expr, enum tree_code code)
01903 {
01904 return build_x_unary_op (code, expr);
01905 }
01906
01907
01908
01909 tree
01910 finish_this_expr (void)
01911 {
01912 tree result;
01913
01914 if (current_class_ptr)
01915 {
01916 result = current_class_ptr;
01917 }
01918 else if (current_function_decl
01919 && DECL_STATIC_FUNCTION_P (current_function_decl))
01920 {
01921 error ("%<this%> is unavailable for static member functions");
01922 result = error_mark_node;
01923 }
01924 else
01925 {
01926 if (current_function_decl)
01927 error ("invalid use of %<this%> in non-member function");
01928 else
01929 error ("invalid use of %<this%> at top level");
01930 result = error_mark_node;
01931 }
01932
01933 return result;
01934 }
01935
01936
01937
01938
01939
01940
01941 tree
01942 finish_pseudo_destructor_expr (tree object, tree scope, tree destructor)
01943 {
01944 if (destructor == error_mark_node)
01945 return error_mark_node;
01946
01947 gcc_assert (TYPE_P (destructor));
01948
01949 if (!processing_template_decl)
01950 {
01951 if (scope == error_mark_node)
01952 {
01953 error ("invalid qualifying scope in pseudo-destructor name");
01954 return error_mark_node;
01955 }
01956 if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
01957 {
01958 error ("qualified type %qT does not match destructor name ~%qT",
01959 scope, destructor);
01960 return error_mark_node;
01961 }
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
01978 destructor))
01979 {
01980 error ("%qE is not of type %qT", object, destructor);
01981 return error_mark_node;
01982 }
01983 }
01984
01985 return build3 (PSEUDO_DTOR_EXPR, void_type_node, object, scope, destructor);
01986 }
01987
01988
01989
01990 tree
01991 finish_unary_op_expr (enum tree_code code, tree expr)
01992 {
01993 tree result = build_x_unary_op (code, expr);
01994
01995
01996
01997 if (code == NEGATE_EXPR && TREE_CODE (expr) == INTEGER_CST
01998 && TREE_CODE (result) == INTEGER_CST
01999 && !TYPE_UNSIGNED (TREE_TYPE (result))
02000 && INT_CST_LT (result, integer_zero_node))
02001 {
02002
02003
02004 result = copy_node (result);
02005 TREE_NEGATED_INT (result) = 1;
02006 }
02007 overflow_warning (result);
02008 return result;
02009 }
02010
02011
02012
02013
02014 tree
02015 finish_compound_literal (tree type, VEC(constructor_elt,gc) *initializer_list)
02016 {
02017 tree var;
02018 tree compound_literal;
02019
02020 if (!TYPE_OBJ_P (type))
02021 {
02022 error ("compound literal of non-object type %qT", type);
02023 return error_mark_node;
02024 }
02025
02026
02027 compound_literal = build_constructor (NULL_TREE, initializer_list);
02028 if (processing_template_decl)
02029 {
02030 TREE_TYPE (compound_literal) = type;
02031
02032 TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
02033 return compound_literal;
02034 }
02035
02036
02037 var = create_temporary_var (type);
02038 if (!current_function_decl)
02039 {
02040
02041
02042
02043 TREE_STATIC (var) = 1;
02044
02045
02046 TREE_PUBLIC (var) = 0;
02047
02048 DECL_NAME (var) = make_anon_name ();
02049 }
02050
02051
02052 pushdecl (var);
02053
02054
02055 cp_finish_decl (var, compound_literal,
02056 false,
02057 NULL_TREE,
02058 LOOKUP_ONLYCONVERTING);
02059 return var;
02060 }
02061
02062
02063
02064
02065 tree
02066 finish_fname (tree id)
02067 {
02068 tree decl;
02069
02070 decl = fname_decl (C_RID_CODE (id), id);
02071 if (processing_template_decl)
02072 decl = DECL_NAME (decl);
02073 return decl;
02074 }
02075
02076
02077
02078 void
02079 finish_translation_unit (void)
02080 {
02081
02082
02083 pop_everything ();
02084 while (current_namespace != global_namespace)
02085 pop_namespace ();
02086
02087
02088 finish_fname_decls ();
02089 }
02090
02091
02092
02093
02094 tree
02095 finish_template_type_parm (tree aggr, tree identifier)
02096 {
02097 if (aggr != class_type_node)
02098 {
02099 pedwarn ("template type parameters must use the keyword %<class%> or %<typename%>");
02100 aggr = class_type_node;
02101 }
02102
02103 return build_tree_list (aggr, identifier);
02104 }
02105
02106
02107
02108
02109 tree
02110 finish_template_template_parm (tree aggr, tree identifier)
02111 {
02112 tree decl = build_decl (TYPE_DECL, identifier, NULL_TREE);
02113 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
02114 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
02115 DECL_TEMPLATE_RESULT (tmpl) = decl;
02116 DECL_ARTIFICIAL (decl) = 1;
02117 end_template_decl ();
02118
02119 gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
02120
02121 return finish_template_type_parm (aggr, tmpl);
02122 }
02123
02124
02125
02126
02127
02128 tree
02129 check_template_template_default_arg (tree argument)
02130 {
02131 if (TREE_CODE (argument) != TEMPLATE_DECL
02132 && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
02133 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
02134 {
02135 if (TREE_CODE (argument) == TYPE_DECL)
02136 error ("invalid use of type %qT as a default value for a template "
02137 "template-parameter", TREE_TYPE (argument));
02138 else
02139 error ("invalid default argument for a template template parameter");
02140 return error_mark_node;
02141 }
02142
02143 return argument;
02144 }
02145
02146
02147
02148 tree
02149 begin_class_definition (tree t, tree attributes)
02150 {
02151 if (t == error_mark_node)
02152 return error_mark_node;
02153
02154 if (processing_template_parmlist)
02155 {
02156 error ("definition of %q#T inside template parameter list", t);
02157 return error_mark_node;
02158 }
02159
02160
02161
02162
02163
02164
02165 else if (TREE_CODE (t) == TYPENAME_TYPE)
02166 {
02167 error ("invalid definition of qualified type %qT", t);
02168 t = error_mark_node;
02169 }
02170
02171 if (t == error_mark_node || ! IS_AGGR_TYPE (t))
02172 {
02173 t = make_aggr_type (RECORD_TYPE);
02174 pushtag (make_anon_name (), t, ts_current);
02175 }
02176
02177
02178 DECL_SOURCE_LOCATION (TYPE_NAME (t)) = input_location;
02179
02180 if (TYPE_BEING_DEFINED (t))
02181 {
02182 t = make_aggr_type (TREE_CODE (t));
02183 pushtag (TYPE_IDENTIFIER (t), t, ts_current);
02184 }
02185 maybe_process_partial_specialization (t);
02186 pushclass (t);
02187 TYPE_BEING_DEFINED (t) = 1;
02188
02189 cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
02190
02191 if (flag_pack_struct)
02192 {
02193 tree v;
02194 TYPE_PACKED (t) = 1;
02195
02196
02197
02198 for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
02199 TYPE_PACKED (v) = 1;
02200 }
02201
02202
02203
02204 if (! TYPE_ANONYMOUS_P (t))
02205 {
02206 struct c_fileinfo *finfo = get_fileinfo (input_filename);
02207 CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
02208 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
02209 (t, finfo->interface_unknown);
02210 }
02211 reset_specialization();
02212
02213
02214 build_self_reference ();
02215
02216 return t;
02217 }
02218
02219
02220
02221 void
02222 finish_member_declaration (tree decl)
02223 {
02224 if (decl == error_mark_node || decl == NULL_TREE)
02225 return;
02226
02227 if (decl == void_type_node)
02228
02229
02230 return;
02231
02232
02233 gcc_assert (TREE_CHAIN (decl) == NULL_TREE);
02234
02235
02236 TREE_PRIVATE (decl)
02237 = (current_access_specifier == access_private_node);
02238 TREE_PROTECTED (decl)
02239 = (current_access_specifier == access_protected_node);
02240 if (TREE_CODE (decl) == TEMPLATE_DECL)
02241 {
02242 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
02243 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
02244 }
02245
02246
02247 DECL_CONTEXT (decl) = current_class_type;
02248
02249
02250
02251
02252
02253 if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c)
02254 SET_DECL_LANGUAGE (decl, lang_cplusplus);
02255
02256
02257
02258
02259 if (TREE_CODE (decl) == FUNCTION_DECL
02260 || DECL_FUNCTION_TEMPLATE_P (decl))
02261 {
02262
02263
02264 if (add_method (current_class_type, decl, NULL_TREE))
02265 {
02266 TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
02267 TYPE_METHODS (current_class_type) = decl;
02268
02269 maybe_add_class_template_decl_list (current_class_type, decl,
02270 0);
02271 }
02272 }
02273
02274 else if ((TREE_CODE (decl) == USING_DECL && !DECL_DEPENDENT_P (decl))
02275 || pushdecl_class_level (decl))
02276 {
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294 if (TREE_CODE (decl) == TYPE_DECL)
02295 TYPE_FIELDS (current_class_type)
02296 = chainon (TYPE_FIELDS (current_class_type), decl);
02297 else
02298 {
02299 TREE_CHAIN (decl) = TYPE_FIELDS (current_class_type);
02300 TYPE_FIELDS (current_class_type) = decl;
02301 }
02302
02303 maybe_add_class_template_decl_list (current_class_type, decl,
02304 0);
02305 }
02306
02307 if (pch_file)
02308 note_decl_for_pch (decl);
02309 }
02310
02311
02312
02313
02314
02315
02316 void
02317 note_decl_for_pch (tree decl)
02318 {
02319 gcc_assert (pch_file);
02320
02321
02322
02323 if ((TREE_CODE (decl) == VAR_DECL
02324 || TREE_CODE (decl) == FUNCTION_DECL)
02325 && !processing_template_decl)
02326 mangle_decl (decl);
02327 }
02328
02329
02330
02331
02332 void
02333 finish_template_decl (tree parms)
02334 {
02335 if (parms)
02336 end_template_decl ();
02337 else
02338 end_specialization ();
02339 }
02340
02341
02342
02343
02344
02345
02346 tree
02347 finish_template_type (tree name, tree args, int entering_scope)
02348 {
02349 tree decl;
02350
02351 decl = lookup_template_class (name, args,
02352 NULL_TREE, NULL_TREE, entering_scope,
02353 tf_warning_or_error | tf_user);
02354 if (decl != error_mark_node)
02355 decl = TYPE_STUB_DECL (decl);
02356
02357 return decl;
02358 }
02359
02360
02361
02362
02363
02364
02365
02366
02367 tree
02368 finish_base_specifier (tree base, tree access, bool virtual_p)
02369 {
02370 tree result;
02371
02372 if (base == error_mark_node)
02373 {
02374 error ("invalid base-class specification");
02375 result = NULL_TREE;
02376 }
02377 else if (! is_aggr_type (base, 1))
02378 result = NULL_TREE;
02379 else
02380 {
02381 if (cp_type_quals (base) != 0)
02382 {
02383 error ("base class %qT has cv qualifiers", base);
02384 base = TYPE_MAIN_VARIANT (base);
02385 }
02386 result = build_tree_list (access, base);
02387 if (virtual_p)
02388 TREE_TYPE (result) = integer_type_node;
02389 }
02390
02391 return result;
02392 }
02393
02394
02395
02396
02397 void
02398 qualified_name_lookup_error (tree scope, tree name, tree decl)
02399 {
02400 if (scope == error_mark_node)
02401 ;
02402 else if (TYPE_P (scope))
02403 {
02404 if (!COMPLETE_TYPE_P (scope))
02405 error ("incomplete type %qT used in nested name specifier", scope);
02406 else if (TREE_CODE (decl) == TREE_LIST)
02407 {
02408 error ("reference to %<%T::%D%> is ambiguous", scope, name);
02409 print_candidates (decl);
02410 }
02411 else
02412 error ("%qD is not a member of %qT", name, scope);
02413 }
02414 else if (scope != global_namespace)
02415 error ("%qD is not a member of %qD", name, scope);
02416 else
02417 error ("%<::%D%> has not been declared", name);
02418 }
02419
02420
02421
02422
02423
02424
02425 tree
02426 baselink_for_fns (tree fns)
02427 {
02428 tree fn;
02429 tree cl;
02430
02431 if (BASELINK_P (fns)
02432 || error_operand_p (fns))
02433 return fns;
02434
02435 fn = fns;
02436 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
02437 fn = TREE_OPERAND (fn, 0);
02438 fn = get_first_fn (fn);
02439 if (!DECL_FUNCTION_MEMBER_P (fn))
02440 return fns;
02441
02442 cl = currently_open_derived_class (DECL_CONTEXT (fn));
02443 if (!cl)
02444 cl = DECL_CONTEXT (fn);
02445 cl = TYPE_BINFO (cl);
02446 return build_baselink (cl, cl, fns, NULL_TREE);
02447 }
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483 tree
02484 finish_id_expression (tree id_expression,
02485 tree decl,
02486 tree scope,
02487 cp_id_kind *idk,
02488 bool integral_constant_expression_p,
02489 bool allow_non_integral_constant_expression_p,
02490 bool *non_integral_constant_expression_p,
02491 bool template_p,
02492 bool done,
02493 bool address_p,
02494 bool template_arg_p,
02495 const char **error_msg)
02496 {
02497
02498 *idk = CP_ID_KIND_NONE;
02499 *error_msg = NULL;
02500
02501 if (id_expression == error_mark_node)
02502 return error_mark_node;
02503
02504
02505
02506 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
02507 || TREE_CODE (decl) == TYPE_DECL)
02508 ;
02509
02510 else
02511 {
02512 if (decl == error_mark_node)
02513 {
02514
02515 if (scope
02516 && (!TYPE_P (scope)
02517 || (!dependent_type_p (scope)
02518 && !(TREE_CODE (id_expression) == IDENTIFIER_NODE
02519 && IDENTIFIER_TYPENAME_P (id_expression)
02520 && dependent_type_p (TREE_TYPE (id_expression))))))
02521 {
02522
02523
02524
02525 qualified_name_lookup_error (scope, id_expression, decl);
02526 return error_mark_node;
02527 }
02528 else if (!scope)
02529 {
02530
02531 *idk = CP_ID_KIND_UNQUALIFIED;
02532 return id_expression;
02533 }
02534 else
02535 decl = id_expression;
02536 }
02537
02538
02539
02540 else
02541 decl = check_for_out_of_scope_variable (decl);
02542
02543
02544
02545
02546
02547 if (!scope && decl != error_mark_node)
02548 maybe_note_name_used_in_class (id_expression, decl);
02549
02550
02551 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
02552 {
02553 tree context = decl_function_context (decl);
02554 if (context != NULL_TREE && context != current_function_decl
02555 && ! TREE_STATIC (decl))
02556 {
02557 error (TREE_CODE (decl) == VAR_DECL
02558 ? "use of %<auto%> variable from containing function"
02559 : "use of parameter from containing function");
02560 error (" %q+#D declared here", decl);
02561 return error_mark_node;
02562 }
02563 }
02564 }
02565
02566
02567
02568 if (TREE_CODE (decl) == TEMPLATE_DECL
02569 && !DECL_FUNCTION_TEMPLATE_P (decl))
02570 {
02571 *error_msg = "missing template arguments";
02572 return error_mark_node;
02573 }
02574 else if (TREE_CODE (decl) == TYPE_DECL
02575 || TREE_CODE (decl) == NAMESPACE_DECL)
02576 {
02577 *error_msg = "expected primary-expression";
02578 return error_mark_node;
02579 }
02580
02581
02582
02583 if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
02584 || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
02585 {
02586 tree r;
02587
02588 *idk = CP_ID_KIND_NONE;
02589 if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
02590 decl = TEMPLATE_PARM_DECL (decl);
02591 r = convert_from_reference (DECL_INITIAL (decl));
02592
02593 if (integral_constant_expression_p
02594 && !dependent_type_p (TREE_TYPE (decl))
02595 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
02596 {
02597 if (!allow_non_integral_constant_expression_p)
02598 error ("template parameter %qD of type %qT is not allowed in "
02599 "an integral constant expression because it is not of "
02600 "integral or enumeration type", decl, TREE_TYPE (decl));
02601 *non_integral_constant_expression_p = true;
02602 }
02603 return r;
02604 }
02605
02606
02607 else if (TREE_CODE (decl) == CONST_DECL)
02608 {
02609 *idk = CP_ID_KIND_NONE;
02610 if (!processing_template_decl)
02611 {
02612 used_types_insert (TREE_TYPE (decl));
02613 return DECL_INITIAL (decl);
02614 }
02615 return decl;
02616 }
02617 else
02618 {
02619 bool dependent_p;
02620
02621
02622
02623
02624 *idk = (scope
02625 ? CP_ID_KIND_QUALIFIED
02626 : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
02627 ? CP_ID_KIND_TEMPLATE_ID
02628 : CP_ID_KIND_UNQUALIFIED));
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641 dependent_p = false;
02642 if (!processing_template_decl)
02643
02644 ;
02645
02646
02647 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
02648 && (TREE_CODE (TREE_OPERAND (decl, 0))
02649 == IDENTIFIER_NODE))
02650 dependent_p = true;
02651
02652
02653 else if (!is_overloaded_fn (decl))
02654 dependent_p
02655 = dependent_type_p (TREE_TYPE (decl));
02656
02657
02658 else
02659 {
02660 tree fns = decl;
02661
02662 if (BASELINK_P (fns))
02663 fns = BASELINK_FUNCTIONS (fns);
02664
02665
02666
02667 if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
02668 {
02669 tree args = TREE_OPERAND (fns, 1);
02670 dependent_p = any_dependent_template_arguments_p (args);
02671
02672
02673 fns = TREE_OPERAND (fns, 0);
02674 }
02675
02676
02677
02678 while (fns && !dependent_p)
02679 {
02680 tree fn = OVL_CURRENT (fns);
02681
02682
02683
02684 if (TREE_CODE (fn) == FUNCTION_DECL
02685 && type_dependent_expression_p (fn))
02686 dependent_p = true;
02687 else if (TREE_CODE (fn) == TEMPLATE_DECL
02688 && dependent_template_p (fn))
02689 dependent_p = true;
02690
02691 fns = OVL_NEXT (fns);
02692 }
02693 }
02694
02695
02696
02697 if (dependent_p)
02698 {
02699
02700
02701 if (scope)
02702 {
02703
02704
02705
02706 if (integral_constant_expression_p)
02707 *non_integral_constant_expression_p = true;
02708 if (TYPE_P (scope))
02709 {
02710 if (address_p && done)
02711 decl = finish_qualified_id_expr (scope, decl,
02712 done, address_p,
02713 template_p,
02714 template_arg_p);
02715 else if (dependent_type_p (scope))
02716 decl = build_qualified_name (NULL_TREE,
02717 scope,
02718 id_expression,
02719 template_p);
02720 else if (DECL_P (decl))
02721 decl = build_qualified_name (TREE_TYPE (decl),
02722 scope,
02723 id_expression,
02724 template_p);
02725 }
02726 if (TREE_TYPE (decl))
02727 decl = convert_from_reference (decl);
02728 return decl;
02729 }
02730
02731
02732 if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR)
02733 return id_expression;
02734 *idk = CP_ID_KIND_UNQUALIFIED_DEPENDENT;
02735
02736
02737
02738 if (TREE_CODE (decl) == VAR_DECL
02739 || TREE_CODE (decl) == PARM_DECL)
02740 return convert_from_reference (decl);
02741
02742
02743 else if (TREE_CODE (decl) == FIELD_DECL)
02744 {
02745
02746
02747
02748 push_deferring_access_checks (dk_no_check);
02749 decl = finish_non_static_data_member
02750 (decl, current_class_ref,
02751 NULL_TREE);
02752 pop_deferring_access_checks ();
02753 return decl;
02754 }
02755 return id_expression;
02756 }
02757
02758
02759
02760
02761 if (integral_constant_expression_p
02762 && ! DECL_INTEGRAL_CONSTANT_VAR_P (decl)
02763 && ! builtin_valid_in_constant_expr_p (decl))
02764 {
02765 if (!allow_non_integral_constant_expression_p)
02766 {
02767 error ("%qD cannot appear in a constant-expression", decl);
02768 return error_mark_node;
02769 }
02770 *non_integral_constant_expression_p = true;
02771 }
02772
02773 if (TREE_CODE (decl) == NAMESPACE_DECL)
02774 {
02775 error ("use of namespace %qD as expression", decl);
02776 return error_mark_node;
02777 }
02778 else if (DECL_CLASS_TEMPLATE_P (decl))
02779 {
02780 error ("use of class template %qT as expression", decl);
02781 return error_mark_node;
02782 }
02783 else if (TREE_CODE (decl) == TREE_LIST)
02784 {
02785
02786 error ("request for member %qD is ambiguous in "
02787 "multiple inheritance lattice", id_expression);
02788 print_candidates (decl);
02789 return error_mark_node;
02790 }
02791
02792
02793
02794 if (TREE_CODE (decl) == VAR_DECL
02795 || TREE_CODE (decl) == PARM_DECL
02796 || TREE_CODE (decl) == RESULT_DECL)
02797 mark_used (decl);
02798
02799 if (scope)
02800 {
02801 decl = (adjust_result_of_qualified_name_lookup
02802 (decl, scope, current_class_type));
02803
02804 if (TREE_CODE (decl) == FUNCTION_DECL)
02805 mark_used (decl);
02806
02807 if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl))
02808 decl = finish_qualified_id_expr (scope,
02809 decl,
02810 done,
02811 address_p,
02812 template_p,
02813 template_arg_p);
02814 else
02815 {
02816 tree r = convert_from_reference (decl);
02817
02818 if (processing_template_decl && TYPE_P (scope))
02819 r = build_qualified_name (TREE_TYPE (r),
02820 scope, decl,
02821 template_p);
02822 decl = r;
02823 }
02824 }
02825 else if (TREE_CODE (decl) == FIELD_DECL)
02826 {
02827
02828
02829
02830 push_deferring_access_checks (dk_no_check);
02831 decl = finish_non_static_data_member (decl, current_class_ref,
02832 NULL_TREE);
02833 pop_deferring_access_checks ();
02834 }
02835 else if (is_overloaded_fn (decl))
02836 {
02837 tree first_fn;
02838
02839 first_fn = decl;
02840 if (TREE_CODE (first_fn) == TEMPLATE_ID_EXPR)
02841 first_fn = TREE_OPERAND (first_fn, 0);
02842 first_fn = get_first_fn (first_fn);
02843 if (TREE_CODE (first_fn) == TEMPLATE_DECL)
02844 first_fn = DECL_TEMPLATE_RESULT (first_fn);
02845
02846 if (!really_overloaded_fn (decl))
02847 mark_used (first_fn);
02848
02849 if (!template_arg_p
02850 && TREE_CODE (first_fn) == FUNCTION_DECL
02851 && DECL_FUNCTION_MEMBER_P (first_fn)
02852 && !shared_member_p (decl))
02853 {
02854
02855 decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
02856 return finish_class_member_access_expr (decl, id_expression,
02857 false);
02858 }
02859
02860 decl = baselink_for_fns (decl);
02861 }
02862 else
02863 {
02864 if (DECL_P (decl) && DECL_NONLOCAL (decl)
02865 && DECL_CLASS_SCOPE_P (decl)
02866 && DECL_CONTEXT (decl) != current_class_type)
02867 {
02868 tree path;
02869
02870 path = currently_open_derived_class (DECL_CONTEXT (decl));
02871 perform_or_defer_access_check (TYPE_BINFO (path), decl, decl);
02872 }
02873
02874 decl = convert_from_reference (decl);
02875 }
02876 }
02877
02878 if (TREE_DEPRECATED (decl))
02879 warn_deprecated_use (decl);
02880
02881 return decl;
02882 }
02883
02884
02885
02886
02887 tree
02888 finish_typeof (tree expr)
02889 {
02890 tree type;
02891
02892 if (type_dependent_expression_p (expr))
02893 {
02894 type = make_aggr_type (TYPEOF_TYPE);
02895 TYPEOF_TYPE_EXPR (type) = expr;
02896
02897 return type;
02898 }
02899
02900 type = unlowered_expr_type (expr);
02901
02902 if (!type || type == unknown_type_node)
02903 {
02904 error ("type of %qE is unknown", expr);
02905 return error_mark_node;
02906 }
02907
02908 return type;
02909 }
02910
02911
02912
02913
02914 tree
02915 finish_offsetof (tree expr)
02916 {
02917 if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
02918 {
02919 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
02920 TREE_OPERAND (expr, 2));
02921 return error_mark_node;
02922 }
02923 if (TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
02924 || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE
02925 || TREE_CODE (TREE_TYPE (expr)) == UNKNOWN_TYPE)
02926 {
02927 if (TREE_CODE (expr) == COMPONENT_REF
02928 || TREE_CODE (expr) == COMPOUND_EXPR)
02929 expr = TREE_OPERAND (expr, 1);
02930 error ("cannot apply %<offsetof%> to member function %qD", expr);
02931 return error_mark_node;
02932 }
02933 return fold_offsetof (expr, NULL_TREE);
02934 }
02935
02936
02937
02938
02939 #ifndef KEY
02940 static
02941 #endif
02942 tree simplify_aggr_init_exprs_r (tree* tp,
02943 int* walk_subtrees,
02944 void* data ATTRIBUTE_UNUSED)
02945 {
02946
02947
02948
02949
02950
02951 if (TYPE_P (*tp))
02952 {
02953 *walk_subtrees = 0;
02954 return NULL_TREE;
02955 }
02956
02957 else if (TREE_CODE (*tp) != AGGR_INIT_EXPR)
02958 return NULL_TREE;
02959
02960 simplify_aggr_init_expr (tp);
02961
02962
02963 return NULL_TREE;
02964 }
02965
02966
02967
02968
02969
02970 void
02971 simplify_aggr_init_expr (tree *tp)
02972 {
02973 tree aggr_init_expr = *tp;
02974
02975
02976 tree fn = TREE_OPERAND (aggr_init_expr, 0);
02977 tree args = TREE_OPERAND (aggr_init_expr, 1);
02978 tree slot = TREE_OPERAND (aggr_init_expr, 2);
02979 tree type = TREE_TYPE (slot);
02980
02981 tree call_expr;
02982 enum style_t { ctor, arg, pcc } style;
02983
02984 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
02985 style = ctor;
02986 #ifdef PCC_STATIC_STRUCT_RETURN
02987 else if (1)
02988 style = pcc;
02989 #endif
02990 else
02991 {
02992 gcc_assert (TREE_ADDRESSABLE (type));
02993 style = arg;
02994 }
02995
02996 if (style == ctor)
02997 {
02998
02999
03000 tree addr;
03001
03002 args = TREE_CHAIN (args);
03003 cxx_mark_addressable (slot);
03004 addr = build1 (ADDR_EXPR, build_pointer_type (type), slot);
03005 args = tree_cons (NULL_TREE, addr, args);
03006 }
03007
03008 call_expr = build3 (CALL_EXPR,
03009 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
03010 fn, args, NULL_TREE);
03011
03012 if (style == arg)
03013 {
03014
03015
03016 cxx_mark_addressable (slot);
03017 CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
03018 call_expr = build2 (MODIFY_EXPR, TREE_TYPE (call_expr), slot, call_expr);
03019 }
03020 else if (style == pcc)
03021 {
03022
03023
03024
03025 push_deferring_access_checks (dk_no_check);
03026 call_expr = build_aggr_init (slot, call_expr,
03027 DIRECT_BIND | LOOKUP_ONLYCONVERTING);
03028 pop_deferring_access_checks ();
03029 call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
03030 }
03031
03032 *tp = call_expr;
03033 }
03034
03035
03036
03037 static void
03038 emit_associated_thunks (tree fn)
03039 {
03040
03041
03042
03043
03044
03045 if (DECL_VIRTUAL_P (fn))
03046 {
03047 tree thunk;
03048
03049 for (thunk = DECL_THUNKS (fn); thunk; thunk = TREE_CHAIN (thunk))
03050 {
03051 if (!THUNK_ALIAS (thunk))
03052 {
03053 use_thunk (thunk, 1);
03054 if (DECL_RESULT_THUNK_P (thunk))
03055 {
03056 tree probe;
03057
03058 for (probe = DECL_THUNKS (thunk);
03059 probe; probe = TREE_CHAIN (probe))
03060 use_thunk (probe, 1);
03061 }
03062 }
03063 else
03064 gcc_assert (!DECL_THUNKS (thunk));
03065 }
03066 }
03067 }
03068
03069
03070
03071 void
03072 expand_body (tree fn)
03073 {
03074 tree saved_function;
03075
03076
03077
03078 if (DECL_DECLARED_INLINE_P (fn))
03079 import_export_decl (fn);
03080
03081
03082
03083
03084
03085
03086 if (DECL_EXTERNAL (fn))
03087 return;
03088
03089
03090 saved_function = current_function_decl;
03091
03092
03093 emit_associated_thunks (fn);
03094
03095
03096
03097
03098 gcc_assert (function_depth == 0);
03099
03100 tree_rest_of_compilation (fn);
03101
03102 current_function_decl = saved_function;
03103
03104 if (DECL_CLONED_FUNCTION_P (fn))
03105 {
03106
03107
03108
03109
03110 tree probe;
03111
03112 for (probe = TREE_CHAIN (DECL_CLONED_FUNCTION (fn));
03113 probe && DECL_CLONED_FUNCTION_P (probe);
03114 probe = TREE_CHAIN (probe))
03115 {
03116 tree parms;
03117
03118 for (parms = DECL_ARGUMENTS (probe);
03119 parms; parms = TREE_CHAIN (parms))
03120 TREE_USED (parms) = 1;
03121 }
03122 }
03123 }
03124
03125
03126
03127 void
03128 expand_or_defer_fn (tree fn)
03129 {
03130
03131
03132 if (processing_template_decl)
03133 {
03134
03135
03136
03137
03138
03139
03140 if (!function_depth)
03141 ggc_collect ();
03142 return;
03143 }
03144
03145 #ifdef KEY
03146
03147
03148
03149
03150 if (!flag_spin_file)
03151 #endif
03152
03153 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
03154 simplify_aggr_init_exprs_r,
03155 NULL);
03156
03157
03158
03159 if (maybe_clone_body (fn))
03160 {
03161
03162
03163 TREE_ASM_WRITTEN (fn) = 1;
03164 return;
03165 }
03166
03167
03168
03169
03170 if (DECL_STATIC_CONSTRUCTOR (fn))
03171 static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
03172
03173
03174
03175
03176 if (DECL_STATIC_DESTRUCTOR (fn))
03177 static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
03178
03179
03180
03181
03182
03183 if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn))
03184 {
03185 if (DECL_INTERFACE_KNOWN (fn))
03186
03187 ;
03188 else if (!at_eof)
03189 {
03190 DECL_EXTERNAL (fn) = 1;
03191 DECL_NOT_REALLY_EXTERN (fn) = 1;
03192 note_vague_linkage_fn (fn);
03193
03194
03195
03196
03197
03198 if (!DECL_IMPLICIT_INSTANTIATION (fn))
03199 {
03200
03201
03202
03203 gcc_assert (TREE_PUBLIC (fn));
03204 comdat_linkage (fn);
03205 DECL_INTERFACE_KNOWN (fn) = 1;
03206 }
03207 }
03208 else
03209 import_export_decl (fn);
03210
03211
03212
03213
03214 if (flag_keep_inline_functions && DECL_DECLARED_INLINE_P (fn))
03215 mark_needed (fn);
03216 }
03217
03218
03219
03220 if (flag_syntax_only)
03221 return;
03222
03223 function_depth++;
03224
03225
03226 cgraph_finalize_function (fn, function_depth > 1);
03227
03228 function_depth--;
03229 }
03230
03231 struct nrv_data
03232 {
03233 tree var;
03234 tree result;
03235 htab_t visited;
03236 };
03237
03238
03239
03240 static tree
03241 finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
03242 {
03243 struct nrv_data *dp = (struct nrv_data *)data;
03244 void **slot;
03245
03246
03247
03248 if (TYPE_P (*tp))
03249 *walk_subtrees = 0;
03250
03251
03252
03253 else if (TREE_CODE (*tp) == RETURN_EXPR)
03254 TREE_OPERAND (*tp, 0) = dp->result;
03255
03256
03257 else if (TREE_CODE (*tp) == CLEANUP_STMT
03258 && CLEANUP_DECL (*tp) == dp->var)
03259 CLEANUP_EH_ONLY (*tp) = 1;
03260
03261
03262 else if (TREE_CODE (*tp) == DECL_EXPR
03263 && DECL_EXPR_DECL (*tp) == dp->var)
03264 {
03265 tree init;
03266 if (DECL_INITIAL (dp->var)
03267 && DECL_INITIAL (dp->var) != error_mark_node)
03268 {
03269 init = build2 (INIT_EXPR, void_type_node, dp->result,
03270 DECL_INITIAL (dp->var));
03271 DECL_INITIAL (dp->var) = error_mark_node;
03272 }
03273 else
03274 init = build_empty_stmt ();
03275 SET_EXPR_LOCUS (init, EXPR_LOCUS (*tp));
03276 *tp = init;
03277 }
03278
03279 else if (*tp == dp->var)
03280 *tp = dp->result;
03281
03282
03283
03284
03285 slot = htab_find_slot (dp->visited, *tp, INSERT);
03286 if (*slot)
03287 *walk_subtrees = 0;
03288 else
03289 *slot = *tp;
03290
03291
03292 return NULL_TREE;
03293 }
03294
03295
03296
03297
03298
03299
03300 void
03301 finalize_nrv (tree *tp, tree var, tree result)
03302 {
03303 struct nrv_data data;
03304
03305 #ifdef KEY
03306 if (flag_spin_file)
03307 DECL_NAMED_RETURN_OBJECT(current_function_decl) = var;
03308 #endif
03309
03310
03311 DECL_NAME (result) = DECL_NAME (var);
03312 DECL_ARTIFICIAL (result) = DECL_ARTIFICIAL (var);
03313 DECL_IGNORED_P (result) = DECL_IGNORED_P (var);
03314 DECL_SOURCE_LOCATION (result) = DECL_SOURCE_LOCATION (var);
03315 DECL_ABSTRACT_ORIGIN (result) = DECL_ABSTRACT_ORIGIN (var);
03316
03317 TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
03318
03319 data.var = var;
03320 data.result = result;
03321 data.visited = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
03322 walk_tree (tp, finalize_nrv_r, &data, 0);
03323 htab_delete (data.visited);
03324 }
03325
03326
03327
03328
03329 tree
03330 finish_omp_clauses (tree clauses)
03331 {
03332 bitmap_head generic_head, firstprivate_head, lastprivate_head;
03333 tree c, t, *pc = &clauses;
03334 const char *name;
03335
03336 bitmap_obstack_initialize (NULL);
03337 bitmap_initialize (&generic_head, &bitmap_default_obstack);
03338 bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
03339 bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
03340
03341 for (pc = &clauses, c = clauses; c ; c = *pc)
03342 {
03343 bool remove = false;
03344
03345 switch (OMP_CLAUSE_CODE (c))
03346 {
03347 case OMP_CLAUSE_SHARED:
03348 name = "shared";
03349 goto check_dup_generic;
03350 case OMP_CLAUSE_PRIVATE:
03351 name = "private";
03352 goto check_dup_generic;
03353 case OMP_CLAUSE_REDUCTION:
03354 name = "reduction";
03355 goto check_dup_generic;
03356 case OMP_CLAUSE_COPYPRIVATE:
03357 name = "copyprivate";
03358 goto check_dup_generic;
03359 case OMP_CLAUSE_COPYIN:
03360 name = "copyin";
03361 goto check_dup_generic;
03362 check_dup_generic:
03363 t = OMP_CLAUSE_DECL (c);
03364 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
03365 {
03366 if (processing_template_decl)
03367 break;
03368 error ("%qE is not a variable in clause %qs", t, name);
03369 remove = true;
03370 }
03371 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
03372 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
03373 || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
03374 {
03375 error ("%qE appears more than once in data clauses", t);
03376 remove = true;
03377 }
03378 else
03379 bitmap_set_bit (&generic_head, DECL_UID (t));
03380 break;
03381
03382 case OMP_CLAUSE_FIRSTPRIVATE:
03383 t = OMP_CLAUSE_DECL (c);
03384 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
03385 {
03386 if (processing_template_decl)
03387 break;
03388 error ("%qE is not a variable in clause %<firstprivate%>", t);
03389 remove = true;
03390 }
03391 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
03392 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
03393 {
03394 error ("%qE appears more than once in data clauses", t);
03395 remove = true;
03396 }
03397 else
03398 bitmap_set_bit (&firstprivate_head, DECL_UID (t));
03399 break;
03400
03401 case OMP_CLAUSE_LASTPRIVATE:
03402 t = OMP_CLAUSE_DECL (c);
03403 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
03404 {
03405 if (processing_template_decl)
03406 break;
03407 error ("%qE is not a variable in clause %<lastprivate%>", t);
03408 remove = true;
03409 }
03410 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
03411 || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
03412 {
03413 error ("%qE appears more than once in data clauses", t);
03414 remove = true;
03415 }
03416 else
03417 bitmap_set_bit (&lastprivate_head, DECL_UID (t));
03418 break;
03419
03420 case OMP_CLAUSE_IF:
03421 t = OMP_CLAUSE_IF_EXPR (c);
03422 t = maybe_convert_cond (t);
03423 if (t == error_mark_node)
03424 remove = true;
03425 OMP_CLAUSE_IF_EXPR (c) = t;
03426 break;
03427
03428 case OMP_CLAUSE_NUM_THREADS:
03429 t = OMP_CLAUSE_NUM_THREADS_EXPR (c);
03430 if (t == error_mark_node)
03431 remove = true;
03432 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
03433 && !type_dependent_expression_p (t))
03434 {
03435 error ("num_threads expression must be integral");
03436 remove = true;
03437 }
03438 break;
03439
03440 case OMP_CLAUSE_SCHEDULE:
03441 t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
03442 if (t == NULL)
03443 ;
03444 else if (t == error_mark_node)
03445 remove = true;
03446 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
03447 && !type_dependent_expression_p (t))
03448 {
03449 error ("schedule chunk size expression must be integral");
03450 remove = true;
03451 }
03452 break;
03453
03454 case OMP_CLAUSE_NOWAIT:
03455 case OMP_CLAUSE_ORDERED:
03456 case OMP_CLAUSE_DEFAULT:
03457 break;
03458
03459 default:
03460 gcc_unreachable ();
03461 }
03462
03463 if (remove)
03464 *pc = OMP_CLAUSE_CHAIN (c);
03465 else
03466 pc = &OMP_CLAUSE_CHAIN (c);
03467 }
03468
03469 for (pc = &clauses, c = clauses; c ; c = *pc)
03470 {
03471 enum tree_code c_kind = OMP_CLAUSE_CODE (c);
03472 bool remove = false;
03473 bool need_complete_non_reference = false;
03474 bool need_default_ctor = false;
03475 bool need_copy_ctor = false;
03476 bool need_copy_assignment = false;
03477 bool need_implicitly_determined = false;
03478 tree type, inner_type;
03479
03480 switch (c_kind)
03481 {
03482 case OMP_CLAUSE_SHARED:
03483 name = "shared";
03484 need_implicitly_determined = true;
03485 break;
03486 case OMP_CLAUSE_PRIVATE:
03487 name = "private";
03488 need_complete_non_reference = true;
03489 need_default_ctor = true;
03490 need_implicitly_determined = true;
03491 break;
03492 case OMP_CLAUSE_FIRSTPRIVATE:
03493 name = "firstprivate";
03494 need_complete_non_reference = true;
03495 need_copy_ctor = true;
03496 need_implicitly_determined = true;
03497 break;
03498 case OMP_CLAUSE_LASTPRIVATE:
03499 name = "lastprivate";
03500 need_complete_non_reference = true;
03501 need_copy_assignment = true;
03502 need_implicitly_determined = true;
03503 break;
03504 case OMP_CLAUSE_REDUCTION:
03505 name = "reduction";
03506 need_implicitly_determined = true;
03507 break;
03508 case OMP_CLAUSE_COPYPRIVATE:
03509 name = "copyprivate";
03510 need_copy_assignment = true;
03511 break;
03512 case OMP_CLAUSE_COPYIN:
03513 name = "copyin";
03514 need_copy_assignment = true;
03515 break;
03516 default:
03517 pc = &OMP_CLAUSE_CHAIN (c);
03518 continue;
03519 }
03520
03521 t = OMP_CLAUSE_DECL (c);
03522 if (processing_template_decl
03523 && TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
03524 {
03525 pc = &OMP_CLAUSE_CHAIN (c);
03526 continue;
03527 }
03528
03529 switch (c_kind)
03530 {
03531 case OMP_CLAUSE_LASTPRIVATE:
03532 if (!bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
03533 need_default_ctor = true;
03534 break;
03535
03536 case OMP_CLAUSE_REDUCTION:
03537 if (AGGREGATE_TYPE_P (TREE_TYPE (t))
03538 || POINTER_TYPE_P (TREE_TYPE (t)))
03539 {
03540 error ("%qE has invalid type for %<reduction%>", t);
03541 remove = true;
03542 }
03543 else if (FLOAT_TYPE_P (TREE_TYPE (t)))
03544 {
03545 enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
03546 switch (r_code)
03547 {
03548 case PLUS_EXPR:
03549 case MULT_EXPR:
03550 case MINUS_EXPR:
03551 break;
03552 default:
03553 error ("%qE has invalid type for %<reduction(%s)%>",
03554 t, operator_name_info[r_code].name);
03555 remove = true;
03556 }
03557 }
03558 break;
03559
03560 case OMP_CLAUSE_COPYIN:
03561 if (TREE_CODE (t) != VAR_DECL || !DECL_THREAD_LOCAL_P (t))
03562 {
03563 error ("%qE must be %<threadprivate%> for %<copyin%>", t);
03564 remove = true;
03565 }
03566 break;
03567
03568 default:
03569 break;
03570 }
03571
03572 if (need_complete_non_reference)
03573 {
03574 t = require_complete_type (t);
03575 if (t == error_mark_node)
03576 remove = true;
03577 else if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
03578 {
03579 error ("%qE has reference type for %qs", t, name);
03580 remove = true;
03581 }
03582 }
03583 if (need_implicitly_determined)
03584 {
03585 const char *share_name = NULL;
03586
03587 if (TREE_CODE (t) == VAR_DECL && DECL_THREAD_LOCAL_P (t))
03588 share_name = "threadprivate";
03589 else switch (cxx_omp_predetermined_sharing (t))
03590 {
03591 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
03592 break;
03593 case OMP_CLAUSE_DEFAULT_SHARED:
03594 share_name = "shared";
03595 break;
03596 case OMP_CLAUSE_DEFAULT_PRIVATE:
03597 share_name = "private";
03598 break;
03599 default:
03600 gcc_unreachable ();
03601 }
03602 if (share_name)
03603 {
03604 error ("%qE is predetermined %qs for %qs",
03605 t, share_name, name);
03606 remove = true;
03607 }
03608 }
03609
03610
03611 inner_type = type = TREE_TYPE (t);
03612 while (TREE_CODE (inner_type) == ARRAY_TYPE)
03613 inner_type = TREE_TYPE (inner_type);
03614
03615
03616
03617
03618 if (CLASS_TYPE_P (inner_type)
03619 && (need_default_ctor || need_copy_ctor || need_copy_assignment)
03620 && !type_dependent_expression_p (t))
03621 {
03622 int save_errorcount = errorcount;
03623 tree info;
03624
03625
03626
03627
03628
03629
03630 info = make_tree_vec (3);
03631 CP_OMP_CLAUSE_INFO (c) = info;
03632
03633 if (need_default_ctor
03634 || (need_copy_ctor
03635 && !TYPE_HAS_TRIVIAL_INIT_REF (inner_type)))
03636 {
03637 if (need_default_ctor)
03638 t = NULL;
03639 else
03640 {
03641 t = build_int_cst (build_pointer_type (inner_type), 0);
03642 t = build1 (INDIRECT_REF, inner_type, t);
03643 t = build_tree_list (NULL, t);
03644 }
03645 t = build_special_member_call (NULL_TREE,
03646 complete_ctor_identifier,
03647 t, inner_type, LOOKUP_NORMAL);
03648 t = get_callee_fndecl (t);
03649 TREE_VEC_ELT (info, 0) = t;
03650 }
03651
03652 if ((need_default_ctor || need_copy_ctor)
03653 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (inner_type))
03654 {
03655 t = build_int_cst (build_pointer_type (inner_type), 0);
03656 t = build1 (INDIRECT_REF, inner_type, t);
03657 t = build_special_member_call (t, complete_dtor_identifier,
03658 NULL, inner_type, LOOKUP_NORMAL);
03659 t = get_callee_fndecl (t);
03660 TREE_VEC_ELT (info, 1) = t;
03661 }
03662
03663 if (need_copy_assignment
03664 && !TYPE_HAS_TRIVIAL_ASSIGN_REF (inner_type))
03665 {
03666 t = build_int_cst (build_pointer_type (inner_type), 0);
03667 t = build1 (INDIRECT_REF, inner_type, t);
03668 t = build_special_member_call (t, ansi_assopname (NOP_EXPR),
03669 build_tree_list (NULL, t),
03670 inner_type, LOOKUP_NORMAL);
03671
03672
03673
03674
03675 if (TREE_CODE (t) == INDIRECT_REF)
03676 t = TREE_OPERAND (t, 0);
03677
03678 t = get_callee_fndecl (t);
03679 TREE_VEC_ELT (info, 2) = t;
03680 }
03681
03682 if (errorcount != save_errorcount)
03683 remove = true;
03684 }
03685
03686 if (remove)
03687 *pc = OMP_CLAUSE_CHAIN (c);
03688 else
03689 pc = &OMP_CLAUSE_CHAIN (c);
03690 }
03691
03692 bitmap_obstack_release (NULL);
03693 return clauses;
03694 }
03695
03696
03697
03698 void
03699 finish_omp_threadprivate (tree vars)
03700 {
03701 tree t;
03702
03703
03704 for (t = vars; t; t = TREE_CHAIN (t))
03705 {
03706 tree v = TREE_PURPOSE (t);
03707
03708
03709
03710 if (TREE_USED (v)
03711 && (DECL_LANG_SPECIFIC (v) == NULL
03712 || !CP_DECL_THREADPRIVATE_P (v)))
03713 error ("%qE declared %<threadprivate%> after first use", v);
03714 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
03715 error ("automatic variable %qE cannot be %<threadprivate%>", v);
03716 else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
03717 error ("%<threadprivate%> %qE has incomplete type", v);
03718 else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v)))
03719 error ("%<threadprivate%> %qE is not file, namespace "
03720 "or block scope variable", v);
03721 else
03722 {
03723
03724 if (DECL_LANG_SPECIFIC (v) == NULL)
03725 {
03726 retrofit_lang_decl (v);
03727
03728
03729
03730 if (DECL_DISCRIMINATOR_P (v))
03731 DECL_LANG_SPECIFIC (v)->decl_flags.u2sel = 1;
03732 }
03733
03734 if (! DECL_THREAD_LOCAL_P (v))
03735 {
03736 DECL_TLS_MODEL (v) = decl_default_tls_model (v);
03737
03738
03739
03740 if (DECL_RTL_SET_P (v))
03741 make_decl_rtl (v);
03742 }
03743 CP_DECL_THREADPRIVATE_P (v) = 1;
03744 }
03745 }
03746 }
03747
03748
03749
03750 tree
03751 begin_omp_structured_block (void)
03752 {
03753 return do_pushlevel (sk_omp);
03754 }
03755
03756 tree
03757 finish_omp_structured_block (tree block)
03758 {
03759 return do_poplevel (block);
03760 }
03761
03762
03763
03764 tree
03765 begin_omp_parallel (void)
03766 {
03767 keep_next_level (true);
03768 return begin_omp_structured_block ();
03769 }
03770
03771 tree
03772 finish_omp_parallel (tree clauses, tree body)
03773 {
03774 tree stmt;
03775
03776 body = finish_omp_structured_block (body);
03777
03778 stmt = make_node (OMP_PARALLEL);
03779 TREE_TYPE (stmt) = void_type_node;
03780 OMP_PARALLEL_CLAUSES (stmt) = clauses;
03781 OMP_PARALLEL_BODY (stmt) = body;
03782
03783 return add_stmt (stmt);
03784 }
03785
03786
03787
03788
03789
03790
03791
03792
03793 tree
03794 finish_omp_for (location_t locus, tree decl, tree init, tree cond,
03795 tree incr, tree body, tree pre_body)
03796 {
03797 if (decl == NULL)
03798 {
03799 if (init != NULL)
03800 switch (TREE_CODE (init))
03801 {
03802 case MODIFY_EXPR:
03803 decl = TREE_OPERAND (init, 0);
03804 init = TREE_OPERAND (init, 1);
03805 break;
03806 case MODOP_EXPR:
03807 if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
03808 {
03809 decl = TREE_OPERAND (init, 0);
03810 init = TREE_OPERAND (init, 2);
03811 }
03812 break;
03813 default:
03814 break;
03815 }
03816
03817 if (decl == NULL)
03818 {
03819 error ("expected iteration declaration or initialization");
03820 return NULL;
03821 }
03822 }
03823
03824 if (type_dependent_expression_p (decl)
03825 || type_dependent_expression_p (init)
03826 || (cond && type_dependent_expression_p (cond))
03827 || (incr && type_dependent_expression_p (incr)))
03828 {
03829 tree stmt;
03830
03831 if (cond == NULL)
03832 {
03833 error ("%Hmissing controlling predicate", &locus);
03834 return NULL;
03835 }
03836
03837 if (incr == NULL)
03838 {
03839 error ("%Hmissing increment expression", &locus);
03840 return NULL;
03841 }
03842
03843 stmt = make_node (OMP_FOR);
03844
03845
03846
03847
03848 init = build2 (MODIFY_EXPR, void_type_node, decl, init);
03849
03850 TREE_TYPE (stmt) = void_type_node;
03851 OMP_FOR_INIT (stmt) = init;
03852 OMP_FOR_COND (stmt) = cond;
03853 OMP_FOR_INCR (stmt) = incr;
03854 OMP_FOR_BODY (stmt) = body;
03855 OMP_FOR_PRE_BODY (stmt) = pre_body;
03856
03857 SET_EXPR_LOCATION (stmt, locus);
03858 return add_stmt (stmt);
03859 }
03860
03861 if (!DECL_P (decl))
03862 {
03863 error ("expected iteration declaration or initialization");
03864 return NULL;
03865 }
03866
03867 if (pre_body == NULL || IS_EMPTY_STMT (pre_body))
03868 pre_body = NULL;
03869 else if (! processing_template_decl)
03870 {
03871 add_stmt (pre_body);
03872 pre_body = NULL;
03873 }
03874 init = build_modify_expr (decl, NOP_EXPR, init);
03875 return c_finish_omp_for (locus, decl, init, cond, incr, body, pre_body);
03876 }
03877
03878 void
03879 finish_omp_atomic (enum tree_code code, tree lhs, tree rhs)
03880 {
03881 tree orig_lhs;
03882 tree orig_rhs;
03883 bool dependent_p;
03884 tree stmt;
03885
03886 orig_lhs = lhs;
03887 orig_rhs = rhs;
03888 dependent_p = false;
03889 stmt = NULL_TREE;
03890
03891
03892
03893 if (processing_template_decl)
03894 {
03895 dependent_p = (type_dependent_expression_p (lhs)
03896 || type_dependent_expression_p (rhs));
03897 if (!dependent_p)
03898 {
03899 lhs = build_non_dependent_expr (lhs);
03900 rhs = build_non_dependent_expr (rhs);
03901 }
03902 }
03903 if (!dependent_p)
03904 {
03905 stmt = c_finish_omp_atomic (code, lhs, rhs);
03906 if (stmt == error_mark_node)
03907 return;
03908 }
03909 if (processing_template_decl)
03910 {
03911 stmt = build2 (OMP_ATOMIC, void_type_node, orig_lhs, orig_rhs);
03912 OMP_ATOMIC_DEPENDENT_P (stmt) = 1;
03913 OMP_ATOMIC_CODE (stmt) = code;
03914 }
03915 add_stmt (stmt);
03916 }
03917
03918 void
03919 finish_omp_barrier (void)
03920 {
03921 tree fn = built_in_decls[BUILT_IN_GOMP_BARRIER];
03922 tree stmt = finish_call_expr (fn, NULL, false, false);
03923 finish_expr_stmt (stmt);
03924 }
03925
03926 void
03927 finish_omp_flush (void)
03928 {
03929 tree fn = built_in_decls[BUILT_IN_SYNCHRONIZE];
03930 tree stmt = finish_call_expr (fn, NULL, false, false);
03931 finish_expr_stmt (stmt);
03932 }
03933
03934
03935
03936 enum omp_clause_default_kind
03937 cxx_omp_predetermined_sharing (tree decl)
03938 {
03939 enum omp_clause_default_kind kind;
03940
03941 kind = c_omp_predetermined_sharing (decl);
03942 if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
03943 return kind;
03944
03945
03946 if (TREE_STATIC (decl))
03947 {
03948 tree ctx = CP_DECL_CONTEXT (decl);
03949 if (TYPE_P (ctx) && IS_AGGR_TYPE (ctx))
03950 return OMP_CLAUSE_DEFAULT_SHARED;
03951 }
03952
03953 return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
03954 }
03955
03956 void
03957 init_cp_semantics (void)
03958 {
03959 }
03960
03961 #include "gt-cp-semantics.h"