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 =