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 #include "config.h"
00035 #include "system.h"
00036 #include "coretypes.h"
00037 #include "tm.h"
00038 #include "tree.h"
00039 #include "rtl.h"
00040 #include "expr.h"
00041 #include "flags.h"
00042 #include "cp-tree.h"
00043 #include "decl.h"
00044 #include "output.h"
00045 #include "except.h"
00046 #include "toplev.h"
00047 #include "timevar.h"
00048 #include "cpplib.h"
00049 #include "target.h"
00050 #include "c-common.h"
00051 #include "tree-mudflap.h"
00052 #include "cgraph.h"
00053 #include "tree-inline.h"
00054 #include "c-pragma.h"
00055 #include "tree-dump.h"
00056 #include "intl.h"
00057 #ifdef KEY
00058 #include "gspin-gcc-interface.h"
00059 #endif
00060
00061 extern cpp_reader *parse_in;
00062
00063
00064
00065 typedef struct priority_info_s {
00066
00067
00068 int initializations_p;
00069
00070
00071 int destructions_p;
00072 } *priority_info;
00073
00074 static void mark_vtable_entries (tree);
00075 static bool maybe_emit_vtables (tree);
00076 static bool acceptable_java_type (tree);
00077 static tree start_objects (int, int);
00078 static void finish_objects (int, int, tree);
00079 static tree start_static_storage_duration_function (unsigned);
00080 static void finish_static_storage_duration_function (tree);
00081 static priority_info get_priority_info (int);
00082 static void do_static_initialization_or_destruction (tree, bool);
00083 static void one_static_initialization_or_destruction (tree, tree, bool);
00084 static void generate_ctor_or_dtor_function (bool, int, location_t *);
00085 static int generate_ctor_and_dtor_functions_for_priority (splay_tree_node,
00086 void *);
00087 static tree prune_vars_needing_no_initialization (tree *);
00088 static void write_out_vars (tree);
00089 static void import_export_class (tree);
00090 static tree get_guard_bits (tree);
00091 static void determine_visibility_from_class (tree, tree);
00092
00093
00094
00095
00096 static GTY(()) VEC(tree,gc) *pending_statics;
00097
00098
00099
00100 static GTY(()) VEC(tree,gc) *deferred_fns;
00101
00102
00103
00104 int at_eof;
00105
00106
00107
00108 tree static_ctors;
00109 tree static_dtors;
00110
00111
00112
00113
00114
00115
00116
00117 tree
00118 build_memfn_type (tree fntype, tree ctype, cp_cv_quals quals)
00119 {
00120 tree raises;
00121 int type_quals;
00122
00123 if (fntype == error_mark_node || ctype == error_mark_node)
00124 return error_mark_node;
00125
00126 type_quals = quals & ~TYPE_QUAL_RESTRICT;
00127 ctype = cp_build_qualified_type (ctype, type_quals);
00128 fntype = build_method_type_directly (ctype, TREE_TYPE (fntype),
00129 (TREE_CODE (fntype) == METHOD_TYPE
00130 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
00131 : TYPE_ARG_TYPES (fntype)));
00132 raises = TYPE_RAISES_EXCEPTIONS (fntype);
00133 if (raises)
00134 fntype = build_exception_variant (fntype, raises);
00135
00136 return fntype;
00137 }
00138
00139
00140
00141
00142 tree
00143 cp_build_parm_decl (tree name, tree type)
00144 {
00145 tree parm = build_decl (PARM_DECL, name, type);
00146
00147
00148 if (!processing_template_decl)
00149 DECL_ARG_TYPE (parm) = type_passed_as (type);
00150 return parm;
00151 }
00152
00153
00154
00155
00156 tree
00157 build_artificial_parm (tree name, tree type)
00158 {
00159 tree parm = cp_build_parm_decl (name, type);
00160 DECL_ARTIFICIAL (parm) = 1;
00161
00162
00163 TREE_READONLY (parm) = 1;
00164 return parm;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 void
00181 maybe_retrofit_in_chrg (tree fn)
00182 {
00183 tree basetype, arg_types, parms, parm, fntype;
00184
00185
00186 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
00187 return;
00188
00189
00190
00191 if (processing_template_decl)
00192 return;
00193
00194
00195
00196 if (DECL_CONSTRUCTOR_P (fn)
00197 && !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
00198 return;
00199
00200 arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
00201 basetype = TREE_TYPE (TREE_VALUE (arg_types));
00202 arg_types = TREE_CHAIN (arg_types);
00203
00204 parms = TREE_CHAIN (DECL_ARGUMENTS (fn));
00205
00206
00207
00208 if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
00209 {
00210 parm = build_artificial_parm (vtt_parm_identifier, vtt_parm_type);
00211
00212
00213 TREE_CHAIN (parm) = parms;
00214 parms = parm;
00215
00216
00217 arg_types = hash_tree_chain (vtt_parm_type, arg_types);
00218
00219 DECL_HAS_VTT_PARM_P (fn) = 1;
00220 }
00221
00222
00223 parm = build_artificial_parm (in_charge_identifier, integer_type_node);
00224 TREE_CHAIN (parm) = parms;
00225 parms = parm;
00226 arg_types = hash_tree_chain (integer_type_node, arg_types);
00227
00228
00229 TREE_CHAIN (DECL_ARGUMENTS (fn)) = parms;
00230
00231
00232 fntype = build_method_type_directly (basetype, TREE_TYPE (TREE_TYPE (fn)),
00233 arg_types);
00234 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
00235 fntype = build_exception_variant (fntype,
00236 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)));
00237 TREE_TYPE (fn) = fntype;
00238
00239
00240 DECL_HAS_IN_CHARGE_PARM_P (fn) = 1;
00241 }
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 void
00264 grokclassfn (tree ctype, tree function, enum overload_flags flags)
00265 {
00266 tree fn_name = DECL_NAME (function);
00267
00268
00269
00270 SET_DECL_LANGUAGE (function, lang_cplusplus);
00271
00272 if (fn_name == NULL_TREE)
00273 {
00274 error ("name missing for member function");
00275 fn_name = get_identifier ("<anonymous>");
00276 DECL_NAME (function) = fn_name;
00277 }
00278
00279 DECL_CONTEXT (function) = ctype;
00280
00281 if (flags == DTOR_FLAG)
00282 DECL_DESTRUCTOR_P (function) = 1;
00283
00284 if (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))
00285 maybe_retrofit_in_chrg (function);
00286 }
00287
00288
00289
00290
00291 tree
00292 grok_array_decl (tree array_expr, tree index_exp)
00293 {
00294 tree type;
00295 tree expr;
00296 tree orig_array_expr = array_expr;
00297 tree orig_index_exp = index_exp;
00298
00299 if (error_operand_p (array_expr) || error_operand_p (index_exp))
00300 return error_mark_node;
00301
00302 if (processing_template_decl)
00303 {
00304 if (type_dependent_expression_p (array_expr)
00305 || type_dependent_expression_p (index_exp))
00306 return build_min_nt (ARRAY_REF, array_expr, index_exp,
00307 NULL_TREE, NULL_TREE);
00308 array_expr = build_non_dependent_expr (array_expr);
00309 index_exp = build_non_dependent_expr (index_exp);
00310 }
00311
00312 type = TREE_TYPE (array_expr);
00313 gcc_assert (type);
00314 type = non_reference (type);
00315
00316
00317 if (IS_AGGR_TYPE (type) || IS_AGGR_TYPE (TREE_TYPE (index_exp)))
00318 expr = build_new_op (ARRAY_REF, LOOKUP_NORMAL,
00319 array_expr, index_exp, NULL_TREE,
00320 NULL);
00321 else
00322 {
00323 tree p1, p2, i1, i2;
00324
00325
00326
00327
00328
00329 if (TREE_CODE (type) == ARRAY_TYPE)
00330 p1 = array_expr;
00331 else
00332 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, false);
00333
00334 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
00335 p2 = index_exp;
00336 else
00337 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, false);
00338
00339 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr,
00340 false);
00341 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp,
00342 false);
00343
00344 if ((p1 && i2) && (i1 && p2))
00345 error ("ambiguous conversion for array subscript");
00346
00347 if (p1 && i2)
00348 array_expr = p1, index_exp = i2;
00349 else if (i1 && p2)
00350 array_expr = p2, index_exp = i1;
00351 else
00352 {
00353 error ("invalid types %<%T[%T]%> for array subscript",
00354 type, TREE_TYPE (index_exp));
00355 return error_mark_node;
00356 }
00357
00358 if (array_expr == error_mark_node || index_exp == error_mark_node)
00359 error ("ambiguous conversion for array subscript");
00360
00361 expr = build_array_ref (array_expr, index_exp);
00362 }
00363 if (processing_template_decl && expr != error_mark_node)
00364 return build_min_non_dep (ARRAY_REF, expr, orig_array_expr, orig_index_exp,
00365 NULL_TREE, NULL_TREE);
00366 return expr;
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376 tree
00377 delete_sanity (tree exp, tree size, bool doing_vec, int use_global_delete)
00378 {
00379 tree t, type;
00380
00381 if (exp == error_mark_node)
00382 return exp;
00383
00384 if (processing_template_decl)
00385 {
00386 t = build_min (DELETE_EXPR, void_type_node, exp, size);
00387 DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
00388 DELETE_EXPR_USE_VEC (t) = doing_vec;
00389 TREE_SIDE_EFFECTS (t) = 1;
00390 return t;
00391 }
00392
00393
00394 if (TREE_CODE (exp) == VAR_DECL
00395 && TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
00396 warning (0, "deleting array %q#D", exp);
00397
00398 t = build_expr_type_conversion (WANT_POINTER, exp, true);
00399
00400 if (t == NULL_TREE || t == error_mark_node)
00401 {
00402 error ("type %q#T argument given to %<delete%>, expected pointer",
00403 TREE_TYPE (exp));
00404 return error_mark_node;
00405 }
00406
00407 type = TREE_TYPE (t);
00408
00409
00410
00411
00412 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
00413 {
00414 error ("cannot delete a function. Only pointer-to-objects are "
00415 "valid arguments to %<delete%>");
00416 return error_mark_node;
00417 }
00418
00419
00420 if (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE)
00421 {
00422 warning (0, "deleting %qT is undefined", type);
00423 doing_vec = 0;
00424 }
00425
00426
00427 if (integer_zerop (t))
00428 return build1 (NOP_EXPR, void_type_node, t);
00429
00430 if (doing_vec)
00431 return build_vec_delete (t, NULL_TREE,
00432 sfk_deleting_destructor,
00433 use_global_delete);
00434 else
00435 return build_delete (type, t, sfk_deleting_destructor,
00436 LOOKUP_NORMAL, use_global_delete);
00437 }
00438
00439
00440
00441
00442 void
00443 check_member_template (tree tmpl)
00444 {
00445 tree decl;
00446
00447 gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL);
00448 decl = DECL_TEMPLATE_RESULT (tmpl);
00449
00450 if (TREE_CODE (decl) == FUNCTION_DECL
00451 || (TREE_CODE (decl) == TYPE_DECL
00452 && IS_AGGR_TYPE (TREE_TYPE (decl))))
00453 {
00454
00455 gcc_assert (!current_function_decl);
00456
00457 gcc_assert (!(TREE_CODE (decl) == FUNCTION_DECL
00458 && DECL_VIRTUAL_P (decl)));
00459
00460
00461
00462 DECL_IGNORED_P (tmpl) = 1;
00463 }
00464 else
00465 error ("template declaration of %q#D", decl);
00466 }
00467
00468
00469
00470 static bool
00471 acceptable_java_type (tree type)
00472 {
00473 if (type == error_mark_node)
00474 return false;
00475
00476 if (TREE_CODE (type) == VOID_TYPE || TYPE_FOR_JAVA (type))
00477 return true;
00478 if (TREE_CODE (type) == POINTER_TYPE || TREE_CODE (type) == REFERENCE_TYPE)
00479 {
00480 type = TREE_TYPE (type);
00481 if (TREE_CODE (type) == RECORD_TYPE)
00482 {
00483 tree args; int i;
00484 if (! TYPE_FOR_JAVA (type))
00485 return false;
00486 if (! CLASSTYPE_TEMPLATE_INFO (type))
00487 return true;
00488 args = CLASSTYPE_TI_ARGS (type);
00489 i = TREE_VEC_LENGTH (args);
00490 while (--i >= 0)
00491 {
00492 type = TREE_VEC_ELT (args, i);
00493 if (TREE_CODE (type) == POINTER_TYPE)
00494 type = TREE_TYPE (type);
00495 if (! TYPE_FOR_JAVA (type))
00496 return false;
00497 }
00498 return true;
00499 }
00500 }
00501 return false;
00502 }
00503
00504
00505
00506
00507
00508 bool
00509 check_java_method (tree method)
00510 {
00511 bool jerr = false;
00512 tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
00513 tree ret_type = TREE_TYPE (TREE_TYPE (method));
00514
00515 if (!acceptable_java_type (ret_type))
00516 {
00517 error ("Java method %qD has non-Java return type %qT",
00518 method, ret_type);
00519 jerr = true;
00520 }
00521
00522 arg_types = TREE_CHAIN (arg_types);
00523 if (DECL_HAS_IN_CHARGE_PARM_P (method))
00524 arg_types = TREE_CHAIN (arg_types);
00525 if (DECL_HAS_VTT_PARM_P (method))
00526 arg_types = TREE_CHAIN (arg_types);
00527
00528 for (; arg_types != NULL_TREE; arg_types = TREE_CHAIN (arg_types))
00529 {
00530 tree type = TREE_VALUE (arg_types);
00531 if (!acceptable_java_type (type))
00532 {
00533 if (type != error_mark_node)
00534 error ("Java method %qD has non-Java parameter type %qT",
00535 method, type);
00536 jerr = true;
00537 }
00538 }
00539 return !jerr;
00540 }
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 tree
00553 check_classfn (tree ctype, tree function, tree template_parms)
00554 {
00555 int ix;
00556 bool is_template;
00557 tree pushed_scope;
00558
00559 if (DECL_USE_TEMPLATE (function)
00560 && !(TREE_CODE (function) == TEMPLATE_DECL
00561 && DECL_TEMPLATE_SPECIALIZATION (function))
00562 && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (function)))
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573 return NULL_TREE;
00574
00575
00576
00577 if (TREE_CODE (function) == TEMPLATE_DECL)
00578 {
00579 gcc_assert (!template_parms
00580 || comp_template_parms (template_parms,
00581 DECL_TEMPLATE_PARMS (function)));
00582 template_parms = DECL_TEMPLATE_PARMS (function);
00583 }
00584
00585
00586 is_template = (template_parms != NULL_TREE);
00587
00588
00589
00590
00591 pushed_scope = push_scope (ctype);
00592 ix = class_method_index_for_fn (complete_type (ctype), function);
00593 if (ix >= 0)
00594 {
00595 VEC(tree,gc) *methods = CLASSTYPE_METHOD_VEC (ctype);
00596 tree fndecls, fndecl = 0;
00597 bool is_conv_op;
00598 const char *format = NULL;
00599
00600 for (fndecls = VEC_index (tree, methods, ix);
00601 fndecls; fndecls = OVL_NEXT (fndecls))
00602 {
00603 tree p1, p2;
00604
00605 fndecl = OVL_CURRENT (fndecls);
00606 p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
00607 p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
00608
00609
00610
00611
00612
00613
00614
00615
00616 if (DECL_STATIC_FUNCTION_P (fndecl)
00617 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
00618 p1 = TREE_CHAIN (p1);
00619
00620
00621
00622 if (is_template != (TREE_CODE (fndecl) == TEMPLATE_DECL))
00623 continue;
00624
00625 if (same_type_p (TREE_TYPE (TREE_TYPE (function)),
00626 TREE_TYPE (TREE_TYPE (fndecl)))
00627 && compparms (p1, p2)
00628 && (!is_template
00629 || comp_template_parms (template_parms,
00630 DECL_TEMPLATE_PARMS (fndecl)))
00631 && (DECL_TEMPLATE_SPECIALIZATION (function)
00632 == DECL_TEMPLATE_SPECIALIZATION (fndecl))
00633 && (!DECL_TEMPLATE_SPECIALIZATION (function)
00634 || (DECL_TI_TEMPLATE (function)
00635 == DECL_TI_TEMPLATE (fndecl))))
00636 break;
00637 }
00638 if (fndecls)
00639 {
00640 if (pushed_scope)
00641 pop_scope (pushed_scope);
00642 return OVL_CURRENT (fndecls);
00643 }
00644
00645 error ("prototype for %q#D does not match any in class %qT",
00646 function, ctype);
00647 is_conv_op = DECL_CONV_FN_P (fndecl);
00648
00649 if (is_conv_op)
00650 ix = CLASSTYPE_FIRST_CONVERSION_SLOT;
00651 fndecls = VEC_index (tree, methods, ix);
00652 while (fndecls)
00653 {
00654 fndecl = OVL_CURRENT (fndecls);
00655 fndecls = OVL_NEXT (fndecls);
00656
00657 if (!fndecls && is_conv_op)
00658 {
00659 if (VEC_length (tree, methods) > (size_t) ++ix)
00660 {
00661 fndecls = VEC_index (tree, methods, ix);
00662 if (!DECL_CONV_FN_P (OVL_CURRENT (fndecls)))
00663 {
00664 fndecls = NULL_TREE;
00665 is_conv_op = false;
00666 }
00667 }
00668 else
00669 is_conv_op = false;
00670 }
00671 if (format)
00672 format = " %+#D";
00673 else if (fndecls)
00674 format = N_("candidates are: %+#D");
00675 else
00676 format = N_("candidate is: %+#D");
00677 error (format, fndecl);
00678 }
00679 }
00680 else if (!COMPLETE_TYPE_P (ctype))
00681 cxx_incomplete_type_error (function, ctype);
00682 else
00683 error ("no %q#D member function declared in class %qT",
00684 function, ctype);
00685
00686
00687
00688
00689
00690 if (COMPLETE_TYPE_P (ctype))
00691 add_method (ctype, function, NULL_TREE);
00692
00693 if (pushed_scope)
00694 pop_scope (pushed_scope);
00695 return NULL_TREE;
00696 }
00697
00698
00699
00700
00701
00702 void
00703 note_vague_linkage_fn (tree decl)
00704 {
00705 if (!DECL_DEFERRED_FN (decl))
00706 {
00707 DECL_DEFERRED_FN (decl) = 1;
00708 DECL_DEFER_OUTPUT (decl) = 1;
00709 VEC_safe_push (tree, gc, deferred_fns, decl);
00710 }
00711 }
00712
00713
00714
00715
00716 void
00717 finish_static_data_member_decl (tree decl,
00718 tree init, bool init_const_expr_p,
00719 tree asmspec_tree,
00720 int flags)
00721 {
00722 DECL_CONTEXT (decl) = current_class_type;
00723
00724
00725
00726
00727
00728 if (! processing_template_decl)
00729 VEC_safe_push (tree, gc, pending_statics, decl);
00730
00731 if (LOCAL_CLASS_P (current_class_type))
00732 pedwarn ("local class %q#T shall not have static data member %q#D",
00733 current_class_type, decl);
00734
00735
00736 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
00737 {
00738 static int explained = 0;
00739
00740 error ("initializer invalid for static member with constructor");
00741 if (!explained)
00742 {
00743 error ("(an out of class initialization is required)");
00744 explained = 1;
00745 }
00746 init = NULL_TREE;
00747 }
00748
00749
00750 if (CP_TYPE_CONST_P (TREE_TYPE (decl)) && init == 0)
00751 TREE_USED (decl) = 1;
00752 DECL_INITIAL (decl) = init;
00753 DECL_IN_AGGR_P (decl) = 1;
00754
00755 cp_finish_decl (decl, init, init_const_expr_p, asmspec_tree, flags);
00756 }
00757
00758
00759
00760
00761
00762 tree
00763 grokfield (const cp_declarator *declarator,
00764 cp_decl_specifier_seq *declspecs,
00765 tree init, bool init_const_expr_p,
00766 tree asmspec_tree,
00767 tree attrlist)
00768 {
00769 tree value;
00770 const char *asmspec = 0;
00771 int flags = LOOKUP_ONLYCONVERTING;
00772
00773 if (init
00774 && TREE_CODE (init) == TREE_LIST
00775 && TREE_VALUE (init) == error_mark_node
00776 && TREE_CHAIN (init) == NULL_TREE)
00777 init = NULL_TREE;
00778
00779 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, &attrlist);
00780 if (! value || error_operand_p (value))
00781
00782 return error_mark_node;
00783
00784 if (TREE_CODE (value) == TYPE_DECL && init)
00785 {
00786 error ("typedef %qD is initialized (use __typeof__ instead)", value);
00787 init = NULL_TREE;
00788 }
00789
00790
00791 if (value == void_type_node)
00792 return value;
00793
00794
00795 if ((TREE_CODE (value) == FUNCTION_DECL
00796 || TREE_CODE (value) == TEMPLATE_DECL)
00797 && DECL_CONTEXT (value) != current_class_type)
00798 return value;
00799
00800 if (DECL_NAME (value) != NULL_TREE
00801 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
00802 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
00803 error ("member %qD conflicts with virtual function table field name",
00804 value);
00805
00806
00807 if (TREE_CODE (value) == TYPE_DECL)
00808 {
00809 DECL_NONLOCAL (value) = 1;
00810 DECL_CONTEXT (value) = current_class_type;
00811
00812 if (processing_template_decl)
00813 value = push_template_decl (value);
00814
00815 if (attrlist)
00816 {
00817
00818
00819 tree type = TREE_TYPE (value);
00820 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
00821 || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
00822 sorry ("applying attributes to template parameters is not implemented");
00823 else
00824 cplus_decl_attributes (&value, attrlist, 0);
00825 }
00826
00827 return value;
00828 }
00829
00830 if (DECL_IN_AGGR_P (value))
00831 {
00832 error ("%qD is already defined in %qT", value, DECL_CONTEXT (value));
00833 return void_type_node;
00834 }
00835
00836 if (asmspec_tree && asmspec_tree != error_mark_node)
00837 asmspec = TREE_STRING_POINTER (asmspec_tree);
00838
00839 if (init)
00840 {
00841 if (TREE_CODE (value) == FUNCTION_DECL)
00842 {
00843
00844
00845 if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
00846 {
00847 gcc_assert (error_operand_p (init) || integer_zerop (init));
00848 DECL_PURE_VIRTUAL_P (value) = 1;
00849 }
00850 else
00851 {
00852 gcc_assert (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE);
00853 error ("initializer specified for static member function %qD",
00854 value);
00855 }
00856 }
00857 else if (pedantic && TREE_CODE (value) != VAR_DECL)
00858
00859 init = NULL_TREE;
00860 else if (!processing_template_decl)
00861 {
00862 if (TREE_CODE (init) == CONSTRUCTOR)
00863 init = digest_init (TREE_TYPE (value), init);
00864 else
00865 init = integral_constant_value (init);
00866
00867 if (init != error_mark_node && !TREE_CONSTANT (init))
00868 {
00869
00870
00871
00872 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
00873 || (TREE_STATIC (init) == 0
00874 && (!DECL_P (init) || DECL_EXTERNAL (init) == 0)))
00875 {
00876 error ("field initializer is not constant");
00877 init = error_mark_node;
00878 }
00879 }
00880 }
00881 }
00882
00883 if (processing_template_decl
00884 && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL))
00885 {
00886 value = push_template_decl (value);
00887 if (error_operand_p (value))
00888 return error_mark_node;
00889 }
00890
00891 if (attrlist)
00892 cplus_decl_attributes (&value, attrlist, 0);
00893
00894 switch (TREE_CODE (value))
00895 {
00896 case VAR_DECL:
00897 finish_static_data_member_decl (value, init, init_const_expr_p,
00898 asmspec_tree, flags);
00899 return value;
00900
00901 case FIELD_DECL:
00902 if (asmspec)
00903 error ("%<asm%> specifiers are not permitted on non-static data members");
00904 if (DECL_INITIAL (value) == error_mark_node)
00905 init = error_mark_node;
00906 cp_finish_decl (value, init, false,
00907 NULL_TREE, flags);
00908 DECL_INITIAL (value) = init;
00909 DECL_IN_AGGR_P (value) = 1;
00910 return value;
00911
00912 case FUNCTION_DECL:
00913 if (asmspec)
00914 set_user_assembler_name (value, asmspec);
00915
00916 cp_finish_decl (value,
00917 NULL_TREE,
00918 false,
00919 asmspec_tree, flags);
00920
00921
00922 if (DECL_FRIEND_P (value))
00923 return void_type_node;
00924
00925 DECL_IN_AGGR_P (value) = 1;
00926 return value;
00927
00928 default:
00929 gcc_unreachable ();
00930 }
00931 return NULL_TREE;
00932 }
00933
00934
00935
00936
00937 tree
00938 grokbitfield (const cp_declarator *declarator,
00939 cp_decl_specifier_seq *declspecs, tree width)
00940 {
00941 tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL);
00942
00943 if (value == error_mark_node)
00944 return NULL_TREE;
00945
00946
00947 if (TREE_CODE (value) == VOID_TYPE)
00948 return void_type_node;
00949
00950 if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
00951 && (POINTER_TYPE_P (value)
00952 || !dependent_type_p (TREE_TYPE (value))))
00953 {
00954 error ("bit-field %qD with non-integral type", value);
00955 return error_mark_node;
00956 }
00957
00958 if (TREE_CODE (value) == TYPE_DECL)
00959 {
00960 error ("cannot declare %qD to be a bit-field type", value);
00961 return NULL_TREE;
00962 }
00963
00964
00965
00966
00967
00968 if (TREE_CODE (value) == FUNCTION_DECL)
00969 {
00970 error ("cannot declare bit-field %qD with function type",
00971 DECL_NAME (value));
00972 return NULL_TREE;
00973 }
00974
00975 if (DECL_IN_AGGR_P (value))
00976 {
00977 error ("%qD is already defined in the class %qT", value,
00978 DECL_CONTEXT (value));
00979 return void_type_node;
00980 }
00981
00982 if (TREE_STATIC (value))
00983 {
00984 error ("static member %qD cannot be a bit-field", value);
00985 return NULL_TREE;
00986 }
00987 finish_decl (value, NULL_TREE, NULL_TREE);
00988
00989 if (width != error_mark_node)
00990 {
00991 constant_expression_warning (width);
00992 DECL_INITIAL (value) = width;
00993 SET_DECL_C_BIT_FIELD (value);
00994 }
00995
00996 DECL_IN_AGGR_P (value) = 1;
00997 return value;
00998 }
00999
01000
01001 void
01002 cplus_decl_attributes (tree *decl, tree attributes, int flags)
01003 {
01004 if (*decl == NULL_TREE || *decl == void_type_node
01005 || *decl == error_mark_node)
01006 return;
01007
01008 if (TREE_CODE (*decl) == TEMPLATE_DECL)
01009 decl = &DECL_TEMPLATE_RESULT (*decl);
01010
01011 decl_attributes (decl, attributes, flags);
01012
01013 if (TREE_CODE (*decl) == TYPE_DECL)
01014 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (*decl), TREE_TYPE (*decl));
01015 }
01016
01017
01018
01019
01020
01021 static tree
01022 build_anon_union_vars (tree type, tree object)
01023 {
01024 tree main_decl = NULL_TREE;
01025 tree field;
01026
01027
01028
01029 if (TREE_CODE (type) != UNION_TYPE)
01030 error ("anonymous struct not inside named type");
01031
01032 for (field = TYPE_FIELDS (type);
01033 field != NULL_TREE;
01034 field = TREE_CHAIN (field))
01035 {
01036 tree decl;
01037 tree ref;
01038
01039 if (DECL_ARTIFICIAL (field))
01040 continue;
01041 if (TREE_CODE (field) != FIELD_DECL)
01042 {
01043 pedwarn ("%q+#D invalid; an anonymous union can only "
01044 "have non-static data members", field);
01045 continue;
01046 }
01047
01048 if (TREE_PRIVATE (field))
01049 pedwarn ("private member %q+#D in anonymous union", field);
01050 else if (TREE_PROTECTED (field))
01051 pedwarn ("protected member %q+#D in anonymous union", field);
01052
01053 if (processing_template_decl)
01054 ref = build_min_nt (COMPONENT_REF, object,
01055 DECL_NAME (field), NULL_TREE);
01056 else
01057 ref = build_class_member_access_expr (object, field, NULL_TREE,
01058 false);
01059
01060 if (DECL_NAME (field))
01061 {
01062 tree base;
01063
01064 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
01065
01066 base = get_base_address (object);
01067 TREE_PUBLIC (decl) = TREE_PUBLIC (base);
01068 TREE_STATIC (decl) = TREE_STATIC (base);
01069 DECL_EXTERNAL (decl) = DECL_EXTERNAL (base);
01070
01071 SET_DECL_VALUE_EXPR (decl, ref);
01072 DECL_HAS_VALUE_EXPR_P (decl) = 1;
01073
01074 decl = pushdecl (decl);
01075 }
01076 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
01077 decl = build_anon_union_vars (TREE_TYPE (field), ref);
01078 else
01079 decl = 0;
01080
01081 if (main_decl == NULL_TREE)
01082 main_decl = decl;
01083 }
01084
01085 return main_decl;
01086 }
01087
01088
01089
01090
01091
01092 void
01093 finish_anon_union (tree anon_union_decl)
01094 {
01095 tree type;
01096 tree main_decl;
01097 bool public_p;
01098
01099 if (anon_union_decl == error_mark_node)
01100 return;
01101
01102 type = TREE_TYPE (anon_union_decl);
01103 public_p = TREE_PUBLIC (anon_union_decl);
01104
01105
01106 DECL_CONTEXT (anon_union_decl) = DECL_CONTEXT (TYPE_NAME (type));
01107
01108 if (TYPE_FIELDS (type) == NULL_TREE)
01109 return;
01110
01111 if (public_p)
01112 {
01113 error ("namespace-scope anonymous aggregates must be static");
01114 return;
01115 }
01116
01117 main_decl = build_anon_union_vars (type, anon_union_decl);
01118 if (main_decl == error_mark_node)
01119 return;
01120 if (main_decl == NULL_TREE)
01121 {
01122 warning (0, "anonymous union with no members");
01123 return;
01124 }
01125
01126 if (!processing_template_decl)
01127 {
01128
01129 DECL_NAME (anon_union_decl) = DECL_NAME (main_decl);
01130 mangle_decl (anon_union_decl);
01131 DECL_NAME (anon_union_decl) = NULL_TREE;
01132 }
01133
01134 pushdecl (anon_union_decl);
01135 if (building_stmt_tree ()
01136 && at_function_scope_p ())
01137 add_decl_expr (anon_union_decl);
01138 else if (!processing_template_decl)
01139 rest_of_decl_compilation (anon_union_decl,
01140 toplevel_bindings_p (), at_eof);
01141 }
01142
01143
01144
01145
01146
01147 tree
01148 coerce_new_type (tree type)
01149 {
01150 int e = 0;
01151 tree args = TYPE_ARG_TYPES (type);
01152
01153 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
01154
01155 if (!same_type_p (TREE_TYPE (type), ptr_type_node))
01156 {
01157 e = 1;
01158 error ("%<operator new%> must return type %qT", ptr_type_node);
01159 }
01160
01161 if (!args || args == void_list_node
01162 || !same_type_p (TREE_VALUE (args), size_type_node))
01163 {
01164 e = 2;
01165 if (args && args != void_list_node)
01166 args = TREE_CHAIN (args);
01167 pedwarn ("%<operator new%> takes type %<size_t%> (%qT) "
01168 "as first parameter", size_type_node);
01169 }
01170 switch (e)
01171 {
01172 case 2:
01173 args = tree_cons (NULL_TREE, size_type_node, args);
01174
01175 case 1:
01176 type = build_exception_variant
01177 (build_function_type (ptr_type_node, args),
01178 TYPE_RAISES_EXCEPTIONS (type));
01179
01180 default:;
01181 }
01182 return type;
01183 }
01184
01185 tree
01186 coerce_delete_type (tree type)
01187 {
01188 int e = 0;
01189 tree args = TYPE_ARG_TYPES (type);
01190
01191 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
01192
01193 if (!same_type_p (TREE_TYPE (type), void_type_node))
01194 {
01195 e = 1;
01196 error ("%<operator delete%> must return type %qT", void_type_node);
01197 }
01198
01199 if (!args || args == void_list_node
01200 || !same_type_p (TREE_VALUE (args), ptr_type_node))
01201 {
01202 e = 2;
01203 if (args && args != void_list_node)
01204 args = TREE_CHAIN (args);
01205 error ("%<operator delete%> takes type %qT as first parameter",
01206 ptr_type_node);
01207 }
01208 switch (e)
01209 {
01210 case 2:
01211 args = tree_cons (NULL_TREE, ptr_type_node, args);
01212
01213 case 1:
01214 type = build_exception_variant
01215 (build_function_type (void_type_node, args),
01216 TYPE_RAISES_EXCEPTIONS (type));
01217
01218 default:;
01219 }
01220
01221 return type;
01222 }
01223
01224 static void
01225 mark_vtable_entries (tree decl)
01226 {
01227 tree fnaddr;
01228 unsigned HOST_WIDE_INT idx;
01229
01230 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)),
01231 idx, fnaddr)
01232 {
01233 tree fn;
01234
01235 STRIP_NOPS (fnaddr);
01236
01237 if (TREE_CODE (fnaddr) != ADDR_EXPR
01238 && TREE_CODE (fnaddr) != FDESC_EXPR)
01239
01240
01241 continue;
01242
01243 fn = TREE_OPERAND (fnaddr, 0);
01244 TREE_ADDRESSABLE (fn) = 1;
01245
01246
01247
01248
01249 if (DECL_THUNK_P (fn))
01250 use_thunk (fn, 0);
01251 mark_used (fn);
01252 }
01253 }
01254
01255
01256
01257
01258 void
01259 comdat_linkage (tree decl)
01260 {
01261 if (flag_weak)
01262 make_decl_one_only (decl);
01263 else if (TREE_CODE (decl) == FUNCTION_DECL
01264 || (TREE_CODE (decl) == VAR_DECL && DECL_ARTIFICIAL (decl)))
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281 TREE_PUBLIC (decl) = 0;
01282 else
01283 {
01284
01285
01286 if (DECL_INITIAL (decl) == 0
01287 || DECL_INITIAL (decl) == error_mark_node)
01288 DECL_COMMON (decl) = 1;
01289 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
01290 {
01291 DECL_COMMON (decl) = 1;
01292 DECL_INITIAL (decl) = error_mark_node;
01293 }
01294 else if (!DECL_EXPLICIT_INSTANTIATION (decl))
01295 {
01296
01297
01298 DECL_EXTERNAL (decl) = 1;
01299 DECL_NOT_REALLY_EXTERN (decl) = 0;
01300 }
01301 }
01302
01303 if (DECL_LANG_SPECIFIC (decl))
01304 DECL_COMDAT (decl) = 1;
01305 }
01306
01307
01308
01309
01310
01311
01312
01313 void
01314 maybe_make_one_only (tree decl)
01315 {
01316
01317
01318
01319
01320
01321
01322 if (! flag_weak)
01323 return;
01324
01325
01326
01327
01328
01329
01330 if (!TARGET_WEAK_NOT_IN_ARCHIVE_TOC
01331 || (! DECL_EXPLICIT_INSTANTIATION (decl)
01332 && ! DECL_TEMPLATE_SPECIALIZATION (decl)))
01333 {
01334 make_decl_one_only (decl);
01335
01336 if (TREE_CODE (decl) == VAR_DECL)
01337 {
01338 DECL_COMDAT (decl) = 1;
01339
01340 mark_decl_referenced (decl);
01341 }
01342 }
01343 }
01344
01345
01346
01347
01348 static void
01349 import_export_class (tree ctype)
01350 {
01351
01352 int import_export = 0;
01353
01354
01355
01356
01357
01358
01359 gcc_assert (at_eof);
01360
01361 if (CLASSTYPE_INTERFACE_KNOWN (ctype))
01362 return;
01363
01364
01365
01366
01367
01368
01369 if (CLASSTYPE_INTERFACE_ONLY (ctype))
01370 return;
01371
01372 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype)))
01373 import_export = -1;
01374 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype)))
01375 import_export = 1;
01376 else if (CLASSTYPE_IMPLICIT_INSTANTIATION (ctype)
01377 && !flag_implicit_templates)
01378
01379
01380
01381
01382 import_export = repo_export_class_p (ctype) ? 1 : -1;
01383 else if (TYPE_POLYMORPHIC_P (ctype))
01384 {
01385
01386
01387 tree method = CLASSTYPE_KEY_METHOD (ctype);
01388
01389
01390
01391
01392
01393
01394 if (method && (flag_weak || ! DECL_DECLARED_INLINE_P (method)))
01395 import_export = (DECL_REALLY_EXTERN (method) ? -1 : 1);
01396 }
01397
01398
01399
01400 if (MULTIPLE_SYMBOL_SPACES && import_export == -1)
01401 import_export = 0;
01402
01403
01404 if (targetm.cxx.import_export_class)
01405 import_export = targetm.cxx.import_export_class (ctype, import_export);
01406
01407 if (import_export)
01408 {
01409 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
01410 CLASSTYPE_INTERFACE_ONLY (ctype) = (import_export < 0);
01411 }
01412 }
01413
01414
01415
01416 static bool
01417 var_finalized_p (tree var)
01418 {
01419 return cgraph_varpool_node (var)->finalized;
01420 }
01421
01422
01423
01424
01425 void
01426 mark_needed (tree decl)
01427 {
01428
01429
01430
01431 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) = 1;
01432 mark_decl_referenced (decl);
01433 }
01434
01435
01436
01437
01438
01439
01440
01441 bool
01442 decl_needed_p (tree decl)
01443 {
01444 gcc_assert (TREE_CODE (decl) == VAR_DECL
01445 || TREE_CODE (decl) == FUNCTION_DECL);
01446
01447
01448
01449 gcc_assert (at_eof);
01450
01451
01452
01453 if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
01454 return true;
01455
01456
01457 if (TREE_USED (decl)
01458 || (DECL_ASSEMBLER_NAME_SET_P (decl)
01459 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
01460 return true;
01461
01462
01463 return false;
01464 }
01465
01466 #ifdef KEY
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482 bool
01483 decl_maybe_needed_p (tree decl)
01484 {
01485 gcc_assert (TREE_CODE (decl) == VAR_DECL
01486 || TREE_CODE (decl) == FUNCTION_DECL);
01487
01488
01489
01490 gcc_assert (at_eof);
01491
01492
01493
01494 if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
01495 return true;
01496
01497
01498 if (TREE_USED (decl)
01499 || (DECL_ASSEMBLER_NAME_SET_P (decl)
01500 ))
01501 return true;
01502
01503
01504 return false;
01505 }
01506 #endif
01507
01508
01509
01510
01511 static bool
01512 maybe_emit_vtables (tree ctype)
01513 {
01514 tree vtbl;
01515 tree primary_vtbl;
01516 int needed = 0;
01517
01518
01519
01520 primary_vtbl = CLASSTYPE_VTABLES (ctype);
01521 if (var_finalized_p (primary_vtbl))
01522 return false;
01523
01524 if (TREE_TYPE (primary_vtbl) == void_type_node)
01525 return false;
01526
01527
01528
01529
01530 if (!targetm.cxx.key_method_may_be_inline ())
01531 determine_key_method (ctype);
01532
01533
01534 for (vtbl = CLASSTYPE_VTABLES (ctype); vtbl; vtbl = TREE_CHAIN (vtbl))
01535 {
01536 import_export_decl (vtbl);
01537 if (DECL_NOT_REALLY_EXTERN (vtbl) && decl_needed_p (vtbl))
01538 needed = 1;
01539 }
01540 if (!needed)
01541 {
01542
01543
01544
01545 if (DECL_COMDAT (primary_vtbl)
01546 && CLASSTYPE_DEBUG_REQUESTED (ctype))
01547 note_debug_info_needed (ctype);
01548 return false;
01549 }
01550
01551
01552
01553 for (vtbl = CLASSTYPE_VTABLES (ctype); vtbl; vtbl = TREE_CHAIN (vtbl))
01554 {
01555
01556 mark_vtable_entries (vtbl);
01557
01558 if (TREE_TYPE (DECL_INITIAL (vtbl)) == 0)
01559 {
01560 tree expr = store_init_value (vtbl, DECL_INITIAL (vtbl));
01561
01562
01563 gcc_assert (!expr);
01564 }
01565
01566
01567 DECL_EXTERNAL (vtbl) = 0;
01568 rest_of_decl_compilation (vtbl, 1, 1);
01569
01570
01571
01572 if (flag_syntax_only)
01573 TREE_ASM_WRITTEN (vtbl) = 1;
01574 }
01575
01576
01577
01578 note_debug_info_needed (ctype);
01579
01580 return true;
01581 }
01582
01583
01584
01585
01586 enum { VISIBILITY_ANON = VISIBILITY_INTERNAL+1 };
01587
01588
01589
01590 static tree
01591 min_vis_r (tree *tp, int *walk_subtrees, void *data)
01592 {
01593 int *vis_p = (int *)data;
01594 if (! TYPE_P (*tp))
01595 {
01596 *walk_subtrees = 0;
01597 }
01598 else if (CLASS_TYPE_P (*tp))
01599 {
01600 if (!TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
01601 {
01602 *vis_p = VISIBILITY_ANON;
01603 return *tp;
01604 }
01605 else if (CLASSTYPE_VISIBILITY (*tp) > *vis_p)
01606 *vis_p = CLASSTYPE_VISIBILITY (*tp);
01607 }
01608 return NULL;
01609 }
01610
01611
01612
01613
01614 static int
01615 type_visibility (tree type)
01616 {
01617 int vis = VISIBILITY_DEFAULT;
01618 walk_tree_without_duplicates (&type, min_vis_r, &vis);
01619 return vis;
01620 }
01621
01622
01623
01624
01625 static bool
01626 constrain_visibility (tree decl, int visibility)
01627 {
01628 if (visibility == VISIBILITY_ANON)
01629 {
01630
01631
01632 if (!DECL_EXTERN_C_P (decl))
01633 {
01634 TREE_PUBLIC (decl) = 0;
01635 DECL_INTERFACE_KNOWN (decl) = 1;
01636 if (DECL_LANG_SPECIFIC (decl))
01637 DECL_NOT_REALLY_EXTERN (decl) = 1;
01638 }
01639 }
01640 else if (visibility > DECL_VISIBILITY (decl)
01641 && !DECL_VISIBILITY_SPECIFIED (decl))
01642 {
01643 DECL_VISIBILITY (decl) = visibility;
01644 return true;
01645 }
01646 return false;
01647 }
01648
01649
01650
01651
01652 static void
01653 constrain_visibility_for_template (tree decl, tree targs)
01654 {
01655
01656
01657
01658 tree args = INNERMOST_TEMPLATE_ARGS (targs);
01659 int i;
01660 for (i = TREE_VEC_LENGTH (args); i > 0; --i)
01661 {
01662 int vis = 0;
01663
01664 tree arg = TREE_VEC_ELT (args, i-1);
01665 if (TYPE_P (arg))
01666 vis = type_visibility (arg);
01667 else if (TREE_TYPE (arg) && POINTER_TYPE_P (TREE_TYPE (arg)))
01668 {
01669 STRIP_NOPS (arg);
01670 if (TREE_CODE (arg) == ADDR_EXPR)
01671 arg = TREE_OPERAND (arg, 0);
01672 if (TREE_CODE (arg) == VAR_DECL
01673 || TREE_CODE (arg) == FUNCTION_DECL)
01674 {
01675 if (! TREE_PUBLIC (arg))
01676 vis = VISIBILITY_ANON;
01677 else
01678 vis = DECL_VISIBILITY (arg);
01679 }
01680 }
01681 if (vis)
01682 constrain_visibility (decl, vis);
01683 }
01684 }
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702 void
01703 determine_visibility (tree decl)
01704 {
01705 tree class_type = NULL_TREE;
01706 bool use_template;
01707
01708
01709
01710
01711 if (!TREE_PUBLIC (decl))
01712 return;
01713
01714
01715
01716
01717 gcc_assert (!DECL_CLONED_FUNCTION_P (decl));
01718
01719 if (TREE_CODE (decl) == TYPE_DECL)
01720 {
01721 if (CLASS_TYPE_P (TREE_TYPE (decl)))
01722 use_template = CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl));
01723 else if (TYPE_TEMPLATE_INFO (TREE_TYPE (decl)))
01724 use_template = 1;
01725 else
01726 use_template = 0;
01727 }
01728 else if (DECL_LANG_SPECIFIC (decl))
01729 use_template = DECL_USE_TEMPLATE (decl);
01730 else
01731 use_template = 0;
01732
01733
01734 if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
01735 && lookup_attribute ("dllexport",
01736 TREE_CODE (decl) == TYPE_DECL
01737 ? TYPE_ATTRIBUTES (TREE_TYPE (decl))
01738 : DECL_ATTRIBUTES (decl)))
01739 {
01740 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
01741 DECL_VISIBILITY_SPECIFIED (decl) = 1;
01742 }
01743
01744
01745
01746 if (DECL_CLASS_SCOPE_P (decl))
01747 class_type = DECL_CONTEXT (decl);
01748 else if (TREE_CODE (decl) == VAR_DECL
01749 && DECL_TINFO_P (decl)
01750 && CLASS_TYPE_P (TREE_TYPE (DECL_NAME (decl))))
01751 class_type = TREE_TYPE (DECL_NAME (decl));
01752 else
01753 {
01754
01755
01756
01757
01758 gcc_assert (TREE_CODE (decl) != VAR_DECL
01759 || !DECL_VTABLE_OR_VTT_P (decl));
01760
01761 if (DECL_FUNCTION_SCOPE_P (decl) && ! DECL_VISIBILITY_SPECIFIED (decl))
01762 {
01763
01764
01765
01766 tree fn = DECL_CONTEXT (decl);
01767 if (DECL_VISIBILITY_SPECIFIED (fn) || ! DECL_CLASS_SCOPE_P (fn))
01768 {
01769 DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
01770 DECL_VISIBILITY_SPECIFIED (decl) =
01771 DECL_VISIBILITY_SPECIFIED (fn);
01772 }
01773 else
01774 determine_visibility_from_class (decl, DECL_CONTEXT (fn));
01775
01776
01777
01778 use_template = 0;
01779 }
01780 else if (TREE_CODE (decl) == VAR_DECL && DECL_TINFO_P (decl))
01781 {
01782
01783 constrain_visibility
01784 (decl, type_visibility (TREE_TYPE (DECL_NAME (decl))));
01785 }
01786 else if (use_template)
01787
01788 ;
01789 else if (! DECL_VISIBILITY_SPECIFIED (decl))
01790 {
01791
01792
01793 DECL_VISIBILITY (decl) = default_visibility;
01794 DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
01795 }
01796 }
01797
01798 if (use_template)
01799 {
01800
01801
01802 tree tinfo = (TREE_CODE (decl) == TYPE_DECL
01803 ? TYPE_TEMPLATE_INFO (TREE_TYPE (decl))
01804 : DECL_TEMPLATE_INFO (decl));
01805 tree args = TI_ARGS (tinfo);
01806
01807 if (args != error_mark_node)
01808 {
01809 int depth = TMPL_ARGS_DEPTH (args);
01810 tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
01811
01812 if (!DECL_VISIBILITY_SPECIFIED (decl))
01813 {
01814 DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern);
01815 DECL_VISIBILITY_SPECIFIED (decl)
01816 = DECL_VISIBILITY_SPECIFIED (pattern);
01817 }
01818
01819
01820 if (args && depth > template_class_depth (class_type))
01821
01822 constrain_visibility_for_template (decl, args);
01823 }
01824 }
01825
01826 if (class_type)
01827 determine_visibility_from_class (decl, class_type);
01828
01829 if (decl_anon_ns_mem_p (decl))
01830
01831
01832 constrain_visibility (decl, VISIBILITY_ANON);
01833 else if (TREE_CODE (decl) != TYPE_DECL)
01834 {
01835
01836 int tvis = type_visibility (TREE_TYPE (decl));
01837 if (tvis == VISIBILITY_ANON)
01838 constrain_visibility (decl, tvis);
01839 }
01840 }
01841
01842
01843
01844
01845 static void
01846 determine_visibility_from_class (tree decl, tree class_type)
01847 {
01848 if (visibility_options.inlines_hidden
01849
01850
01851
01852 && !processing_template_decl
01853 && ! DECL_VISIBILITY_SPECIFIED (decl)
01854 && TREE_CODE (decl) == FUNCTION_DECL
01855 && DECL_DECLARED_INLINE_P (decl)
01856 && (! DECL_LANG_SPECIFIC (decl)
01857 || ! DECL_EXPLICIT_INSTANTIATION (decl)))
01858 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
01859 else if (!DECL_VISIBILITY_SPECIFIED (decl))
01860 {
01861
01862 DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
01863 DECL_VISIBILITY_SPECIFIED (decl)
01864 = CLASSTYPE_VISIBILITY_SPECIFIED (class_type);
01865 }
01866
01867
01868
01869 if (TREE_CODE (decl) == VAR_DECL
01870 && (DECL_TINFO_P (decl)
01871 || (DECL_VTABLE_OR_VTT_P (decl)
01872
01873
01874
01875 && !DECL_CONSTRUCTION_VTABLE_P (decl)))
01876 && TREE_PUBLIC (decl)
01877 && !DECL_REALLY_EXTERN (decl)
01878 && !DECL_VISIBILITY_SPECIFIED (decl)
01879 && !CLASSTYPE_VISIBILITY_SPECIFIED (class_type))
01880 targetm.cxx.determine_class_data_visibility (decl);
01881 }
01882
01883
01884
01885
01886 void
01887 constrain_class_visibility (tree type)
01888 {
01889 tree binfo;
01890 tree t;
01891 int i;
01892
01893 int vis = type_visibility (type);
01894
01895 if (vis == VISIBILITY_ANON
01896 || DECL_IN_SYSTEM_HEADER (TYPE_MAIN_DECL (type)))
01897 return;
01898
01899
01900 if (CLASSTYPE_VISIBILITY_SPECIFIED (type))
01901 vis = VISIBILITY_INTERNAL;
01902
01903 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
01904 if (TREE_CODE (t) == FIELD_DECL && TREE_TYPE (t) != error_mark_node)
01905 {
01906 tree ftype = strip_array_types (TREE_TYPE (t));
01907 int subvis = type_visibility (ftype);
01908
01909 if (subvis == VISIBILITY_ANON)
01910 warning (0, "\
01911 %qT has a field %qD whose type uses the anonymous namespace",
01912 type, t);
01913 else if (IS_AGGR_TYPE (ftype)
01914 && vis < VISIBILITY_HIDDEN
01915 && subvis >= VISIBILITY_HIDDEN)
01916 warning (OPT_Wattributes, "\
01917 %qT declared with greater visibility than the type of its field %qD",
01918 type, t);
01919 }
01920
01921 binfo = TYPE_BINFO (type);
01922 for (i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
01923 {
01924 int subvis = type_visibility (TREE_TYPE (t));
01925
01926 if (subvis == VISIBILITY_ANON)
01927 warning (0, "\
01928 %qT has a base %qT whose type uses the anonymous namespace",
01929 type, TREE_TYPE (t));
01930 else if (vis < VISIBILITY_HIDDEN
01931 && subvis >= VISIBILITY_HIDDEN)
01932 warning (OPT_Wattributes, "\
01933 %qT declared with greater visibility than its base %qT",
01934 type, TREE_TYPE (t));
01935 }
01936 }
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950 void
01951 import_export_decl (tree decl)
01952 {
01953 int emit_p;
01954 bool comdat_p;
01955 bool import_p;
01956 tree class_type = NULL_TREE;
01957
01958 if (DECL_INTERFACE_KNOWN (decl))
01959 return;
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969 gcc_assert (at_eof);
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
01993 || TREE_CODE (decl) == VAR_DECL);
01994
01995
01996 gcc_assert (TREE_PUBLIC (decl));
01997 if (TREE_CODE (decl) == FUNCTION_DECL)
01998 gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
01999 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
02000 || DECL_DECLARED_INLINE_P (decl));
02001 else
02002 gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl)
02003 || DECL_VTABLE_OR_VTT_P (decl)
02004 || DECL_TINFO_P (decl));
02005
02006
02007 gcc_assert (!DECL_REALLY_EXTERN (decl));
02008
02009
02010 comdat_p = false;
02011
02012
02013 import_p = false;
02014
02015
02016
02017 emit_p = repo_emit_p (decl);
02018 if (emit_p == 0)
02019 import_p = true;
02020 else if (emit_p == 1)
02021 {
02022
02023
02024 if (TREE_CODE (decl) == VAR_DECL)
02025 mark_needed (decl);
02026 else if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl)
02027 || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
02028 {
02029 tree clone;
02030 FOR_EACH_CLONE (clone, decl)
02031 mark_needed (clone);
02032 }
02033 else
02034 mark_needed (decl);
02035
02036 DECL_EXTERNAL (decl) = 0;
02037 DECL_INTERFACE_KNOWN (decl) = 1;
02038 return;
02039 }
02040
02041 if (import_p)
02042
02043
02044 ;
02045 else if (TREE_CODE (decl) == VAR_DECL && DECL_VTABLE_OR_VTT_P (decl))
02046 {
02047 class_type = DECL_CONTEXT (decl);
02048 import_export_class (class_type);
02049 if (TYPE_FOR_JAVA (class_type))
02050 import_p = true;
02051 else if (CLASSTYPE_INTERFACE_KNOWN (class_type)
02052 && CLASSTYPE_INTERFACE_ONLY (class_type))
02053 import_p = true;
02054 else if ((!flag_weak || TARGET_WEAK_NOT_IN_ARCHIVE_TOC)
02055 && !CLASSTYPE_USE_TEMPLATE (class_type)
02056 && CLASSTYPE_KEY_METHOD (class_type)
02057 && !DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (class_type)))
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068 DECL_EXTERNAL (decl) = 0;
02069 else if (CLASSTYPE_INTERFACE_KNOWN (class_type))
02070 {
02071
02072
02073 if (!flag_weak && CLASSTYPE_EXPLICIT_INSTANTIATION (class_type))
02074
02075
02076
02077
02078
02079
02080
02081 DECL_EXTERNAL (decl) = 0;
02082 else
02083 {
02084
02085
02086
02087
02088
02089
02090
02091
02092 if (!CLASSTYPE_KEY_METHOD (class_type)
02093 || DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (class_type))
02094 || targetm.cxx.class_data_always_comdat ())
02095 {
02096
02097
02098
02099
02100 comdat_p = true;
02101 mark_needed (decl);
02102 }
02103 }
02104 }
02105 else if (!flag_implicit_templates
02106 && CLASSTYPE_IMPLICIT_INSTANTIATION (class_type))
02107 import_p = true;
02108 else
02109 comdat_p = true;
02110 }
02111 else if (TREE_CODE (decl) == VAR_DECL && DECL_TINFO_P (decl))
02112 {
02113 tree type = TREE_TYPE (DECL_NAME (decl));
02114 if (CLASS_TYPE_P (type))
02115 {
02116 class_type = type;
02117 import_export_class (type);
02118 if (CLASSTYPE_INTERFACE_KNOWN (type)
02119 && TYPE_POLYMORPHIC_P (type)
02120 && CLASSTYPE_INTERFACE_ONLY (type)
02121
02122
02123
02124
02125 && flag_rtti)
02126 import_p = true;
02127 else
02128 {
02129 if (CLASSTYPE_INTERFACE_KNOWN (type)
02130 && !CLASSTYPE_INTERFACE_ONLY (type))
02131 {
02132 comdat_p = (targetm.cxx.class_data_always_comdat ()
02133 || (CLASSTYPE_KEY_METHOD (type)
02134 && DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (type))));
02135 mark_needed (decl);
02136 if (!flag_weak)
02137 {
02138 comdat_p = false;
02139 DECL_EXTERNAL (decl) = 0;
02140 }
02141 }
02142 else
02143 comdat_p = true;
02144 }
02145 }
02146 else
02147 comdat_p = true;
02148 }
02149 else if (DECL_TEMPLATE_INSTANTIATION (decl)
02150 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl))
02151 {
02152
02153
02154 if (flag_implicit_templates
02155 || (flag_implicit_inline_templates
02156 && TREE_CODE (decl) == FUNCTION_DECL
02157 && DECL_DECLARED_INLINE_P (decl)))
02158 comdat_p = true;
02159 else
02160
02161
02162 import_p = true;
02163 }
02164 else if (DECL_FUNCTION_MEMBER_P (decl))
02165 {
02166 if (!DECL_DECLARED_INLINE_P (decl))
02167 {
02168 tree ctype = DECL_CONTEXT (decl);
02169 import_export_class (ctype);
02170 if (CLASSTYPE_INTERFACE_KNOWN (ctype))
02171 {
02172 DECL_NOT_REALLY_EXTERN (decl)
02173 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
02174 || (DECL_DECLARED_INLINE_P (decl)
02175 && ! flag_implement_inlines
02176 && !DECL_VINDEX (decl)));
02177
02178 if (!DECL_NOT_REALLY_EXTERN (decl))
02179 DECL_EXTERNAL (decl) = 1;
02180
02181
02182 if (DECL_ARTIFICIAL (decl) && flag_weak)
02183 comdat_p = true;
02184 else
02185 maybe_make_one_only (decl);
02186 }
02187 }
02188 else
02189 comdat_p = true;
02190 }
02191 else
02192 comdat_p = true;
02193
02194 if (import_p)
02195 {
02196
02197
02198 DECL_EXTERNAL (decl) = 1;
02199 DECL_NOT_REALLY_EXTERN (decl) = 0;
02200 }
02201 else if (comdat_p)
02202 {
02203
02204
02205 comdat_linkage (decl);
02206 }
02207
02208 DECL_INTERFACE_KNOWN (decl) = 1;
02209 }
02210
02211
02212
02213
02214
02215 tree
02216 build_cleanup (tree decl)
02217 {
02218 tree temp;
02219 tree type = TREE_TYPE (decl);
02220
02221
02222
02223 gcc_assert (!TYPE_HAS_TRIVIAL_DESTRUCTOR (type));
02224
02225
02226
02227 mark_used (decl);
02228
02229 if (TREE_CODE (type) == ARRAY_TYPE)
02230 temp = decl;
02231 else
02232 {
02233 cxx_mark_addressable (decl);
02234 temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
02235 }
02236 temp = build_delete (TREE_TYPE (temp), temp,
02237 sfk_complete_destructor,
02238 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
02239 return temp;
02240 }
02241
02242
02243
02244
02245 tree
02246 get_guard (tree decl)
02247 {
02248 tree sname;
02249 tree guard;
02250
02251 sname = mangle_guard_variable (decl);
02252 guard = IDENTIFIER_GLOBAL_VALUE (sname);
02253 if (! guard)
02254 {
02255 tree guard_type;
02256
02257
02258
02259 guard_type = targetm.cxx.guard_type ();
02260 guard = build_decl (VAR_DECL, sname, guard_type);
02261
02262
02263 TREE_PUBLIC (guard) = TREE_PUBLIC (decl);
02264 TREE_STATIC (guard) = TREE_STATIC (decl);
02265 DECL_COMMON (guard) = DECL_COMMON (decl);
02266 DECL_ONE_ONLY (guard) = DECL_ONE_ONLY (decl);
02267 if (TREE_PUBLIC (decl))
02268 DECL_WEAK (guard) = DECL_WEAK (decl);
02269
02270 DECL_ARTIFICIAL (guard) = 1;
02271 DECL_IGNORED_P (guard) = 1;
02272 TREE_USED (guard) = 1;
02273 pushdecl_top_level_and_finish (guard, NULL_TREE);
02274 }
02275 return guard;
02276 }
02277
02278
02279
02280
02281 static tree
02282 get_guard_bits (tree guard)
02283 {
02284 if (!targetm.cxx.guard_mask_bit ())
02285 {
02286
02287
02288 guard = build1 (ADDR_EXPR,
02289 build_pointer_type (TREE_TYPE (guard)),
02290 guard);
02291 guard = build1 (NOP_EXPR,
02292 build_pointer_type (char_type_node),
02293 guard);
02294 guard = build1 (INDIRECT_REF, char_type_node, guard);
02295 }
02296
02297 return guard;
02298 }
02299
02300
02301
02302
02303 tree
02304 get_guard_cond (tree guard)
02305 {
02306 tree guard_value;
02307
02308
02309 guard = get_guard_bits (guard);
02310
02311
02312 if (targetm.cxx.guard_mask_bit ())
02313 {
02314 guard_value = integer_one_node;
02315 if (!same_type_p (TREE_TYPE (guard_value), TREE_TYPE (guard)))
02316 guard_value = convert (TREE_TYPE (guard), guard_value);
02317 guard = cp_build_binary_op (BIT_AND_EXPR, guard, guard_value);
02318 }
02319
02320 guard_value = integer_zero_node;
02321 if (!same_type_p (TREE_TYPE (guard_value), TREE_TYPE (guard)))
02322 guard_value = convert (TREE_TYPE (guard), guard_value);
02323 return cp_build_binary_op (EQ_EXPR, guard, guard_value);
02324 }
02325
02326
02327
02328
02329 tree
02330 set_guard (tree guard)
02331 {
02332 tree guard_init;
02333
02334
02335 guard = get_guard_bits (guard);
02336 guard_init = integer_one_node;
02337 if (!same_type_p (TREE_TYPE (guard_init), TREE_TYPE (guard)))
02338 guard_init = convert (TREE_TYPE (guard), guard_init);
02339 return build_modify_expr (guard, NOP_EXPR, guard_init);
02340 }
02341
02342
02343
02344
02345 static tree
02346 start_objects (int method_type, int initp)
02347 {
02348 tree body;
02349 tree fndecl;
02350 char type[10];
02351
02352
02353
02354 if (initp != DEFAULT_INIT_PRIORITY)
02355 {
02356 char joiner;
02357
02358 #ifdef JOINER
02359 joiner = JOINER;
02360 #else
02361 joiner = '_';
02362 #endif
02363
02364 sprintf (type, "%c%c%.5u", method_type, joiner, initp);
02365 }
02366 else
02367 sprintf (type, "%c", method_type);
02368
02369 fndecl = build_lang_decl (FUNCTION_DECL,
02370 get_file_function_name_long (type),
02371 build_function_type (void_type_node,
02372 void_list_node));
02373 start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
02374
02375
02376
02377 TREE_PUBLIC (current_function_decl) = ! targetm.have_ctors_dtors;
02378
02379
02380 TREE_USED (current_function_decl) = 1;
02381
02382
02383 if (method_type == 'I')
02384 DECL_GLOBAL_CTOR_P (current_function_decl) = 1;
02385 else
02386 DECL_GLOBAL_DTOR_P (current_function_decl) = 1;
02387 DECL_LANG_SPECIFIC (current_function_decl)->decl_flags.u2sel = 1;
02388
02389 body = begin_compound_stmt (BCS_FN_BODY);
02390
02391
02392
02393
02394
02395 DECL_INLINE (current_function_decl) = 0;
02396 DECL_UNINLINABLE (current_function_decl) = 1;
02397
02398 return body;
02399 }
02400
02401
02402
02403
02404 static void
02405 finish_objects (int method_type, int initp, tree body)
02406 {
02407 tree fn;
02408
02409
02410 finish_compound_stmt (body);
02411 fn = finish_function (0);
02412 expand_or_defer_fn (fn);
02413
02414
02415
02416
02417 if (flag_syntax_only)
02418 return;
02419
02420 if (targetm.have_ctors_dtors)
02421 {
02422 rtx fnsym = XEXP (DECL_RTL (fn), 0);
02423 cgraph_mark_needed_node (cgraph_node (fn));
02424 if (method_type == 'I')
02425 (* targetm.asm_out.constructor) (fnsym, initp);
02426 else
02427 (* targetm.asm_out.destructor) (fnsym, initp);
02428 }
02429 }
02430
02431
02432
02433
02434 #define INITIALIZE_P_IDENTIFIER "__initialize_p"
02435 #define PRIORITY_IDENTIFIER "__priority"
02436
02437
02438
02439 #define SSDF_IDENTIFIER "__static_initialization_and_destruction"
02440
02441
02442 static GTY(()) tree initialize_p_decl;
02443
02444
02445 static GTY(()) tree priority_decl;
02446
02447
02448 static GTY(()) tree ssdf_decl;
02449
02450
02451
02452 static GTY(()) VEC(tree,gc) *ssdf_decls;
02453
02454
02455
02456
02457 static splay_tree priority_info_map;
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471 static tree
02472 start_static_storage_duration_function (unsigned count)
02473 {
02474 tree parm_types;
02475 tree type;
02476 tree body;
02477 char id[sizeof (SSDF_IDENTIFIER) + 1 + 32];
02478
02479
02480
02481 sprintf (id, "%s_%u", SSDF_IDENTIFIER, count);
02482
02483
02484 parm_types = void_list_node;
02485 parm_types = tree_cons (NULL_TREE, integer_type_node, parm_types);
02486 parm_types = tree_cons (NULL_TREE, integer_type_node, parm_types);
02487 type = build_function_type (void_type_node, parm_types);
02488
02489
02490 ssdf_decl = build_lang_decl (FUNCTION_DECL,
02491 get_identifier (id),
02492 type);
02493 TREE_PUBLIC (ssdf_decl) = 0;
02494 DECL_ARTIFICIAL (ssdf_decl) = 1;
02495
02496
02497
02498 if (!ssdf_decls)
02499 {
02500 ssdf_decls = VEC_alloc (tree, gc, 32);
02501
02502
02503
02504 priority_info_map = splay_tree_new (splay_tree_compare_ints,
02505 0,
02506
02507 (splay_tree_delete_value_fn) &free);
02508
02509
02510
02511
02512
02513 get_priority_info (DEFAULT_INIT_PRIORITY);
02514 }
02515
02516 VEC_safe_push (tree, gc, ssdf_decls, ssdf_decl);
02517
02518
02519 initialize_p_decl = cp_build_parm_decl
02520 (get_identifier (INITIALIZE_P_IDENTIFIER), integer_type_node);
02521 DECL_CONTEXT (initialize_p_decl) = ssdf_decl;
02522 TREE_USED (initialize_p_decl) = 1;
02523 priority_decl = cp_build_parm_decl
02524 (get_identifier (PRIORITY_IDENTIFIER), integer_type_node);
02525 DECL_CONTEXT (priority_decl) = ssdf_decl;
02526 TREE_USED (priority_decl) = 1;
02527
02528 TREE_CHAIN (initialize_p_decl) = priority_decl;
02529 DECL_ARGUMENTS (ssdf_decl) = initialize_p_decl;
02530
02531
02532 pushdecl (ssdf_decl);
02533
02534
02535
02536
02537
02538
02539
02540
02541 start_preparsed_function (ssdf_decl,
02542 NULL_TREE,
02543 SF_PRE_PARSED);
02544
02545
02546 body = begin_compound_stmt (BCS_FN_BODY);
02547
02548
02549
02550 DECL_INLINE (ssdf_decl) = 0;
02551 DECL_UNINLINABLE (ssdf_decl) = 1;
02552
02553 return body;
02554 }
02555
02556
02557
02558
02559
02560 static void
02561 finish_static_storage_duration_function (tree body)
02562 {
02563
02564 finish_compound_stmt (body);
02565 expand_or_defer_fn (finish_function (0));
02566 }
02567
02568
02569
02570
02571
02572 static priority_info
02573 get_priority_info (int priority)
02574 {
02575 priority_info pi;
02576 splay_tree_node n;
02577
02578 n = splay_tree_lookup (priority_info_map,
02579 (splay_tree_key) priority);
02580 if (!n)
02581 {
02582
02583
02584 pi = XNEW (struct priority_info_s);
02585 pi->initializations_p = 0;
02586 pi->destructions_p = 0;
02587 splay_tree_insert (priority_info_map,
02588 (splay_tree_key) priority,
02589 (splay_tree_value) pi);
02590 }
02591 else
02592 pi = (priority_info) n->value;
02593
02594 return pi;
02595 }
02596
02597
02598
02599 #define DECL_EFFECTIVE_INIT_PRIORITY(decl) \
02600 ((!DECL_HAS_INIT_PRIORITY_P (decl) || DECL_INIT_PRIORITY (decl) == 0) \
02601 ? DEFAULT_INIT_PRIORITY : DECL_INIT_PRIORITY (decl))
02602
02603
02604
02605
02606 #define NEEDS_GUARD_P(decl) (TREE_PUBLIC (decl) && (DECL_COMMON (decl) \
02607 || DECL_ONE_ONLY (decl) \
02608 || DECL_WEAK (decl)))
02609
02610
02611
02612
02613
02614 static void
02615 one_static_initialization_or_destruction (tree decl, tree init, bool initp)
02616 {
02617 tree guard_if_stmt = NULL_TREE;
02618 tree guard;
02619
02620
02621
02622 if (!initp
02623 && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
02624 return;
02625
02626
02627
02628
02629
02630 input_location = DECL_SOURCE_LOCATION (decl);
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644 if (member_p (decl))
02645 {
02646 DECL_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
02647 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
02648 }
02649
02650
02651 guard = NULL_TREE;
02652
02653
02654
02655
02656 if (NEEDS_GUARD_P (decl))
02657 {
02658 tree guard_cond;
02659
02660 guard = get_guard (decl);
02661
02662
02663
02664 if (flag_use_cxa_atexit)
02665 {
02666
02667
02668 gcc_assert (initp);
02669 guard_cond = get_guard_cond (guard);
02670 }
02671
02672
02673
02674
02675
02676
02677
02678 else if (initp)
02679 guard_cond
02680 = cp_build_binary_op (EQ_EXPR,
02681 build_unary_op (PREINCREMENT_EXPR,
02682 guard,
02683 1),
02684 integer_one_node);
02685 else
02686 guard_cond
02687 = cp_build_binary_op (EQ_EXPR,
02688 build_unary_op (PREDECREMENT_EXPR,
02689 guard,
02690 1),
02691 integer_zero_node);
02692
02693 guard_if_stmt = begin_if_stmt ();
02694 finish_if_stmt_cond (guard_cond, guard_if_stmt);
02695 }
02696
02697
02698
02699
02700 if (guard && initp && flag_use_cxa_atexit)
02701 finish_expr_stmt (set_guard (guard));
02702
02703
02704 if (initp)
02705 {
02706 if (init)
02707 finish_expr_stmt (init);
02708
02709
02710
02711 if (flag_use_cxa_atexit)
02712 finish_expr_stmt (register_dtor_fn (decl));
02713 }
02714 else
02715 finish_expr_stmt (build_cleanup (decl));
02716
02717
02718 if (guard)
02719 {
02720 finish_then_clause (guard_if_stmt);
02721 finish_if_stmt (guard_if_stmt);
02722 }
02723
02724
02725
02726 DECL_CONTEXT (current_function_decl) = NULL_TREE;
02727 DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
02728 }
02729
02730
02731
02732
02733
02734 static void
02735 do_static_initialization_or_destruction (tree vars, bool initp)
02736 {
02737 tree node, init_if_stmt, cond;
02738
02739
02740 init_if_stmt = begin_if_stmt ();
02741 cond = initp ? integer_one_node : integer_zero_node;
02742 cond = cp_build_binary_op (EQ_EXPR,
02743 initialize_p_decl,
02744 cond);
02745 finish_if_stmt_cond (cond, init_if_stmt);
02746
02747 node = vars;
02748 do {
02749 tree decl = TREE_VALUE (node);
02750 tree priority_if_stmt;
02751 int priority;
02752 priority_info pi;
02753
02754
02755
02756 if (!initp && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
02757 {
02758 node = TREE_CHAIN (node);
02759 continue;
02760 }
02761
02762
02763
02764 priority = DECL_EFFECTIVE_INIT_PRIORITY (decl);
02765 pi = get_priority_info (priority);
02766 if (initp)
02767 pi->initializations_p = 1;
02768 else
02769 pi->destructions_p = 1;
02770
02771
02772
02773 priority_if_stmt = begin_if_stmt ();
02774 cond = cp_build_binary_op (EQ_EXPR,
02775 priority_decl,
02776 build_int_cst (NULL_TREE, priority));
02777 finish_if_stmt_cond (cond, priority_if_stmt);
02778
02779
02780 for (; node
02781 && DECL_EFFECTIVE_INIT_PRIORITY (TREE_VALUE (node)) == priority;
02782 node = TREE_CHAIN (node))
02783
02784 one_static_initialization_or_destruction (TREE_VALUE (node),
02785 TREE_PURPOSE (node), initp);
02786
02787
02788 finish_then_clause (priority_if_stmt);
02789 finish_if_stmt (priority_if_stmt);
02790
02791 } while (node);
02792
02793
02794 finish_then_clause (init_if_stmt);
02795 finish_if_stmt (init_if_stmt);
02796 }
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806 static tree
02807 prune_vars_needing_no_initialization (tree *vars)
02808 {
02809 tree *var = vars;
02810 tree result = NULL_TREE;
02811
02812 while (*var)
02813 {
02814 tree t = *var;
02815 tree decl = TREE_VALUE (t);
02816 tree init = TREE_PURPOSE (t);
02817
02818
02819 if (decl == error_mark_node)
02820 {
02821 var = &TREE_CHAIN (t);
02822 continue;
02823 }
02824
02825
02826 gcc_assert (TREE_CODE (decl) == VAR_DECL);
02827
02828
02829
02830 if (DECL_EXTERNAL (decl))
02831 {
02832 var = &TREE_CHAIN (t);
02833 continue;
02834 }
02835
02836
02837
02838 if (init && TREE_CODE (init) == TREE_LIST
02839 && value_member (error_mark_node, init))
02840 {
02841 var = &TREE_CHAIN (t);
02842 continue;
02843 }
02844
02845
02846
02847 *var = TREE_CHAIN (t);
02848 TREE_CHAIN (t) = result;
02849 result = t;
02850 }
02851
02852 return result;
02853 }
02854
02855
02856
02857
02858 static void
02859 write_out_vars (tree vars)
02860 {
02861 tree v;
02862
02863 for (v = vars; v; v = TREE_CHAIN (v))
02864 {
02865 tree var = TREE_VALUE (v);
02866 if (!var_finalized_p (var))
02867 {
02868 import_export_decl (var);
02869 rest_of_decl_compilation (var, 1, 1);
02870 }
02871 }
02872 }
02873
02874
02875
02876
02877
02878 static void
02879 generate_ctor_or_dtor_function (bool constructor_p, int priority,
02880 location_t *locus)
02881 {
02882 char function_key;
02883 tree arguments;
02884 tree fndecl;
02885 tree body;
02886 size_t i;
02887
02888 input_location = *locus;
02889 #ifdef USE_MAPPED_LOCATION
02890
02891 #else
02892 locus->line++;
02893 #endif
02894
02895
02896
02897 function_key = constructor_p ? 'I' : 'D';
02898
02899
02900
02901 body = NULL_TREE;
02902
02903
02904
02905 if (c_dialect_objc () && (priority == DEFAULT_INIT_PRIORITY)
02906 && constructor_p && objc_static_init_needed_p ())
02907 {
02908 body = start_objects (function_key, priority);
02909 static_ctors = objc_generate_static_init_call (static_ctors);
02910 }
02911
02912
02913
02914 for (i = 0; VEC_iterate (tree, ssdf_decls, i, fndecl); ++i)
02915 {
02916
02917 if (! (flags_from_decl_or_type (fndecl) & (ECF_CONST | ECF_PURE)))
02918 {
02919 if (! body)
02920 body = start_objects (function_key, priority);
02921
02922 arguments = tree_cons (NULL_TREE,
02923 build_int_cst (NULL_TREE, priority),
02924 NULL_TREE);
02925 arguments = tree_cons (NULL_TREE,
02926 build_int_cst (NULL_TREE, constructor_p),
02927 arguments);
02928 finish_expr_stmt (build_function_call (fndecl, arguments));
02929 }
02930 }
02931
02932
02933
02934
02935 if (priority == DEFAULT_INIT_PRIORITY)
02936 {
02937 tree fns;
02938
02939 for (fns = constructor_p ? static_ctors : static_dtors;
02940 fns;
02941 fns = TREE_CHAIN (fns))
02942 {
02943 fndecl = TREE_VALUE (fns);
02944
02945
02946 if (! (flags_from_decl_or_type (fndecl) & (ECF_CONST | ECF_PURE)))
02947 {
02948 if (! body)
02949 body = start_objects (function_key, priority);
02950 finish_expr_stmt (build_function_call (fndecl, NULL_TREE));
02951 }
02952 }
02953 }
02954
02955
02956 if (body)
02957 finish_objects (function_key, priority, body);
02958 }
02959
02960
02961
02962
02963 static int
02964 generate_ctor_and_dtor_functions_for_priority (splay_tree_node n, void * data)
02965 {
02966 location_t *locus = (location_t *) data;
02967 int priority = (int) n->key;
02968 priority_info pi = (priority_info) n->value;
02969
02970
02971
02972 if (pi->initializations_p
02973 || (priority == DEFAULT_INIT_PRIORITY && static_ctors))
02974 generate_ctor_or_dtor_function (true, priority, locus);
02975 if (pi->destructions_p
02976 || (priority == DEFAULT_INIT_PRIORITY && static_dtors))
02977 generate_ctor_or_dtor_function (false, priority, locus);
02978
02979
02980 return 0;
02981 }
02982
02983
02984
02985
02986
02987
02988
02989 tree
02990 cxx_callgraph_analyze_expr (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
02991 tree from ATTRIBUTE_UNUSED)
02992 {
02993 tree t = *tp;
02994
02995 switch (TREE_CODE (t))
02996 {
02997 case PTRMEM_CST:
02998 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
02999 cgraph_mark_needed_node (cgraph_node (PTRMEM_CST_MEMBER (t)));
03000 break;
03001 case BASELINK:
03002 if (TREE_CODE (BASELINK_FUNCTIONS (t)) == FUNCTION_DECL)
03003 cgraph_mark_needed_node (cgraph_node (BASELINK_FUNCTIONS (t)));
03004 break;
03005 case VAR_DECL:
03006 if (DECL_VTABLE_OR_VTT_P (t))
03007 {
03008
03009
03010 tree vtbl;
03011 for (vtbl = CLASSTYPE_VTABLES (DECL_CONTEXT (t));
03012 vtbl;
03013 vtbl = TREE_CHAIN (vtbl))
03014 mark_decl_referenced (vtbl);
03015 }
03016 else if (DECL_CONTEXT (t)
03017 && TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL)
03018
03019
03020 mark_decl_referenced (DECL_CONTEXT (t));
03021 break;
03022 default:
03023 break;
03024 }
03025
03026 return NULL;
03027 }
03028
03029
03030
03031
03032
03033 static void
03034 build_java_method_aliases (void)
03035 {
03036 struct cgraph_node *node;
03037
03038 #ifndef HAVE_GAS_HIDDEN
03039 return;
03040 #endif
03041
03042 for (node = cgraph_nodes; node ; node = node->next)
03043 {
03044 tree fndecl = node->decl;
03045
03046 if (TREE_ASM_WRITTEN (fndecl)
03047 && DECL_CONTEXT (fndecl)
03048 && TYPE_P (DECL_CONTEXT (fndecl))
03049 && TYPE_FOR_JAVA (DECL_CONTEXT (fndecl))
03050 && TARGET_USE_LOCAL_THUNK_ALIAS_P (fndecl))
03051 {
03052
03053
03054 tree oid, nid, alias;
03055 const char *oname;
03056 char *nname;
03057
03058 oid = DECL_ASSEMBLER_NAME (fndecl);
03059 oname = IDENTIFIER_POINTER (oid);
03060 gcc_assert (oname[0] == '_' && oname[1] == 'Z');
03061 nname = ACONCAT (("_ZGA", oname+2, NULL));
03062 nid = get_identifier (nname);
03063
03064 alias = make_alias_for (fndecl, nid);
03065 TREE_PUBLIC (alias) = 1;
03066 DECL_VISIBILITY (alias) = VISIBILITY_HIDDEN;
03067
03068 assemble_alias (alias, oid);
03069 }
03070 }
03071 }
03072
03073 #ifdef KEY
03074 extern int processing_global_namespace;
03075 #endif
03076
03077
03078
03079
03080
03081
03082 void
03083 cp_finish_file (void)
03084 {
03085 tree vars;
03086 bool reconsider;
03087 size_t i;
03088 location_t locus;
03089 unsigned ssdf_count = 0;
03090 int retries = 0;
03091 tree decl;
03092
03093 locus = input_location;
03094 at_eof = 1;
03095
03096
03097 if (! global_bindings_p () || current_class_type || decl_namespace_list)
03098 return;
03099
03100 if (pch_file)
03101 c_common_write_pch ();
03102
03103 #ifdef USE_MAPPED_LOCATION
03104
03105 #else
03106
03107
03108 input_line -= 1;
03109 #endif
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127 timevar_push (TV_VARCONST);
03128
03129 emit_support_tinfos ();
03130
03131 do
03132 {
03133 tree t;
03134 tree decl;
03135
03136 reconsider = false;
03137
03138
03139
03140 instantiate_pending_templates (retries);
03141 ggc_collect ();
03142
03143
03144
03145
03146
03147
03148
03149 while (keyed_classes != NULL_TREE
03150 && maybe_emit_vtables (TREE_VALUE (keyed_classes)))
03151 {
03152 reconsider = true;
03153 keyed_classes = TREE_CHAIN (keyed_classes);
03154 }
03155
03156 t = keyed_classes;
03157 if (t != NULL_TREE)
03158 {
03159 tree next = TREE_CHAIN (t);
03160
03161 while (next)
03162 {
03163 if (maybe_emit_vtables (TREE_VALUE (next)))
03164 {
03165 reconsider = true;
03166 TREE_CHAIN (t) = TREE_CHAIN (next);
03167 }
03168 else
03169 t = next;
03170
03171 next = TREE_CHAIN (t);
03172 }
03173 }
03174
03175
03176
03177
03178
03179
03180 for (i = VEC_length (tree, unemitted_tinfo_decls);
03181 VEC_iterate (tree, unemitted_tinfo_decls, --i, t);)
03182 if (emit_tinfo_decl (t))
03183 {
03184 reconsider = true;
03185 VEC_unordered_remove (tree, unemitted_tinfo_decls, i);
03186 }
03187
03188
03189
03190
03191
03192
03193 vars = prune_vars_needing_no_initialization (&static_aggregates);
03194
03195 if (vars)
03196 {
03197
03198
03199
03200
03201
03202
03203
03204 tree ssdf_body;
03205
03206
03207
03208 input_location = locus;
03209 ssdf_body = start_static_storage_duration_function (ssdf_count);
03210
03211
03212 write_out_vars (vars);
03213
03214
03215 if (vars)
03216 do_static_initialization_or_destruction (vars, true);
03217
03218
03219
03220
03221
03222
03223
03224 if (!flag_use_cxa_atexit && vars)
03225 {
03226 vars = nreverse (vars);
03227 do_static_initialization_or_destruction (vars, false);
03228 }
03229 else
03230 vars = NULL_TREE;
03231
03232
03233
03234 input_location = locus;
03235 finish_static_storage_duration_function (ssdf_body);
03236
03237
03238
03239
03240 reconsider = true;
03241 ssdf_count++;
03242 #ifdef USE_MAPPED_LOCATION
03243
03244 #else
03245 locus.line++;
03246 #endif
03247 }
03248
03249
03250
03251
03252 for (i = 0; VEC_iterate (tree, deferred_fns, i, decl); ++i)
03253 {
03254
03255 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
03256 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
03257 {
03258
03259
03260
03261
03262
03263 push_to_top_level ();
03264
03265
03266
03267 input_location = DECL_SOURCE_LOCATION (decl);
03268 synthesize_method (decl);
03269 pop_from_top_level ();
03270 reconsider = true;
03271 }
03272
03273 if (!DECL_SAVED_TREE (decl))
03274 continue;
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285
03286
03287
03288
03289
03290
03291 import_export_decl (decl);
03292 if (DECL_NOT_REALLY_EXTERN (decl)
03293 && DECL_INITIAL (decl)
03294 && decl_needed_p (decl))
03295 DECL_EXTERNAL (decl) = 0;
03296
03297 #ifdef KEY
03298 if (flag_spin_file && gspin_invoked(decl))
03299 gs_set_flag_value (decl, GS_DECL_EXTERNAL, DECL_EXTERNAL(decl));
03300 #endif
03301
03302
03303
03304
03305
03306 if (!DECL_EXTERNAL (decl)
03307 && decl_needed_p (decl)
03308 && !TREE_ASM_WRITTEN (decl)
03309 && !cgraph_node (decl)->local.finalized)
03310 {
03311
03312
03313 DECL_DEFER_OUTPUT (decl) = 0;
03314
03315
03316 expand_or_defer_fn (decl);
03317
03318
03319
03320 if (flag_syntax_only)
03321 TREE_ASM_WRITTEN (decl) = 1;
03322 reconsider = true;
03323 #ifdef KEY
03324
03325
03326 if (flag_spin_file)
03327 gspin_gxx_emits_decl (decl);
03328 #endif
03329 }
03330 }
03331
03332 if (walk_namespaces (wrapup_globals_for_namespace, 0))
03333 reconsider = true;
03334
03335
03336 for (i = 0; VEC_iterate (tree, pending_statics, i, decl); ++i)
03337 {
03338 if (var_finalized_p (decl) || DECL_REALLY_EXTERN (decl))
03339 continue;
03340 import_export_decl (decl);
03341
03342
03343 if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl))
03344 DECL_EXTERNAL (decl) = 0;
03345 }
03346 if (VEC_length (tree, pending_statics) != 0
03347 && wrapup_global_declarations (VEC_address (tree, pending_statics),
03348 VEC_length (tree, pending_statics)))
03349 reconsider = true;
03350
03351 retries++;
03352 }
03353 while (reconsider);
03354
03355
03356 for (i = 0; VEC_iterate (tree, deferred_fns, i, decl); ++i)
03357 {
03358 if (
03359 TREE_USED (decl) && DECL_DECLARED_INLINE_P (decl)
03360
03361
03362
03363
03364
03365 && !DECL_INITIAL (decl)
03366
03367
03368
03369 && !DECL_EXPLICIT_INSTANTIATION (decl))
03370 {
03371 warning (0, "inline function %q+D used but never defined", decl);
03372
03373 TREE_NO_WARNING (decl) = 1;
03374 }
03375 }
03376
03377
03378 push_lang_context (lang_name_c);
03379
03380
03381
03382 if (priority_info_map)
03383 splay_tree_foreach (priority_info_map,
03384 generate_ctor_and_dtor_functions_for_priority,
03385 &locus);
03386 else
03387 {
03388
03389
03390 if (static_ctors || (c_dialect_objc () && objc_static_init_needed_p ()))
03391 generate_ctor_or_dtor_function (true,
03392 DEFAULT_INIT_PRIORITY, &locus);
03393 if (static_dtors)
03394 generate_ctor_or_dtor_function (false,
03395 DEFAULT_INIT_PRIORITY, &locus);
03396 }
03397
03398
03399 if (priority_info_map)
03400 splay_tree_delete (priority_info_map);
03401
03402
03403 maybe_apply_pending_pragma_weaks ();
03404
03405
03406
03407 pop_lang_context ();
03408
03409 cgraph_finalize_compilation_unit ();
03410 cgraph_optimize ();
03411
03412
03413
03414 walk_namespaces (wrapup_globals_for_namespace, &reconsider);
03415 if (VEC_length (tree, pending_statics) != 0)
03416 {
03417 check_global_declarations (VEC_address (tree, pending_statics),
03418 VEC_length (tree, pending_statics));
03419 emit_debug_global_declarations (VEC_address (tree, pending_statics),
03420 VEC_length (tree, pending_statics));
03421 }
03422
03423
03424 build_java_method_aliases ();
03425
03426 finish_repo ();
03427
03428 #ifdef KEY
03429
03430 if (flag_spin_file)
03431 {
03432 static int spun_global_namespace = 0;
03433 if (!spun_global_namespace)
03434 {
03435 processing_global_namespace = 1;
03436 gspin (global_namespace);
03437
03438 processing_global_namespace = 0;
03439 spun_global_namespace = 1;
03440 }
03441 }
03442 #endif
03443
03444
03445
03446 {
03447 int flags;
03448 FILE *stream = dump_begin (TDI_tu, &flags);
03449
03450 if (stream)
03451 {
03452 dump_node (global_namespace, flags & ~TDF_SLIM, stream);
03453 dump_end (TDI_tu, stream);
03454 }
03455 }
03456
03457 timevar_pop (TV_VARCONST);
03458
03459 if (flag_detailed_statistics)
03460 {
03461 dump_tree_statistics ();
03462 dump_time_statistics ();
03463 }
03464 input_location = locus;
03465
03466 #ifdef ENABLE_CHECKING
03467 validate_conversion_obstack ();
03468 #endif
03469 }
03470
03471
03472
03473
03474
03475
03476 tree
03477 build_offset_ref_call_from_tree (tree fn, tree args)
03478 {
03479 tree orig_fn;
03480 tree orig_args;
03481 tree expr;
03482 tree object;
03483
03484 orig_fn = fn;
03485 orig_args = args;
03486 object = TREE_OPERAND (fn, 0);
03487
03488 if (processing_template_decl)
03489 {
03490 gcc_assert (TREE_CODE (fn) == DOTSTAR_EXPR
03491 || TREE_CODE (fn) == MEMBER_REF);
03492 if (type_dependent_expression_p (fn)
03493 || any_type_dependent_arguments_p (args))
03494 return build_min_nt (CALL_EXPR, fn, args, NULL_TREE);
03495
03496
03497
03498
03499 args = build_non_dependent_args (args);
03500 if (TREE_CODE (fn) == DOTSTAR_EXPR)
03501 object = build_unary_op (ADDR_EXPR, object, 0);
03502 object = build_non_dependent_expr (object);
03503 args = tree_cons (NULL_TREE, object, args);
03504
03505 fn = build_non_dependent_expr (fn);
03506 }
03507
03508
03509
03510
03511
03512
03513
03514 if (TREE_CODE (fn) == OFFSET_REF)
03515 {
03516 tree object_addr = build_unary_op (ADDR_EXPR, object, 0);
03517 fn = TREE_OPERAND (fn, 1);
03518 fn = get_member_function_from_ptrfunc (&object_addr, fn);
03519 args = tree_cons (NULL_TREE, object_addr, args);
03520 }
03521
03522 expr = build_function_call (fn, args);
03523 if (processing_template_decl && expr != error_mark_node)
03524 return build_min_non_dep (CALL_EXPR, expr, orig_fn, orig_args, NULL_TREE);
03525 return expr;
03526 }
03527
03528
03529 void
03530 check_default_args (tree x)
03531 {
03532 tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
03533 bool saw_def = false;
03534 int i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
03535 for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
03536 {
03537 if (TREE_PURPOSE (arg))
03538 saw_def = true;
03539 else if (saw_def)
03540 {
03541 error ("default argument missing for parameter %P of %q+#D", i, x);
03542 TREE_PURPOSE (arg) = error_mark_node;
03543 }
03544 }
03545 }
03546
03547
03548
03549
03550
03551 void
03552 mark_used (tree decl)
03553 {
03554 HOST_WIDE_INT saved_processing_template_decl = 0;
03555
03556
03557
03558
03559
03560 if (TREE_CODE (decl) == BASELINK)
03561 {
03562 decl = BASELINK_FUNCTIONS (decl);
03563 if (really_overloaded_fn (decl))
03564 return;
03565 decl = OVL_CURRENT (decl);
03566 }
03567
03568 TREE_USED (decl) = 1;
03569 if (DECL_CLONED_FUNCTION_P (decl))
03570 TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1;
03571
03572 if (skip_evaluation)
03573 return;
03574
03575
03576
03577
03578 if (TREE_CODE (decl) == VAR_DECL
03579 && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
03580 && DECL_CLASS_SCOPE_P (decl))
03581 {
03582
03583
03584
03585
03586
03587 if (CLASSTYPE_TEMPLATE_INFO ((DECL_CONTEXT (decl)))
03588 && uses_template_parms (CLASSTYPE_TI_ARGS (DECL_CONTEXT (decl))))
03589 return;
03590
03591
03592 saved_processing_template_decl = processing_template_decl;
03593 processing_template_decl = 0;
03594 }
03595
03596 if (processing_template_decl)
03597 return;
03598
03599 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl)
03600 && !TREE_ASM_WRITTEN (decl))
03601
03602 {
03603 if (DECL_DEFERRED_FN (decl))
03604 return;
03605
03606
03607
03608
03609 if (DECL_ARTIFICIAL (decl) && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
03610 && !DECL_THUNK_P (decl))
03611 DECL_SOURCE_LOCATION (decl) = input_location;
03612
03613 note_vague_linkage_fn (decl);
03614 }
03615
03616 assemble_external (decl);
03617
03618
03619 if (TREE_CODE (decl) == FUNCTION_DECL
03620 && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
03621 && DECL_ARTIFICIAL (decl)
03622 && !DECL_THUNK_P (decl)
03623 && ! DECL_INITIAL (decl)
03624
03625
03626
03627
03628 && current_function_decl)
03629 {
03630 synthesize_method (decl);
03631
03632
03633 }
03634 else if ((DECL_NON_THUNK_FUNCTION_P (decl) || TREE_CODE (decl) == VAR_DECL)
03635 && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
03636 && (!DECL_EXPLICIT_INSTANTIATION (decl)
03637 || (TREE_CODE (decl) == FUNCTION_DECL
03638 && DECL_INLINE (DECL_TEMPLATE_RESULT
03639 (template_for_substitution (decl))))
03640
03641
03642
03643 || (TREE_CODE (decl) == VAR_DECL
03644 && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))))
03645
03646
03647
03648
03649
03650
03651
03652
03653
03654 instantiate_decl (decl, true,
03655 false);
03656
03657 processing_template_decl = saved_processing_template_decl;
03658 }
03659
03660 #include "gt-cp-decl2.h"