00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "config.h"
00036 #include "system.h"
00037 #include "tree.h"
00038 #include "rtl.h"
00039 #include "expr.h"
00040 #include "flags.h"
00041 #include "cp-tree.h"
00042 #include "tree-inline.h"
00043 #include "decl.h"
00044 #include "lex.h"
00045 #include "output.h"
00046 #include "except.h"
00047 #include "toplev.h"
00048 #include "hashtab.h"
00049 #include "ggc.h"
00050 #include "tm_p.h"
00051 #include "target.h"
00052 #include "c-common.h"
00053 #include "c-pragma.h"
00054 #include "diagnostic.h"
00055 #include "debug.h"
00056 #include "timevar.h"
00057 #include "input.h"
00058 #ifdef SGI_MONGOOSE
00059 #include "defaults.h"
00060 #endif
00061
00062 #ifdef KEY
00063 extern void add_duplicates (tree, tree);
00064 extern void gxx_emits_decl PARAMS ((tree));
00065 extern void push_mp_local_vars PARAMS ((tree));
00066 extern bool In_MP_Region;
00067 #endif
00068 static tree grokparms PARAMS ((tree));
00069 static const char *redeclaration_error_message PARAMS ((tree, tree));
00070
00071 static void push_binding_level PARAMS ((struct cp_binding_level *, int,
00072 int));
00073 static void pop_binding_level PARAMS ((void));
00074 static void suspend_binding_level PARAMS ((void));
00075 static void resume_binding_level PARAMS ((struct cp_binding_level *));
00076 static struct cp_binding_level *make_binding_level PARAMS ((void));
00077 static void declare_namespace_level PARAMS ((void));
00078 static int decl_jump_unsafe PARAMS ((tree));
00079 static void storedecls PARAMS ((tree));
00080 static void require_complete_types_for_parms PARAMS ((tree));
00081 static int ambi_op_p PARAMS ((enum tree_code));
00082 static int unary_op_p PARAMS ((enum tree_code));
00083 static cxx_saved_binding *store_bindings (tree, cxx_saved_binding *);
00084 static tree lookup_tag_reverse PARAMS ((tree, tree));
00085 static tree lookup_name_real PARAMS ((tree, int, int, int));
00086 static void push_local_name PARAMS ((tree));
00087 static void warn_extern_redeclared_static PARAMS ((tree, tree));
00088 static tree grok_reference_init PARAMS ((tree, tree, tree, tree *));
00089 static tree grokfndecl PARAMS ((tree, tree, tree, tree, int,
00090 enum overload_flags, tree,
00091 tree, int, int, int, int, int, int, tree));
00092 static tree grokvardecl PARAMS ((tree, tree, RID_BIT_TYPE *, int, int, tree));
00093 static tree follow_tag_typedef PARAMS ((tree));
00094 static tree lookup_tag PARAMS ((enum tree_code, tree,
00095 struct cp_binding_level *, int));
00096 static void set_identifier_type_value_with_scope
00097 PARAMS ((tree, tree, struct cp_binding_level *));
00098 static void record_unknown_type PARAMS ((tree, const char *));
00099 static tree builtin_function_1 PARAMS ((const char *, tree, tree, int,
00100 enum built_in_class, const char *,
00101 tree));
00102 static tree build_library_fn_1 PARAMS ((tree, enum tree_code, tree));
00103 static int member_function_or_else PARAMS ((tree, tree, enum overload_flags));
00104 static void bad_specifiers PARAMS ((tree, const char *, int, int, int, int,
00105 int));
00106 static tree maybe_process_template_type_declaration PARAMS ((tree, int, struct cp_binding_level*));
00107 static void check_for_uninitialized_const_var PARAMS ((tree));
00108 static hashval_t typename_hash PARAMS ((const void *));
00109 static int typename_compare PARAMS ((const void *, const void *));
00110 static void push_binding PARAMS ((tree, tree, struct cp_binding_level*));
00111 static int add_binding PARAMS ((tree, tree));
00112 static void pop_binding PARAMS ((tree, tree));
00113 static tree local_variable_p_walkfn PARAMS ((tree *, int *, void *));
00114 static cxx_binding *find_binding (tree, tree, cxx_binding *);
00115 static tree select_decl (cxx_binding *, int);
00116 static int lookup_flags PARAMS ((int, int));
00117 static tree qualify_lookup PARAMS ((tree, int));
00118 static tree record_builtin_java_type PARAMS ((const char *, int));
00119 static const char *tag_name PARAMS ((enum tag_types code));
00120 static void find_class_binding_level PARAMS ((void));
00121 static struct cp_binding_level *innermost_nonclass_level PARAMS ((void));
00122 static void warn_about_implicit_typename_lookup PARAMS ((tree, tree));
00123 static int walk_namespaces_r PARAMS ((tree, walk_namespaces_fn, void *));
00124 static int walk_globals_r PARAMS ((tree, void *));
00125 static int walk_vtables_r PARAMS ((tree, void*));
00126 static void add_decl_to_level PARAMS ((tree, struct cp_binding_level *));
00127 static tree make_label_decl PARAMS ((tree, int));
00128 static void use_label PARAMS ((tree));
00129 static void check_previous_goto_1 PARAMS ((tree, struct cp_binding_level *, tree,
00130 const char *, int));
00131 static void check_previous_goto PARAMS ((struct named_label_use_list *));
00132 static void check_switch_goto PARAMS ((struct cp_binding_level *));
00133 static void check_previous_gotos PARAMS ((tree));
00134 static void pop_label PARAMS ((tree, tree));
00135 static void pop_labels PARAMS ((tree));
00136 static void maybe_deduce_size_from_array_init PARAMS ((tree, tree));
00137 static void layout_var_decl PARAMS ((tree));
00138 static void maybe_commonize_var PARAMS ((tree));
00139 static tree check_initializer (tree, tree, int, tree *);
00140 static void make_rtl_for_nonlocal_decl PARAMS ((tree, tree, const char *));
00141 static void save_function_data PARAMS ((tree));
00142 static void check_function_type PARAMS ((tree, tree));
00143 static void begin_constructor_body PARAMS ((void));
00144 static void finish_constructor_body PARAMS ((void));
00145 static void begin_destructor_body PARAMS ((void));
00146 static void finish_destructor_body PARAMS ((void));
00147 static tree create_array_type_for_decl PARAMS ((tree, tree, tree));
00148 static tree get_atexit_node PARAMS ((void));
00149 static tree get_dso_handle_node PARAMS ((void));
00150 static tree start_cleanup_fn PARAMS ((void));
00151 static void end_cleanup_fn PARAMS ((void));
00152 static tree cp_make_fname_decl PARAMS ((tree, int));
00153 static void initialize_predefined_identifiers PARAMS ((void));
00154 static tree check_special_function_return_type
00155 PARAMS ((special_function_kind, tree, tree));
00156 static tree push_cp_library_fn PARAMS ((enum tree_code, tree));
00157 static tree build_cp_library_fn PARAMS ((tree, enum tree_code, tree));
00158 static void store_parm_decls PARAMS ((tree));
00159 static int cp_missing_noreturn_ok_p PARAMS ((tree));
00160 static void initialize_local_var (tree, tree);
00161 static void expand_static_init (tree, tree);
00162 static tree next_initializable_field (tree);
00163 static tree reshape_init (tree, tree *);
00164
00165
00166 tree error_mark_list;
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 tree cp_global_trees[CPTI_MAX];
00214
00215
00216
00217
00218 static GTY(()) tree global_type_node;
00219
00220
00221 static int only_namespace_names;
00222
00223
00224
00225
00226 struct named_label_use_list GTY(())
00227 {
00228 struct cp_binding_level *binding_level;
00229 tree names_in_scope;
00230 tree label_decl;
00231 const char *filename_o_goto;
00232 int lineno_o_goto;
00233 struct named_label_use_list *next;
00234 };
00235
00236 #define named_label_uses cp_function_chain->x_named_label_uses
00237
00238 #define local_names cp_function_chain->x_local_names
00239
00240
00241
00242
00243
00244 tree static_aggregates;
00245
00246
00247
00248
00249
00250 tree integer_two_node, integer_three_node;
00251
00252
00253 tree last_function_parms;
00254
00255
00256
00257
00258
00259 struct named_label_list GTY(())
00260 {
00261 struct cp_binding_level *binding_level;
00262 tree names_in_scope;
00263 tree old_value;
00264 tree label_decl;
00265 tree bad_decls;
00266 struct named_label_list *next;
00267 unsigned int in_try_scope : 1;
00268 unsigned int in_catch_scope : 1;
00269 };
00270
00271 #define named_labels cp_function_chain->x_named_labels
00272
00273
00274
00275 tree anonymous_namespace_name;
00276
00277
00278
00279
00280 int function_depth;
00281
00282
00283
00284
00285
00286
00287 enum deprecated_states {
00288 DEPRECATED_NORMAL,
00289 DEPRECATED_SUPPRESS
00290 };
00291
00292 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
00293
00294
00295
00296
00297 int adding_implicit_members = 0;
00298
00299
00300
00301 bool have_extern_spec;
00302
00303
00304
00305
00306
00307 #define ENTRY_INDEX(HASH, COUNT) (((HASH) >> 3) & ((COUNT) - 1))
00308
00309
00310 static GTY((deletable(""))) binding_entry free_binding_entry;
00311
00312
00313 static inline binding_entry
00314 binding_entry_make (tree name, tree type)
00315 {
00316 binding_entry entry;
00317
00318 if (free_binding_entry)
00319 {
00320 entry = free_binding_entry;
00321 free_binding_entry = entry->chain;
00322 }
00323 else
00324 entry = ggc_alloc (sizeof (struct binding_entry_s));
00325
00326 entry->name = name;
00327 entry->type = type;
00328
00329 return entry;
00330 }
00331
00332
00333 static inline void
00334 binding_entry_free (binding_entry entry)
00335 {
00336 entry->chain = free_binding_entry;
00337 free_binding_entry = entry;
00338 }
00339
00340
00341
00342 struct binding_table_s GTY(())
00343 {
00344
00345 binding_entry * GTY((length ("%h.chain_count"))) chain;
00346
00347
00348
00349 size_t chain_count;
00350
00351
00352 size_t entry_count;
00353 };
00354
00355
00356 #define SCOPE_DEFAULT_HT_SIZE (1 << 3)
00357 #define CLASS_SCOPE_HT_SIZE (1 << 3)
00358 #define NAMESPACE_ORDINARY_HT_SIZE (1 << 5)
00359 #define NAMESPACE_STD_HT_SIZE (1 << 8)
00360 #define GLOBAL_SCOPE_HT_SIZE (1 << 8)
00361
00362
00363 static inline void
00364 binding_table_construct (binding_table table, size_t chain_count)
00365 {
00366 table->chain_count = chain_count;
00367 table->entry_count = 0;
00368 table->chain = ggc_alloc_cleared
00369 (table->chain_count * sizeof (binding_entry));
00370 }
00371
00372
00373 static inline void
00374 binding_table_free (binding_table table)
00375 {
00376 size_t i;
00377 if (table == NULL)
00378 return;
00379
00380 for (i = 0; i < table->chain_count; ++i)
00381 {
00382 while (table->chain[i] != NULL)
00383 {
00384 binding_entry entry = table->chain[i];
00385 table->chain[i] = entry->chain;
00386 binding_entry_free (entry);
00387 }
00388 }
00389 table->entry_count = 0;
00390 }
00391
00392
00393 static inline binding_table
00394 binding_table_new (size_t chain_count)
00395 {
00396 binding_table table = ggc_alloc (sizeof (struct binding_table_s));
00397 binding_table_construct (table, chain_count);
00398 return table;
00399 }
00400
00401
00402 static void
00403 binding_table_expand (binding_table table)
00404 {
00405 const size_t old_chain_count = table->chain_count;
00406 const size_t old_entry_count = table->entry_count;
00407 const size_t new_chain_count = 2 * old_chain_count;
00408 binding_entry *old_chains = table->chain;
00409 size_t i;
00410
00411 binding_table_construct (table, new_chain_count);
00412 for (i = 0; i < old_chain_count; ++i)
00413 {
00414 binding_entry entry = old_chains[i];
00415 for (; entry != NULL; entry = old_chains[i])
00416 {
00417 const unsigned int hash = IDENTIFIER_HASH_VALUE (entry->name);
00418 const size_t j = ENTRY_INDEX (hash, new_chain_count);
00419
00420 old_chains[i] = entry->chain;
00421 entry->chain = table->chain[j];
00422 table->chain[j] = entry;
00423 }
00424 }
00425 table->entry_count = old_entry_count;
00426 }
00427
00428
00429 static inline void
00430 binding_table_insert (binding_table table, tree name, tree type)
00431 {
00432 const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
00433 const size_t i = ENTRY_INDEX (hash, table->chain_count);
00434 binding_entry entry = binding_entry_make (name, type);
00435
00436 entry->chain = table->chain[i];
00437 table->chain[i] = entry;
00438 ++table->entry_count;
00439
00440 if (3 * table->chain_count < 5 * table->entry_count)
00441 binding_table_expand (table);
00442 }
00443
00444
00445 binding_entry
00446 binding_table_find (binding_table table, tree name)
00447 {
00448 const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
00449 binding_entry entry = table->chain[ENTRY_INDEX (hash, table->chain_count)];
00450
00451 while (entry != NULL && entry->name != name)
00452 entry = entry->chain;
00453
00454 return entry;
00455 }
00456
00457
00458 static inline tree
00459 binding_table_find_anon_type (binding_table table, tree name)
00460 {
00461 const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
00462 binding_entry entry = table->chain[ENTRY_INDEX (hash, table->chain_count)];
00463
00464 while (entry != NULL && TYPE_IDENTIFIER (entry->type) != name)
00465 entry = entry->chain;
00466
00467 return entry ? entry->type : NULL;
00468 }
00469
00470
00471
00472 static inline binding_entry
00473 binding_table_reverse_maybe_remap (binding_table table, tree type, tree name)
00474 {
00475 const size_t chain_count = table->chain_count;
00476 binding_entry entry = NULL;
00477 binding_entry *p = NULL;
00478 size_t i;
00479
00480 for (i = 0; i < chain_count && entry == NULL; ++i)
00481 {
00482 p = &table->chain[i];
00483 while (*p != NULL && entry == NULL)
00484 if ((*p)->type == type)
00485 entry = *p;
00486 else
00487 p = &(*p)->chain;
00488 }
00489
00490 if (entry != NULL && name != NULL && entry->name != name)
00491 {
00492
00493 *p = (*p)->chain;
00494
00495
00496 i = ENTRY_INDEX (IDENTIFIER_HASH_VALUE (name), chain_count);
00497 entry->chain = table->chain[i];
00498 entry->name = name;
00499 table->chain[i] = entry;
00500 }
00501
00502 return entry;
00503 }
00504
00505
00506
00507 static void
00508 binding_table_remove_anonymous_types (binding_table table)
00509 {
00510 const size_t chain_count = table->chain_count;
00511 size_t i;
00512
00513 for (i = 0; i < chain_count; ++i)
00514 {
00515 binding_entry *p = &table->chain[i];
00516
00517 while (*p != NULL)
00518 if (ANON_AGGRNAME_P ((*p)->name))
00519 {
00520 binding_entry e = *p;
00521 *p = (*p)->chain;
00522 --table->entry_count;
00523 binding_entry_free (e);
00524 }
00525 else
00526 p = &(*p)->chain;
00527 }
00528 }
00529
00530
00531 void
00532 binding_table_foreach (binding_table table, bt_foreach_proc proc, void *data)
00533 {
00534 const size_t chain_count = table->chain_count;
00535 size_t i;
00536
00537 for (i = 0; i < chain_count; ++i)
00538 {
00539 binding_entry entry = table->chain[i];
00540 for (; entry != NULL; entry = entry->chain)
00541 proc (entry, data);
00542 }
00543 }
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570 struct cp_binding_level GTY(())
00571 {
00572
00573
00574
00575
00576 tree names;
00577
00578
00579 size_t names_size;
00580
00581
00582 tree namespaces;
00583
00584
00585 varray_type static_decls;
00586
00587
00588 tree vtables;
00589
00590
00591 binding_table type_decls;
00592
00593
00594 tree usings;
00595
00596
00597
00598 tree using_directives;
00599
00600
00601
00602
00603
00604 tree class_shadowed;
00605
00606
00607
00608
00609 tree type_shadowed;
00610
00611
00612
00613
00614 tree shadowed_labels;
00615
00616
00617
00618
00619 tree blocks;
00620
00621
00622 tree this_class;
00623
00624
00625 struct cp_binding_level *level_chain;
00626
00627
00628
00629
00630
00631 tree dead_vars_from_for;
00632
00633
00634
00635 unsigned parm_flag : 2;
00636
00637
00638
00639 unsigned keep : 2;
00640
00641
00642 unsigned tag_transparent : 1;
00643
00644
00645
00646 unsigned more_cleanups_ok : 1;
00647 unsigned have_cleanups : 1;
00648
00649
00650
00651
00652 unsigned template_parms_p : 1;
00653
00654
00655
00656
00657 unsigned template_spec_p : 1;
00658
00659
00660 unsigned namespace_p : 1;
00661
00662
00663
00664 unsigned is_for_scope : 1;
00665
00666
00667
00668 unsigned is_try_scope : 1;
00669
00670
00671
00672 unsigned is_catch_scope : 1;
00673
00674
00675
00676
00677 unsigned binding_depth;
00678 };
00679
00680 #define NULL_BINDING_LEVEL ((struct cp_binding_level *) NULL)
00681
00682
00683 #define global_scope_p(SCOPE) \
00684 ((SCOPE) == NAMESPACE_LEVEL (global_namespace))
00685
00686
00687
00688 #ifdef KEY
00689 static void inline
00690 copy_to_current_binding_level (struct cp_binding_level * level)
00691 {
00692 if (cfun && cp_function_chain->bindings)
00693 cp_function_chain->bindings = level;
00694 else
00695 scope_chain->bindings = level;
00696 }
00697 #endif // KEY
00698
00699 #define current_binding_level \
00700 (cfun && cp_function_chain->bindings \
00701 ? cp_function_chain->bindings \
00702 : scope_chain->bindings)
00703
00704
00705
00706 #define class_binding_level scope_chain->class_bindings
00707
00708
00709
00710 static GTY((deletable (""))) struct cp_binding_level *free_binding_level;
00711
00712
00713
00714 static int keep_next_level_flag;
00715
00716
00717
00718
00719
00720 static GTY(()) tree incomplete_vars;
00721
00722 #ifndef ENABLE_SCOPE_CHECKING
00723 # define ENABLE_SCOPE_CHECKING 0
00724 #else
00725 # define ENABLE_SCOPE_CHECKING 1
00726 #endif
00727
00728 static unsigned binding_depth = 0;
00729 static int is_class_level = 0;
00730
00731 static void
00732 indent (unsigned depth)
00733 {
00734 unsigned i;
00735
00736 for (i = 0; i < depth * 2; i++)
00737 putc (' ', stderr);
00738 }
00739
00740 static tree pushdecl_with_scope PARAMS ((tree, struct cp_binding_level *));
00741
00742 static void
00743 push_binding_level (newlevel, tag_transparent, keep)
00744 struct cp_binding_level *newlevel;
00745 int tag_transparent, keep;
00746 {
00747
00748
00749 memset ((char*) newlevel, 0, sizeof (struct cp_binding_level));
00750 newlevel->level_chain = current_binding_level;
00751 #ifdef KEY
00752 copy_to_current_binding_level (newlevel);
00753 #else
00754 current_binding_level = newlevel;
00755 #endif // KEY
00756 newlevel->tag_transparent = tag_transparent;
00757 newlevel->more_cleanups_ok = 1;
00758
00759 newlevel->keep = keep;
00760 if (ENABLE_SCOPE_CHECKING)
00761 {
00762 newlevel->binding_depth = binding_depth;
00763 indent (binding_depth);
00764 verbatim ("push %s level %p line %d\n",
00765 (is_class_level) ? "class" : "block",
00766 (void *) newlevel, lineno);
00767 is_class_level = 0;
00768 binding_depth++;
00769 }
00770 }
00771
00772
00773
00774
00775 static void
00776 find_class_binding_level ()
00777 {
00778 struct cp_binding_level *level = current_binding_level;
00779
00780 while (level && level->parm_flag != 2)
00781 level = level->level_chain;
00782 if (level && level->parm_flag == 2)
00783 class_binding_level = level;
00784 else
00785 class_binding_level = 0;
00786 }
00787
00788 static void
00789 pop_binding_level ()
00790 {
00791 if (NAMESPACE_LEVEL (global_namespace))
00792
00793 my_friendly_assert (!global_scope_p (current_binding_level), 20030527);
00794
00795 if (ENABLE_SCOPE_CHECKING)
00796 {
00797 indent (--binding_depth);
00798 verbatim ("pop %s level %p line %d\n",
00799 (is_class_level) ? "class" : "block",
00800 (void *) current_binding_level, lineno);
00801 if (is_class_level != (current_binding_level == class_binding_level))
00802 {
00803 indent (binding_depth);
00804 verbatim ("XXX is_class_level != (current_binding_level "
00805 "== class_binding_level)\n");
00806 }
00807 is_class_level = 0;
00808 }
00809 {
00810 register struct cp_binding_level *level = current_binding_level;
00811 #ifdef KEY
00812 copy_to_current_binding_level (current_binding_level->level_chain);
00813 #else
00814 current_binding_level = current_binding_level->level_chain;
00815 #endif // KEY
00816 level->level_chain = free_binding_level;
00817 if (level->parm_flag != 2)
00818 binding_table_free (level->type_decls);
00819 else
00820 level->type_decls = NULL;
00821 my_friendly_assert (!ENABLE_SCOPE_CHECKING
00822 || level->binding_depth == binding_depth, 20030529);
00823 free_binding_level = level;
00824 find_class_binding_level ();
00825 }
00826 }
00827
00828 static void
00829 suspend_binding_level ()
00830 {
00831 if (class_binding_level)
00832 {
00833 #ifdef KEY
00834 copy_to_current_binding_level (class_binding_level);
00835 #else
00836 current_binding_level = class_binding_level;
00837 #endif // KEY
00838 }
00839
00840 if (NAMESPACE_LEVEL (global_namespace))
00841 my_friendly_assert (!global_scope_p (current_binding_level), 20030527);
00842
00843 if (ENABLE_SCOPE_CHECKING)
00844 {
00845 indent (--binding_depth);
00846 verbatim("suspend %s level %p line %d\n",
00847 (is_class_level) ? "class" : "block",
00848 (void *) current_binding_level, lineno);
00849 if (is_class_level != (current_binding_level == class_binding_level))
00850 {
00851 indent (binding_depth);
00852 verbatim ("XXX is_class_level != (current_binding_level "
00853 "== class_binding_level)\n");
00854 }
00855 is_class_level = 0;
00856 }
00857 #ifdef KEY
00858 copy_to_current_binding_level (current_binding_level->level_chain);
00859 #else
00860 current_binding_level = current_binding_level->level_chain;
00861 #endif // KEY
00862 find_class_binding_level ();
00863 }
00864
00865 static void
00866 resume_binding_level (b)
00867 struct cp_binding_level *b;
00868 {
00869
00870
00871 my_friendly_assert(!class_binding_level, 386);
00872
00873 my_friendly_assert(b->level_chain == current_binding_level, 386);
00874 #ifdef KEY
00875 copy_to_current_binding_level (b);
00876 #else
00877 current_binding_level = b;
00878 #endif // KEY
00879 if (ENABLE_SCOPE_CHECKING)
00880 {
00881 b->binding_depth = binding_depth;
00882 indent (binding_depth);
00883 verbatim ("resume %s level %p line %d\n",
00884 (is_class_level) ? "class" : "block", (void *) b, lineno);
00885 is_class_level = 0;
00886 binding_depth++;
00887 }
00888 }
00889
00890
00891
00892 static
00893 struct cp_binding_level *
00894 make_binding_level ()
00895 {
00896
00897 return (struct cp_binding_level *) ggc_alloc (sizeof (struct cp_binding_level));
00898 }
00899
00900
00901
00902 int
00903 global_bindings_p ()
00904 {
00905 return global_scope_p (current_binding_level);
00906 }
00907
00908
00909
00910 static struct cp_binding_level *
00911 innermost_nonclass_level ()
00912 {
00913 struct cp_binding_level *b;
00914
00915 b = current_binding_level;
00916 while (b->parm_flag == 2)
00917 b = b->level_chain;
00918
00919 return b;
00920 }
00921
00922
00923
00924
00925
00926
00927
00928 int
00929 toplevel_bindings_p ()
00930 {
00931 struct cp_binding_level *b = innermost_nonclass_level ();
00932
00933 return b->namespace_p || b->template_parms_p;
00934 }
00935
00936
00937
00938
00939
00940 int
00941 namespace_bindings_p ()
00942 {
00943 struct cp_binding_level *b = innermost_nonclass_level ();
00944
00945 return b->namespace_p;
00946 }
00947
00948
00949
00950
00951
00952 void
00953 keep_next_level (keep)
00954 int keep;
00955 {
00956 keep_next_level_flag = keep;
00957 }
00958
00959
00960
00961 int
00962 kept_level_p ()
00963 {
00964 return (current_binding_level->blocks != NULL_TREE
00965 || current_binding_level->keep
00966 || current_binding_level->names != NULL_TREE
00967 || (current_binding_level->type_decls != NULL
00968 && !current_binding_level->tag_transparent));
00969 }
00970
00971
00972
00973 bool
00974 innermost_scope_is_class_p ()
00975 {
00976 return current_binding_level->parm_flag == 2;
00977 }
00978
00979 static void
00980 declare_namespace_level ()
00981 {
00982 current_binding_level->namespace_p = 1;
00983 }
00984
00985
00986
00987
00988 int
00989 template_parm_scope_p ()
00990 {
00991 return current_binding_level->template_parms_p;
00992 }
00993
00994
00995
00996
00997
00998 tmpl_spec_kind
00999 current_tmpl_spec_kind (n_class_scopes)
01000 int n_class_scopes;
01001 {
01002 int n_template_parm_scopes = 0;
01003 int seen_specialization_p = 0;
01004 int innermost_specialization_p = 0;
01005 struct cp_binding_level *b;
01006
01007
01008 for (b = current_binding_level; b->template_parms_p; b = b->level_chain)
01009 {
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019 if (b->template_spec_p)
01020 {
01021 if (n_template_parm_scopes == 0)
01022 innermost_specialization_p = 1;
01023 else
01024 seen_specialization_p = 1;
01025 }
01026 else if (seen_specialization_p == 1)
01027 return tsk_invalid_member_spec;
01028
01029 ++n_template_parm_scopes;
01030 }
01031
01032
01033 if (processing_explicit_instantiation)
01034 {
01035 if (n_template_parm_scopes != 0)
01036
01037
01038
01039
01040
01041
01042 return tsk_invalid_expl_inst;
01043 else
01044 return tsk_expl_inst;
01045 }
01046
01047 if (n_template_parm_scopes < n_class_scopes)
01048
01049
01050
01051
01052
01053
01054
01055 return tsk_insufficient_parms;
01056 else if (n_template_parm_scopes == n_class_scopes)
01057
01058
01059
01060
01061
01062
01063
01064 return tsk_none;
01065 else if (n_template_parm_scopes > n_class_scopes + 1)
01066
01067
01068
01069
01070
01071 return tsk_excessive_parms;
01072 else
01073
01074
01075
01076
01077
01078
01079
01080 return innermost_specialization_p ? tsk_expl_spec : tsk_template;
01081 }
01082
01083 void
01084 set_class_shadows (shadows)
01085 tree shadows;
01086 {
01087 class_binding_level->class_shadowed = shadows;
01088 }
01089
01090
01091
01092
01093
01094 void
01095 pushlevel (tag_transparent)
01096 int tag_transparent;
01097 {
01098 struct cp_binding_level *newlevel;
01099
01100 if (cfun && !doing_semantic_analysis_p ())
01101 return;
01102
01103
01104 if (!ENABLE_SCOPE_CHECKING && free_binding_level)
01105 {
01106 newlevel = free_binding_level;
01107 free_binding_level = free_binding_level->level_chain;
01108 }
01109 else
01110 newlevel = make_binding_level ();
01111
01112 push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
01113 keep_next_level_flag = 0;
01114 }
01115
01116
01117
01118
01119
01120 void
01121 maybe_push_cleanup_level (type)
01122 tree type;
01123 {
01124 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
01125 && current_binding_level->more_cleanups_ok == 0)
01126 {
01127 keep_next_level (2);
01128 pushlevel (1);
01129 clear_last_expr ();
01130 add_scope_stmt (1, 1);
01131 }
01132 }
01133
01134
01135
01136
01137 void
01138 begin_scope (sk)
01139 scope_kind sk;
01140 {
01141 pushlevel (0);
01142
01143 switch (sk)
01144 {
01145 case sk_template_spec:
01146 current_binding_level->template_spec_p = 1;
01147
01148
01149 case sk_template_parms:
01150 current_binding_level->template_parms_p = 1;
01151 break;
01152
01153 default:
01154 abort ();
01155 }
01156 }
01157
01158
01159
01160 void
01161 finish_scope ()
01162 {
01163 poplevel (0, 0, 0);
01164 }
01165
01166 void
01167 note_level_for_for ()
01168 {
01169 current_binding_level->is_for_scope = 1;
01170 }
01171
01172
01173
01174 void
01175 note_level_for_try ()
01176 {
01177 current_binding_level->is_try_scope = 1;
01178 }
01179
01180
01181
01182 void
01183 note_level_for_catch ()
01184 {
01185 current_binding_level->is_catch_scope = 1;
01186 }
01187
01188
01189
01190 #define BINDING_LEVEL(NODE) ((NODE)->scope.level)
01191
01192
01193
01194 static GTY((deletable (""))) cxx_binding *free_bindings;
01195
01196
01197
01198
01199 static void
01200 push_binding (id, decl, level)
01201 tree id;
01202 tree decl;
01203 struct cp_binding_level* level;
01204 {
01205 cxx_binding *binding;
01206
01207 if (free_bindings)
01208 {
01209 binding = free_bindings;
01210 free_bindings = binding->previous;
01211 }
01212 else
01213 binding = cxx_binding_make ();
01214
01215
01216 BINDING_VALUE (binding) = decl;
01217 BINDING_TYPE (binding) = NULL_TREE;
01218 BINDING_LEVEL (binding) = level;
01219 INHERITED_VALUE_BINDING_P (binding) = 0;
01220 LOCAL_BINDING_P (binding) = (level != class_binding_level);
01221 BINDING_HAS_LEVEL_P (binding) = 1;
01222
01223
01224 binding->previous = IDENTIFIER_BINDING (id);
01225 IDENTIFIER_BINDING (id) = binding;
01226 }
01227
01228
01229
01230
01231
01232
01233
01234 static int
01235 add_binding (id, decl)
01236 tree id;
01237 tree decl;
01238 {
01239 cxx_binding *binding = IDENTIFIER_BINDING (id);
01240 int ok = 1;
01241
01242 timevar_push (TV_NAME_LOOKUP);
01243 if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl))
01244
01245 BINDING_TYPE (binding) = decl;
01246 else if (!BINDING_VALUE (binding))
01247
01248
01249
01250 BINDING_VALUE (binding) = decl;
01251 else if (TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL
01252 && DECL_ARTIFICIAL (BINDING_VALUE (binding)))
01253 {
01254
01255
01256
01257
01258
01259 BINDING_TYPE (binding) = BINDING_VALUE (binding);
01260 BINDING_VALUE (binding) = decl;
01261 INHERITED_VALUE_BINDING_P (binding) = 0;
01262 }
01263 else if (TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL
01264 && TREE_CODE (decl) == TYPE_DECL
01265 && DECL_NAME (decl) == DECL_NAME (BINDING_VALUE (binding))
01266 && (same_type_p (TREE_TYPE (decl),
01267 TREE_TYPE (BINDING_VALUE (binding)))
01268
01269
01270 || uses_template_parms (TREE_TYPE (decl))
01271 || uses_template_parms (TREE_TYPE (BINDING_VALUE (binding)))))
01272
01273
01274
01275
01276
01277
01278
01279
01280 ok = 0;
01281
01282
01283
01284
01285
01286
01287
01288
01289 else if (TREE_CODE (decl) == VAR_DECL
01290 && TREE_CODE (BINDING_VALUE (binding)) == VAR_DECL
01291 && DECL_EXTERNAL (decl)
01292 && DECL_EXTERNAL (BINDING_VALUE (binding))
01293 && !DECL_CLASS_SCOPE_P (decl))
01294 {
01295 duplicate_decls (decl, BINDING_VALUE (binding));
01296 ok = 0;
01297 }
01298 else
01299 {
01300 error ("declaration of `%#D'", decl);
01301 cp_error_at ("conflicts with previous declaration `%#D'",
01302 BINDING_VALUE (binding));
01303 ok = 0;
01304 }
01305
01306 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ok);
01307 }
01308
01309
01310
01311 static void
01312 add_decl_to_level (decl, b)
01313 tree decl;
01314 struct cp_binding_level *b;
01315 {
01316 if (TREE_CODE (decl) == NAMESPACE_DECL
01317 && !DECL_NAMESPACE_ALIAS (decl))
01318 {
01319 TREE_CHAIN (decl) = b->namespaces;
01320 b->namespaces = decl;
01321 }
01322 else if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
01323 {
01324 TREE_CHAIN (decl) = b->vtables;
01325 b->vtables = decl;
01326 }
01327 else
01328 {
01329
01330
01331 TREE_CHAIN (decl) = b->names;
01332 b->names = decl;
01333 b->names_size++;
01334
01335
01336 if (b->namespace_p)
01337 if ((TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
01338 || (TREE_CODE (decl) == FUNCTION_DECL
01339 && (!TREE_PUBLIC (decl) || DECL_DECLARED_INLINE_P (decl))))
01340 VARRAY_PUSH_TREE (b->static_decls, decl);
01341 }
01342 }
01343
01344
01345
01346
01347
01348
01349 void
01350 push_local_binding (id, decl, flags)
01351 tree id;
01352 tree decl;
01353 int flags;
01354 {
01355 struct cp_binding_level *b;
01356
01357
01358
01359 b = current_binding_level;
01360 while (b->parm_flag == 2)
01361 b = b->level_chain;
01362
01363 if (lookup_name_current_level (id))
01364 {
01365
01366 if (!add_binding (id, decl))
01367
01368
01369
01370 return;
01371 }
01372 else
01373
01374 push_binding (id, decl, b);
01375
01376 if (TREE_CODE (decl) == OVERLOAD || (flags & PUSH_USING))
01377
01378
01379
01380 decl = build_tree_list (NULL_TREE, decl);
01381
01382
01383
01384 add_decl_to_level (decl, b);
01385 }
01386
01387
01388
01389
01390 int
01391 push_class_binding (id, decl)
01392 tree id;
01393 tree decl;
01394 {
01395 int result = 1;
01396 cxx_binding *binding = IDENTIFIER_BINDING (id);
01397 tree context;
01398
01399 timevar_push (TV_NAME_LOOKUP);
01400
01401
01402
01403 note_name_declared_in_class (id, decl);
01404
01405 if (binding && BINDING_LEVEL (binding) == class_binding_level)
01406
01407 result = add_binding (id, decl);
01408 else
01409
01410 push_binding (id, decl, class_binding_level);
01411
01412
01413
01414
01415
01416
01417 IDENTIFIER_CLASS_VALUE (id) = BINDING_VALUE (IDENTIFIER_BINDING (id));
01418
01419
01420 binding = IDENTIFIER_BINDING (id);
01421 if (BINDING_VALUE (binding) == decl && TREE_CODE (decl) != TREE_LIST)
01422 {
01423
01424
01425
01426
01427 if (IMPLICIT_TYPENAME_TYPE_DECL_P (decl))
01428 INHERITED_VALUE_BINDING_P (binding) = 1;
01429 else
01430 {
01431 if (TREE_CODE (decl) == OVERLOAD)
01432 context = CP_DECL_CONTEXT (OVL_CURRENT (decl));
01433 else
01434 {
01435 my_friendly_assert (DECL_P (decl), 0);
01436 context = context_for_name_lookup (decl);
01437 }
01438
01439 if (is_properly_derived_from (current_class_type, context))
01440 INHERITED_VALUE_BINDING_P (binding) = 1;
01441 else
01442 INHERITED_VALUE_BINDING_P (binding) = 0;
01443 }
01444 }
01445 else if (BINDING_VALUE (binding) == decl)
01446
01447
01448
01449 INHERITED_VALUE_BINDING_P (binding) = 1;
01450
01451 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, result);
01452 }
01453
01454
01455
01456
01457 static void
01458 pop_binding (id, decl)
01459 tree id;
01460 tree decl;
01461 {
01462 cxx_binding *binding;
01463
01464 if (id == NULL_TREE)
01465
01466
01467
01468 return;
01469
01470
01471 binding = IDENTIFIER_BINDING (id);
01472
01473
01474 my_friendly_assert (binding != NULL, 0);
01475
01476
01477
01478 if (BINDING_VALUE (binding) == decl)
01479 BINDING_VALUE (binding) = NULL_TREE;
01480 else if (BINDING_TYPE (binding) == decl)
01481 BINDING_TYPE (binding) = NULL_TREE;
01482 else
01483 abort ();
01484
01485 if (!BINDING_VALUE (binding) && !BINDING_TYPE (binding))
01486 {
01487
01488
01489 IDENTIFIER_BINDING (id) = binding->previous;
01490
01491
01492 binding->previous = free_bindings;
01493 free_bindings = binding;
01494
01495
01496
01497 BINDING_LEVEL (binding) = NULL;
01498 }
01499 }
01500
01501
01502
01503
01504 static void
01505 pop_label (label, old_value)
01506 tree label;
01507 tree old_value;
01508 {
01509 if (!processing_template_decl && doing_semantic_analysis_p ())
01510 {
01511 if (DECL_INITIAL (label) == NULL_TREE)
01512 {
01513 cp_error_at ("label `%D' used but not defined", label);
01514
01515 define_label (input_filename, 1, DECL_NAME (label));
01516 }
01517 else if (warn_unused_label && !TREE_USED (label))
01518 cp_warning_at ("label `%D' defined but not used", label);
01519 }
01520
01521 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value);
01522 }
01523
01524
01525
01526
01527
01528 static void
01529 pop_labels (block)
01530 tree block;
01531 {
01532 struct named_label_list *link;
01533
01534
01535
01536 for (link = named_labels; link; link = link->next)
01537 {
01538 pop_label (link->label_decl, link->old_value);
01539
01540
01541 TREE_CHAIN (link->label_decl) = BLOCK_VARS (block);
01542 BLOCK_VARS (block) = link->label_decl;
01543 }
01544
01545 named_labels = NULL;
01546 }
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563 tree
01564 poplevel (keep, reverse, functionbody)
01565 int keep;
01566 int reverse;
01567 int functionbody;
01568 {
01569 register tree link;
01570
01571
01572 tree decls;
01573 int tmp = functionbody;
01574 int real_functionbody;
01575 tree subblocks;
01576 tree block = NULL_TREE;
01577 tree decl;
01578 int leaving_for_scope;
01579
01580 timevar_push (TV_NAME_LOOKUP);
01581
01582 if (cfun && !doing_semantic_analysis_p ())
01583 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
01584
01585 my_friendly_assert (current_binding_level->parm_flag != 2,
01586 19990916);
01587
01588 real_functionbody = (current_binding_level->keep == 2
01589 ? ((functionbody = 0), tmp) : functionbody);
01590 subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
01591
01592 my_friendly_assert (!current_binding_level->class_shadowed,
01593 19990414);
01594
01595
01596
01597
01598 my_friendly_assert (keep == 0 || keep == 1, 0);
01599
01600 if (current_binding_level->keep == 1)
01601 keep = 1;
01602
01603
01604
01605 if (cfun && !functionbody)
01606 {
01607 struct cp_binding_level *level_chain;
01608 level_chain = current_binding_level->level_chain;
01609 if (level_chain)
01610 {
01611 struct named_label_use_list *uses;
01612 struct named_label_list *labels;
01613 for (labels = named_labels; labels; labels = labels->next)
01614 if (labels->binding_level == current_binding_level)
01615 {
01616 tree decl;
01617 if (current_binding_level->is_try_scope)
01618 labels->in_try_scope = 1;
01619 if (current_binding_level->is_catch_scope)
01620 labels->in_catch_scope = 1;
01621 for (decl = labels->names_in_scope; decl;
01622 decl = TREE_CHAIN (decl))
01623 if (decl_jump_unsafe (decl))
01624 labels->bad_decls = tree_cons (NULL_TREE, decl,
01625 labels->bad_decls);
01626 labels->binding_level = level_chain;
01627 labels->names_in_scope = level_chain->names;
01628 }
01629
01630 for (uses = named_label_uses; uses; uses = uses->next)
01631 if (uses->binding_level == current_binding_level)
01632 {
01633 uses->binding_level = level_chain;
01634 uses->names_in_scope = level_chain->names;
01635 }
01636 }
01637 }
01638
01639
01640
01641
01642
01643 if (reverse)
01644 current_binding_level->names
01645 = decls = nreverse (current_binding_level->names);
01646 else
01647 decls = current_binding_level->names;
01648
01649
01650
01651 for (decl = decls; decl; decl = TREE_CHAIN (decl))
01652 if (TREE_CODE (decl) == FUNCTION_DECL
01653 && ! TREE_ASM_WRITTEN (decl)
01654 && DECL_INITIAL (decl) != NULL_TREE
01655 && TREE_ADDRESSABLE (decl)
01656 && decl_function_context (decl) == current_function_decl)
01657 {
01658
01659
01660
01661 if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
01662 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
01663 else
01664 {
01665 push_function_context ();
01666 output_inline_function (decl);
01667 pop_function_context ();
01668 }
01669 }
01670
01671
01672
01673
01674
01675
01676 if (!processing_template_decl)
01677 warn_about_unused_variables (getdecls ());
01678
01679
01680
01681
01682 block = NULL_TREE;
01683 if (keep == 1 || functionbody)
01684 block = make_node (BLOCK);
01685 if (block != NULL_TREE)
01686 {
01687 BLOCK_VARS (block) = decls;
01688 BLOCK_SUBBLOCKS (block) = subblocks;
01689 }
01690
01691
01692 if (keep >= 0)
01693 for (link = subblocks; link; link = TREE_CHAIN (link))
01694 BLOCK_SUPERCONTEXT (link) = block;
01695
01696
01697
01698
01699
01700 leaving_for_scope
01701 = current_binding_level->is_for_scope && flag_new_for_scope == 1;
01702
01703
01704 for (link = decls; link; link = TREE_CHAIN (link))
01705 {
01706 if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
01707 && DECL_NAME (link))
01708 {
01709 cxx_binding *outer_binding
01710 = IDENTIFIER_BINDING (DECL_NAME (link))->previous;
01711 tree ns_binding;
01712
01713 if (!outer_binding)
01714 ns_binding = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (link));
01715 else
01716 ns_binding = NULL_TREE;
01717
01718 if (outer_binding
01719 && (BINDING_LEVEL (outer_binding)
01720 == current_binding_level->level_chain))
01721
01722
01723
01724
01725
01726
01727
01728 pop_binding (DECL_NAME (link), link);
01729 else if ((outer_binding
01730 && (TREE_CODE (BINDING_VALUE (outer_binding))
01731 == TYPE_DECL))
01732 || (ns_binding
01733 && TREE_CODE (ns_binding) == TYPE_DECL))
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744 pop_binding (DECL_NAME (link), link);
01745 else
01746 {
01747
01748
01749 DECL_DEAD_FOR_LOCAL (link) = 1;
01750
01751
01752
01753 if (outer_binding && BINDING_VALUE (outer_binding))
01754 DECL_SHADOWED_FOR_VAR (link)
01755 = BINDING_VALUE (outer_binding);
01756
01757
01758
01759
01760 current_binding_level->level_chain->dead_vars_from_for
01761 = tree_cons (NULL_TREE, link,
01762 current_binding_level->level_chain->
01763 dead_vars_from_for);
01764
01765
01766
01767 BINDING_LEVEL (IDENTIFIER_BINDING (DECL_NAME (link)))
01768 = 0;
01769 }
01770 }
01771 else
01772 {
01773
01774 decl = link;
01775 if (TREE_CODE (decl) == TREE_LIST)
01776 decl = TREE_VALUE (decl);
01777 if (DECL_P (decl))
01778 pop_binding (DECL_NAME (decl), decl);
01779 else if (TREE_CODE (decl) == OVERLOAD)
01780 pop_binding (DECL_NAME (OVL_FUNCTION (decl)), decl);
01781 else
01782 abort ();
01783 }
01784 }
01785
01786
01787
01788 for (link = current_binding_level->dead_vars_from_for;
01789 link; link = TREE_CHAIN (link))
01790 pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link));
01791
01792
01793 for (link = current_binding_level->type_shadowed;
01794 link; link = TREE_CHAIN (link))
01795 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
01796
01797
01798 for (link = current_binding_level->shadowed_labels;
01799 link;
01800 link = TREE_CHAIN (link))
01801 pop_label (TREE_VALUE (link), TREE_PURPOSE (link));
01802
01803
01804
01805
01806
01807
01808
01809 if (block)
01810 {
01811 tree* d;
01812
01813 for (d = &BLOCK_VARS (block); *d; )
01814 {
01815 if (TREE_CODE (*d) == TREE_LIST)
01816 *d = TREE_CHAIN (*d);
01817 else
01818 d = &TREE_CHAIN (*d);
01819 }
01820 }
01821
01822
01823
01824 if (functionbody)
01825 {
01826
01827
01828
01829 BLOCK_VARS (block) = 0;
01830 pop_labels (block);
01831 }
01832
01833 tmp = current_binding_level->keep;
01834
01835 pop_binding_level ();
01836 if (functionbody)
01837 DECL_INITIAL (current_function_decl) = block;
01838 else if (block)
01839 current_binding_level->blocks
01840 = chainon (current_binding_level->blocks, block);
01841
01842
01843
01844
01845
01846
01847 else if (subblocks)
01848 current_binding_level->blocks
01849 = chainon (current_binding_level->blocks, subblocks);
01850
01851
01852
01853
01854 if (block)
01855 TREE_USED (block) = 1;
01856
01857
01858 if (tmp == 2)
01859 {
01860 tree scope_stmts;
01861
01862 scope_stmts
01863 = add_scope_stmt (0, 1);
01864 if (block)
01865 {
01866 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
01867 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
01868 }
01869
01870 block = poplevel (keep, reverse, functionbody);
01871 }
01872
01873 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, block);
01874 }
01875
01876
01877
01878
01879
01880 void
01881 delete_block (block)
01882 tree block;
01883 {
01884 tree t;
01885 if (current_binding_level->blocks == block)
01886 current_binding_level->blocks = TREE_CHAIN (block);
01887 for (t = current_binding_level->blocks; t;)
01888 {
01889 if (TREE_CHAIN (t) == block)
01890 TREE_CHAIN (t) = TREE_CHAIN (block);
01891 else
01892 t = TREE_CHAIN (t);
01893 }
01894 TREE_CHAIN (block) = NULL_TREE;
01895
01896
01897 TREE_USED (block) = 0;
01898 }
01899
01900
01901
01902
01903
01904 void
01905 insert_block (block)
01906 tree block;
01907 {
01908 TREE_USED (block) = 1;
01909 current_binding_level->blocks
01910 = chainon (current_binding_level->blocks, block);
01911 }
01912
01913
01914
01915
01916 void
01917 set_block (block)
01918 tree block ATTRIBUTE_UNUSED;
01919 {
01920
01921
01922 my_friendly_assert (cfun && !doing_semantic_analysis_p (), 20000911);
01923 }
01924
01925
01926
01927 void
01928 pushlevel_class ()
01929 {
01930 register struct cp_binding_level *newlevel;
01931
01932
01933 if (!ENABLE_SCOPE_CHECKING && free_binding_level)
01934 {
01935 newlevel = free_binding_level;
01936 free_binding_level = free_binding_level->level_chain;
01937 }
01938 else
01939 newlevel = make_binding_level ();
01940
01941 if (ENABLE_SCOPE_CHECKING)
01942 is_class_level = 1;
01943
01944 push_binding_level (newlevel, 0, 0);
01945
01946 class_binding_level = current_binding_level;
01947 class_binding_level->parm_flag = 2;
01948 class_binding_level->this_class = current_class_type;
01949 }
01950
01951
01952
01953 void
01954 poplevel_class ()
01955 {
01956 register struct cp_binding_level *level = class_binding_level;
01957 tree shadowed;
01958
01959 timevar_push (TV_NAME_LOOKUP);
01960
01961 my_friendly_assert (level != 0, 354);
01962
01963
01964
01965
01966
01967
01968 if (current_class_depth != 1)
01969 {
01970 struct cp_binding_level* b;
01971
01972
01973 for (shadowed = level->class_shadowed;
01974 shadowed;
01975 shadowed = TREE_CHAIN (shadowed))
01976 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = NULL_TREE;
01977
01978
01979
01980 b = level->level_chain;
01981 while (b && b->parm_flag != 2)
01982 b = b->level_chain;
01983
01984 if (b)
01985 for (shadowed = b->class_shadowed;
01986 shadowed;
01987 shadowed = TREE_CHAIN (shadowed))
01988 {
01989 cxx_binding *binding;
01990
01991 binding = IDENTIFIER_BINDING (TREE_PURPOSE (shadowed));
01992 while (binding && BINDING_LEVEL (binding) != b)
01993 binding = binding->previous;
01994
01995 if (binding)
01996 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed))
01997 = BINDING_VALUE (binding);
01998 }
01999 }
02000 else
02001
02002
02003 {
02004 previous_class_type = current_class_type;
02005 previous_class_values = class_binding_level->class_shadowed;
02006 }
02007 for (shadowed = level->type_shadowed;
02008 shadowed;
02009 shadowed = TREE_CHAIN (shadowed))
02010 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed));
02011
02012
02013 for (shadowed = level->class_shadowed;
02014 shadowed;
02015 shadowed = TREE_CHAIN (shadowed))
02016 pop_binding (TREE_PURPOSE (shadowed), TREE_TYPE (shadowed));
02017
02018
02019
02020 if (ENABLE_SCOPE_CHECKING)
02021 is_class_level = 1;
02022
02023 pop_binding_level ();
02024
02025 timevar_pop (TV_NAME_LOOKUP);
02026 }
02027
02028
02029
02030
02031 void
02032 clear_identifier_class_values ()
02033 {
02034 tree t;
02035
02036 if (!class_binding_level)
02037 return;
02038
02039 for (t = class_binding_level->class_shadowed;
02040 t;
02041 t = TREE_CHAIN (t))
02042 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
02043 }
02044
02045
02046
02047 int
02048 vtable_decl_p (t, data)
02049 tree t;
02050 void *data ATTRIBUTE_UNUSED;
02051 {
02052 return (TREE_CODE (t) == VAR_DECL && DECL_VIRTUAL_P (t));
02053 }
02054
02055
02056
02057
02058 int
02059 vtype_decl_p (t, data)
02060 tree t;
02061 void *data ATTRIBUTE_UNUSED;
02062 {
02063 return (TREE_CODE (t) == TYPE_DECL
02064 && TREE_CODE (TREE_TYPE (t)) == RECORD_TYPE
02065 && TYPE_POLYMORPHIC_P (TREE_TYPE (t)));
02066 }
02067
02068
02069
02070 tree
02071 cp_namespace_decls (ns)
02072 tree ns;
02073 {
02074 return NAMESPACE_LEVEL (ns)->names;
02075 }
02076
02077 struct walk_globals_data {
02078 walk_globals_pred p;
02079 walk_globals_fn f;
02080 void *data;
02081 };
02082
02083
02084
02085
02086
02087 static int
02088 walk_vtables_r (namespace, data)
02089 tree namespace;
02090 void *data;
02091 {
02092 struct walk_globals_data* wgd = (struct walk_globals_data *) data;
02093 walk_globals_fn f = wgd->f;
02094 void *d = wgd->data;
02095 tree decl = NAMESPACE_LEVEL (namespace)->vtables;
02096 int result = 0;
02097
02098 for (; decl ; decl = TREE_CHAIN (decl))
02099 result |= (*f) (&decl, d);
02100
02101 return result;
02102 }
02103
02104
02105
02106
02107 int
02108 walk_vtables (p, f, data)
02109 walk_globals_pred p;
02110 walk_globals_fn f;
02111 void *data;
02112 {
02113 struct walk_globals_data wgd;
02114 wgd.p = p;
02115 wgd.f = f;
02116 wgd.data = data;
02117
02118 return walk_namespaces (walk_vtables_r, &wgd);
02119 }
02120
02121
02122
02123
02124 static int
02125 walk_namespaces_r (namespace, f, data)
02126 tree namespace;
02127 walk_namespaces_fn f;
02128 void *data;
02129 {
02130 int result = 0;
02131 tree current = NAMESPACE_LEVEL (namespace)->namespaces;
02132
02133 result |= (*f) (namespace, data);
02134
02135 for (; current; current = TREE_CHAIN (current))
02136 result |= walk_namespaces_r (current, f, data);
02137
02138 return result;
02139 }
02140
02141
02142
02143
02144 int
02145 walk_namespaces (f, data)
02146 walk_namespaces_fn f;
02147 void *data;
02148 {
02149 return walk_namespaces_r (global_namespace, f, data);
02150 }
02151
02152
02153
02154
02155
02156 static int
02157 walk_globals_r (namespace, data)
02158 tree namespace;
02159 void *data;
02160 {
02161 struct walk_globals_data* wgd = (struct walk_globals_data *) data;
02162 walk_globals_pred p = wgd->p;
02163 walk_globals_fn f = wgd->f;
02164 void *d = wgd->data;
02165 tree *t;
02166 int result = 0;
02167
02168 t = &NAMESPACE_LEVEL (namespace)->names;
02169
02170 while (*t)
02171 {
02172 tree glbl = *t;
02173
02174 if ((*p) (glbl, d))
02175 result |= (*f) (t, d);
02176
02177
02178
02179 if (*t == glbl)
02180 t = &TREE_CHAIN (*t);
02181 }
02182
02183 return result;
02184 }
02185
02186
02187
02188
02189
02190 int
02191 walk_globals (p, f, data)
02192 walk_globals_pred p;
02193 walk_globals_fn f;
02194 void *data;
02195 {
02196 struct walk_globals_data wgd;
02197 wgd.p = p;
02198 wgd.f = f;
02199 wgd.data = data;
02200
02201 return walk_namespaces (walk_globals_r, &wgd);
02202 }
02203
02204
02205
02206
02207
02208 int
02209 wrapup_globals_for_namespace (namespace, data)
02210 tree namespace;
02211 void *data;
02212 {
02213 struct cp_binding_level *level = NAMESPACE_LEVEL (namespace);
02214 varray_type statics = level->static_decls;
02215 tree *vec = &VARRAY_TREE (statics, 0);
02216 int len = VARRAY_ACTIVE_SIZE (statics);
02217 int last_time = (data != 0);
02218
02219 if (last_time)
02220 {
02221 check_global_declarations (vec, len);
02222 return 0;
02223 }
02224
02225
02226 return wrapup_global_declarations (vec, len);
02227 }
02228
02229
02230
02231 static int no_print_functions = 0;
02232 static int no_print_builtins = 0;
02233
02234
02235
02236
02237 static void
02238 bt_print_entry (binding_entry entry, void *data)
02239 {
02240 int *p = (int *) data;
02241 int len;
02242
02243 if (entry->name == NULL)
02244 len = 3;
02245 else if (entry->name == TYPE_IDENTIFIER (entry->type))
02246 len = 2;
02247 else
02248 len = 4;
02249
02250 *p += len;
02251
02252 if (*p > 5)
02253 {
02254 fprintf (stderr, "\n\t");
02255 *p = len;
02256 }
02257 if (entry->name == NULL)
02258 {
02259 print_node_brief (stderr, "<unnamed-typedef", entry->type, 0);
02260 fprintf (stderr, ">");
02261 }
02262 else if (entry->name == TYPE_IDENTIFIER (entry->type))
02263 print_node_brief (stderr, "", entry->type, 0);
02264 else
02265 {
02266 print_node_brief (stderr, "<typedef", entry->name, 0);
02267 print_node_brief (stderr, "", entry->type, 0);
02268 fprintf (stderr, ">");
02269 }
02270 }
02271
02272 void
02273 print_binding_level (lvl)
02274 struct cp_binding_level *lvl;
02275 {
02276 tree t;
02277 int i = 0, len;
02278 fprintf (stderr, " blocks=");
02279 fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
02280 if (lvl->tag_transparent)
02281 fprintf (stderr, " tag-transparent");
02282 if (lvl->more_cleanups_ok)
02283 fprintf (stderr, " more-cleanups-ok");
02284 if (lvl->have_cleanups)
02285 fprintf (stderr, " have-cleanups");
02286 fprintf (stderr, "\n");
02287 if (lvl->names)
02288 {
02289 fprintf (stderr, " names:\t");
02290
02291 for (t = lvl->names; t; t = TREE_CHAIN (t))
02292 {
02293 if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL))
02294 continue;
02295 if (no_print_builtins
02296 && (TREE_CODE (t) == TYPE_DECL)
02297 && (!strcmp (DECL_SOURCE_FILE (t),"<built-in>")))
02298 continue;
02299
02300
02301 if (TREE_CODE (t) == FUNCTION_DECL)
02302 len = 3;
02303 else
02304 len = 2;
02305 i += len;
02306 if (i > 6)
02307 {
02308 fprintf (stderr, "\n\t");
02309 i = len;
02310 }
02311 print_node_brief (stderr, "", t, 0);
02312 if (t == error_mark_node)
02313 break;
02314 }
02315 if (i)
02316 fprintf (stderr, "\n");
02317 }
02318 if (lvl->type_decls)
02319 {
02320 fprintf (stderr, " tags:\t");
02321 i = 0;
02322 binding_table_foreach (lvl->type_decls, bt_print_entry, &i);
02323 if (i)
02324 fprintf (stderr, "\n");
02325 }
02326 if (lvl->class_shadowed)
02327 {
02328 fprintf (stderr, " class-shadowed:");
02329 for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
02330 {
02331 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
02332 }
02333 fprintf (stderr, "\n");
02334 }
02335 if (lvl->type_shadowed)
02336 {
02337 fprintf (stderr, " type-shadowed:");
02338 for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
02339 {
02340 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
02341 }
02342 fprintf (stderr, "\n");
02343 }
02344 }
02345
02346 void
02347 print_other_binding_stack (stack)
02348 struct cp_binding_level *stack;
02349 {
02350 struct cp_binding_level *level;
02351 for (level = stack; !global_scope_p (level); level = level->level_chain)
02352 {
02353 fprintf (stderr, "binding level ");
02354 fprintf (stderr, HOST_PTR_PRINTF, level);
02355 fprintf (stderr, "\n");
02356 print_binding_level (level);
02357 }
02358 }
02359
02360 void
02361 print_binding_stack ()
02362 {
02363 struct cp_binding_level *b;
02364 fprintf (stderr, "current_binding_level=");
02365 fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
02366 fprintf (stderr, "\nclass_binding_level=");
02367 fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
02368 fprintf (stderr, "\nNAMESPACE_LEVEL (global_namespace)=");
02369 fprintf (stderr, HOST_PTR_PRINTF,
02370 (void *) NAMESPACE_LEVEL (global_namespace));
02371 fprintf (stderr, "\n");
02372 if (class_binding_level)
02373 {
02374 for (b = class_binding_level; b; b = b->level_chain)
02375 if (b == current_binding_level)
02376 break;
02377 if (b)
02378 b = class_binding_level;
02379 else
02380 b = current_binding_level;
02381 }
02382 else
02383 b = current_binding_level;
02384 print_other_binding_stack (b);
02385 fprintf (stderr, "global:\n");
02386 print_binding_level (NAMESPACE_LEVEL (global_namespace));
02387 }
02388
02389
02390
02391
02392
02393
02394 static inline cxx_binding *
02395 find_binding (tree name, tree scope, cxx_binding *front)
02396 {
02397 cxx_binding *iter;
02398 cxx_binding *prev = NULL;
02399
02400 timevar_push (TV_NAME_LOOKUP);
02401
02402 for (iter = front; iter; iter = iter->previous)
02403 {
02404 if (BINDING_SCOPE (iter) == scope)
02405 {
02406
02407
02408 if (prev)
02409 {
02410 prev->previous = iter->previous;
02411 iter->previous = front;
02412 IDENTIFIER_NAMESPACE_BINDINGS (name) = iter;
02413 }
02414 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, iter);
02415 }
02416 prev = iter;
02417 }
02418 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL);
02419 }
02420
02421
02422 cxx_binding *
02423 cxx_scope_find_binding_for_name (tree scope, tree name)
02424 {
02425 cxx_binding *b = IDENTIFIER_NAMESPACE_BINDINGS (name);
02426 if (b)
02427 {
02428 scope = ORIGINAL_NAMESPACE (scope);
02429
02430 if (scope == BINDING_SCOPE (b) && b->previous == NULL)
02431 return b;
02432 return find_binding (name, scope, b);
02433 }
02434 return b;
02435 }
02436
02437
02438
02439
02440
02441 cxx_binding *
02442 binding_for_name (tree name, tree scope)
02443 {
02444 cxx_binding *result;
02445
02446 scope = ORIGINAL_NAMESPACE (scope);
02447 result = cxx_scope_find_binding_for_name (scope, name);
02448 if (result)
02449 return result;
02450
02451 result = cxx_binding_make ();
02452 result->previous = IDENTIFIER_NAMESPACE_BINDINGS (name);
02453 BINDING_TYPE (result) = NULL_TREE;
02454 BINDING_VALUE (result) = NULL_TREE;
02455 BINDING_SCOPE (result) = scope;
02456 result->is_local = false;
02457 result->value_is_inherited = false;
02458 result->has_level = false;
02459 IDENTIFIER_NAMESPACE_BINDINGS (name) = result;
02460 return result;
02461 }
02462
02463
02464
02465 tree
02466 namespace_binding (tree name, tree scope)
02467 {
02468 cxx_binding *b =
02469 cxx_scope_find_binding_for_name (scope ? scope : global_namespace, name);
02470
02471 return b ? b->value : NULL_TREE;
02472 }
02473
02474
02475
02476 void
02477 set_namespace_binding (name, scope, val)
02478 tree name;
02479 tree scope;
02480 tree val;
02481 {
02482 cxx_binding *b;
02483
02484 timevar_push (TV_NAME_LOOKUP);
02485 if (scope == NULL_TREE)
02486 scope = global_namespace;
02487
02488 b = binding_for_name (name, scope);
02489 BINDING_VALUE (b) = val;
02490 timevar_pop (TV_NAME_LOOKUP);
02491 }
02492
02493
02494
02495
02496 void
02497 push_namespace (name)
02498 tree name;
02499 {
02500 tree d = NULL_TREE;
02501 int need_new = 1;
02502 int implicit_use = 0;
02503 int global = 0;
02504
02505 timevar_push (TV_NAME_LOOKUP);
02506
02507 if (!global_namespace)
02508 {
02509
02510 my_friendly_assert (name == get_identifier ("::"), 377);
02511 global = 1;
02512 }
02513 else if (!name)
02514 {
02515
02516
02517 if (!anonymous_namespace_name)
02518 anonymous_namespace_name = get_file_function_name ('N');
02519 name = anonymous_namespace_name;
02520 d = IDENTIFIER_NAMESPACE_VALUE (name);
02521 if (d)
02522
02523 need_new = 0;
02524 implicit_use = 1;
02525 }
02526 else
02527 {
02528
02529 d = IDENTIFIER_NAMESPACE_VALUE (name);
02530 if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL)
02531 {
02532 need_new = 0;
02533 if (DECL_NAMESPACE_ALIAS (d))
02534 {
02535 error ("namespace alias `%D' not allowed here, assuming `%D'",
02536 d, DECL_NAMESPACE_ALIAS (d));
02537 d = DECL_NAMESPACE_ALIAS (d);
02538 }
02539 }
02540 }
02541
02542 if (need_new)
02543 {
02544
02545 d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
02546
02547 #ifdef KEY
02548
02549 gxx_emits_decl (d);
02550 #endif
02551
02552
02553
02554 if (!global)
02555 {
02556 DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace);
02557 d = pushdecl (d);
02558 pushlevel (0);
02559 declare_namespace_level ();
02560 NAMESPACE_LEVEL (d) = current_binding_level;
02561 current_binding_level->type_decls =
02562 binding_table_new (name == std_identifier
02563 ? NAMESPACE_STD_HT_SIZE
02564 : NAMESPACE_ORDINARY_HT_SIZE);
02565 VARRAY_TREE_INIT (current_binding_level->static_decls,
02566 name != std_identifier ? 10 : 200,
02567 "Static declarations");
02568 }
02569 }
02570 else
02571 resume_binding_level (NAMESPACE_LEVEL (d));
02572
02573 if (implicit_use)
02574 do_using_directive (d);
02575
02576 current_namespace = d;
02577
02578 timevar_pop (TV_NAME_LOOKUP);
02579 }
02580
02581
02582
02583 void
02584 pop_namespace ()
02585 {
02586 my_friendly_assert (current_namespace != global_namespace, 20010801);
02587 current_namespace = CP_DECL_CONTEXT (current_namespace);
02588
02589 suspend_binding_level ();
02590 }
02591
02592
02593
02594
02595 void
02596 push_nested_namespace (ns)
02597 tree ns;
02598 {
02599 if (ns == global_namespace)
02600 push_to_top_level ();
02601 else
02602 {
02603 push_nested_namespace (CP_DECL_CONTEXT (ns));
02604 push_namespace (DECL_NAME (ns));
02605 }
02606 }
02607
02608
02609
02610
02611 void
02612 pop_nested_namespace (ns)
02613 tree ns;
02614 {
02615 timevar_push (TV_NAME_LOOKUP);
02616 while (ns != global_namespace)
02617 {
02618 pop_namespace ();
02619 ns = CP_DECL_CONTEXT (ns);
02620 }
02621
02622 pop_from_top_level ();
02623 timevar_pop (TV_NAME_LOOKUP);
02624 }
02625
02626
02627
02628 #define cxx_saved_binding_make() \
02629 (ggc_alloc (sizeof (cxx_saved_binding)))
02630
02631 struct cxx_saved_binding GTY(())
02632 {
02633
02634 cxx_saved_binding *previous;
02635
02636 tree identifier;
02637
02638 cxx_binding *binding;
02639 tree class_value;
02640 tree real_type_value;
02641 };
02642
02643
02644
02645
02646
02647
02648 struct saved_scope *scope_chain;
02649
02650 static cxx_saved_binding *
02651 store_bindings (tree names, cxx_saved_binding *old_bindings)
02652 {
02653 tree t;
02654 cxx_saved_binding *search_bindings = old_bindings;
02655
02656 timevar_push (TV_NAME_LOOKUP);
02657 for (t = names; t; t = TREE_CHAIN (t))
02658 {
02659 tree id;
02660 cxx_saved_binding *saved;
02661 cxx_saved_binding *t1;
02662
02663 if (TREE_CODE (t) == TREE_LIST)
02664 id = TREE_PURPOSE (t);
02665 else
02666 id = DECL_NAME (t);
02667
02668 if (!id
02669
02670
02671
02672 || !(IDENTIFIER_BINDING (id) || IDENTIFIER_CLASS_VALUE (id)))
02673 continue;
02674
02675 for (t1 = search_bindings; t1; t1 = t1->previous)
02676 if (t1->identifier == id)
02677 goto skip_it;
02678
02679 my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
02680 saved = cxx_saved_binding_make ();
02681 saved->previous = old_bindings;
02682 saved->identifier = id;
02683 saved->binding = IDENTIFIER_BINDING (id);
02684 saved->class_value = IDENTIFIER_CLASS_VALUE (id);;
02685 saved->real_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
02686 IDENTIFIER_BINDING (id) = NULL;
02687 IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
02688 old_bindings = saved;
02689 skip_it:
02690 ;
02691 }
02692 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, old_bindings);
02693 }
02694
02695 void
02696 maybe_push_to_top_level (pseudo)
02697 int pseudo;
02698 {
02699 struct saved_scope *s;
02700 struct cp_binding_level *b;
02701 cxx_saved_binding *old_bindings;
02702 int need_pop;
02703
02704 timevar_push (TV_NAME_LOOKUP);
02705
02706 s = (struct saved_scope *) ggc_alloc_cleared (sizeof (struct saved_scope));
02707
02708 b = scope_chain ? current_binding_level : 0;
02709
02710
02711 if (cfun)
02712 {
02713 need_pop = 1;
02714 push_function_context_to (NULL_TREE);
02715 }
02716 else
02717 need_pop = 0;
02718
02719 old_bindings = NULL;
02720 if (scope_chain && previous_class_type)
02721 old_bindings = store_bindings (previous_class_values, old_bindings);
02722
02723
02724
02725 for (; b; b = b->level_chain)
02726 {
02727 tree t;
02728
02729
02730
02731
02732
02733 if (global_scope_p (b) || (pseudo && b->template_parms_p))
02734 break;
02735
02736 old_bindings = store_bindings (b->names, old_bindings);
02737
02738
02739 if (b->parm_flag == 2)
02740 old_bindings = store_bindings (b->class_shadowed, old_bindings);
02741
02742
02743 for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
02744 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
02745 }
02746 s->prev = scope_chain;
02747 s->old_bindings = old_bindings;
02748 s->bindings = b;
02749 s->need_pop_function_context = need_pop;
02750 s->function_decl = current_function_decl;
02751 s->last_parms = last_function_parms;
02752
02753 scope_chain = s;
02754 current_function_decl = NULL_TREE;
02755 VARRAY_TREE_INIT (current_lang_base, 10, "current_lang_base");
02756 current_lang_name = lang_name_cplusplus;
02757 current_namespace = global_namespace;
02758 timevar_pop (TV_NAME_LOOKUP);
02759 }
02760
02761 void
02762 push_to_top_level ()
02763 {
02764 maybe_push_to_top_level (0);
02765 }
02766
02767 void
02768 pop_from_top_level ()
02769 {
02770 struct saved_scope *s = scope_chain;
02771 cxx_saved_binding *saved;
02772
02773 timevar_push (TV_NAME_LOOKUP);
02774
02775
02776 if (previous_class_type)
02777 invalidate_class_lookup_cache ();
02778
02779 current_lang_base = 0;
02780
02781 scope_chain = s->prev;
02782 for (saved = s->old_bindings; saved; saved = saved->previous)
02783 {
02784 tree id = saved->identifier;
02785
02786 IDENTIFIER_BINDING (id) = saved->binding;
02787 IDENTIFIER_CLASS_VALUE (id) = saved->class_value;
02788 SET_IDENTIFIER_TYPE_VALUE (id, saved->real_type_value);
02789 }
02790
02791
02792
02793 if (s->need_pop_function_context)
02794 pop_function_context_from (NULL_TREE);
02795 current_function_decl = s->function_decl;
02796 last_function_parms = s->last_parms;
02797
02798 timevar_pop (TV_NAME_LOOKUP);
02799 }
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813
02814 static void
02815 set_identifier_type_value_with_scope (id, type, b)
02816 tree id;
02817 tree type;
02818 struct cp_binding_level *b;
02819 {
02820 if (!b->namespace_p)
02821 {
02822
02823
02824 tree old_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
02825 b->type_shadowed
02826 = tree_cons (id, old_type_value, b->type_shadowed);
02827 }
02828 else
02829 {
02830 cxx_binding *binding = binding_for_name (id, current_namespace);
02831 BINDING_TYPE (binding) = type;
02832
02833 type = global_type_node;
02834 }
02835 SET_IDENTIFIER_TYPE_VALUE (id, type);
02836 }
02837
02838
02839
02840 void
02841 set_identifier_type_value (id, type)
02842 tree id;
02843 tree type;
02844 {
02845 set_identifier_type_value_with_scope (id, type, current_binding_level);
02846 }
02847
02848
02849
02850 tree
02851 identifier_type_value (id)
02852 tree id;
02853 {
02854 timevar_push (TV_NAME_LOOKUP);
02855
02856 if (REAL_IDENTIFIER_TYPE_VALUE (id) == NULL_TREE)
02857 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
02858
02859 if (REAL_IDENTIFIER_TYPE_VALUE (id) != global_type_node)
02860 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, REAL_IDENTIFIER_TYPE_VALUE (id));
02861
02862
02863 id = lookup_name_real (id, 2, 1, 0);
02864 if (id)
02865 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, TREE_TYPE (id));
02866 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
02867 }
02868
02869
02870
02871
02872
02873 void
02874 pop_everything ()
02875 {
02876 if (ENABLE_SCOPE_CHECKING)
02877 verbatim ("XXX entering pop_everything ()\n");
02878 while (!toplevel_bindings_p ())
02879 {
02880 if (current_binding_level->parm_flag == 2)
02881 pop_nested_class ();
02882 else
02883 poplevel (0, 0, 0);
02884 }
02885 if (ENABLE_SCOPE_CHECKING)
02886 verbatim ("XXX leaving pop_everything ()\n");
02887 }
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898 static tree
02899 maybe_process_template_type_declaration (type, globalize, b)
02900 tree type;
02901 int globalize;
02902 struct cp_binding_level* b;
02903 {
02904 tree decl = TYPE_NAME (type);
02905
02906 if (processing_template_parmlist)
02907
02908
02909
02910
02911
02912
02913 ;
02914 else
02915 {
02916 maybe_check_template_type (type);
02917
02918 my_friendly_assert (IS_AGGR_TYPE (type)
02919 || TREE_CODE (type) == ENUMERAL_TYPE, 0);
02920
02921
02922 if (processing_template_decl)
02923 {
02924
02925
02926 tree name = DECL_NAME (decl);
02927
02928 decl = push_template_decl_real (decl, globalize);
02929
02930
02931
02932
02933
02934
02935
02936 if (TREE_CODE (type) != ENUMERAL_TYPE
02937 && !globalize && b->template_parms_p
02938 && b->level_chain->parm_flag == 2)
02939 {
02940 finish_member_declaration (CLASSTYPE_TI_TEMPLATE (type));
02941
02942
02943
02944 if (b->level_chain->type_decls == NULL)
02945 b->level_chain->type_decls =
02946 binding_table_new (SCOPE_DEFAULT_HT_SIZE);
02947 binding_table_insert (b->level_chain->type_decls, name, type);
02948 if (!COMPLETE_TYPE_P (current_class_type))
02949 {
02950 maybe_add_class_template_decl_list (current_class_type,
02951 type, 0);
02952 CLASSTYPE_NESTED_UDTS (current_class_type) =
02953 b->level_chain->type_decls;
02954 }
02955 }
02956 }
02957 }
02958
02959 return decl;
02960 }
02961
02962
02963
02964
02965
02966
02967 tree
02968 create_implicit_typedef (name, type)
02969 tree name;
02970 tree type;
02971 {
02972 tree decl;
02973
02974 decl = build_decl (TYPE_DECL, name, type);
02975 DECL_ARTIFICIAL (decl) = 1;
02976
02977
02978
02979 SET_DECL_IMPLICIT_TYPEDEF_P (decl);
02980 TYPE_NAME (type) = decl;
02981
02982 return decl;
02983 }
02984
02985
02986
02987 static void
02988 push_local_name (decl)
02989 tree decl;
02990 {
02991 size_t i, nelts;
02992 tree t, name;
02993
02994 timevar_push (TV_NAME_LOOKUP);
02995
02996 if (!local_names)
02997 VARRAY_TREE_INIT (local_names, 8, "local_names");
02998
02999 name = DECL_NAME (decl);
03000
03001 nelts = VARRAY_ACTIVE_SIZE (local_names);
03002 for (i = 0; i < nelts; i++)
03003 {
03004 t = VARRAY_TREE (local_names, i);
03005 if (DECL_NAME (t) == name)
03006 {
03007 if (!DECL_LANG_SPECIFIC (decl))
03008 retrofit_lang_decl (decl);
03009 DECL_LANG_SPECIFIC (decl)->decl_flags.u2sel = 1;
03010 if (DECL_LANG_SPECIFIC (t))
03011 DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
03012 else
03013 DECL_DISCRIMINATOR (decl) = 1;
03014
03015 VARRAY_TREE (local_names, i) = decl;
03016 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, (void)0);
03017 }
03018 }
03019
03020 VARRAY_PUSH_TREE (local_names, decl);
03021 timevar_pop (TV_NAME_LOOKUP);
03022 }
03023
03024
03025
03026
03027
03028
03029 void
03030 pushtag (name, type, globalize)
03031 tree name, type;
03032 int globalize;
03033 {
03034 register struct cp_binding_level *b;
03035
03036 timevar_push (TV_NAME_LOOKUP);
03037
03038 b = current_binding_level;
03039 while (b->tag_transparent
03040 || (b->parm_flag == 2
03041 && (globalize
03042
03043
03044
03045
03046 || COMPLETE_TYPE_P (b->this_class))))
03047 b = b->level_chain;
03048
03049 if (b->type_decls == NULL)
03050 b->type_decls = binding_table_new (SCOPE_DEFAULT_HT_SIZE);
03051 binding_table_insert (b->type_decls, name, type);
03052
03053 if (name)
03054 {
03055
03056 if (IDENTIFIER_TYPE_VALUE (name) != type)
03057 {
03058 register tree d = NULL_TREE;
03059 int in_class = 0;
03060 tree context = TYPE_CONTEXT (type);
03061
03062 if (! context)
03063 {
03064 tree cs = current_scope ();
03065
03066 if (! globalize)
03067 context = cs;
03068 else if (cs != NULL_TREE && TYPE_P (cs))
03069
03070
03071
03072 context = decl_function_context (get_type_decl (cs));
03073 }
03074 if (!context)
03075 context = current_namespace;
03076
03077 if ((b->template_parms_p && b->level_chain->parm_flag == 2)
03078 || b->parm_flag == 2)
03079 in_class = 1;
03080
03081 if (current_lang_name == lang_name_java)
03082 TYPE_FOR_JAVA (type) = 1;
03083
03084 d = create_implicit_typedef (name, type);
03085 DECL_CONTEXT (d) = FROB_CONTEXT (context);
03086 if (! in_class)
03087 set_identifier_type_value_with_scope (name, type, b);
03088
03089 d = maybe_process_template_type_declaration (type,
03090 globalize, b);
03091
03092 if (b->parm_flag == 2)
03093 {
03094 if (!PROCESSING_REAL_TEMPLATE_DECL_P ())
03095
03096
03097
03098
03099 finish_member_declaration (d);
03100 else
03101 pushdecl_class_level (d);
03102 }
03103 else
03104 d = pushdecl_with_scope (d, b);
03105
03106
03107 if (ANON_AGGRNAME_P (name))
03108 DECL_IGNORED_P (d) = 1;
03109
03110 TYPE_CONTEXT (type) = DECL_CONTEXT (d);
03111
03112
03113
03114
03115
03116
03117 if (TYPE_CONTEXT (type)
03118 && TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL
03119 && !processing_template_decl)
03120 VARRAY_PUSH_TREE (local_classes, type);
03121 }
03122 if (b->parm_flag == 2)
03123 {
03124 if (!COMPLETE_TYPE_P (current_class_type))
03125 {
03126 maybe_add_class_template_decl_list (current_class_type,
03127 type, 0);
03128 CLASSTYPE_NESTED_UDTS (current_class_type) = b->type_decls;
03129 }
03130 }
03131 }
03132
03133 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
03134
03135 TYPE_STUB_DECL (type) = TYPE_NAME (type);
03136 else
03137 {
03138
03139
03140
03141
03142
03143
03144
03145
03146 tree d = build_decl (TYPE_DECL, NULL_TREE, type);
03147 TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
03148 }
03149
03150 timevar_pop (TV_NAME_LOOKUP);
03151 }
03152
03153
03154
03155 static int anon_cnt = 0;
03156
03157
03158
03159
03160 tree
03161 make_anon_name ()
03162 {
03163 char buf[32];
03164
03165 sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
03166 return get_identifier (buf);
03167 }
03168
03169
03170
03171
03172 void
03173 clear_anon_tags ()
03174 {
03175 register struct cp_binding_level *b;
03176 static int last_cnt = 0;
03177
03178
03179 if (last_cnt == anon_cnt)
03180 return;
03181
03182 b = current_binding_level;
03183 while (b->tag_transparent)
03184 b = b->level_chain;
03185 if (b->type_decls != NULL)
03186 binding_table_remove_anonymous_types (b->type_decls);
03187 last_cnt = anon_cnt;
03188 }
03189
03190
03191
03192
03193
03194
03195
03196
03197 int
03198 decls_match (newdecl, olddecl)
03199 tree newdecl, olddecl;
03200 {
03201 int types_match;
03202
03203 if (newdecl == olddecl)
03204 return 1;
03205
03206 if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
03207
03208
03209 return 0;
03210
03211 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03212 {
03213 tree f1 = TREE_TYPE (newdecl);
03214 tree f2 = TREE_TYPE (olddecl);
03215 tree p1 = TYPE_ARG_TYPES (f1);
03216 tree p2 = TYPE_ARG_TYPES (f2);
03217
03218 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
03219 && ! (DECL_EXTERN_C_P (newdecl)
03220 && DECL_EXTERN_C_P (olddecl)))
03221 return 0;
03222
03223 if (TREE_CODE (f1) != TREE_CODE (f2))
03224 return 0;
03225
03226 if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
03227 {
03228 if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
03229 && (DECL_BUILT_IN (olddecl)
03230 #ifndef NO_IMPLICIT_EXTERN_C
03231 || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
03232 || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl))
03233 #endif
03234 ))
03235 {
03236 types_match = self_promoting_args_p (p1);
03237 if (p1 == void_list_node)
03238 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
03239 }
03240 #ifndef NO_IMPLICIT_EXTERN_C
03241 else if (p1 == NULL_TREE
03242 && (DECL_EXTERN_C_P (olddecl)
03243 && DECL_IN_SYSTEM_HEADER (olddecl)
03244 && !DECL_CLASS_SCOPE_P (olddecl))
03245 && (DECL_EXTERN_C_P (newdecl)
03246 && DECL_IN_SYSTEM_HEADER (newdecl)
03247 && !DECL_CLASS_SCOPE_P (newdecl)))
03248 {
03249 types_match = self_promoting_args_p (p2);
03250 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
03251 }
03252 #endif
03253 else
03254 types_match = compparms (p1, p2);
03255 }
03256 else
03257 types_match = 0;
03258 }
03259 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
03260 {
03261 if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
03262 DECL_TEMPLATE_PARMS (olddecl)))
03263 return 0;
03264
03265 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
03266 != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
03267 return 0;
03268
03269 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
03270 types_match = 1;
03271 else
03272 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
03273 DECL_TEMPLATE_RESULT (newdecl));
03274 }
03275 else
03276 {
03277 if (TREE_TYPE (newdecl) == error_mark_node)
03278 types_match = TREE_TYPE (olddecl) == error_mark_node;
03279 else if (TREE_TYPE (olddecl) == NULL_TREE)
03280 types_match = TREE_TYPE (newdecl) == NULL_TREE;
03281 else if (TREE_TYPE (newdecl) == NULL_TREE)
03282 types_match = 0;
03283 else
03284 types_match = comptypes (TREE_TYPE (newdecl),
03285 TREE_TYPE (olddecl),
03286 COMPARE_REDECLARATION);
03287 }
03288
03289 #ifdef KEY
03290
03291 if (types_match && TREE_CODE (newdecl) == FUNCTION_DECL)
03292 add_duplicates (newdecl, olddecl);
03293 #endif
03294 return types_match;
03295 }
03296
03297
03298
03299
03300
03301
03302
03303
03304
03305
03306 static void
03307 warn_extern_redeclared_static (newdecl, olddecl)
03308 tree newdecl, olddecl;
03309 {
03310 static const char *const explicit_extern_static_warning
03311 = "`%D' was declared `extern' and later `static'";
03312 static const char *const implicit_extern_static_warning
03313 = "`%D' was declared implicitly `extern' and later `static'";
03314
03315 tree name;
03316
03317 if (TREE_CODE (newdecl) == TYPE_DECL
03318 || TREE_CODE (newdecl) == TEMPLATE_DECL
03319 || TREE_CODE (newdecl) == CONST_DECL)
03320 return;
03321
03322
03323
03324 if (TREE_CODE (newdecl) == FUNCTION_DECL
03325 && DECL_STATIC_FUNCTION_P (newdecl))
03326 return;
03327
03328
03329
03330 if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
03331 return;
03332
03333
03334 if (TREE_CODE (olddecl) == FUNCTION_DECL
03335 && DECL_ARTIFICIAL (olddecl))
03336 return;
03337
03338 name = DECL_ASSEMBLER_NAME (newdecl);
03339 pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
03340 ? implicit_extern_static_warning
03341 : explicit_extern_static_warning, newdecl);
03342 cp_pedwarn_at ("previous declaration of `%D'", olddecl);
03343 }
03344
03345
03346
03347
03348
03349
03350
03351
03352 int
03353 duplicate_decls (newdecl, olddecl)
03354 tree newdecl, olddecl;
03355 {
03356 unsigned olddecl_uid = DECL_UID (olddecl);
03357 int olddecl_friend = 0, types_match = 0;
03358 int new_defines_function = 0;
03359
03360 if (newdecl == olddecl)
03361 return 1;
03362
03363 types_match = decls_match (newdecl, olddecl);
03364
03365
03366
03367
03368
03369
03370 if (TREE_TYPE (newdecl) == error_mark_node
03371 || TREE_TYPE (olddecl) == error_mark_node)
03372 types_match = 1;
03373
03374 if (DECL_P (olddecl)
03375 && TREE_CODE (newdecl) == FUNCTION_DECL
03376 && TREE_CODE (olddecl) == FUNCTION_DECL
03377 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
03378 {
03379 if (DECL_DECLARED_INLINE_P (newdecl)
03380 && DECL_UNINLINABLE (newdecl)
03381 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
03382 ;
03383 else if (DECL_DECLARED_INLINE_P (olddecl)
03384 && DECL_UNINLINABLE (olddecl)
03385 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
03386 ;
03387 else if (DECL_DECLARED_INLINE_P (newdecl)
03388 && DECL_UNINLINABLE (olddecl)
03389 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
03390 {
03391 warning_with_decl (newdecl,
03392 "function `%s' redeclared as inline");
03393 warning_with_decl (olddecl,
03394 "previous declaration of function `%s' with attribute noinline");
03395 }
03396 else if (DECL_DECLARED_INLINE_P (olddecl)
03397 && DECL_UNINLINABLE (newdecl)
03398 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
03399 {
03400 warning_with_decl (newdecl,
03401 "function `%s' redeclared with attribute noinline");
03402 warning_with_decl (olddecl,
03403 "previous declaration of function `%s' was inline");
03404 }
03405 }
03406
03407
03408 if (TREE_CODE (olddecl) == FUNCTION_DECL
03409 && DECL_ARTIFICIAL (olddecl))
03410 {
03411 if (TREE_CODE (newdecl) != FUNCTION_DECL)
03412 {
03413
03414 if (DECL_ANTICIPATED (olddecl))
03415 return 0;
03416
03417
03418
03419
03420 if (! TREE_PUBLIC (newdecl))
03421 {
03422 if (warn_shadow)
03423 warning ("shadowing %s function `%#D'",
03424 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
03425 olddecl);
03426
03427 return 0;
03428 }
03429
03430
03431 else if (! DECL_BUILT_IN (olddecl))
03432 warning ("library function `%#D' redeclared as non-function `%#D'",
03433 olddecl, newdecl);
03434 else
03435 {
03436 error ("declaration of `%#D'", newdecl);
03437 error ("conflicts with built-in declaration `%#D'",
03438 olddecl);
03439 }
03440 return 0;
03441 }
03442 else if (!types_match)
03443 {
03444
03445 if (DECL_ANTICIPATED (olddecl))
03446 ;
03447 else if ((DECL_EXTERN_C_P (newdecl)
03448 && DECL_EXTERN_C_P (olddecl))
03449 || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
03450 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
03451 {
03452
03453
03454 if (TREE_PUBLIC (newdecl))
03455 {
03456 warning ("new declaration `%#D'", newdecl);
03457 warning ("ambiguates built-in declaration `%#D'",
03458 olddecl);
03459 }
03460 else if (warn_shadow)
03461 warning ("shadowing %s function `%#D'",
03462 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
03463 olddecl);
03464 }
03465 else
03466
03467 return 0;
03468
03469
03470 SET_DECL_RTL (olddecl, DECL_RTL (newdecl));
03471 }
03472
03473
03474 else if (DECL_ANTICIPATED (olddecl))
03475 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
03476
03477
03478
03479 TREE_NOTHROW (olddecl) = 0;
03480
03481 if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
03482 {
03483
03484
03485 DECL_THIS_STATIC (olddecl) = 1;
03486 TREE_PUBLIC (olddecl) = 0;
03487
03488
03489
03490
03491 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
03492 SET_DECL_RTL (olddecl, DECL_RTL (newdecl));
03493 }
03494 }
03495 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
03496 {
03497 if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
03498 && TREE_CODE (newdecl) != TYPE_DECL
03499 && ! (TREE_CODE (newdecl) == TEMPLATE_DECL
03500 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL))
03501 || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
03502 && TREE_CODE (olddecl) != TYPE_DECL
03503 && ! (TREE_CODE (olddecl) == TEMPLATE_DECL
03504 && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
03505 == TYPE_DECL))))
03506 {
03507
03508
03509
03510
03511
03512 return 0;
03513 }
03514
03515 if ((TREE_CODE (newdecl) == FUNCTION_DECL
03516 && DECL_FUNCTION_TEMPLATE_P (olddecl))
03517 || (TREE_CODE (olddecl) == FUNCTION_DECL
03518 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
03519 return 0;
03520
03521 error ("`%#D' redeclared as different kind of symbol", newdecl);
03522 if (TREE_CODE (olddecl) == TREE_LIST)
03523 olddecl = TREE_VALUE (olddecl);
03524 cp_error_at ("previous declaration of `%#D'", olddecl);
03525
03526
03527
03528
03529 return 0;
03530 }
03531 else if (!types_match)
03532 {
03533 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
03534
03535
03536 return 0;
03537
03538 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
03539 {
03540
03541
03542
03543 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
03544 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
03545 {
03546 error ("declaration of template `%#D'", newdecl);
03547 cp_error_at ("conflicts with previous declaration `%#D'",
03548 olddecl);
03549 }
03550 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
03551 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
03552 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
03553 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
03554 && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
03555 DECL_TEMPLATE_PARMS (olddecl))
03556
03557
03558 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
03559 TREE_TYPE (TREE_TYPE (olddecl))))
03560 {
03561 error ("new declaration `%#D'", newdecl);
03562 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
03563 }
03564 return 0;
03565 }
03566 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03567 {
03568 if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
03569 {
03570 error ("declaration of C function `%#D' conflicts with",
03571 newdecl);
03572 cp_error_at ("previous declaration `%#D' here", olddecl);
03573 }
03574 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
03575 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
03576 {
03577 error ("new declaration `%#D'", newdecl);
03578 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
03579 }
03580 else
03581 return 0;
03582 }
03583
03584
03585 else if (current_class_type == NULL_TREE
03586 || !DECL_ASSEMBLER_NAME_SET_P (newdecl)
03587 || (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl))
03588 != current_class_type))
03589 {
03590 error ("conflicting types for `%#D'", newdecl);
03591 cp_error_at ("previous declaration as `%#D'", olddecl);
03592 }
03593 }
03594 else if (TREE_CODE (newdecl) == FUNCTION_DECL
03595 && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
03596 && (!DECL_TEMPLATE_INFO (newdecl)
03597 || (DECL_TI_TEMPLATE (newdecl)
03598 != DECL_TI_TEMPLATE (olddecl))))
03599 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
03600 && (!DECL_TEMPLATE_INFO (olddecl)
03601 || (DECL_TI_TEMPLATE (olddecl)
03602 != DECL_TI_TEMPLATE (newdecl))))))
03603
03604
03605
03606
03607
03608
03609
03610
03611 return 0;
03612 else if (TREE_CODE (newdecl) == FUNCTION_DECL
03613 && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
03614 && !DECL_USE_TEMPLATE (newdecl))
03615 || (DECL_TEMPLATE_INSTANTIATION (newdecl)
03616 && !DECL_USE_TEMPLATE (olddecl))))
03617
03618
03619 return 0;
03620 else if (TREE_CODE (newdecl) == NAMESPACE_DECL
03621 && DECL_NAMESPACE_ALIAS (newdecl)
03622 && DECL_NAMESPACE_ALIAS (newdecl) == DECL_NAMESPACE_ALIAS (olddecl))
03623
03624 return 1;
03625 else
03626 {
03627 const char *errmsg = redeclaration_error_message (newdecl, olddecl);
03628 if (errmsg)
03629 {
03630 error (errmsg, newdecl);
03631 if (DECL_NAME (olddecl) != NULL_TREE)
03632 cp_error_at ((DECL_INITIAL (olddecl)
03633 && namespace_bindings_p ())
03634 ? "`%#D' previously defined here"
03635 : "`%#D' previously declared here", olddecl);
03636 return 0;
03637 }
03638 else if (TREE_CODE (olddecl) == FUNCTION_DECL
03639 && DECL_INITIAL (olddecl) != NULL_TREE
03640 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
03641 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
03642 {
03643
03644 cp_warning_at ("prototype for `%#D'", newdecl);
03645 cp_warning_at ("follows non-prototype definition here", olddecl);
03646 }
03647 else if (TREE_CODE (olddecl) == FUNCTION_DECL
03648 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
03649 {
03650
03651
03652
03653 if (current_lang_depth () == 0)
03654 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
03655 else
03656 {
03657 cp_error_at ("previous declaration of `%#D' with %L linkage",
03658 olddecl, DECL_LANGUAGE (olddecl));
03659 error ("conflicts with new declaration with %L linkage",
03660 DECL_LANGUAGE (newdecl));
03661 }
03662 }
03663
03664 if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
03665 ;
03666 else if (TREE_CODE (olddecl) == FUNCTION_DECL)
03667 {
03668 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
03669 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
03670 int i = 1;
03671
03672 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
03673 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
03674
03675 for (; t1 && t1 != void_list_node;
03676 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
03677 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
03678 {
03679 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
03680 TREE_PURPOSE (t2)))
03681 {
03682 pedwarn ("default argument given for parameter %d of `%#D'",
03683 i, newdecl);
03684 cp_pedwarn_at ("after previous specification in `%#D'",
03685 olddecl);
03686 }
03687 else
03688 {
03689 error ("default argument given for parameter %d of `%#D'",
03690 i, newdecl);
03691 cp_error_at ("after previous specification in `%#D'",
03692 olddecl);
03693 }
03694 }
03695
03696 if (DECL_DECLARED_INLINE_P (newdecl)
03697 && ! DECL_DECLARED_INLINE_P (olddecl)
03698 && TREE_ADDRESSABLE (olddecl) && warn_inline)
03699 {
03700 warning ("`%#D' was used before it was declared inline",
03701 newdecl);
03702 cp_warning_at ("previous non-inline declaration here",
03703 olddecl);
03704 }
03705 }
03706 }
03707
03708
03709
03710
03711
03712
03713
03714
03715 if (TREE_CODE (olddecl) == TYPE_DECL
03716 && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
03717 || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
03718 return 0;
03719
03720
03721
03722 warn_extern_redeclared_static (newdecl, olddecl);
03723
03724
03725 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03726 {
03727
03728
03729
03730
03731 if (DECL_VINDEX (olddecl))
03732 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
03733 if (DECL_CONTEXT (olddecl))
03734 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
03735 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
03736 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
03737 DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
03738 DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
03739 DECL_NEEDS_FINAL_OVERRIDER_P (newdecl) |= DECL_NEEDS_FINAL_OVERRIDER_P (olddecl);
03740 DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
03741 if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
03742 SET_OVERLOADED_OPERATOR_CODE
03743 (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
03744 new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
03745
03746
03747
03748
03749 if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
03750 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
03751
03752 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
03753
03754 && ! (DECL_FRIEND_P (newdecl) || DECL_FRIEND_P (olddecl)))
03755 {
03756 warning ("redundant redeclaration of `%D' in same scope", newdecl);
03757 cp_warning_at ("previous declaration of `%D'", olddecl);
03758 }
03759 }
03760
03761
03762 if (TREE_CODE (olddecl) == TYPE_DECL)
03763 {
03764 register tree newtype = TREE_TYPE (newdecl);
03765 register tree oldtype = TREE_TYPE (olddecl);
03766
03767 if (newtype != error_mark_node && oldtype != error_mark_node
03768 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
03769 CLASSTYPE_FRIEND_CLASSES (newtype)
03770 = CLASSTYPE_FRIEND_CLASSES (oldtype);
03771 \
03772 DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
03773 }
03774
03775
03776
03777 DECL_ATTRIBUTES (newdecl)
03778 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
03779
03780 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
03781 {
03782 TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl));
03783 DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
03784 = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
03785 DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
03786
03787
03788
03789 if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE
03790 && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) != NULL_TREE)
03791 {
03792 DECL_SOURCE_LOCATION (olddecl)
03793 = DECL_SOURCE_LOCATION (DECL_TEMPLATE_RESULT (olddecl))
03794 = DECL_SOURCE_LOCATION (newdecl);
03795 }
03796
03797 return 1;
03798 }
03799
03800 if (types_match)
03801 {
03802
03803 tree oldtype = TREE_TYPE (olddecl);
03804 tree newtype;
03805
03806
03807 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
03808
03809
03810 if (TREE_CODE (newdecl) == TYPE_DECL
03811 && newtype == DECL_ORIGINAL_TYPE (newdecl))
03812 newtype = oldtype;
03813
03814 if (TREE_CODE (newdecl) == VAR_DECL)
03815 {
03816 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
03817 DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
03818 }
03819
03820
03821
03822 else if (TREE_CODE (newdecl) == FUNCTION_DECL
03823 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
03824 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
03825 {
03826 TREE_TYPE (newdecl) = build_exception_variant (newtype,
03827 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
03828 TREE_TYPE (olddecl) = build_exception_variant (newtype,
03829 TYPE_RAISES_EXCEPTIONS (oldtype));
03830
03831 if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl))
03832 && DECL_SOURCE_LINE (olddecl) != 0
03833 && flag_exceptions
03834 && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)),
03835 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)), 1))
03836 {
03837 error ("declaration of `%F' throws different exceptions",
03838 newdecl);
03839 cp_error_at ("than previous declaration `%F'", olddecl);
03840 }
03841 }
03842 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
03843
03844
03845 if (! same_type_p (newtype, oldtype)
03846 && TREE_TYPE (newdecl) != error_mark_node
03847 && !(processing_template_decl && uses_template_parms (newdecl)))
03848 layout_type (TREE_TYPE (newdecl));
03849
03850 if ((TREE_CODE (newdecl) == VAR_DECL
03851 || TREE_CODE (newdecl) == PARM_DECL
03852 || TREE_CODE (newdecl) == RESULT_DECL
03853 || TREE_CODE (newdecl) == FIELD_DECL
03854 || TREE_CODE (newdecl) == TYPE_DECL)
03855 && !(processing_template_decl && uses_template_parms (newdecl)))
03856 layout_decl (newdecl, 0);
03857
03858
03859 if (TREE_READONLY (newdecl))
03860 TREE_READONLY (olddecl) = 1;
03861 if (TREE_THIS_VOLATILE (newdecl))
03862 TREE_THIS_VOLATILE (olddecl) = 1;
03863
03864
03865 if (DECL_INITIAL (newdecl) == NULL_TREE
03866 && DECL_INITIAL (olddecl) != NULL_TREE)
03867 {
03868 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
03869 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
03870 if (CAN_HAVE_FULL_LANG_DECL_P (newdecl)
03871 && DECL_LANG_SPECIFIC (newdecl)
03872 && DECL_LANG_SPECIFIC (olddecl))
03873 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
03874 }
03875
03876
03877
03878
03879
03880 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
03881 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
03882
03883 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03884 {
03885 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
03886 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
03887 DECL_NO_LIMIT_STACK (newdecl)
03888 |= DECL_NO_LIMIT_STACK (olddecl);
03889
03890 COPY_DECL_RTL (olddecl, newdecl);
03891 }
03892 else if (TREE_CODE (newdecl) == VAR_DECL
03893 && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
03894 {
03895
03896
03897
03898
03899 COPY_DECL_RTL (olddecl, newdecl);
03900 }
03901 }
03902
03903
03904 else
03905 {
03906
03907 tree oldstatic = value_member (olddecl, static_aggregates);
03908 if (oldstatic)
03909 TREE_VALUE (oldstatic) = error_mark_node;
03910
03911 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
03912 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
03913 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
03914 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
03915 }
03916
03917
03918 merge_weak (newdecl, olddecl);
03919
03920 DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl);
03921 DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
03922 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
03923 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
03924 if (! DECL_EXTERNAL (olddecl))
03925 DECL_EXTERNAL (newdecl) = 0;
03926
03927 if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
03928 {
03929 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
03930 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
03931 DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
03932 DECL_TEMPLATE_INSTANTIATED (newdecl)
03933 |= DECL_TEMPLATE_INSTANTIATED (olddecl);
03934
03935
03936 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
03937 DECL_LANG_SPECIFIC (newdecl)->decl_flags.u2 =
03938 DECL_LANG_SPECIFIC (olddecl)->decl_flags.u2;
03939 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
03940 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
03941 DECL_INITIALIZED_IN_CLASS_P (newdecl)
03942 |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
03943 olddecl_friend = DECL_FRIEND_P (olddecl);
03944
03945
03946 if (TREE_CODE (newdecl) == FUNCTION_DECL
03947 || DECL_FUNCTION_TEMPLATE_P (newdecl))
03948 {
03949 DECL_BEFRIENDING_CLASSES (newdecl)
03950 = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
03951 DECL_BEFRIENDING_CLASSES (olddecl));
03952
03953
03954 if (DECL_VIRTUAL_P (newdecl))
03955 DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
03956 }
03957 }
03958
03959 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03960 {
03961 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
03962 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
03963 {
03964
03965
03966
03967 my_friendly_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl),
03968 0);
03969
03970 if (TREE_USED (olddecl))
03971
03972
03973
03974
03975
03976
03977
03978
03979 error ("explicit specialization of %D after first use",
03980 olddecl);
03981
03982 SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
03983
03984
03985
03986 }
03987 else
03988 {
03989 if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
03990 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
03991
03992 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
03993
03994
03995
03996 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
03997 DECL_INLINE (olddecl) = 1;
03998 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
03999
04000 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
04001 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
04002 }
04003
04004
04005 DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
04006
04007 if (! types_match)
04008 {
04009 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
04010 COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
04011 SET_DECL_RTL (olddecl, DECL_RTL (newdecl));
04012 }
04013 if (! types_match || new_defines_function)
04014 {
04015
04016
04017
04018 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
04019 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
04020 }
04021 if (new_defines_function)
04022
04023
04024 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
04025 else if (types_match)
04026 {
04027
04028
04029 if (DECL_BUILT_IN (olddecl))
04030 {
04031 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
04032 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
04033
04034
04035 SET_DECL_RTL (newdecl, DECL_RTL (olddecl));
04036 }
04037 else
04038 DECL_NUM_STMTS (newdecl) = DECL_NUM_STMTS (olddecl);
04039
04040 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
04041
04042 if (DECL_ARGUMENTS (olddecl))
04043 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
04044 }
04045 }
04046 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
04047 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
04048
04049
04050 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
04051 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
04052 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
04053 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
04054
04055 if (TREE_CODE (newdecl) == FUNCTION_DECL)
04056 {
04057 int function_size;
04058
04059 function_size = sizeof (struct tree_decl);
04060
04061 memcpy ((char *) olddecl + sizeof (struct tree_common),
04062 (char *) newdecl + sizeof (struct tree_common),
04063 function_size - sizeof (struct tree_common));
04064
04065 if (DECL_TEMPLATE_INSTANTIATION (newdecl))
04066 {
04067
04068
04069
04070
04071
04072
04073
04074
04075
04076
04077
04078
04079
04080
04081
04082
04083
04084
04085
04086
04087
04088
04089 tree tmpl = DECL_TI_TEMPLATE (newdecl);
04090 tree decls = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
04091
04092 for (; decls; decls = TREE_CHAIN (decls))
04093 if (TREE_VALUE (decls) == newdecl)
04094 TREE_VALUE (decls) = olddecl;
04095 }
04096 }
04097 else
04098 {
04099 memcpy ((char *) olddecl + sizeof (struct tree_common),
04100 (char *) newdecl + sizeof (struct tree_common),
04101 sizeof (struct tree_decl) - sizeof (struct tree_common)
04102 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
04103 }
04104
04105 DECL_UID (olddecl) = olddecl_uid;
04106 if (olddecl_friend)
04107 DECL_FRIEND_P (olddecl) = 1;
04108
04109
04110
04111 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
04112
04113
04114
04115
04116 if (DECL_RTL_SET_P (olddecl)
04117 && (TREE_CODE (olddecl) == FUNCTION_DECL
04118 || (TREE_CODE (olddecl) == VAR_DECL
04119 && TREE_STATIC (olddecl))))
04120 make_decl_rtl (olddecl, NULL);
04121
04122 return 1;
04123 }
04124
04125
04126
04127
04128
04129
04130
04131
04132
04133 tree
04134 pushdecl (x)
04135 tree x;
04136 {
04137 register tree t;
04138 register tree name;
04139 int need_new_binding;
04140
04141 timevar_push (TV_NAME_LOOKUP);
04142
04143
04144
04145 my_friendly_assert (!cfun || doing_semantic_analysis_p (),
04146 19990913);
04147
04148 need_new_binding = 1;
04149
04150 if (DECL_TEMPLATE_PARM_P (x))
04151
04152
04153 ;
04154 else
04155 {
04156 if (current_function_decl && x != current_function_decl
04157
04158
04159 && !(TREE_CODE (x) == FUNCTION_DECL && !DECL_INITIAL (x))
04160
04161
04162
04163 && !(TREE_CODE (x) == VAR_DECL && DECL_EXTERNAL (x))
04164 && !DECL_CONTEXT (x))
04165 DECL_CONTEXT (x) = current_function_decl;
04166
04167
04168
04169
04170 if (TREE_CODE (x) == FUNCTION_DECL
04171 && DECL_NAMESPACE_SCOPE_P (x)
04172 && current_function_decl
04173 && x != current_function_decl)
04174 DECL_LOCAL_FUNCTION_P (x) = 1;
04175 }
04176
04177 name = DECL_NAME (x);
04178 if (name)
04179 {
04180 int different_binding_level = 0;
04181
04182 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
04183 name = TREE_OPERAND (name, 0);
04184
04185
04186
04187 if (TREE_CODE (x) == VAR_DECL && DECL_NAMESPACE_SCOPE_P (x)
04188 && namespace_bindings_p ())
04189 t = namespace_binding (name, DECL_CONTEXT (x));
04190 else
04191 t = lookup_name_current_level (name);
04192
04193
04194
04195
04196
04197
04198 if (! t && current_function_decl && x != current_function_decl
04199 && (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
04200 && DECL_EXTERNAL (x))
04201 {
04202
04203 t = IDENTIFIER_VALUE (name);
04204
04205 if (! t)
04206 t = namespace_binding (name, DECL_CONTEXT (x));
04207
04208
04209 if (t && DECL_P (t) && ! (TREE_STATIC (t) || DECL_EXTERNAL (t)))
04210 t = NULL_TREE;
04211 if (t)
04212 different_binding_level = 1;
04213 }
04214
04215
04216
04217
04218
04219
04220 if (t && TREE_CODE (t) == OVERLOAD)
04221 {
04222 tree match;
04223
04224 if (TREE_CODE (x) == FUNCTION_DECL)
04225 for (match = t; match; match = OVL_NEXT (match))
04226 {
04227 if (decls_match (OVL_CURRENT (match), x))
04228 break;
04229 }
04230 else
04231
04232 match = t;
04233
04234 if (match)
04235 t = OVL_CURRENT (match);
04236 else
04237 t = NULL_TREE;
04238 }
04239
04240 if (t == error_mark_node)
04241 {
04242
04243 t = NULL_TREE;
04244 cp_error_at ("`%#D' used prior to declaration", x);
04245 }
04246 else if (t != NULL_TREE)
04247 {
04248 if (different_binding_level)
04249 {
04250 if (decls_match (x, t))
04251
04252
04253
04254
04255 TREE_PUBLIC (x) = TREE_PUBLIC (t);
04256 }
04257 else if (TREE_CODE (t) == PARM_DECL)
04258 {
04259 if (DECL_CONTEXT (t) == NULL_TREE)
04260
04261
04262 abort ();
04263
04264
04265 if (duplicate_decls (x, t))
04266 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04267 }
04268 else if ((DECL_EXTERN_C_FUNCTION_P (x)
04269 || DECL_FUNCTION_TEMPLATE_P (x))
04270 && is_overloaded_fn (t))
04271 ;
04272 else if (t == wchar_decl_node)
04273 {
04274 if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
04275 pedwarn ("redeclaration of `wchar_t' as `%T'",
04276 TREE_TYPE (x));
04277
04278
04279 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04280 }
04281 else if (TREE_CODE (t) != TREE_CODE (x))
04282 {
04283 if (duplicate_decls (x, t))
04284 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04285 }
04286 else if (duplicate_decls (x, t))
04287 {
04288 if (TREE_CODE (t) == TYPE_DECL)
04289 SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
04290 else if (TREE_CODE (t) == FUNCTION_DECL)
04291 check_default_args (t);
04292
04293 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04294 }
04295 else if (DECL_MAIN_P (x))
04296 {
04297
04298
04299
04300
04301
04302
04303 cp_error_at ("invalid redeclaration of `%D'", t);
04304 error ("as `%D'", x);
04305
04306
04307 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04308 }
04309 }
04310
04311 check_template_shadow (x);
04312
04313
04314
04315 if (DECL_NON_THUNK_FUNCTION_P (x) && ! DECL_LANG_SPECIFIC (x))
04316 {
04317 retrofit_lang_decl (x);
04318 SET_DECL_LANGUAGE (x, lang_c);
04319 }
04320
04321 if (DECL_NON_THUNK_FUNCTION_P (x) && ! DECL_FUNCTION_MEMBER_P (x))
04322 {
04323 t = push_overloaded_decl (x, PUSH_LOCAL);
04324 if (t != x)
04325 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04326 if (!namespace_bindings_p ())
04327
04328
04329
04330 need_new_binding = 0;
04331 }
04332 else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_NAMESPACE_SCOPE_P (x))
04333 {
04334 t = push_overloaded_decl (x, PUSH_GLOBAL);
04335 if (t == x)
04336 add_decl_to_level (x, NAMESPACE_LEVEL (CP_DECL_CONTEXT (t)));
04337 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04338 }
04339
04340
04341
04342
04343 if (TREE_CODE (x) == TYPE_DECL)
04344 {
04345 tree type = TREE_TYPE (x);
04346 if (DECL_SOURCE_LINE (x) == 0)
04347 {
04348 if (TYPE_NAME (type) == 0)
04349 TYPE_NAME (type) = x;
04350 }
04351 else if (type != error_mark_node && TYPE_NAME (type) != x
04352
04353
04354
04355 && (!TYPE_NAME (type)
04356 || TYPE_NAME (type) != DECL_ABSTRACT_ORIGIN (x)))
04357 {
04358 DECL_ORIGINAL_TYPE (x) = type;
04359 type = build_type_copy (type);
04360 TYPE_STUB_DECL (type) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x));
04361 TYPE_NAME (type) = x;
04362 TREE_TYPE (x) = type;
04363 }
04364
04365 if (type != error_mark_node
04366 && TYPE_NAME (type)
04367 && TYPE_IDENTIFIER (type))
04368 set_identifier_type_value_with_scope (DECL_NAME (x), type,
04369 current_binding_level);
04370
04371 }
04372
04373
04374
04375
04376
04377
04378
04379 if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
04380 {
04381 tree decl;
04382
04383 decl = IDENTIFIER_NAMESPACE_VALUE (name);
04384 if (decl && TREE_CODE (decl) == OVERLOAD)
04385 decl = OVL_FUNCTION (decl);
04386
04387 if (decl && decl != error_mark_node
04388 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl))
04389
04390 && TREE_CODE (decl) == TREE_CODE (x)
04391 && !same_type_p (TREE_TYPE (x), TREE_TYPE (decl)))
04392 {
04393 pedwarn ("type mismatch with previous external decl", x);
04394 cp_pedwarn_at ("previous external decl of `%#D'", decl);
04395 }
04396 }
04397
04398
04399
04400 if (namespace_bindings_p ())
04401 {
04402
04403
04404
04405
04406 if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
04407 TREE_PUBLIC (name) = 1;
04408
04409
04410 if (!(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
04411 && t != NULL_TREE)
04412 && (TREE_CODE (x) == TYPE_DECL
04413 || TREE_CODE (x) == VAR_DECL
04414 || TREE_CODE (x) == NAMESPACE_DECL
04415 || TREE_CODE (x) == CONST_DECL
04416 || TREE_CODE (x) == TEMPLATE_DECL))
04417 SET_IDENTIFIER_NAMESPACE_VALUE (name, x);
04418
04419
04420 if (IDENTIFIER_IMPLICIT_DECL (name)
04421 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
04422 TREE_USED (x) = 1;
04423
04424
04425 if (IDENTIFIER_IMPLICIT_DECL (name)
04426 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
04427 TREE_ADDRESSABLE (x) = 1;
04428
04429
04430 if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
04431
04432 && ! (TREE_CODE (x) == FUNCTION_DECL
04433 && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
04434 warning
04435 ("`%D' was previously implicitly declared to return `int'", x);
04436
04437
04438
04439 if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
04440 warn_extern_redeclared_static (x, t);
04441 }
04442 else
04443 {
04444
04445 tree oldlocal = IDENTIFIER_VALUE (name);
04446 tree oldglobal = IDENTIFIER_NAMESPACE_VALUE (name);
04447
04448 if (need_new_binding)
04449 {
04450 push_local_binding (name, x, 0);
04451
04452
04453
04454 need_new_binding = 0;
04455 }
04456
04457
04458 if (TREE_CODE (x) == TYPE_DECL)
04459 set_identifier_type_value_with_scope (name, TREE_TYPE (x),
04460 current_binding_level);
04461
04462
04463
04464
04465 if (TREE_CODE (x) == NAMESPACE_DECL)
04466 set_identifier_type_value_with_scope (name, NULL_TREE,
04467 current_binding_level);
04468
04469 if (oldlocal)
04470 {
04471 tree d = oldlocal;
04472
04473 while (oldlocal
04474 && TREE_CODE (oldlocal) == VAR_DECL
04475 && DECL_DEAD_FOR_LOCAL (oldlocal))
04476 oldlocal = DECL_SHADOWED_FOR_VAR (oldlocal);
04477
04478 if (oldlocal == NULL_TREE)
04479 oldlocal = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (d));
04480 }
04481
04482
04483
04484 if (oldlocal == NULL_TREE
04485 && DECL_EXTERNAL (x)
04486 && oldglobal != NULL_TREE
04487 && TREE_CODE (x) == FUNCTION_DECL
04488 && TREE_CODE (oldglobal) == FUNCTION_DECL)
04489 {
04490
04491 if (decls_match (x, oldglobal))
04492 ;
04493 else
04494 {
04495 warning ("extern declaration of `%#D' doesn't match", x);
04496 cp_warning_at ("global declaration `%#D'", oldglobal);
04497 }
04498 }
04499
04500
04501
04502 if (oldlocal == NULL_TREE
04503 && oldglobal == NULL_TREE
04504 && DECL_EXTERNAL (x)
04505 && TREE_PUBLIC (x))
04506 TREE_PUBLIC (name) = 1;
04507
04508
04509 if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
04510
04511 && !DECL_FROM_INLINE (x)
04512 && TREE_CODE (oldlocal) == PARM_DECL
04513
04514 && !DECL_ARTIFICIAL (oldlocal))
04515 {
04516 bool err = false;
04517
04518
04519 if (DECL_CONTEXT (oldlocal) == current_function_decl
04520 && TREE_CODE (x) != PARM_DECL)
04521 {
04522
04523
04524 struct cp_binding_level *b = current_binding_level->level_chain;
04525
04526
04527 if (b->parm_flag == 1)
04528 {
04529 error ("declaration of `%#D' shadows a parameter",
04530 name);
04531 err = true;
04532 }
04533 }
04534
04535 if (warn_shadow && !err)
04536 shadow_warning ("a parameter", name, oldlocal);
04537 }
04538
04539
04540 else if (warn_shadow && !DECL_EXTERNAL (x)
04541
04542 && ! DECL_ARTIFICIAL (x)
04543
04544 && ! DECL_FROM_INLINE (x))
04545 {
04546 if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
04547 && current_class_ptr
04548 && !TREE_STATIC (name))
04549 warning ("declaration of `%s' shadows a member of `this'",
04550 IDENTIFIER_POINTER (name));
04551 else if (oldlocal != NULL_TREE
04552 && TREE_CODE (oldlocal) == VAR_DECL)
04553 shadow_warning ("a previous local", name, oldlocal);
04554 else if (oldglobal != NULL_TREE
04555 && TREE_CODE (oldglobal) == VAR_DECL)
04556
04557 shadow_warning ("a global declaration", name, oldglobal);
04558 }
04559 }
04560
04561 if (TREE_CODE (x) == FUNCTION_DECL)
04562 check_default_args (x);
04563
04564 if (TREE_CODE (x) == VAR_DECL)
04565 maybe_register_incomplete_var (x);
04566 }
04567
04568 if (need_new_binding)
04569 add_decl_to_level (x,
04570 DECL_NAMESPACE_SCOPE_P (x)
04571 ? NAMESPACE_LEVEL (CP_DECL_CONTEXT (x))
04572 : current_binding_level);
04573
04574 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04575 }
04576
04577
04578
04579
04580 static tree
04581 pushdecl_with_scope (x, level)
04582 tree x;
04583 struct cp_binding_level *level;
04584 {
04585 register struct cp_binding_level *b;
04586 tree function_decl = current_function_decl;
04587
04588 timevar_push (TV_NAME_LOOKUP);
04589
04590 current_function_decl = NULL_TREE;
04591 if (level->parm_flag == 2)
04592 {
04593 b = class_binding_level;
04594 class_binding_level = level;
04595 pushdecl_class_level (x);
04596 class_binding_level = b;
04597 }
04598 else
04599 {
04600 b = current_binding_level;
04601 #ifdef KEY
04602 copy_to_current_binding_level (level);
04603 #else
04604 current_binding_level = level;
04605 #endif // KEY
04606 x = pushdecl (x);
04607 #ifdef KEY
04608 copy_to_current_binding_level (b);
04609 #else
04610 current_binding_level = b;
04611 #endif // KEY
04612 }
04613 current_function_decl = function_decl;
04614 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04615 }
04616
04617
04618
04619
04620 tree
04621 pushdecl_namespace_level (x)
04622 tree x;
04623 {
04624 register struct cp_binding_level *b = current_binding_level;
04625 register tree t;
04626
04627 timevar_push (TV_NAME_LOOKUP);
04628 t = pushdecl_with_scope (x, NAMESPACE_LEVEL (current_namespace));
04629
04630
04631
04632 if (TREE_CODE (x) == TYPE_DECL)
04633 {
04634 tree name = DECL_NAME (x);
04635 tree newval;
04636 tree *ptr = (tree *)0;
04637 for (; !global_scope_p (b); b = b->level_chain)
04638 {
04639 tree shadowed = b->type_shadowed;
04640 for (; shadowed; shadowed = TREE_CHAIN (shadowed))
04641 if (TREE_PURPOSE (shadowed) == name)
04642 {
04643 ptr = &TREE_VALUE (shadowed);
04644
04645
04646
04647 }
04648 }
04649 newval = TREE_TYPE (x);
04650 if (ptr == (tree *)0)
04651 {
04652
04653
04654 SET_IDENTIFIER_TYPE_VALUE (name, newval);
04655 }
04656 else
04657 {
04658 *ptr = newval;
04659 }
04660 }
04661 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04662 }
04663
04664
04665
04666
04667
04668 static tree
04669 pushdecl_top_level_1 (tree x, tree *init)
04670 {
04671 timevar_push (TV_NAME_LOOKUP);
04672 push_to_top_level ();
04673 x = pushdecl_namespace_level (x);
04674 if (init)
04675 cp_finish_decl (x, *init, NULL_TREE, 0);
04676 pop_from_top_level ();
04677 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04678 }
04679
04680
04681
04682 tree
04683 pushdecl_top_level (tree x)
04684 {
04685 return pushdecl_top_level_1 (x, NULL);
04686 }
04687
04688
04689
04690
04691
04692 tree
04693 pushdecl_top_level_and_finish (tree x, tree init)
04694 {
04695 return pushdecl_top_level_1 (x, &init);
04696 }
04697
04698
04699
04700 bool
04701 pushdecl_class_level (x)
04702 tree x;
04703 {
04704 tree name;
04705 bool is_valid = true;
04706
04707 timevar_push (TV_NAME_LOOKUP);
04708
04709 if (TREE_CODE (x) == OVERLOAD)
04710 name = DECL_NAME (get_first_fn (x));
04711 else
04712 name = DECL_NAME (x);
04713
04714 if (name)
04715 {
04716 is_valid = push_class_level_binding (name, x);
04717 if (TREE_CODE (x) == TYPE_DECL)
04718 set_identifier_type_value (name, TREE_TYPE (x));
04719 }
04720 else if (ANON_AGGR_TYPE_P (TREE_TYPE (x)))
04721 {
04722
04723
04724
04725 tree f;
04726
04727 for (f = TYPE_FIELDS (TREE_TYPE (x)); f; f = TREE_CHAIN (f))
04728 {
04729 push_srcloc (DECL_SOURCE_FILE (f), DECL_SOURCE_LINE (f));
04730 if (!pushdecl_class_level (f))
04731 is_valid = false;
04732 pop_srcloc ();
04733 }
04734 }
04735 timevar_pop (TV_NAME_LOOKUP);
04736
04737 return is_valid;
04738 }
04739
04740
04741
04742
04743 tree
04744 maybe_push_decl (decl)
04745 tree decl;
04746 {
04747 tree type = TREE_TYPE (decl);
04748
04749
04750
04751
04752 if (decl == error_mark_node
04753 || (TREE_CODE (decl) != PARM_DECL
04754 && DECL_CONTEXT (decl) != NULL_TREE
04755
04756
04757 && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL)
04758 || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ())
04759 || TREE_CODE (type) == UNKNOWN_TYPE
04760
04761
04762
04763 || (TREE_CODE (decl) == FUNCTION_DECL
04764 && DECL_TEMPLATE_SPECIALIZATION (decl)))
04765 return decl;
04766 else
04767 return pushdecl (decl);
04768 }
04769
04770
04771
04772
04773 bool
04774 push_class_level_binding (tree name, tree x)
04775 {
04776 cxx_binding *binding;
04777
04778 timevar_push (TV_NAME_LOOKUP);
04779
04780
04781 if (!class_binding_level)
04782 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
04783
04784
04785
04786 if (TYPE_BEING_DEFINED (current_class_type))
04787 check_template_shadow (x);
04788
04789
04790
04791
04792 binding = IDENTIFIER_BINDING (name);
04793 if (binding
04794 && ((TREE_CODE (x) == OVERLOAD
04795 && BINDING_VALUE (binding)
04796 && is_overloaded_fn (BINDING_VALUE (binding)))
04797 || INHERITED_VALUE_BINDING_P (binding)))
04798 {
04799 tree shadow;
04800 tree old_decl;
04801
04802
04803
04804
04805
04806 if (INHERITED_VALUE_BINDING_P (binding)
04807 && BINDING_VALUE (binding)
04808 && TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL
04809 && DECL_ARTIFICIAL (BINDING_VALUE (binding))
04810 && !(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)))
04811 {
04812 old_decl = BINDING_TYPE (binding);
04813 BINDING_TYPE (binding) = BINDING_VALUE (binding);
04814 BINDING_VALUE (binding) = NULL_TREE;
04815 INHERITED_VALUE_BINDING_P (binding) = 0;
04816 }
04817 else
04818 old_decl = BINDING_VALUE (binding);
04819
04820
04821
04822 for (shadow = class_binding_level->class_shadowed;
04823 shadow;
04824 shadow = TREE_CHAIN (shadow))
04825 if (TREE_PURPOSE (shadow) == name
04826 && TREE_TYPE (shadow) == old_decl)
04827 {
04828 BINDING_VALUE (binding) = x;
04829 INHERITED_VALUE_BINDING_P (binding) = 0;
04830 TREE_TYPE (shadow) = x;
04831 IDENTIFIER_CLASS_VALUE (name) = x;
04832 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
04833 }
04834 }
04835
04836
04837
04838 if (push_class_binding (name, x))
04839 {
04840 class_binding_level->class_shadowed
04841 = tree_cons (name, NULL,
04842 class_binding_level->class_shadowed);
04843
04844
04845 TREE_TYPE (class_binding_level->class_shadowed) = x;
04846 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
04847 }
04848
04849 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, false);
04850 }
04851
04852
04853
04854
04855
04856
04857 tree
04858 push_using_decl (scope, name)
04859 tree scope;
04860 tree name;
04861 {
04862 tree decl;
04863
04864 timevar_push (TV_NAME_LOOKUP);
04865
04866 my_friendly_assert (TREE_CODE (scope) == NAMESPACE_DECL, 383);
04867 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 384);
04868 for (decl = current_binding_level->usings; decl; decl = TREE_CHAIN (decl))
04869 if (DECL_INITIAL (decl) == scope && DECL_NAME (decl) == name)
04870 break;
04871 if (decl)
04872 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP,
04873 namespace_bindings_p () ? decl : NULL_TREE);
04874 decl = build_lang_decl (USING_DECL, name, void_type_node);
04875 DECL_INITIAL (decl) = scope;
04876 TREE_CHAIN (decl) = current_binding_level->usings;
04877 current_binding_level->usings = decl;
04878 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
04879 }
04880
04881
04882
04883
04884
04885 tree
04886 push_using_directive (used)
04887 tree used;
04888 {
04889 tree ud = current_binding_level->using_directives;
04890 tree iter, ancestor;
04891
04892 timevar_push (TV_NAME_LOOKUP);
04893
04894
04895 if (purpose_member (used, ud) != NULL_TREE)
04896 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
04897
04898 ancestor = namespace_ancestor (current_decl_namespace (), used);
04899 ud = current_binding_level->using_directives;
04900 ud = tree_cons (used, ancestor, ud);
04901 current_binding_level->using_directives = ud;
04902
04903
04904 for (iter = DECL_NAMESPACE_USING (used); iter; iter = TREE_CHAIN (iter))
04905 push_using_directive (TREE_PURPOSE (iter));
04906
04907 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ud);
04908 }
04909
04910
04911
04912
04913
04914
04915
04916
04917
04918
04919
04920
04921
04922
04923
04924
04925
04926
04927
04928
04929 tree
04930 push_overloaded_decl (decl, flags)
04931 tree decl;
04932 int flags;
04933 {
04934 tree name = DECL_NAME (decl);
04935 tree old;
04936 tree new_binding;
04937 int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL));
04938
04939 timevar_push (TV_NAME_LOOKUP);
04940
04941 if (doing_global)
04942 old = namespace_binding (name, DECL_CONTEXT (decl));
04943 else
04944 old = lookup_name_current_level (name);
04945
04946 if (old)
04947 {
04948 if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
04949 {
04950 tree t = TREE_TYPE (old);
04951 if (IS_AGGR_TYPE (t) && warn_shadow
04952 && (! DECL_IN_SYSTEM_HEADER (decl)
04953 || ! DECL_IN_SYSTEM_HEADER (old)))
04954 warning ("`%#D' hides constructor for `%#T'", decl, t);
04955 old = NULL_TREE;
04956 }
04957 else if (is_overloaded_fn (old))
04958 {
04959 tree tmp;
04960
04961 for (tmp = old; tmp; tmp = OVL_NEXT (tmp))
04962 {
04963 tree fn = OVL_CURRENT (tmp);
04964
04965 if (TREE_CODE (tmp) == OVERLOAD && OVL_USED (tmp)
04966 && !(flags & PUSH_USING)
04967 && compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
04968 TYPE_ARG_TYPES (TREE_TYPE (decl))))
04969 error ("`%#D' conflicts with previous using declaration `%#D'",
04970 decl, fn);
04971
04972 if (duplicate_decls (decl, fn))
04973 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, fn);
04974 }
04975 }
04976 else if (old == error_mark_node)
04977
04978 old = NULL_TREE;
04979 else
04980 {
04981 cp_error_at ("previous non-function declaration `%#D'", old);
04982 error ("conflicts with function declaration `%#D'", decl);
04983 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
04984 }
04985 }
04986
04987 if (old || TREE_CODE (decl) == TEMPLATE_DECL)
04988 {
04989 if (old && TREE_CODE (old) != OVERLOAD)
04990 new_binding = ovl_cons (decl, ovl_cons (old, NULL_TREE));
04991 else
04992 new_binding = ovl_cons (decl, old);
04993 if (flags & PUSH_USING)
04994 OVL_USED (new_binding) = 1;
04995 }
04996 else
04997
04998 new_binding = decl;
04999
05000 if (doing_global)
05001 set_namespace_binding (name, current_namespace, new_binding);
05002 else
05003 {
05004
05005
05006
05007
05008
05009
05010 if (TREE_CODE (new_binding) == OVERLOAD && old)
05011 {
05012 tree *d;
05013
05014 for (d = &BINDING_LEVEL (IDENTIFIER_BINDING (name))->names;
05015 *d;
05016 d = &TREE_CHAIN (*d))
05017 if (*d == old
05018 || (TREE_CODE (*d) == TREE_LIST
05019 && TREE_VALUE (*d) == old))
05020 {
05021 if (TREE_CODE (*d) == TREE_LIST)
05022
05023 TREE_VALUE (*d) = new_binding;
05024 else
05025
05026 *d = tree_cons (NULL_TREE, new_binding,
05027 TREE_CHAIN (*d));
05028
05029
05030 BINDING_VALUE (IDENTIFIER_BINDING (name))
05031 = new_binding;
05032 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
05033 }
05034
05035
05036 abort ();
05037 }
05038
05039
05040 push_local_binding (name, new_binding, flags);
05041 }
05042
05043 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
05044 }
05045
05046
05047
05048
05049 tree
05050 implicitly_declare (functionid)
05051 tree functionid;
05052 {
05053 register tree decl;
05054
05055
05056
05057
05058 decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
05059
05060 DECL_EXTERNAL (decl) = 1;
05061 TREE_PUBLIC (decl) = 1;
05062
05063
05064
05065 pushdecl (decl);
05066 rest_of_decl_compilation (decl, NULL, 0, 0);
05067
05068 if (warn_implicit
05069
05070 && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
05071 {
05072 pedwarn ("implicit declaration of function `%#D'", decl);
05073 }
05074
05075 SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
05076
05077 return decl;
05078 }
05079
05080
05081
05082
05083
05084
05085
05086 static const char *
05087 redeclaration_error_message (newdecl, olddecl)
05088 tree newdecl, olddecl;
05089 {
05090 if (TREE_CODE (newdecl) == TYPE_DECL)
05091 {
05092
05093
05094
05095 if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
05096 return 0;
05097 else
05098 return "redefinition of `%#D'";
05099 }
05100 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
05101 {
05102
05103
05104
05105 if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl))
05106 return 0;
05107
05108
05109
05110 if (DECL_NAMESPACE_SCOPE_P (olddecl)
05111 && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl))
05112 return "`%D' conflicts with used function";
05113
05114
05115
05116
05117
05118 if (DECL_INITIAL (olddecl) != NULL_TREE
05119 && DECL_INITIAL (newdecl) != NULL_TREE)
05120 {
05121 if (DECL_NAME (olddecl) == NULL_TREE)
05122 return "`%#D' not declared in class";
05123 else
05124 return "redefinition of `%#D'";
05125 }
05126 return 0;
05127 }
05128 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
05129 {
05130 if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
05131 && (DECL_TEMPLATE_RESULT (newdecl)
05132 != DECL_TEMPLATE_RESULT (olddecl))
05133 && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl))
05134 && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)))
05135 || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL
05136 && COMPLETE_TYPE_P (TREE_TYPE (newdecl))
05137 && COMPLETE_TYPE_P (TREE_TYPE (olddecl))))
05138 return "redefinition of `%#D'";
05139 return 0;
05140 }
05141 else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
05142 {
05143
05144
05145 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
05146 return 0;
05147
05148 return "redefinition of `%#D'";
05149 }
05150 else
05151 {
05152
05153
05154
05155 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
05156 return "redeclaration of `%#D'";
05157 return 0;
05158 }
05159 }
05160
05161
05162
05163 static tree
05164 make_label_decl (id, local_p)
05165 tree id;
05166 int local_p;
05167 {
05168 tree decl;
05169
05170 decl = build_decl (LABEL_DECL, id, void_type_node);
05171 if (expanding_p)
05172
05173 label_rtx (decl);
05174
05175 DECL_CONTEXT (decl) = current_function_decl;
05176 DECL_MODE (decl) = VOIDmode;
05177 C_DECLARED_LABEL_FLAG (decl) = local_p;
05178
05179
05180
05181 DECL_SOURCE_LINE (decl) = lineno;
05182 DECL_SOURCE_FILE (decl) = input_filename;
05183
05184
05185 SET_IDENTIFIER_LABEL_VALUE (id, decl);
05186
05187 return decl;
05188 }
05189
05190
05191
05192
05193
05194
05195 static void
05196 use_label (decl)
05197 tree decl;
05198 {
05199 if (named_label_uses == NULL
05200 || named_label_uses->names_in_scope != current_binding_level->names
05201 || named_label_uses->label_decl != decl)
05202 {
05203 struct named_label_use_list *new_ent;
05204 new_ent = ((struct named_label_use_list *)
05205 ggc_alloc (sizeof (struct named_label_use_list)));
05206 new_ent->label_decl = decl;
05207 new_ent->names_in_scope = current_binding_level->names;
05208 new_ent->binding_level = current_binding_level;
05209 new_ent->lineno_o_goto = lineno;
05210 new_ent->filename_o_goto = input_filename;
05211 new_ent->next = named_label_uses;
05212 named_label_uses = new_ent;
05213 }
05214 }
05215
05216
05217
05218
05219
05220 tree
05221 lookup_label (id)
05222 tree id;
05223 {
05224 tree decl;
05225 struct named_label_list *ent;
05226
05227 timevar_push (TV_NAME_LOOKUP);
05228
05229
05230 if (current_function_decl == NULL_TREE)
05231 {
05232 error ("label `%s' referenced outside of any function",
05233 IDENTIFIER_POINTER (id));
05234 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05235 }
05236
05237
05238 decl = IDENTIFIER_LABEL_VALUE (id);
05239 if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
05240 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
05241
05242
05243
05244
05245 ent = ((struct named_label_list *)
05246 ggc_alloc_cleared (sizeof (struct named_label_list)));
05247 ent->old_value = IDENTIFIER_LABEL_VALUE (id);
05248 ent->next = named_labels;
05249 named_labels = ent;
05250
05251
05252 decl = make_label_decl (id, 0);
05253
05254
05255 ent->label_decl = decl;
05256
05257 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
05258 }
05259
05260
05261
05262 tree
05263 declare_local_label (id)
05264 tree id;
05265 {
05266 tree decl;
05267
05268
05269
05270
05271 current_binding_level->shadowed_labels
05272 = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
05273 current_binding_level->shadowed_labels);
05274
05275 decl = make_label_decl (id, 1);
05276
05277 TREE_VALUE (current_binding_level->shadowed_labels) = decl;
05278
05279 return decl;
05280 }
05281
05282
05283
05284
05285 static int
05286 decl_jump_unsafe (decl)
05287 tree decl;
05288 {
05289 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl))
05290 return 0;
05291
05292 if (DECL_INITIAL (decl) == NULL_TREE
05293 && pod_type_p (TREE_TYPE (decl)))
05294 return 0;
05295
05296
05297
05298
05299 if (DECL_INITIAL (decl)
05300 || (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))
05301 return 2;
05302 return 1;
05303 }
05304
05305
05306
05307
05308
05309
05310 static void
05311 check_previous_goto_1 (decl, level, names, file, line)
05312 tree decl;
05313 struct cp_binding_level *level;
05314 tree names;
05315 const char *file;
05316 int line;
05317 {
05318 int identified = 0;
05319 int saw_eh = 0;
05320 struct cp_binding_level *b = current_binding_level;
05321 for (; b; b = b->level_chain)
05322 {
05323 tree new_decls = b->names;
05324 tree old_decls = (b == level ? names : NULL_TREE);
05325 for (; new_decls != old_decls;
05326 new_decls = TREE_CHAIN (new_decls))
05327 {
05328 int problem = decl_jump_unsafe (new_decls);
05329 if (! problem)
05330 continue;
05331
05332 if (! identified)
05333 {
05334 if (decl)
05335 pedwarn ("jump to label `%D'", decl);
05336 else
05337 pedwarn ("jump to case label");
05338
05339 if (file)
05340 pedwarn_with_file_and_line (file, line, " from here");
05341 identified = 1;
05342 }
05343
05344 if (problem > 1)
05345 cp_error_at (" crosses initialization of `%#D'",
05346 new_decls);
05347 else
05348 cp_pedwarn_at (" enters scope of non-POD `%#D'",
05349 new_decls);
05350 }
05351
05352 if (b == level)
05353 break;
05354 if ((b->is_try_scope || b->is_catch_scope) && ! saw_eh)
05355 {
05356 if (! identified)
05357 {
05358 if (decl)
05359 pedwarn ("jump to label `%D'", decl);
05360 else
05361 pedwarn ("jump to case label");
05362
05363 if (file)
05364 pedwarn_with_file_and_line (file, line, " from here");
05365 identified = 1;
05366 }
05367 if (b->is_try_scope)
05368 error (" enters try block");
05369 else
05370 error (" enters catch block");
05371 saw_eh = 1;
05372 }
05373 }
05374 }
05375
05376 static void
05377 check_previous_goto (use)
05378 struct named_label_use_list *use;
05379 {
05380 check_previous_goto_1 (use->label_decl, use->binding_level,
05381 use->names_in_scope, use->filename_o_goto,
05382 use->lineno_o_goto);
05383 }
05384
05385 static void
05386 check_switch_goto (level)
05387 struct cp_binding_level *level;
05388 {
05389 check_previous_goto_1 (NULL_TREE, level, level->names, NULL, 0);
05390 }
05391
05392
05393
05394
05395 static void
05396 check_previous_gotos (decl)
05397 tree decl;
05398 {
05399 struct named_label_use_list **usep;
05400
05401 if (! TREE_USED (decl))
05402 return;
05403
05404 for (usep = &named_label_uses; *usep; )
05405 {
05406 struct named_label_use_list *use = *usep;
05407 if (use->label_decl == decl)
05408 {
05409 check_previous_goto (use);
05410 *usep = use->next;
05411 }
05412 else
05413 usep = &(use->next);
05414 }
05415 }
05416
05417
05418
05419
05420 void
05421 check_goto (decl)
05422 tree decl;
05423 {
05424 int identified = 0;
05425 tree bad;
05426 struct named_label_list *lab;
05427
05428
05429
05430 if (! DECL_P (decl))
05431 return;
05432
05433
05434 if (! DECL_INITIAL (decl))
05435 {
05436 use_label (decl);
05437 return;
05438 }
05439
05440 for (lab = named_labels; lab; lab = lab->next)
05441 if (decl == lab->label_decl)
05442 break;
05443
05444
05445
05446 if (lab == 0)
05447 return;
05448
05449 if ((lab->in_try_scope || lab->in_catch_scope || lab->bad_decls)
05450 && !identified)
05451 {
05452 cp_pedwarn_at ("jump to label `%D'", decl);
05453 pedwarn (" from here");
05454 identified = 1;
05455 }
05456
05457 for (bad = lab->bad_decls; bad; bad = TREE_CHAIN (bad))
05458 {
05459 tree b = TREE_VALUE (bad);
05460 int u = decl_jump_unsafe (b);
05461
05462 if (u > 1 && DECL_ARTIFICIAL (b))
05463
05464 cp_error_at (" enters catch block", b);
05465 else if (u > 1)
05466 cp_error_at (" skips initialization of `%#D'", b);
05467 else
05468 cp_pedwarn_at (" enters scope of non-POD `%#D'", b);
05469 }
05470
05471 if (lab->in_try_scope)
05472 error (" enters try block");
05473 else if (lab->in_catch_scope)
05474 error (" enters catch block");
05475 }
05476
05477
05478
05479
05480 tree
05481 define_label (filename, line, name)
05482 const char *filename;
05483 int line;
05484 tree name;
05485 {
05486 tree decl = lookup_label (name);
05487 struct named_label_list *ent;
05488 register struct cp_binding_level *p;
05489
05490 timevar_push (TV_NAME_LOOKUP);
05491
05492 for (ent = named_labels; ent; ent = ent->next)
05493 if (ent->label_decl == decl)
05494 break;
05495
05496
05497
05498 for (p = current_binding_level; !(p->parm_flag); p = p->level_chain)
05499 p->more_cleanups_ok = 0;
05500
05501 if (name == get_identifier ("wchar_t"))
05502 pedwarn ("label named wchar_t");
05503
05504 if (DECL_INITIAL (decl) != NULL_TREE)
05505 error ("duplicate label `%D'", decl);
05506 else
05507 {
05508
05509 DECL_INITIAL (decl) = error_mark_node;
05510
05511 DECL_SOURCE_FILE (decl) = filename;
05512 DECL_SOURCE_LINE (decl) = line;
05513 if (ent)
05514 {
05515 ent->names_in_scope = current_binding_level->names;
05516 ent->binding_level = current_binding_level;
05517 }
05518 check_previous_gotos (decl);
05519 }
05520
05521 timevar_pop (TV_NAME_LOOKUP);
05522 return decl;
05523 }
05524
05525 struct cp_switch
05526 {
05527 struct cp_binding_level *level;
05528 struct cp_switch *next;
05529
05530 tree switch_stmt;
05531
05532
05533
05534
05535
05536 splay_tree cases;
05537 };
05538
05539
05540
05541
05542
05543
05544
05545 static struct cp_switch *switch_stack;
05546
05547
05548
05549
05550 void
05551 push_switch (switch_stmt)
05552 tree switch_stmt;
05553 {
05554 struct cp_switch *p
05555 = (struct cp_switch *) xmalloc (sizeof (struct cp_switch));
05556 p->level = current_binding_level;
05557 p->next = switch_stack;
05558 p->switch_stmt = switch_stmt;
05559 p->cases = splay_tree_new (case_compare, NULL, NULL);
05560 switch_stack = p;
05561 }
05562
05563 void
05564 pop_switch ()
05565 {
05566 struct cp_switch *cs;
05567
05568 cs = switch_stack;
05569 splay_tree_delete (cs->cases);
05570 switch_stack = switch_stack->next;
05571 free (cs);
05572 }
05573
05574
05575
05576
05577 tree
05578 finish_case_label (low_value, high_value)
05579 tree low_value;
05580 tree high_value;
05581 {
05582 tree cond, r;
05583 register struct cp_binding_level *p;
05584
05585 if (! switch_stack)
05586 {
05587 if (high_value)
05588 error ("case label not within a switch statement");
05589 else if (low_value)
05590 error ("case label `%E' not within a switch statement",
05591 low_value);
05592 else
05593 error ("`default' label not within a switch statement");
05594 return NULL_TREE;
05595 }
05596
05597 if (processing_template_decl)
05598 {
05599 tree label;
05600
05601
05602
05603 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
05604 return add_stmt (build_case_label (low_value, high_value, label));
05605 }
05606
05607
05608 cond = SWITCH_COND (switch_stack->switch_stmt);
05609 if (cond && TREE_CODE (cond) == TREE_LIST)
05610 cond = TREE_VALUE (cond);
05611
05612 r = c_add_case_label (switch_stack->cases, cond, low_value, high_value);
05613 if (r == error_mark_node)
05614 r = NULL_TREE;
05615
05616 check_switch_goto (switch_stack->level);
05617
05618
05619
05620 for (p = current_binding_level; !(p->parm_flag); p = p->level_chain)
05621 p->more_cleanups_ok = 0;
05622
05623 return r;
05624 }
05625
05626
05627
05628
05629
05630
05631 tree
05632 getdecls ()
05633 {
05634 return current_binding_level->names;
05635 }
05636
05637
05638
05639
05640
05641 static void
05642 storedecls (decls)
05643 tree decls;
05644 {
05645 current_binding_level->names = decls;
05646 }
05647
05648
05649
05650
05651 void
05652 cxx_remember_type_decls (binding_table table)
05653 {
05654 current_binding_level->type_decls = table;
05655 }
05656
05657
05658
05659
05660
05661
05662
05663
05664
05665
05666
05667
05668
05669
05670
05671
05672
05673
05674
05675
05676
05677
05678
05679
05680
05681 static tree
05682 follow_tag_typedef (type)
05683 tree type;
05684 {
05685 tree original;
05686
05687 original = original_type (type);
05688 if (! TYPE_NAME (original))
05689 return NULL_TREE;
05690 if (TYPE_IDENTIFIER (original) == TYPE_IDENTIFIER (type)
05691 && (CP_DECL_CONTEXT (TYPE_NAME (original))
05692 == CP_DECL_CONTEXT (TYPE_NAME (type)))
05693 && !(CLASS_TYPE_P (original) && TYPE_WAS_ANONYMOUS (original)))
05694 return original;
05695 else
05696 return NULL_TREE;
05697 }
05698
05699
05700
05701
05702
05703
05704
05705
05706
05707
05708
05709
05710 static tree
05711 lookup_tag (form, name, binding_level, thislevel_only)
05712 enum tree_code form;
05713 tree name;
05714 struct cp_binding_level *binding_level;
05715 int thislevel_only;
05716 {
05717 register struct cp_binding_level *level;
05718
05719
05720 int allow_template_parms_p = 1;
05721 bool type_is_anonymous = ANON_AGGRNAME_P (name);
05722
05723 timevar_push (TV_NAME_LOOKUP);
05724
05725 for (level = binding_level; level; level = level->level_chain)
05726 {
05727 register tree tail;
05728 if (type_is_anonymous && level->type_decls != NULL)
05729 {
05730 tree type = binding_table_find_anon_type (level->type_decls, name);
05731
05732
05733 if (type != NULL)
05734 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, type);
05735 }
05736 else if (level->namespace_p)
05737
05738 for (tail = current_namespace; 1; tail = CP_DECL_CONTEXT (tail))
05739 {
05740 cxx_binding *binding =
05741 cxx_scope_find_binding_for_name (tail, name);
05742 tree old;
05743
05744
05745
05746
05747
05748 if (thislevel_only && !allow_template_parms_p
05749 && binding && BINDING_VALUE (binding)
05750 && DECL_CLASS_TEMPLATE_P (BINDING_VALUE (binding)))
05751 old = TREE_TYPE (BINDING_VALUE (binding));
05752 else if (binding)
05753 old = BINDING_TYPE (binding);
05754 else
05755 old = NULL;
05756
05757 if (old)
05758 {
05759
05760
05761
05762 old = follow_tag_typedef (old);
05763 if (!old)
05764 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05765 if (TREE_CODE (old) != form
05766 && (form == ENUMERAL_TYPE
05767 || TREE_CODE (old) == ENUMERAL_TYPE))
05768 {
05769 error ("`%#D' redeclared as %C", old, form);
05770 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05771 }
05772 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, old);
05773 }
05774 if (thislevel_only || tail == global_namespace)
05775 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05776 }
05777 else if (level->type_decls != NULL)
05778 {
05779 binding_entry entry = binding_table_find (level->type_decls, name);
05780 if (entry != NULL)
05781 {
05782 enum tree_code code = TREE_CODE (entry->type);
05783
05784 if (code != form
05785 && (form == ENUMERAL_TYPE || code == ENUMERAL_TYPE))
05786 {
05787
05788 error ("`%#D' redeclared as %C", entry->type, form);
05789 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05790 }
05791 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, entry->type);
05792 }
05793 }
05794 if (thislevel_only && ! level->tag_transparent)
05795 {
05796 if (level->template_parms_p && allow_template_parms_p)
05797 {
05798
05799
05800
05801
05802
05803
05804
05805
05806
05807
05808
05809 allow_template_parms_p = 0;
05810 continue;
05811 }
05812 else
05813 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05814 }
05815 }
05816 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05817 }
05818
05819 #if 0
05820 void
05821 set_current_level_tags_transparency (tags_transparent)
05822 int tags_transparent;
05823 {
05824 current_binding_level->tag_transparent = tags_transparent;
05825 }
05826 #endif
05827
05828
05829
05830
05831
05832
05833
05834
05835 static tree
05836 lookup_tag_reverse (type, name)
05837 tree type;
05838 tree name;
05839 {
05840 register struct cp_binding_level *level;
05841
05842 timevar_push (TV_NAME_LOOKUP);
05843
05844 for (level = current_binding_level; level; level = level->level_chain)
05845 {
05846 binding_entry entry = level->type_decls == NULL
05847 ? NULL
05848 : binding_table_reverse_maybe_remap (level->type_decls, type, name);
05849 if (entry)
05850 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, entry->name);
05851 }
05852 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05853 }
05854
05855
05856
05857 tree
05858 lookup_namespace_name (namespace, name)
05859 tree namespace, name;
05860 {
05861 tree val;
05862 tree template_id = NULL_TREE;
05863 cxx_binding binding;
05864
05865 timevar_push (TV_NAME_LOOKUP);
05866
05867 my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370);
05868
05869 if (TREE_CODE (name) == NAMESPACE_DECL)
05870
05871 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, name);
05872 else if (TREE_CODE (name) == TEMPLATE_DECL)
05873 {
05874
05875
05876 error ("invalid use of `%D'", name);
05877 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
05878 }
05879
05880 namespace = ORIGINAL_NAMESPACE (namespace);
05881
05882 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
05883 {
05884 template_id = name;
05885 name = TREE_OPERAND (name, 0);
05886 if (TREE_CODE (name) == OVERLOAD)
05887 name = DECL_NAME (OVL_CURRENT (name));
05888 else if (DECL_P (name))
05889 name = DECL_NAME (name);
05890 }
05891
05892 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373);
05893
05894 cxx_binding_clear (&binding);
05895 if (!qualified_lookup_using_namespace (name, namespace, &binding, 0))
05896 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
05897
05898 if (binding.value)
05899 {
05900 val = binding.value;
05901
05902 if (template_id)
05903 {
05904 if (DECL_CLASS_TEMPLATE_P (val))
05905 val = lookup_template_class (val,
05906 TREE_OPERAND (template_id, 1),
05907 NULL_TREE,
05908 NULL_TREE,
05909 0,
05910 tf_error | tf_warning);
05911 else if (DECL_FUNCTION_TEMPLATE_P (val)
05912 || TREE_CODE (val) == OVERLOAD)
05913 val = lookup_template_function (val,
05914 TREE_OPERAND (template_id, 1));
05915 else
05916 {
05917 error ("`%D::%D' is not a template",
05918 namespace, name);
05919 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
05920 }
05921 }
05922
05923
05924 if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val))
05925 val = OVL_FUNCTION (val);
05926
05927
05928 if (!val || !DECL_P(val)
05929 || !DECL_LANG_SPECIFIC(val)
05930 || !DECL_ANTICIPATED (val))
05931 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
05932 }
05933
05934 error ("`%D' undeclared in namespace `%D'", name, namespace);
05935 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
05936 }
05937
05938
05939
05940 static hashval_t
05941 typename_hash (k)
05942 const void * k;
05943 {
05944 hashval_t hash;
05945 tree t = (tree) k;
05946
05947 hash = (htab_hash_pointer (TYPE_CONTEXT (t))
05948 ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
05949
05950 return hash;
05951 }
05952
05953
05954
05955 static int
05956 typename_compare (k1, k2)
05957 const void * k1;
05958 const void * k2;
05959 {
05960 tree t1;
05961 tree t2;
05962 tree d1;
05963 tree d2;
05964
05965 t1 = (tree) k1;
05966 t2 = (tree) k2;
05967 d1 = TYPE_NAME (t1);
05968 d2 = TYPE_NAME (t2);
05969
05970 return (DECL_NAME (d1) == DECL_NAME (d2)
05971 && TYPE_CONTEXT (t1) == TYPE_CONTEXT (t2)
05972 && ((TREE_TYPE (t1) != NULL_TREE)
05973 == (TREE_TYPE (t2) != NULL_TREE))
05974 && same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
05975 && TYPENAME_TYPE_FULLNAME (t1) == TYPENAME_TYPE_FULLNAME (t2));
05976 }
05977
05978
05979
05980
05981
05982
05983
05984
05985
05986 static GTY ((param_is (union tree_node))) htab_t typename_htab;
05987
05988 tree
05989 build_typename_type (context, name, fullname, base_type)
05990 tree context;
05991 tree name;
05992 tree fullname;
05993 tree base_type;
05994 {
05995 tree t;
05996 tree d;
05997 PTR *e;
05998
05999 if (typename_htab == NULL)
06000 {
06001 typename_htab = htab_create_ggc (61, &typename_hash,
06002 &typename_compare, NULL);
06003 }
06004
06005
06006 t = make_aggr_type (TYPENAME_TYPE);
06007 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
06008 TYPENAME_TYPE_FULLNAME (t) = fullname;
06009 TREE_TYPE (t) = base_type;
06010
06011
06012 d = build_decl (TYPE_DECL, name, t);
06013 TYPE_NAME (TREE_TYPE (d)) = d;
06014 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
06015 DECL_CONTEXT (d) = FROB_CONTEXT (context);
06016 DECL_ARTIFICIAL (d) = 1;
06017
06018
06019 e = htab_find_slot (typename_htab, t, INSERT);
06020 if (*e)
06021 t = (tree) *e;
06022 else
06023 *e = t;
06024
06025 return t;
06026 }
06027
06028
06029
06030
06031
06032
06033
06034
06035 tree
06036 make_typename_type (context, name, complain)
06037 tree context, name;
06038 tsubst_flags_t complain;
06039 {
06040 tree fullname;
06041
06042 if (TYPE_P (name))
06043 {
06044 if (!(TYPE_LANG_SPECIFIC (name)
06045 && (CLASSTYPE_IS_TEMPLATE (name)
06046 || CLASSTYPE_USE_TEMPLATE (name))))
06047 name = TYPE_IDENTIFIER (name);
06048 else
06049
06050 name = build_nt (TEMPLATE_ID_EXPR,
06051 CLASSTYPE_TI_TEMPLATE (name),
06052 CLASSTYPE_TI_ARGS (name));
06053 }
06054 else if (TREE_CODE (name) == TYPE_DECL)
06055 name = DECL_NAME (name);
06056
06057 fullname = name;
06058
06059 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
06060 {
06061 name = TREE_OPERAND (name, 0);
06062 if (TREE_CODE (name) == TEMPLATE_DECL)
06063 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
06064 }
06065 if (TREE_CODE (name) == TEMPLATE_DECL)
06066 {
06067 error ("`%D' used without template parameters", name);
06068 return error_mark_node;
06069 }
06070 if (TREE_CODE (name) != IDENTIFIER_NODE)
06071 abort ();
06072
06073 if (TREE_CODE (context) == NAMESPACE_DECL)
06074 {
06075
06076
06077 if (complain & tf_error)
06078 error ("no class template named `%#T' in `%#T'",
06079 name, context);
06080 return error_mark_node;
06081 }
06082
06083 if (! uses_template_parms (context)
06084 || currently_open_class (context))
06085 {
06086 if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
06087 {
06088 tree tmpl = NULL_TREE;
06089 if (IS_AGGR_TYPE (context))
06090 tmpl = lookup_field (context, name, 0, 0);
06091 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
06092 {
06093 if (complain & tf_error)
06094 error ("no class template named `%#T' in `%#T'",
06095 name, context);
06096 return error_mark_node;
06097 }
06098
06099 if (complain & tf_error)
06100 {
06101 if (complain & tf_parsing)
06102 type_access_control (context, tmpl);
06103 else
06104 enforce_access (context, tmpl);
06105 }
06106
06107 return lookup_template_class (tmpl,
06108 TREE_OPERAND (fullname, 1),
06109 NULL_TREE, context,
06110 0,
06111 tf_error | tf_warning);
06112 }
06113 else
06114 {
06115 tree t;
06116
06117 if (!IS_AGGR_TYPE (context))
06118 {
06119 if (complain & tf_error)
06120 error ("no type named `%#T' in `%#T'", name, context);
06121 return error_mark_node;
06122 }
06123
06124 t = lookup_field (context, name, 0, 1);
06125 if (t)
06126 {
06127 if (TREE_CODE (t) != TYPE_DECL)
06128 {
06129 if (complain & tf_error)
06130 error ("no type named `%#T' in `%#T'", name, context);
06131 return error_mark_node;
06132 }
06133
06134 if (complain & tf_error)
06135 {
06136 if (complain & tf_parsing)
06137 type_access_control (context, t);
06138 else
06139 enforce_access (context, t);
06140 }
06141
06142 if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
06143 t = TREE_TYPE (t);
06144 if (IMPLICIT_TYPENAME_P (t))
06145 {
06146
06147
06148
06149
06150
06151 t = copy_node (t);
06152 TREE_TYPE (t) = NULL_TREE;
06153 }
06154
06155 return t;
06156 }
06157 }
06158 }
06159
06160
06161
06162 if (!uses_template_parms (context))
06163 {
06164 if (complain & tf_error)
06165 error ("no type named `%#T' in `%#T'", name, context);
06166 return error_mark_node;
06167 }
06168
06169 return build_typename_type (context, name, fullname, NULL_TREE);
06170 }
06171
06172
06173
06174
06175
06176
06177
06178 tree
06179 make_unbound_class_template (context, name, complain)
06180 tree context, name;
06181 tsubst_flags_t complain;
06182 {
06183 tree t;
06184 tree d;
06185
06186 if (TYPE_P (name))
06187 name = TYPE_IDENTIFIER (name);
06188 else if (DECL_P (name))
06189 name = DECL_NAME (name);
06190 if (TREE_CODE (name) != IDENTIFIER_NODE)
06191 abort ();
06192
06193 if (!uses_template_parms (context)
06194 || currently_open_class (context))
06195 {
06196 tree tmpl = NULL_TREE;
06197
06198 if (IS_AGGR_TYPE (context))
06199 tmpl = lookup_field (context, name, 0, 0);
06200
06201 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
06202 {
06203 if (complain & tf_error)
06204 error ("no class template named `%#T' in `%#T'", name, context);
06205 return error_mark_node;
06206 }
06207
06208 if (complain & tf_error)
06209 {
06210 if (complain & tf_parsing)
06211 type_access_control (context, tmpl);
06212 else
06213 enforce_access (context, tmpl);
06214 }
06215
06216 return tmpl;
06217 }
06218
06219
06220 t = make_aggr_type (UNBOUND_CLASS_TEMPLATE);
06221 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
06222 TREE_TYPE (t) = NULL_TREE;
06223
06224
06225 d = build_decl (TEMPLATE_DECL, name, t);
06226 TYPE_NAME (TREE_TYPE (d)) = d;
06227 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
06228 DECL_CONTEXT (d) = FROB_CONTEXT (context);
06229 DECL_ARTIFICIAL (d) = 1;
06230
06231 return t;
06232 }
06233
06234
06235
06236 static tree
06237 select_decl (cxx_binding *binding, int flags)
06238 {
06239 tree val;
06240
06241 timevar_push (TV_NAME_LOOKUP);
06242
06243 val = BINDING_VALUE (binding);
06244
06245 if (LOOKUP_NAMESPACES_ONLY (flags))
06246 {
06247
06248 if (val && TREE_CODE (val) == NAMESPACE_DECL)
06249 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
06250 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
06251 }
06252
06253
06254
06255 if (BINDING_TYPE (binding)
06256 && (!val || ((flags & LOOKUP_PREFER_TYPES)
06257 && TREE_CODE (val) != TYPE_DECL)))
06258 val = TYPE_STUB_DECL (BINDING_TYPE (binding));
06259
06260 else if (val && LOOKUP_TYPES_ONLY (flags) && TREE_CODE (val) != TYPE_DECL
06261 && (TREE_CODE (val) != TEMPLATE_DECL
06262 || !DECL_CLASS_TEMPLATE_P (val)))
06263 val = NULL_TREE;
06264
06265 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
06266 }
06267
06268
06269
06270
06271
06272 tree
06273 unqualified_namespace_lookup (name, flags, spacesp)
06274 tree name;
06275 int flags;
06276 tree *spacesp;
06277 {
06278 tree initial = current_decl_namespace ();
06279 tree scope = initial;
06280 tree siter;
06281 struct cp_binding_level *level;
06282 tree val = NULL_TREE;
06283 cxx_binding binding;
06284
06285 timevar_push (TV_NAME_LOOKUP);
06286 cxx_binding_clear (&binding);
06287 if (spacesp)
06288 *spacesp = NULL_TREE;
06289
06290 for (; !val; scope = CP_DECL_CONTEXT (scope))
06291 {
06292 cxx_binding *b;
06293 if (spacesp)
06294 *spacesp = tree_cons (scope, NULL_TREE, *spacesp);
06295 b = cxx_scope_find_binding_for_name (scope, name);
06296
06297
06298 if (b && BINDING_VALUE (b) && DECL_P (BINDING_VALUE (b))
06299 && DECL_LANG_SPECIFIC (BINDING_VALUE (b))
06300 && DECL_ANTICIPATED (BINDING_VALUE (b)))
06301 ;
06302 else if (b)
06303 {
06304
06305 binding.value = BINDING_VALUE (b);
06306 binding.type = BINDING_TYPE (b);
06307 }
06308
06309
06310 for (level = current_binding_level;
06311 !level->namespace_p;
06312 level = level->level_chain)
06313 if (!lookup_using_namespace (name, &binding, level->using_directives,
06314 scope, flags, spacesp))
06315
06316 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
06317
06318
06319
06320 siter = initial;
06321 while (1)
06322 {
06323 if (!lookup_using_namespace (name, &binding,
06324 DECL_NAMESPACE_USING (siter),
06325 scope, flags, spacesp))
06326
06327 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
06328 if (siter == scope) break;
06329 siter = CP_DECL_CONTEXT (siter);
06330 }
06331
06332 val = select_decl (&binding, flags);
06333 if (scope == global_namespace)
06334 break;
06335 }
06336 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
06337 }
06338
06339
06340
06341 static int
06342 lookup_flags (prefer_type, namespaces_only)
06343 int prefer_type, namespaces_only;
06344 {
06345 if (namespaces_only)
06346 return LOOKUP_PREFER_NAMESPACES;
06347 if (prefer_type > 1)
06348 return LOOKUP_PREFER_TYPES;
06349 if (prefer_type > 0)
06350 return LOOKUP_PREFER_BOTH;
06351 return 0;
06352 }
06353
06354
06355
06356
06357 static tree
06358 qualify_lookup (val, flags)
06359 tree val;
06360 int flags;
06361 {
06362 if (val == NULL_TREE)
06363 return val;
06364 if ((flags & LOOKUP_PREFER_NAMESPACES) && TREE_CODE (val) == NAMESPACE_DECL)
06365 return val;
06366 if ((flags & LOOKUP_PREFER_TYPES)
06367 && (TREE_CODE (val) == TYPE_DECL
06368 || ((flags & LOOKUP_TEMPLATES_EXPECTED)
06369 && DECL_CLASS_TEMPLATE_P (val))))
06370 return val;
06371 if (flags & (LOOKUP_PREFER_NAMESPACES | LOOKUP_PREFER_TYPES))
06372 return NULL_TREE;
06373 return val;
06374 }
06375
06376
06377
06378
06379 static void
06380 warn_about_implicit_typename_lookup (typename, binding)
06381 tree typename;
06382 tree binding;
06383 {
06384 tree subtype = TREE_TYPE (TREE_TYPE (typename));
06385 tree name = DECL_NAME (typename);
06386
06387 if (! (TREE_CODE (binding) == TEMPLATE_DECL
06388 && CLASS_TYPE_P (subtype)
06389 && CLASSTYPE_TEMPLATE_INFO (subtype)
06390 && CLASSTYPE_TI_TEMPLATE (subtype) == binding)
06391 && ! (TREE_CODE (binding) == TYPE_DECL
06392 && same_type_p (TREE_TYPE (binding), subtype)))
06393 {
06394 warning ("lookup of `%D' finds `%#D'",
06395 name, binding);
06396 warning (" instead of `%D' from dependent base class",
06397 typename);
06398 warning (" (use `typename %T::%D' if that's what you meant)",
06399 constructor_name (current_class_type), name);
06400 }
06401 }
06402
06403
06404
06405
06406
06407
06408
06409
06410 tree
06411 check_for_out_of_scope_variable (tree decl)
06412 {
06413 tree shadowed;
06414
06415
06416 if (!(TREE_CODE (decl) == VAR_DECL && DECL_DEAD_FOR_LOCAL (decl)))
06417 return decl;
06418
06419 shadowed = DECL_SHADOWED_FOR_VAR (decl);
06420 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
06421 && DECL_DEAD_FOR_LOCAL (shadowed))
06422 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
06423 if (!shadowed)
06424 shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (decl));
06425 if (shadowed)
06426 {
06427 if (!DECL_ERROR_REPORTED (decl))
06428 {
06429 warning ("name lookup of `%D' changed",
06430 DECL_NAME (decl));
06431 cp_warning_at (" matches this `%D' under ISO standard rules",
06432 shadowed);
06433 cp_warning_at (" matches this `%D' under old rules", decl);
06434 DECL_ERROR_REPORTED (decl) = 1;
06435 }
06436 return shadowed;
06437 }
06438
06439
06440
06441 if (DECL_ERROR_REPORTED (decl))
06442 return decl;
06443
06444 DECL_ERROR_REPORTED (decl) = 1;
06445 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
06446 {
06447 error ("name lookup of `%D' changed for new ISO `for' scoping",
06448 DECL_NAME (decl));
06449 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", decl);
06450 return error_mark_node;
06451 }
06452 else
06453 {
06454 pedwarn ("name lookup of `%D' changed for new ISO `for' scoping",
06455 DECL_NAME (decl));
06456 cp_pedwarn_at (" using obsolete binding at `%D'", decl);
06457 }
06458
06459 return decl;
06460 }
06461
06462
06463
06464
06465
06466
06467
06468
06469
06470
06471
06472
06473
06474
06475
06476 static tree
06477 lookup_name_real (name, prefer_type, nonclass, namespaces_only)
06478 tree name;
06479 int prefer_type, nonclass, namespaces_only;
06480 {
06481 tree t;
06482 tree val = NULL_TREE;
06483 int yylex = 0;
06484 tree from_obj = NULL_TREE;
06485 int flags;
06486 int val_is_implicit_typename = 0;
06487 cxx_binding *iter;
06488
06489 timevar_push (TV_NAME_LOOKUP);
06490
06491
06492 if (only_namespace_names)
06493 namespaces_only = 1;
06494
06495 if (prefer_type == -2)
06496 {
06497 extern int looking_for_typename;
06498 tree type = NULL_TREE;
06499
06500 yylex = 1;
06501 prefer_type = looking_for_typename;
06502
06503 flags = lookup_flags (prefer_type, namespaces_only);
06504
06505 if (looking_for_template)
06506 flags |= LOOKUP_TEMPLATES_EXPECTED;
06507
06508 if (got_scope)
06509 type = got_scope;
06510 else if (got_object != error_mark_node)
06511 type = got_object;
06512
06513 if (type)
06514 {
06515 if (type == error_mark_node)
06516 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
06517 if (IMPLICIT_TYPENAME_P (type))
06518 type = TREE_TYPE (type);
06519
06520 if (TYPE_P (type))
06521 type = complete_type (type);
06522
06523 if (TREE_CODE (type) == VOID_TYPE)
06524 type = global_namespace;
06525 if (TREE_CODE (type) == NAMESPACE_DECL)
06526 {
06527 cxx_binding b;
06528 cxx_binding_clear (&b);
06529 flags |= LOOKUP_COMPLAIN;
06530 if (!qualified_lookup_using_namespace (name, type, &b, flags))
06531 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
06532 val = select_decl (&b, flags);
06533 }
06534 else if (! IS_AGGR_TYPE (type)
06535 || TREE_CODE (type) == TEMPLATE_TYPE_PARM
06536 || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
06537 || TREE_CODE (type) == TYPENAME_TYPE)
06538
06539 val = NULL_TREE;
06540 else if (type == current_class_type)
06541 val = IDENTIFIER_CLASS_VALUE (name);
06542 else
06543 {
06544 val = lookup_member (type, name, 0, prefer_type);
06545 if (!uses_template_parms (type))
06546 type_access_control (type, val);
06547
06548
06549
06550 if (got_scope && got_scope != type
06551 && val && TREE_CODE (val) == TYPE_DECL
06552 && TREE_CODE (TREE_TYPE (val)) == TYPENAME_TYPE)
06553 {
06554 val = TREE_TYPE (val);
06555 val = build_typename_type (got_scope, name,
06556 TYPENAME_TYPE_FULLNAME (val),
06557 TREE_TYPE (val));
06558 val = TYPE_STUB_DECL (val);
06559 }
06560 }
06561 }
06562 else
06563 val = NULL_TREE;
06564
06565 if (got_scope)
06566 goto done;
06567 else if (got_object && val)
06568 {
06569 from_obj = val;
06570 val = NULL_TREE;
06571 }
06572 }
06573 else
06574 {
06575 flags = lookup_flags (prefer_type, namespaces_only);
06576
06577 flags |= LOOKUP_COMPLAIN;
06578 }
06579
06580
06581
06582
06583 if (IDENTIFIER_TYPENAME_P (name))
06584 {
06585 struct cp_binding_level *level;
06586
06587 for (level = current_binding_level;
06588 level && !level->namespace_p;
06589 level = level->level_chain)
06590 {
06591 tree class_type;
06592 tree operators;
06593
06594
06595
06596 if (level->parm_flag != 2)
06597 continue;
06598
06599
06600 class_type = level->this_class;
06601 operators = lookup_fnfields (class_type, name, 0);
06602 if (operators)
06603 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, operators);
06604 }
06605
06606 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
06607 }
06608
06609
06610
06611 if (current_class_type == NULL_TREE)
06612 nonclass = 1;
06613
06614 for (iter = IDENTIFIER_BINDING (name); iter; iter = iter->previous)
06615 {
06616 tree binding;
06617
06618 if (!LOCAL_BINDING_P (iter) && nonclass)
06619
06620 continue;
06621
06622
06623 if (qualify_lookup (BINDING_VALUE (iter), flags))
06624 binding = BINDING_VALUE (iter);
06625 else if ((flags & LOOKUP_PREFER_TYPES)
06626 && qualify_lookup (BINDING_TYPE (iter), flags))
06627 binding = BINDING_TYPE (iter);
06628 else
06629 binding = NULL_TREE;
06630
06631
06632 if (binding && ! yylex
06633 && BINDING_LEVEL (iter) && BINDING_LEVEL (iter)->parm_flag == 2)
06634 type_access_control (BINDING_LEVEL (iter)->this_class, binding);
06635
06636 if (binding
06637 && (!val || !IMPLICIT_TYPENAME_TYPE_DECL_P (binding)))
06638 {
06639 if (val_is_implicit_typename && !yylex)
06640 warn_about_implicit_typename_lookup (val, binding);
06641 val = binding;
06642 val_is_implicit_typename
06643 = IMPLICIT_TYPENAME_TYPE_DECL_P (val);
06644 if (!val_is_implicit_typename)
06645 break;
06646 }
06647 }
06648
06649
06650 if (!val && !nonclass && current_class_type)
06651 val = qualify_lookup (lookup_nested_field (name, !yylex), flags);
06652
06653
06654 if (!val || val_is_implicit_typename)
06655 {
06656 t = unqualified_namespace_lookup (name, flags, 0);
06657 if (t)
06658 {
06659 if (val_is_implicit_typename && !yylex)
06660 warn_about_implicit_typename_lookup (val, t);
06661 val = t;
06662 }
06663 }
06664
06665 done:
06666 if (val)
06667 {
06668
06669 if (from_obj && from_obj != val)
06670 {
06671 if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL
06672 && TREE_CODE (val) == TYPE_DECL
06673 && ! same_type_p (TREE_TYPE (from_obj), TREE_TYPE (val)))
06674 pedwarn ("\
06675 lookup of `%D' in the scope of `%#T' (`%#D') \
06676 does not match lookup in the current scope (`%#D')",
06677 name, got_object, from_obj, val);
06678
06679
06680
06681
06682 if (! uses_template_parms (got_object))
06683 val = from_obj;
06684 }
06685
06686
06687 if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val))
06688 val = OVL_FUNCTION (val);
06689 }
06690 else if (from_obj)
06691 val = from_obj;
06692
06693 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
06694 }
06695
06696 tree
06697 lookup_name_nonclass (name)
06698 tree name;
06699 {
06700 return lookup_name_real (name, 0, 1, 0);
06701 }
06702
06703 tree
06704 lookup_function_nonclass (name, args)
06705 tree name;
06706 tree args;
06707 {
06708 return lookup_arg_dependent (name, lookup_name_nonclass (name), args);
06709 }
06710
06711 tree
06712 lookup_name_namespace_only (name)
06713 tree name;
06714 {
06715
06716 return lookup_name_real (name, 1, 1, 1);
06717 }
06718
06719 tree
06720 lookup_name (name, prefer_type)
06721 tree name;
06722 int prefer_type;
06723 {
06724 return lookup_name_real (name, prefer_type, 0, 0);
06725 }
06726
06727
06728
06729
06730 tree
06731 lookup_name_current_level (name)
06732 tree name;
06733 {
06734 struct cp_binding_level *b;
06735 tree t = NULL_TREE;
06736
06737 timevar_push (TV_NAME_LOOKUP);
06738
06739 b = current_binding_level;
06740 while (b->parm_flag == 2)
06741 b = b->level_chain;
06742
06743 if (b->namespace_p)
06744 {
06745 t = IDENTIFIER_NAMESPACE_VALUE (name);
06746
06747
06748 if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
06749 t = TREE_VALUE (t);
06750 }
06751 else if (IDENTIFIER_BINDING (name)
06752 && LOCAL_BINDING_P (IDENTIFIER_BINDING (name)))
06753 {
06754 while (1)
06755 {
06756 if (BINDING_LEVEL (IDENTIFIER_BINDING (name)) == b)
06757 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, IDENTIFIER_VALUE (name));
06758
06759 if (b->keep == 2)
06760 b = b->level_chain;
06761 else
06762 break;
06763 }
06764 }
06765
06766 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
06767 }
06768
06769
06770
06771 tree
06772 lookup_type_current_level (name)
06773 tree name;
06774 {
06775 register tree t = NULL_TREE;
06776
06777 timevar_push (TV_NAME_LOOKUP);
06778
06779 my_friendly_assert (! current_binding_level->namespace_p, 980716);
06780
06781 if (REAL_IDENTIFIER_TYPE_VALUE (name) != NULL_TREE
06782 && REAL_IDENTIFIER_TYPE_VALUE (name) != global_type_node)
06783 {
06784 struct cp_binding_level *b = current_binding_level;
06785 while (1)
06786 {
06787 if (purpose_member (name, b->type_shadowed))
06788 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP,
06789 REAL_IDENTIFIER_TYPE_VALUE (name));
06790 if (b->keep == 2)
06791 b = b->level_chain;
06792 else
06793 break;
06794 }
06795 }
06796
06797 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
06798 }
06799
06800 void
06801 begin_only_namespace_names ()
06802 {
06803 only_namespace_names = 1;
06804 }
06805
06806 void
06807 end_only_namespace_names ()
06808 {
06809 only_namespace_names = 0;
06810 }
06811
06812
06813
06814
06815
06816
06817 void
06818 record_builtin_type (rid_index, name, type)
06819 enum rid rid_index;
06820 const char *name;
06821 tree type;
06822 {
06823 tree rname = NULL_TREE, tname = NULL_TREE;
06824 tree tdecl = NULL_TREE;
06825
06826 if ((int) rid_index < (int) RID_MAX)
06827 rname = ridpointers[(int) rid_index];
06828 if (name)
06829 tname = get_identifier (name);
06830
06831 TYPE_BUILT_IN (type) = 1;
06832
06833 if (tname)
06834 {
06835 tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
06836 set_identifier_type_value (tname, NULL_TREE);
06837 if ((int) rid_index < (int) RID_MAX)
06838
06839 SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
06840 }
06841 if (rname != NULL_TREE)
06842 {
06843 if (tname != NULL_TREE)
06844 {
06845 set_identifier_type_value (rname, NULL_TREE);
06846 SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
06847 }
06848 else
06849 {
06850 tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
06851 set_identifier_type_value (rname, NULL_TREE);
06852 }
06853 }
06854 }
06855
06856
06857
06858
06859
06860
06861 static tree
06862 record_builtin_java_type (name, size)
06863 const char *name;
06864 int size;
06865 {
06866 tree type, decl;
06867 if (size > 0)
06868 type = make_signed_type (size);
06869 else if (size > -32)
06870 {
06871 type = make_unsigned_type (-size);
06872
06873 }
06874 else
06875 {
06876 type = make_node (REAL_TYPE);
06877 TYPE_PRECISION (type) = - size;
06878 layout_type (type);
06879 }
06880 record_builtin_type (RID_MAX, name, type);
06881 decl = TYPE_NAME (type);
06882
06883
06884
06885
06886 DECL_IGNORED_P (decl) = 1;
06887
06888 TYPE_FOR_JAVA (type) = 1;
06889 return type;
06890 }
06891
06892
06893
06894 static void
06895 record_unknown_type (type, name)
06896 tree type;
06897 const char *name;
06898 {
06899 tree decl = pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
06900
06901 DECL_IGNORED_P (decl) = 1;
06902 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
06903 TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
06904 TYPE_ALIGN (type) = 1;
06905 TYPE_USER_ALIGN (type) = 0;
06906 TYPE_MODE (type) = TYPE_MODE (void_type_node);
06907 }
06908
06909
06910
06911
06912 typedef struct predefined_identifier
06913 {
06914
06915 const char *const name;
06916
06917 tree *const node;
06918
06919 const int ctor_or_dtor_p;
06920 } predefined_identifier;
06921
06922
06923
06924 static void
06925 initialize_predefined_identifiers ()
06926 {
06927 const predefined_identifier *pid;
06928
06929
06930 static const predefined_identifier predefined_identifiers[] = {
06931 { "C++", &lang_name_cplusplus, 0 },
06932 { "C", &lang_name_c, 0 },
06933 { "Java", &lang_name_java, 0 },
06934 { CTOR_NAME, &ctor_identifier, 1 },
06935 { "__base_ctor", &base_ctor_identifier, 1 },
06936 { "__comp_ctor", &complete_ctor_identifier, 1 },
06937 { DTOR_NAME, &dtor_identifier, 1 },
06938 { "__comp_dtor", &complete_dtor_identifier, 1 },
06939 { "__base_dtor", &base_dtor_identifier, 1 },
06940 { "__deleting_dtor", &deleting_dtor_identifier, 1 },
06941 { IN_CHARGE_NAME, &in_charge_identifier, 0 },
06942 { "nelts", &nelts_identifier, 0 },
06943 { THIS_NAME, &this_identifier, 0 },
06944 { VTABLE_DELTA_NAME, &delta_identifier, 0 },
06945 { VTABLE_PFN_NAME, &pfn_identifier, 0 },
06946 { "_vptr", &vptr_identifier, 0 },
06947 { "__vtt_parm", &vtt_parm_identifier, 0 },
06948 { "std", &std_identifier, 0 },
06949 { NULL, NULL, 0 }
06950 };
06951
06952 for (pid = predefined_identifiers; pid->name; ++pid)
06953 {
06954 *pid->node = get_identifier (pid->name);
06955 if (pid->ctor_or_dtor_p)
06956 IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
06957 }
06958 }
06959
06960
06961
06962
06963
06964
06965 void
06966 cxx_init_decl_processing ()
06967 {
06968 tree void_ftype;
06969 tree void_ftype_ptr;
06970
06971
06972 initialize_predefined_identifiers ();
06973
06974
06975 lang_missing_noreturn_ok_p = &cp_missing_noreturn_ok_p;
06976
06977
06978 push_to_top_level ();
06979
06980
06981 my_friendly_assert (global_namespace == NULL_TREE, 375);
06982 push_namespace (get_identifier ("::"));
06983 global_namespace = current_namespace;
06984 current_lang_name = NULL_TREE;
06985
06986
06987 if (!flag_permissive)
06988 flag_pedantic_errors = 1;
06989 if (!flag_no_inline)
06990 {
06991 flag_inline_trees = 1;
06992 flag_no_inline = 1;
06993 }
06994 if (flag_inline_functions)
06995 {
06996 flag_inline_trees = 2;
06997 flag_inline_functions = 0;
06998 }
06999
07000
07001
07002 if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
07003 && force_align_functions_log < 1)
07004 force_align_functions_log = 1;
07005
07006
07007 current_lang_name = lang_name_c;
07008
07009 current_function_decl = NULL_TREE;
07010 #ifdef KEY
07011 copy_to_current_binding_level (NULL_BINDING_LEVEL);
07012 #else
07013 current_binding_level = NULL_BINDING_LEVEL;
07014 #endif // KEY
07015 free_binding_level = NULL_BINDING_LEVEL;
07016
07017 build_common_tree_nodes (flag_signed_char);
07018
07019 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
07020 TREE_TYPE (error_mark_list) = error_mark_node;
07021
07022
07023 pushlevel (0);
07024 current_binding_level->type_decls = binding_table_new (GLOBAL_SCOPE_HT_SIZE);
07025
07026 NAMESPACE_LEVEL (global_namespace) = current_binding_level;
07027 declare_namespace_level ();
07028
07029 VARRAY_TREE_INIT (current_binding_level->static_decls,
07030 200,
07031 "Static declarations");
07032
07033
07034 push_namespace (std_identifier);
07035 std_node = current_namespace;
07036 pop_namespace ();
07037
07038 c_common_nodes_and_builtins ();
07039
07040 java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
07041 java_short_type_node = record_builtin_java_type ("__java_short", 16);
07042 java_int_type_node = record_builtin_java_type ("__java_int", 32);
07043 java_long_type_node = record_builtin_java_type ("__java_long", 64);
07044 java_float_type_node = record_builtin_java_type ("__java_float", -32);
07045 java_double_type_node = record_builtin_java_type ("__java_double", -64);
07046 java_char_type_node = record_builtin_java_type ("__java_char", -16);
07047 java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
07048
07049 integer_two_node = build_int_2 (2, 0);
07050 TREE_TYPE (integer_two_node) = integer_type_node;
07051 integer_three_node = build_int_2 (3, 0);
07052 TREE_TYPE (integer_three_node) = integer_type_node;
07053
07054 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
07055 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
07056 TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0);
07057 TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node;
07058 TYPE_PRECISION (boolean_type_node) = 1;
07059 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
07060 boolean_false_node = build_int_2 (0, 0);
07061 TREE_TYPE (boolean_false_node) = boolean_type_node;
07062 boolean_true_node = build_int_2 (1, 0);
07063 TREE_TYPE (boolean_true_node) = boolean_type_node;
07064
07065 empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
07066
07067 #if 0
07068 record_builtin_type (RID_MAX, NULL, string_type_node);
07069 #endif
07070
07071 delta_type_node = ptrdiff_type_node;
07072 vtable_index_type = ptrdiff_type_node;
07073
07074 vtt_parm_type = build_pointer_type (const_ptr_type_node);
07075 void_ftype = build_function_type (void_type_node, void_list_node);
07076 void_ftype_ptr = build_function_type (void_type_node,
07077 tree_cons (NULL_TREE,
07078 ptr_type_node,
07079 void_list_node));
07080 void_ftype_ptr
07081 = build_exception_variant (void_ftype_ptr, empty_except_spec);
07082
07083
07084
07085 unknown_type_node = make_node (UNKNOWN_TYPE);
07086 record_unknown_type (unknown_type_node, "unknown type");
07087
07088
07089 TREE_TYPE (unknown_type_node) = unknown_type_node;
07090
07091
07092
07093 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
07094 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
07095
07096 {
07097
07098
07099 tree vfunc_type = make_node (FUNCTION_TYPE);
07100 TREE_TYPE (vfunc_type) = integer_type_node;
07101 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
07102 layout_type (vfunc_type);
07103
07104 vtable_entry_type = build_pointer_type (vfunc_type);
07105 }
07106 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
07107
07108 vtbl_type_node
07109 = build_cplus_array_type (vtable_entry_type, NULL_TREE);
07110 layout_type (vtbl_type_node);
07111 vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
07112 record_builtin_type (RID_MAX, NULL, vtbl_type_node);
07113 vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
07114 layout_type (vtbl_ptr_type_node);
07115 record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
07116
07117 push_namespace (get_identifier ("__cxxabiv1"));
07118 abi_node = current_namespace;
07119 pop_namespace ();
07120
07121 global_type_node = make_node (LANG_TYPE);
07122 record_unknown_type (global_type_node, "global type");
07123
07124
07125 current_lang_name = lang_name_cplusplus;
07126
07127 {
07128 tree bad_alloc_type_node, newtype, deltype;
07129 tree ptr_ftype_sizetype;
07130
07131 push_namespace (std_identifier);
07132 bad_alloc_type_node
07133 = xref_tag (class_type, get_identifier ("bad_alloc"),
07134 NULL_TREE, 1);
07135 pop_namespace ();
07136 ptr_ftype_sizetype
07137 = build_function_type (ptr_type_node,
07138 tree_cons (NULL_TREE,
07139 size_type_node,
07140 void_list_node));
07141 newtype = build_exception_variant
07142 (ptr_ftype_sizetype, add_exception_specifier
07143 (NULL_TREE, bad_alloc_type_node, -1));
07144 deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
07145 push_cp_library_fn (NEW_EXPR, newtype);
07146 push_cp_library_fn (VEC_NEW_EXPR, newtype);
07147 global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype);
07148 push_cp_library_fn (VEC_DELETE_EXPR, deltype);
07149 }
07150
07151 abort_fndecl
07152 = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype);
07153
07154
07155 init_class_processing ();
07156 init_search_processing ();
07157 init_rtti_processing ();
07158
07159 if (flag_exceptions)
07160 init_exception_processing ();
07161
07162 if (! supports_one_only ())
07163 flag_weak = 0;
07164
07165 make_fname_decl = cp_make_fname_decl;
07166 start_fname_decls ();
07167
07168
07169 using_eh_for_cleanups ();
07170
07171
07172
07173 if (flag_writable_strings)
07174 flag_const_strings = 0;
07175 }
07176
07177
07178
07179
07180
07181 tree
07182 cp_fname_init (name)
07183 const char *name;
07184 {
07185 tree domain = NULL_TREE;
07186 tree type;
07187 tree init = NULL_TREE;
07188 size_t length = 0;
07189
07190 if (name)
07191 {
07192 length = strlen (name);
07193 domain = build_index_type (size_int (length));
07194 init = build_string (length + 1, name);
07195 }
07196
07197 type = build_qualified_type (char_type_node, TYPE_QUAL_CONST);
07198 type = build_cplus_array_type (type, domain);
07199
07200 if (init)
07201 TREE_TYPE (init) = type;
07202 else
07203
07204
07205 init = build (ERROR_MARK, type);
07206
07207 return init;
07208 }
07209
07210
07211
07212
07213
07214
07215
07216 static tree
07217 cp_make_fname_decl (id, type_dep)
07218 tree id;
07219 int type_dep;
07220 {
07221 const char *const name = (type_dep && processing_template_decl
07222 ? NULL : fname_as_string (type_dep));
07223 tree init = cp_fname_init (name);
07224 tree decl = build_decl (VAR_DECL, id, TREE_TYPE (init));
07225
07226
07227 DECL_CONTEXT (decl) = current_function_decl;
07228 DECL_PRETTY_FUNCTION_P (decl) = type_dep;
07229
07230 TREE_STATIC (decl) = 1;
07231 TREE_READONLY (decl) = 1;
07232 DECL_ARTIFICIAL (decl) = 1;
07233 DECL_INITIAL (decl) = init;
07234
07235 TREE_USED (decl) = 1;
07236
07237 cp_finish_decl (decl, init, NULL_TREE, LOOKUP_ONLYCONVERTING);
07238
07239 if (!current_function_decl)
07240 rest_of_decl_compilation (decl, 0, 1, 0);
07241
07242 return decl;
07243 }
07244
07245
07246
07247
07248
07249
07250
07251
07252
07253
07254
07255
07256
07257 static tree
07258 builtin_function_1 (name, type, context, code, class, libname, attrs)
07259 const char *name;
07260 tree type;
07261 tree context;
07262 int code;
07263 enum built_in_class class;
07264 const char *libname;
07265 tree attrs;
07266 {
07267 tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type);
07268 DECL_BUILT_IN_CLASS (decl) = class;
07269 DECL_FUNCTION_CODE (decl) = code;
07270 DECL_CONTEXT (decl) = context;
07271
07272 pushdecl (decl);
07273
07274
07275
07276
07277 if (libname)
07278 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
07279 make_decl_rtl (decl, NULL);
07280
07281
07282
07283 if (name[0] != '_' || name[1] != '_')
07284 DECL_ANTICIPATED (decl) = 1;
07285
07286
07287 if (attrs)
07288 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
07289 else
07290 decl_attributes (&decl, NULL_TREE, 0);
07291
07292 return decl;
07293 }
07294
07295
07296
07297
07298
07299
07300
07301
07302
07303
07304
07305
07306
07307
07308
07309
07310
07311 tree
07312 builtin_function (name, type, code, class, libname, attrs)
07313 const char *name;
07314 tree type;
07315 int code;
07316 enum built_in_class class;
07317 const char *libname;
07318 tree attrs;
07319 {
07320
07321
07322 if (name[0] != '_')
07323 {
07324 push_namespace (std_identifier);
07325 builtin_function_1 (name, type, std_node, code, class, libname, attrs);
07326 pop_namespace ();
07327 }
07328
07329 return builtin_function_1 (name, type, NULL_TREE, code,
07330 class, libname, attrs);
07331 }
07332
07333
07334
07335
07336 static tree
07337 build_library_fn_1 (name, operator_code, type)
07338 tree name;
07339 enum tree_code operator_code;
07340 tree type;
07341 {
07342 tree fn = build_lang_decl (FUNCTION_DECL, name, type);
07343 DECL_EXTERNAL (fn) = 1;
07344 TREE_PUBLIC (fn) = 1;
07345 DECL_ARTIFICIAL (fn) = 1;
07346 TREE_NOTHROW (fn) = 1;
07347 SET_OVERLOADED_OPERATOR_CODE (fn, operator_code);
07348 SET_DECL_LANGUAGE (fn, lang_c);
07349 return fn;
07350 }
07351
07352
07353
07354
07355
07356 tree
07357 build_library_fn (name, type)
07358 tree name;
07359 tree type;
07360 {
07361 return build_library_fn_1 (name, ERROR_MARK, type);
07362 }
07363
07364
07365
07366 static tree
07367 build_cp_library_fn (name, operator_code, type)
07368 tree name;
07369 enum tree_code operator_code;
07370 tree type;
07371 {
07372 tree fn = build_library_fn_1 (name, operator_code, type);
07373 TREE_NOTHROW (fn) = TYPE_NOTHROW_P (type);
07374 DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
07375 SET_DECL_LANGUAGE (fn, lang_cplusplus);
07376 set_mangled_name_for_decl (fn);
07377 return fn;
07378 }
07379
07380
07381
07382
07383 tree
07384 build_library_fn_ptr (name, type)
07385 const char *name;
07386 tree type;
07387 {
07388 return build_library_fn (get_identifier (name), type);
07389 }
07390
07391
07392
07393
07394 tree
07395 build_cp_library_fn_ptr (name, type)
07396 const char *name;
07397 tree type;
07398 {
07399 return build_cp_library_fn (get_identifier (name), ERROR_MARK, type);
07400 }
07401
07402
07403
07404
07405 tree
07406 push_library_fn (name, type)
07407 tree name, type;
07408 {
07409 tree fn = build_library_fn (name, type);
07410 pushdecl_top_level (fn);
07411 return fn;
07412 }
07413
07414
07415
07416
07417 static tree
07418 push_cp_library_fn (operator_code, type)
07419 enum tree_code operator_code;
07420 tree type;
07421 {
07422 tree fn = build_cp_library_fn (ansi_opname (operator_code),
07423 operator_code,
07424 type);
07425 pushdecl (fn);
07426 return fn;
07427 }
07428
07429
07430
07431
07432 tree
07433 push_void_library_fn (name, parmtypes)
07434 tree name, parmtypes;
07435 {
07436 tree type = build_function_type (void_type_node, parmtypes);
07437 return push_library_fn (name, type);
07438 }
07439
07440
07441
07442
07443 tree
07444 push_throw_library_fn (name, type)
07445 tree name, type;
07446 {
07447 tree fn = push_library_fn (name, type);
07448 TREE_THIS_VOLATILE (fn) = 1;
07449 TREE_NOTHROW (fn) = 0;
07450 return fn;
07451 }
07452
07453
07454
07455
07456 void
07457 cxx_insert_default_attributes (decl)
07458 tree decl;
07459 {
07460 if (!DECL_EXTERN_C_FUNCTION_P (decl))
07461 return;
07462 if (!TREE_PUBLIC (decl))
07463 return;
07464 c_common_insert_default_attributes (decl);
07465 }
07466
07467
07468
07469
07470
07471
07472
07473
07474
07475
07476
07477 void
07478 fixup_anonymous_aggr (t)
07479 tree t;
07480 {
07481 tree *q;
07482
07483
07484 TYPE_HAS_CONSTRUCTOR (t) = 0;
07485 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
07486 TYPE_HAS_INIT_REF (t) = 0;
07487 TYPE_HAS_CONST_INIT_REF (t) = 0;
07488 TYPE_HAS_ASSIGN_REF (t) = 0;
07489 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
07490
07491
07492
07493 q = &TYPE_METHODS (t);
07494 while (*q)
07495 {
07496 if (DECL_ARTIFICIAL (*q))
07497 *q = TREE_CHAIN (*q);
07498 else
07499 q = &TREE_CHAIN (*q);
07500 }
07501
07502
07503 if (TYPE_METHODS (t))
07504 cp_error_at ("an anonymous union cannot have function members", t);
07505
07506
07507
07508
07509
07510 if (TREE_CODE (t) != UNION_TYPE)
07511 {
07512 tree field, type;
07513
07514 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
07515 if (TREE_CODE (field) == FIELD_DECL)
07516 {
07517 type = TREE_TYPE (field);
07518 if (CLASS_TYPE_P (type))
07519 {
07520 if (TYPE_NEEDS_CONSTRUCTING (type))
07521 cp_error_at ("member %#D' with constructor not allowed in anonymous aggregate",
07522 field);
07523 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
07524 cp_error_at ("member %#D' with destructor not allowed in anonymous aggregate",
07525 field);
07526 if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
07527 cp_error_at ("member %#D' with copy assignment operator not allowed in anonymous aggregate",
07528 field);
07529 }
07530 }
07531 }
07532 }
07533
07534
07535
07536
07537
07538
07539 tree
07540 check_tag_decl (declspecs)
07541 tree declspecs;
07542 {
07543 int found_type = 0;
07544 int saw_friend = 0;
07545 int saw_typedef = 0;
07546 tree ob_modifier = NULL_TREE;
07547 register tree link;
07548 register tree t = NULL_TREE;
07549
07550 for (link = declspecs; link; link = TREE_CHAIN (link))
07551 {
07552 register tree value = TREE_VALUE (link);
07553
07554 if (TYPE_P (value)
07555 || TREE_CODE (value) == TYPE_DECL
07556 || (TREE_CODE (value) == IDENTIFIER_NODE
07557 && IDENTIFIER_GLOBAL_VALUE (value)
07558 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (value)) == TYPE_DECL))
07559 {
07560 ++found_type;
07561
07562 if (found_type == 2 && TREE_CODE (value) == IDENTIFIER_NODE)
07563 {
07564 if (! in_system_header)
07565 pedwarn ("redeclaration of C++ built-in type `%T'", value);
07566 return NULL_TREE;
07567 }
07568
07569 if (TYPE_P (value)
07570 && ((TREE_CODE (value) != TYPENAME_TYPE && IS_AGGR_TYPE (value))
07571 || TREE_CODE (value) == ENUMERAL_TYPE))
07572 {
07573 my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261);
07574 t = value;
07575 }
07576 }
07577 else if (value == ridpointers[(int) RID_TYPEDEF])
07578 saw_typedef = 1;
07579 else if (value == ridpointers[(int) RID_FRIEND])
07580 {
07581 if (current_class_type == NULL_TREE
07582 || current_scope () != current_class_type)
07583 ob_modifier = value;
07584 else
07585 saw_friend = 1;
07586 }
07587 else if (value == ridpointers[(int) RID_STATIC]
07588 || value == ridpointers[(int) RID_EXTERN]
07589 || value == ridpointers[(int) RID_AUTO]
07590 || value == ridpointers[(int) RID_REGISTER]
07591 || value == ridpointers[(int) RID_INLINE]
07592 || value == ridpointers[(int) RID_VIRTUAL]
07593 || value == ridpointers[(int) RID_CONST]
07594 || value == ridpointers[(int) RID_VOLATILE]
07595 || value == ridpointers[(int) RID_EXPLICIT]
07596 || value == ridpointers[(int) RID_THREAD])
07597 ob_modifier = value;
07598 }
07599
07600 if (found_type > 1)
07601 error ("multiple types in one declaration");
07602
07603 if (t == NULL_TREE && ! saw_friend)
07604 pedwarn ("declaration does not declare anything");
07605
07606
07607 else if (t && IS_AGGR_TYPE_CODE (TREE_CODE (t))
07608 && TYPE_ANONYMOUS_P (t))
07609 {
07610
07611
07612
07613
07614
07615
07616
07617
07618
07619
07620
07621
07622
07623
07624
07625
07626 if (saw_typedef)
07627 {
07628 error ("missing type-name in typedef-declaration");
07629 return NULL_TREE;
07630 }
07631 ;
07632 SET_ANON_AGGR_TYPE_P (t);
07633
07634 if (TREE_CODE (t) != UNION_TYPE && pedantic && ! in_system_header)
07635 pedwarn ("ISO C++ prohibits anonymous structs");
07636 }
07637
07638 else if (ob_modifier)
07639 {
07640 if (ob_modifier == ridpointers[(int) RID_INLINE]
07641 || ob_modifier == ridpointers[(int) RID_VIRTUAL])
07642 error ("`%D' can only be specified for functions", ob_modifier);
07643 else if (ob_modifier == ridpointers[(int) RID_FRIEND])
07644 error ("`%D' can only be specified inside a class", ob_modifier);
07645 else if (ob_modifier == ridpointers[(int) RID_EXPLICIT])
07646 error ("`%D' can only be specified for constructors",
07647 ob_modifier);
07648 else
07649 error ("`%D' can only be specified for objects and functions",
07650 ob_modifier);
07651 }
07652
07653 return t;
07654 }
07655
07656
07657
07658
07659
07660
07661
07662
07663
07664
07665
07666
07667 void
07668 shadow_tag (declspecs)
07669 tree declspecs;
07670 {
07671 tree t = check_tag_decl (declspecs);
07672
07673 if (t)
07674 maybe_process_partial_specialization (t);
07675
07676
07677
07678
07679
07680
07681 if (t && ANON_AGGR_TYPE_P (t))
07682 {
07683 fixup_anonymous_aggr (t);
07684
07685 if (TYPE_FIELDS (t))
07686 {
07687 tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
07688 NULL);
07689 finish_anon_union (decl);
07690 }
07691 }
07692 }
07693
07694
07695
07696 tree
07697 groktypename (typename)
07698 tree typename;
07699 {
07700 tree specs, attrs;
07701 tree type;
07702 if (TREE_CODE (typename) != TREE_LIST)
07703 return typename;
07704 split_specs_attrs (TREE_PURPOSE (typename), &specs, &attrs);
07705 type = grokdeclarator (TREE_VALUE (typename), specs,
07706 TYPENAME, 0, &attrs);
07707 if (attrs)
07708 cplus_decl_attributes (&type, attrs, 0);
07709 return type;
07710 }
07711
07712
07713
07714
07715
07716
07717
07718
07719
07720
07721
07722
07723
07724
07725
07726
07727 tree
07728 start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
07729 tree declarator, declspecs;
07730 int initialized;
07731 tree attributes, prefix_attributes;
07732 {
07733 tree decl;
07734 register tree type, tem;
07735 tree context;
07736
07737 #if 0
07738
07739 int init_written = initialized;
07740 #endif
07741
07742
07743 if (have_extern_spec)
07744 {
07745 declspecs = tree_cons (NULL_TREE, get_identifier ("extern"),
07746 declspecs);
07747 have_extern_spec = false;
07748 }
07749
07750
07751
07752 if (lookup_attribute ("deprecated", attributes))
07753 deprecated_state = DEPRECATED_SUPPRESS;
07754
07755 attributes = chainon (attributes, prefix_attributes);
07756
07757 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
07758 &attributes);
07759
07760 deprecated_state = DEPRECATED_NORMAL;
07761
07762 if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE)
07763 return NULL_TREE;
07764
07765 type = TREE_TYPE (decl);
07766
07767 if (type == error_mark_node)
07768 return NULL_TREE;
07769
07770 context = DECL_CONTEXT (decl);
07771
07772 if (initialized && context && TREE_CODE (context) == NAMESPACE_DECL
07773 && context != current_namespace && TREE_CODE (decl) == VAR_DECL)
07774 {
07775
07776
07777 push_decl_namespace (context);
07778 }
07779
07780
07781 if (context && TREE_CODE (context) == NAMESPACE_DECL)
07782 context = NULL_TREE;
07783
07784 if (initialized)
07785
07786
07787
07788 switch (TREE_CODE (decl))
07789 {
07790 case TYPE_DECL:
07791 error ("typedef `%D' is initialized (use __typeof__ instead)", decl);
07792 initialized = 0;
07793 break;
07794
07795 case FUNCTION_DECL:
07796 error ("function `%#D' is initialized like a variable", decl);
07797 initialized = 0;
07798 break;
07799
07800 default:
07801 break;
07802 }
07803
07804 if (initialized)
07805 {
07806 if (! toplevel_bindings_p ()
07807 && DECL_EXTERNAL (decl))
07808 warning ("declaration of `%#D' has `extern' and is initialized",
07809 decl);
07810 DECL_EXTERNAL (decl) = 0;
07811 if (toplevel_bindings_p ())
07812 TREE_STATIC (decl) = 1;
07813
07814
07815
07816
07817 DECL_INITIAL (decl) = error_mark_node;
07818 }
07819
07820
07821 cplus_decl_attributes (&decl, attributes, 0);
07822
07823
07824 if (global_scope_p (current_binding_level))
07825 maybe_apply_pragma_weak (decl);
07826
07827 if (TREE_CODE (decl) == FUNCTION_DECL
07828 && DECL_DECLARED_INLINE_P (decl)
07829 && DECL_UNINLINABLE (decl)
07830 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
07831 warning_with_decl (decl,
07832 "inline function `%s' given attribute noinline");
07833
07834 if (context && COMPLETE_TYPE_P (complete_type (context)))
07835 {
07836 push_nested_class (context, 2);
07837
07838 if (TREE_CODE (decl) == VAR_DECL)
07839 {
07840 tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
07841 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
07842 error ("`%#D' is not a static member of `%#T'", decl, context);
07843 else
07844 {
07845 if (DECL_CONTEXT (field) != context)
07846 {
07847 pedwarn ("ISO C++ does not permit `%T::%D' to be defined as `%T::%D'",
07848 DECL_CONTEXT (field), DECL_NAME (decl),
07849 context, DECL_NAME (decl));
07850 DECL_CONTEXT (decl) = DECL_CONTEXT (field);
07851 }
07852
07853
07854
07855
07856
07857 if (DECL_INITIAL (decl) && DECL_INITIAL (field))
07858 error ("duplicate initialization of %D", decl);
07859 if (duplicate_decls (decl, field))
07860 decl = field;
07861 }
07862 }
07863 else
07864 {
07865 tree field = check_classfn (context, decl);
07866 if (field && duplicate_decls (decl, field))
07867 decl = field;
07868 }
07869
07870
07871 DECL_IN_AGGR_P (decl) = 0;
07872 if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
07873 || CLASSTYPE_TEMPLATE_INSTANTIATION (context))
07874 {
07875 SET_DECL_TEMPLATE_SPECIALIZATION (decl);
07876
07877
07878
07879
07880
07881
07882 if (DECL_INITIAL (decl) == NULL_TREE && processing_specialization)
07883 DECL_EXTERNAL (decl) = 1;
07884 }
07885
07886 if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl))
07887 pedwarn ("declaration of `%#D' outside of class is not definition",
07888 decl);
07889 }
07890
07891
07892 tem = maybe_push_decl (decl);
07893
07894 if (processing_template_decl)
07895 tem = push_template_decl (tem);
07896
07897 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
07898
07899
07900
07901
07902
07903 DECL_COMMON (tem) = ((TREE_CODE (tem) != VAR_DECL
07904 || !DECL_THREAD_LOCAL (tem))
07905 && (flag_conserve_space || ! TREE_PUBLIC (tem)));
07906 #endif
07907
07908 if (! processing_template_decl)
07909 start_decl_1 (tem);
07910
07911 return tem;
07912 }
07913
07914 void
07915 start_decl_1 (decl)
07916 tree decl;
07917 {
07918 tree type = TREE_TYPE (decl);
07919 int initialized = (DECL_INITIAL (decl) != NULL_TREE);
07920
07921 if (type == error_mark_node)
07922 return;
07923
07924 maybe_push_cleanup_level (type);
07925
07926 if (initialized)
07927
07928
07929
07930 {
07931
07932
07933 if (COMPLETE_TYPE_P (complete_type (type)))
07934 ;
07935 else if (TREE_CODE (type) != ARRAY_TYPE)
07936 {
07937 error ("variable `%#D' has initializer but incomplete type",
07938 decl);
07939 initialized = 0;
07940 type = TREE_TYPE (decl) = error_mark_node;
07941 }
07942 else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
07943 {
07944 if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
07945 error ("elements of array `%#D' have incomplete type", decl);
07946
07947 initialized = 0;
07948 }
07949 }
07950
07951 if (!initialized
07952 && TREE_CODE (decl) != TYPE_DECL
07953 && TREE_CODE (decl) != TEMPLATE_DECL
07954 && type != error_mark_node
07955 && IS_AGGR_TYPE (type)
07956 && ! DECL_EXTERNAL (decl))
07957 {
07958 if ((! processing_template_decl || ! uses_template_parms (type))
07959 && !COMPLETE_TYPE_P (complete_type (type)))
07960 {
07961 error ("aggregate `%#D' has incomplete type and cannot be defined",
07962 decl);
07963
07964
07965 type = TREE_TYPE (decl) = error_mark_node;
07966 }
07967 else
07968 {
07969
07970
07971
07972
07973
07974
07975 initialized = TYPE_NEEDS_CONSTRUCTING (type);
07976 }
07977 }
07978
07979 if (! initialized)
07980 DECL_INITIAL (decl) = NULL_TREE;
07981 }
07982
07983
07984
07985
07986
07987
07988
07989
07990
07991
07992
07993 static tree
07994 grok_reference_init (tree decl, tree type, tree init, tree *cleanup)
07995 {
07996 tree tmp;
07997
07998 if (init == NULL_TREE)
07999 {
08000 if ((DECL_LANG_SPECIFIC (decl) == 0
08001 || DECL_IN_AGGR_P (decl) == 0)
08002 && ! DECL_THIS_EXTERN (decl))
08003 error ("`%D' declared as reference but not initialized", decl);
08004 return NULL_TREE;
08005 }
08006
08007 if (init == error_mark_node)
08008 return NULL_TREE;
08009
08010 if (TREE_CODE (init) == CONSTRUCTOR)
08011 {
08012 error ("ISO C++ forbids use of initializer list to initialize reference `%D'", decl);
08013 return NULL_TREE;
08014 }
08015
08016 if (TREE_CODE (init) == TREE_LIST)
08017 init = build_compound_expr (init);
08018
08019 if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
08020 init = convert_from_reference (init);
08021
08022 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
08023 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
08024 {
08025
08026 init = default_conversion (init);
08027 }
08028
08029
08030
08031
08032
08033
08034
08035
08036 tmp = initialize_reference (type, init, decl, cleanup);
08037
08038 if (tmp == error_mark_node)
08039 return NULL_TREE;
08040 else if (tmp == NULL_TREE)
08041 {
08042 error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
08043 return NULL_TREE;
08044 }
08045
08046 if (TREE_STATIC (decl) && !TREE_CONSTANT (tmp))
08047 return tmp;
08048
08049 DECL_INITIAL (decl) = tmp;
08050
08051 return NULL_TREE;
08052 }
08053
08054
08055
08056
08057
08058 static void
08059 maybe_deduce_size_from_array_init (decl, init)
08060 tree decl;
08061 tree init;
08062 {
08063 tree type = TREE_TYPE (decl);
08064
08065 if (TREE_CODE (type) == ARRAY_TYPE
08066 && TYPE_DOMAIN (type) == NULL_TREE
08067 && TREE_CODE (decl) != TYPE_DECL)
08068 {
08069
08070
08071 int do_default = !DECL_EXTERNAL (decl);
08072 tree initializer = init ? init : DECL_INITIAL (decl);
08073 int failure = complete_array_type (type, initializer, do_default);
08074
08075 if (failure == 1)
08076 error ("initializer fails to determine size of `%D'", decl);
08077
08078 if (failure == 2)
08079 {
08080 if (do_default)
08081 error ("array size missing in `%D'", decl);
08082
08083
08084
08085
08086 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
08087 DECL_EXTERNAL (decl) = 1;
08088 }
08089
08090 if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
08091 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
08092 integer_zero_node))
08093 error ("zero-size array `%D'", decl);
08094
08095 layout_decl (decl, 0);
08096 }
08097 }
08098
08099
08100
08101
08102 static void
08103 layout_var_decl (decl)
08104 tree decl;
08105 {
08106 tree type = TREE_TYPE (decl);
08107 #if 0
08108 tree ttype = target_type (type);
08109 #endif
08110
08111
08112
08113
08114
08115
08116 if (!DECL_EXTERNAL (decl))
08117 complete_type (type);
08118 if (!DECL_SIZE (decl)
08119 && TREE_TYPE (decl) != error_mark_node
08120 && (COMPLETE_TYPE_P (type)
08121 || (TREE_CODE (type) == ARRAY_TYPE
08122 && !TYPE_DOMAIN (type)
08123 && COMPLETE_TYPE_P (TREE_TYPE (type)))))
08124 layout_decl (decl, 0);
08125
08126 if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
08127 {
08128
08129
08130
08131 error ("storage size of `%D' isn't known", decl);
08132 TREE_TYPE (decl) = error_mark_node;
08133 }
08134 #if 0
08135
08136
08137
08138 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
08139
08140 note_debug_info_needed (ttype);
08141
08142 if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
08143 note_debug_info_needed (DECL_CONTEXT (decl));
08144 #endif
08145
08146 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
08147 && DECL_SIZE (decl) != NULL_TREE
08148 && ! TREE_CONSTANT (DECL_SIZE (decl)))
08149 {
08150 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
08151 constant_expression_warning (DECL_SIZE (decl));
08152 else
08153 error ("storage size of `%D' isn't constant", decl);
08154 }
08155
08156 if (TREE_STATIC (decl)
08157 && !DECL_ARTIFICIAL (decl)
08158 && current_function_decl
08159 && DECL_CONTEXT (decl) == current_function_decl)
08160 push_local_name (decl);
08161 }
08162
08163
08164
08165
08166
08167 static void
08168 maybe_commonize_var (decl)
08169 tree decl;
08170 {
08171
08172
08173 if (TREE_STATIC (decl)
08174
08175 && ! DECL_ARTIFICIAL (decl)
08176 && DECL_FUNCTION_SCOPE_P (decl)
08177
08178
08179
08180 && (DECL_COMDAT (DECL_CONTEXT (decl))
08181 || ((DECL_DECLARED_INLINE_P (DECL_CONTEXT (decl))
08182 || DECL_TEMPLATE_INSTANTIATION (DECL_CONTEXT (decl)))
08183 && TREE_PUBLIC (DECL_CONTEXT (decl)))))
08184 {
08185 if (flag_weak)
08186 {
08187
08188
08189
08190 comdat_linkage (decl);
08191 }
08192 else
08193 {
08194 if (DECL_INITIAL (decl) == NULL_TREE
08195 || DECL_INITIAL (decl) == error_mark_node)
08196 {
08197
08198
08199 TREE_PUBLIC (decl) = 1;
08200 DECL_COMMON (decl) = 1;
08201 }
08202 else
08203 {
08204
08205
08206
08207 TREE_PUBLIC (decl) = 0;
08208 DECL_COMMON (decl) = 0;
08209 cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl);
08210 cp_warning_at (" you can work around this by removing the initializer", decl);
08211 }
08212 }
08213 }
08214 else if (DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
08215
08216
08217 comdat_linkage (decl);
08218 }
08219
08220
08221
08222 static void
08223 check_for_uninitialized_const_var (decl)
08224 tree decl;
08225 {
08226 tree type = TREE_TYPE (decl);
08227
08228
08229
08230
08231 if (TREE_CODE (decl) == VAR_DECL
08232 && TREE_CODE (type) != REFERENCE_TYPE
08233 && CP_TYPE_CONST_P (type)
08234 && !TYPE_NEEDS_CONSTRUCTING (type)
08235 && !DECL_INITIAL (decl))
08236 error ("uninitialized const `%D'", decl);
08237 }
08238
08239
08240
08241
08242
08243
08244 static tree
08245 next_initializable_field (tree field)
08246 {
08247 while (field
08248 && (TREE_CODE (field) != FIELD_DECL
08249 || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))
08250 || DECL_ARTIFICIAL (field)))
08251 field = TREE_CHAIN (field);
08252
08253 return field;
08254 }
08255
08256
08257
08258
08259
08260
08261
08262
08263
08264
08265
08266
08267
08268
08269
08270
08271 static tree
08272 reshape_init (tree type, tree *initp)
08273 {
08274 tree inits;
08275 tree old_init;
08276 tree old_init_value;
08277 tree new_init;
08278 bool brace_enclosed_p;
08279
08280 old_init = *initp;
08281 old_init_value = (TREE_CODE (*initp) == TREE_LIST
08282 ? TREE_VALUE (*initp) : old_init);
08283
08284
08285 if (!old_init_value)
08286 {
08287 my_friendly_assert (TREE_CODE (old_init) == TREE_LIST, 20021202);
08288 TREE_VALUE (old_init) = error_mark_node;
08289 *initp = TREE_CHAIN (old_init);
08290 return old_init;
08291 }
08292
08293
08294
08295
08296 if (TREE_CODE (old_init_value) == CONSTRUCTOR
08297 && TREE_HAS_CONSTRUCTOR (old_init_value))
08298 {
08299 *initp = TREE_CHAIN (old_init);
08300 TREE_CHAIN (old_init) = NULL_TREE;
08301 inits = CONSTRUCTOR_ELTS (old_init_value);
08302 initp = &inits;
08303 brace_enclosed_p = true;
08304 }
08305 else
08306 {
08307 inits = NULL_TREE;
08308 brace_enclosed_p = false;
08309 }
08310
08311
08312
08313 if (!CP_AGGREGATE_TYPE_P (type))
08314 {
08315 *initp = TREE_CHAIN (old_init);
08316 TREE_CHAIN (old_init) = NULL_TREE;
08317
08318
08319 if (brace_enclosed_p)
08320 {
08321 error ("brace-enclosed initializer used to initialize `%T'",
08322 type);
08323 if (TREE_CODE (old_init) == TREE_LIST)
08324 TREE_VALUE (old_init) = error_mark_node;
08325 else
08326 old_init = error_mark_node;
08327 }
08328
08329 return old_init;
08330 }
08331
08332
08333
08334
08335
08336
08337
08338
08339
08340
08341 if (CLASS_TYPE_P (type)
08342 && !brace_enclosed_p
08343 && can_convert_arg (type, TREE_TYPE (old_init_value), old_init_value))
08344 {
08345 *initp = TREE_CHAIN (old_init);
08346 TREE_CHAIN (old_init) = NULL_TREE;
08347 return old_init;
08348 }
08349
08350 if (TREE_CODE (old_init_value) == STRING_CST
08351 && TREE_CODE (type) == ARRAY_TYPE
08352 && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
08353 {
08354
08355
08356
08357
08358
08359
08360 new_init = old_init;
08361
08362 *initp = TREE_CHAIN (old_init);
08363 TREE_CHAIN (old_init) = NULL_TREE;
08364 }
08365 else
08366 {
08367
08368 new_init = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
08369 TREE_HAS_CONSTRUCTOR (new_init) = 1;
08370
08371 if (CLASS_TYPE_P (type))
08372 {
08373 tree field;
08374
08375 field = next_initializable_field (TYPE_FIELDS (type));
08376
08377 if (!field)
08378 {
08379
08380
08381
08382
08383
08384 if (!brace_enclosed_p)
08385 error ("initializer for `%T' must be brace-enclosed",
08386 type);
08387 }
08388 else
08389 {
08390
08391
08392 while (*initp)
08393 {
08394 tree field_init;
08395
08396
08397 if (TREE_PURPOSE (*initp))
08398 {
08399 if (pedantic)
08400 pedwarn ("ISO C++ does not allow designated initializers");
08401 field = lookup_field_1 (type, TREE_PURPOSE (*initp),
08402 false);
08403 if (!field || TREE_CODE (field) != FIELD_DECL)
08404 error ("`%T' has no non-static data member named `%D'",
08405 type, TREE_PURPOSE (*initp));
08406 }
08407 if (!field)
08408 break;
08409
08410 field_init = reshape_init (TREE_TYPE (field), initp);
08411 TREE_CHAIN (field_init) = CONSTRUCTOR_ELTS (new_init);
08412 CONSTRUCTOR_ELTS (new_init) = field_init;
08413
08414
08415
08416
08417
08418 if (TREE_CODE (type) == UNION_TYPE)
08419 break;
08420 field = next_initializable_field (TREE_CHAIN (field));
08421 }
08422 }
08423 }
08424 else if (TREE_CODE (type) == ARRAY_TYPE)
08425 {
08426 tree index;
08427 tree max_index;
08428
08429
08430
08431 max_index = (TYPE_DOMAIN (type)
08432 ? array_type_nelts (type) : NULL_TREE);
08433
08434 for (index = size_zero_node;
08435 *initp && (!max_index || !tree_int_cst_lt (max_index, index));
08436 index = size_binop (PLUS_EXPR, index, size_one_node))
08437 {
08438 tree element_init;
08439
08440 element_init = reshape_init (TREE_TYPE (type), initp);
08441 TREE_CHAIN (element_init) = CONSTRUCTOR_ELTS (new_init);
08442 CONSTRUCTOR_ELTS (new_init) = element_init;
08443 if (TREE_PURPOSE (element_init))
08444 index = TREE_PURPOSE (element_init);
08445 }
08446 }
08447 else
08448 abort ();
08449
08450
08451
08452 CONSTRUCTOR_ELTS (new_init) = nreverse (CONSTRUCTOR_ELTS (new_init));
08453
08454 if (TREE_CODE (old_init) == TREE_LIST)
08455 new_init = build_tree_list (TREE_PURPOSE (old_init), new_init);
08456 }
08457
08458
08459
08460 if (brace_enclosed_p && *initp)
08461 error ("too many initializers for `%T'", type);
08462
08463 return new_init;
08464 }
08465
08466
08467
08468
08469
08470
08471
08472
08473 static tree
08474 check_initializer (tree decl, tree init, int flags, tree *cleanup)
08475 {
08476 tree type = TREE_TYPE (decl);
08477
08478
08479 if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
08480 init = NULL_TREE;
08481
08482
08483
08484
08485
08486 DECL_INITIAL (decl) = NULL_TREE;
08487
08488
08489
08490 TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
08491
08492 if (type == error_mark_node)
08493
08494 init = NULL_TREE;
08495 else if (init && COMPLETE_TYPE_P (type)
08496 && !TREE_CONSTANT (TYPE_SIZE (type)))
08497 {
08498 error ("variable-sized object `%D' may not be initialized", decl);
08499 init = NULL_TREE;
08500 }
08501 else if (TREE_CODE (type) == ARRAY_TYPE
08502 && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
08503 {
08504 error ("elements of array `%#D' have incomplete type", decl);
08505 init = NULL_TREE;
08506 }
08507 else if (TREE_CODE (type) != ARRAY_TYPE && !COMPLETE_TYPE_P (type))
08508 {
08509 error ("`%D' has incomplete type", decl);
08510 TREE_TYPE (decl) = error_mark_node;
08511 init = NULL_TREE;
08512 }
08513
08514 if (TREE_CODE (decl) == CONST_DECL)
08515 {
08516 my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
08517
08518 DECL_INITIAL (decl) = init;
08519
08520 my_friendly_assert (init != NULL_TREE, 149);
08521 init = NULL_TREE;
08522 }
08523 else if (!DECL_EXTERNAL (decl) && TREE_CODE (type) == REFERENCE_TYPE)
08524 init = grok_reference_init (decl, type, init, cleanup);
08525 else if (init)
08526 {
08527 if (TREE_CODE (init) == CONSTRUCTOR && TREE_HAS_CONSTRUCTOR (init))
08528 {
08529
08530
08531
08532
08533
08534
08535
08536
08537
08538 if (CP_AGGREGATE_TYPE_P (type))
08539 init = reshape_init (type, &init);
08540 }
08541
08542
08543
08544 maybe_deduce_size_from_array_init (decl, init);
08545 type = TREE_TYPE (decl);
08546 if (TREE_CODE (init) == CONSTRUCTOR && TREE_HAS_CONSTRUCTOR (init))
08547 TREE_TYPE (init) = type;
08548
08549 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
08550 {
08551 if (TREE_CODE (type) == ARRAY_TYPE)
08552 goto initialize_aggr;
08553 else if (TREE_CODE (init) == CONSTRUCTOR
08554 && TREE_HAS_CONSTRUCTOR (init))
08555 {
08556 if (TYPE_NON_AGGREGATE_CLASS (type))
08557 {
08558 error ("`%D' must be initialized by constructor, not by `{...}'",
08559 decl);
08560 init = error_mark_node;
08561 }
08562 else
08563 goto dont_use_constructor;
08564 }
08565 else
08566 {
08567 int saved_stmts_are_full_exprs_p;
08568
08569 initialize_aggr:
08570 saved_stmts_are_full_exprs_p = 0;
08571 if (building_stmt_tree ())
08572 {
08573 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
08574 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
08575 }
08576 init = build_aggr_init (decl, init, flags);
08577 if (building_stmt_tree ())
08578 current_stmt_tree ()->stmts_are_full_exprs_p =
08579 saved_stmts_are_full_exprs_p;
08580 return init;
08581 }
08582 }
08583 else
08584 {
08585 dont_use_constructor:
08586 if (TREE_CODE (init) != TREE_VEC)
08587 init = store_init_value (decl, init);
08588 }
08589 }
08590 else if (DECL_EXTERNAL (decl))
08591 ;
08592 else if (TYPE_P (type) && TYPE_NEEDS_CONSTRUCTING (type))
08593 goto initialize_aggr;
08594 else if (IS_AGGR_TYPE (type))
08595 {
08596 tree core_type = strip_array_types (type);
08597
08598 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type))
08599 error ("structure `%D' with uninitialized const members", decl);
08600 if (CLASSTYPE_REF_FIELDS_NEED_INIT (core_type))
08601 error ("structure `%D' with uninitialized reference members",
08602 decl);
08603
08604 check_for_uninitialized_const_var (decl);
08605 }
08606 else
08607 check_for_uninitialized_const_var (decl);
08608
08609 if (init && init != error_mark_node)
08610 init = build (INIT_EXPR, type, decl, init);
08611
08612 return init;
08613 }
08614
08615
08616
08617 static void
08618 make_rtl_for_nonlocal_decl (decl, init, asmspec)
08619 tree decl;
08620 tree init;
08621 const char *asmspec;
08622 {
08623 int toplev = toplevel_bindings_p ();
08624 int defer_p;
08625
08626
08627 if (TREE_CODE (decl) != VAR_DECL)
08628 {
08629 rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
08630 return;
08631 }
08632
08633
08634
08635 if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
08636 {
08637 my_friendly_assert (TREE_STATIC (decl), 19990828);
08638
08639
08640 if (init == NULL_TREE)
08641 my_friendly_assert (DECL_EXTERNAL (decl), 20000723);
08642 }
08643
08644
08645 if (asmspec)
08646 {
08647 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
08648
08649
08650
08651 if (DECL_REGISTER (decl))
08652 DECL_C_HARD_REGISTER (decl) = 1;
08653 }
08654
08655
08656 if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
08657 return;
08658
08659
08660
08661 defer_p = DECL_FUNCTION_SCOPE_P (decl) || DECL_VIRTUAL_P (decl);
08662
08663
08664
08665 if (!DECL_VIRTUAL_P (decl)
08666 && TREE_READONLY (decl)
08667 && DECL_INITIAL (decl) != NULL_TREE
08668 && DECL_INITIAL (decl) != error_mark_node
08669 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))
08670 && toplev
08671 && !TREE_PUBLIC (decl))
08672 {
08673
08674
08675 if (!interface_unknown && !TREE_PUBLIC (decl))
08676 {
08677 TREE_PUBLIC (decl) = 1;
08678 DECL_EXTERNAL (decl) = interface_only;
08679 }
08680
08681 defer_p = 1;
08682 }
08683
08684 else if (DECL_COMDAT (decl))
08685 defer_p = 1;
08686
08687
08688
08689
08690
08691
08692 if (defer_p && asmspec)
08693 make_decl_rtl (decl, asmspec);
08694
08695 else if (!defer_p)
08696 rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
08697 }
08698
08699
08700
08701
08702
08703
08704
08705 void
08706 maybe_inject_for_scope_var (decl)
08707 tree decl;
08708 {
08709 timevar_push (TV_NAME_LOOKUP);
08710
08711 if (!DECL_NAME (decl))
08712 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, (void)0);
08713
08714
08715
08716
08717 if (DECL_PRETTY_FUNCTION_P (decl))
08718 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, (void)0);
08719
08720 if (current_binding_level->is_for_scope)
08721 {
08722 struct cp_binding_level *outer
08723 = current_binding_level->level_chain;
08724
08725
08726
08727
08728
08729
08730
08731
08732
08733
08734 cxx_binding *outer_binding
08735 = IDENTIFIER_BINDING (DECL_NAME (decl))->previous;
08736
08737 if (outer_binding && BINDING_LEVEL (outer_binding) == outer
08738 && (TREE_CODE (BINDING_VALUE (outer_binding))
08739 == VAR_DECL)
08740 && DECL_DEAD_FOR_LOCAL (BINDING_VALUE (outer_binding)))
08741 {
08742 BINDING_VALUE (outer_binding)
08743 = DECL_SHADOWED_FOR_VAR (BINDING_VALUE (outer_binding));
08744 current_binding_level->is_for_scope = 0;
08745 }
08746 else if (DECL_IN_MEMORY_P (decl))
08747 preserve_temp_slots (DECL_RTL (decl));
08748 }
08749
08750 timevar_pop (TV_NAME_LOOKUP);
08751 }
08752
08753
08754
08755 static void
08756 initialize_local_var (decl, init)
08757 tree decl;
08758 tree init;
08759 {
08760 tree type = TREE_TYPE (decl);
08761 tree cleanup;
08762
08763 my_friendly_assert (TREE_CODE (decl) == VAR_DECL
08764 || TREE_CODE (decl) == RESULT_DECL,
08765 20021010);
08766 my_friendly_assert (!TREE_STATIC (decl), 20021010);
08767
08768 if (DECL_SIZE (decl) == NULL_TREE)
08769 {
08770
08771 DECL_INITIAL (decl) = NULL_TREE;
08772 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
08773 }
08774
08775 if (DECL_SIZE (decl) && type != error_mark_node)
08776 {
08777 int already_used;
08778
08779
08780 already_used = TREE_USED (decl) || TREE_USED (type);
08781
08782
08783 if (init)
08784 {
08785 int saved_stmts_are_full_exprs_p;
08786
08787 my_friendly_assert (building_stmt_tree (), 20000906);
08788 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
08789 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
08790 finish_expr_stmt (init);
08791 current_stmt_tree ()->stmts_are_full_exprs_p =
08792 saved_stmts_are_full_exprs_p;
08793 }
08794
08795
08796
08797
08798
08799
08800
08801 if (TYPE_NEEDS_CONSTRUCTING (type)
08802 && ! already_used
08803 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
08804 && DECL_NAME (decl))
08805 TREE_USED (decl) = 0;
08806 else if (already_used)
08807 TREE_USED (decl) = 1;
08808 }
08809
08810
08811 cleanup = cxx_maybe_build_cleanup (decl);
08812 if (DECL_SIZE (decl) && cleanup)
08813 finish_decl_cleanup (decl, cleanup);
08814 }
08815
08816
08817
08818
08819
08820
08821
08822
08823
08824
08825
08826
08827 void
08828 cp_finish_decl (decl, init, asmspec_tree, flags)
08829 tree decl, init;
08830 tree asmspec_tree;
08831 int flags;
08832 {
08833 tree type;
08834 tree ttype = NULL_TREE;
08835 tree cleanup;
08836 const char *asmspec = NULL;
08837 int was_readonly = 0;
08838
08839 if (! decl)
08840 {
08841 if (init)
08842 error ("assignment (not initialization) in declaration");
08843 return;
08844 }
08845
08846
08847 cleanup = NULL_TREE;
08848
08849
08850 if (global_scope_p (current_binding_level))
08851 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
08852 if (asmspec_tree)
08853 asmspec = TREE_STRING_POINTER (asmspec_tree);
08854
08855 if (init && TREE_CODE (init) == NAMESPACE_DECL)
08856 {
08857 error ("cannot initialize `%D' to namespace `%D'",
08858 decl, init);
08859 init = NULL_TREE;
08860 }
08861
08862 if (current_class_type
08863 && CP_DECL_CONTEXT (decl) == current_class_type
08864 && TYPE_BEING_DEFINED (current_class_type)
08865 && (DECL_INITIAL (decl) || init))
08866 DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
08867
08868 if (TREE_CODE (decl) == VAR_DECL
08869 && DECL_CONTEXT (decl)
08870 && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL
08871 && DECL_CONTEXT (decl) != current_namespace
08872 && init)
08873 {
08874
08875 pop_decl_namespace ();
08876 }
08877
08878 type = TREE_TYPE (decl);
08879
08880 if (type == error_mark_node)
08881 return;
08882
08883 if (TYPE_HAS_MUTABLE_P (type))
08884 TREE_READONLY (decl) = 0;
08885
08886 if (processing_template_decl)
08887 {
08888
08889 if (at_function_scope_p ()
08890 && TREE_CODE (decl) != RESULT_DECL)
08891 add_decl_stmt (decl);
08892
08893 if (init && DECL_INITIAL (decl))
08894 DECL_INITIAL (decl) = init;
08895 goto finish_end0;
08896 }
08897
08898
08899 my_friendly_assert (TREE_CODE (decl) != PARM_DECL, 19990828);
08900
08901
08902 if (TREE_CODE (decl) == TYPE_DECL)
08903 {
08904 if (type != error_mark_node
08905 && IS_AGGR_TYPE (type) && DECL_NAME (decl))
08906 {
08907 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
08908 warning ("shadowing previous type declaration of `%#D'", decl);
08909 set_identifier_type_value (DECL_NAME (decl), type);
08910 CLASSTYPE_GOT_SEMICOLON (type) = 1;
08911 }
08912
08913
08914
08915
08916 if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
08917 && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
08918 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
08919
08920 rest_of_decl_compilation (decl, NULL,
08921 DECL_CONTEXT (decl) == NULL_TREE, at_eof);
08922 goto finish_end;
08923 }
08924
08925 if (TREE_CODE (decl) != FUNCTION_DECL)
08926 ttype = target_type (type);
08927
08928 if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
08929 && (TYPE_NEEDS_CONSTRUCTING (type)
08930 || TREE_CODE (type) == REFERENCE_TYPE))
08931 {
08932
08933
08934
08935
08936 was_readonly = 1;
08937 TREE_READONLY (decl) = 0;
08938 }
08939
08940 if (TREE_CODE (decl) == FIELD_DECL && asmspec)
08941 {
08942
08943
08944 SET_DECL_RTL (TREE_TYPE (decl), NULL_RTX);
08945 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
08946 make_decl_rtl (decl, asmspec);
08947 }
08948 else if (TREE_CODE (decl) == RESULT_DECL)
08949 init = check_initializer (decl, init, flags, &cleanup);
08950 else if (TREE_CODE (decl) == VAR_DECL)
08951 {
08952
08953
08954 if (DECL_THREAD_LOCAL (decl) && !pod_type_p (TREE_TYPE (decl)))
08955 error ("`%D' cannot be thread-local because it has non-POD type `%T'",
08956 decl, TREE_TYPE (decl));
08957
08958
08959 if (!DECL_INITIALIZED_P (decl)
08960
08961
08962
08963
08964 && (!DECL_EXTERNAL (decl) || init))
08965 {
08966 init = check_initializer (decl, init, flags, &cleanup);
08967
08968 if (DECL_THREAD_LOCAL (decl) && init)
08969 {
08970 error ("`%D' is thread-local and so cannot be dynamically "
08971 "initialized", decl);
08972 init = NULL_TREE;
08973 }
08974
08975
08976
08977
08978
08979
08980
08981
08982
08983
08984
08985
08986 if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
08987 DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
08988 NULL_TREE,
08989 true);
08990
08991
08992 DECL_INITIALIZED_P (decl) = 1;
08993 }
08994
08995
08996
08997
08998 else if (TREE_CODE (type) == ARRAY_TYPE)
08999 layout_type (type);
09000 }
09001
09002
09003
09004
09005 if (building_stmt_tree ()
09006 && at_function_scope_p ()
09007 && TREE_CODE (decl) != RESULT_DECL)
09008 add_decl_stmt (decl);
09009
09010 if (TREE_CODE (decl) == VAR_DECL)
09011 layout_var_decl (decl);
09012
09013
09014
09015
09016 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
09017 || TREE_CODE (decl) == RESULT_DECL)
09018 {
09019 if (TREE_CODE (decl) == VAR_DECL)
09020 maybe_commonize_var (decl);
09021
09022 make_rtl_for_nonlocal_decl (decl, init, asmspec);
09023
09024 if (TREE_CODE (type) == FUNCTION_TYPE
09025 || TREE_CODE (type) == METHOD_TYPE)
09026 abstract_virtuals_error (decl,
09027 strip_array_types (TREE_TYPE (type)));
09028 else
09029 abstract_virtuals_error (decl, strip_array_types (type));
09030
09031 if (TREE_CODE (decl) == FUNCTION_DECL
09032 || TREE_TYPE (decl) == error_mark_node)
09033
09034 ;
09035 else if (DECL_EXTERNAL (decl)
09036 && ! (DECL_LANG_SPECIFIC (decl)
09037 && DECL_NOT_REALLY_EXTERN (decl)))
09038 {
09039 if (init)
09040 DECL_INITIAL (decl) = init;
09041 }
09042 else
09043 {
09044
09045 if (DECL_FUNCTION_SCOPE_P (decl))
09046 {
09047
09048 if (doing_semantic_analysis_p ())
09049 maybe_inject_for_scope_var (decl);
09050
09051 if (processing_template_decl)
09052 {
09053 if (init || DECL_INITIAL (decl) == error_mark_node)
09054 DECL_INITIAL (decl) = init;
09055 }
09056 else if (!TREE_STATIC (decl))
09057 initialize_local_var (decl, init);
09058 }
09059
09060 if (TREE_STATIC (decl))
09061 expand_static_init (decl, init);
09062 }
09063 finish_end0:
09064
09065
09066
09067
09068 {
09069 tree context = CP_DECL_CONTEXT (decl);
09070 if (context
09071 && TYPE_P (context)
09072 && (TREE_CODE (decl) == VAR_DECL
09073
09074
09075 || TREE_CODE (decl) == FUNCTION_DECL)
09076
09077
09078
09079 && COMPLETE_TYPE_P (context)
09080 && context == current_class_type)
09081 pop_nested_class ();
09082 }
09083 }
09084
09085
09086
09087 if (cleanup)
09088 add_stmt (cleanup);
09089
09090 finish_end:
09091
09092 if (was_readonly)
09093 TREE_READONLY (decl) = 1;
09094 }
09095
09096
09097
09098 void
09099 finish_decl (decl, init, asmspec_tree)
09100 tree decl, init;
09101 tree asmspec_tree;
09102 {
09103 cp_finish_decl (decl, init, asmspec_tree, 0);
09104 }
09105
09106
09107
09108
09109
09110
09111
09112
09113 tree
09114 declare_global_var (name, type)
09115 tree name;
09116 tree type;
09117 {
09118 tree decl;
09119
09120 push_to_top_level ();
09121 decl = build_decl (VAR_DECL, name, type);
09122 TREE_PUBLIC (decl) = 1;
09123 DECL_EXTERNAL (decl) = 1;
09124 DECL_ARTIFICIAL (decl) = 1;
09125 pushdecl (decl);
09126 cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
09127 pop_from_top_level ();
09128
09129 return decl;
09130 }
09131
09132
09133
09134
09135
09136 static tree
09137 get_atexit_node ()
09138 {
09139 tree atexit_fndecl;
09140 tree arg_types;
09141 tree fn_type;
09142 tree fn_ptr_type;
09143 const char *name;
09144
09145 if (atexit_node)
09146 return atexit_node;
09147
09148 if (flag_use_cxa_atexit)
09149 {
09150
09151
09152
09153
09154
09155
09156
09157
09158
09159 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
09160 fn_type = build_function_type (void_type_node, arg_types);
09161 fn_ptr_type = build_pointer_type (fn_type);
09162
09163 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
09164 arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
09165 arg_types = tree_cons (NULL_TREE, fn_ptr_type, arg_types);
09166
09167 fn_type = build_function_type (integer_type_node, arg_types);
09168 fn_ptr_type = build_pointer_type (fn_type);
09169 name = "__cxa_atexit";
09170 }
09171 else
09172 {
09173
09174
09175
09176
09177
09178
09179 fn_type = build_function_type (void_type_node, void_list_node);
09180 fn_ptr_type = build_pointer_type (fn_type);
09181 arg_types = tree_cons (NULL_TREE, fn_ptr_type, void_list_node);
09182
09183 fn_type = build_function_type (integer_type_node, arg_types);
09184 name = "atexit";
09185 }
09186
09187
09188 push_lang_context (lang_name_c);
09189 atexit_fndecl = build_library_fn_ptr (name, fn_type);
09190 mark_used (atexit_fndecl);
09191 pop_lang_context ();
09192 atexit_node = default_conversion (atexit_fndecl);
09193
09194 return atexit_node;
09195 }
09196
09197
09198
09199 static tree
09200 get_dso_handle_node ()
09201 {
09202 if (dso_handle_node)
09203 return dso_handle_node;
09204
09205
09206 dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
09207 ptr_type_node);
09208
09209 return dso_handle_node;
09210 }
09211
09212
09213
09214
09215 static tree
09216 start_cleanup_fn ()
09217 {
09218 static int counter = 0;
09219 int old_interface_only = interface_only;
09220 int old_interface_unknown = interface_unknown;
09221 char name[32];
09222 tree parmtypes;
09223 tree fntype;
09224 tree fndecl;
09225
09226 push_to_top_level ();
09227
09228
09229 push_lang_context (lang_name_c);
09230
09231 interface_only = 0;
09232 interface_unknown = 1;
09233
09234
09235 parmtypes = void_list_node;
09236
09237
09238
09239
09240 if (flag_use_cxa_atexit)
09241 parmtypes = tree_cons (NULL_TREE, ptr_type_node, parmtypes);
09242
09243 fntype = build_function_type (void_type_node, parmtypes);
09244
09245 sprintf (name, "__tcf_%d", counter++);
09246
09247 fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
09248
09249
09250 TREE_PUBLIC (fndecl) = 0;
09251 DECL_ARTIFICIAL (fndecl) = 1;
09252
09253
09254
09255
09256 DECL_INLINE (fndecl) = 1;
09257
09258 if (flag_use_cxa_atexit)
09259 {
09260 tree parmdecl;
09261
09262 parmdecl = cp_build_parm_decl (NULL_TREE, ptr_type_node);
09263 DECL_CONTEXT (parmdecl) = fndecl;
09264 TREE_USED (parmdecl) = 1;
09265 DECL_ARGUMENTS (fndecl) = parmdecl;
09266 }
09267
09268 pushdecl (fndecl);
09269 start_function (NULL_TREE, fndecl, NULL_TREE, SF_PRE_PARSED);
09270
09271 interface_unknown = old_interface_unknown;
09272 interface_only = old_interface_only;
09273
09274 pop_lang_context ();
09275
09276 return current_function_decl;
09277 }
09278
09279
09280
09281 static void
09282 end_cleanup_fn ()
09283 {
09284 expand_body (finish_function (0));
09285
09286 pop_from_top_level ();
09287 }
09288
09289
09290
09291
09292 void
09293 register_dtor_fn (decl)
09294 tree decl;
09295 {
09296 tree cleanup;
09297 tree compound_stmt;
09298 tree args;
09299 tree fcall;
09300
09301 int saved_flag_access_control;
09302
09303 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
09304 return;
09305
09306
09307
09308
09309 build_cleanup (decl);
09310
09311
09312 cleanup = start_cleanup_fn ();
09313
09314
09315
09316
09317
09318 saved_flag_access_control = flag_access_control;
09319 flag_access_control = 0;
09320 fcall = build_cleanup (decl);
09321 flag_access_control = saved_flag_access_control;
09322
09323
09324 compound_stmt = begin_compound_stmt (0);
09325 finish_expr_stmt (fcall);
09326 finish_compound_stmt (0, compound_stmt);
09327 end_cleanup_fn ();
09328
09329
09330 cxx_mark_addressable (cleanup);
09331 cleanup = build_unary_op (ADDR_EXPR, cleanup, 0);
09332 if (flag_use_cxa_atexit)
09333 {
09334 args = tree_cons (NULL_TREE,
09335 build_unary_op (ADDR_EXPR, get_dso_handle_node (), 0),
09336 NULL_TREE);
09337 args = tree_cons (NULL_TREE, null_pointer_node, args);
09338 args = tree_cons (NULL_TREE, cleanup, args);
09339 }
09340 else
09341 args = tree_cons (NULL_TREE, cleanup, NULL_TREE);
09342 finish_expr_stmt (build_function_call (get_atexit_node (), args));
09343 }
09344
09345
09346
09347
09348
09349 static void
09350 expand_static_init (decl, init)
09351 tree decl;
09352 tree init;
09353 {
09354 tree oldstatic;
09355
09356 my_friendly_assert (TREE_CODE (decl) == VAR_DECL, 20021010);
09357 my_friendly_assert (TREE_STATIC (decl), 20021010);
09358
09359
09360 if (!init
09361 && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
09362 && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
09363 return;
09364
09365 oldstatic = value_member (decl, static_aggregates);
09366
09367 if (oldstatic)
09368 {
09369 if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
09370 error ("multiple initializations given for `%D'", decl);
09371 }
09372 else if (! toplevel_bindings_p ())
09373 {
09374
09375 tree if_stmt;
09376 tree then_clause;
09377 tree assignment;
09378 tree guard;
09379 tree guard_init;
09380
09381
09382
09383
09384
09385
09386
09387
09388
09389
09390
09391
09392
09393
09394
09395
09396
09397
09398
09399
09400
09401
09402
09403
09404
09405
09406
09407 guard = get_guard (decl);
09408
09409
09410 if_stmt = begin_if_stmt ();
09411 finish_if_stmt_cond (get_guard_cond (guard), if_stmt);
09412 then_clause = begin_compound_stmt (0);
09413
09414
09415 assignment = init ? init : NULL_TREE;
09416
09417
09418
09419
09420
09421
09422
09423
09424
09425 guard_init = set_guard (guard);
09426 if (assignment)
09427 {
09428 assignment = tree_cons (NULL_TREE, assignment,
09429 build_tree_list (NULL_TREE,
09430 guard_init));
09431 assignment = build_compound_expr (assignment);
09432 }
09433 else
09434 assignment = guard_init;
09435 finish_expr_stmt (assignment);
09436
09437
09438
09439 register_dtor_fn (decl);
09440
09441 finish_compound_stmt (0, then_clause);
09442 finish_then_clause (if_stmt);
09443 finish_if_stmt ();
09444 }
09445 else
09446 static_aggregates = tree_cons (init, decl, static_aggregates);
09447 }
09448
09449
09450
09451 tree
09452 start_handler_parms (declspecs, declarator)
09453 tree declspecs;
09454 tree declarator;
09455 {
09456 tree decl;
09457 if (declspecs)
09458 {
09459 decl = grokdeclarator (declarator, declspecs, CATCHPARM,
09460 1, NULL);
09461 if (decl == NULL_TREE)
09462 error ("invalid catch parameter");
09463 }
09464 else
09465 decl = NULL_TREE;
09466
09467 return decl;
09468 }
09469
09470
09471
09472
09473
09474
09475 int
09476 complete_array_type (type, initial_value, do_default)
09477 tree type, initial_value;
09478 int do_default;
09479 {
09480 register tree maxindex = NULL_TREE;
09481 int value = 0;
09482
09483 if (initial_value)
09484 {
09485
09486
09487 if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
09488 && TREE_CODE (initial_value) == CONSTRUCTOR
09489 && CONSTRUCTOR_ELTS (initial_value)
09490 && (TREE_CODE (TREE_VALUE (CONSTRUCTOR_ELTS (initial_value)))
09491 == STRING_CST)
09492 && TREE_CHAIN (CONSTRUCTOR_ELTS (initial_value)) == NULL_TREE)
09493 initial_value = TREE_VALUE (CONSTRUCTOR_ELTS (initial_value));
09494
09495
09496
09497 if (TREE_CODE (initial_value) == STRING_CST)
09498 {
09499 int eltsize
09500 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
09501 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
09502 / eltsize) - 1, 0);
09503 }
09504 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
09505 {
09506 tree elts = CONSTRUCTOR_ELTS (initial_value);
09507
09508 maxindex = ssize_int (-1);
09509 for (; elts; elts = TREE_CHAIN (elts))
09510 {
09511 if (TREE_PURPOSE (elts))
09512 maxindex = TREE_PURPOSE (elts);
09513 else
09514 maxindex = size_binop (PLUS_EXPR, maxindex, ssize_int (1));
09515 }
09516 maxindex = copy_node (maxindex);
09517 }
09518 else
09519 {
09520
09521 if (initial_value != error_mark_node)
09522 value = 1;
09523 else
09524 initial_value = NULL_TREE;
09525
09526
09527 maxindex = build_int_2 (0, 0);
09528 }
09529 }
09530
09531 if (!maxindex)
09532 {
09533 if (do_default)
09534 maxindex = build_int_2 (0, 0);
09535 value = 2;
09536 }
09537
09538 if (maxindex)
09539 {
09540 tree itype;
09541 tree domain;
09542
09543 domain = build_index_type (maxindex);
09544 TYPE_DOMAIN (type) = domain;
09545
09546 if (! TREE_TYPE (maxindex))
09547 TREE_TYPE (maxindex) = domain;
09548 if (initial_value)
09549 itype = TREE_TYPE (initial_value);
09550 else
09551 itype = NULL;
09552 if (itype && !TYPE_DOMAIN (itype))
09553 TYPE_DOMAIN (itype) = domain;
09554
09555
09556
09557 if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)))
09558 TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = domain;
09559 }
09560
09561
09562
09563 layout_type (type);
09564
09565 return value;
09566 }
09567
09568
09569
09570
09571
09572 static int
09573 member_function_or_else (ctype, cur_type, flags)
09574 tree ctype, cur_type;
09575 enum overload_flags flags;
09576 {
09577 if (ctype && ctype != cur_type)
09578 {
09579 if (flags == DTOR_FLAG)
09580 error ("destructor for alien class `%T' cannot be a member",
09581 ctype);
09582 else
09583 error ("constructor for alien class `%T' cannot be a member",
09584 ctype);
09585 return 0;
09586 }
09587 return 1;
09588 }
09589
09590
09591
09592
09593
09594
09595 static void
09596 bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
09597 tree object;
09598 const char *type;
09599 int virtualp, quals, friendp, raises, inlinep;
09600 {
09601 if (virtualp)
09602 error ("`%D' declared as a `virtual' %s", object, type);
09603 if (inlinep)
09604 error ("`%D' declared as an `inline' %s", object, type);
09605 if (quals)
09606 error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
09607 object, type);
09608 if (friendp)
09609 cp_error_at ("`%D' declared as a friend", object);
09610 if (raises
09611 && (TREE_CODE (object) == TYPE_DECL
09612 || (!TYPE_PTRFN_P (TREE_TYPE (object))
09613 && !TYPE_REFFN_P (TREE_TYPE (object))
09614 && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
09615 cp_error_at ("`%D' declared with an exception specification", object);
09616 }
09617
09618
09619
09620
09621
09622
09623
09624
09625
09626
09627
09628
09629
09630
09631
09632
09633 static tree
09634 grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals,
09635 raises, check, friendp, publicp, inlinep, funcdef_flag,
09636 template_count, in_namespace)
09637 tree ctype, type;
09638 tree declarator;
09639 tree orig_declarator;
09640 int virtualp;
09641 enum overload_flags flags;
09642 tree quals, raises;
09643 int check, friendp, publicp, inlinep, funcdef_flag, template_count;
09644 tree in_namespace;
09645 {
09646 tree decl;
09647 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
09648 int has_default_arg = 0;
09649 tree t;
09650
09651 if (raises)
09652 type = build_exception_variant (type, raises);
09653
09654 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
09655
09656 if (TYPE_VOLATILE (type))
09657 TREE_THIS_VOLATILE (decl) = 1;
09658
09659
09660 if (in_namespace)
09661 set_decl_namespace (decl, in_namespace, friendp);
09662 else if (!ctype)
09663 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
09664
09665
09666 if ((MAIN_NAME_P (declarator)
09667 || (IDENTIFIER_LENGTH (declarator) > 10
09668 && IDENTIFIER_POINTER (declarator)[0] == '_'
09669 && IDENTIFIER_POINTER (declarator)[1] == '_'
09670 && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
09671 && current_lang_name == lang_name_cplusplus
09672 && ctype == NULL_TREE
09673
09674 && DECL_CONTEXT (decl) == NULL_TREE)
09675 SET_DECL_LANGUAGE (decl, lang_c);
09676
09677
09678 if (staticp)
09679 {
09680 DECL_STATIC_FUNCTION_P (decl) = 1;
09681 DECL_CONTEXT (decl) = ctype;
09682 }
09683
09684 if (ctype)
09685 DECL_CONTEXT (decl) = ctype;
09686
09687 if (ctype == NULL_TREE && DECL_MAIN_P (decl))
09688 {
09689 if (processing_template_decl)
09690 error ("cannot declare `::main' to be a template");
09691 if (inlinep)
09692 error ("cannot declare `::main' to be inline");
09693 if (!publicp)
09694 error ("cannot declare `::main' to be static");
09695 if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
09696 integer_type_node))
09697 error ("`main' must return `int'");
09698 inlinep = 0;
09699 publicp = 1;
09700 }
09701
09702
09703
09704
09705 if (ctype && (TYPE_ANONYMOUS_P (ctype)
09706 || decl_function_context (TYPE_MAIN_DECL (ctype))))
09707 publicp = 0;
09708
09709 if (publicp)
09710 {
09711
09712
09713
09714
09715
09716 t = no_linkage_check (TREE_TYPE (decl));
09717 if (t)
09718 {
09719 if (TYPE_ANONYMOUS_P (t))
09720 {
09721 if (DECL_EXTERN_C_P (decl))
09722 ;
09723 else
09724 {
09725 pedwarn ("non-local function `%#D' uses anonymous type",
09726 decl);
09727 if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
09728 cp_pedwarn_at ("\
09729 `%#D' does not refer to the unqualified type, so it is not used for linkage",
09730 TYPE_NAME (t));
09731 }
09732 }
09733 else
09734 pedwarn ("non-local function `%#D' uses local type `%T'",
09735 decl, t);
09736 }
09737 }
09738
09739 TREE_PUBLIC (decl) = publicp;
09740 if (! publicp)
09741 {
09742 DECL_INTERFACE_KNOWN (decl) = 1;
09743 DECL_NOT_REALLY_EXTERN (decl) = 1;
09744 }
09745
09746 DID_INLINE_FUNC (decl) = 0;
09747
09748 if (inlinep)
09749 DECL_DECLARED_INLINE_P (decl) = 1;
09750
09751
09752 if (DECL_DECLARED_INLINE_P (decl))
09753 DECL_INLINE (decl) = 1;
09754 if (flag_inline_trees == 2 && !DECL_INLINE (decl) && funcdef_flag)
09755 {
09756 DID_INLINE_FUNC (decl) = 1;
09757 DECL_INLINE (decl) = 1;
09758 }
09759
09760 DECL_EXTERNAL (decl) = 1;
09761 if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
09762 {
09763 error ("%smember function `%D' cannot have `%T' method qualifier",
09764 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
09765 quals = NULL_TREE;
09766 }
09767
09768 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
09769 grok_op_properties (decl, friendp);
09770
09771 if (ctype && decl_function_context (decl))
09772 DECL_NO_STATIC_CHAIN (decl) = 1;
09773
09774 for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
09775 if (TREE_PURPOSE (t)
09776 && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG)
09777 {
09778 has_default_arg = 1;
09779 break;
09780 }
09781
09782 if (friendp
09783 && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
09784 {
09785 if (funcdef_flag)
09786 error
09787 ("defining explicit specialization `%D' in friend declaration",
09788 orig_declarator);
09789 else
09790 {
09791 tree fns = TREE_OPERAND (orig_declarator, 0);
09792 tree args = TREE_OPERAND (orig_declarator, 1);
09793
09794 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
09795 {
09796
09797 error ("invalid use of template-id `%D' in declaration of primary template",
09798 orig_declarator);
09799 return NULL_TREE;
09800 }
09801
09802
09803
09804
09805 SET_DECL_IMPLICIT_INSTANTIATION (decl);
09806
09807 if (TREE_CODE (fns) == COMPONENT_REF)
09808 {
09809
09810
09811
09812
09813
09814 my_friendly_assert (TREE_TYPE (TREE_OPERAND (fns, 0))
09815 == current_class_type, 20001120);
09816 fns = TREE_OPERAND (fns, 1);
09817 }
09818 my_friendly_assert (TREE_CODE (fns) == IDENTIFIER_NODE
09819 || TREE_CODE (fns) == LOOKUP_EXPR
09820 || TREE_CODE (fns) == OVERLOAD, 20001120);
09821 DECL_TEMPLATE_INFO (decl) = tree_cons (fns, args, NULL_TREE);
09822
09823 if (has_default_arg)
09824 {
09825 error ("default arguments are not allowed in declaration of friend template specialization `%D'",
09826 decl);
09827 return NULL_TREE;
09828 }
09829
09830 if (inlinep)
09831 {
09832 error ("`inline' is not allowed in declaration of friend template specialization `%D'",
09833 decl);
09834 return NULL_TREE;
09835 }
09836 }
09837 }
09838
09839 if (has_default_arg)
09840 add_defarg_fn (decl);
09841
09842 if (funcdef_flag)
09843
09844
09845 DECL_INITIAL (decl) = error_mark_node;
09846
09847 if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
09848 TREE_NOTHROW (decl) = 1;
09849
09850
09851 if (check < 0)
09852 return decl;
09853
09854 if (flags == NO_SPECIAL && ctype && constructor_name (ctype) == declarator)
09855 DECL_CONSTRUCTOR_P (decl) = 1;
09856
09857
09858
09859
09860 if (ctype != NULL_TREE)
09861 grokclassfn (ctype, decl, flags, quals);
09862
09863 decl = check_explicit_specialization (orig_declarator, decl,
09864 template_count,
09865 2 * (funcdef_flag != 0) +
09866 4 * (friendp != 0));
09867 if (decl == error_mark_node)
09868 return NULL_TREE;
09869
09870 if (ctype != NULL_TREE
09871 && (! TYPE_FOR_JAVA (ctype) || check_java_method (decl))
09872 && check)
09873 {
09874 tree old_decl;
09875
09876 old_decl = check_classfn (ctype, decl);
09877
09878 if (old_decl && TREE_CODE (old_decl) == TEMPLATE_DECL)
09879
09880
09881
09882
09883 old_decl = DECL_TEMPLATE_RESULT (old_decl);
09884
09885 if (old_decl && DECL_STATIC_FUNCTION_P (old_decl)
09886 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
09887 {
09888
09889
09890 revert_static_member_fn (decl);
09891 last_function_parms = TREE_CHAIN (last_function_parms);
09892 }
09893 if (old_decl && DECL_ARTIFICIAL (old_decl))
09894 error ("definition of implicitly-declared `%D'", old_decl);
09895
09896 if (old_decl)
09897 {
09898
09899
09900 if (TREE_CODE (decl) == TEMPLATE_DECL)
09901 decl = DECL_TEMPLATE_RESULT (decl);
09902
09903
09904
09905 if (!duplicate_decls (decl, old_decl))
09906 error ("no `%#D' member function declared in class `%T'",
09907 decl, ctype);
09908 return old_decl;
09909 }
09910 }
09911
09912 if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
09913 return NULL_TREE;
09914
09915 if (ctype == NULL_TREE || check)
09916 return decl;
09917
09918 if (virtualp)
09919 DECL_VIRTUAL_P (decl) = 1;
09920
09921 return decl;
09922 }
09923
09924
09925
09926
09927
09928
09929
09930 static tree
09931 grokvardecl (type, name, specbits_in, initialized, constp, scope)
09932 tree type;
09933 tree name;
09934 RID_BIT_TYPE *specbits_in;
09935 int initialized;
09936 int constp;
09937 tree scope;
09938 {
09939 tree decl;
09940 RID_BIT_TYPE specbits;
09941
09942 my_friendly_assert (!name || TREE_CODE (name) == IDENTIFIER_NODE,
09943 20020808);
09944
09945 specbits = *specbits_in;
09946
09947
09948 if (!scope)
09949 {
09950
09951
09952 if (RIDBIT_SETP (RID_EXTERN, specbits))
09953 scope = current_namespace;
09954 else if (!at_function_scope_p ())
09955 {
09956 scope = current_scope ();
09957 if (!scope)
09958 scope = current_namespace;
09959 }
09960 }
09961
09962 if (scope
09963 && (
09964
09965 (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
09966
09967
09968 || (TREE_CODE (scope) == NAMESPACE_DECL
09969 && current_lang_name != lang_name_cplusplus)
09970
09971 || TYPE_P (scope)))
09972 decl = build_lang_decl (VAR_DECL, name, type);
09973 else
09974 decl = build_decl (VAR_DECL, name, type);
09975
09976 if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
09977 set_decl_namespace (decl, scope, 0);
09978 else
09979 DECL_CONTEXT (decl) = scope;
09980
09981 if (name && scope && current_lang_name != lang_name_c)
09982
09983
09984
09985 mangle_decl (decl);
09986
09987 if (RIDBIT_SETP (RID_EXTERN, specbits))
09988 {
09989 DECL_THIS_EXTERN (decl) = 1;
09990 DECL_EXTERNAL (decl) = !initialized;
09991 }
09992
09993
09994
09995 if (DECL_CLASS_SCOPE_P (decl))
09996 {
09997 TREE_PUBLIC (decl) = 1;
09998 TREE_STATIC (decl) = 1;
09999 DECL_EXTERNAL (decl) = 0;
10000 }
10001
10002
10003 else if (toplevel_bindings_p ())
10004 {
10005 TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits)
10006 && (DECL_THIS_EXTERN (decl) || ! constp));
10007 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
10008 }
10009
10010 else
10011 {
10012 TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
10013 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
10014 }
10015
10016 if (RIDBIT_SETP (RID_THREAD, specbits))
10017 {
10018 if (targetm.have_tls)
10019 DECL_THREAD_LOCAL (decl) = 1;
10020 else
10021
10022
10023 error ("thread-local storage not supported for this target");
10024 }
10025
10026 if (TREE_PUBLIC (decl))
10027 {
10028
10029
10030
10031
10032
10033 tree t = no_linkage_check (TREE_TYPE (decl));
10034 if (t)
10035 {
10036 if (TYPE_ANONYMOUS_P (t))
10037 ;
10038 else
10039 pedwarn ("non-local variable `%#D' uses local type `%T'",
10040 decl, t);
10041 }
10042 }
10043
10044 return decl;
10045 }
10046
10047
10048
10049
10050 tree
10051 build_ptrmemfunc_type (tree type)
10052 {
10053 tree fields[4];
10054 tree t;
10055 tree unqualified_variant = NULL_TREE;
10056
10057 if (type == error_mark_node)
10058 return type;
10059
10060
10061
10062
10063
10064 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
10065 return t;
10066
10067
10068
10069 if (cp_type_quals (type) != TYPE_UNQUALIFIED)
10070 unqualified_variant
10071 = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
10072
10073 t = make_aggr_type (RECORD_TYPE);
10074
10075 TYPE_PTRMEMFUNC_FLAG (t) = 1;
10076
10077 SET_IS_AGGR_TYPE (t, 0);
10078
10079 fields[0] = build_decl (FIELD_DECL, pfn_identifier, type);
10080 fields[1] = build_decl (FIELD_DECL, delta_identifier,
10081 delta_type_node);
10082 finish_builtin_type (t, "__ptrmemfunc_type", fields, 1, ptr_type_node);
10083
10084
10085
10086 TYPE_NAME (t) = NULL_TREE;
10087
10088
10089
10090
10091
10092 if (cp_type_quals (type) != TYPE_UNQUALIFIED)
10093 {
10094 t = build_qualified_type (t, cp_type_quals (type));
10095 TYPE_MAIN_VARIANT (t) = unqualified_variant;
10096 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (unqualified_variant);
10097 TYPE_NEXT_VARIANT (unqualified_variant) = t;
10098 }
10099
10100
10101
10102 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
10103
10104
10105 CLASSTYPE_GOT_SEMICOLON (t) = 1;
10106
10107 return t;
10108 }
10109
10110
10111
10112 tree
10113 build_ptrmem_type (tree class_type, tree member_type)
10114 {
10115 return build_pointer_type (build_offset_type (class_type, member_type));
10116 }
10117
10118
10119
10120
10121
10122
10123 int
10124 check_static_variable_definition (decl, type)
10125 tree decl;
10126 tree type;
10127 {
10128
10129
10130
10131
10132
10133
10134 if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
10135 {
10136 error ("invalid in-class initialization of static data member of non-integral type `%T'",
10137 type);
10138
10139
10140
10141
10142 return 1;
10143 }
10144 else if (!CP_TYPE_CONST_P (type))
10145 error ("ISO C++ forbids in-class initialization of non-const static member `%D'",
10146 decl);
10147 else if (pedantic && !INTEGRAL_TYPE_P (type))
10148 pedwarn ("ISO C++ forbids initialization of member constant `%D' of non-integral type `%T'", decl, type);
10149
10150 return 0;
10151 }
10152
10153
10154
10155
10156
10157 tree
10158 compute_array_index_type (name, size)
10159 tree name;
10160 tree size;
10161 {
10162 tree itype;
10163
10164
10165
10166
10167
10168
10169 if (processing_template_decl)
10170 {
10171
10172
10173 if (TREE_CODE (size) == SCOPE_REF
10174 && TREE_OPERAND (size, 0) == current_class_type)
10175 {
10176 tree t = lookup_field (current_class_type,
10177 TREE_OPERAND (size, 1), 0, 0);
10178 if (t)
10179 size = t;
10180 }
10181
10182 return build_index_type (build_min (MINUS_EXPR, sizetype,
10183 size, integer_one_node));
10184 }
10185
10186
10187 STRIP_TYPE_NOPS (size);
10188
10189
10190 size = decl_constant_value (size);
10191
10192
10193 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
10194 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE
10195 && TREE_CODE (TREE_TYPE (size)) != BOOLEAN_TYPE)
10196 {
10197 if (name)
10198 error ("size of array `%D' has non-integer type", name);
10199 else
10200 error ("size of array has non-integer type");
10201 size = integer_one_node;
10202 }
10203
10204
10205 if (TREE_CODE (size) == INTEGER_CST)
10206 {
10207
10208
10209 int old_flag_pedantic_errors = flag_pedantic_errors;
10210 int old_pedantic = pedantic;
10211 pedantic = flag_pedantic_errors = 1;
10212 constant_expression_warning (size);
10213 pedantic = old_pedantic;
10214 flag_pedantic_errors = old_flag_pedantic_errors;
10215
10216
10217 if (INT_CST_LT (size, integer_zero_node))
10218 {
10219 if (name)
10220 error ("size of array `%D' is negative", name);
10221 else
10222 error ("size of array is negative");
10223 size = integer_one_node;
10224 }
10225
10226
10227
10228 else if (integer_zerop (size) && pedantic && !in_system_header)
10229 {
10230 if (name)
10231 pedwarn ("ISO C++ forbids zero-size array `%D'", name);
10232 else
10233 pedwarn ("ISO C++ forbids zero-size array");
10234 }
10235 }
10236 else if (TREE_CONSTANT (size))
10237 {
10238
10239 if (name)
10240 error ("size of array `%D' is not an integral constant-expression",
10241 name);
10242 else
10243 error ("size of array is not an integral constant-expression");
10244 }
10245
10246
10247
10248 itype
10249 = fold (cp_build_binary_op (MINUS_EXPR,
10250 cp_convert (ssizetype, size),
10251 cp_convert (ssizetype,
10252 integer_one_node)));
10253
10254
10255
10256 if (!TREE_CONSTANT (itype))
10257 {
10258 if (pedantic)
10259 {
10260 if (name)
10261 pedwarn ("ISO C++ forbids variable-size array `%D'",
10262 name);
10263 else
10264 pedwarn ("ISO C++ forbids variable-size array");
10265 }
10266
10267
10268 itype = variable_size (itype);
10269 }
10270
10271
10272
10273 else if (TREE_OVERFLOW (itype))
10274 {
10275 error ("overflow in array dimension");
10276 TREE_OVERFLOW (itype) = 0;
10277 }
10278
10279
10280 return build_index_type (itype);
10281 }
10282
10283
10284
10285
10286
10287 static tree
10288 create_array_type_for_decl (name, type, size)
10289 tree name;
10290 tree type;
10291 tree size;
10292 {
10293 tree itype = NULL_TREE;
10294 const char* error_msg;
10295
10296
10297 if (type == error_mark_node || size == error_mark_node)
10298 return error_mark_node;
10299
10300
10301 error_msg = NULL;
10302
10303
10304 switch (TREE_CODE (type))
10305 {
10306 case VOID_TYPE:
10307 error_msg = "array of void";
10308 break;
10309
10310 case FUNCTION_TYPE:
10311 error_msg = "array of functions";
10312 break;
10313
10314 case REFERENCE_TYPE:
10315 error_msg = "array of references";
10316 break;
10317
10318 case OFFSET_TYPE:
10319 error_msg = "array of data members";
10320 break;
10321
10322 case METHOD_TYPE:
10323 error_msg = "array of function members";
10324 break;
10325
10326 default:
10327 break;
10328 }
10329
10330
10331 if (error_msg)
10332 {
10333 if (name)
10334 error ("declaration of `%D' as %s", name, error_msg);
10335 else
10336 error ("creating %s", error_msg);
10337
10338 return error_mark_node;
10339 }
10340
10341
10342
10343
10344
10345 if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
10346 {
10347 if (name)
10348 error ("declaration of `%D' as multidimensional array must have bounds for all dimensions except the first",
10349 name);
10350 else
10351 error ("multidimensional array must have bounds for all dimensions except the first");
10352
10353 return error_mark_node;
10354 }
10355
10356
10357 if (size)
10358 itype = compute_array_index_type (name, size);
10359
10360 return build_cplus_array_type (type, itype);
10361 }
10362
10363
10364
10365
10366
10367
10368
10369
10370 static tree
10371 check_special_function_return_type (sfk, type, optype)
10372 special_function_kind sfk;
10373 tree type;
10374 tree optype;
10375 {
10376 switch (sfk)
10377 {
10378 case sfk_constructor:
10379 if (type)
10380 error ("return type specification for constructor invalid");
10381
10382 type = void_type_node;
10383 break;
10384
10385 case sfk_destructor:
10386 if (type)
10387 error ("return type specification for destructor invalid");
10388 type = void_type_node;
10389 break;
10390
10391 case sfk_conversion:
10392 if (type && !same_type_p (type, optype))
10393 error ("operator `%T' declared to return `%T'", optype, type);
10394 else if (type)
10395 pedwarn ("return type specified for `operator %T'", optype);
10396 type = optype;
10397 break;
10398
10399 default:
10400 abort ();
10401 break;
10402 }
10403
10404 return type;
10405 }
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468 tree
10469 grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
10470 tree declspecs;
10471 tree declarator;
10472 enum decl_context decl_context;
10473 int initialized;
10474 tree *attrlist;
10475 {
10476 RID_BIT_TYPE specbits;
10477 int nclasses = 0;
10478 tree spec;
10479 tree type = NULL_TREE;
10480 int longlong = 0;
10481 int type_quals;
10482 int virtualp, explicitp, friendp, inlinep, staticp;
10483 int explicit_int = 0;
10484 int explicit_char = 0;
10485 int defaulted_int = 0;
10486 int extern_langp = 0;
10487 tree dependant_name = NULL_TREE;
10488
10489 tree typedef_decl = NULL_TREE;
10490 const char *name;
10491 tree typedef_type = NULL_TREE;
10492 int funcdef_flag = 0;
10493 enum tree_code innermost_code = ERROR_MARK;
10494 int bitfield = 0;
10495 #if 0
10496
10497 tree decl_attr = NULL_TREE;
10498 #endif
10499
10500
10501 tree init = NULL_TREE;
10502
10503
10504
10505
10506 special_function_kind sfk = sfk_none;
10507
10508 tree dname = NULL_TREE;
10509 tree ctype = current_class_type;
10510 tree ctor_return_type = NULL_TREE;
10511 enum overload_flags flags = NO_SPECIAL;
10512 tree quals = NULL_TREE;
10513 tree raises = NULL_TREE;
10514 int template_count = 0;
10515 tree in_namespace = NULL_TREE;
10516 tree returned_attrs = NULL_TREE;
10517
10518 RIDBIT_RESET_ALL (specbits);
10519 if (decl_context == FUNCDEF)
10520 funcdef_flag = 1, decl_context = NORMAL;
10521 else if (decl_context == MEMFUNCDEF)
10522 funcdef_flag = -1, decl_context = FIELD;
10523 else if (decl_context == BITFIELD)
10524 bitfield = 1, decl_context = FIELD;
10525
10526
10527
10528 {
10529 tree *next = &declarator;
10530 register tree decl;
10531 name = NULL;
10532
10533 while (next && *next)
10534 {
10535 decl = *next;
10536 switch (TREE_CODE (decl))
10537 {
10538 case TREE_LIST:
10539
10540 next = &TREE_VALUE (decl);
10541 break;
10542
10543 case COND_EXPR:
10544 ctype = NULL_TREE;
10545 next = &TREE_OPERAND (decl, 0);
10546 break;
10547
10548 case BIT_NOT_EXPR:
10549 {
10550 tree name = TREE_OPERAND (decl, 0);
10551 tree rename = NULL_TREE;
10552
10553 my_friendly_assert (flags == NO_SPECIAL, 152);
10554 flags = DTOR_FLAG;
10555 sfk = sfk_destructor;
10556 if (TREE_CODE (name) == TYPE_DECL)
10557 TREE_OPERAND (decl, 0) = name = constructor_name (name);
10558 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
10559 if (ctype == NULL_TREE)
10560 {
10561 if (current_class_type == NULL_TREE)
10562 {
10563 error ("destructors must be member functions");
10564 flags = NO_SPECIAL;
10565 }
10566 else
10567 {
10568 tree t = constructor_name (current_class_name);
10569 if (t != name)
10570 rename = t;
10571 }
10572 }
10573 else
10574 {
10575 tree t = constructor_name (ctype);
10576 if (t != name)
10577 rename = t;
10578 }
10579
10580 if (rename)
10581 {
10582 error ("destructor `%T' must match class name `%T'",
10583 name, rename);
10584 TREE_OPERAND (decl, 0) = rename;
10585 }
10586 next = &name;
10587 }
10588 break;
10589
10590 case ADDR_EXPR:
10591
10592 case ARRAY_REF:
10593 case INDIRECT_REF:
10594 ctype = NULL_TREE;
10595 innermost_code = TREE_CODE (decl);
10596 next = &TREE_OPERAND (decl, 0);
10597 break;
10598
10599 case CALL_EXPR:
10600 if (parmlist_is_exprlist (CALL_DECLARATOR_PARMS (decl)))
10601 {
10602
10603
10604
10605
10606
10607 tree attributes;
10608
10609 if (decl_context != NORMAL)
10610 {
10611 error ("variable declaration is not allowed here");
10612 return error_mark_node;
10613 }
10614
10615 *next = TREE_OPERAND (decl, 0);
10616 init = CALL_DECLARATOR_PARMS (decl);
10617
10618 if (attrlist)
10619 {
10620 attributes = *attrlist;
10621 }
10622 else
10623 {
10624 attributes = NULL_TREE;
10625 }
10626
10627 decl = start_decl (declarator, declspecs, 1,
10628 attributes, NULL_TREE);
10629 decl_type_access_control (decl);
10630 if (decl)
10631 {
10632
10633 if (TREE_USED (TREE_TYPE (decl)))
10634 TREE_USED (decl) = 1;
10635 finish_decl (decl, init, NULL_TREE);
10636 }
10637 else
10638 error ("invalid declarator");
10639 return NULL_TREE;
10640 }
10641 innermost_code = TREE_CODE (decl);
10642 if (decl_context == FIELD && ctype == NULL_TREE)
10643 ctype = current_class_type;
10644 if (ctype
10645 && TREE_OPERAND (decl, 0)
10646 && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL
10647 && constructor_name_p (DECL_NAME (TREE_OPERAND (decl, 0)),
10648 ctype)))
10649 TREE_OPERAND (decl, 0) = constructor_name (ctype);
10650 next = &TREE_OPERAND (decl, 0);
10651 decl = *next;
10652 if (ctype != NULL_TREE
10653 && decl != NULL_TREE && flags != DTOR_FLAG
10654 && decl == constructor_name (ctype))
10655 {
10656 sfk = sfk_constructor;
10657 ctor_return_type = ctype;
10658 }
10659 ctype = NULL_TREE;
10660 break;
10661
10662 case TEMPLATE_ID_EXPR:
10663 {
10664 tree fns = TREE_OPERAND (decl, 0);
10665
10666 if (TREE_CODE (fns) == LOOKUP_EXPR)
10667 fns = TREE_OPERAND (fns, 0);
10668
10669 dname = fns;
10670 if (TREE_CODE (dname) == COMPONENT_REF)
10671 dname = TREE_OPERAND (dname, 1);
10672 if (TREE_CODE (dname) != IDENTIFIER_NODE)
10673 {
10674 my_friendly_assert (is_overloaded_fn (dname),
10675 19990331);
10676 dname = DECL_NAME (get_first_fn (dname));
10677 }
10678 }
10679
10680
10681 case IDENTIFIER_NODE:
10682 if (TREE_CODE (decl) == IDENTIFIER_NODE)
10683 dname = decl;
10684
10685 next = 0;
10686
10687 if (C_IS_RESERVED_WORD (dname))
10688 {
10689 error ("declarator-id missing; using reserved word `%D'",
10690 dname);
10691 name = IDENTIFIER_POINTER (dname);
10692 }
10693 else if (!IDENTIFIER_TYPENAME_P (dname))
10694 name = IDENTIFIER_POINTER (dname);
10695 else
10696 {
10697 my_friendly_assert (flags == NO_SPECIAL, 154);
10698 flags = TYPENAME_FLAG;
10699 ctor_return_type = TREE_TYPE (dname);
10700 sfk = sfk_conversion;
10701 if (IDENTIFIER_GLOBAL_VALUE (dname)
10702 && (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (dname))
10703 == TYPE_DECL))
10704 name = IDENTIFIER_POINTER (dname);
10705 else
10706 name = "<invalid operator>";
10707 }
10708 break;
10709
10710
10711 case SCOPE_REF:
10712 {
10713
10714 tree cname = TREE_OPERAND (decl, 0);
10715 if (cname == NULL_TREE)
10716 ctype = NULL_TREE;
10717 else if (TREE_CODE (cname) == NAMESPACE_DECL)
10718 {
10719 ctype = NULL_TREE;
10720 in_namespace = TREE_OPERAND (decl, 0);
10721 TREE_OPERAND (decl, 0) = NULL_TREE;
10722 }
10723 else if (! is_aggr_type (cname, 1))
10724 TREE_OPERAND (decl, 0) = NULL_TREE;
10725
10726
10727 else if (TREE_OPERAND (decl, 1)
10728 && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
10729 ctype = cname;
10730 else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM
10731 || TREE_CODE (cname) == BOUND_TEMPLATE_TEMPLATE_PARM)
10732 {
10733
10734
10735 ctype = cname;
10736 dependant_name = TREE_OPERAND (decl, 1);
10737 }
10738 else if (ctype == NULL_TREE)
10739 ctype = cname;
10740 else if (TREE_COMPLEXITY (decl) == current_class_depth)
10741 TREE_OPERAND (decl, 0) = ctype;
10742 else
10743 {
10744 if (! UNIQUELY_DERIVED_FROM_P (cname, ctype))
10745 {
10746 error ("type `%T' is not derived from type `%T'",
10747 cname, ctype);
10748 TREE_OPERAND (decl, 0) = NULL_TREE;
10749 }
10750 else
10751 ctype = cname;
10752 }
10753
10754
10755
10756
10757
10758
10759 if (TREE_CODE (TREE_OPERAND (decl, 1)) == NAMESPACE_DECL)
10760 TREE_OPERAND (decl, 1) = DECL_NAME (TREE_OPERAND (decl, 1));
10761
10762 if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL
10763 && constructor_name_p (DECL_NAME (TREE_OPERAND (decl, 1)),
10764 ctype))
10765 TREE_OPERAND (decl, 1) = constructor_name (ctype);
10766 next = &TREE_OPERAND (decl, 1);
10767 decl = *next;
10768 if (ctype)
10769 {
10770 if (TREE_CODE (decl) == IDENTIFIER_NODE
10771 && constructor_name (ctype) == decl)
10772 {
10773 sfk = sfk_constructor;
10774 ctor_return_type = ctype;
10775 }
10776 else if (TREE_CODE (decl) == BIT_NOT_EXPR
10777 && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
10778 && constructor_name_p (TREE_OPERAND (decl, 0),
10779 ctype))
10780 {
10781 sfk = sfk_destructor;
10782 ctor_return_type = ctype;
10783 flags = DTOR_FLAG;
10784 TREE_OPERAND (decl, 0) = constructor_name (ctype);
10785 next = &TREE_OPERAND (decl, 0);
10786 }
10787 }
10788 }
10789 break;
10790
10791 case ERROR_MARK:
10792 next = 0;
10793 break;
10794
10795 case TYPE_DECL:
10796
10797
10798 error ("`%T' specified as declarator-id", DECL_NAME (decl));
10799 if (TREE_TYPE (decl) == current_class_type)
10800 error (" perhaps you want `%T' for a constructor",
10801 current_class_name);
10802 dname = DECL_NAME (decl);
10803 name = IDENTIFIER_POINTER (dname);
10804
10805
10806 IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE;
10807
10808 declspecs = tree_cons (NULL_TREE, integer_type_node, declspecs);
10809 *next = dname;
10810 next = 0;
10811 break;
10812
10813 case BASELINK:
10814 next = &BASELINK_FUNCTIONS (decl);
10815 break;
10816
10817 case TEMPLATE_DECL:
10818
10819
10820
10821
10822 error ("invalid use of template-name '%E' in a declarator", decl);
10823 return error_mark_node;
10824 break;
10825
10826 default:
10827 my_friendly_assert (0, 20020917);
10828 }
10829 }
10830 }
10831
10832
10833
10834
10835 if (funcdef_flag && innermost_code != CALL_EXPR)
10836 return 0;
10837
10838 if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
10839 && innermost_code != CALL_EXPR
10840 && ! (ctype && declspecs == NULL_TREE))
10841 {
10842 error ("declaration of `%D' as non-function", dname);
10843 return void_type_node;
10844 }
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860 if (decl_context == NORMAL && !toplevel_bindings_p ())
10861 {
10862 struct cp_binding_level *b = current_binding_level;
10863 #ifdef KEY
10864 copy_to_current_binding_level (b->level_chain);
10865 #else
10866 current_binding_level = b->level_chain;
10867 #endif // KEY
10868 if (current_binding_level != 0 && toplevel_bindings_p ())
10869 decl_context = PARM;
10870 #ifdef KEY
10871 copy_to_current_binding_level (b);
10872 #else
10873 current_binding_level = b;
10874 #endif // KEY
10875 }
10876
10877 if (name == NULL)
10878 name = decl_context == PARM ? "parameter" : "type name";
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
10897 {
10898 register int i;
10899 register tree id;
10900
10901
10902
10903
10904 if (TREE_CODE (spec) != TREE_LIST)
10905 return 0;
10906
10907 id = TREE_VALUE (spec);
10908
10909
10910
10911 if (!adding_implicit_members && id && TREE_DEPRECATED (id))
10912 {
10913 if (deprecated_state != DEPRECATED_SUPPRESS)
10914 warn_deprecated_use (id);
10915 }
10916
10917 if (TREE_CODE (id) == IDENTIFIER_NODE)
10918 {
10919 if (id == ridpointers[(int) RID_INT]
10920 || id == ridpointers[(int) RID_CHAR]
10921 || id == ridpointers[(int) RID_BOOL]
10922 || id == ridpointers[(int) RID_WCHAR])
10923 {
10924 if (type)
10925 {
10926 if (id == ridpointers[(int) RID_BOOL])
10927 error ("`bool' is now a keyword");
10928 else
10929 error ("extraneous `%T' ignored", id);
10930 }
10931 else
10932 {
10933 if (id == ridpointers[(int) RID_INT])
10934 explicit_int = 1;
10935 else if (id == ridpointers[(int) RID_CHAR])
10936 explicit_char = 1;
10937 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
10938 }
10939 goto found;
10940 }
10941
10942 if (IDENTIFIER_HAS_TYPE_VALUE (id))
10943 {
10944 if (type)
10945 error ("multiple declarations `%T' and `%T'", type, id);
10946 else
10947 type = IDENTIFIER_TYPE_VALUE (id);
10948 goto found;
10949 }
10950
10951 for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++)
10952 {
10953 if (ridpointers[i] == id)
10954 {
10955 if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
10956 {
10957 if (pedantic && ! in_system_header && warn_long_long)
10958 pedwarn ("ISO C++ does not support `long long'");
10959 if (longlong)
10960 error ("`long long long' is too long for GCC");
10961 else
10962 longlong = 1;
10963 }
10964 else if (RIDBIT_SETP (i, specbits))
10965 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
10966
10967
10968
10969 if (i == (int)RID_THREAD)
10970 {
10971 if (RIDBIT_SETP (RID_EXTERN, specbits))
10972 error ("`__thread' before `extern'");
10973 if (RIDBIT_SETP (RID_STATIC, specbits))
10974 error ("`__thread' before `static'");
10975 }
10976
10977 if (i == (int)RID_EXTERN
10978 && TREE_PURPOSE (spec) == error_mark_node)
10979
10980 extern_langp = 1;
10981
10982 RIDBIT_SET (i, specbits);
10983 goto found;
10984 }
10985 }
10986 }
10987 else if (TREE_CODE (id) == TYPE_DECL)
10988 {
10989 if (type)
10990 error ("multiple declarations `%T' and `%T'", type,
10991 TREE_TYPE (id));
10992 else
10993 {
10994 type = TREE_TYPE (id);
10995 TREE_VALUE (spec) = type;
10996 typedef_decl = id;
10997 }
10998 goto found;
10999 }
11000 if (type)
11001 error ("two or more data types in declaration of `%s'", name);
11002 else if (TREE_CODE (id) == IDENTIFIER_NODE)
11003 {
11004 register tree t = lookup_name (id, 1);
11005 if (!t || TREE_CODE (t) != TYPE_DECL)
11006 error ("`%s' fails to be a typedef or built in type",
11007 IDENTIFIER_POINTER (id));
11008 else
11009 {
11010 type = TREE_TYPE (t);
11011 typedef_decl = t;
11012 }
11013 }
11014 else if (id != error_mark_node)
11015
11016 type = id;
11017
11018 found: ;
11019 }
11020
11021 #if 0
11022
11023 if (typedef_decl)
11024 decl_attr = DECL_ATTRIBUTES (typedef_decl);
11025 #endif
11026 typedef_type = type;
11027
11028
11029
11030
11031 if (type == NULL_TREE
11032 && (RIDBIT_SETP (RID_SIGNED, specbits)
11033 || RIDBIT_SETP (RID_UNSIGNED, specbits)
11034 || RIDBIT_SETP (RID_LONG, specbits)
11035 || RIDBIT_SETP (RID_SHORT, specbits)))
11036 {
11037
11038 type = integer_type_node;
11039 defaulted_int = 1;
11040 }
11041
11042 if (sfk != sfk_none)
11043 type = check_special_function_return_type (sfk, type,
11044 ctor_return_type);
11045 else if (type == NULL_TREE)
11046 {
11047 int is_main;
11048
11049 explicit_int = -1;
11050
11051
11052
11053
11054 is_main = (funcdef_flag
11055 && dname && MAIN_NAME_P (dname)
11056 && ctype == NULL_TREE
11057 && in_namespace == NULL_TREE
11058 && current_namespace == global_namespace);
11059
11060 if (in_system_header || flag_ms_extensions)
11061 ;
11062 else if (pedantic || ! is_main)
11063 pedwarn ("ISO C++ forbids declaration of `%s' with no type",
11064 name);
11065 else if (warn_return_type)
11066 warning ("ISO C++ forbids declaration of `%s' with no type",
11067 name);
11068
11069 type = integer_type_node;
11070 }
11071
11072 if (type && IMPLICIT_TYPENAME_P (type))
11073 {
11074
11075
11076 warning ("`%T' is implicitly a typename", type);
11077 cp_deprecated ("implicit typename");
11078
11079
11080
11081
11082
11083 type = copy_node (type);
11084 TREE_TYPE (type) = NULL_TREE;
11085 }
11086
11087 ctype = NULL_TREE;
11088
11089
11090
11091
11092
11093
11094 if (RIDBIT_SETP (RID_LONG, specbits)
11095 && TYPE_MAIN_VARIANT (type) == double_type_node)
11096 {
11097 RIDBIT_RESET (RID_LONG, specbits);
11098 type = build_qualified_type (long_double_type_node,
11099 cp_type_quals (type));
11100 }
11101
11102
11103
11104 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
11105 || RIDBIT_SETP (RID_SIGNED, specbits)
11106 || RIDBIT_SETP (RID_LONG, specbits)
11107 || RIDBIT_SETP (RID_SHORT, specbits))
11108 {
11109 int ok = 0;
11110
11111 if (TREE_CODE (type) == REAL_TYPE)
11112 error ("short, signed or unsigned invalid for `%s'", name);
11113 else if (TREE_CODE (type) != INTEGER_TYPE)
11114 error ("long, short, signed or unsigned invalid for `%s'", name);
11115 else if (RIDBIT_SETP (RID_LONG, specbits)
11116 && RIDBIT_SETP (RID_SHORT, specbits))
11117 error ("long and short specified together for `%s'", name);
11118 else if ((RIDBIT_SETP (RID_LONG, specbits)
11119 || RIDBIT_SETP (RID_SHORT, specbits))
11120 && explicit_char)
11121 error ("long or short specified with char for `%s'", name);
11122 else if ((RIDBIT_SETP (RID_LONG, specbits)
11123 || RIDBIT_SETP (RID_SHORT, specbits))
11124 && TREE_CODE (type) == REAL_TYPE)
11125 error ("long or short specified with floating type for `%s'", name);
11126 else if (RIDBIT_SETP (RID_SIGNED, specbits)
11127 && RIDBIT_SETP (RID_UNSIGNED, specbits))
11128 error ("signed and unsigned given together for `%s'", name);
11129 else
11130 {
11131 ok = 1;
11132 if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
11133 {
11134 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
11135 name);
11136 if (flag_pedantic_errors)
11137 ok = 0;
11138 }
11139 }
11140
11141
11142 if (! ok)
11143 {
11144 RIDBIT_RESET (RID_UNSIGNED, specbits);
11145 RIDBIT_RESET (RID_SIGNED, specbits);
11146 RIDBIT_RESET (RID_LONG, specbits);
11147 RIDBIT_RESET (RID_SHORT, specbits);
11148 longlong = 0;
11149 }
11150 }
11151
11152 if (RIDBIT_SETP (RID_COMPLEX, specbits)
11153 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
11154 {
11155 error ("complex invalid for `%s'", name);
11156 RIDBIT_RESET (RID_COMPLEX, specbits);
11157 }
11158
11159
11160
11161 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
11162
11163
11164
11165
11166
11167
11168
11169
11170 || (bitfield && !flag_signed_bitfields
11171 && RIDBIT_NOTSETP (RID_SIGNED, specbits)
11172
11173
11174
11175 && !(typedef_decl
11176 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
11177 && (TREE_CODE (type) == INTEGER_TYPE
11178 || TREE_CODE (type) == CHAR_TYPE)
11179 && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
11180 {
11181 if (longlong)
11182 type = long_long_unsigned_type_node;
11183 else if (RIDBIT_SETP (RID_LONG, specbits))
11184 type = long_unsigned_type_node;
11185 else if (RIDBIT_SETP (RID_SHORT, specbits))
11186 type = short_unsigned_type_node;
11187 else if (type == char_type_node)
11188 type = unsigned_char_type_node;
11189 else if (typedef_decl)
11190 type = c_common_unsigned_type (type);
11191 else
11192 type = unsigned_type_node;
11193 }
11194 else if (RIDBIT_SETP (RID_SIGNED, specbits)
11195 && type == char_type_node)
11196 type = signed_char_type_node;
11197 else if (longlong)
11198 type = long_long_integer_type_node;
11199 else if (RIDBIT_SETP (RID_LONG, specbits))
11200 type = long_integer_type_node;
11201 else if (RIDBIT_SETP (RID_SHORT, specbits))
11202 type = short_integer_type_node;
11203
11204 if (RIDBIT_SETP (RID_COMPLEX, specbits))
11205 {
11206
11207
11208
11209
11210
11211 if (defaulted_int && ! longlong
11212 && ! (RIDBIT_SETP (RID_LONG, specbits)
11213 || RIDBIT_SETP (RID_SHORT, specbits)
11214 || RIDBIT_SETP (RID_SIGNED, specbits)
11215 || RIDBIT_SETP (RID_UNSIGNED, specbits)))
11216 type = complex_double_type_node;
11217 else if (type == integer_type_node)
11218 type = complex_integer_type_node;
11219 else if (type == float_type_node)
11220 type = complex_float_type_node;
11221 else if (type == double_type_node)
11222 type = complex_double_type_node;
11223 else if (type == long_double_type_node)
11224 type = complex_long_double_type_node;
11225 else
11226 type = build_complex_type (type);
11227 }
11228
11229 type_quals = TYPE_UNQUALIFIED;
11230 if (RIDBIT_SETP (RID_CONST, specbits))
11231 type_quals |= TYPE_QUAL_CONST;
11232 if (RIDBIT_SETP (RID_VOLATILE, specbits))
11233 type_quals |= TYPE_QUAL_VOLATILE;
11234 if (RIDBIT_SETP (RID_RESTRICT, specbits))
11235 type_quals |= TYPE_QUAL_RESTRICT;
11236 if (sfk == sfk_conversion && type_quals != TYPE_UNQUALIFIED)
11237 error ("qualifiers are not allowed on declaration of `operator %T'",
11238 ctor_return_type);
11239
11240 type_quals |= cp_type_quals (type);
11241 type = cp_build_qualified_type_real
11242 (type, type_quals, ((typedef_decl && !DECL_ARTIFICIAL (typedef_decl)
11243 ? tf_ignore_bad_quals : 0) | tf_error | tf_warning));
11244
11245 type_quals = cp_type_quals (type);
11246
11247 staticp = 0;
11248 inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
11249 virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
11250 RIDBIT_RESET (RID_VIRTUAL, specbits);
11251 explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0;
11252 RIDBIT_RESET (RID_EXPLICIT, specbits);
11253
11254 if (RIDBIT_SETP (RID_STATIC, specbits))
11255 staticp = 1 + (decl_context == FIELD);
11256
11257 if (virtualp && staticp == 2)
11258 {
11259 error ("member `%D' cannot be declared both virtual and static",
11260 dname);
11261 staticp = 0;
11262 }
11263 friendp = RIDBIT_SETP (RID_FRIEND, specbits);
11264 RIDBIT_RESET (RID_FRIEND, specbits);
11265
11266 if (dependant_name && !friendp)
11267 {
11268 error ("`%T::%D' is not a valid declarator", ctype, dependant_name);
11269 return void_type_node;
11270 }
11271
11272
11273
11274 if (RIDBIT_ANY_SET (specbits))
11275 {
11276 if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
11277 if (RIDBIT_SETP (RID_EXTERN, specbits) && !extern_langp) nclasses++;
11278 if (RIDBIT_SETP (RID_THREAD, specbits)) nclasses++;
11279 if (decl_context == PARM && nclasses > 0)
11280 error ("storage class specifiers invalid in parameter declarations");
11281 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
11282 {
11283 if (decl_context == PARM)
11284 error ("typedef declaration invalid in parameter declaration");
11285 nclasses++;
11286 }
11287 if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
11288 if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
11289 if (!nclasses && !friendp && extern_langp)
11290 nclasses++;
11291 }
11292
11293
11294 if (virtualp
11295 && (current_class_name == NULL_TREE || decl_context != FIELD))
11296 {
11297 error ("virtual outside class declaration");
11298 virtualp = 0;
11299 }
11300
11301
11302 if (staticp && decl_context == TYPENAME
11303 && TREE_CODE (declspecs) == TREE_LIST
11304 && ANON_AGGR_TYPE_P (TREE_VALUE (declspecs)))
11305 decl_context = FIELD;
11306
11307
11308
11309
11310
11311 if (nclasses == 2
11312 && RIDBIT_SETP (RID_THREAD, specbits)
11313 && (RIDBIT_SETP (RID_EXTERN, specbits)
11314 || RIDBIT_SETP (RID_STATIC, specbits)))
11315 nclasses = 1;
11316
11317 if (nclasses > 1)
11318 error ("multiple storage classes in declaration of `%s'", name);
11319 else if (decl_context != NORMAL && nclasses > 0)
11320 {
11321 if ((decl_context == PARM || decl_context == CATCHPARM)
11322 && (RIDBIT_SETP (RID_REGISTER, specbits)
11323 || RIDBIT_SETP (RID_AUTO, specbits)))
11324 ;
11325 else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
11326 ;
11327 else if (decl_context == FIELD
11328
11329 && RIDBIT_SETP (RID_STATIC, specbits))
11330
11331
11332 ;
11333 else
11334 {
11335 if (decl_context == FIELD)
11336 {
11337 tree tmp = NULL_TREE;
11338 register int op = 0;
11339
11340 if (declarator)
11341 {
11342
11343 if (TREE_CODE (declarator) == IDENTIFIER_NODE)
11344 tmp = declarator;
11345 else
11346 tmp = TREE_OPERAND (declarator, 0);
11347 op = IDENTIFIER_OPNAME_P (tmp);
11348 if (IDENTIFIER_TYPENAME_P (tmp))
11349 {
11350 if (IDENTIFIER_GLOBAL_VALUE (tmp)
11351 && (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (tmp))
11352 == TYPE_DECL))
11353 name = IDENTIFIER_POINTER (tmp);
11354 else
11355 name = "<invalid operator>";
11356 }
11357 }
11358 error ("storage class specified for %s `%s'",
11359 op ? "member operator" : "field",
11360 name);
11361 }
11362 else
11363 {
11364 if (decl_context == PARM || decl_context == CATCHPARM)
11365 error ("storage class specified for parameter `%s'", name);
11366 else
11367 error ("storage class specified for typename");
11368 }
11369 RIDBIT_RESET (RID_REGISTER, specbits);
11370 RIDBIT_RESET (RID_AUTO, specbits);
11371 RIDBIT_RESET (RID_EXTERN, specbits);
11372 RIDBIT_RESET (RID_THREAD, specbits);
11373 }
11374 }
11375 else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
11376 {
11377 if (toplevel_bindings_p ())
11378 {
11379
11380
11381 if (!(type_quals & TYPE_QUAL_CONST))
11382 warning ("`%s' initialized and declared `extern'", name);
11383 }
11384 else
11385 error ("`%s' has both `extern' and initializer", name);
11386 }
11387 else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
11388 && ! toplevel_bindings_p ())
11389 error ("nested function `%s' declared `extern'", name);
11390 else if (toplevel_bindings_p ())
11391 {
11392 if (RIDBIT_SETP (RID_AUTO, specbits))
11393 error ("top-level declaration of `%s' specifies `auto'", name);
11394 }
11395 else if (RIDBIT_SETP (RID_THREAD, specbits)
11396 && !RIDBIT_SETP (RID_EXTERN, specbits)
11397 && !RIDBIT_SETP (RID_STATIC, specbits))
11398 {
11399 error ("function-scope `%s' implicitly auto and declared `__thread'",
11400 name);
11401 RIDBIT_RESET (RID_THREAD, specbits);
11402 }
11403
11404 if (nclasses > 0 && friendp)
11405 error ("storage class specifiers invalid in friend function declarations");
11406
11407
11408
11409
11410
11411 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE
11412 && TREE_CODE (declarator) != TEMPLATE_ID_EXPR)
11413 {
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435 if (type == error_mark_node)
11436 {
11437 if (TREE_CODE (declarator) == SCOPE_REF)
11438 declarator = TREE_OPERAND (declarator, 1);
11439 else
11440 declarator = TREE_OPERAND (declarator, 0);
11441 continue;
11442 }
11443 if (quals != NULL_TREE
11444 && (declarator == NULL_TREE
11445 || TREE_CODE (declarator) != SCOPE_REF))
11446 {
11447 if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
11448 ctype = TYPE_METHOD_BASETYPE (type);
11449 if (ctype != NULL_TREE)
11450 {
11451 tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
11452 grok_method_quals (ctype, dummy, quals);
11453 type = TREE_TYPE (dummy);
11454 ctype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type)));
11455 quals = NULL_TREE;
11456 }
11457 }
11458
11459 switch (TREE_CODE (declarator))
11460 {
11461 case TREE_LIST:
11462 {
11463
11464
11465 tree attrs = TREE_PURPOSE (declarator);
11466 tree inner_decl;
11467 int attr_flags;
11468
11469 declarator = TREE_VALUE (declarator);
11470 inner_decl = declarator;
11471 while (inner_decl != NULL_TREE
11472 && TREE_CODE (inner_decl) == TREE_LIST)
11473 inner_decl = TREE_VALUE (inner_decl);
11474 attr_flags = 0;
11475 if (inner_decl == NULL_TREE
11476 || TREE_CODE (inner_decl) == IDENTIFIER_NODE)
11477 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
11478 if (TREE_CODE (inner_decl) == CALL_EXPR)
11479 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
11480 if (TREE_CODE (inner_decl) == ARRAY_REF)
11481 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
11482 returned_attrs = decl_attributes (&type,
11483 chainon (returned_attrs, attrs),
11484 attr_flags);
11485 }
11486 break;
11487
11488 case ARRAY_REF:
11489 {
11490 register tree size;
11491
11492 size = TREE_OPERAND (declarator, 1);
11493
11494
11495 if (size == NULL_TREE && decl_context == FIELD && ! staticp
11496 && ! RIDBIT_SETP (RID_TYPEDEF, specbits))
11497 size = integer_zero_node;
11498
11499 declarator = TREE_OPERAND (declarator, 0);
11500
11501 type = create_array_type_for_decl (dname, type, size);
11502
11503 ctype = NULL_TREE;
11504 }
11505 break;
11506
11507 case CALL_EXPR:
11508 {
11509 tree arg_types;
11510 int funcdecl_p;
11511 tree inner_parms = CALL_DECLARATOR_PARMS (declarator);
11512 tree inner_decl = TREE_OPERAND (declarator, 0);
11513
11514
11515
11516
11517
11518
11519 type_quals = TYPE_UNQUALIFIED;
11520
11521
11522
11523 if (TREE_CODE (type) == FUNCTION_TYPE)
11524 {
11525 error ("`%s' declared as function returning a function", name);
11526 type = integer_type_node;
11527 }
11528 if (TREE_CODE (type) == ARRAY_TYPE)
11529 {
11530 error ("`%s' declared as function returning an array", name);
11531 type = integer_type_node;
11532 }
11533
11534 if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
11535 inner_decl = TREE_OPERAND (inner_decl, 1);
11536
11537 if (inner_decl && TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR)
11538 inner_decl = dname;
11539
11540
11541 quals = CALL_DECLARATOR_QUALS (declarator);
11542
11543
11544 raises = CALL_DECLARATOR_EXCEPTION_SPEC (declarator);
11545
11546
11547
11548 funcdecl_p
11549 = inner_decl
11550 && (TREE_CODE (inner_decl) == IDENTIFIER_NODE
11551 || TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR
11552 || TREE_CODE (inner_decl) == BIT_NOT_EXPR);
11553
11554 if (ctype == NULL_TREE
11555 && decl_context == FIELD
11556 && funcdecl_p
11557 && (friendp == 0 || dname == current_class_name))
11558 ctype = current_class_type;
11559
11560 if (ctype && sfk == sfk_conversion)
11561 TYPE_HAS_CONVERSION (ctype) = 1;
11562 if (ctype && constructor_name (ctype) == dname)
11563 {
11564
11565
11566
11567
11568
11569 if (flags == DTOR_FLAG)
11570 {
11571
11572
11573
11574 if (staticp == 2)
11575 error ("destructor cannot be static member function");
11576 if (quals)
11577 {
11578 error ("destructors may not be `%s'",
11579 IDENTIFIER_POINTER (TREE_VALUE (quals)));
11580 quals = NULL_TREE;
11581 }
11582 if (decl_context == FIELD)
11583 {
11584 if (! member_function_or_else (ctype,
11585 current_class_type,
11586 flags))
11587 return void_type_node;
11588 }
11589 }
11590 else
11591 {
11592 if (explicitp == 1)
11593 explicitp = 2;
11594
11595
11596
11597
11598 if (staticp == 2)
11599 error ("constructor cannot be static member function");
11600 if (virtualp)
11601 {
11602 pedwarn ("constructors cannot be declared virtual");
11603 virtualp = 0;
11604 }
11605 if (quals)
11606 {
11607 error ("constructors may not be `%s'",
11608 IDENTIFIER_POINTER (TREE_VALUE (quals)));
11609 quals = NULL_TREE;
11610 }
11611 {
11612 RID_BIT_TYPE tmp_bits;
11613 memcpy (&tmp_bits, &specbits, sizeof (RID_BIT_TYPE));
11614 RIDBIT_RESET (RID_INLINE, tmp_bits);
11615 RIDBIT_RESET (RID_STATIC, tmp_bits);
11616 if (RIDBIT_ANY_SET (tmp_bits))
11617 error ("return value type specifier for constructor ignored");
11618 }
11619 if (decl_context == FIELD)
11620 {
11621 if (! member_function_or_else (ctype,
11622 current_class_type,
11623 flags))
11624 return void_type_node;
11625 TYPE_HAS_CONSTRUCTOR (ctype) = 1;
11626 if (sfk != sfk_constructor)
11627 return NULL_TREE;
11628 }
11629 }
11630 if (decl_context == FIELD)
11631 staticp = 0;
11632 }
11633 else if (friendp)
11634 {
11635 if (initialized)
11636 error ("can't initialize friend function `%s'", name);
11637 if (virtualp)
11638 {
11639
11640 error ("virtual functions cannot be friends");
11641 RIDBIT_RESET (RID_FRIEND, specbits);
11642 friendp = 0;
11643 }
11644 if (decl_context == NORMAL)
11645 error ("friend declaration not in class definition");
11646 if (current_function_decl && funcdef_flag)
11647 error ("can't define friend function `%s' in a local class definition",
11648 name);
11649 }
11650
11651
11652
11653
11654 declarator = TREE_OPERAND (declarator, 0);
11655
11656
11657
11658
11659 arg_types = grokparms (inner_parms);
11660
11661 if (declarator && flags == DTOR_FLAG)
11662 {
11663
11664
11665
11666 if (TREE_CODE (declarator) == BIT_NOT_EXPR)
11667 declarator = TREE_OPERAND (declarator, 0);
11668
11669 if (arg_types != void_list_node)
11670 {
11671 error ("destructors may not have parameters");
11672 arg_types = void_list_node;
11673 last_function_parms = NULL_TREE;
11674 }
11675 }
11676
11677
11678
11679 type = build_function_type (type, arg_types);
11680
11681 {
11682 tree t;
11683 for (t = arg_types; t; t = TREE_CHAIN (t))
11684 if (TREE_PURPOSE (t)
11685 && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG)
11686 {
11687 add_defarg_fn (type);
11688 break;
11689 }
11690 }
11691 }
11692 break;
11693
11694 case ADDR_EXPR:
11695 case INDIRECT_REF:
11696
11697
11698
11699 if (TREE_CODE (type) == REFERENCE_TYPE)
11700 {
11701 error (TREE_CODE (declarator) == ADDR_EXPR
11702 ? "cannot declare reference to `%#T'"
11703 : "cannot declare pointer to `%#T'", type);
11704 type = TREE_TYPE (type);
11705 }
11706 else if (VOID_TYPE_P (type)
11707 && (ctype || TREE_CODE (declarator) == ADDR_EXPR))
11708 error (ctype ? "cannot declare pointer to `%#T' member"
11709 : "cannot declare reference to `%#T'", type);
11710
11711
11712
11713
11714
11715
11716 type_quals = TYPE_UNQUALIFIED;
11717
11718 if (TREE_CODE (declarator) == ADDR_EXPR)
11719 {
11720 if (!VOID_TYPE_P (type))
11721 type = build_reference_type (type);
11722 }
11723 else if (TREE_CODE (type) == METHOD_TYPE)
11724 type = build_ptrmemfunc_type (build_pointer_type (type));
11725 else if (ctype)
11726 type = build_ptrmem_type (ctype, type);
11727 else
11728 type = build_pointer_type (type);
11729
11730
11731
11732
11733 if (TREE_TYPE (declarator))
11734 {
11735 register tree typemodlist;
11736 int erred = 0;
11737 int constp = 0;
11738 int volatilep = 0;
11739 int restrictp = 0;
11740
11741 for (typemodlist = TREE_TYPE (declarator); typemodlist;
11742 typemodlist = TREE_CHAIN (typemodlist))
11743 {
11744 tree qualifier = TREE_VALUE (typemodlist);
11745
11746 if (qualifier == ridpointers[(int) RID_CONST])
11747 {
11748 constp++;
11749 type_quals |= TYPE_QUAL_CONST;
11750 }
11751 else if (qualifier == ridpointers[(int) RID_VOLATILE])
11752 {
11753 volatilep++;
11754 type_quals |= TYPE_QUAL_VOLATILE;
11755 }
11756 else if (qualifier == ridpointers[(int) RID_RESTRICT])
11757 {
11758 restrictp++;
11759 type_quals |= TYPE_QUAL_RESTRICT;
11760 }
11761 else if (!erred)
11762 {
11763 erred = 1;
11764 error ("invalid type modifier within pointer declarator");
11765 }
11766 }
11767 if (constp > 1)
11768 pedwarn ("duplicate `const'");
11769 if (volatilep > 1)
11770 pedwarn ("duplicate `volatile'");
11771 if (restrictp > 1)
11772 pedwarn ("duplicate `restrict'");
11773 type = cp_build_qualified_type (type, type_quals);
11774 type_quals = cp_type_quals (type);
11775 }
11776 declarator = TREE_OPERAND (declarator, 0);
11777 ctype = NULL_TREE;
11778 break;
11779
11780 case SCOPE_REF:
11781 {
11782
11783
11784
11785
11786
11787
11788 tree sname = TREE_OPERAND (declarator, 1);
11789 tree t;
11790
11791
11792 if (TREE_CODE (sname) == BIT_NOT_EXPR)
11793 sname = TREE_OPERAND (sname, 0);
11794
11795 if (TREE_COMPLEXITY (declarator) == 0)
11796
11797 ;
11798 else if (TREE_COMPLEXITY (declarator) == -1)
11799
11800 pop_decl_namespace ();
11801 else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
11802 ;
11803 else if (!TREE_OPERAND (declarator, 0)
11804 || !IS_AGGR_TYPE_CODE
11805 (TREE_CODE (TREE_OPERAND (declarator, 0))))
11806 ;
11807 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
11808 {
11809
11810
11811
11812
11813
11814 if (current_template_parms
11815 && uses_template_parms (type)
11816 && uses_template_parms (current_class_type))
11817 {
11818 tree args = current_template_args ();
11819 type = tsubst (type, args, tf_error | tf_warning,
11820 NULL_TREE);
11821 }
11822
11823
11824
11825
11826
11827 pop_nested_class ();
11828 TREE_COMPLEXITY (declarator) = current_class_depth;
11829 }
11830 else
11831 abort ();
11832
11833 if (TREE_OPERAND (declarator, 0) == NULL_TREE)
11834 {
11835
11836
11837
11838
11839 declarator = sname;
11840 continue;
11841 }
11842 ctype = TREE_OPERAND (declarator, 0);
11843
11844 t = ctype;
11845 while (t != NULL_TREE && CLASS_TYPE_P (t))
11846 {
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857 if (CLASSTYPE_TEMPLATE_INFO (t)
11858 && (CLASSTYPE_TEMPLATE_INSTANTIATION (t)
11859 || uses_template_parms (CLASSTYPE_TI_ARGS (t)))
11860 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))
11861 template_count += 1;
11862
11863 t = TYPE_MAIN_DECL (t);
11864 t = DECL_CONTEXT (t);
11865 }
11866
11867 if (sname == NULL_TREE)
11868 goto done_scoping;
11869
11870 if (TREE_CODE (sname) == IDENTIFIER_NODE)
11871 {
11872
11873
11874
11875 if (ctype == current_class_type)
11876 {
11877
11878
11879
11880
11881
11882
11883 if (pedantic)
11884 pedwarn ("extra qualification `%T::' on member `%s' ignored",
11885 ctype, name);
11886 }
11887 else if (TREE_CODE (type) == FUNCTION_TYPE)
11888 {
11889 if (current_class_type == NULL_TREE || friendp)
11890 type = build_cplus_method_type (ctype, TREE_TYPE (type),
11891 TYPE_ARG_TYPES (type));
11892 else
11893 {
11894 error ("cannot declare member function `%T::%s' within `%T'",
11895 ctype, name, current_class_type);
11896 return void_type_node;
11897 }
11898 }
11899 else if (RIDBIT_SETP (RID_TYPEDEF, specbits)
11900 || COMPLETE_TYPE_P (complete_type (ctype)))
11901 {
11902
11903
11904
11905
11906
11907 if (current_class_type)
11908 {
11909 error ("cannot declare member `%T::%s' within `%T'",
11910 ctype, name, current_class_type);
11911 return void_type_node;
11912 }
11913 }
11914 else
11915 {
11916 cxx_incomplete_type_error (NULL_TREE, ctype);
11917 return error_mark_node;
11918 }
11919
11920 declarator = sname;
11921 }
11922 else if (TREE_CODE (sname) == SCOPE_REF)
11923 abort ();
11924 else
11925 {
11926 done_scoping:
11927 declarator = TREE_OPERAND (declarator, 1);
11928 if (declarator && TREE_CODE (declarator) == CALL_EXPR)
11929
11930 ;
11931 else if (TREE_CODE (type) == FUNCTION_TYPE)
11932 type = build_cplus_method_type (ctype, TREE_TYPE (type),
11933 TYPE_ARG_TYPES (type));
11934 }
11935 }
11936 break;
11937
11938 case BIT_NOT_EXPR:
11939 declarator = TREE_OPERAND (declarator, 0);
11940 break;
11941
11942 case BASELINK:
11943 declarator = BASELINK_FUNCTIONS (declarator);
11944 break;
11945
11946 case RECORD_TYPE:
11947 case UNION_TYPE:
11948 case ENUMERAL_TYPE:
11949 declarator = NULL_TREE;
11950 break;
11951
11952 case ERROR_MARK:
11953 declarator = NULL_TREE;
11954 break;
11955
11956 default:
11957 abort ();
11958 }
11959 }
11960
11961 if (returned_attrs)
11962 {
11963 if (attrlist)
11964 *attrlist = chainon (returned_attrs, *attrlist);
11965 else
11966 attrlist = &returned_attrs;
11967 }
11968
11969
11970
11971
11972
11973 if (TREE_CODE (type) == ARRAY_TYPE
11974 && COMPLETE_TYPE_P (type)
11975 && TREE_OVERFLOW (TYPE_SIZE (type)))
11976 {
11977 error ("size of array `%s' is too large", name);
11978
11979
11980 type = error_mark_node;
11981 }
11982
11983 if ((decl_context == FIELD || decl_context == PARM)
11984 && !processing_template_decl
11985 && variably_modified_type_p (type))
11986 {
11987 if (decl_context == FIELD)
11988 error ("data member may not have variably modified type `%T'", type);
11989 else
11990 error ("parameter may not have variably modified type `%T'", type);
11991 type = error_mark_node;
11992 }
11993
11994 if (explicitp == 1 || (explicitp && friendp))
11995 {
11996
11997
11998 error ("only declarations of constructors can be `explicit'");
11999 explicitp = 0;
12000 }
12001
12002 if (RIDBIT_SETP (RID_MUTABLE, specbits))
12003 {
12004 if (decl_context != FIELD || friendp)
12005 {
12006 error ("non-member `%s' cannot be declared `mutable'", name);
12007 RIDBIT_RESET (RID_MUTABLE, specbits);
12008 }
12009 else if (decl_context == TYPENAME || RIDBIT_SETP (RID_TYPEDEF, specbits))
12010 {
12011 error ("non-object member `%s' cannot be declared `mutable'", name);
12012 RIDBIT_RESET (RID_MUTABLE, specbits);
12013 }
12014 else if (TREE_CODE (type) == FUNCTION_TYPE
12015 || TREE_CODE (type) == METHOD_TYPE)
12016 {
12017 error ("function `%s' cannot be declared `mutable'", name);
12018 RIDBIT_RESET (RID_MUTABLE, specbits);
12019 }
12020 else if (staticp)
12021 {
12022 error ("static `%s' cannot be declared `mutable'", name);
12023 RIDBIT_RESET (RID_MUTABLE, specbits);
12024 }
12025 else if (type_quals & TYPE_QUAL_CONST)
12026 {
12027 error ("const `%s' cannot be declared `mutable'", name);
12028 RIDBIT_RESET (RID_MUTABLE, specbits);
12029 }
12030 }
12031
12032 if (declarator == NULL_TREE
12033 || TREE_CODE (declarator) == IDENTIFIER_NODE
12034 || (TREE_CODE (declarator) == TEMPLATE_ID_EXPR
12035 && (TREE_CODE (type) == FUNCTION_TYPE
12036 || TREE_CODE (type) == METHOD_TYPE)))
12037 ;
12038 else if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR)
12039 {
12040 error ("template-id `%D' used as a declarator", declarator);
12041 declarator = dname;
12042 }
12043 else
12044
12045 abort ();
12046
12047
12048
12049 if (RIDBIT_SETP (RID_TYPEDEF, specbits) && decl_context != TYPENAME)
12050 {
12051 tree decl;
12052
12053
12054
12055 if (current_lang_name == lang_name_java)
12056 TYPE_FOR_JAVA (type) = 1;
12057
12058 if (decl_context == FIELD)
12059 {
12060 if (declarator == constructor_name (current_class_type))
12061 pedwarn ("ISO C++ forbids nested type `%D' with same name as enclosing class",
12062 declarator);
12063 decl = build_lang_decl (TYPE_DECL, declarator, type);
12064 }
12065 else
12066 {
12067 decl = build_decl (TYPE_DECL, declarator, type);
12068 if (!current_function_decl)
12069 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
12070 }
12071
12072
12073
12074
12075
12076 if (type != error_mark_node
12077 && declarator
12078 && TYPE_NAME (type)
12079 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12080 && TYPE_ANONYMOUS_P (type)
12081
12082 && (!attrlist || !*attrlist)
12083 && cp_type_quals (type) == TYPE_UNQUALIFIED)
12084 {
12085 tree oldname = TYPE_NAME (type);
12086 tree t;
12087
12088
12089 lookup_tag_reverse (type, declarator);
12090 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
12091 if (TYPE_NAME (t) == oldname)
12092 TYPE_NAME (t) = decl;
12093
12094 if (TYPE_LANG_SPECIFIC (type))
12095 TYPE_WAS_ANONYMOUS (type) = 1;
12096
12097
12098
12099
12100 if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
12101 DECL_NAME (CLASSTYPE_TI_TEMPLATE (type))
12102 = TYPE_IDENTIFIER (type);
12103
12104
12105
12106 }
12107
12108 if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
12109 {
12110 cp_error_at ("typedef name may not be class-qualified", decl);
12111 return NULL_TREE;
12112 }
12113 else if (quals)
12114 {
12115 if (ctype == NULL_TREE)
12116 {
12117 if (TREE_CODE (type) != METHOD_TYPE)
12118 cp_error_at ("invalid type qualifier for non-member function type", decl);
12119 else
12120 ctype = TYPE_METHOD_BASETYPE (type);
12121 }
12122 if (ctype != NULL_TREE)
12123 grok_method_quals (ctype, decl, quals);
12124 }
12125
12126 if (RIDBIT_SETP (RID_SIGNED, specbits)
12127 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
12128 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
12129
12130 bad_specifiers (decl, "type", virtualp, quals != NULL_TREE,
12131 inlinep, friendp, raises != NULL_TREE);
12132
12133 return decl;
12134 }
12135
12136
12137
12138
12139
12140
12141 if (type && typedef_type
12142 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
12143 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
12144 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
12145
12146
12147
12148
12149
12150 if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
12151 {
12152 tree decls = NULL_TREE;
12153 tree args;
12154
12155 for (args = TYPE_ARG_TYPES (type); args; args = TREE_CHAIN (args))
12156 {
12157 tree decl = cp_build_parm_decl (NULL_TREE, TREE_VALUE (args));
12158
12159 TREE_CHAIN (decl) = decls;
12160 decls = decl;
12161 }
12162
12163 last_function_parms = nreverse (decls);
12164 }
12165
12166
12167
12168
12169 if (decl_context == TYPENAME)
12170 {
12171
12172
12173 if (type_quals != TYPE_UNQUALIFIED)
12174 type_quals = TYPE_UNQUALIFIED;
12175
12176
12177 if (friendp)
12178 {
12179 if (type_quals != TYPE_UNQUALIFIED)
12180 {
12181 error ("type qualifiers specified for friend class declaration");
12182 type_quals = TYPE_UNQUALIFIED;
12183 }
12184 if (inlinep)
12185 {
12186 error ("`inline' specified for friend class declaration");
12187 inlinep = 0;
12188 }
12189
12190 if (!current_aggr)
12191 {
12192
12193 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
12194 pedwarn ("template parameters cannot be friends");
12195 else if (TREE_CODE (type) == TYPENAME_TYPE)
12196 pedwarn ("friend declaration requires class-key, "
12197 "i.e. `friend class %T::%D'",
12198 TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
12199 else
12200 pedwarn ("friend declaration requires class-key, "
12201 "i.e. `friend %#T'",
12202 type);
12203 }
12204
12205
12206 if (type != integer_type_node)
12207 {
12208 decl_type_access_control (TYPE_NAME (type));
12209
12210
12211 if (current_class_type)
12212 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
12213 else
12214 error ("trying to make class `%T' a friend of global scope",
12215 type);
12216
12217 type = void_type_node;
12218 }
12219 }
12220 else if (quals)
12221 {
12222 if (ctype == NULL_TREE)
12223 {
12224 if (TREE_CODE (type) != METHOD_TYPE)
12225 error ("invalid qualifiers on non-member function type");
12226 else
12227 ctype = TYPE_METHOD_BASETYPE (type);
12228 }
12229 if (ctype)
12230 {
12231 tree dummy = build_decl (TYPE_DECL, declarator, type);
12232 grok_method_quals (ctype, dummy, quals);
12233 type = TREE_TYPE (dummy);
12234 }
12235 }
12236
12237 return type;
12238 }
12239 else if (declarator == NULL_TREE && decl_context != PARM
12240 && decl_context != CATCHPARM
12241 && TREE_CODE (type) != UNION_TYPE
12242 && ! bitfield)
12243 {
12244 error ("abstract declarator `%T' used as declaration", type);
12245 declarator = make_anon_name ();
12246 }
12247
12248
12249
12250
12251
12252
12253 if (TREE_CODE (type) == VOID_TYPE && decl_context != PARM)
12254 {
12255 if (! declarator)
12256 error ("unnamed variable or field declared void");
12257 else if (TREE_CODE (declarator) == IDENTIFIER_NODE)
12258 {
12259 if (IDENTIFIER_OPNAME_P (declarator))
12260 abort ();
12261 else
12262 error ("variable or field `%s' declared void", name);
12263 }
12264 else
12265 error ("variable or field declared void");
12266 type = integer_type_node;
12267 }
12268
12269
12270
12271
12272 if (decl_context == PARM || decl_context == CATCHPARM)
12273 {
12274 if (ctype || in_namespace)
12275 error ("cannot use `::' in parameter declaration");
12276
12277
12278
12279
12280
12281 if (TREE_CODE (type) == ARRAY_TYPE)
12282 {
12283
12284 type = build_pointer_type (TREE_TYPE (type));
12285 type_quals = TYPE_UNQUALIFIED;
12286 }
12287 else if (TREE_CODE (type) == FUNCTION_TYPE)
12288 type = build_pointer_type (type);
12289 else if (TREE_CODE (type) == OFFSET_TYPE)
12290 type = build_pointer_type (type);
12291 }
12292
12293 {
12294 register tree decl;
12295
12296 if (decl_context == PARM)
12297 {
12298 decl = cp_build_parm_decl (declarator, type);
12299
12300 bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
12301 inlinep, friendp, raises != NULL_TREE);
12302 }
12303 else if (decl_context == FIELD)
12304 {
12305 if (type == error_mark_node)
12306 {
12307
12308
12309 decl = NULL_TREE;
12310 }
12311 else if (in_namespace && !friendp)
12312 {
12313
12314 error ("invalid use of `::'");
12315 decl = NULL_TREE;
12316 }
12317 else if (TREE_CODE (type) == FUNCTION_TYPE)
12318 {
12319 int publicp = 0;
12320 tree function_context;
12321
12322
12323
12324 if (friendp && declarator == ridpointers[(int) RID_SIGNED])
12325 {
12326 error ("function `%D' cannot be declared friend",
12327 declarator);
12328 friendp = 0;
12329 }
12330
12331 if (friendp == 0)
12332 {
12333 if (ctype == NULL_TREE)
12334 ctype = current_class_type;
12335
12336 if (ctype == NULL_TREE)
12337 {
12338 error ("can't make `%D' into a method -- not in a class",
12339 declarator);
12340 return void_type_node;
12341 }
12342
12343
12344
12345 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
12346 {
12347 error ("function `%D' declared virtual inside a union",
12348 declarator);
12349 return void_type_node;
12350 }
12351
12352 if (declarator == ansi_opname (NEW_EXPR)
12353 || declarator == ansi_opname (VEC_NEW_EXPR)
12354 || declarator == ansi_opname (DELETE_EXPR)
12355 || declarator == ansi_opname (VEC_DELETE_EXPR))
12356 {
12357 if (virtualp)
12358 {
12359 error ("`%D' cannot be declared virtual, since it is always static",
12360 declarator);
12361 virtualp = 0;
12362 }
12363 }
12364 else if (staticp < 2)
12365 type = build_cplus_method_type (ctype, TREE_TYPE (type),
12366 TYPE_ARG_TYPES (type));
12367 }
12368
12369
12370 function_context = (ctype != NULL_TREE) ?
12371 decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE;
12372 publicp = (! friendp || ! staticp)
12373 && function_context == NULL_TREE;
12374 decl = grokfndecl (ctype, type,
12375 TREE_CODE (declarator) != TEMPLATE_ID_EXPR
12376 ? declarator : dname,
12377 declarator,
12378 virtualp, flags, quals, raises,
12379 friendp ? -1 : 0, friendp, publicp, inlinep,
12380 funcdef_flag, template_count, in_namespace);
12381 if (decl == NULL_TREE)
12382 return decl;
12383 #if 0
12384
12385
12386 decl = build_decl_attribute_variant (decl, decl_attr);
12387 #endif
12388
12389
12390
12391
12392
12393
12394
12395
12396 if (explicitp == 2)
12397 DECL_NONCONVERTING_P (decl) = 1;
12398 else if (DECL_CONSTRUCTOR_P (decl))
12399 {
12400
12401
12402
12403
12404 tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (decl);
12405
12406 if (arg_types == void_list_node
12407 || (arg_types
12408 && TREE_CHAIN (arg_types)
12409 && TREE_CHAIN (arg_types) != void_list_node
12410 && !TREE_PURPOSE (TREE_CHAIN (arg_types))))
12411 DECL_NONCONVERTING_P (decl) = 1;
12412 }
12413 }
12414 else if (TREE_CODE (type) == METHOD_TYPE)
12415 {
12416
12417
12418
12419
12420 decl = grokfndecl (ctype, type, declarator, declarator,
12421 virtualp, flags, quals, raises,
12422 friendp ? -1 : 0, friendp, 1, 0, funcdef_flag,
12423 template_count, in_namespace);
12424 if (decl == NULL_TREE)
12425 return NULL_TREE;
12426 }
12427 else if (!staticp && ! processing_template_decl
12428 && !COMPLETE_TYPE_P (complete_type (type))
12429 && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
12430 {
12431 if (declarator)
12432 error ("field `%D' has incomplete type", declarator);
12433 else
12434 error ("name `%T' has incomplete type", type);
12435
12436
12437
12438 if (current_class_type
12439 && TYPE_NAME (current_class_type)
12440 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type))
12441 && declspecs && TREE_VALUE (declspecs)
12442 && TREE_TYPE (TREE_VALUE (declspecs)) == type)
12443 error (" in instantiation of template `%T'",
12444 current_class_type);
12445
12446 type = error_mark_node;
12447 decl = NULL_TREE;
12448 }
12449 else
12450 {
12451 if (friendp)
12452 {
12453 error ("`%s' is neither function nor member function; cannot be declared friend",
12454 IDENTIFIER_POINTER (declarator));
12455 friendp = 0;
12456 }
12457 decl = NULL_TREE;
12458 }
12459
12460 if (friendp)
12461 {
12462
12463 if (ctype == current_class_type)
12464 warning ("member functions are implicitly friends of their class");
12465 else
12466 {
12467 tree t = NULL_TREE;
12468 if (decl && DECL_NAME (decl))
12469 {
12470 if (template_class_depth (current_class_type) == 0)
12471 {
12472 decl
12473 = check_explicit_specialization
12474 (declarator, decl,
12475 template_count, 2 * (funcdef_flag != 0) + 4);
12476 if (decl == error_mark_node)
12477 return error_mark_node;
12478 }
12479
12480 t = do_friend (ctype, declarator, decl,
12481 last_function_parms, *attrlist,
12482 flags, quals, funcdef_flag);
12483 }
12484 if (t && funcdef_flag)
12485 return t;
12486
12487 return void_type_node;
12488 }
12489 }
12490
12491
12492
12493 if (decl == NULL_TREE)
12494 {
12495 if (initialized)
12496 {
12497 if (!staticp)
12498 {
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511 pedwarn ("ISO C++ forbids initialization of member `%D'",
12512 declarator);
12513 pedwarn ("making `%D' static", declarator);
12514 staticp = 1;
12515 }
12516
12517 if (uses_template_parms (type))
12518
12519 ;
12520 else if (check_static_variable_definition (declarator,
12521 type))
12522
12523
12524
12525
12526
12527 return void_type_node;
12528 }
12529
12530
12531 if (declarator == constructor_name (current_class_type)
12532
12533
12534
12535
12536 && staticp)
12537 pedwarn ("ISO C++ forbids static data member `%D' with same name as enclosing class",
12538 declarator);
12539
12540 if (staticp)
12541 {
12542
12543
12544 decl = build_lang_decl (VAR_DECL, declarator, type);
12545 TREE_STATIC (decl) = 1;
12546
12547 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = 1;
12548 }
12549 else
12550 {
12551 decl = build_decl (FIELD_DECL, declarator, type);
12552 DECL_NONADDRESSABLE_P (decl) = bitfield;
12553 if (RIDBIT_SETP (RID_MUTABLE, specbits))
12554 {
12555 DECL_MUTABLE_P (decl) = 1;
12556 RIDBIT_RESET (RID_MUTABLE, specbits);
12557 }
12558 }
12559
12560 bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
12561 inlinep, friendp, raises != NULL_TREE);
12562 }
12563 }
12564 else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
12565 {
12566 tree original_name;
12567 int publicp = 0;
12568
12569 if (! declarator)
12570 return NULL_TREE;
12571
12572 if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR)
12573 original_name = dname;
12574 else
12575 original_name = declarator;
12576
12577 if (RIDBIT_SETP (RID_AUTO, specbits))
12578 error ("storage class `auto' invalid for function `%s'", name);
12579 else if (RIDBIT_SETP (RID_REGISTER, specbits))
12580 error ("storage class `register' invalid for function `%s'", name);
12581 else if (RIDBIT_SETP (RID_THREAD, specbits))
12582 error ("storage class `__thread' invalid for function `%s'", name);
12583
12584
12585
12586
12587 if (! toplevel_bindings_p ()
12588 && (RIDBIT_SETP (RID_STATIC, specbits)
12589 || RIDBIT_SETP (RID_INLINE, specbits))
12590 && pedantic)
12591 {
12592 if (RIDBIT_SETP (RID_STATIC, specbits))
12593 pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
12594 else
12595 pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
12596 }
12597
12598 if (ctype == NULL_TREE)
12599 {
12600 if (virtualp)
12601 {
12602 error ("virtual non-class function `%s'", name);
12603 virtualp = 0;
12604 }
12605 }
12606 else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
12607 type = build_cplus_method_type (ctype, TREE_TYPE (type),
12608 TYPE_ARG_TYPES (type));
12609
12610
12611 publicp = (ctype != NULL_TREE
12612 || RIDBIT_SETP (RID_EXTERN, specbits)
12613 || !RIDBIT_SETP (RID_STATIC, specbits));
12614
12615 decl = grokfndecl (ctype, type, original_name, declarator,
12616 virtualp, flags, quals, raises,
12617 1, friendp,
12618 publicp, inlinep, funcdef_flag,
12619 template_count, in_namespace);
12620 if (decl == NULL_TREE)
12621 return NULL_TREE;
12622
12623 if (staticp == 1)
12624 {
12625 int invalid_static = 0;
12626
12627
12628
12629 if (TREE_CODE (type) == METHOD_TYPE)
12630 {
12631 pedwarn ("cannot declare member function `%D' to have static linkage", decl);
12632 invalid_static = 1;
12633 }
12634 else if (current_function_decl)
12635 {
12636
12637 error ("cannot declare static function inside another function");
12638 invalid_static = 1;
12639 }
12640
12641 if (invalid_static)
12642 {
12643 staticp = 0;
12644 RIDBIT_RESET (RID_STATIC, specbits);
12645 }
12646 }
12647 }
12648 else
12649 {
12650
12651
12652
12653 decl = grokvardecl (type, declarator, &specbits,
12654 initialized,
12655 (type_quals & TYPE_QUAL_CONST) != 0,
12656 ctype ? ctype : in_namespace);
12657 bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
12658 inlinep, friendp, raises != NULL_TREE);
12659
12660 if (ctype)
12661 {
12662 DECL_CONTEXT (decl) = ctype;
12663 if (staticp == 1)
12664 {
12665 pedwarn ("`static' may not be used when defining (as opposed to declaring) a static data member");
12666 staticp = 0;
12667 RIDBIT_RESET (RID_STATIC, specbits);
12668 }
12669 if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl))
12670 {
12671 error ("static member `%D' declared `register'", decl);
12672 RIDBIT_RESET (RID_REGISTER, specbits);
12673 }
12674 if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic)
12675 {
12676 pedwarn ("cannot explicitly declare member `%#D' to have extern linkage",
12677 decl);
12678 RIDBIT_RESET (RID_EXTERN, specbits);
12679 }
12680 }
12681 }
12682
12683 my_friendly_assert (!RIDBIT_SETP (RID_MUTABLE, specbits), 19990927);
12684
12685
12686
12687
12688 if (RIDBIT_SETP (RID_REGISTER, specbits))
12689 DECL_REGISTER (decl) = 1;
12690
12691 if (RIDBIT_SETP (RID_EXTERN, specbits))
12692 DECL_THIS_EXTERN (decl) = 1;
12693
12694 if (RIDBIT_SETP (RID_STATIC, specbits))
12695 DECL_THIS_STATIC (decl) = 1;
12696
12697
12698
12699
12700 if (!processing_template_decl)
12701 c_apply_type_quals_to_decl (type_quals, decl);
12702
12703 #ifdef KEY
12704 if (In_MP_Region && decl && TREE_CODE (decl) == VAR_DECL)
12705 push_mp_local_vars (decl);
12706 #endif
12707 return decl;
12708 }
12709 }
12710
12711
12712
12713
12714
12715
12716 int
12717 parmlist_is_exprlist (exprs)
12718 tree exprs;
12719 {
12720 if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
12721 return 0;
12722
12723 if (toplevel_bindings_p ())
12724 {
12725
12726
12727 while (exprs)
12728 {
12729 if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
12730 return 1;
12731 exprs = TREE_CHAIN (exprs);
12732 }
12733 return 0;
12734 }
12735 return 1;
12736 }
12737
12738
12739
12740
12741
12742 static void
12743 require_complete_types_for_parms (parms)
12744 tree parms;
12745 {
12746 for (; parms; parms = TREE_CHAIN (parms))
12747 {
12748 if (VOID_TYPE_P (TREE_TYPE (parms)))
12749
12750 TREE_TYPE (parms) = error_mark_node;
12751 else if (complete_type_or_else (TREE_TYPE (parms), parms))
12752 {
12753 layout_decl (parms, 0);
12754 DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
12755 }
12756 else
12757 TREE_TYPE (parms) = error_mark_node;
12758 }
12759 }
12760
12761
12762
12763 int
12764 local_variable_p (t)
12765 tree t;
12766 {
12767 if ((TREE_CODE (t) == VAR_DECL
12768
12769
12770 && !TYPE_P (CP_DECL_CONTEXT (t))
12771
12772 && !DECL_NAMESPACE_SCOPE_P (t))
12773 || (TREE_CODE (t) == PARM_DECL))
12774 return 1;
12775
12776 return 0;
12777 }
12778
12779
12780
12781
12782
12783 int
12784 nonstatic_local_decl_p (t)
12785 tree t;
12786 {
12787 return ((local_variable_p (t) && !TREE_STATIC (t))
12788 || TREE_CODE (t) == LABEL_DECL
12789 || TREE_CODE (t) == RESULT_DECL);
12790 }
12791
12792
12793
12794
12795 static tree
12796 local_variable_p_walkfn (tp, walk_subtrees, data)
12797 tree *tp;
12798 int *walk_subtrees ATTRIBUTE_UNUSED;
12799 void *data ATTRIBUTE_UNUSED;
12800 {
12801 return ((local_variable_p (*tp) && !DECL_ARTIFICIAL (*tp))
12802 ? *tp : NULL_TREE);
12803 }
12804
12805
12806
12807
12808
12809
12810 tree
12811 check_default_argument (decl, arg)
12812 tree decl;
12813 tree arg;
12814 {
12815 tree var;
12816 tree decl_type;
12817
12818 if (TREE_CODE (arg) == DEFAULT_ARG)
12819
12820
12821
12822 return arg;
12823
12824 if (processing_template_decl || uses_template_parms (arg))
12825
12826
12827
12828
12829 return arg;
12830
12831 if (TYPE_P (decl))
12832 {
12833 decl_type = decl;
12834 decl = NULL_TREE;
12835 }
12836 else
12837 decl_type = TREE_TYPE (decl);
12838
12839 if (arg == error_mark_node
12840 || decl == error_mark_node
12841 || TREE_TYPE (arg) == error_mark_node
12842 || decl_type == error_mark_node)
12843
12844
12845 return error_mark_node;
12846
12847
12848
12849
12850
12851 if (!TREE_TYPE (arg)
12852 || !can_convert_arg (decl_type, TREE_TYPE (arg), arg))
12853 {
12854 if (decl)
12855 error ("default argument for `%#D' has type `%T'",
12856 decl, TREE_TYPE (arg));
12857 else
12858 error ("default argument for parameter of type `%T' has type `%T'",
12859 decl_type, TREE_TYPE (arg));
12860
12861 return error_mark_node;
12862 }
12863
12864
12865
12866
12867
12868
12869
12870
12871 var = walk_tree_without_duplicates (&arg, local_variable_p_walkfn,
12872 NULL);
12873 if (var)
12874 {
12875 error ("default argument `%E' uses local variable `%D'",
12876 arg, var);
12877 return error_mark_node;
12878 }
12879
12880
12881 return arg;
12882 }
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894 static tree
12895 grokparms (first_parm)
12896 tree first_parm;
12897 {
12898 tree result = NULL_TREE;
12899 tree decls = NULL_TREE;
12900 int ellipsis = !first_parm || PARMLIST_ELLIPSIS_P (first_parm);
12901 tree parm, chain;
12902 int any_error = 0;
12903
12904 my_friendly_assert (!first_parm || TREE_PARMLIST (first_parm), 20001115);
12905
12906 for (parm = first_parm; parm != NULL_TREE; parm = chain)
12907 {
12908 tree type = NULL_TREE;
12909 tree decl = TREE_VALUE (parm);
12910 tree init = TREE_PURPOSE (parm);
12911 tree specs, attrs;
12912
12913 chain = TREE_CHAIN (parm);
12914
12915 if (TREE_CODE (decl) != VOID_TYPE
12916 && TREE_CODE (decl) != TREE_LIST)
12917 {
12918
12919 if (TREE_CODE (decl) == STRING_CST)
12920 error ("invalid string constant `%E'", decl);
12921 else if (TREE_CODE (decl) == INTEGER_CST)
12922 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
12923 continue;
12924 }
12925
12926 if (parm == void_list_node)
12927 break;
12928
12929 split_specs_attrs (TREE_PURPOSE (decl), &specs, &attrs);
12930 decl = grokdeclarator (TREE_VALUE (decl), specs,
12931 PARM, init != NULL_TREE, &attrs);
12932 if (! decl || TREE_TYPE (decl) == error_mark_node)
12933 continue;
12934
12935 if (attrs)
12936 cplus_decl_attributes (&decl, attrs, 0);
12937
12938 type = TREE_TYPE (decl);
12939 if (VOID_TYPE_P (type))
12940 {
12941 if (same_type_p (type, void_type_node)
12942 && !DECL_NAME (decl) && !result && !chain && !ellipsis)
12943
12944 break;
12945 cxx_incomplete_type_error (decl, type);
12946
12947
12948
12949 type = error_mark_node;
12950 TREE_TYPE (decl) = error_mark_node;
12951 }
12952
12953 if (type != error_mark_node)
12954 {
12955
12956
12957 type = TYPE_MAIN_VARIANT (type);
12958 if (TREE_CODE (type) == METHOD_TYPE)
12959 {
12960 error ("parameter `%D' invalidly declared method type", decl);
12961 type = build_pointer_type (type);
12962 TREE_TYPE (decl) = type;
12963 }
12964 else if (TREE_CODE (type) == OFFSET_TYPE)
12965 {
12966 error ("parameter `%D' invalidly declared offset type", decl);
12967 type = build_pointer_type (type);
12968 TREE_TYPE (decl) = type;
12969 }
12970 else if (abstract_virtuals_error (decl, type))
12971 any_error = 1;
12972 else if (POINTER_TYPE_P (type))
12973 {
12974
12975
12976 tree t = TREE_TYPE (type);
12977 int ptr = TYPE_PTR_P (type);
12978
12979 while (1)
12980 {
12981 if (TYPE_PTR_P (t))
12982 ptr = 1;
12983 else if (TREE_CODE (t) != ARRAY_TYPE)
12984 break;
12985 else if (!TYPE_DOMAIN (t))
12986 break;
12987 t = TREE_TYPE (t);
12988 }
12989 if (TREE_CODE (t) == ARRAY_TYPE)
12990 error ("parameter `%D' includes %s to array of unknown bound `%T'",
12991 decl, ptr ? "pointer" : "reference", t);
12992 }
12993
12994 if (!any_error && init)
12995 init = check_default_argument (decl, init);
12996 else
12997 init = NULL_TREE;
12998 }
12999
13000 TREE_CHAIN (decl) = decls;
13001 decls = decl;
13002 result = tree_cons (init, type, result);
13003 }
13004 decls = nreverse (decls);
13005 result = nreverse (result);
13006 if (!ellipsis)
13007 result = chainon (result, void_list_node);
13008 last_function_parms = decls;
13009
13010 return result;
13011 }
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032 int
13033 copy_fn_p (d)
13034 tree d;
13035 {
13036 tree args;
13037 tree arg_type;
13038 int result = 1;
13039
13040 my_friendly_assert (DECL_FUNCTION_MEMBER_P (d), 20011208);
13041
13042 if (DECL_TEMPLATE_INFO (d) && is_member_template (DECL_TI_TEMPLATE (d)))
13043
13044
13045
13046
13047 return 0;
13048
13049 args = FUNCTION_FIRST_USER_PARMTYPE (d);
13050 if (!args)
13051 return 0;
13052
13053 arg_type = TREE_VALUE (args);
13054
13055 if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
13056 {
13057
13058 result = -1;
13059 }
13060 else if (TREE_CODE (arg_type) == REFERENCE_TYPE
13061 && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
13062 {
13063 if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
13064 result = 2;
13065 }
13066 else
13067 return 0;
13068
13069 args = TREE_CHAIN (args);
13070
13071 if (args && args != void_list_node && !TREE_PURPOSE (args))
13072
13073 return 0;
13074
13075 return result;
13076 }
13077
13078
13079
13080 void grok_special_member_properties (decl)
13081 tree decl;
13082 {
13083 if (!DECL_NONSTATIC_MEMBER_FUNCTION_P(decl))
13084 ;
13085 else if (DECL_CONSTRUCTOR_P (decl))
13086 {
13087 int ctor = copy_fn_p (decl);
13088
13089 if (ctor > 0)
13090 {
13091
13092
13093
13094
13095
13096
13097
13098 TYPE_HAS_INIT_REF (DECL_CONTEXT (decl)) = 1;
13099 if (ctor > 1)
13100 TYPE_HAS_CONST_INIT_REF (DECL_CONTEXT (decl)) = 1;
13101 }
13102 else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
13103 TYPE_HAS_DEFAULT_CONSTRUCTOR (DECL_CONTEXT (decl)) = 1;
13104 }
13105 else if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
13106 {
13107
13108
13109
13110
13111
13112
13113 int assop = copy_fn_p (decl);
13114
13115 if (assop)
13116 {
13117 TYPE_HAS_ASSIGN_REF (DECL_CONTEXT (decl)) = 1;
13118 if (assop != 1)
13119 TYPE_HAS_CONST_ASSIGN_REF (DECL_CONTEXT (decl)) = 1;
13120 if (DECL_PURE_VIRTUAL_P (decl))
13121 TYPE_HAS_ABSTRACT_ASSIGN_REF (DECL_CONTEXT (decl)) = 1;
13122 }
13123 }
13124 }
13125
13126
13127
13128
13129 int
13130 grok_ctor_properties (ctype, decl)
13131 tree ctype, decl;
13132 {
13133 int ctor_parm = copy_fn_p (decl);
13134
13135 if (ctor_parm < 0)
13136 {
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152 error ("invalid constructor; you probably meant `%T (const %T&)'",
13153 ctype, ctype);
13154 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
13155 return 0;
13156 }
13157
13158 return 1;
13159 }
13160
13161
13162
13163 static int
13164 ambi_op_p (code)
13165 enum tree_code code;
13166 {
13167 return (code == INDIRECT_REF
13168 || code == ADDR_EXPR
13169 || code == CONVERT_EXPR
13170 || code == NEGATE_EXPR
13171 || code == PREINCREMENT_EXPR
13172 || code == PREDECREMENT_EXPR);
13173 }
13174
13175
13176
13177 static int
13178 unary_op_p (code)
13179 enum tree_code code;
13180 {
13181 return (code == TRUTH_NOT_EXPR
13182 || code == BIT_NOT_EXPR
13183 || code == COMPONENT_REF
13184 || code == TYPE_EXPR);
13185 }
13186
13187
13188
13189 void
13190 grok_op_properties (decl, friendp)
13191 tree decl;
13192 int friendp;
13193 {
13194 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
13195 tree argtype;
13196 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
13197 tree name = DECL_NAME (decl);
13198 enum tree_code operator_code;
13199 int arity;
13200
13201
13202 for (argtype = argtypes, arity = 0;
13203 argtype && argtype != void_list_node;
13204 argtype = TREE_CHAIN (argtype))
13205 ++arity;
13206
13207 if (current_class_type == NULL_TREE)
13208 friendp = 1;
13209
13210 if (DECL_CONV_FN_P (decl))
13211 operator_code = TYPE_EXPR;
13212 else
13213 do
13214 {
13215 #define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \
13216 if (ansi_opname (CODE) == name) \
13217 { \
13218 operator_code = (CODE); \
13219 break; \
13220 } \
13221 else if (ansi_assopname (CODE) == name) \
13222 { \
13223 operator_code = (CODE); \
13224 DECL_ASSIGNMENT_OPERATOR_P (decl) = 1; \
13225 break; \
13226 }
13227
13228 #include "operators.def"
13229 #undef DEF_OPERATOR
13230
13231 abort ();
13232 }
13233 while (0);
13234 my_friendly_assert (operator_code != LAST_CPLUS_TREE_CODE, 20000526);
13235 SET_OVERLOADED_OPERATOR_CODE (decl, operator_code);
13236
13237 if (! friendp)
13238 {
13239 switch (operator_code)
13240 {
13241 case CALL_EXPR:
13242 TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
13243 break;
13244
13245 case ARRAY_REF:
13246 TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
13247 break;
13248
13249 case COMPONENT_REF:
13250 case MEMBER_REF:
13251 TYPE_OVERLOADS_ARROW (current_class_type) = 1;
13252 break;
13253
13254 case NEW_EXPR:
13255 TYPE_HAS_NEW_OPERATOR (current_class_type) = 1;
13256 break;
13257
13258 case DELETE_EXPR:
13259 TYPE_GETS_DELETE (current_class_type) |= 1;
13260 break;
13261
13262 case VEC_NEW_EXPR:
13263 TYPE_HAS_ARRAY_NEW_OPERATOR (current_class_type) = 1;
13264 break;
13265
13266 case VEC_DELETE_EXPR:
13267 TYPE_GETS_DELETE (current_class_type) |= 2;
13268 break;
13269
13270 default:
13271 break;
13272 }
13273 }
13274
13275 if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR)
13276 {
13277
13278
13279 if (methodp)
13280 revert_static_member_fn (decl);
13281
13282 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
13283 }
13284 else if (operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR)
13285 {
13286 if (methodp)
13287 revert_static_member_fn (decl);
13288
13289 TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
13290 }
13291 else
13292 {
13293
13294
13295
13296 if (! methodp || DECL_STATIC_FUNCTION_P (decl))
13297 {
13298 if (operator_code == TYPE_EXPR
13299 || operator_code == CALL_EXPR
13300 || operator_code == COMPONENT_REF
13301 || operator_code == ARRAY_REF
13302 || operator_code == NOP_EXPR)
13303 error ("`%D' must be a nonstatic member function", decl);
13304 else
13305 {
13306 tree p = argtypes;
13307
13308 if (DECL_STATIC_FUNCTION_P (decl))
13309 error ("`%D' must be either a non-static member function or a non-member function", decl);
13310
13311 if (p)
13312 for (; TREE_CODE (TREE_VALUE (p)) != VOID_TYPE ; p = TREE_CHAIN (p))
13313 {
13314 tree arg = TREE_VALUE (p);
13315 if (TREE_CODE (arg) == REFERENCE_TYPE)
13316 arg = TREE_TYPE (arg);
13317
13318
13319 if (IS_AGGR_TYPE (arg)
13320 || TREE_CODE (arg) == ENUMERAL_TYPE
13321 || TREE_CODE (arg) == TEMPLATE_TYPE_PARM
13322 || TREE_CODE (arg) == BOUND_TEMPLATE_TEMPLATE_PARM)
13323 goto foundaggr;
13324 }
13325 error
13326 ("`%D' must have an argument of class or enumerated type",
13327 decl);
13328 foundaggr:
13329 ;
13330 }
13331 }
13332
13333 if (operator_code == CALL_EXPR)
13334 return;
13335
13336 if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl))
13337 {
13338 tree t = TREE_TYPE (name);
13339 if (! friendp)
13340 {
13341 int ref = (TREE_CODE (t) == REFERENCE_TYPE);
13342 const char *what = 0;
13343
13344 if (ref)
13345 t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
13346
13347 if (TREE_CODE (t) == VOID_TYPE)
13348 what = "void";
13349 else if (t == current_class_type)
13350 what = "the same type";
13351
13352 else if (IS_AGGR_TYPE (t)
13353 && COMPLETE_TYPE_P (t)
13354 && DERIVED_FROM_P (t, current_class_type))
13355 what = "a base class";
13356
13357 if (what && warn_conversion)
13358 warning ("conversion to %s%s will never use a type conversion operator",
13359 ref ? "a reference to " : "", what);
13360 }
13361 }
13362 if (operator_code == COND_EXPR)
13363 {
13364
13365 error ("ISO C++ prohibits overloading operator ?:");
13366 }
13367 else if (ambi_op_p (operator_code))
13368 {
13369 if (arity == 1)
13370
13371
13372 ;
13373 else if (arity == 2)
13374 {
13375
13376
13377 switch (operator_code)
13378 {
13379 case INDIRECT_REF:
13380 operator_code = MULT_EXPR;
13381 break;
13382
13383 case ADDR_EXPR:
13384 operator_code = BIT_AND_EXPR;
13385 break;
13386
13387 case CONVERT_EXPR:
13388 operator_code = PLUS_EXPR;
13389 break;
13390
13391 case NEGATE_EXPR:
13392 operator_code = MINUS_EXPR;
13393 break;
13394
13395 case PREINCREMENT_EXPR:
13396 operator_code = POSTINCREMENT_EXPR;
13397 break;
13398
13399 case PREDECREMENT_EXPR:
13400 operator_code = POSTDECREMENT_EXPR;
13401 break;
13402
13403 default:
13404 abort ();
13405 }
13406
13407 SET_OVERLOADED_OPERATOR_CODE (decl, operator_code);
13408
13409 if ((operator_code == POSTINCREMENT_EXPR
13410 || operator_code == POSTDECREMENT_EXPR)
13411 && ! processing_template_decl
13412 && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)), integer_type_node))
13413 {
13414 if (methodp)
13415 error ("postfix `%D' must take `int' as its argument",
13416 decl);
13417 else
13418 error
13419 ("postfix `%D' must take `int' as its second argument",
13420 decl);
13421 }
13422 }
13423 else
13424 {
13425 if (methodp)
13426 error ("`%D' must take either zero or one argument", decl);
13427 else
13428 error ("`%D' must take either one or two arguments", decl);
13429 }
13430
13431
13432 if (warn_ecpp
13433 && (operator_code == POSTINCREMENT_EXPR
13434 || operator_code == POSTDECREMENT_EXPR
13435 || operator_code == PREINCREMENT_EXPR
13436 || operator_code == PREDECREMENT_EXPR))
13437 {
13438 tree arg = TREE_VALUE (argtypes);
13439 tree ret = TREE_TYPE (TREE_TYPE (decl));
13440 if (methodp || TREE_CODE (arg) == REFERENCE_TYPE)
13441 arg = TREE_TYPE (arg);
13442 arg = TYPE_MAIN_VARIANT (arg);
13443 if (operator_code == PREINCREMENT_EXPR
13444 || operator_code == PREDECREMENT_EXPR)
13445 {
13446 if (TREE_CODE (ret) != REFERENCE_TYPE
13447 || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)),
13448 arg))
13449 warning ("prefix `%D' should return `%T'", decl,
13450 build_reference_type (arg));
13451 }
13452 else
13453 {
13454 if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
13455 warning ("postfix `%D' should return `%T'", decl, arg);
13456 }
13457 }
13458 }
13459 else if (unary_op_p (operator_code))
13460 {
13461 if (arity != 1)
13462 {
13463 if (methodp)
13464 error ("`%D' must take `void'", decl);
13465 else
13466 error ("`%D' must take exactly one argument", decl);
13467 }
13468 }
13469 else
13470 {
13471 if (arity != 2)
13472 {
13473 if (methodp)
13474 error ("`%D' must take exactly one argument", decl);
13475 else
13476 error ("`%D' must take exactly two arguments", decl);
13477 }
13478
13479
13480 if (warn_ecpp
13481 && (operator_code == TRUTH_ANDIF_EXPR
13482 || operator_code == TRUTH_ORIF_EXPR
13483 || operator_code == COMPOUND_EXPR))
13484 warning ("user-defined `%D' always evaluates both arguments",
13485 decl);
13486 }
13487
13488
13489 if (warn_ecpp
13490 && arity == 2
13491 && !DECL_ASSIGNMENT_OPERATOR_P (decl)
13492 && (operator_code == PLUS_EXPR
13493 || operator_code == MINUS_EXPR
13494 || operator_code == TRUNC_DIV_EXPR
13495 || operator_code == MULT_EXPR
13496 || operator_code == TRUNC_MOD_EXPR)
13497 && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE)
13498 warning ("`%D' should return by value", decl);
13499
13500
13501 for (; argtypes && argtypes != void_list_node;
13502 argtypes = TREE_CHAIN (argtypes))
13503 if (TREE_PURPOSE (argtypes))
13504 {
13505 TREE_PURPOSE (argtypes) = NULL_TREE;
13506 if (operator_code == POSTINCREMENT_EXPR
13507 || operator_code == POSTDECREMENT_EXPR)
13508 {
13509 if (pedantic)
13510 pedwarn ("`%D' cannot have default arguments", decl);
13511 }
13512 else
13513 error ("`%D' cannot have default arguments", decl);
13514 }
13515
13516 }
13517 }
13518
13519 static const char *
13520 tag_name (code)
13521 enum tag_types code;
13522 {
13523 switch (code)
13524 {
13525 case record_type:
13526 return "struct";
13527 case class_type:
13528 return "class";
13529 case union_type:
13530 return "union ";
13531 case enum_type:
13532 return "enum";
13533 default:
13534 abort ();
13535 }
13536 }
13537
13538
13539
13540
13541
13542
13543 static tree
13544 check_elaborated_type_specifier (enum tag_types tag_code,
13545 tree type)
13546 {
13547 tree t;
13548
13549 t = follow_tag_typedef (type);
13550
13551
13552
13553
13554 if (!t)
13555 {
13556 error ("using typedef-name `%D' after `%s'",
13557 TYPE_NAME (type), tag_name (tag_code));
13558 t = error_mark_node;
13559 }
13560 else if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
13561 {
13562 error ("using template type parameter `%T' after `%s'",
13563 type, tag_name (tag_code));
13564 t = error_mark_node;
13565 }
13566
13567 return t;
13568 }
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580 tree
13581 xref_tag (enum tag_types tag_code, tree name, tree attributes,
13582 bool globalize)
13583 {
13584 enum tree_code code;
13585 register tree ref, t;
13586 struct cp_binding_level *b = current_binding_level;
13587 tree context = NULL_TREE;
13588
13589 timevar_push (TV_NAME_LOOKUP);
13590
13591 switch (tag_code)
13592 {
13593 case record_type:
13594 case class_type:
13595 code = RECORD_TYPE;
13596 break;
13597 case union_type:
13598 code = UNION_TYPE;
13599 break;
13600 case enum_type:
13601 code = ENUMERAL_TYPE;
13602 break;
13603 default:
13604 abort ();
13605 }
13606
13607
13608
13609 if (TYPE_P (name))
13610 {
13611 t = name;
13612 name = TYPE_IDENTIFIER (t);
13613 }
13614 else
13615 t = IDENTIFIER_TYPE_VALUE (name);
13616
13617
13618 if (t && globalize && TREE_CODE (t) == TYPENAME_TYPE)
13619 {
13620 static int explained;
13621 tree shadowed;
13622
13623 warning ("`%s %T' declares a new type at namespace scope",
13624 tag_name (tag_code), name);
13625 if (!explained++)
13626 warning (" names from dependent base classes are not visible to unqualified name lookup - to refer to the inherited type, say `%s %T::%T'",
13627 tag_name (tag_code),
13628 constructor_name (current_class_type),
13629 TYPE_IDENTIFIER (t));
13630
13631
13632
13633 for (shadowed = b->class_shadowed;
13634 shadowed;
13635 shadowed = TREE_CHAIN (shadowed))
13636 if (TREE_TYPE (shadowed) == TYPE_NAME (t))
13637 {
13638 TREE_PURPOSE (shadowed) = NULL_TREE;
13639 break;
13640 }
13641 }
13642
13643 if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM
13644 && TREE_CODE (t) != BOUND_TEMPLATE_TEMPLATE_PARM)
13645 t = NULL_TREE;
13646
13647 if (! globalize)
13648 {
13649
13650
13651 ref = lookup_tag (code, name, b, 1);
13652 }
13653 else
13654 {
13655 if (t)
13656 {
13657 ref = check_elaborated_type_specifier (tag_code, t);
13658 if (ref == error_mark_node)
13659 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
13660 }
13661 else
13662 ref = lookup_tag (code, name, b, 0);
13663
13664 if (! ref)
13665 {
13666
13667
13668 ref = lookup_name (name, 1);
13669
13670 if (ref != NULL_TREE
13671 && processing_template_decl
13672 && DECL_CLASS_TEMPLATE_P (ref)
13673 && template_class_depth (current_class_type) == 0)
13674
13675
13676 ref = DECL_TEMPLATE_RESULT (ref);
13677
13678 if (ref && TREE_CODE (ref) == TYPE_DECL)
13679 {
13680 ref = check_elaborated_type_specifier (tag_code,
13681 TREE_TYPE (ref));
13682 if (ref == error_mark_node)
13683 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
13684 if (ref && TREE_CODE (ref) != code)
13685 ref = NULL_TREE;
13686 }
13687 else
13688 ref = NULL_TREE;
13689 }
13690
13691 if (ref && current_class_type
13692 && template_class_depth (current_class_type)
13693 && PROCESSING_REAL_TEMPLATE_DECL_P ())
13694 {
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731 context = TYPE_CONTEXT (ref);
13732 ref = NULL_TREE;
13733 }
13734 }
13735
13736 if (! ref)
13737 {
13738
13739
13740
13741
13742 if (code == ENUMERAL_TYPE)
13743 {
13744 error ("use of enum `%#D' without previous declaration", name);
13745
13746 ref = make_node (ENUMERAL_TYPE);
13747
13748
13749
13750 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
13751 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
13752 TYPE_USER_ALIGN (ref) = 0;
13753 TREE_UNSIGNED (ref) = 1;
13754 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
13755 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
13756 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
13757
13758
13759
13760
13761
13762
13763 pushtag (name, ref, globalize);
13764 }
13765 else
13766 {
13767 struct cp_binding_level *old_b = class_binding_level;
13768
13769 ref = make_aggr_type (code);
13770 TYPE_CONTEXT (ref) = context;
13771
13772 #ifdef NONNESTED_CLASSES
13773
13774 class_binding_level = (struct cp_binding_level *)0;
13775 #endif
13776 pushtag (name, ref, globalize);
13777 class_binding_level = old_b;
13778 }
13779 }
13780 else
13781 {
13782 if (!globalize && processing_template_decl && IS_AGGR_TYPE (ref))
13783 redeclare_class_template (ref, current_template_parms);
13784 }
13785
13786 TYPE_ATTRIBUTES (ref) = attributes;
13787
13788 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ref);
13789 }
13790
13791 tree
13792 xref_tag_from_type (old, id, globalize)
13793 tree old, id;
13794 int globalize;
13795 {
13796 enum tag_types tag_kind;
13797
13798 if (TREE_CODE (old) == RECORD_TYPE)
13799 tag_kind = (CLASSTYPE_DECLARED_CLASS (old) ? class_type : record_type);
13800 else
13801 tag_kind = union_type;
13802
13803 if (id == NULL_TREE)
13804 id = TYPE_IDENTIFIER (old);
13805
13806 return xref_tag (tag_kind, id, NULL_TREE, globalize);
13807 }
13808
13809
13810
13811
13812
13813
13814
13815 void
13816 xref_basetypes (ref, binfo)
13817 tree ref;
13818 tree binfo;
13819 {
13820
13821
13822 tree binfos;
13823 tree base;
13824
13825 int i, len;
13826 enum tag_types tag_code;
13827
13828 if (TREE_CODE (ref) == UNION_TYPE)
13829 {
13830 error ("derived union `%T' invalid", ref);
13831 return;
13832 }
13833
13834 tag_code = (CLASSTYPE_DECLARED_CLASS (ref) ? class_type : record_type);
13835
13836 len = list_length (binfo);
13837
13838
13839
13840
13841
13842 for (base = binfo; base; base = TREE_CHAIN (base))
13843 complete_type (TREE_VALUE (base));
13844
13845 SET_CLASSTYPE_MARKED (ref);
13846 BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
13847
13848 for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
13849 {
13850
13851 int via_public
13852 = (TREE_PURPOSE (binfo) == access_public_node
13853 || TREE_PURPOSE (binfo) == access_public_virtual_node
13854 || (tag_code != class_type
13855 && (TREE_PURPOSE (binfo) == access_default_node
13856 || TREE_PURPOSE (binfo) == access_default_virtual_node)));
13857 int via_protected
13858 = (TREE_PURPOSE (binfo) == access_protected_node
13859 || TREE_PURPOSE (binfo) == access_protected_virtual_node);
13860 int via_virtual
13861 = (TREE_PURPOSE (binfo) == access_private_virtual_node
13862 || TREE_PURPOSE (binfo) == access_protected_virtual_node
13863 || TREE_PURPOSE (binfo) == access_public_virtual_node
13864 || TREE_PURPOSE (binfo) == access_default_virtual_node);
13865 tree basetype = TREE_VALUE (binfo);
13866 tree base_binfo;
13867
13868 if (basetype && TREE_CODE (basetype) == TYPE_DECL)
13869 basetype = TREE_TYPE (basetype);
13870 if (!basetype
13871 || (TREE_CODE (basetype) != RECORD_TYPE
13872 && TREE_CODE (basetype) != TYPENAME_TYPE
13873 && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM
13874 && TREE_CODE (basetype) != BOUND_TEMPLATE_TEMPLATE_PARM))
13875 {
13876 error ("base type `%T' fails to be a struct or class type",
13877 TREE_VALUE (binfo));
13878 continue;
13879 }
13880
13881
13882
13883 if (!COMPLETE_TYPE_P (basetype)
13884 && ! (current_template_parms && uses_template_parms (basetype)))
13885 {
13886 error ("base class `%T' has incomplete type", basetype);
13887 continue;
13888 }
13889 else
13890 {
13891 if (CLASSTYPE_MARKED (basetype))
13892 {
13893 if (basetype == ref)
13894 error ("recursive type `%T' undefined", basetype);
13895 else
13896 error ("duplicate base type `%T' invalid", basetype);
13897 continue;
13898 }
13899
13900 if (TYPE_FOR_JAVA (basetype)
13901 && (current_lang_depth () == 0))
13902 TYPE_FOR_JAVA (ref) = 1;
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912 base_binfo
13913 = make_binfo (size_zero_node, basetype,
13914 CLASS_TYPE_P (basetype)
13915 ? TYPE_BINFO_VTABLE (basetype) : NULL_TREE,
13916 CLASS_TYPE_P (basetype)
13917 ? TYPE_BINFO_VIRTUALS (basetype) : NULL_TREE);
13918
13919 TREE_VEC_ELT (binfos, i) = base_binfo;
13920 TREE_VIA_PUBLIC (base_binfo) = via_public;
13921 TREE_VIA_PROTECTED (base_binfo) = via_protected;
13922 TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
13923 BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref);
13924
13925
13926
13927 unshare_base_binfos (base_binfo);
13928
13929 SET_CLASSTYPE_MARKED (basetype);
13930
13931
13932
13933 if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
13934 {
13935 TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
13936
13937
13938 TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (ref) = 1;
13939 }
13940
13941 if (CLASS_TYPE_P (basetype))
13942 {
13943 TYPE_HAS_NEW_OPERATOR (ref)
13944 |= TYPE_HAS_NEW_OPERATOR (basetype);
13945 TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
13946 |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
13947 TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
13948
13949 TYPE_USES_MULTIPLE_INHERITANCE (ref)
13950 |= TYPE_USES_MULTIPLE_INHERITANCE (basetype);
13951
13952
13953
13954 TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (ref)
13955 |= TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (basetype);
13956 }
13957
13958 i += 1;
13959 }
13960 }
13961 if (i)
13962 TREE_VEC_LENGTH (binfos) = i;
13963 else
13964 BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
13965
13966 if (i > 1)
13967 {
13968 TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
13969
13970
13971 TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (ref) = 1;
13972 }
13973
13974
13975 while (--i >= 0)
13976 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
13977 CLEAR_CLASSTYPE_MARKED (ref);
13978
13979
13980
13981 get_vbase_types (ref);
13982 }
13983
13984
13985
13986
13987
13988
13989
13990
13991 tree
13992 start_enum (name)
13993 tree name;
13994 {
13995 register tree enumtype = NULL_TREE;
13996 struct cp_binding_level *b = current_binding_level;
13997
13998
13999
14000
14001
14002 if (name != NULL_TREE)
14003 enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
14004
14005 if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
14006 {
14007 error ("multiple definition of `%#T'", enumtype);
14008 cp_error_at ("previous definition here", enumtype);
14009
14010 TYPE_VALUES (enumtype) = NULL_TREE;
14011 }
14012 else
14013 {
14014 enumtype = make_node (ENUMERAL_TYPE);
14015 pushtag (name, enumtype, 0);
14016 }
14017
14018 return enumtype;
14019 }
14020
14021
14022
14023
14024
14025 void
14026 finish_enum (enumtype)
14027 tree enumtype;
14028 {
14029 tree pair;
14030 tree minnode;
14031 tree maxnode;
14032 tree t;
14033 bool unsignedp;
14034 int lowprec;
14035 int highprec;
14036 int precision;
14037
14038
14039 TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
14040
14041
14042
14043
14044
14045 if (processing_template_decl)
14046 {
14047 for (pair = TYPE_VALUES (enumtype); pair; pair = TREE_CHAIN (pair))
14048 TREE_TYPE (TREE_VALUE (pair)) = enumtype;
14049 if (at_function_scope_p ())
14050 add_stmt (build_min (TAG_DEFN, enumtype));
14051 return;
14052 }
14053
14054 if (TYPE_VALUES (enumtype))
14055 {
14056 minnode = maxnode = NULL_TREE;
14057
14058 for (pair = TYPE_VALUES (enumtype); pair; pair = TREE_CHAIN (pair))
14059 {
14060 tree decl = TREE_VALUE (pair);
14061 tree value = DECL_INITIAL (decl);
14062
14063
14064
14065
14066
14067 TREE_TYPE (decl) = enumtype;
14068
14069
14070
14071 if (!minnode)
14072 minnode = maxnode = value;
14073 else if (tree_int_cst_lt (maxnode, value))
14074 maxnode = value;
14075 else if (tree_int_cst_lt (value, minnode))
14076 minnode = value;
14077
14078
14079
14080
14081
14082 if (TREE_TYPE (value) != enumtype)
14083 {
14084 value = DECL_INITIAL (decl) = copy_node (value);
14085 TREE_TYPE (value) = enumtype;
14086 }
14087
14088
14089
14090 TREE_VALUE (pair) = value;
14091 }
14092 }
14093 else
14094 minnode = maxnode = integer_zero_node;
14095
14096
14097
14098
14099
14100 unsignedp = tree_int_cst_sgn (minnode) >= 0;
14101 lowprec = min_precision (minnode, unsignedp);
14102 highprec = min_precision (maxnode, unsignedp);
14103 precision = MAX (lowprec, highprec);
14104
14105
14106
14107
14108
14109 if (precision > TYPE_PRECISION (long_long_integer_type_node))
14110 {
14111 error ("no integral type can represent all of the enumerator values "
14112 "for `%T'", enumtype);
14113 precision = TYPE_PRECISION (long_long_integer_type_node);
14114 }
14115
14116
14117
14118 TYPE_PRECISION (enumtype) = precision;
14119 TYPE_SIZE (enumtype) = NULL_TREE;
14120 if (unsignedp)
14121 fixup_unsigned_type (enumtype);
14122 else
14123 fixup_signed_type (enumtype);
14124
14125 if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node)))
14126
14127
14128 TYPE_PRECISION (enumtype) = TYPE_PRECISION (c_common_type_for_size
14129 (precision, 1));
14130 else
14131 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
14132
14133 TYPE_SIZE (enumtype) = NULL_TREE;
14134 layout_type (enumtype);
14135
14136
14137 for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
14138 {
14139 TYPE_VALUES (t) = TYPE_VALUES (enumtype);
14140 TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (enumtype);
14141 TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (enumtype);
14142 TYPE_SIZE (t) = TYPE_SIZE (enumtype);
14143 TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (enumtype);
14144 TYPE_MODE (t) = TYPE_MODE (enumtype);
14145 TYPE_PRECISION (t) = TYPE_PRECISION (enumtype);
14146 TYPE_ALIGN (t) = TYPE_ALIGN (enumtype);
14147 TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (enumtype);
14148 TREE_UNSIGNED (t) = TREE_UNSIGNED (enumtype);
14149 }
14150
14151
14152 rest_of_type_compilation (enumtype, namespace_bindings_p ());
14153 }
14154
14155
14156
14157
14158
14159 void
14160 build_enumerator (name, value, enumtype)
14161 tree name;
14162 tree value;
14163 tree enumtype;
14164 {
14165 tree decl;
14166 tree context;
14167 tree type;
14168
14169
14170 if (value)
14171 STRIP_TYPE_NOPS (value);
14172
14173 if (! processing_template_decl)
14174 {
14175
14176 if (value != NULL_TREE)
14177 {
14178 value = decl_constant_value (value);
14179
14180 if (TREE_CODE (value) == INTEGER_CST)
14181 {
14182 value = default_conversion (value);
14183 constant_expression_warning (value);
14184 }
14185 else
14186 {
14187 error ("enumerator value for `%D' not integer constant", name);
14188 value = NULL_TREE;
14189 }
14190 }
14191
14192
14193 if (value == NULL_TREE && ! processing_template_decl)
14194 {
14195 tree prev_value;
14196
14197 if (TYPE_VALUES (enumtype))
14198 {
14199
14200 prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
14201
14202 value = cp_build_binary_op (PLUS_EXPR,
14203 prev_value,
14204 integer_one_node);
14205
14206 if (tree_int_cst_lt (value, prev_value))
14207 error ("overflow in enumeration values at `%D'", name);
14208 }
14209 else
14210 value = integer_zero_node;
14211 }
14212
14213
14214 STRIP_TYPE_NOPS (value);
14215 }
14216
14217
14218 context = current_scope ();
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233 type = value ? TREE_TYPE (value) : NULL_TREE;
14234
14235 if (context && context == current_class_type)
14236
14237
14238 decl = build_lang_decl (CONST_DECL, name, type);
14239 else
14240
14241
14242 decl = build_decl (CONST_DECL, name, type);
14243
14244 DECL_CONTEXT (decl) = FROB_CONTEXT (context);
14245 DECL_INITIAL (decl) = value;
14246 TREE_READONLY (decl) = 1;
14247
14248 if (context && context == current_class_type)
14249
14250
14251
14252 finish_member_declaration (decl);
14253 else
14254 pushdecl (decl);
14255
14256
14257 TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
14258 }
14259
14260
14261
14262
14263 static void
14264 check_function_type (decl, current_function_parms)
14265 tree decl;
14266 tree current_function_parms;
14267 {
14268 tree fntype = TREE_TYPE (decl);
14269 tree return_type = complete_type (TREE_TYPE (fntype));
14270
14271
14272 require_complete_types_for_parms (current_function_parms);
14273
14274 if (!COMPLETE_OR_VOID_TYPE_P (return_type))
14275 {
14276 error ("return type `%#T' is incomplete", TREE_TYPE (fntype));
14277
14278
14279
14280 if (TREE_CODE (fntype) == METHOD_TYPE)
14281 {
14282 tree ctype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype)));
14283 TREE_TYPE (decl)
14284 = build_cplus_method_type (ctype,
14285 void_type_node,
14286 FUNCTION_ARG_CHAIN (decl));
14287 }
14288 else
14289 TREE_TYPE (decl)
14290 = build_function_type (void_type_node,
14291 TYPE_ARG_TYPES (TREE_TYPE (decl)));
14292 TREE_TYPE (decl)
14293 = build_exception_variant (fntype,
14294 TYPE_RAISES_EXCEPTIONS (fntype));
14295 }
14296 else
14297 abstract_virtuals_error (decl, TREE_TYPE (fntype));
14298 }
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322 int
14323 start_function (declspecs, declarator, attrs, flags)
14324 tree declspecs, declarator, attrs;
14325 int flags;
14326 {
14327 tree decl1;
14328 tree ctype = NULL_TREE;
14329 tree fntype;
14330 tree restype;
14331 int doing_friend = 0;
14332 struct cp_binding_level *bl;
14333 tree current_function_parms;
14334
14335
14336 my_friendly_assert (TREE_CODE (TREE_VALUE (void_list_node)) == VOID_TYPE, 160);
14337 my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
14338
14339
14340 if (have_extern_spec)
14341 {
14342 declspecs = tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
14343 have_extern_spec = false;
14344 }
14345
14346 if (flags & SF_PRE_PARSED)
14347 {
14348 decl1 = declarator;
14349
14350 fntype = TREE_TYPE (decl1);
14351 if (TREE_CODE (fntype) == METHOD_TYPE)
14352 ctype = TYPE_METHOD_BASETYPE (fntype);
14353
14354
14355
14356 if (!ctype && DECL_FRIEND_P (decl1))
14357 {
14358 ctype = DECL_FRIEND_CONTEXT (decl1);
14359
14360
14361
14362
14363 if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
14364 ctype = NULL_TREE;
14365 else
14366 doing_friend = 1;
14367 }
14368
14369 last_function_parms = DECL_ARGUMENTS (decl1);
14370 }
14371 else
14372 {
14373 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL);
14374
14375
14376 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
14377 return 0;
14378
14379 cplus_decl_attributes (&decl1, attrs, 0);
14380
14381
14382 if (global_scope_p (current_binding_level))
14383 maybe_apply_pragma_weak (decl1);
14384
14385 fntype = TREE_TYPE (decl1);
14386
14387 restype = TREE_TYPE (fntype);
14388 if (CLASS_TYPE_P (restype) && !CLASSTYPE_GOT_SEMICOLON (restype))
14389 {
14390 error ("semicolon missing after declaration of `%#T'", restype);
14391 shadow_tag (build_tree_list (NULL_TREE, restype));
14392 CLASSTYPE_GOT_SEMICOLON (restype) = 1;
14393 if (TREE_CODE (fntype) == FUNCTION_TYPE)
14394 fntype = build_function_type (integer_type_node,
14395 TYPE_ARG_TYPES (fntype));
14396 else
14397 fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
14398 integer_type_node,
14399 TYPE_ARG_TYPES (fntype));
14400 TREE_TYPE (decl1) = fntype;
14401 }
14402
14403 if (TREE_CODE (fntype) == METHOD_TYPE)
14404 ctype = TYPE_METHOD_BASETYPE (fntype);
14405 else if (DECL_MAIN_P (decl1))
14406 {
14407
14408 if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
14409 {
14410 if (pedantic || warn_return_type)
14411 pedwarn ("return type for `main' changed to `int'");
14412 TREE_TYPE (decl1) = fntype = default_function_type;
14413 }
14414 }
14415 }
14416
14417 if (DECL_DECLARED_INLINE_P (decl1)
14418 && lookup_attribute ("noinline", attrs))
14419 warning_with_decl (decl1,
14420 "inline function `%s' given attribute noinline");
14421
14422 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
14423
14424
14425
14426 adjust_clone_args (decl1);
14427
14428
14429
14430 if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)
14431 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE)
14432 {
14433 revert_static_member_fn (decl1);
14434 last_function_parms = TREE_CHAIN (last_function_parms);
14435 ctype = NULL_TREE;
14436 }
14437
14438
14439
14440 if (! warn_implicit
14441 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
14442 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
14443
14444
14445
14446 if (ctype)
14447 push_nested_class (ctype, 1);
14448 else if (DECL_STATIC_FUNCTION_P (decl1))
14449 push_nested_class (DECL_CONTEXT (decl1), 2);
14450
14451
14452
14453
14454
14455
14456
14457 if (flags & SF_INCLASS_INLINE)
14458 maybe_begin_member_template_processing (decl1);
14459
14460
14461 if (warn_ecpp
14462 && DECL_OVERLOADED_OPERATOR_P (decl1) == NOP_EXPR
14463 && TREE_CODE (TREE_TYPE (fntype)) == VOID_TYPE)
14464 warning ("`operator=' should return a reference to `*this'");
14465
14466
14467
14468 if (!DECL_INITIAL (decl1))
14469 DECL_INITIAL (decl1) = error_mark_node;
14470
14471
14472
14473 TREE_STATIC (decl1) = 1;
14474
14475
14476
14477
14478
14479 if (processing_template_decl)
14480 decl1 = push_template_decl (decl1);
14481
14482
14483 current_function_decl = decl1;
14484
14485
14486
14487 current_function_parms = last_function_parms;
14488
14489
14490
14491
14492 if (! processing_template_decl)
14493 check_function_type (decl1, current_function_parms);
14494
14495
14496 restype = TREE_TYPE (fntype);
14497
14498 if (c_promoting_integer_type_p (restype))
14499 restype = type_promotes_to (restype);
14500 if (DECL_RESULT (decl1) == NULL_TREE)
14501 {
14502 DECL_RESULT (decl1)
14503 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
14504 c_apply_type_quals_to_decl (cp_type_quals (restype),
14505 DECL_RESULT (decl1));
14506 }
14507
14508
14509
14510
14511
14512
14513 bl = current_binding_level;
14514 init_function_start (decl1, input_filename, lineno);
14515 #ifdef KEY
14516 copy_to_current_binding_level (bl);
14517 #else
14518 current_binding_level = bl;
14519 #endif // KEY
14520
14521
14522
14523
14524
14525 immediate_size_expand = 0;
14526 cfun->x_dont_save_pending_sizes_p = 1;
14527
14528
14529 begin_stmt_tree (&DECL_SAVED_TREE (decl1));
14530
14531
14532 announce_function (decl1);
14533
14534
14535
14536
14537 if (!processing_template_decl && !(flags & SF_PRE_PARSED))
14538 {
14539
14540 if (!DECL_TEMPLATE_SPECIALIZATION (decl1)
14541 && ! DECL_FUNCTION_MEMBER_P (decl1))
14542 decl1 = pushdecl (decl1);
14543 else
14544 {
14545
14546 if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
14547 DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
14548
14549 check_default_args (decl1);
14550 }
14551 fntype = TREE_TYPE (decl1);
14552 }
14553
14554
14555 current_function_decl = decl1;
14556 cfun->decl = decl1;
14557
14558
14559
14560 if (!DECL_PENDING_INLINE_P (decl1))
14561 DECL_SAVED_FUNCTION_DATA (decl1) = NULL;
14562
14563 if (ctype && !doing_friend && !DECL_STATIC_FUNCTION_P (decl1))
14564 {
14565
14566
14567
14568
14569 tree t = DECL_ARGUMENTS (decl1);
14570
14571 my_friendly_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL,
14572 162);
14573 my_friendly_assert (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE,
14574 19990811);
14575
14576 cp_function_chain->x_current_class_ref
14577 = build_indirect_ref (t, NULL);
14578 cp_function_chain->x_current_class_ptr = t;
14579
14580
14581
14582 t = TREE_CHAIN (t);
14583 if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
14584 {
14585 current_in_charge_parm = t;
14586 t = TREE_CHAIN (t);
14587 }
14588 if (DECL_HAS_VTT_PARM_P (decl1))
14589 {
14590 if (DECL_NAME (t) != vtt_parm_identifier)
14591 abort ();
14592 current_vtt_parm = t;
14593 }
14594 }
14595
14596 if (DECL_INTERFACE_KNOWN (decl1))
14597 {
14598 tree ctx = decl_function_context (decl1);
14599
14600 if (DECL_NOT_REALLY_EXTERN (decl1))
14601 DECL_EXTERNAL (decl1) = 0;
14602
14603 if (ctx != NULL_TREE && DECL_DECLARED_INLINE_P (ctx)
14604 && TREE_PUBLIC (ctx))
14605
14606
14607 comdat_linkage (decl1);
14608 }
14609
14610
14611
14612 else if (interface_unknown == 0
14613 && (! DECL_TEMPLATE_INSTANTIATION (decl1)
14614 || flag_alt_external_templates))
14615 {
14616 if (DECL_DECLARED_INLINE_P (decl1)
14617 || DECL_TEMPLATE_INSTANTIATION (decl1)
14618 || processing_template_decl)
14619 {
14620 DECL_EXTERNAL (decl1)
14621 = (interface_only
14622 || (DECL_DECLARED_INLINE_P (decl1)
14623 && ! flag_implement_inlines
14624 && !DECL_VINDEX (decl1)));
14625
14626
14627 maybe_make_one_only (decl1);
14628 }
14629 else
14630 DECL_EXTERNAL (decl1) = 0;
14631 DECL_NOT_REALLY_EXTERN (decl1) = 0;
14632 DECL_INTERFACE_KNOWN (decl1) = 1;
14633 }
14634 else if (interface_unknown && interface_only
14635 && (! DECL_TEMPLATE_INSTANTIATION (decl1)
14636 || flag_alt_external_templates))
14637 {
14638
14639
14640
14641
14642
14643 comdat_linkage (decl1);
14644 DECL_EXTERNAL (decl1) = 0;
14645 DECL_INTERFACE_KNOWN (decl1) = 1;
14646 DECL_DEFER_OUTPUT (decl1) = 1;
14647 }
14648 else
14649 {
14650
14651
14652 DECL_EXTERNAL (decl1) = 0;
14653
14654 if ((DECL_DECLARED_INLINE_P (decl1)
14655 || DECL_TEMPLATE_INSTANTIATION (decl1))
14656 && ! DECL_INTERFACE_KNOWN (decl1)
14657
14658 && ! decl_function_context (decl1))
14659 DECL_DEFER_OUTPUT (decl1) = 1;
14660 else
14661 DECL_INTERFACE_KNOWN (decl1) = 1;
14662 }
14663
14664 pushlevel (0);
14665 current_binding_level->parm_flag = 1;
14666
14667 ++function_depth;
14668
14669 if (DECL_DESTRUCTOR_P (decl1))
14670 {
14671 dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
14672 DECL_CONTEXT (dtor_label) = current_function_decl;
14673 }
14674
14675 start_fname_decls ();
14676
14677 store_parm_decls (current_function_parms);
14678
14679 return 1;
14680 }
14681
14682
14683
14684
14685
14686
14687
14688 static void
14689 store_parm_decls (current_function_parms)
14690 tree current_function_parms;
14691 {
14692 register tree fndecl = current_function_decl;
14693 register tree parm;
14694
14695
14696
14697
14698 tree nonparms = NULL_TREE;
14699
14700 if (current_function_parms)
14701 {
14702
14703
14704
14705
14706
14707 tree specparms = current_function_parms;
14708 tree next;
14709
14710
14711
14712 storedecls (NULL_TREE);
14713
14714
14715
14716
14717 specparms = nreverse (specparms);
14718
14719 for (parm = specparms; parm; parm = next)
14720 {
14721 next = TREE_CHAIN (parm);
14722 if (TREE_CODE (parm) == PARM_DECL)
14723 {
14724 if (DECL_NAME (parm) == NULL_TREE
14725 || TREE_CODE (parm) != VOID_TYPE)
14726 pushdecl (parm);
14727 else
14728 error ("parameter `%D' declared void", parm);
14729 }
14730 else
14731 {
14732
14733
14734 TREE_CHAIN (parm) = NULL_TREE;
14735 nonparms = chainon (nonparms, parm);
14736 }
14737 }
14738
14739
14740
14741
14742 DECL_ARGUMENTS (fndecl) = getdecls ();
14743 }
14744 else
14745 DECL_ARGUMENTS (fndecl) = NULL_TREE;
14746
14747
14748
14749
14750
14751 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
14752
14753
14754 if (flag_exceptions && !processing_template_decl
14755 && flag_enforce_eh_specs
14756 && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl)))
14757 current_eh_spec_block = begin_eh_spec_block ();
14758 }
14759
14760
14761
14762
14763
14764
14765 static void
14766 save_function_data (decl)
14767 tree decl;
14768 {
14769 struct language_function *f;
14770
14771
14772
14773 my_friendly_assert (!DECL_PENDING_INLINE_P (decl),
14774 19990908);
14775
14776
14777 f = ((struct language_function *)
14778 ggc_alloc (sizeof (struct language_function)));
14779 memcpy (f, cp_function_chain, sizeof (struct language_function));
14780 DECL_SAVED_FUNCTION_DATA (decl) = f;
14781
14782
14783 f->base.x_stmt_tree.x_last_stmt = NULL_TREE;
14784 f->base.x_stmt_tree.x_last_expr_type = NULL_TREE;
14785 f->x_named_label_uses = NULL;
14786 f->bindings = NULL;
14787 f->x_local_names = NULL;
14788
14789
14790 f->x_expanding_p = 1;
14791
14792
14793
14794
14795 if (current_function_cannot_inline)
14796 {
14797 f->cannot_inline = current_function_cannot_inline;
14798 DECL_INLINE (decl) = 0;
14799 }
14800 }
14801
14802
14803
14804
14805
14806 static void
14807 begin_constructor_body ()
14808 {
14809 }
14810
14811
14812
14813
14814
14815 static void
14816 finish_constructor_body ()
14817 {
14818 }
14819
14820
14821
14822
14823 static void
14824 begin_destructor_body ()
14825 {
14826 tree if_stmt;
14827 tree compound_stmt;
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842 if_stmt = begin_if_stmt ();
14843
14844
14845
14846
14847
14848
14849 finish_if_stmt_cond (boolean_true_node, if_stmt);
14850
14851 compound_stmt = begin_compound_stmt (0);
14852
14853
14854
14855
14856 initialize_vtbl_ptrs (current_class_ptr);
14857
14858 finish_compound_stmt (0, compound_stmt);
14859 finish_then_clause (if_stmt);
14860 finish_if_stmt ();
14861
14862
14863
14864 push_base_cleanups ();
14865 }
14866
14867
14868
14869
14870 static void
14871 finish_destructor_body ()
14872 {
14873 tree exprstmt;
14874
14875
14876
14877 add_stmt (build_stmt (LABEL_STMT, dtor_label));
14878
14879
14880 if (DECL_VIRTUAL_P (current_function_decl))
14881 {
14882 tree if_stmt;
14883 tree virtual_size = cxx_sizeof (current_class_type);
14884
14885
14886
14887
14888
14889
14890
14891 exprstmt = build_op_delete_call
14892 (DELETE_EXPR, current_class_ptr, virtual_size,
14893 LOOKUP_NORMAL | LOOKUP_SPECULATIVELY, NULL_TREE);
14894
14895 if_stmt = begin_if_stmt ();
14896 finish_if_stmt_cond (build (BIT_AND_EXPR, integer_type_node,
14897 current_in_charge_parm,
14898 integer_one_node),
14899 if_stmt);
14900 finish_expr_stmt (exprstmt);
14901 finish_then_clause (if_stmt);
14902 finish_if_stmt ();
14903 }
14904 }
14905
14906
14907
14908
14909
14910
14911
14912 tree
14913 begin_function_body ()
14914 {
14915 tree stmt;
14916
14917 if (processing_template_decl)
14918 ;
14919 else
14920
14921
14922
14923 keep_next_level (1);
14924
14925 stmt = begin_compound_stmt (0);
14926 COMPOUND_STMT_BODY_BLOCK (stmt) = 1;
14927
14928 if (processing_template_decl)
14929 ;
14930 else if (DECL_CONSTRUCTOR_P (current_function_decl))
14931 begin_constructor_body ();
14932 else if (DECL_DESTRUCTOR_P (current_function_decl))
14933 begin_destructor_body ();
14934
14935 return stmt;
14936 }
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947 void
14948 finish_function_body (compstmt)
14949 tree compstmt;
14950 {
14951
14952 finish_compound_stmt (0, compstmt);
14953
14954 if (processing_template_decl)
14955 ;
14956 else if (DECL_CONSTRUCTOR_P (current_function_decl))
14957 finish_constructor_body ();
14958 else if (DECL_DESTRUCTOR_P (current_function_decl))
14959 finish_destructor_body ();
14960 }
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972 tree
14973 finish_function (flags)
14974 int flags;
14975 {
14976 register tree fndecl = current_function_decl;
14977 tree fntype, ctype = NULL_TREE;
14978 int inclass_inline = (flags & 2) != 0;
14979 int nested;
14980
14981
14982
14983 if (fndecl == NULL_TREE)
14984 return error_mark_node;
14985
14986 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
14987 && DECL_VIRTUAL_P (fndecl)
14988 && !processing_template_decl)
14989 {
14990 tree fnclass = DECL_CONTEXT (fndecl);
14991 if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
14992 keyed_classes = tree_cons (NULL_TREE, fnclass, keyed_classes);
14993 }
14994
14995 nested = function_depth > 1;
14996 fntype = TREE_TYPE (fndecl);
14997
14998
14999
15000
15001
15002 my_friendly_assert (building_stmt_tree (), 20000911);
15003
15004 finish_fname_decls ();
15005
15006
15007
15008 if (!DECL_CLONED_FUNCTION_P (fndecl))
15009 {
15010 if (DECL_MAIN_P (current_function_decl))
15011 {
15012
15013 #if VMS_TARGET
15014 finish_return_stmt (integer_one_node);
15015 #else
15016 finish_return_stmt (integer_zero_node);
15017 #endif
15018 }
15019
15020
15021 if (flag_exceptions && !processing_template_decl
15022 && flag_enforce_eh_specs
15023 && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl)))
15024 finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
15025 (TREE_TYPE (current_function_decl)),
15026 current_eh_spec_block);
15027 }
15028
15029
15030 finish_stmt_tree (&DECL_SAVED_TREE (fndecl));
15031
15032
15033 if (!processing_template_decl
15034 && !cp_function_chain->can_throw
15035 && !flag_non_call_exceptions)
15036 TREE_NOTHROW (fndecl) = 1;
15037
15038
15039
15040
15041
15042
15043
15044
15045 if (current_binding_level->parm_flag != 1)
15046 {
15047
15048 if (errorcount == 0)
15049 abort ();
15050
15051
15052
15053 DECL_SAVED_TREE (fndecl) = build_stmt (COMPOUND_STMT, NULL_TREE);
15054
15055 while (current_binding_level->parm_flag != 1)
15056 {
15057 if (current_binding_level->parm_flag == 2)
15058 pop_nested_class ();
15059 else
15060 poplevel (0, 0, 0);
15061 }
15062 }
15063 poplevel (1, 0, 1);
15064
15065
15066
15067
15068
15069 if (current_function_return_value)
15070 {
15071 tree r = current_function_return_value;
15072 tree outer;
15073
15074 if (r != error_mark_node
15075 #ifdef KEY
15076
15077
15078
15079
15080 && !current_function_returns_pcc_struct
15081 && struct_value_incoming_rtx == 0
15082 #endif
15083
15084
15085 && aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl)))
15086
15087
15088
15089
15090 && (outer = BLOCK_SUBBLOCKS (DECL_INITIAL (fndecl)),
15091 chain_member (r, BLOCK_VARS (outer))))
15092 {
15093
15094 DECL_ALIGN (r) = DECL_ALIGN (DECL_RESULT (fndecl));
15095 walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl),
15096 nullify_returns_r, r);
15097 }
15098 else
15099 {
15100
15101
15102 current_function_return_value = NULL_TREE;
15103 #ifdef KEY
15104
15105
15106 DECL_NAMED_RETURN_OBJECT (fndecl) = NULL_TREE;
15107 #endif
15108 }
15109 }
15110
15111
15112 if (current_class_name)
15113 ctype = current_class_type;
15114
15115
15116 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
15117
15118
15119
15120 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
15121
15122
15123 if (!processing_template_decl)
15124 save_function_data (fndecl);
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135 if (!processing_template_decl && calls_setjmp_p (fndecl))
15136 DECL_UNINLINABLE (fndecl) = 1;
15137
15138
15139 if (warn_return_type
15140 && !processing_template_decl
15141 && TREE_CODE (TREE_TYPE (fntype)) != VOID_TYPE
15142 && !current_function_returns_value && !current_function_returns_null
15143
15144 && !current_function_returns_abnormally
15145 && !DECL_NAME (DECL_RESULT (fndecl))
15146
15147
15148 && DECL_INLINE (fndecl))
15149 warning ("no return statement in function returning non-void");
15150
15151
15152 free_after_parsing (cfun);
15153
15154
15155 free_after_compilation (cfun);
15156 cfun = NULL;
15157
15158
15159
15160
15161
15162 if (inclass_inline)
15163 maybe_end_member_template_processing ();
15164
15165
15166 if (ctype)
15167 pop_nested_class ();
15168
15169 --function_depth;
15170
15171
15172 if (! nested)
15173
15174
15175
15176 current_function_decl = NULL_TREE;
15177
15178 return fndecl;
15179 }
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202 tree
15203 start_method (declspecs, declarator, attrlist)
15204 tree declarator, declspecs, attrlist;
15205 {
15206 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
15207 &attrlist);
15208
15209
15210 if (fndecl == NULL_TREE)
15211 return NULL_TREE;
15212
15213 if (attrlist)
15214 cplus_decl_attributes (&fndecl, attrlist, 0);
15215
15216
15217 if (fndecl == void_type_node)
15218 return fndecl;
15219
15220 if (TREE_CODE (fndecl) != FUNCTION_DECL)
15221
15222 return NULL_TREE;
15223
15224 if (DECL_IN_AGGR_P (fndecl))
15225 {
15226 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
15227 {
15228 if (DECL_CONTEXT (fndecl)
15229 && TREE_CODE( DECL_CONTEXT (fndecl)) != NAMESPACE_DECL)
15230 error ("`%D' is already defined in class `%T'", fndecl,
15231 DECL_CONTEXT (fndecl));
15232 }
15233 return void_type_node;
15234 }
15235
15236 check_template_shadow (fndecl);
15237
15238 DECL_DECLARED_INLINE_P (fndecl) = 1;
15239
15240 DID_INLINE_FUNC (fndecl) = 0;
15241 if (flag_default_inline)
15242 DECL_INLINE (fndecl) = 1;
15243
15244
15245 if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
15246 fndecl = push_template_decl (fndecl);
15247
15248 if (! DECL_FRIEND_P (fndecl))
15249 {
15250 if (TREE_CHAIN (fndecl))
15251 {
15252 fndecl = copy_node (fndecl);
15253 TREE_CHAIN (fndecl) = NULL_TREE;
15254 }
15255 grok_special_member_properties (fndecl);
15256 }
15257
15258 cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0);
15259
15260
15261 pushlevel (0);
15262 current_binding_level->parm_flag = 1;
15263
15264 DECL_IN_AGGR_P (fndecl) = 1;
15265 return fndecl;
15266 }
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280 tree
15281 finish_method (decl)
15282 tree decl;
15283 {
15284 register tree fndecl = decl;
15285 tree old_initial;
15286
15287 register tree link;
15288
15289 if (decl == void_type_node)
15290 return decl;
15291
15292 old_initial = DECL_INITIAL (fndecl);
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304 for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
15305 {
15306 if (DECL_NAME (link) != NULL_TREE)
15307 pop_binding (DECL_NAME (link), link);
15308 my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
15309 DECL_CONTEXT (link) = NULL_TREE;
15310 }
15311
15312 poplevel (0, 0, 0);
15313
15314 DECL_INITIAL (fndecl) = old_initial;
15315
15316
15317
15318
15319 if (DECL_FRIEND_P (fndecl))
15320 {
15321 CLASSTYPE_INLINE_FRIENDS (current_class_type)
15322 = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
15323 decl = void_type_node;
15324 }
15325
15326 return decl;
15327 }
15328
15329
15330
15331
15332
15333 void
15334 maybe_register_incomplete_var (var)
15335 tree var;
15336 {
15337 my_friendly_assert (TREE_CODE (var) == VAR_DECL, 20020406);
15338
15339
15340 if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
15341 && DECL_EXTERNAL (var))
15342 {
15343 tree inner_type = TREE_TYPE (var);
15344
15345 while (TREE_CODE (inner_type) == ARRAY_TYPE)
15346 inner_type = TREE_TYPE (inner_type);
15347 inner_type = TYPE_MAIN_VARIANT (inner_type);
15348
15349 if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
15350
15351 || (TYPE_LANG_SPECIFIC (inner_type)
15352 && TYPE_BEING_DEFINED (inner_type)))
15353 incomplete_vars = tree_cons (inner_type, var, incomplete_vars);
15354 }
15355 }
15356
15357
15358
15359
15360
15361 void
15362 complete_vars (type)
15363 tree type;
15364 {
15365 tree *list = &incomplete_vars;
15366
15367 my_friendly_assert (CLASS_TYPE_P (type), 20020406);
15368 while (*list)
15369 {
15370 if (same_type_p (type, TREE_PURPOSE (*list)))
15371 {
15372 tree var = TREE_VALUE (*list);
15373
15374
15375 complete_type (TREE_TYPE (var));
15376
15377 *list = TREE_CHAIN (*list);
15378 }
15379 else
15380 list = &TREE_CHAIN (*list);
15381 }
15382 }
15383
15384
15385
15386
15387 tree
15388 cxx_maybe_build_cleanup (decl)
15389 tree decl;
15390 {
15391 tree type = TREE_TYPE (decl);
15392
15393 if (type != error_mark_node && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
15394 {
15395 int flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
15396 tree rval;
15397
15398 if (TREE_CODE (type) == ARRAY_TYPE)
15399 rval = decl;
15400 else
15401 {
15402 cxx_mark_addressable (decl);
15403 rval = build_unary_op (ADDR_EXPR, decl, 0);
15404 }
15405
15406
15407 if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
15408 || flag_expensive_optimizations)
15409 flags |= LOOKUP_NONVIRTUAL;
15410
15411 rval = build_delete (TREE_TYPE (rval), rval,
15412 sfk_complete_destructor, flags, 0);
15413
15414 if (TYPE_USES_VIRTUAL_BASECLASSES (type)
15415 && ! TYPE_HAS_DESTRUCTOR (type))
15416 rval = build_compound_expr (tree_cons (NULL_TREE, rval,
15417 build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
15418
15419 return rval;
15420 }
15421 return NULL_TREE;
15422 }
15423
15424
15425
15426 void
15427 finish_stmt ()
15428 {
15429
15430
15431
15432 last_expr_type = NULL_TREE;
15433 }
15434
15435
15436
15437
15438 void
15439 revert_static_member_fn (decl)
15440 tree decl;
15441 {
15442 tree tmp;
15443 tree function = TREE_TYPE (decl);
15444 tree args = TYPE_ARG_TYPES (function);
15445
15446 if (cp_type_quals (TREE_TYPE (TREE_VALUE (args)))
15447 != TYPE_UNQUALIFIED)
15448 error ("static member function `%#D' declared with type qualifiers",
15449 decl);
15450
15451 args = TREE_CHAIN (args);
15452 tmp = build_function_type (TREE_TYPE (function), args);
15453 tmp = build_qualified_type (tmp, cp_type_quals (function));
15454 tmp = build_exception_variant (tmp,
15455 TYPE_RAISES_EXCEPTIONS (function));
15456 TREE_TYPE (decl) = tmp;
15457 if (DECL_ARGUMENTS (decl))
15458 DECL_ARGUMENTS (decl) = TREE_CHAIN (DECL_ARGUMENTS (decl));
15459 DECL_STATIC_FUNCTION_P (decl) = 1;
15460 }
15461
15462
15463
15464
15465 void
15466 cxx_push_function_context (f)
15467 struct function *f;
15468 {
15469 struct language_function *p
15470 = ((struct language_function *)
15471 ggc_alloc_cleared (sizeof (struct language_function)));
15472 f->language = p;
15473
15474
15475
15476 expanding_p = 0;
15477
15478
15479
15480 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
15481 }
15482
15483
15484
15485
15486 void
15487 cxx_pop_function_context (f)
15488 struct function *f;
15489 {
15490 f->language = 0;
15491 }
15492
15493
15494
15495
15496 enum cp_tree_node_structure_enum
15497 cp_tree_node_structure (t)
15498 union lang_tree_node *t;
15499 {
15500 switch (TREE_CODE (&t->generic))
15501 {
15502 case DEFAULT_ARG: return TS_CP_IDENTIFIER;
15503 case IDENTIFIER_NODE: return TS_CP_IDENTIFIER;
15504 case OVERLOAD: return TS_CP_OVERLOAD;
15505 case TEMPLATE_PARM_INDEX: return TS_CP_TPI;
15506 case PTRMEM_CST: return TS_CP_PTRMEM;
15507 case WRAPPER: return TS_CP_WRAPPER;
15508 case SRCLOC: return TS_CP_SRCLOC;
15509 default: return TS_CP_GENERIC;
15510 }
15511 }
15512
15513
15514
15515
15516 tree
15517 identifier_global_value (t)
15518 tree t;
15519 {
15520 return IDENTIFIER_GLOBAL_VALUE (t);
15521 }
15522
15523
15524 tree
15525 build_void_list_node ()
15526 {
15527 tree t = build_tree_list (NULL_TREE, void_type_node);
15528 TREE_PARMLIST (t) = 1;
15529 return t;
15530 }
15531
15532 static int
15533 cp_missing_noreturn_ok_p (decl)
15534 tree decl;
15535 {
15536
15537 return DECL_MAIN_P (decl);
15538 }
15539
15540 #include "gt-cp-decl.h"
15541 #include "gtype-cp.h"