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 #include "config.h"
00032 #include "system.h"
00033 #include "tree.h"
00034 #include "rtl.h"
00035 #include "expr.h"
00036 #include "flags.h"
00037 #include "cp-tree.h"
00038 #include "tree-inline.h"
00039 #include "decl.h"
00040 #include "lex.h"
00041 #include "output.h"
00042 #include "except.h"
00043 #include "toplev.h"
00044 #include "hashtab.h"
00045 #include "ggc.h"
00046 #include "tm_p.h"
00047 #include "target.h"
00048 #include "c-common.h"
00049 #include "c-pragma.h"
00050 #include "diagnostic.h"
00051 #include "debug.h"
00052 #include "timevar.h"
00053 #include "input.h"
00054
00055 static tree grokparms PARAMS ((tree));
00056 static const char *redeclaration_error_message PARAMS ((tree, tree));
00057
00058 static void push_binding_level PARAMS ((struct cp_binding_level *, int,
00059 int));
00060 static void pop_binding_level PARAMS ((void));
00061 static void suspend_binding_level PARAMS ((void));
00062 static void resume_binding_level PARAMS ((struct cp_binding_level *));
00063 static struct cp_binding_level *make_binding_level PARAMS ((void));
00064 static void declare_namespace_level PARAMS ((void));
00065 static int decl_jump_unsafe PARAMS ((tree));
00066 static void storedecls PARAMS ((tree));
00067 static void require_complete_types_for_parms PARAMS ((tree));
00068 static int ambi_op_p PARAMS ((enum tree_code));
00069 static int unary_op_p PARAMS ((enum tree_code));
00070 static cxx_saved_binding *store_bindings (tree, cxx_saved_binding *);
00071 static tree lookup_tag_reverse PARAMS ((tree, tree));
00072 static tree lookup_name_real PARAMS ((tree, int, int, int));
00073 static void push_local_name PARAMS ((tree));
00074 static void warn_extern_redeclared_static PARAMS ((tree, tree));
00075 static tree grok_reference_init PARAMS ((tree, tree, tree, tree *));
00076 static tree grokfndecl PARAMS ((tree, tree, tree, tree, int,
00077 enum overload_flags, tree,
00078 tree, int, int, int, int, int, int, tree));
00079 static tree grokvardecl PARAMS ((tree, tree, RID_BIT_TYPE *, int, int, tree));
00080 static tree follow_tag_typedef PARAMS ((tree));
00081 static tree lookup_tag PARAMS ((enum tree_code, tree,
00082 struct cp_binding_level *, int));
00083 static void set_identifier_type_value_with_scope
00084 PARAMS ((tree, tree, struct cp_binding_level *));
00085 static void record_unknown_type PARAMS ((tree, const char *));
00086 static tree builtin_function_1 PARAMS ((const char *, tree, tree, int,
00087 enum built_in_class, const char *,
00088 tree));
00089 static tree build_library_fn_1 PARAMS ((tree, enum tree_code, tree));
00090 static int member_function_or_else PARAMS ((tree, tree, enum overload_flags));
00091 static void bad_specifiers PARAMS ((tree, const char *, int, int, int, int,
00092 int));
00093 static tree maybe_process_template_type_declaration PARAMS ((tree, int, struct cp_binding_level*));
00094 static void check_for_uninitialized_const_var PARAMS ((tree));
00095 static hashval_t typename_hash PARAMS ((const void *));
00096 static int typename_compare PARAMS ((const void *, const void *));
00097 static void push_binding PARAMS ((tree, tree, struct cp_binding_level*));
00098 static int add_binding PARAMS ((tree, tree));
00099 static void pop_binding PARAMS ((tree, tree));
00100 static tree local_variable_p_walkfn PARAMS ((tree *, int *, void *));
00101 static cxx_binding *find_binding (tree, tree, cxx_binding *);
00102 static tree select_decl (cxx_binding *, int);
00103 static int lookup_flags PARAMS ((int, int));
00104 static tree qualify_lookup PARAMS ((tree, int));
00105 static tree record_builtin_java_type PARAMS ((const char *, int));
00106 static const char *tag_name PARAMS ((enum tag_types code));
00107 static void find_class_binding_level PARAMS ((void));
00108 static struct cp_binding_level *innermost_nonclass_level PARAMS ((void));
00109 static void warn_about_implicit_typename_lookup PARAMS ((tree, tree));
00110 static int walk_namespaces_r PARAMS ((tree, walk_namespaces_fn, void *));
00111 static int walk_globals_r PARAMS ((tree, void *));
00112 static int walk_vtables_r PARAMS ((tree, void*));
00113 static void add_decl_to_level PARAMS ((tree, struct cp_binding_level *));
00114 static tree make_label_decl PARAMS ((tree, int));
00115 static void use_label PARAMS ((tree));
00116 static void check_previous_goto_1 PARAMS ((tree, struct cp_binding_level *, tree,
00117 const char *, int));
00118 static void check_previous_goto PARAMS ((struct named_label_use_list *));
00119 static void check_switch_goto PARAMS ((struct cp_binding_level *));
00120 static void check_previous_gotos PARAMS ((tree));
00121 static void pop_label PARAMS ((tree, tree));
00122 static void pop_labels PARAMS ((tree));
00123 static void maybe_deduce_size_from_array_init PARAMS ((tree, tree));
00124 static void layout_var_decl PARAMS ((tree));
00125 static void maybe_commonize_var PARAMS ((tree));
00126 static tree check_initializer (tree, tree, int, tree *);
00127 static void make_rtl_for_nonlocal_decl PARAMS ((tree, tree, const char *));
00128 static void save_function_data PARAMS ((tree));
00129 static void check_function_type PARAMS ((tree, tree));
00130 static void begin_constructor_body PARAMS ((void));
00131 static void finish_constructor_body PARAMS ((void));
00132 static void begin_destructor_body PARAMS ((void));
00133 static void finish_destructor_body PARAMS ((void));
00134 static tree create_array_type_for_decl PARAMS ((tree, tree, tree));
00135 static tree get_atexit_node PARAMS ((void));
00136 static tree get_dso_handle_node PARAMS ((void));
00137 static tree start_cleanup_fn PARAMS ((void));
00138 static void end_cleanup_fn PARAMS ((void));
00139 static tree cp_make_fname_decl PARAMS ((tree, int));
00140 static void initialize_predefined_identifiers PARAMS ((void));
00141 static tree check_special_function_return_type
00142 PARAMS ((special_function_kind, tree, tree));
00143 static tree push_cp_library_fn PARAMS ((enum tree_code, tree));
00144 static tree build_cp_library_fn PARAMS ((tree, enum tree_code, tree));
00145 static void store_parm_decls PARAMS ((tree));
00146 static int cp_missing_noreturn_ok_p PARAMS ((tree));
00147 static void initialize_local_var (tree, tree);
00148 static void expand_static_init (tree, tree);
00149 static tree next_initializable_field (tree);
00150 static tree reshape_init (tree, tree *);
00151
00152
00153 tree error_mark_list;
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
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 tree cp_global_trees[CPTI_MAX];
00201
00202
00203
00204
00205 static GTY(()) tree global_type_node;
00206
00207
00208 static int only_namespace_names;
00209
00210
00211
00212
00213 struct named_label_use_list GTY(())
00214 {
00215 struct cp_binding_level *binding_level;
00216 tree names_in_scope;
00217 tree label_decl;
00218 const char *filename_o_goto;
00219 int lineno_o_goto;
00220 struct named_label_use_list *next;
00221 };
00222
00223 #define named_label_uses cp_function_chain->x_named_label_uses
00224
00225 #define local_names cp_function_chain->x_local_names
00226
00227
00228
00229
00230
00231 tree static_aggregates;
00232
00233
00234
00235
00236
00237 tree integer_two_node, integer_three_node;
00238
00239
00240 tree last_function_parms;
00241
00242
00243
00244
00245
00246 struct named_label_list GTY(())
00247 {
00248 struct cp_binding_level *binding_level;
00249 tree names_in_scope;
00250 tree old_value;
00251 tree label_decl;
00252 tree bad_decls;
00253 struct named_label_list *next;
00254 unsigned int in_try_scope : 1;
00255 unsigned int in_catch_scope : 1;
00256 };
00257
00258 #define named_labels cp_function_chain->x_named_labels
00259
00260
00261
00262 tree anonymous_namespace_name;
00263
00264
00265
00266
00267 int function_depth;
00268
00269
00270
00271
00272
00273
00274 enum deprecated_states {
00275 DEPRECATED_NORMAL,
00276 DEPRECATED_SUPPRESS
00277 };
00278
00279 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
00280
00281
00282
00283
00284 int adding_implicit_members = 0;
00285
00286
00287
00288 bool have_extern_spec;
00289
00290
00291
00292
00293
00294 #define ENTRY_INDEX(HASH, COUNT) (((HASH) >> 3) & ((COUNT) - 1))
00295
00296
00297 static GTY((deletable(""))) binding_entry free_binding_entry;
00298
00299
00300 static inline binding_entry
00301 binding_entry_make (tree name, tree type)
00302 {
00303 binding_entry entry;
00304
00305 if (free_binding_entry)
00306 {
00307 entry = free_binding_entry;
00308 free_binding_entry = entry->chain;
00309 }
00310 else
00311 entry = ggc_alloc (sizeof (struct binding_entry_s));
00312
00313 entry->name = name;
00314 entry->type = type;
00315
00316 return entry;
00317 }
00318
00319
00320 static inline void
00321 binding_entry_free (binding_entry entry)
00322 {
00323 entry->chain = free_binding_entry;
00324 free_binding_entry = entry;
00325 }
00326
00327
00328
00329 struct binding_table_s GTY(())
00330 {
00331
00332 binding_entry * GTY((length ("%h.chain_count"))) chain;
00333
00334
00335
00336 size_t chain_count;
00337
00338
00339 size_t entry_count;
00340 };
00341
00342
00343 #define SCOPE_DEFAULT_HT_SIZE (1 << 3)
00344 #define CLASS_SCOPE_HT_SIZE (1 << 3)
00345 #define NAMESPACE_ORDINARY_HT_SIZE (1 << 5)
00346 #define NAMESPACE_STD_HT_SIZE (1 << 8)
00347 #define GLOBAL_SCOPE_HT_SIZE (1 << 8)
00348
00349
00350 static inline void
00351 binding_table_construct (binding_table table, size_t chain_count)
00352 {
00353 table->chain_count = chain_count;
00354 table->entry_count = 0;
00355 table->chain = ggc_alloc_cleared
00356 (table->chain_count * sizeof (binding_entry));
00357 }
00358
00359
00360 static inline void
00361 binding_table_free (binding_table table)
00362 {
00363 size_t i;
00364 if (table == NULL)
00365 return;
00366
00367 for (i = 0; i < table->chain_count; ++i)
00368 {
00369 while (table->chain[i] != NULL)
00370 {
00371 binding_entry entry = table->chain[i];
00372 table->chain[i] = entry->chain;
00373 binding_entry_free (entry);
00374 }
00375 }
00376 table->entry_count = 0;
00377 }
00378
00379
00380 static inline binding_table
00381 binding_table_new (size_t chain_count)
00382 {
00383 binding_table table = ggc_alloc (sizeof (struct binding_table_s));
00384 binding_table_construct (table, chain_count);
00385 return table;
00386 }
00387
00388
00389 static void
00390 binding_table_expand (binding_table table)
00391 {
00392 const size_t old_chain_count = table->chain_count;
00393 const size_t old_entry_count = table->entry_count;
00394 const size_t new_chain_count = 2 * old_chain_count;
00395 binding_entry *old_chains = table->chain;
00396 size_t i;
00397
00398 binding_table_construct (table, new_chain_count);
00399 for (i = 0; i < old_chain_count; ++i)
00400 {
00401 binding_entry entry = old_chains[i];
00402 for (; entry != NULL; entry = old_chains[i])
00403 {
00404 const unsigned int hash = IDENTIFIER_HASH_VALUE (entry->name);
00405 const size_t j = ENTRY_INDEX (hash, new_chain_count);
00406
00407 old_chains[i] = entry->chain;
00408 entry->chain = table->chain[j];
00409 table->chain[j] = entry;
00410 }
00411 }
00412 table->entry_count = old_entry_count;
00413 }
00414
00415
00416 static inline void
00417 binding_table_insert (binding_table table, tree name, tree type)
00418 {
00419 const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
00420 const size_t i = ENTRY_INDEX (hash, table->chain_count);
00421 binding_entry entry = binding_entry_make (name, type);
00422
00423 entry->chain = table->chain[i];
00424 table->chain[i] = entry;
00425 ++table->entry_count;
00426
00427 if (3 * table->chain_count < 5 * table->entry_count)
00428 binding_table_expand (table);
00429 }
00430
00431
00432 binding_entry
00433 binding_table_find (binding_table table, tree name)
00434 {
00435 const unsigned int hash = IDENTIFIER_HASH_VALUE (name);
00436 binding_entry entry = table->chain[ENTRY_INDEX (hash, table->chain_count)];
00437
00438 while (entry != NULL && entry->name != name)
00439 entry = entry->chain;
00440
00441 return entry;
00442 }
00443
00444
00445 static inline tree
00446 binding_table_find_anon_type (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 && TYPE_IDENTIFIER (entry->type) != name)
00452 entry = entry->chain;
00453
00454 return entry ? entry->type : NULL;
00455 }
00456
00457
00458
00459 static inline binding_entry
00460 binding_table_reverse_maybe_remap (binding_table table, tree type, tree name)
00461 {
00462 const size_t chain_count = table->chain_count;
00463 binding_entry entry = NULL;
00464 binding_entry *p = NULL;
00465 size_t i;
00466
00467 for (i = 0; i < chain_count && entry == NULL; ++i)
00468 {
00469 p = &table->chain[i];
00470 while (*p != NULL && entry == NULL)
00471 if ((*p)->type == type)
00472 entry = *p;
00473 else
00474 p = &(*p)->chain;
00475 }
00476
00477 if (entry != NULL && name != NULL && entry->name != name)
00478 {
00479
00480 *p = (*p)->chain;
00481
00482
00483 i = ENTRY_INDEX (IDENTIFIER_HASH_VALUE (name), chain_count);
00484 entry->chain = table->chain[i];
00485 entry->name = name;
00486 table->chain[i] = entry;
00487 }
00488
00489 return entry;
00490 }
00491
00492
00493
00494 static void
00495 binding_table_remove_anonymous_types (binding_table table)
00496 {
00497 const size_t chain_count = table->chain_count;
00498 size_t i;
00499
00500 for (i = 0; i < chain_count; ++i)
00501 {
00502 binding_entry *p = &table->chain[i];
00503
00504 while (*p != NULL)
00505 if (ANON_AGGRNAME_P ((*p)->name))
00506 {
00507 binding_entry e = *p;
00508 *p = (*p)->chain;
00509 --table->entry_count;
00510 binding_entry_free (e);
00511 }
00512 else
00513 p = &(*p)->chain;
00514 }
00515 }
00516
00517
00518 void
00519 binding_table_foreach (binding_table table, bt_foreach_proc proc, void *data)
00520 {
00521 const size_t chain_count = table->chain_count;
00522 size_t i;
00523
00524 for (i = 0; i < chain_count; ++i)
00525 {
00526 binding_entry entry = table->chain[i];
00527 for (; entry != NULL; entry = entry->chain)
00528 proc (entry, data);
00529 }
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557 struct cp_binding_level GTY(())
00558 {
00559
00560
00561
00562
00563 tree names;
00564
00565
00566 size_t names_size;
00567
00568
00569 tree namespaces;
00570
00571
00572 varray_type static_decls;
00573
00574
00575 tree vtables;
00576
00577
00578 binding_table type_decls;
00579
00580
00581 tree usings;
00582
00583
00584
00585 tree using_directives;
00586
00587
00588
00589
00590
00591 tree class_shadowed;
00592
00593
00594
00595
00596 tree type_shadowed;
00597
00598
00599
00600
00601 tree shadowed_labels;
00602
00603
00604
00605
00606 tree blocks;
00607
00608
00609 tree this_class;
00610
00611
00612 struct cp_binding_level *level_chain;
00613
00614
00615
00616
00617
00618 tree dead_vars_from_for;
00619
00620
00621
00622 unsigned parm_flag : 2;
00623
00624
00625
00626 unsigned keep : 2;
00627
00628
00629 unsigned tag_transparent : 1;
00630
00631
00632
00633 unsigned more_cleanups_ok : 1;
00634 unsigned have_cleanups : 1;
00635
00636
00637
00638
00639 unsigned template_parms_p : 1;
00640
00641
00642
00643
00644 unsigned template_spec_p : 1;
00645
00646
00647 unsigned namespace_p : 1;
00648
00649
00650
00651 unsigned is_for_scope : 1;
00652
00653
00654
00655 unsigned is_try_scope : 1;
00656
00657
00658
00659 unsigned is_catch_scope : 1;
00660
00661
00662
00663
00664 unsigned binding_depth;
00665 };
00666
00667 #define NULL_BINDING_LEVEL ((struct cp_binding_level *) NULL)
00668
00669
00670 #define global_scope_p(SCOPE) \
00671 ((SCOPE) == NAMESPACE_LEVEL (global_namespace))
00672
00673
00674
00675 #define current_binding_level \
00676 (cfun && cp_function_chain->bindings \
00677 ? cp_function_chain->bindings \
00678 : scope_chain->bindings)
00679
00680
00681
00682 #define class_binding_level scope_chain->class_bindings
00683
00684
00685
00686 static GTY((deletable (""))) struct cp_binding_level *free_binding_level;
00687
00688
00689
00690 static int keep_next_level_flag;
00691
00692
00693
00694
00695
00696 static GTY(()) tree incomplete_vars;
00697
00698 #ifndef ENABLE_SCOPE_CHECKING
00699 # define ENABLE_SCOPE_CHECKING 0
00700 #else
00701 # define ENABLE_SCOPE_CHECKING 1
00702 #endif
00703
00704 static unsigned binding_depth = 0;
00705 static int is_class_level = 0;
00706
00707 static void
00708 indent (unsigned depth)
00709 {
00710 unsigned i;
00711
00712 for (i = 0; i < depth * 2; i++)
00713 putc (' ', stderr);
00714 }
00715
00716 static tree pushdecl_with_scope PARAMS ((tree, struct cp_binding_level *));
00717
00718 static void
00719 push_binding_level (newlevel, tag_transparent, keep)
00720 struct cp_binding_level *newlevel;
00721 int tag_transparent, keep;
00722 {
00723
00724
00725 memset ((char*) newlevel, 0, sizeof (struct cp_binding_level));
00726 newlevel->level_chain = current_binding_level;
00727 current_binding_level = newlevel;
00728 newlevel->tag_transparent = tag_transparent;
00729 newlevel->more_cleanups_ok = 1;
00730
00731 newlevel->keep = keep;
00732 if (ENABLE_SCOPE_CHECKING)
00733 {
00734 newlevel->binding_depth = binding_depth;
00735 indent (binding_depth);
00736 verbatim ("push %s level %p line %d\n",
00737 (is_class_level) ? "class" : "block",
00738 (void *) newlevel, lineno);
00739 is_class_level = 0;
00740 binding_depth++;
00741 }
00742 }
00743
00744
00745
00746
00747 static void
00748 find_class_binding_level ()
00749 {
00750 struct cp_binding_level *level = current_binding_level;
00751
00752 while (level && level->parm_flag != 2)
00753 level = level->level_chain;
00754 if (level && level->parm_flag == 2)
00755 class_binding_level = level;
00756 else
00757 class_binding_level = 0;
00758 }
00759
00760 static void
00761 pop_binding_level ()
00762 {
00763 if (NAMESPACE_LEVEL (global_namespace))
00764
00765 my_friendly_assert (!global_scope_p (current_binding_level), 20030527);
00766
00767 if (ENABLE_SCOPE_CHECKING)
00768 {
00769 indent (--binding_depth);
00770 verbatim ("pop %s level %p line %d\n",
00771 (is_class_level) ? "class" : "block",
00772 (void *) current_binding_level, lineno);
00773 if (is_class_level != (current_binding_level == class_binding_level))
00774 {
00775 indent (binding_depth);
00776 verbatim ("XXX is_class_level != (current_binding_level "
00777 "== class_binding_level)\n");
00778 }
00779 is_class_level = 0;
00780 }
00781 {
00782 register struct cp_binding_level *level = current_binding_level;
00783 current_binding_level = current_binding_level->level_chain;
00784 level->level_chain = free_binding_level;
00785 if (level->parm_flag != 2)
00786 binding_table_free (level->type_decls);
00787 else
00788 level->type_decls = NULL;
00789 my_friendly_assert (!ENABLE_SCOPE_CHECKING
00790 || level->binding_depth == binding_depth, 20030529);
00791 free_binding_level = level;
00792 find_class_binding_level ();
00793 }
00794 }
00795
00796 static void
00797 suspend_binding_level ()
00798 {
00799 if (class_binding_level)
00800 current_binding_level = class_binding_level;
00801
00802 if (NAMESPACE_LEVEL (global_namespace))
00803 my_friendly_assert (!global_scope_p (current_binding_level), 20030527);
00804
00805 if (ENABLE_SCOPE_CHECKING)
00806 {
00807 indent (--binding_depth);
00808 verbatim("suspend %s level %p line %d\n",
00809 (is_class_level) ? "class" : "block",
00810 (void *) current_binding_level, lineno);
00811 if (is_class_level != (current_binding_level == class_binding_level))
00812 {
00813 indent (binding_depth);
00814 verbatim ("XXX is_class_level != (current_binding_level "
00815 "== class_binding_level)\n");
00816 }
00817 is_class_level = 0;
00818 }
00819 current_binding_level = current_binding_level->level_chain;
00820 find_class_binding_level ();
00821 }
00822
00823 static void
00824 resume_binding_level (b)
00825 struct cp_binding_level *b;
00826 {
00827
00828
00829 my_friendly_assert(!class_binding_level, 386);
00830
00831 my_friendly_assert(b->level_chain == current_binding_level, 386);
00832 current_binding_level = b;
00833 if (ENABLE_SCOPE_CHECKING)
00834 {
00835 b->binding_depth = binding_depth;
00836 indent (binding_depth);
00837 verbatim ("resume %s level %p line %d\n",
00838 (is_class_level) ? "class" : "block", (void *) b, lineno);
00839 is_class_level = 0;
00840 binding_depth++;
00841 }
00842 }
00843
00844
00845
00846 static
00847 struct cp_binding_level *
00848 make_binding_level ()
00849 {
00850
00851 return (struct cp_binding_level *) ggc_alloc (sizeof (struct cp_binding_level));
00852 }
00853
00854
00855
00856 int
00857 global_bindings_p ()
00858 {
00859 return global_scope_p (current_binding_level);
00860 }
00861
00862
00863
00864 static struct cp_binding_level *
00865 innermost_nonclass_level ()
00866 {
00867 struct cp_binding_level *b;
00868
00869 b = current_binding_level;
00870 while (b->parm_flag == 2)
00871 b = b->level_chain;
00872
00873 return b;
00874 }
00875
00876
00877
00878
00879
00880
00881
00882 int
00883 toplevel_bindings_p ()
00884 {
00885 struct cp_binding_level *b = innermost_nonclass_level ();
00886
00887 return b->namespace_p || b->template_parms_p;
00888 }
00889
00890
00891
00892
00893
00894 int
00895 namespace_bindings_p ()
00896 {
00897 struct cp_binding_level *b = innermost_nonclass_level ();
00898
00899 return b->namespace_p;
00900 }
00901
00902
00903
00904
00905
00906 void
00907 keep_next_level (keep)
00908 int keep;
00909 {
00910 keep_next_level_flag = keep;
00911 }
00912
00913
00914
00915 int
00916 kept_level_p ()
00917 {
00918 return (current_binding_level->blocks != NULL_TREE
00919 || current_binding_level->keep
00920 || current_binding_level->names != NULL_TREE
00921 || (current_binding_level->type_decls != NULL
00922 && !current_binding_level->tag_transparent));
00923 }
00924
00925
00926
00927 bool
00928 innermost_scope_is_class_p ()
00929 {
00930 return current_binding_level->parm_flag == 2;
00931 }
00932
00933 static void
00934 declare_namespace_level ()
00935 {
00936 current_binding_level->namespace_p = 1;
00937 }
00938
00939
00940
00941
00942 int
00943 template_parm_scope_p ()
00944 {
00945 return current_binding_level->template_parms_p;
00946 }
00947
00948
00949
00950
00951
00952 tmpl_spec_kind
00953 current_tmpl_spec_kind (n_class_scopes)
00954 int n_class_scopes;
00955 {
00956 int n_template_parm_scopes = 0;
00957 int seen_specialization_p = 0;
00958 int innermost_specialization_p = 0;
00959 struct cp_binding_level *b;
00960
00961
00962 for (b = current_binding_level; b->template_parms_p; b = b->level_chain)
00963 {
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973 if (b->template_spec_p)
00974 {
00975 if (n_template_parm_scopes == 0)
00976 innermost_specialization_p = 1;
00977 else
00978 seen_specialization_p = 1;
00979 }
00980 else if (seen_specialization_p == 1)
00981 return tsk_invalid_member_spec;
00982
00983 ++n_template_parm_scopes;
00984 }
00985
00986
00987 if (processing_explicit_instantiation)
00988 {
00989 if (n_template_parm_scopes != 0)
00990
00991
00992
00993
00994
00995
00996 return tsk_invalid_expl_inst;
00997 else
00998 return tsk_expl_inst;
00999 }
01000
01001 if (n_template_parm_scopes < n_class_scopes)
01002
01003
01004
01005
01006
01007
01008
01009 return tsk_insufficient_parms;
01010 else if (n_template_parm_scopes == n_class_scopes)
01011
01012
01013
01014
01015
01016
01017
01018 return tsk_none;
01019 else if (n_template_parm_scopes > n_class_scopes + 1)
01020
01021
01022
01023
01024
01025 return tsk_excessive_parms;
01026 else
01027
01028
01029
01030
01031
01032
01033
01034 return innermost_specialization_p ? tsk_expl_spec : tsk_template;
01035 }
01036
01037 void
01038 set_class_shadows (shadows)
01039 tree shadows;
01040 {
01041 class_binding_level->class_shadowed = shadows;
01042 }
01043
01044
01045
01046
01047
01048 void
01049 pushlevel (tag_transparent)
01050 int tag_transparent;
01051 {
01052 struct cp_binding_level *newlevel;
01053
01054 if (cfun && !doing_semantic_analysis_p ())
01055 return;
01056
01057
01058 if (!ENABLE_SCOPE_CHECKING && free_binding_level)
01059 {
01060 newlevel = free_binding_level;
01061 free_binding_level = free_binding_level->level_chain;
01062 }
01063 else
01064 newlevel = make_binding_level ();
01065
01066 push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
01067 keep_next_level_flag = 0;
01068 }
01069
01070
01071
01072
01073
01074 void
01075 maybe_push_cleanup_level (type)
01076 tree type;
01077 {
01078 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
01079 && current_binding_level->more_cleanups_ok == 0)
01080 {
01081 keep_next_level (2);
01082 pushlevel (1);
01083 clear_last_expr ();
01084 add_scope_stmt (1, 1);
01085 }
01086 }
01087
01088
01089
01090
01091 void
01092 begin_scope (sk)
01093 scope_kind sk;
01094 {
01095 pushlevel (0);
01096
01097 switch (sk)
01098 {
01099 case sk_template_spec:
01100 current_binding_level->template_spec_p = 1;
01101
01102
01103 case sk_template_parms:
01104 current_binding_level->template_parms_p = 1;
01105 break;
01106
01107 default:
01108 abort ();
01109 }
01110 }
01111
01112
01113
01114 void
01115 finish_scope ()
01116 {
01117 poplevel (0, 0, 0);
01118 }
01119
01120 void
01121 note_level_for_for ()
01122 {
01123 current_binding_level->is_for_scope = 1;
01124 }
01125
01126
01127
01128 void
01129 note_level_for_try ()
01130 {
01131 current_binding_level->is_try_scope = 1;
01132 }
01133
01134
01135
01136 void
01137 note_level_for_catch ()
01138 {
01139 current_binding_level->is_catch_scope = 1;
01140 }
01141
01142
01143
01144 #define BINDING_LEVEL(NODE) ((NODE)->scope.level)
01145
01146
01147
01148 static GTY((deletable (""))) cxx_binding *free_bindings;
01149
01150
01151
01152
01153 static void
01154 push_binding (id, decl, level)
01155 tree id;
01156 tree decl;
01157 struct cp_binding_level* level;
01158 {
01159 cxx_binding *binding;
01160
01161 if (free_bindings)
01162 {
01163 binding = free_bindings;
01164 free_bindings = binding->previous;
01165 }
01166 else
01167 binding = cxx_binding_make ();
01168
01169
01170 BINDING_VALUE (binding) = decl;
01171 BINDING_TYPE (binding) = NULL_TREE;
01172 BINDING_LEVEL (binding) = level;
01173 INHERITED_VALUE_BINDING_P (binding) = 0;
01174 LOCAL_BINDING_P (binding) = (level != class_binding_level);
01175 BINDING_HAS_LEVEL_P (binding) = 1;
01176
01177
01178 binding->previous = IDENTIFIER_BINDING (id);
01179 IDENTIFIER_BINDING (id) = binding;
01180 }
01181
01182
01183
01184
01185
01186
01187
01188 static int
01189 add_binding (id, decl)
01190 tree id;
01191 tree decl;
01192 {
01193 cxx_binding *binding = IDENTIFIER_BINDING (id);
01194 int ok = 1;
01195
01196 timevar_push (TV_NAME_LOOKUP);
01197 if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl))
01198
01199 BINDING_TYPE (binding) = decl;
01200 else if (!BINDING_VALUE (binding))
01201
01202
01203
01204 BINDING_VALUE (binding) = decl;
01205 else if (TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL
01206 && DECL_ARTIFICIAL (BINDING_VALUE (binding)))
01207 {
01208
01209
01210
01211
01212
01213 BINDING_TYPE (binding) = BINDING_VALUE (binding);
01214 BINDING_VALUE (binding) = decl;
01215 INHERITED_VALUE_BINDING_P (binding) = 0;
01216 }
01217 else if (TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL
01218 && TREE_CODE (decl) == TYPE_DECL
01219 && DECL_NAME (decl) == DECL_NAME (BINDING_VALUE (binding))
01220 && (same_type_p (TREE_TYPE (decl),
01221 TREE_TYPE (BINDING_VALUE (binding)))
01222
01223
01224 || uses_template_parms (TREE_TYPE (decl))
01225 || uses_template_parms (TREE_TYPE (BINDING_VALUE (binding)))))
01226
01227
01228
01229
01230
01231
01232
01233
01234 ok = 0;
01235
01236
01237
01238
01239
01240
01241
01242
01243 else if (TREE_CODE (decl) == VAR_DECL
01244 && TREE_CODE (BINDING_VALUE (binding)) == VAR_DECL
01245 && DECL_EXTERNAL (decl)
01246 && DECL_EXTERNAL (BINDING_VALUE (binding))
01247 && !DECL_CLASS_SCOPE_P (decl))
01248 {
01249 duplicate_decls (decl, BINDING_VALUE (binding));
01250 ok = 0;
01251 }
01252 else
01253 {
01254 error ("declaration of `%#D'", decl);
01255 cp_error_at ("conflicts with previous declaration `%#D'",
01256 BINDING_VALUE (binding));
01257 ok = 0;
01258 }
01259
01260 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ok);
01261 }
01262
01263
01264
01265 static void
01266 add_decl_to_level (decl, b)
01267 tree decl;
01268 struct cp_binding_level *b;
01269 {
01270 if (TREE_CODE (decl) == NAMESPACE_DECL
01271 && !DECL_NAMESPACE_ALIAS (decl))
01272 {
01273 TREE_CHAIN (decl) = b->namespaces;
01274 b->namespaces = decl;
01275 }
01276 else if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
01277 {
01278 TREE_CHAIN (decl) = b->vtables;
01279 b->vtables = decl;
01280 }
01281 else
01282 {
01283
01284
01285 TREE_CHAIN (decl) = b->names;
01286 b->names = decl;
01287 b->names_size++;
01288
01289
01290 if (b->namespace_p)
01291 if ((TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
01292 || (TREE_CODE (decl) == FUNCTION_DECL
01293 && (!TREE_PUBLIC (decl) || DECL_DECLARED_INLINE_P (decl))))
01294 VARRAY_PUSH_TREE (b->static_decls, decl);
01295 }
01296 }
01297
01298
01299
01300
01301
01302
01303 void
01304 push_local_binding (id, decl, flags)
01305 tree id;
01306 tree decl;
01307 int flags;
01308 {
01309 struct cp_binding_level *b;
01310
01311
01312
01313 b = current_binding_level;
01314 while (b->parm_flag == 2)
01315 b = b->level_chain;
01316
01317 if (lookup_name_current_level (id))
01318 {
01319
01320 if (!add_binding (id, decl))
01321
01322
01323
01324 return;
01325 }
01326 else
01327
01328 push_binding (id, decl, b);
01329
01330 if (TREE_CODE (decl) == OVERLOAD || (flags & PUSH_USING))
01331
01332
01333
01334 decl = build_tree_list (NULL_TREE, decl);
01335
01336
01337
01338 add_decl_to_level (decl, b);
01339 }
01340
01341
01342
01343
01344 int
01345 push_class_binding (id, decl)
01346 tree id;
01347 tree decl;
01348 {
01349 int result = 1;
01350 cxx_binding *binding = IDENTIFIER_BINDING (id);
01351 tree context;
01352
01353 timevar_push (TV_NAME_LOOKUP);
01354
01355
01356
01357 note_name_declared_in_class (id, decl);
01358
01359 if (binding && BINDING_LEVEL (binding) == class_binding_level)
01360
01361 result = add_binding (id, decl);
01362 else
01363
01364 push_binding (id, decl, class_binding_level);
01365
01366
01367
01368
01369
01370
01371 IDENTIFIER_CLASS_VALUE (id) = BINDING_VALUE (IDENTIFIER_BINDING (id));
01372
01373
01374 binding = IDENTIFIER_BINDING (id);
01375 if (BINDING_VALUE (binding) == decl && TREE_CODE (decl) != TREE_LIST)
01376 {
01377
01378
01379
01380
01381 if (IMPLICIT_TYPENAME_TYPE_DECL_P (decl))
01382 INHERITED_VALUE_BINDING_P (binding) = 1;
01383 else
01384 {
01385 if (TREE_CODE (decl) == OVERLOAD)
01386 context = CP_DECL_CONTEXT (OVL_CURRENT (decl));
01387 else
01388 {
01389 my_friendly_assert (DECL_P (decl), 0);
01390 context = context_for_name_lookup (decl);
01391 }
01392
01393 if (is_properly_derived_from (current_class_type, context))
01394 INHERITED_VALUE_BINDING_P (binding) = 1;
01395 else
01396 INHERITED_VALUE_BINDING_P (binding) = 0;
01397 }
01398 }
01399 else if (BINDING_VALUE (binding) == decl)
01400
01401
01402
01403 INHERITED_VALUE_BINDING_P (binding) = 1;
01404
01405 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, result);
01406 }
01407
01408
01409
01410
01411 static void
01412 pop_binding (id, decl)
01413 tree id;
01414 tree decl;
01415 {
01416 cxx_binding *binding;
01417
01418 if (id == NULL_TREE)
01419
01420
01421
01422 return;
01423
01424
01425 binding = IDENTIFIER_BINDING (id);
01426
01427
01428 my_friendly_assert (binding != NULL, 0);
01429
01430
01431
01432 if (BINDING_VALUE (binding) == decl)
01433 BINDING_VALUE (binding) = NULL_TREE;
01434 else if (BINDING_TYPE (binding) == decl)
01435 BINDING_TYPE (binding) = NULL_TREE;
01436 else
01437 abort ();
01438
01439 if (!BINDING_VALUE (binding) && !BINDING_TYPE (binding))
01440 {
01441
01442
01443 IDENTIFIER_BINDING (id) = binding->previous;
01444
01445
01446 binding->previous = free_bindings;
01447 free_bindings = binding;
01448
01449
01450
01451 BINDING_LEVEL (binding) = NULL;
01452 }
01453 }
01454
01455
01456
01457
01458 static void
01459 pop_label (label, old_value)
01460 tree label;
01461 tree old_value;
01462 {
01463 if (!processing_template_decl && doing_semantic_analysis_p ())
01464 {
01465 if (DECL_INITIAL (label) == NULL_TREE)
01466 {
01467 cp_error_at ("label `%D' used but not defined", label);
01468
01469 define_label (input_filename, 1, DECL_NAME (label));
01470 }
01471 else if (warn_unused_label && !TREE_USED (label))
01472 cp_warning_at ("label `%D' defined but not used", label);
01473 }
01474
01475 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value);
01476 }
01477
01478
01479
01480
01481
01482 static void
01483 pop_labels (block)
01484 tree block;
01485 {
01486 struct named_label_list *link;
01487
01488
01489
01490 for (link = named_labels; link; link = link->next)
01491 {
01492 pop_label (link->label_decl, link->old_value);
01493
01494
01495 TREE_CHAIN (link->label_decl) = BLOCK_VARS (block);
01496 BLOCK_VARS (block) = link->label_decl;
01497 }
01498
01499 named_labels = NULL;
01500 }
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517 tree
01518 poplevel (keep, reverse, functionbody)
01519 int keep;
01520 int reverse;
01521 int functionbody;
01522 {
01523 register tree link;
01524
01525
01526 tree decls;
01527 int tmp = functionbody;
01528 int real_functionbody;
01529 tree subblocks;
01530 tree block = NULL_TREE;
01531 tree decl;
01532 int leaving_for_scope;
01533
01534 timevar_push (TV_NAME_LOOKUP);
01535
01536 if (cfun && !doing_semantic_analysis_p ())
01537 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
01538
01539 my_friendly_assert (current_binding_level->parm_flag != 2,
01540 19990916);
01541
01542 real_functionbody = (current_binding_level->keep == 2
01543 ? ((functionbody = 0), tmp) : functionbody);
01544 subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
01545
01546 my_friendly_assert (!current_binding_level->class_shadowed,
01547 19990414);
01548
01549
01550
01551
01552 my_friendly_assert (keep == 0 || keep == 1, 0);
01553
01554 if (current_binding_level->keep == 1)
01555 keep = 1;
01556
01557
01558
01559 if (cfun && !functionbody)
01560 {
01561 struct cp_binding_level *level_chain;
01562 level_chain = current_binding_level->level_chain;
01563 if (level_chain)
01564 {
01565 struct named_label_use_list *uses;
01566 struct named_label_list *labels;
01567 for (labels = named_labels; labels; labels = labels->next)
01568 if (labels->binding_level == current_binding_level)
01569 {
01570 tree decl;
01571 if (current_binding_level->is_try_scope)
01572 labels->in_try_scope = 1;
01573 if (current_binding_level->is_catch_scope)
01574 labels->in_catch_scope = 1;
01575 for (decl = labels->names_in_scope; decl;
01576 decl = TREE_CHAIN (decl))
01577 if (decl_jump_unsafe (decl))
01578 labels->bad_decls = tree_cons (NULL_TREE, decl,
01579 labels->bad_decls);
01580 labels->binding_level = level_chain;
01581 labels->names_in_scope = level_chain->names;
01582 }
01583
01584 for (uses = named_label_uses; uses; uses = uses->next)
01585 if (uses->binding_level == current_binding_level)
01586 {
01587 uses->binding_level = level_chain;
01588 uses->names_in_scope = level_chain->names;
01589 }
01590 }
01591 }
01592
01593
01594
01595
01596
01597 if (reverse)
01598 current_binding_level->names
01599 = decls = nreverse (current_binding_level->names);
01600 else
01601 decls = current_binding_level->names;
01602
01603
01604
01605 for (decl = decls; decl; decl = TREE_CHAIN (decl))
01606 if (TREE_CODE (decl) == FUNCTION_DECL
01607 && ! TREE_ASM_WRITTEN (decl)
01608 && DECL_INITIAL (decl) != NULL_TREE
01609 && TREE_ADDRESSABLE (decl)
01610 && decl_function_context (decl) == current_function_decl)
01611 {
01612
01613
01614
01615 if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
01616 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
01617 else
01618 {
01619 push_function_context ();
01620 output_inline_function (decl);
01621 pop_function_context ();
01622 }
01623 }
01624
01625
01626
01627
01628
01629
01630 if (!processing_template_decl)
01631 warn_about_unused_variables (getdecls ());
01632
01633
01634
01635
01636 block = NULL_TREE;
01637 if (keep == 1 || functionbody)
01638 block = make_node (BLOCK);
01639 if (block != NULL_TREE)
01640 {
01641 BLOCK_VARS (block) = decls;
01642 BLOCK_SUBBLOCKS (block) = subblocks;
01643 }
01644
01645
01646 if (keep >= 0)
01647 for (link = subblocks; link; link = TREE_CHAIN (link))
01648 BLOCK_SUPERCONTEXT (link) = block;
01649
01650
01651
01652
01653
01654 leaving_for_scope
01655 = current_binding_level->is_for_scope && flag_new_for_scope == 1;
01656
01657
01658 for (link = decls; link; link = TREE_CHAIN (link))
01659 {
01660 if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
01661 && DECL_NAME (link))
01662 {
01663 cxx_binding *outer_binding
01664 = IDENTIFIER_BINDING (DECL_NAME (link))->previous;
01665 tree ns_binding;
01666
01667 if (!outer_binding)
01668 ns_binding = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (link));
01669 else
01670 ns_binding = NULL_TREE;
01671
01672 if (outer_binding
01673 && (BINDING_LEVEL (outer_binding)
01674 == current_binding_level->level_chain))
01675
01676
01677
01678
01679
01680
01681
01682 pop_binding (DECL_NAME (link), link);
01683 else if ((outer_binding
01684 && (TREE_CODE (BINDING_VALUE (outer_binding))
01685 == TYPE_DECL))
01686 || (ns_binding
01687 && TREE_CODE (ns_binding) == TYPE_DECL))
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698 pop_binding (DECL_NAME (link), link);
01699 else
01700 {
01701
01702
01703 DECL_DEAD_FOR_LOCAL (link) = 1;
01704
01705
01706
01707 if (outer_binding && BINDING_VALUE (outer_binding))
01708 DECL_SHADOWED_FOR_VAR (link)
01709 = BINDING_VALUE (outer_binding);
01710
01711
01712
01713
01714 current_binding_level->level_chain->dead_vars_from_for
01715 = tree_cons (NULL_TREE, link,
01716 current_binding_level->level_chain->
01717 dead_vars_from_for);
01718
01719
01720
01721 BINDING_LEVEL (IDENTIFIER_BINDING (DECL_NAME (link)))
01722 = 0;
01723 }
01724 }
01725 else
01726 {
01727
01728 decl = link;
01729 if (TREE_CODE (decl) == TREE_LIST)
01730 decl = TREE_VALUE (decl);
01731 if (DECL_P (decl))
01732 pop_binding (DECL_NAME (decl), decl);
01733 else if (TREE_CODE (decl) == OVERLOAD)
01734 pop_binding (DECL_NAME (OVL_FUNCTION (decl)), decl);
01735 else
01736 abort ();
01737 }
01738 }
01739
01740
01741
01742 for (link = current_binding_level->dead_vars_from_for;
01743 link; link = TREE_CHAIN (link))
01744 pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link));
01745
01746
01747 for (link = current_binding_level->type_shadowed;
01748 link; link = TREE_CHAIN (link))
01749 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
01750
01751
01752 for (link = current_binding_level->shadowed_labels;
01753 link;
01754 link = TREE_CHAIN (link))
01755 pop_label (TREE_VALUE (link), TREE_PURPOSE (link));
01756
01757
01758
01759
01760
01761
01762
01763 if (block)
01764 {
01765 tree* d;
01766
01767 for (d = &BLOCK_VARS (block); *d; )
01768 {
01769 if (TREE_CODE (*d) == TREE_LIST)
01770 *d = TREE_CHAIN (*d);
01771 else
01772 d = &TREE_CHAIN (*d);
01773 }
01774 }
01775
01776
01777
01778 if (functionbody)
01779 {
01780
01781
01782
01783 BLOCK_VARS (block) = 0;
01784 pop_labels (block);
01785 }
01786
01787 tmp = current_binding_level->keep;
01788
01789 pop_binding_level ();
01790 if (functionbody)
01791 DECL_INITIAL (current_function_decl) = block;
01792 else if (block)
01793 current_binding_level->blocks
01794 = chainon (current_binding_level->blocks, block);
01795
01796
01797
01798
01799
01800
01801 else if (subblocks)
01802 current_binding_level->blocks
01803 = chainon (current_binding_level->blocks, subblocks);
01804
01805
01806
01807
01808 if (block)
01809 TREE_USED (block) = 1;
01810
01811
01812 if (tmp == 2)
01813 {
01814 tree scope_stmts;
01815
01816 scope_stmts
01817 = add_scope_stmt (0, 1);
01818 if (block)
01819 {
01820 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmts)) = block;
01821 SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmts)) = block;
01822 }
01823
01824 block = poplevel (keep, reverse, functionbody);
01825 }
01826
01827 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, block);
01828 }
01829
01830
01831
01832
01833
01834 void
01835 delete_block (block)
01836 tree block;
01837 {
01838 tree t;
01839 if (current_binding_level->blocks == block)
01840 current_binding_level->blocks = TREE_CHAIN (block);
01841 for (t = current_binding_level->blocks; t;)
01842 {
01843 if (TREE_CHAIN (t) == block)
01844 TREE_CHAIN (t) = TREE_CHAIN (block);
01845 else
01846 t = TREE_CHAIN (t);
01847 }
01848 TREE_CHAIN (block) = NULL_TREE;
01849
01850
01851 TREE_USED (block) = 0;
01852 }
01853
01854
01855
01856
01857
01858 void
01859 insert_block (block)
01860 tree block;
01861 {
01862 TREE_USED (block) = 1;
01863 current_binding_level->blocks
01864 = chainon (current_binding_level->blocks, block);
01865 }
01866
01867
01868
01869
01870 void
01871 set_block (block)
01872 tree block ATTRIBUTE_UNUSED;
01873 {
01874
01875
01876 my_friendly_assert (cfun && !doing_semantic_analysis_p (), 20000911);
01877 }
01878
01879
01880
01881 void
01882 pushlevel_class ()
01883 {
01884 register struct cp_binding_level *newlevel;
01885
01886
01887 if (!ENABLE_SCOPE_CHECKING && free_binding_level)
01888 {
01889 newlevel = free_binding_level;
01890 free_binding_level = free_binding_level->level_chain;
01891 }
01892 else
01893 newlevel = make_binding_level ();
01894
01895 if (ENABLE_SCOPE_CHECKING)
01896 is_class_level = 1;
01897
01898 push_binding_level (newlevel, 0, 0);
01899
01900 class_binding_level = current_binding_level;
01901 class_binding_level->parm_flag = 2;
01902 class_binding_level->this_class = current_class_type;
01903 }
01904
01905
01906
01907 void
01908 poplevel_class ()
01909 {
01910 register struct cp_binding_level *level = class_binding_level;
01911 tree shadowed;
01912
01913 timevar_push (TV_NAME_LOOKUP);
01914
01915 my_friendly_assert (level != 0, 354);
01916
01917
01918
01919
01920
01921
01922 if (current_class_depth != 1)
01923 {
01924 struct cp_binding_level* b;
01925
01926
01927 for (shadowed = level->class_shadowed;
01928 shadowed;
01929 shadowed = TREE_CHAIN (shadowed))
01930 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = NULL_TREE;
01931
01932
01933
01934 b = level->level_chain;
01935 while (b && b->parm_flag != 2)
01936 b = b->level_chain;
01937
01938 if (b)
01939 for (shadowed = b->class_shadowed;
01940 shadowed;
01941 shadowed = TREE_CHAIN (shadowed))
01942 {
01943 cxx_binding *binding;
01944
01945 binding = IDENTIFIER_BINDING (TREE_PURPOSE (shadowed));
01946 while (binding && BINDING_LEVEL (binding) != b)
01947 binding = binding->previous;
01948
01949 if (binding)
01950 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed))
01951 = BINDING_VALUE (binding);
01952 }
01953 }
01954 else
01955
01956
01957 {
01958 previous_class_type = current_class_type;
01959 previous_class_values = class_binding_level->class_shadowed;
01960 }
01961 for (shadowed = level->type_shadowed;
01962 shadowed;
01963 shadowed = TREE_CHAIN (shadowed))
01964 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed));
01965
01966
01967 for (shadowed = level->class_shadowed;
01968 shadowed;
01969 shadowed = TREE_CHAIN (shadowed))
01970 pop_binding (TREE_PURPOSE (shadowed), TREE_TYPE (shadowed));
01971
01972
01973
01974 if (ENABLE_SCOPE_CHECKING)
01975 is_class_level = 1;
01976
01977 pop_binding_level ();
01978
01979 timevar_pop (TV_NAME_LOOKUP);
01980 }
01981
01982
01983
01984
01985 void
01986 clear_identifier_class_values ()
01987 {
01988 tree t;
01989
01990 if (!class_binding_level)
01991 return;
01992
01993 for (t = class_binding_level->class_shadowed;
01994 t;
01995 t = TREE_CHAIN (t))
01996 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
01997 }
01998
01999
02000
02001 int
02002 vtable_decl_p (t, data)
02003 tree t;
02004 void *data ATTRIBUTE_UNUSED;
02005 {
02006 return (TREE_CODE (t) == VAR_DECL && DECL_VIRTUAL_P (t));
02007 }
02008
02009
02010
02011
02012 int
02013 vtype_decl_p (t, data)
02014 tree t;
02015 void *data ATTRIBUTE_UNUSED;
02016 {
02017 return (TREE_CODE (t) == TYPE_DECL
02018 && TREE_CODE (TREE_TYPE (t)) == RECORD_TYPE
02019 && TYPE_POLYMORPHIC_P (TREE_TYPE (t)));
02020 }
02021
02022
02023
02024 tree
02025 cp_namespace_decls (ns)
02026 tree ns;
02027 {
02028 return NAMESPACE_LEVEL (ns)->names;
02029 }
02030
02031 struct walk_globals_data {
02032 walk_globals_pred p;
02033 walk_globals_fn f;
02034 void *data;
02035 };
02036
02037
02038
02039
02040
02041 static int
02042 walk_vtables_r (namespace, data)
02043 tree namespace;
02044 void *data;
02045 {
02046 struct walk_globals_data* wgd = (struct walk_globals_data *) data;
02047 walk_globals_fn f = wgd->f;
02048 void *d = wgd->data;
02049 tree decl = NAMESPACE_LEVEL (namespace)->vtables;
02050 int result = 0;
02051
02052 for (; decl ; decl = TREE_CHAIN (decl))
02053 result |= (*f) (&decl, d);
02054
02055 return result;
02056 }
02057
02058
02059
02060
02061 int
02062 walk_vtables (p, f, data)
02063 walk_globals_pred p;
02064 walk_globals_fn f;
02065 void *data;
02066 {
02067 struct walk_globals_data wgd;
02068 wgd.p = p;
02069 wgd.f = f;
02070 wgd.data = data;
02071
02072 return walk_namespaces (walk_vtables_r, &wgd);
02073 }
02074
02075
02076
02077
02078 static int
02079 walk_namespaces_r (namespace, f, data)
02080 tree namespace;
02081 walk_namespaces_fn f;
02082 void *data;
02083 {
02084 int result = 0;
02085 tree current = NAMESPACE_LEVEL (namespace)->namespaces;
02086
02087 result |= (*f) (namespace, data);
02088
02089 for (; current; current = TREE_CHAIN (current))
02090 result |= walk_namespaces_r (current, f, data);
02091
02092 return result;
02093 }
02094
02095
02096
02097
02098 int
02099 walk_namespaces (f, data)
02100 walk_namespaces_fn f;
02101 void *data;
02102 {
02103 return walk_namespaces_r (global_namespace, f, data);
02104 }
02105
02106
02107
02108
02109
02110 static int
02111 walk_globals_r (namespace, data)
02112 tree namespace;
02113 void *data;
02114 {
02115 struct walk_globals_data* wgd = (struct walk_globals_data *) data;
02116 walk_globals_pred p = wgd->p;
02117 walk_globals_fn f = wgd->f;
02118 void *d = wgd->data;
02119 tree *t;
02120 int result = 0;
02121
02122 t = &NAMESPACE_LEVEL (namespace)->names;
02123
02124 while (*t)
02125 {
02126 tree glbl = *t;
02127
02128 if ((*p) (glbl, d))
02129 result |= (*f) (t, d);
02130
02131
02132
02133 if (*t == glbl)
02134 t = &TREE_CHAIN (*t);
02135 }
02136
02137 return result;
02138 }
02139
02140
02141
02142
02143
02144 int
02145 walk_globals (p, f, data)
02146 walk_globals_pred p;
02147 walk_globals_fn f;
02148 void *data;
02149 {
02150 struct walk_globals_data wgd;
02151 wgd.p = p;
02152 wgd.f = f;
02153 wgd.data = data;
02154
02155 return walk_namespaces (walk_globals_r, &wgd);
02156 }
02157
02158
02159
02160
02161
02162 int
02163 wrapup_globals_for_namespace (namespace, data)
02164 tree namespace;
02165 void *data;
02166 {
02167 struct cp_binding_level *level = NAMESPACE_LEVEL (namespace);
02168 varray_type statics = level->static_decls;
02169 tree *vec = &VARRAY_TREE (statics, 0);
02170 int len = VARRAY_ACTIVE_SIZE (statics);
02171 int last_time = (data != 0);
02172
02173 if (last_time)
02174 {
02175 check_global_declarations (vec, len);
02176 return 0;
02177 }
02178
02179
02180 return wrapup_global_declarations (vec, len);
02181 }
02182
02183
02184
02185 static int no_print_functions = 0;
02186 static int no_print_builtins = 0;
02187
02188
02189
02190
02191 static void
02192 bt_print_entry (binding_entry entry, void *data)
02193 {
02194 int *p = (int *) data;
02195 int len;
02196
02197 if (entry->name == NULL)
02198 len = 3;
02199 else if (entry->name == TYPE_IDENTIFIER (entry->type))
02200 len = 2;
02201 else
02202 len = 4;
02203
02204 *p += len;
02205
02206 if (*p > 5)
02207 {
02208 fprintf (stderr, "\n\t");
02209 *p = len;
02210 }
02211 if (entry->name == NULL)
02212 {
02213 print_node_brief (stderr, "<unnamed-typedef", entry->type, 0);
02214 fprintf (stderr, ">");
02215 }
02216 else if (entry->name == TYPE_IDENTIFIER (entry->type))
02217 print_node_brief (stderr, "", entry->type, 0);
02218 else
02219 {
02220 print_node_brief (stderr, "<typedef", entry->name, 0);
02221 print_node_brief (stderr, "", entry->type, 0);
02222 fprintf (stderr, ">");
02223 }
02224 }
02225
02226 void
02227 print_binding_level (lvl)
02228 struct cp_binding_level *lvl;
02229 {
02230 tree t;
02231 int i = 0, len;
02232 fprintf (stderr, " blocks=");
02233 fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
02234 if (lvl->tag_transparent)
02235 fprintf (stderr, " tag-transparent");
02236 if (lvl->more_cleanups_ok)
02237 fprintf (stderr, " more-cleanups-ok");
02238 if (lvl->have_cleanups)
02239 fprintf (stderr, " have-cleanups");
02240 fprintf (stderr, "\n");
02241 if (lvl->names)
02242 {
02243 fprintf (stderr, " names:\t");
02244
02245 for (t = lvl->names; t; t = TREE_CHAIN (t))
02246 {
02247 if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL))
02248 continue;
02249 if (no_print_builtins
02250 && (TREE_CODE (t) == TYPE_DECL)
02251 && (!strcmp (DECL_SOURCE_FILE (t),"<built-in>")))
02252 continue;
02253
02254
02255 if (TREE_CODE (t) == FUNCTION_DECL)
02256 len = 3;
02257 else
02258 len = 2;
02259 i += len;
02260 if (i > 6)
02261 {
02262 fprintf (stderr, "\n\t");
02263 i = len;
02264 }
02265 print_node_brief (stderr, "", t, 0);
02266 if (t == error_mark_node)
02267 break;
02268 }
02269 if (i)
02270 fprintf (stderr, "\n");
02271 }
02272 if (lvl->type_decls)
02273 {
02274 fprintf (stderr, " tags:\t");
02275 i = 0;
02276 binding_table_foreach (lvl->type_decls, bt_print_entry, &i);
02277 if (i)
02278 fprintf (stderr, "\n");
02279 }
02280 if (lvl->class_shadowed)
02281 {
02282 fprintf (stderr, " class-shadowed:");
02283 for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
02284 {
02285 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
02286 }
02287 fprintf (stderr, "\n");
02288 }
02289 if (lvl->type_shadowed)
02290 {
02291 fprintf (stderr, " type-shadowed:");
02292 for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
02293 {
02294 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
02295 }
02296 fprintf (stderr, "\n");
02297 }
02298 }
02299
02300 void
02301 print_other_binding_stack (stack)
02302 struct cp_binding_level *stack;
02303 {
02304 struct cp_binding_level *level;
02305 for (level = stack; !global_scope_p (level); level = level->level_chain)
02306 {
02307 fprintf (stderr, "binding level ");
02308 fprintf (stderr, HOST_PTR_PRINTF, level);
02309 fprintf (stderr, "\n");
02310 print_binding_level (level);
02311 }
02312 }
02313
02314 void
02315 print_binding_stack ()
02316 {
02317 struct cp_binding_level *b;
02318 fprintf (stderr, "current_binding_level=");
02319 fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
02320 fprintf (stderr, "\nclass_binding_level=");
02321 fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
02322 fprintf (stderr, "\nNAMESPACE_LEVEL (global_namespace)=");
02323 fprintf (stderr, HOST_PTR_PRINTF,
02324 (void *) NAMESPACE_LEVEL (global_namespace));
02325 fprintf (stderr, "\n");
02326 if (class_binding_level)
02327 {
02328 for (b = class_binding_level; b; b = b->level_chain)
02329 if (b == current_binding_level)
02330 break;
02331 if (b)
02332 b = class_binding_level;
02333 else
02334 b = current_binding_level;
02335 }
02336 else
02337 b = current_binding_level;
02338 print_other_binding_stack (b);
02339 fprintf (stderr, "global:\n");
02340 print_binding_level (NAMESPACE_LEVEL (global_namespace));
02341 }
02342
02343
02344
02345
02346
02347
02348 static inline cxx_binding *
02349 find_binding (tree name, tree scope, cxx_binding *front)
02350 {
02351 cxx_binding *iter;
02352 cxx_binding *prev = NULL;
02353
02354 timevar_push (TV_NAME_LOOKUP);
02355
02356 for (iter = front; iter; iter = iter->previous)
02357 {
02358 if (BINDING_SCOPE (iter) == scope)
02359 {
02360
02361
02362 if (prev)
02363 {
02364 prev->previous = iter->previous;
02365 iter->previous = front;
02366 IDENTIFIER_NAMESPACE_BINDINGS (name) = iter;
02367 }
02368 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, iter);
02369 }
02370 prev = iter;
02371 }
02372 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL);
02373 }
02374
02375
02376 cxx_binding *
02377 cxx_scope_find_binding_for_name (tree scope, tree name)
02378 {
02379 cxx_binding *b = IDENTIFIER_NAMESPACE_BINDINGS (name);
02380 if (b)
02381 {
02382 scope = ORIGINAL_NAMESPACE (scope);
02383
02384 if (scope == BINDING_SCOPE (b) && b->previous == NULL)
02385 return b;
02386 return find_binding (name, scope, b);
02387 }
02388 return b;
02389 }
02390
02391
02392
02393
02394
02395 cxx_binding *
02396 binding_for_name (tree name, tree scope)
02397 {
02398 cxx_binding *result;
02399
02400 scope = ORIGINAL_NAMESPACE (scope);
02401 result = cxx_scope_find_binding_for_name (scope, name);
02402 if (result)
02403 return result;
02404
02405 result = cxx_binding_make ();
02406 result->previous = IDENTIFIER_NAMESPACE_BINDINGS (name);
02407 BINDING_TYPE (result) = NULL_TREE;
02408 BINDING_VALUE (result) = NULL_TREE;
02409 BINDING_SCOPE (result) = scope;
02410 result->is_local = false;
02411 result->value_is_inherited = false;
02412 result->has_level = false;
02413 IDENTIFIER_NAMESPACE_BINDINGS (name) = result;
02414 return result;
02415 }
02416
02417
02418
02419 tree
02420 namespace_binding (tree name, tree scope)
02421 {
02422 cxx_binding *b =
02423 cxx_scope_find_binding_for_name (scope ? scope : global_namespace, name);
02424
02425 return b ? b->value : NULL_TREE;
02426 }
02427
02428
02429
02430 void
02431 set_namespace_binding (name, scope, val)
02432 tree name;
02433 tree scope;
02434 tree val;
02435 {
02436 cxx_binding *b;
02437
02438 timevar_push (TV_NAME_LOOKUP);
02439 if (scope == NULL_TREE)
02440 scope = global_namespace;
02441
02442 b = binding_for_name (name, scope);
02443 BINDING_VALUE (b) = val;
02444 timevar_pop (TV_NAME_LOOKUP);
02445 }
02446
02447
02448
02449
02450 void
02451 push_namespace (name)
02452 tree name;
02453 {
02454 tree d = NULL_TREE;
02455 int need_new = 1;
02456 int implicit_use = 0;
02457 int global = 0;
02458
02459 timevar_push (TV_NAME_LOOKUP);
02460
02461 if (!global_namespace)
02462 {
02463
02464 my_friendly_assert (name == get_identifier ("::"), 377);
02465 global = 1;
02466 }
02467 else if (!name)
02468 {
02469
02470
02471 if (!anonymous_namespace_name)
02472 anonymous_namespace_name = get_file_function_name ('N');
02473 name = anonymous_namespace_name;
02474 d = IDENTIFIER_NAMESPACE_VALUE (name);
02475 if (d)
02476
02477 need_new = 0;
02478 implicit_use = 1;
02479 }
02480 else
02481 {
02482
02483 d = IDENTIFIER_NAMESPACE_VALUE (name);
02484 if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL)
02485 {
02486 need_new = 0;
02487 if (DECL_NAMESPACE_ALIAS (d))
02488 {
02489 error ("namespace alias `%D' not allowed here, assuming `%D'",
02490 d, DECL_NAMESPACE_ALIAS (d));
02491 d = DECL_NAMESPACE_ALIAS (d);
02492 }
02493 }
02494 }
02495
02496 if (need_new)
02497 {
02498
02499 d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
02500
02501
02502 if (!global)
02503 {
02504 DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace);
02505 d = pushdecl (d);
02506 pushlevel (0);
02507 declare_namespace_level ();
02508 NAMESPACE_LEVEL (d) = current_binding_level;
02509 current_binding_level->type_decls =
02510 binding_table_new (name == std_identifier
02511 ? NAMESPACE_STD_HT_SIZE
02512 : NAMESPACE_ORDINARY_HT_SIZE);
02513 VARRAY_TREE_INIT (current_binding_level->static_decls,
02514 name != std_identifier ? 10 : 200,
02515 "Static declarations");
02516 }
02517 }
02518 else
02519 resume_binding_level (NAMESPACE_LEVEL (d));
02520
02521 if (implicit_use)
02522 do_using_directive (d);
02523
02524 current_namespace = d;
02525
02526 timevar_pop (TV_NAME_LOOKUP);
02527 }
02528
02529
02530
02531 void
02532 pop_namespace ()
02533 {
02534 my_friendly_assert (current_namespace != global_namespace, 20010801);
02535 current_namespace = CP_DECL_CONTEXT (current_namespace);
02536
02537 suspend_binding_level ();
02538 }
02539
02540
02541
02542
02543 void
02544 push_nested_namespace (ns)
02545 tree ns;
02546 {
02547 if (ns == global_namespace)
02548 push_to_top_level ();
02549 else
02550 {
02551 push_nested_namespace (CP_DECL_CONTEXT (ns));
02552 push_namespace (DECL_NAME (ns));
02553 }
02554 }
02555
02556
02557
02558
02559 void
02560 pop_nested_namespace (ns)
02561 tree ns;
02562 {
02563 timevar_push (TV_NAME_LOOKUP);
02564 while (ns != global_namespace)
02565 {
02566 pop_namespace ();
02567 ns = CP_DECL_CONTEXT (ns);
02568 }
02569
02570 pop_from_top_level ();
02571 timevar_pop (TV_NAME_LOOKUP);
02572 }
02573
02574
02575
02576 #define cxx_saved_binding_make() \
02577 (ggc_alloc (sizeof (cxx_saved_binding)))
02578
02579 struct cxx_saved_binding GTY(())
02580 {
02581
02582 cxx_saved_binding *previous;
02583
02584 tree identifier;
02585
02586 cxx_binding *binding;
02587 tree class_value;
02588 tree real_type_value;
02589 };
02590
02591
02592
02593
02594
02595
02596 struct saved_scope *scope_chain;
02597
02598 static cxx_saved_binding *
02599 store_bindings (tree names, cxx_saved_binding *old_bindings)
02600 {
02601 tree t;
02602 cxx_saved_binding *search_bindings = old_bindings;
02603
02604 timevar_push (TV_NAME_LOOKUP);
02605 for (t = names; t; t = TREE_CHAIN (t))
02606 {
02607 tree id;
02608 cxx_saved_binding *saved;
02609 cxx_saved_binding *t1;
02610
02611 if (TREE_CODE (t) == TREE_LIST)
02612 id = TREE_PURPOSE (t);
02613 else
02614 id = DECL_NAME (t);
02615
02616 if (!id
02617
02618
02619
02620 || !(IDENTIFIER_BINDING (id) || IDENTIFIER_CLASS_VALUE (id)))
02621 continue;
02622
02623 for (t1 = search_bindings; t1; t1 = t1->previous)
02624 if (t1->identifier == id)
02625 goto skip_it;
02626
02627 my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
02628 saved = cxx_saved_binding_make ();
02629 saved->previous = old_bindings;
02630 saved->identifier = id;
02631 saved->binding = IDENTIFIER_BINDING (id);
02632 saved->class_value = IDENTIFIER_CLASS_VALUE (id);;
02633 saved->real_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
02634 IDENTIFIER_BINDING (id) = NULL;
02635 IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
02636 old_bindings = saved;
02637 skip_it:
02638 ;
02639 }
02640 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, old_bindings);
02641 }
02642
02643 void
02644 maybe_push_to_top_level (pseudo)
02645 int pseudo;
02646 {
02647 struct saved_scope *s;
02648 struct cp_binding_level *b;
02649 cxx_saved_binding *old_bindings;
02650 int need_pop;
02651
02652 timevar_push (TV_NAME_LOOKUP);
02653
02654 s = (struct saved_scope *) ggc_alloc_cleared (sizeof (struct saved_scope));
02655
02656 b = scope_chain ? current_binding_level : 0;
02657
02658
02659 if (cfun)
02660 {
02661 need_pop = 1;
02662 push_function_context_to (NULL_TREE);
02663 }
02664 else
02665 need_pop = 0;
02666
02667 old_bindings = NULL;
02668 if (scope_chain && previous_class_type)
02669 old_bindings = store_bindings (previous_class_values, old_bindings);
02670
02671
02672
02673 for (; b; b = b->level_chain)
02674 {
02675 tree t;
02676
02677
02678
02679
02680
02681 if (global_scope_p (b) || (pseudo && b->template_parms_p))
02682 break;
02683
02684 old_bindings = store_bindings (b->names, old_bindings);
02685
02686
02687 if (b->parm_flag == 2)
02688 old_bindings = store_bindings (b->class_shadowed, old_bindings);
02689
02690
02691 for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
02692 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
02693 }
02694 s->prev = scope_chain;
02695 s->old_bindings = old_bindings;
02696 s->bindings = b;
02697 s->need_pop_function_context = need_pop;
02698 s->function_decl = current_function_decl;
02699 s->last_parms = last_function_parms;
02700
02701 scope_chain = s;
02702 current_function_decl = NULL_TREE;
02703 VARRAY_TREE_INIT (current_lang_base, 10, "current_lang_base");
02704 current_lang_name = lang_name_cplusplus;
02705 current_namespace = global_namespace;
02706 timevar_pop (TV_NAME_LOOKUP);
02707 }
02708
02709 void
02710 push_to_top_level ()
02711 {
02712 maybe_push_to_top_level (0);
02713 }
02714
02715 void
02716 pop_from_top_level ()
02717 {
02718 struct saved_scope *s = scope_chain;
02719 cxx_saved_binding *saved;
02720
02721 timevar_push (TV_NAME_LOOKUP);
02722
02723
02724 if (previous_class_type)
02725 invalidate_class_lookup_cache ();
02726
02727 current_lang_base = 0;
02728
02729 scope_chain = s->prev;
02730 for (saved = s->old_bindings; saved; saved = saved->previous)
02731 {
02732 tree id = saved->identifier;
02733
02734 IDENTIFIER_BINDING (id) = saved->binding;
02735 IDENTIFIER_CLASS_VALUE (id) = saved->class_value;
02736 SET_IDENTIFIER_TYPE_VALUE (id, saved->real_type_value);
02737 }
02738
02739
02740
02741 if (s->need_pop_function_context)
02742 pop_function_context_from (NULL_TREE);
02743 current_function_decl = s->function_decl;
02744 last_function_parms = s->last_parms;
02745
02746 timevar_pop (TV_NAME_LOOKUP);
02747 }
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762 static void
02763 set_identifier_type_value_with_scope (id, type, b)
02764 tree id;
02765 tree type;
02766 struct cp_binding_level *b;
02767 {
02768 if (!b->namespace_p)
02769 {
02770
02771
02772 tree old_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
02773 b->type_shadowed
02774 = tree_cons (id, old_type_value, b->type_shadowed);
02775 }
02776 else
02777 {
02778 cxx_binding *binding = binding_for_name (id, current_namespace);
02779 BINDING_TYPE (binding) = type;
02780
02781 type = global_type_node;
02782 }
02783 SET_IDENTIFIER_TYPE_VALUE (id, type);
02784 }
02785
02786
02787
02788 void
02789 set_identifier_type_value (id, type)
02790 tree id;
02791 tree type;
02792 {
02793 set_identifier_type_value_with_scope (id, type, current_binding_level);
02794 }
02795
02796
02797
02798 tree
02799 identifier_type_value (id)
02800 tree id;
02801 {
02802 timevar_push (TV_NAME_LOOKUP);
02803
02804 if (REAL_IDENTIFIER_TYPE_VALUE (id) == NULL_TREE)
02805 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
02806
02807 if (REAL_IDENTIFIER_TYPE_VALUE (id) != global_type_node)
02808 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, REAL_IDENTIFIER_TYPE_VALUE (id));
02809
02810
02811 id = lookup_name_real (id, 2, 1, 0);
02812 if (id)
02813 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, TREE_TYPE (id));
02814 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
02815 }
02816
02817
02818
02819
02820
02821 void
02822 pop_everything ()
02823 {
02824 if (ENABLE_SCOPE_CHECKING)
02825 verbatim ("XXX entering pop_everything ()\n");
02826 while (!toplevel_bindings_p ())
02827 {
02828 if (current_binding_level->parm_flag == 2)
02829 pop_nested_class ();
02830 else
02831 poplevel (0, 0, 0);
02832 }
02833 if (ENABLE_SCOPE_CHECKING)
02834 verbatim ("XXX leaving pop_everything ()\n");
02835 }
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846 static tree
02847 maybe_process_template_type_declaration (type, globalize, b)
02848 tree type;
02849 int globalize;
02850 struct cp_binding_level* b;
02851 {
02852 tree decl = TYPE_NAME (type);
02853
02854 if (processing_template_parmlist)
02855
02856
02857
02858
02859
02860
02861 ;
02862 else
02863 {
02864 maybe_check_template_type (type);
02865
02866 my_friendly_assert (IS_AGGR_TYPE (type)
02867 || TREE_CODE (type) == ENUMERAL_TYPE, 0);
02868
02869
02870 if (processing_template_decl)
02871 {
02872
02873
02874 tree name = DECL_NAME (decl);
02875
02876 decl = push_template_decl_real (decl, globalize);
02877
02878
02879
02880
02881
02882
02883
02884 if (TREE_CODE (type) != ENUMERAL_TYPE
02885 && !globalize && b->template_parms_p
02886 && b->level_chain->parm_flag == 2)
02887 {
02888 finish_member_declaration (CLASSTYPE_TI_TEMPLATE (type));
02889
02890
02891
02892 if (b->level_chain->type_decls == NULL)
02893 b->level_chain->type_decls =
02894 binding_table_new (SCOPE_DEFAULT_HT_SIZE);
02895 binding_table_insert (b->level_chain->type_decls, name, type);
02896 if (!COMPLETE_TYPE_P (current_class_type))
02897 {
02898 maybe_add_class_template_decl_list (current_class_type,
02899 type, 0);
02900 CLASSTYPE_NESTED_UDTS (current_class_type) =
02901 b->level_chain->type_decls;
02902 }
02903 }
02904 }
02905 }
02906
02907 return decl;
02908 }
02909
02910
02911
02912
02913
02914
02915 tree
02916 create_implicit_typedef (name, type)
02917 tree name;
02918 tree type;
02919 {
02920 tree decl;
02921
02922 decl = build_decl (TYPE_DECL, name, type);
02923 DECL_ARTIFICIAL (decl) = 1;
02924
02925
02926
02927 SET_DECL_IMPLICIT_TYPEDEF_P (decl);
02928 TYPE_NAME (type) = decl;
02929
02930 return decl;
02931 }
02932
02933
02934
02935 static void
02936 push_local_name (decl)
02937 tree decl;
02938 {
02939 size_t i, nelts;
02940 tree t, name;
02941
02942 timevar_push (TV_NAME_LOOKUP);
02943
02944 if (!local_names)
02945 VARRAY_TREE_INIT (local_names, 8, "local_names");
02946
02947 name = DECL_NAME (decl);
02948
02949 nelts = VARRAY_ACTIVE_SIZE (local_names);
02950 for (i = 0; i < nelts; i++)
02951 {
02952 t = VARRAY_TREE (local_names, i);
02953 if (DECL_NAME (t) == name)
02954 {
02955 if (!DECL_LANG_SPECIFIC (decl))
02956 retrofit_lang_decl (decl);
02957 DECL_LANG_SPECIFIC (decl)->decl_flags.u2sel = 1;
02958 if (DECL_LANG_SPECIFIC (t))
02959 DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1;
02960 else
02961 DECL_DISCRIMINATOR (decl) = 1;
02962
02963 VARRAY_TREE (local_names, i) = decl;
02964 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, (void)0);
02965 }
02966 }
02967
02968 VARRAY_PUSH_TREE (local_names, decl);
02969 timevar_pop (TV_NAME_LOOKUP);
02970 }
02971
02972
02973
02974
02975
02976
02977 void
02978 pushtag (name, type, globalize)
02979 tree name, type;
02980 int globalize;
02981 {
02982 register struct cp_binding_level *b;
02983
02984 timevar_push (TV_NAME_LOOKUP);
02985
02986 b = current_binding_level;
02987 while (b->tag_transparent
02988 || (b->parm_flag == 2
02989 && (globalize
02990
02991
02992
02993
02994 || COMPLETE_TYPE_P (b->this_class))))
02995 b = b->level_chain;
02996
02997 if (b->type_decls == NULL)
02998 b->type_decls = binding_table_new (SCOPE_DEFAULT_HT_SIZE);
02999 binding_table_insert (b->type_decls, name, type);
03000
03001 if (name)
03002 {
03003
03004 if (IDENTIFIER_TYPE_VALUE (name) != type)
03005 {
03006 register tree d = NULL_TREE;
03007 int in_class = 0;
03008 tree context = TYPE_CONTEXT (type);
03009
03010 if (! context)
03011 {
03012 tree cs = current_scope ();
03013
03014 if (! globalize)
03015 context = cs;
03016 else if (cs != NULL_TREE && TYPE_P (cs))
03017
03018
03019
03020 context = decl_function_context (get_type_decl (cs));
03021 }
03022 if (!context)
03023 context = current_namespace;
03024
03025 if ((b->template_parms_p && b->level_chain->parm_flag == 2)
03026 || b->parm_flag == 2)
03027 in_class = 1;
03028
03029 if (current_lang_name == lang_name_java)
03030 TYPE_FOR_JAVA (type) = 1;
03031
03032 d = create_implicit_typedef (name, type);
03033 DECL_CONTEXT (d) = FROB_CONTEXT (context);
03034 if (! in_class)
03035 set_identifier_type_value_with_scope (name, type, b);
03036
03037 d = maybe_process_template_type_declaration (type,
03038 globalize, b);
03039
03040 if (b->parm_flag == 2)
03041 {
03042 if (!PROCESSING_REAL_TEMPLATE_DECL_P ())
03043
03044
03045
03046
03047 finish_member_declaration (d);
03048 else
03049 pushdecl_class_level (d);
03050 }
03051 else
03052 d = pushdecl_with_scope (d, b);
03053
03054
03055 if (ANON_AGGRNAME_P (name))
03056 DECL_IGNORED_P (d) = 1;
03057
03058 TYPE_CONTEXT (type) = DECL_CONTEXT (d);
03059
03060
03061
03062
03063
03064
03065 if (TYPE_CONTEXT (type)
03066 && TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL
03067 && !processing_template_decl)
03068 VARRAY_PUSH_TREE (local_classes, type);
03069 }
03070 if (b->parm_flag == 2)
03071 {
03072 if (!COMPLETE_TYPE_P (current_class_type))
03073 {
03074 maybe_add_class_template_decl_list (current_class_type,
03075 type, 0);
03076 CLASSTYPE_NESTED_UDTS (current_class_type) = b->type_decls;
03077 }
03078 }
03079 }
03080
03081 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
03082
03083 TYPE_STUB_DECL (type) = TYPE_NAME (type);
03084 else
03085 {
03086
03087
03088
03089
03090
03091
03092
03093
03094 tree d = build_decl (TYPE_DECL, NULL_TREE, type);
03095 TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
03096 }
03097
03098 timevar_pop (TV_NAME_LOOKUP);
03099 }
03100
03101
03102
03103 static int anon_cnt = 0;
03104
03105
03106
03107
03108 tree
03109 make_anon_name ()
03110 {
03111 char buf[32];
03112
03113 sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
03114 return get_identifier (buf);
03115 }
03116
03117
03118
03119
03120 void
03121 clear_anon_tags ()
03122 {
03123 register struct cp_binding_level *b;
03124 static int last_cnt = 0;
03125
03126
03127 if (last_cnt == anon_cnt)
03128 return;
03129
03130 b = current_binding_level;
03131 while (b->tag_transparent)
03132 b = b->level_chain;
03133 if (b->type_decls != NULL)
03134 binding_table_remove_anonymous_types (b->type_decls);
03135 last_cnt = anon_cnt;
03136 }
03137
03138
03139
03140
03141
03142
03143
03144
03145 int
03146 decls_match (newdecl, olddecl)
03147 tree newdecl, olddecl;
03148 {
03149 int types_match;
03150
03151 if (newdecl == olddecl)
03152 return 1;
03153
03154 if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
03155
03156
03157 return 0;
03158
03159 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03160 {
03161 tree f1 = TREE_TYPE (newdecl);
03162 tree f2 = TREE_TYPE (olddecl);
03163 tree p1 = TYPE_ARG_TYPES (f1);
03164 tree p2 = TYPE_ARG_TYPES (f2);
03165
03166 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
03167 && ! (DECL_EXTERN_C_P (newdecl)
03168 && DECL_EXTERN_C_P (olddecl)))
03169 return 0;
03170
03171 if (TREE_CODE (f1) != TREE_CODE (f2))
03172 return 0;
03173
03174 if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)))
03175 {
03176 if (p2 == NULL_TREE && DECL_EXTERN_C_P (olddecl)
03177 && (DECL_BUILT_IN (olddecl)
03178 #ifndef NO_IMPLICIT_EXTERN_C
03179 || (DECL_IN_SYSTEM_HEADER (newdecl) && !DECL_CLASS_SCOPE_P (newdecl))
03180 || (DECL_IN_SYSTEM_HEADER (olddecl) && !DECL_CLASS_SCOPE_P (olddecl))
03181 #endif
03182 ))
03183 {
03184 types_match = self_promoting_args_p (p1);
03185 if (p1 == void_list_node)
03186 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
03187 }
03188 #ifndef NO_IMPLICIT_EXTERN_C
03189 else if (p1 == NULL_TREE
03190 && (DECL_EXTERN_C_P (olddecl)
03191 && DECL_IN_SYSTEM_HEADER (olddecl)
03192 && !DECL_CLASS_SCOPE_P (olddecl))
03193 && (DECL_EXTERN_C_P (newdecl)
03194 && DECL_IN_SYSTEM_HEADER (newdecl)
03195 && !DECL_CLASS_SCOPE_P (newdecl)))
03196 {
03197 types_match = self_promoting_args_p (p2);
03198 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
03199 }
03200 #endif
03201 else
03202 types_match = compparms (p1, p2);
03203 }
03204 else
03205 types_match = 0;
03206 }
03207 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
03208 {
03209 if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
03210 DECL_TEMPLATE_PARMS (olddecl)))
03211 return 0;
03212
03213 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
03214 != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
03215 return 0;
03216
03217 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
03218 types_match = 1;
03219 else
03220 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
03221 DECL_TEMPLATE_RESULT (newdecl));
03222 }
03223 else
03224 {
03225 if (TREE_TYPE (newdecl) == error_mark_node)
03226 types_match = TREE_TYPE (olddecl) == error_mark_node;
03227 else if (TREE_TYPE (olddecl) == NULL_TREE)
03228 types_match = TREE_TYPE (newdecl) == NULL_TREE;
03229 else if (TREE_TYPE (newdecl) == NULL_TREE)
03230 types_match = 0;
03231 else
03232 types_match = comptypes (TREE_TYPE (newdecl),
03233 TREE_TYPE (olddecl),
03234 COMPARE_REDECLARATION);
03235 }
03236
03237 return types_match;
03238 }
03239
03240
03241
03242
03243
03244
03245
03246
03247
03248
03249 static void
03250 warn_extern_redeclared_static (newdecl, olddecl)
03251 tree newdecl, olddecl;
03252 {
03253 static const char *const explicit_extern_static_warning
03254 = "`%D' was declared `extern' and later `static'";
03255 static const char *const implicit_extern_static_warning
03256 = "`%D' was declared implicitly `extern' and later `static'";
03257
03258 tree name;
03259
03260 if (TREE_CODE (newdecl) == TYPE_DECL
03261 || TREE_CODE (newdecl) == TEMPLATE_DECL
03262 || TREE_CODE (newdecl) == CONST_DECL)
03263 return;
03264
03265
03266
03267 if (TREE_CODE (newdecl) == FUNCTION_DECL
03268 && DECL_STATIC_FUNCTION_P (newdecl))
03269 return;
03270
03271
03272
03273 if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
03274 return;
03275
03276
03277 if (TREE_CODE (olddecl) == FUNCTION_DECL
03278 && DECL_ARTIFICIAL (olddecl))
03279 return;
03280
03281 name = DECL_ASSEMBLER_NAME (newdecl);
03282 pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
03283 ? implicit_extern_static_warning
03284 : explicit_extern_static_warning, newdecl);
03285 cp_pedwarn_at ("previous declaration of `%D'", olddecl);
03286 }
03287
03288
03289
03290
03291
03292
03293
03294
03295 int
03296 duplicate_decls (newdecl, olddecl)
03297 tree newdecl, olddecl;
03298 {
03299 unsigned olddecl_uid = DECL_UID (olddecl);
03300 int olddecl_friend = 0, types_match = 0;
03301 int new_defines_function = 0;
03302
03303 if (newdecl == olddecl)
03304 return 1;
03305
03306 types_match = decls_match (newdecl, olddecl);
03307
03308
03309
03310
03311
03312
03313 if (TREE_TYPE (newdecl) == error_mark_node
03314 || TREE_TYPE (olddecl) == error_mark_node)
03315 types_match = 1;
03316
03317 if (DECL_P (olddecl)
03318 && TREE_CODE (newdecl) == FUNCTION_DECL
03319 && TREE_CODE (olddecl) == FUNCTION_DECL
03320 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
03321 {
03322 if (DECL_DECLARED_INLINE_P (newdecl)
03323 && DECL_UNINLINABLE (newdecl)
03324 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
03325 ;
03326 else if (DECL_DECLARED_INLINE_P (olddecl)
03327 && DECL_UNINLINABLE (olddecl)
03328 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
03329 ;
03330 else if (DECL_DECLARED_INLINE_P (newdecl)
03331 && DECL_UNINLINABLE (olddecl)
03332 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
03333 {
03334 warning_with_decl (newdecl,
03335 "function `%s' redeclared as inline");
03336 warning_with_decl (olddecl,
03337 "previous declaration of function `%s' with attribute noinline");
03338 }
03339 else if (DECL_DECLARED_INLINE_P (olddecl)
03340 && DECL_UNINLINABLE (newdecl)
03341 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
03342 {
03343 warning_with_decl (newdecl,
03344 "function `%s' redeclared with attribute noinline");
03345 warning_with_decl (olddecl,
03346 "previous declaration of function `%s' was inline");
03347 }
03348 }
03349
03350
03351 if (TREE_CODE (olddecl) == FUNCTION_DECL
03352 && DECL_ARTIFICIAL (olddecl))
03353 {
03354 if (TREE_CODE (newdecl) != FUNCTION_DECL)
03355 {
03356
03357 if (DECL_ANTICIPATED (olddecl))
03358 return 0;
03359
03360
03361
03362
03363 if (! TREE_PUBLIC (newdecl))
03364 {
03365 if (warn_shadow)
03366 warning ("shadowing %s function `%#D'",
03367 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
03368 olddecl);
03369
03370 return 0;
03371 }
03372
03373
03374 else if (! DECL_BUILT_IN (olddecl))
03375 warning ("library function `%#D' redeclared as non-function `%#D'",
03376 olddecl, newdecl);
03377 else
03378 {
03379 error ("declaration of `%#D'", newdecl);
03380 error ("conflicts with built-in declaration `%#D'",
03381 olddecl);
03382 }
03383 return 0;
03384 }
03385 else if (!types_match)
03386 {
03387
03388 if (DECL_ANTICIPATED (olddecl))
03389 ;
03390 else if ((DECL_EXTERN_C_P (newdecl)
03391 && DECL_EXTERN_C_P (olddecl))
03392 || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
03393 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
03394 {
03395
03396
03397 if (TREE_PUBLIC (newdecl))
03398 {
03399 warning ("new declaration `%#D'", newdecl);
03400 warning ("ambiguates built-in declaration `%#D'",
03401 olddecl);
03402 }
03403 else if (warn_shadow)
03404 warning ("shadowing %s function `%#D'",
03405 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
03406 olddecl);
03407 }
03408 else
03409
03410 return 0;
03411
03412
03413 SET_DECL_RTL (olddecl, DECL_RTL (newdecl));
03414 }
03415
03416
03417 else if (DECL_ANTICIPATED (olddecl))
03418 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
03419
03420
03421
03422 TREE_NOTHROW (olddecl) = 0;
03423
03424 if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
03425 {
03426
03427
03428 DECL_THIS_STATIC (olddecl) = 1;
03429 TREE_PUBLIC (olddecl) = 0;
03430
03431
03432
03433
03434 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
03435 SET_DECL_RTL (olddecl, DECL_RTL (newdecl));
03436 }
03437 }
03438 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
03439 {
03440 if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
03441 && TREE_CODE (newdecl) != TYPE_DECL
03442 && ! (TREE_CODE (newdecl) == TEMPLATE_DECL
03443 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL))
03444 || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
03445 && TREE_CODE (olddecl) != TYPE_DECL
03446 && ! (TREE_CODE (olddecl) == TEMPLATE_DECL
03447 && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
03448 == TYPE_DECL))))
03449 {
03450
03451
03452
03453
03454
03455 return 0;
03456 }
03457
03458 if ((TREE_CODE (newdecl) == FUNCTION_DECL
03459 && DECL_FUNCTION_TEMPLATE_P (olddecl))
03460 || (TREE_CODE (olddecl) == FUNCTION_DECL
03461 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
03462 return 0;
03463
03464 error ("`%#D' redeclared as different kind of symbol", newdecl);
03465 if (TREE_CODE (olddecl) == TREE_LIST)
03466 olddecl = TREE_VALUE (olddecl);
03467 cp_error_at ("previous declaration of `%#D'", olddecl);
03468
03469
03470
03471
03472 return 0;
03473 }
03474 else if (!types_match)
03475 {
03476 if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
03477
03478
03479 return 0;
03480
03481 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
03482 {
03483
03484
03485
03486 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL
03487 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
03488 {
03489 error ("declaration of template `%#D'", newdecl);
03490 cp_error_at ("conflicts with previous declaration `%#D'",
03491 olddecl);
03492 }
03493 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL
03494 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
03495 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))),
03496 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
03497 && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
03498 DECL_TEMPLATE_PARMS (olddecl))
03499
03500
03501 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
03502 TREE_TYPE (TREE_TYPE (olddecl))))
03503 {
03504 error ("new declaration `%#D'", newdecl);
03505 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
03506 }
03507 return 0;
03508 }
03509 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03510 {
03511 if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
03512 {
03513 error ("declaration of C function `%#D' conflicts with",
03514 newdecl);
03515 cp_error_at ("previous declaration `%#D' here", olddecl);
03516 }
03517 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
03518 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
03519 {
03520 error ("new declaration `%#D'", newdecl);
03521 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
03522 }
03523 else
03524 return 0;
03525 }
03526
03527
03528 else if (current_class_type == NULL_TREE
03529 || !DECL_ASSEMBLER_NAME_SET_P (newdecl)
03530 || (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl))
03531 != current_class_type))
03532 {
03533 error ("conflicting types for `%#D'", newdecl);
03534 cp_error_at ("previous declaration as `%#D'", olddecl);
03535 }
03536 }
03537 else if (TREE_CODE (newdecl) == FUNCTION_DECL
03538 && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
03539 && (!DECL_TEMPLATE_INFO (newdecl)
03540 || (DECL_TI_TEMPLATE (newdecl)
03541 != DECL_TI_TEMPLATE (olddecl))))
03542 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
03543 && (!DECL_TEMPLATE_INFO (olddecl)
03544 || (DECL_TI_TEMPLATE (olddecl)
03545 != DECL_TI_TEMPLATE (newdecl))))))
03546
03547
03548
03549
03550
03551
03552
03553
03554 return 0;
03555 else if (TREE_CODE (newdecl) == FUNCTION_DECL
03556 && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
03557 && !DECL_USE_TEMPLATE (newdecl))
03558 || (DECL_TEMPLATE_INSTANTIATION (newdecl)
03559 && !DECL_USE_TEMPLATE (olddecl))))
03560
03561
03562 return 0;
03563 else if (TREE_CODE (newdecl) == NAMESPACE_DECL
03564 && DECL_NAMESPACE_ALIAS (newdecl)
03565 && DECL_NAMESPACE_ALIAS (newdecl) == DECL_NAMESPACE_ALIAS (olddecl))
03566
03567 return 1;
03568 else
03569 {
03570 const char *errmsg = redeclaration_error_message (newdecl, olddecl);
03571 if (errmsg)
03572 {
03573 error (errmsg, newdecl);
03574 if (DECL_NAME (olddecl) != NULL_TREE)
03575 cp_error_at ((DECL_INITIAL (olddecl)
03576 && namespace_bindings_p ())
03577 ? "`%#D' previously defined here"
03578 : "`%#D' previously declared here", olddecl);
03579 return 0;
03580 }
03581 else if (TREE_CODE (olddecl) == FUNCTION_DECL
03582 && DECL_INITIAL (olddecl) != NULL_TREE
03583 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
03584 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
03585 {
03586
03587 cp_warning_at ("prototype for `%#D'", newdecl);
03588 cp_warning_at ("follows non-prototype definition here", olddecl);
03589 }
03590 else if (TREE_CODE (olddecl) == FUNCTION_DECL
03591 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
03592 {
03593
03594
03595
03596 if (current_lang_depth () == 0)
03597 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
03598 else
03599 {
03600 cp_error_at ("previous declaration of `%#D' with %L linkage",
03601 olddecl, DECL_LANGUAGE (olddecl));
03602 error ("conflicts with new declaration with %L linkage",
03603 DECL_LANGUAGE (newdecl));
03604 }
03605 }
03606
03607 if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
03608 ;
03609 else if (TREE_CODE (olddecl) == FUNCTION_DECL)
03610 {
03611 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
03612 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
03613 int i = 1;
03614
03615 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
03616 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
03617
03618 for (; t1 && t1 != void_list_node;
03619 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
03620 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
03621 {
03622 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
03623 TREE_PURPOSE (t2)))
03624 {
03625 pedwarn ("default argument given for parameter %d of `%#D'",
03626 i, newdecl);
03627 cp_pedwarn_at ("after previous specification in `%#D'",
03628 olddecl);
03629 }
03630 else
03631 {
03632 error ("default argument given for parameter %d of `%#D'",
03633 i, newdecl);
03634 cp_error_at ("after previous specification in `%#D'",
03635 olddecl);
03636 }
03637 }
03638
03639 if (DECL_DECLARED_INLINE_P (newdecl)
03640 && ! DECL_DECLARED_INLINE_P (olddecl)
03641 && TREE_ADDRESSABLE (olddecl) && warn_inline)
03642 {
03643 warning ("`%#D' was used before it was declared inline",
03644 newdecl);
03645 cp_warning_at ("previous non-inline declaration here",
03646 olddecl);
03647 }
03648 }
03649 }
03650
03651
03652
03653
03654
03655
03656
03657
03658 if (TREE_CODE (olddecl) == TYPE_DECL
03659 && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
03660 || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
03661 return 0;
03662
03663
03664
03665 warn_extern_redeclared_static (newdecl, olddecl);
03666
03667
03668 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03669 {
03670
03671
03672
03673
03674 if (DECL_VINDEX (olddecl))
03675 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
03676 if (DECL_CONTEXT (olddecl))
03677 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
03678 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
03679 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
03680 DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
03681 DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
03682 DECL_NEEDS_FINAL_OVERRIDER_P (newdecl) |= DECL_NEEDS_FINAL_OVERRIDER_P (olddecl);
03683 DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
03684 if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
03685 SET_OVERLOADED_OPERATOR_CODE
03686 (newdecl, DECL_OVERLOADED_OPERATOR_P (olddecl));
03687 new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
03688
03689
03690
03691
03692 if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
03693 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
03694
03695 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
03696
03697 && ! (DECL_FRIEND_P (newdecl) || DECL_FRIEND_P (olddecl)))
03698 {
03699 warning ("redundant redeclaration of `%D' in same scope", newdecl);
03700 cp_warning_at ("previous declaration of `%D'", olddecl);
03701 }
03702 }
03703
03704
03705 if (TREE_CODE (olddecl) == TYPE_DECL)
03706 {
03707 register tree newtype = TREE_TYPE (newdecl);
03708 register tree oldtype = TREE_TYPE (olddecl);
03709
03710 if (newtype != error_mark_node && oldtype != error_mark_node
03711 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
03712 CLASSTYPE_FRIEND_CLASSES (newtype)
03713 = CLASSTYPE_FRIEND_CLASSES (oldtype);
03714 \
03715 DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
03716 }
03717
03718
03719
03720 DECL_ATTRIBUTES (newdecl)
03721 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
03722
03723 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
03724 {
03725 TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl));
03726 DECL_TEMPLATE_SPECIALIZATIONS (olddecl)
03727 = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl),
03728 DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
03729
03730
03731
03732 if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE
03733 && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) != NULL_TREE)
03734 {
03735 DECL_SOURCE_LOCATION (olddecl)
03736 = DECL_SOURCE_LOCATION (DECL_TEMPLATE_RESULT (olddecl))
03737 = DECL_SOURCE_LOCATION (newdecl);
03738 }
03739
03740 return 1;
03741 }
03742
03743 if (types_match)
03744 {
03745
03746 tree oldtype = TREE_TYPE (olddecl);
03747 tree newtype;
03748
03749
03750 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
03751
03752
03753 if (TREE_CODE (newdecl) == TYPE_DECL
03754 && newtype == DECL_ORIGINAL_TYPE (newdecl))
03755 newtype = oldtype;
03756
03757 if (TREE_CODE (newdecl) == VAR_DECL)
03758 {
03759 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
03760 DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
03761 }
03762
03763
03764
03765 else if (TREE_CODE (newdecl) == FUNCTION_DECL
03766 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
03767 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
03768 {
03769 TREE_TYPE (newdecl) = build_exception_variant (newtype,
03770 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
03771 TREE_TYPE (olddecl) = build_exception_variant (newtype,
03772 TYPE_RAISES_EXCEPTIONS (oldtype));
03773
03774 if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl))
03775 && DECL_SOURCE_LINE (olddecl) != 0
03776 && flag_exceptions
03777 && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)),
03778 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)), 1))
03779 {
03780 error ("declaration of `%F' throws different exceptions",
03781 newdecl);
03782 cp_error_at ("than previous declaration `%F'", olddecl);
03783 }
03784 }
03785 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
03786
03787
03788 if (! same_type_p (newtype, oldtype)
03789 && TREE_TYPE (newdecl) != error_mark_node
03790 && !(processing_template_decl && uses_template_parms (newdecl)))
03791 layout_type (TREE_TYPE (newdecl));
03792
03793 if ((TREE_CODE (newdecl) == VAR_DECL
03794 || TREE_CODE (newdecl) == PARM_DECL
03795 || TREE_CODE (newdecl) == RESULT_DECL
03796 || TREE_CODE (newdecl) == FIELD_DECL
03797 || TREE_CODE (newdecl) == TYPE_DECL)
03798 && !(processing_template_decl && uses_template_parms (newdecl)))
03799 layout_decl (newdecl, 0);
03800
03801
03802 if (TREE_READONLY (newdecl))
03803 TREE_READONLY (olddecl) = 1;
03804 if (TREE_THIS_VOLATILE (newdecl))
03805 TREE_THIS_VOLATILE (olddecl) = 1;
03806
03807
03808 if (DECL_INITIAL (newdecl) == NULL_TREE
03809 && DECL_INITIAL (olddecl) != NULL_TREE)
03810 {
03811 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
03812 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
03813 if (CAN_HAVE_FULL_LANG_DECL_P (newdecl)
03814 && DECL_LANG_SPECIFIC (newdecl)
03815 && DECL_LANG_SPECIFIC (olddecl))
03816 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
03817 }
03818
03819
03820
03821
03822
03823 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
03824 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
03825
03826 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03827 {
03828 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
03829 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
03830 DECL_NO_LIMIT_STACK (newdecl)
03831 |= DECL_NO_LIMIT_STACK (olddecl);
03832
03833 COPY_DECL_RTL (olddecl, newdecl);
03834 }
03835 else if (TREE_CODE (newdecl) == VAR_DECL
03836 && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
03837 {
03838
03839
03840
03841
03842 COPY_DECL_RTL (olddecl, newdecl);
03843 }
03844 }
03845
03846
03847 else
03848 {
03849
03850 tree oldstatic = value_member (olddecl, static_aggregates);
03851 if (oldstatic)
03852 TREE_VALUE (oldstatic) = error_mark_node;
03853
03854 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
03855 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
03856 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
03857 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
03858 }
03859
03860
03861 merge_weak (newdecl, olddecl);
03862
03863 DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl);
03864 DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
03865 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
03866 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
03867 if (! DECL_EXTERNAL (olddecl))
03868 DECL_EXTERNAL (newdecl) = 0;
03869
03870 if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
03871 {
03872 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
03873 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
03874 DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
03875 DECL_TEMPLATE_INSTANTIATED (newdecl)
03876 |= DECL_TEMPLATE_INSTANTIATED (olddecl);
03877
03878
03879 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
03880 DECL_LANG_SPECIFIC (newdecl)->decl_flags.u2 =
03881 DECL_LANG_SPECIFIC (olddecl)->decl_flags.u2;
03882 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
03883 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
03884 DECL_INITIALIZED_IN_CLASS_P (newdecl)
03885 |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
03886 olddecl_friend = DECL_FRIEND_P (olddecl);
03887
03888
03889 if (TREE_CODE (newdecl) == FUNCTION_DECL
03890 || DECL_FUNCTION_TEMPLATE_P (newdecl))
03891 {
03892 DECL_BEFRIENDING_CLASSES (newdecl)
03893 = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
03894 DECL_BEFRIENDING_CLASSES (olddecl));
03895
03896
03897 if (DECL_VIRTUAL_P (newdecl))
03898 DECL_THUNKS (newdecl) = DECL_THUNKS (olddecl);
03899 }
03900 }
03901
03902 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03903 {
03904 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
03905 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
03906 {
03907
03908
03909
03910 my_friendly_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl),
03911 0);
03912
03913 if (TREE_USED (olddecl))
03914
03915
03916
03917
03918
03919
03920
03921
03922 error ("explicit specialization of %D after first use",
03923 olddecl);
03924
03925 SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
03926
03927
03928
03929 }
03930 else
03931 {
03932 if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
03933 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
03934
03935 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
03936
03937
03938
03939 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
03940 DECL_INLINE (olddecl) = 1;
03941 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
03942
03943 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
03944 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
03945 }
03946
03947
03948 DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
03949
03950 if (! types_match)
03951 {
03952 SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
03953 COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
03954 SET_DECL_RTL (olddecl, DECL_RTL (newdecl));
03955 }
03956 if (! types_match || new_defines_function)
03957 {
03958
03959
03960
03961 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
03962 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
03963 }
03964 if (new_defines_function)
03965
03966
03967 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
03968 else if (types_match)
03969 {
03970
03971
03972 if (DECL_BUILT_IN (olddecl))
03973 {
03974 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
03975 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
03976
03977
03978 SET_DECL_RTL (newdecl, DECL_RTL (olddecl));
03979 }
03980 else
03981 DECL_NUM_STMTS (newdecl) = DECL_NUM_STMTS (olddecl);
03982
03983 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
03984
03985 if (DECL_ARGUMENTS (olddecl))
03986 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
03987 }
03988 }
03989 else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
03990 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
03991
03992
03993 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
03994 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
03995 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
03996 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
03997
03998 if (TREE_CODE (newdecl) == FUNCTION_DECL)
03999 {
04000 int function_size;
04001
04002 function_size = sizeof (struct tree_decl);
04003
04004 memcpy ((char *) olddecl + sizeof (struct tree_common),
04005 (char *) newdecl + sizeof (struct tree_common),
04006 function_size - sizeof (struct tree_common));
04007
04008 if (DECL_TEMPLATE_INSTANTIATION (newdecl))
04009 {
04010
04011
04012
04013
04014
04015
04016
04017
04018
04019
04020
04021
04022
04023
04024
04025
04026
04027
04028
04029
04030
04031
04032 tree tmpl = DECL_TI_TEMPLATE (newdecl);
04033 tree decls = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
04034
04035 for (; decls; decls = TREE_CHAIN (decls))
04036 if (TREE_VALUE (decls) == newdecl)
04037 TREE_VALUE (decls) = olddecl;
04038 }
04039 }
04040 else
04041 {
04042 memcpy ((char *) olddecl + sizeof (struct tree_common),
04043 (char *) newdecl + sizeof (struct tree_common),
04044 sizeof (struct tree_decl) - sizeof (struct tree_common)
04045 + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
04046 }
04047
04048 DECL_UID (olddecl) = olddecl_uid;
04049 if (olddecl_friend)
04050 DECL_FRIEND_P (olddecl) = 1;
04051
04052
04053
04054 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
04055
04056
04057
04058
04059 if (DECL_RTL_SET_P (olddecl)
04060 && (TREE_CODE (olddecl) == FUNCTION_DECL
04061 || (TREE_CODE (olddecl) == VAR_DECL
04062 && TREE_STATIC (olddecl))))
04063 make_decl_rtl (olddecl, NULL);
04064
04065 return 1;
04066 }
04067
04068
04069
04070
04071
04072
04073
04074
04075
04076 tree
04077 pushdecl (x)
04078 tree x;
04079 {
04080 register tree t;
04081 register tree name;
04082 int need_new_binding;
04083
04084 timevar_push (TV_NAME_LOOKUP);
04085
04086
04087
04088 my_friendly_assert (!cfun || doing_semantic_analysis_p (),
04089 19990913);
04090
04091 need_new_binding = 1;
04092
04093 if (DECL_TEMPLATE_PARM_P (x))
04094
04095
04096 ;
04097 else
04098 {
04099 if (current_function_decl && x != current_function_decl
04100
04101
04102 && !(TREE_CODE (x) == FUNCTION_DECL && !DECL_INITIAL (x))
04103
04104
04105
04106 && !(TREE_CODE (x) == VAR_DECL && DECL_EXTERNAL (x))
04107 && !DECL_CONTEXT (x))
04108 DECL_CONTEXT (x) = current_function_decl;
04109
04110
04111
04112
04113 if (TREE_CODE (x) == FUNCTION_DECL
04114 && DECL_NAMESPACE_SCOPE_P (x)
04115 && current_function_decl
04116 && x != current_function_decl)
04117 DECL_LOCAL_FUNCTION_P (x) = 1;
04118 }
04119
04120 name = DECL_NAME (x);
04121 if (name)
04122 {
04123 int different_binding_level = 0;
04124
04125 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
04126 name = TREE_OPERAND (name, 0);
04127
04128
04129
04130 if (TREE_CODE (x) == VAR_DECL && DECL_NAMESPACE_SCOPE_P (x)
04131 && namespace_bindings_p ())
04132 t = namespace_binding (name, DECL_CONTEXT (x));
04133 else
04134 t = lookup_name_current_level (name);
04135
04136
04137
04138
04139
04140
04141 if (! t && current_function_decl && x != current_function_decl
04142 && (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
04143 && DECL_EXTERNAL (x))
04144 {
04145
04146 t = IDENTIFIER_VALUE (name);
04147
04148 if (! t)
04149 t = namespace_binding (name, DECL_CONTEXT (x));
04150
04151
04152 if (t && DECL_P (t) && ! (TREE_STATIC (t) || DECL_EXTERNAL (t)))
04153 t = NULL_TREE;
04154 if (t)
04155 different_binding_level = 1;
04156 }
04157
04158
04159
04160
04161
04162
04163 if (t && TREE_CODE (t) == OVERLOAD)
04164 {
04165 tree match;
04166
04167 if (TREE_CODE (x) == FUNCTION_DECL)
04168 for (match = t; match; match = OVL_NEXT (match))
04169 {
04170 if (decls_match (OVL_CURRENT (match), x))
04171 break;
04172 }
04173 else
04174
04175 match = t;
04176
04177 if (match)
04178 t = OVL_CURRENT (match);
04179 else
04180 t = NULL_TREE;
04181 }
04182
04183 if (t == error_mark_node)
04184 {
04185
04186 t = NULL_TREE;
04187 cp_error_at ("`%#D' used prior to declaration", x);
04188 }
04189 else if (t != NULL_TREE)
04190 {
04191 if (different_binding_level)
04192 {
04193 if (decls_match (x, t))
04194
04195
04196
04197
04198 TREE_PUBLIC (x) = TREE_PUBLIC (t);
04199 }
04200 else if (TREE_CODE (t) == PARM_DECL)
04201 {
04202 if (DECL_CONTEXT (t) == NULL_TREE)
04203
04204
04205 abort ();
04206
04207
04208 if (duplicate_decls (x, t))
04209 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04210 }
04211 else if ((DECL_EXTERN_C_FUNCTION_P (x)
04212 || DECL_FUNCTION_TEMPLATE_P (x))
04213 && is_overloaded_fn (t))
04214 ;
04215 else if (t == wchar_decl_node)
04216 {
04217 if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
04218 pedwarn ("redeclaration of `wchar_t' as `%T'",
04219 TREE_TYPE (x));
04220
04221
04222 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04223 }
04224 else if (TREE_CODE (t) != TREE_CODE (x))
04225 {
04226 if (duplicate_decls (x, t))
04227 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04228 }
04229 else if (duplicate_decls (x, t))
04230 {
04231 if (TREE_CODE (t) == TYPE_DECL)
04232 SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
04233 else if (TREE_CODE (t) == FUNCTION_DECL)
04234 check_default_args (t);
04235
04236 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04237 }
04238 else if (DECL_MAIN_P (x))
04239 {
04240
04241
04242
04243
04244
04245
04246 cp_error_at ("invalid redeclaration of `%D'", t);
04247 error ("as `%D'", x);
04248
04249
04250 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04251 }
04252 }
04253
04254 check_template_shadow (x);
04255
04256
04257
04258 if (DECL_NON_THUNK_FUNCTION_P (x) && ! DECL_LANG_SPECIFIC (x))
04259 {
04260 retrofit_lang_decl (x);
04261 SET_DECL_LANGUAGE (x, lang_c);
04262 }
04263
04264 if (DECL_NON_THUNK_FUNCTION_P (x) && ! DECL_FUNCTION_MEMBER_P (x))
04265 {
04266 t = push_overloaded_decl (x, PUSH_LOCAL);
04267 if (t != x)
04268 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04269 if (!namespace_bindings_p ())
04270
04271
04272
04273 need_new_binding = 0;
04274 }
04275 else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_NAMESPACE_SCOPE_P (x))
04276 {
04277 t = push_overloaded_decl (x, PUSH_GLOBAL);
04278 if (t == x)
04279 add_decl_to_level (x, NAMESPACE_LEVEL (CP_DECL_CONTEXT (t)));
04280 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04281 }
04282
04283
04284
04285
04286 if (TREE_CODE (x) == TYPE_DECL)
04287 {
04288 tree type = TREE_TYPE (x);
04289 if (DECL_SOURCE_LINE (x) == 0)
04290 {
04291 if (TYPE_NAME (type) == 0)
04292 TYPE_NAME (type) = x;
04293 }
04294 else if (type != error_mark_node && TYPE_NAME (type) != x
04295
04296
04297
04298 && (!TYPE_NAME (type)
04299 || TYPE_NAME (type) != DECL_ABSTRACT_ORIGIN (x)))
04300 {
04301 DECL_ORIGINAL_TYPE (x) = type;
04302 type = build_type_copy (type);
04303 TYPE_STUB_DECL (type) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x));
04304 TYPE_NAME (type) = x;
04305 TREE_TYPE (x) = type;
04306 }
04307
04308 if (type != error_mark_node
04309 && TYPE_NAME (type)
04310 && TYPE_IDENTIFIER (type))
04311 set_identifier_type_value_with_scope (DECL_NAME (x), type,
04312 current_binding_level);
04313
04314 }
04315
04316
04317
04318
04319
04320
04321
04322 if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
04323 {
04324 tree decl;
04325
04326 decl = IDENTIFIER_NAMESPACE_VALUE (name);
04327 if (decl && TREE_CODE (decl) == OVERLOAD)
04328 decl = OVL_FUNCTION (decl);
04329
04330 if (decl && decl != error_mark_node
04331 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl))
04332
04333 && TREE_CODE (decl) == TREE_CODE (x)
04334 && !same_type_p (TREE_TYPE (x), TREE_TYPE (decl)))
04335 {
04336 pedwarn ("type mismatch with previous external decl", x);
04337 cp_pedwarn_at ("previous external decl of `%#D'", decl);
04338 }
04339 }
04340
04341
04342
04343 if (namespace_bindings_p ())
04344 {
04345
04346
04347
04348
04349 if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
04350 TREE_PUBLIC (name) = 1;
04351
04352
04353 if (!(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
04354 && t != NULL_TREE)
04355 && (TREE_CODE (x) == TYPE_DECL
04356 || TREE_CODE (x) == VAR_DECL
04357 || TREE_CODE (x) == NAMESPACE_DECL
04358 || TREE_CODE (x) == CONST_DECL
04359 || TREE_CODE (x) == TEMPLATE_DECL))
04360 SET_IDENTIFIER_NAMESPACE_VALUE (name, x);
04361
04362
04363 if (IDENTIFIER_IMPLICIT_DECL (name)
04364 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
04365 TREE_USED (x) = 1;
04366
04367
04368 if (IDENTIFIER_IMPLICIT_DECL (name)
04369 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
04370 TREE_ADDRESSABLE (x) = 1;
04371
04372
04373 if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
04374
04375 && ! (TREE_CODE (x) == FUNCTION_DECL
04376 && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
04377 warning
04378 ("`%D' was previously implicitly declared to return `int'", x);
04379
04380
04381
04382 if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
04383 warn_extern_redeclared_static (x, t);
04384 }
04385 else
04386 {
04387
04388 tree oldlocal = IDENTIFIER_VALUE (name);
04389 tree oldglobal = IDENTIFIER_NAMESPACE_VALUE (name);
04390
04391 if (need_new_binding)
04392 {
04393 push_local_binding (name, x, 0);
04394
04395
04396
04397 need_new_binding = 0;
04398 }
04399
04400
04401 if (TREE_CODE (x) == TYPE_DECL)
04402 set_identifier_type_value_with_scope (name, TREE_TYPE (x),
04403 current_binding_level);
04404
04405
04406
04407
04408 if (TREE_CODE (x) == NAMESPACE_DECL)
04409 set_identifier_type_value_with_scope (name, NULL_TREE,
04410 current_binding_level);
04411
04412 if (oldlocal)
04413 {
04414 tree d = oldlocal;
04415
04416 while (oldlocal
04417 && TREE_CODE (oldlocal) == VAR_DECL
04418 && DECL_DEAD_FOR_LOCAL (oldlocal))
04419 oldlocal = DECL_SHADOWED_FOR_VAR (oldlocal);
04420
04421 if (oldlocal == NULL_TREE)
04422 oldlocal = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (d));
04423 }
04424
04425
04426
04427 if (oldlocal == NULL_TREE
04428 && DECL_EXTERNAL (x)
04429 && oldglobal != NULL_TREE
04430 && TREE_CODE (x) == FUNCTION_DECL
04431 && TREE_CODE (oldglobal) == FUNCTION_DECL)
04432 {
04433
04434 if (decls_match (x, oldglobal))
04435 ;
04436 else
04437 {
04438 warning ("extern declaration of `%#D' doesn't match", x);
04439 cp_warning_at ("global declaration `%#D'", oldglobal);
04440 }
04441 }
04442
04443
04444
04445 if (oldlocal == NULL_TREE
04446 && oldglobal == NULL_TREE
04447 && DECL_EXTERNAL (x)
04448 && TREE_PUBLIC (x))
04449 TREE_PUBLIC (name) = 1;
04450
04451
04452 if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
04453
04454 && !DECL_FROM_INLINE (x)
04455 && TREE_CODE (oldlocal) == PARM_DECL
04456
04457 && !DECL_ARTIFICIAL (oldlocal))
04458 {
04459 bool err = false;
04460
04461
04462 if (DECL_CONTEXT (oldlocal) == current_function_decl
04463 && TREE_CODE (x) != PARM_DECL)
04464 {
04465
04466
04467 struct cp_binding_level *b = current_binding_level->level_chain;
04468
04469
04470 if (b->parm_flag == 1)
04471 {
04472 error ("declaration of `%#D' shadows a parameter",
04473 name);
04474 err = true;
04475 }
04476 }
04477
04478 if (warn_shadow && !err)
04479 shadow_warning ("a parameter", name, oldlocal);
04480 }
04481
04482
04483 else if (warn_shadow && !DECL_EXTERNAL (x)
04484
04485 && ! DECL_ARTIFICIAL (x)
04486
04487 && ! DECL_FROM_INLINE (x))
04488 {
04489 if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
04490 && current_class_ptr
04491 && !TREE_STATIC (name))
04492 warning ("declaration of `%s' shadows a member of `this'",
04493 IDENTIFIER_POINTER (name));
04494 else if (oldlocal != NULL_TREE
04495 && TREE_CODE (oldlocal) == VAR_DECL)
04496 shadow_warning ("a previous local", name, oldlocal);
04497 else if (oldglobal != NULL_TREE
04498 && TREE_CODE (oldglobal) == VAR_DECL)
04499
04500 shadow_warning ("a global declaration", name, oldglobal);
04501 }
04502 }
04503
04504 if (TREE_CODE (x) == FUNCTION_DECL)
04505 check_default_args (x);
04506
04507 if (TREE_CODE (x) == VAR_DECL)
04508 maybe_register_incomplete_var (x);
04509 }
04510
04511 if (need_new_binding)
04512 add_decl_to_level (x,
04513 DECL_NAMESPACE_SCOPE_P (x)
04514 ? NAMESPACE_LEVEL (CP_DECL_CONTEXT (x))
04515 : current_binding_level);
04516
04517 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04518 }
04519
04520
04521
04522
04523 static tree
04524 pushdecl_with_scope (x, level)
04525 tree x;
04526 struct cp_binding_level *level;
04527 {
04528 register struct cp_binding_level *b;
04529 tree function_decl = current_function_decl;
04530
04531 timevar_push (TV_NAME_LOOKUP);
04532
04533 current_function_decl = NULL_TREE;
04534 if (level->parm_flag == 2)
04535 {
04536 b = class_binding_level;
04537 class_binding_level = level;
04538 pushdecl_class_level (x);
04539 class_binding_level = b;
04540 }
04541 else
04542 {
04543 b = current_binding_level;
04544 current_binding_level = level;
04545 x = pushdecl (x);
04546 current_binding_level = b;
04547 }
04548 current_function_decl = function_decl;
04549 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04550 }
04551
04552
04553
04554
04555 tree
04556 pushdecl_namespace_level (x)
04557 tree x;
04558 {
04559 register struct cp_binding_level *b = current_binding_level;
04560 register tree t;
04561
04562 timevar_push (TV_NAME_LOOKUP);
04563 t = pushdecl_with_scope (x, NAMESPACE_LEVEL (current_namespace));
04564
04565
04566
04567 if (TREE_CODE (x) == TYPE_DECL)
04568 {
04569 tree name = DECL_NAME (x);
04570 tree newval;
04571 tree *ptr = (tree *)0;
04572 for (; !global_scope_p (b); b = b->level_chain)
04573 {
04574 tree shadowed = b->type_shadowed;
04575 for (; shadowed; shadowed = TREE_CHAIN (shadowed))
04576 if (TREE_PURPOSE (shadowed) == name)
04577 {
04578 ptr = &TREE_VALUE (shadowed);
04579
04580
04581
04582 }
04583 }
04584 newval = TREE_TYPE (x);
04585 if (ptr == (tree *)0)
04586 {
04587
04588
04589 SET_IDENTIFIER_TYPE_VALUE (name, newval);
04590 }
04591 else
04592 {
04593 *ptr = newval;
04594 }
04595 }
04596 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
04597 }
04598
04599
04600
04601
04602
04603 static tree
04604 pushdecl_top_level_1 (tree x, tree *init)
04605 {
04606 timevar_push (TV_NAME_LOOKUP);
04607 push_to_top_level ();
04608 x = pushdecl_namespace_level (x);
04609 if (init)
04610 cp_finish_decl (x, *init, NULL_TREE, 0);
04611 pop_from_top_level ();
04612 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04613 }
04614
04615
04616
04617 tree
04618 pushdecl_top_level (tree x)
04619 {
04620 return pushdecl_top_level_1 (x, NULL);
04621 }
04622
04623
04624
04625
04626
04627 tree
04628 pushdecl_top_level_and_finish (tree x, tree init)
04629 {
04630 return pushdecl_top_level_1 (x, &init);
04631 }
04632
04633
04634
04635 bool
04636 pushdecl_class_level (x)
04637 tree x;
04638 {
04639 tree name;
04640 bool is_valid = true;
04641
04642 timevar_push (TV_NAME_LOOKUP);
04643
04644 if (TREE_CODE (x) == OVERLOAD)
04645 name = DECL_NAME (get_first_fn (x));
04646 else
04647 name = DECL_NAME (x);
04648
04649 if (name)
04650 {
04651 is_valid = push_class_level_binding (name, x);
04652 if (TREE_CODE (x) == TYPE_DECL)
04653 set_identifier_type_value (name, TREE_TYPE (x));
04654 }
04655 else if (ANON_AGGR_TYPE_P (TREE_TYPE (x)))
04656 {
04657
04658
04659
04660 tree f;
04661
04662 for (f = TYPE_FIELDS (TREE_TYPE (x)); f; f = TREE_CHAIN (f))
04663 {
04664 push_srcloc (DECL_SOURCE_FILE (f), DECL_SOURCE_LINE (f));
04665 if (!pushdecl_class_level (f))
04666 is_valid = false;
04667 pop_srcloc ();
04668 }
04669 }
04670 timevar_pop (TV_NAME_LOOKUP);
04671
04672 return is_valid;
04673 }
04674
04675
04676
04677
04678 tree
04679 maybe_push_decl (decl)
04680 tree decl;
04681 {
04682 tree type = TREE_TYPE (decl);
04683
04684
04685
04686
04687 if (decl == error_mark_node
04688 || (TREE_CODE (decl) != PARM_DECL
04689 && DECL_CONTEXT (decl) != NULL_TREE
04690
04691
04692 && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL)
04693 || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ())
04694 || TREE_CODE (type) == UNKNOWN_TYPE
04695
04696
04697
04698 || (TREE_CODE (decl) == FUNCTION_DECL
04699 && DECL_TEMPLATE_SPECIALIZATION (decl)))
04700 return decl;
04701 else
04702 return pushdecl (decl);
04703 }
04704
04705
04706
04707
04708 bool
04709 push_class_level_binding (tree name, tree x)
04710 {
04711 cxx_binding *binding;
04712
04713 timevar_push (TV_NAME_LOOKUP);
04714
04715
04716 if (!class_binding_level)
04717 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
04718
04719
04720
04721 if (TYPE_BEING_DEFINED (current_class_type))
04722 check_template_shadow (x);
04723
04724
04725
04726
04727 binding = IDENTIFIER_BINDING (name);
04728 if (binding
04729 && ((TREE_CODE (x) == OVERLOAD
04730 && BINDING_VALUE (binding)
04731 && is_overloaded_fn (BINDING_VALUE (binding)))
04732 || INHERITED_VALUE_BINDING_P (binding)))
04733 {
04734 tree shadow;
04735 tree old_decl;
04736
04737
04738
04739
04740
04741 if (INHERITED_VALUE_BINDING_P (binding)
04742 && BINDING_VALUE (binding)
04743 && TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL
04744 && DECL_ARTIFICIAL (BINDING_VALUE (binding))
04745 && !(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)))
04746 {
04747 old_decl = BINDING_TYPE (binding);
04748 BINDING_TYPE (binding) = BINDING_VALUE (binding);
04749 BINDING_VALUE (binding) = NULL_TREE;
04750 INHERITED_VALUE_BINDING_P (binding) = 0;
04751 }
04752 else
04753 old_decl = BINDING_VALUE (binding);
04754
04755
04756
04757 for (shadow = class_binding_level->class_shadowed;
04758 shadow;
04759 shadow = TREE_CHAIN (shadow))
04760 if (TREE_PURPOSE (shadow) == name
04761 && TREE_TYPE (shadow) == old_decl)
04762 {
04763 BINDING_VALUE (binding) = x;
04764 INHERITED_VALUE_BINDING_P (binding) = 0;
04765 TREE_TYPE (shadow) = x;
04766 IDENTIFIER_CLASS_VALUE (name) = x;
04767 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
04768 }
04769 }
04770
04771
04772
04773 if (push_class_binding (name, x))
04774 {
04775 class_binding_level->class_shadowed
04776 = tree_cons (name, NULL,
04777 class_binding_level->class_shadowed);
04778
04779
04780 TREE_TYPE (class_binding_level->class_shadowed) = x;
04781 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
04782 }
04783
04784 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, false);
04785 }
04786
04787
04788
04789
04790
04791
04792 tree
04793 push_using_decl (scope, name)
04794 tree scope;
04795 tree name;
04796 {
04797 tree decl;
04798
04799 timevar_push (TV_NAME_LOOKUP);
04800
04801 my_friendly_assert (TREE_CODE (scope) == NAMESPACE_DECL, 383);
04802 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 384);
04803 for (decl = current_binding_level->usings; decl; decl = TREE_CHAIN (decl))
04804 if (DECL_INITIAL (decl) == scope && DECL_NAME (decl) == name)
04805 break;
04806 if (decl)
04807 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP,
04808 namespace_bindings_p () ? decl : NULL_TREE);
04809 decl = build_lang_decl (USING_DECL, name, void_type_node);
04810 DECL_INITIAL (decl) = scope;
04811 TREE_CHAIN (decl) = current_binding_level->usings;
04812 current_binding_level->usings = decl;
04813 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
04814 }
04815
04816
04817
04818
04819
04820 tree
04821 push_using_directive (used)
04822 tree used;
04823 {
04824 tree ud = current_binding_level->using_directives;
04825 tree iter, ancestor;
04826
04827 timevar_push (TV_NAME_LOOKUP);
04828
04829
04830 if (purpose_member (used, ud) != NULL_TREE)
04831 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
04832
04833 ancestor = namespace_ancestor (current_decl_namespace (), used);
04834 ud = current_binding_level->using_directives;
04835 ud = tree_cons (used, ancestor, ud);
04836 current_binding_level->using_directives = ud;
04837
04838
04839 for (iter = DECL_NAMESPACE_USING (used); iter; iter = TREE_CHAIN (iter))
04840 push_using_directive (TREE_PURPOSE (iter));
04841
04842 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ud);
04843 }
04844
04845
04846
04847
04848
04849
04850
04851
04852
04853
04854
04855
04856
04857
04858
04859
04860
04861
04862
04863
04864 tree
04865 push_overloaded_decl (decl, flags)
04866 tree decl;
04867 int flags;
04868 {
04869 tree name = DECL_NAME (decl);
04870 tree old;
04871 tree new_binding;
04872 int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL));
04873
04874 timevar_push (TV_NAME_LOOKUP);
04875
04876 if (doing_global)
04877 old = namespace_binding (name, DECL_CONTEXT (decl));
04878 else
04879 old = lookup_name_current_level (name);
04880
04881 if (old)
04882 {
04883 if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
04884 {
04885 tree t = TREE_TYPE (old);
04886 if (IS_AGGR_TYPE (t) && warn_shadow
04887 && (! DECL_IN_SYSTEM_HEADER (decl)
04888 || ! DECL_IN_SYSTEM_HEADER (old)))
04889 warning ("`%#D' hides constructor for `%#T'", decl, t);
04890 old = NULL_TREE;
04891 }
04892 else if (is_overloaded_fn (old))
04893 {
04894 tree tmp;
04895
04896 for (tmp = old; tmp; tmp = OVL_NEXT (tmp))
04897 {
04898 tree fn = OVL_CURRENT (tmp);
04899
04900 if (TREE_CODE (tmp) == OVERLOAD && OVL_USED (tmp)
04901 && !(flags & PUSH_USING)
04902 && compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
04903 TYPE_ARG_TYPES (TREE_TYPE (decl))))
04904 error ("`%#D' conflicts with previous using declaration `%#D'",
04905 decl, fn);
04906
04907 if (duplicate_decls (decl, fn))
04908 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, fn);
04909 }
04910 }
04911 else if (old == error_mark_node)
04912
04913 old = NULL_TREE;
04914 else
04915 {
04916 cp_error_at ("previous non-function declaration `%#D'", old);
04917 error ("conflicts with function declaration `%#D'", decl);
04918 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
04919 }
04920 }
04921
04922 if (old || TREE_CODE (decl) == TEMPLATE_DECL)
04923 {
04924 if (old && TREE_CODE (old) != OVERLOAD)
04925 new_binding = ovl_cons (decl, ovl_cons (old, NULL_TREE));
04926 else
04927 new_binding = ovl_cons (decl, old);
04928 if (flags & PUSH_USING)
04929 OVL_USED (new_binding) = 1;
04930 }
04931 else
04932
04933 new_binding = decl;
04934
04935 if (doing_global)
04936 set_namespace_binding (name, current_namespace, new_binding);
04937 else
04938 {
04939
04940
04941
04942
04943
04944
04945 if (TREE_CODE (new_binding) == OVERLOAD && old)
04946 {
04947 tree *d;
04948
04949 for (d = &BINDING_LEVEL (IDENTIFIER_BINDING (name))->names;
04950 *d;
04951 d = &TREE_CHAIN (*d))
04952 if (*d == old
04953 || (TREE_CODE (*d) == TREE_LIST
04954 && TREE_VALUE (*d) == old))
04955 {
04956 if (TREE_CODE (*d) == TREE_LIST)
04957
04958 TREE_VALUE (*d) = new_binding;
04959 else
04960
04961 *d = tree_cons (NULL_TREE, new_binding,
04962 TREE_CHAIN (*d));
04963
04964
04965 BINDING_VALUE (IDENTIFIER_BINDING (name))
04966 = new_binding;
04967 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
04968 }
04969
04970
04971 abort ();
04972 }
04973
04974
04975 push_local_binding (name, new_binding, flags);
04976 }
04977
04978 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
04979 }
04980
04981
04982
04983
04984 tree
04985 implicitly_declare (functionid)
04986 tree functionid;
04987 {
04988 register tree decl;
04989
04990
04991
04992
04993 decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
04994
04995 DECL_EXTERNAL (decl) = 1;
04996 TREE_PUBLIC (decl) = 1;
04997
04998
04999
05000 pushdecl (decl);
05001 rest_of_decl_compilation (decl, NULL, 0, 0);
05002
05003 if (warn_implicit
05004
05005 && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
05006 {
05007 pedwarn ("implicit declaration of function `%#D'", decl);
05008 }
05009
05010 SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
05011
05012 return decl;
05013 }
05014
05015
05016
05017
05018
05019
05020
05021 static const char *
05022 redeclaration_error_message (newdecl, olddecl)
05023 tree newdecl, olddecl;
05024 {
05025 if (TREE_CODE (newdecl) == TYPE_DECL)
05026 {
05027
05028
05029
05030 if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
05031 return 0;
05032 else
05033 return "redefinition of `%#D'";
05034 }
05035 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
05036 {
05037
05038
05039
05040 if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl))
05041 return 0;
05042
05043
05044
05045 if (DECL_NAMESPACE_SCOPE_P (olddecl)
05046 && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl))
05047 return "`%D' conflicts with used function";
05048
05049
05050
05051
05052
05053 if (DECL_INITIAL (olddecl) != NULL_TREE
05054 && DECL_INITIAL (newdecl) != NULL_TREE)
05055 {
05056 if (DECL_NAME (olddecl) == NULL_TREE)
05057 return "`%#D' not declared in class";
05058 else
05059 return "redefinition of `%#D'";
05060 }
05061 return 0;
05062 }
05063 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
05064 {
05065 if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
05066 && (DECL_TEMPLATE_RESULT (newdecl)
05067 != DECL_TEMPLATE_RESULT (olddecl))
05068 && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl))
05069 && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)))
05070 || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL
05071 && COMPLETE_TYPE_P (TREE_TYPE (newdecl))
05072 && COMPLETE_TYPE_P (TREE_TYPE (olddecl))))
05073 return "redefinition of `%#D'";
05074 return 0;
05075 }
05076 else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
05077 {
05078
05079
05080 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
05081 return 0;
05082
05083 return "redefinition of `%#D'";
05084 }
05085 else
05086 {
05087
05088
05089
05090 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
05091 return "redeclaration of `%#D'";
05092 return 0;
05093 }
05094 }
05095
05096
05097
05098 static tree
05099 make_label_decl (id, local_p)
05100 tree id;
05101 int local_p;
05102 {
05103 tree decl;
05104
05105 decl = build_decl (LABEL_DECL, id, void_type_node);
05106 if (expanding_p)
05107
05108 label_rtx (decl);
05109
05110 DECL_CONTEXT (decl) = current_function_decl;
05111 DECL_MODE (decl) = VOIDmode;
05112 C_DECLARED_LABEL_FLAG (decl) = local_p;
05113
05114
05115
05116 DECL_SOURCE_LINE (decl) = lineno;
05117 DECL_SOURCE_FILE (decl) = input_filename;
05118
05119
05120 SET_IDENTIFIER_LABEL_VALUE (id, decl);
05121
05122 return decl;
05123 }
05124
05125
05126
05127
05128
05129
05130 static void
05131 use_label (decl)
05132 tree decl;
05133 {
05134 if (named_label_uses == NULL
05135 || named_label_uses->names_in_scope != current_binding_level->names
05136 || named_label_uses->label_decl != decl)
05137 {
05138 struct named_label_use_list *new_ent;
05139 new_ent = ((struct named_label_use_list *)
05140 ggc_alloc (sizeof (struct named_label_use_list)));
05141 new_ent->label_decl = decl;
05142 new_ent->names_in_scope = current_binding_level->names;
05143 new_ent->binding_level = current_binding_level;
05144 new_ent->lineno_o_goto = lineno;
05145 new_ent->filename_o_goto = input_filename;
05146 new_ent->next = named_label_uses;
05147 named_label_uses = new_ent;
05148 }
05149 }
05150
05151
05152
05153
05154
05155 tree
05156 lookup_label (id)
05157 tree id;
05158 {
05159 tree decl;
05160 struct named_label_list *ent;
05161
05162 timevar_push (TV_NAME_LOOKUP);
05163
05164
05165 if (current_function_decl == NULL_TREE)
05166 {
05167 error ("label `%s' referenced outside of any function",
05168 IDENTIFIER_POINTER (id));
05169 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05170 }
05171
05172
05173 decl = IDENTIFIER_LABEL_VALUE (id);
05174 if (decl != NULL_TREE && DECL_CONTEXT (decl) == current_function_decl)
05175 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
05176
05177
05178
05179
05180 ent = ((struct named_label_list *)
05181 ggc_alloc_cleared (sizeof (struct named_label_list)));
05182 ent->old_value = IDENTIFIER_LABEL_VALUE (id);
05183 ent->next = named_labels;
05184 named_labels = ent;
05185
05186
05187 decl = make_label_decl (id, 0);
05188
05189
05190 ent->label_decl = decl;
05191
05192 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
05193 }
05194
05195
05196
05197 tree
05198 declare_local_label (id)
05199 tree id;
05200 {
05201 tree decl;
05202
05203
05204
05205
05206 current_binding_level->shadowed_labels
05207 = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
05208 current_binding_level->shadowed_labels);
05209
05210 decl = make_label_decl (id, 1);
05211
05212 TREE_VALUE (current_binding_level->shadowed_labels) = decl;
05213
05214 return decl;
05215 }
05216
05217
05218
05219
05220 static int
05221 decl_jump_unsafe (decl)
05222 tree decl;
05223 {
05224 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl))
05225 return 0;
05226
05227 if (DECL_INITIAL (decl) == NULL_TREE
05228 && pod_type_p (TREE_TYPE (decl)))
05229 return 0;
05230
05231
05232
05233
05234 if (DECL_INITIAL (decl)
05235 || (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))
05236 return 2;
05237 return 1;
05238 }
05239
05240
05241
05242
05243
05244
05245 static void
05246 check_previous_goto_1 (decl, level, names, file, line)
05247 tree decl;
05248 struct cp_binding_level *level;
05249 tree names;
05250 const char *file;
05251 int line;
05252 {
05253 int identified = 0;
05254 int saw_eh = 0;
05255 struct cp_binding_level *b = current_binding_level;
05256 for (; b; b = b->level_chain)
05257 {
05258 tree new_decls = b->names;
05259 tree old_decls = (b == level ? names : NULL_TREE);
05260 for (; new_decls != old_decls;
05261 new_decls = TREE_CHAIN (new_decls))
05262 {
05263 int problem = decl_jump_unsafe (new_decls);
05264 if (! problem)
05265 continue;
05266
05267 if (! identified)
05268 {
05269 if (decl)
05270 pedwarn ("jump to label `%D'", decl);
05271 else
05272 pedwarn ("jump to case label");
05273
05274 if (file)
05275 pedwarn_with_file_and_line (file, line, " from here");
05276 identified = 1;
05277 }
05278
05279 if (problem > 1)
05280 cp_error_at (" crosses initialization of `%#D'",
05281 new_decls);
05282 else
05283 cp_pedwarn_at (" enters scope of non-POD `%#D'",
05284 new_decls);
05285 }
05286
05287 if (b == level)
05288 break;
05289 if ((b->is_try_scope || b->is_catch_scope) && ! saw_eh)
05290 {
05291 if (! identified)
05292 {
05293 if (decl)
05294 pedwarn ("jump to label `%D'", decl);
05295 else
05296 pedwarn ("jump to case label");
05297
05298 if (file)
05299 pedwarn_with_file_and_line (file, line, " from here");
05300 identified = 1;
05301 }
05302 if (b->is_try_scope)
05303 error (" enters try block");
05304 else
05305 error (" enters catch block");
05306 saw_eh = 1;
05307 }
05308 }
05309 }
05310
05311 static void
05312 check_previous_goto (use)
05313 struct named_label_use_list *use;
05314 {
05315 check_previous_goto_1 (use->label_decl, use->binding_level,
05316 use->names_in_scope, use->filename_o_goto,
05317 use->lineno_o_goto);
05318 }
05319
05320 static void
05321 check_switch_goto (level)
05322 struct cp_binding_level *level;
05323 {
05324 check_previous_goto_1 (NULL_TREE, level, level->names, NULL, 0);
05325 }
05326
05327
05328
05329
05330 static void
05331 check_previous_gotos (decl)
05332 tree decl;
05333 {
05334 struct named_label_use_list **usep;
05335
05336 if (! TREE_USED (decl))
05337 return;
05338
05339 for (usep = &named_label_uses; *usep; )
05340 {
05341 struct named_label_use_list *use = *usep;
05342 if (use->label_decl == decl)
05343 {
05344 check_previous_goto (use);
05345 *usep = use->next;
05346 }
05347 else
05348 usep = &(use->next);
05349 }
05350 }
05351
05352
05353
05354
05355 void
05356 check_goto (decl)
05357 tree decl;
05358 {
05359 int identified = 0;
05360 tree bad;
05361 struct named_label_list *lab;
05362
05363
05364
05365 if (! DECL_P (decl))
05366 return;
05367
05368
05369 if (! DECL_INITIAL (decl))
05370 {
05371 use_label (decl);
05372 return;
05373 }
05374
05375 for (lab = named_labels; lab; lab = lab->next)
05376 if (decl == lab->label_decl)
05377 break;
05378
05379
05380
05381 if (lab == 0)
05382 return;
05383
05384 if ((lab->in_try_scope || lab->in_catch_scope || lab->bad_decls)
05385 && !identified)
05386 {
05387 cp_pedwarn_at ("jump to label `%D'", decl);
05388 pedwarn (" from here");
05389 identified = 1;
05390 }
05391
05392 for (bad = lab->bad_decls; bad; bad = TREE_CHAIN (bad))
05393 {
05394 tree b = TREE_VALUE (bad);
05395 int u = decl_jump_unsafe (b);
05396
05397 if (u > 1 && DECL_ARTIFICIAL (b))
05398
05399 cp_error_at (" enters catch block", b);
05400 else if (u > 1)
05401 cp_error_at (" skips initialization of `%#D'", b);
05402 else
05403 cp_pedwarn_at (" enters scope of non-POD `%#D'", b);
05404 }
05405
05406 if (lab->in_try_scope)
05407 error (" enters try block");
05408 else if (lab->in_catch_scope)
05409 error (" enters catch block");
05410 }
05411
05412
05413
05414
05415 tree
05416 define_label (filename, line, name)
05417 const char *filename;
05418 int line;
05419 tree name;
05420 {
05421 tree decl = lookup_label (name);
05422 struct named_label_list *ent;
05423 register struct cp_binding_level *p;
05424
05425 timevar_push (TV_NAME_LOOKUP);
05426
05427 for (ent = named_labels; ent; ent = ent->next)
05428 if (ent->label_decl == decl)
05429 break;
05430
05431
05432
05433 for (p = current_binding_level; !(p->parm_flag); p = p->level_chain)
05434 p->more_cleanups_ok = 0;
05435
05436 if (name == get_identifier ("wchar_t"))
05437 pedwarn ("label named wchar_t");
05438
05439 if (DECL_INITIAL (decl) != NULL_TREE)
05440 error ("duplicate label `%D'", decl);
05441 else
05442 {
05443
05444 DECL_INITIAL (decl) = error_mark_node;
05445
05446 DECL_SOURCE_FILE (decl) = filename;
05447 DECL_SOURCE_LINE (decl) = line;
05448 if (ent)
05449 {
05450 ent->names_in_scope = current_binding_level->names;
05451 ent->binding_level = current_binding_level;
05452 }
05453 check_previous_gotos (decl);
05454 }
05455
05456 timevar_pop (TV_NAME_LOOKUP);
05457 return decl;
05458 }
05459
05460 struct cp_switch
05461 {
05462 struct cp_binding_level *level;
05463 struct cp_switch *next;
05464
05465 tree switch_stmt;
05466
05467
05468
05469
05470
05471 splay_tree cases;
05472 };
05473
05474
05475
05476
05477
05478
05479
05480 static struct cp_switch *switch_stack;
05481
05482
05483
05484
05485 void
05486 push_switch (switch_stmt)
05487 tree switch_stmt;
05488 {
05489 struct cp_switch *p
05490 = (struct cp_switch *) xmalloc (sizeof (struct cp_switch));
05491 p->level = current_binding_level;
05492 p->next = switch_stack;
05493 p->switch_stmt = switch_stmt;
05494 p->cases = splay_tree_new (case_compare, NULL, NULL);
05495 switch_stack = p;
05496 }
05497
05498 void
05499 pop_switch ()
05500 {
05501 struct cp_switch *cs;
05502
05503 cs = switch_stack;
05504 splay_tree_delete (cs->cases);
05505 switch_stack = switch_stack->next;
05506 free (cs);
05507 }
05508
05509
05510
05511
05512 tree
05513 finish_case_label (low_value, high_value)
05514 tree low_value;
05515 tree high_value;
05516 {
05517 tree cond, r;
05518 register struct cp_binding_level *p;
05519
05520 if (! switch_stack)
05521 {
05522 if (high_value)
05523 error ("case label not within a switch statement");
05524 else if (low_value)
05525 error ("case label `%E' not within a switch statement",
05526 low_value);
05527 else
05528 error ("`default' label not within a switch statement");
05529 return NULL_TREE;
05530 }
05531
05532 if (processing_template_decl)
05533 {
05534 tree label;
05535
05536
05537
05538 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
05539 return add_stmt (build_case_label (low_value, high_value, label));
05540 }
05541
05542
05543 cond = SWITCH_COND (switch_stack->switch_stmt);
05544 if (cond && TREE_CODE (cond) == TREE_LIST)
05545 cond = TREE_VALUE (cond);
05546
05547 r = c_add_case_label (switch_stack->cases, cond, low_value, high_value);
05548 if (r == error_mark_node)
05549 r = NULL_TREE;
05550
05551 check_switch_goto (switch_stack->level);
05552
05553
05554
05555 for (p = current_binding_level; !(p->parm_flag); p = p->level_chain)
05556 p->more_cleanups_ok = 0;
05557
05558 return r;
05559 }
05560
05561
05562
05563
05564
05565
05566 tree
05567 getdecls ()
05568 {
05569 return current_binding_level->names;
05570 }
05571
05572
05573
05574
05575
05576 static void
05577 storedecls (decls)
05578 tree decls;
05579 {
05580 current_binding_level->names = decls;
05581 }
05582
05583
05584
05585
05586 void
05587 cxx_remember_type_decls (binding_table table)
05588 {
05589 current_binding_level->type_decls = table;
05590 }
05591
05592
05593
05594
05595
05596
05597
05598
05599
05600
05601
05602
05603
05604
05605
05606
05607
05608
05609
05610
05611
05612
05613
05614
05615
05616 static tree
05617 follow_tag_typedef (type)
05618 tree type;
05619 {
05620 tree original;
05621
05622 original = original_type (type);
05623 if (! TYPE_NAME (original))
05624 return NULL_TREE;
05625 if (TYPE_IDENTIFIER (original) == TYPE_IDENTIFIER (type)
05626 && (CP_DECL_CONTEXT (TYPE_NAME (original))
05627 == CP_DECL_CONTEXT (TYPE_NAME (type)))
05628 && !(CLASS_TYPE_P (original) && TYPE_WAS_ANONYMOUS (original)))
05629 return original;
05630 else
05631 return NULL_TREE;
05632 }
05633
05634
05635
05636
05637
05638
05639
05640
05641
05642
05643
05644
05645 static tree
05646 lookup_tag (form, name, binding_level, thislevel_only)
05647 enum tree_code form;
05648 tree name;
05649 struct cp_binding_level *binding_level;
05650 int thislevel_only;
05651 {
05652 register struct cp_binding_level *level;
05653
05654
05655 int allow_template_parms_p = 1;
05656 bool type_is_anonymous = ANON_AGGRNAME_P (name);
05657
05658 timevar_push (TV_NAME_LOOKUP);
05659
05660 for (level = binding_level; level; level = level->level_chain)
05661 {
05662 register tree tail;
05663 if (type_is_anonymous && level->type_decls != NULL)
05664 {
05665 tree type = binding_table_find_anon_type (level->type_decls, name);
05666
05667
05668 if (type != NULL)
05669 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, type);
05670 }
05671 else if (level->namespace_p)
05672
05673 for (tail = current_namespace; 1; tail = CP_DECL_CONTEXT (tail))
05674 {
05675 cxx_binding *binding =
05676 cxx_scope_find_binding_for_name (tail, name);
05677 tree old;
05678
05679
05680
05681
05682
05683 if (thislevel_only && !allow_template_parms_p
05684 && binding && BINDING_VALUE (binding)
05685 && DECL_CLASS_TEMPLATE_P (BINDING_VALUE (binding)))
05686 old = TREE_TYPE (BINDING_VALUE (binding));
05687 else if (binding)
05688 old = BINDING_TYPE (binding);
05689 else
05690 old = NULL;
05691
05692 if (old)
05693 {
05694
05695
05696
05697 old = follow_tag_typedef (old);
05698 if (!old)
05699 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05700 if (TREE_CODE (old) != form
05701 && (form == ENUMERAL_TYPE
05702 || TREE_CODE (old) == ENUMERAL_TYPE))
05703 {
05704 error ("`%#D' redeclared as %C", old, form);
05705 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05706 }
05707 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, old);
05708 }
05709 if (thislevel_only || tail == global_namespace)
05710 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05711 }
05712 else if (level->type_decls != NULL)
05713 {
05714 binding_entry entry = binding_table_find (level->type_decls, name);
05715 if (entry != NULL)
05716 {
05717 enum tree_code code = TREE_CODE (entry->type);
05718
05719 if (code != form
05720 && (form == ENUMERAL_TYPE || code == ENUMERAL_TYPE))
05721 {
05722
05723 error ("`%#D' redeclared as %C", entry->type, form);
05724 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05725 }
05726 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, entry->type);
05727 }
05728 }
05729 if (thislevel_only && ! level->tag_transparent)
05730 {
05731 if (level->template_parms_p && allow_template_parms_p)
05732 {
05733
05734
05735
05736
05737
05738
05739
05740
05741
05742
05743
05744 allow_template_parms_p = 0;
05745 continue;
05746 }
05747 else
05748 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05749 }
05750 }
05751 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05752 }
05753
05754 #if 0
05755 void
05756 set_current_level_tags_transparency (tags_transparent)
05757 int tags_transparent;
05758 {
05759 current_binding_level->tag_transparent = tags_transparent;
05760 }
05761 #endif
05762
05763
05764
05765
05766
05767
05768
05769
05770 static tree
05771 lookup_tag_reverse (type, name)
05772 tree type;
05773 tree name;
05774 {
05775 register struct cp_binding_level *level;
05776
05777 timevar_push (TV_NAME_LOOKUP);
05778
05779 for (level = current_binding_level; level; level = level->level_chain)
05780 {
05781 binding_entry entry = level->type_decls == NULL
05782 ? NULL
05783 : binding_table_reverse_maybe_remap (level->type_decls, type, name);
05784 if (entry)
05785 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, entry->name);
05786 }
05787 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
05788 }
05789
05790
05791
05792 tree
05793 lookup_namespace_name (namespace, name)
05794 tree namespace, name;
05795 {
05796 tree val;
05797 tree template_id = NULL_TREE;
05798 cxx_binding binding;
05799
05800 timevar_push (TV_NAME_LOOKUP);
05801
05802 my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370);
05803
05804 if (TREE_CODE (name) == NAMESPACE_DECL)
05805
05806 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, name);
05807 else if (TREE_CODE (name) == TEMPLATE_DECL)
05808 {
05809
05810
05811 error ("invalid use of `%D'", name);
05812 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
05813 }
05814
05815 namespace = ORIGINAL_NAMESPACE (namespace);
05816
05817 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
05818 {
05819 template_id = name;
05820 name = TREE_OPERAND (name, 0);
05821 if (TREE_CODE (name) == OVERLOAD)
05822 name = DECL_NAME (OVL_CURRENT (name));
05823 else if (DECL_P (name))
05824 name = DECL_NAME (name);
05825 }
05826
05827 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373);
05828
05829 cxx_binding_clear (&binding);
05830 if (!qualified_lookup_using_namespace (name, namespace, &binding, 0))
05831 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
05832
05833 if (binding.value)
05834 {
05835 val = binding.value;
05836
05837 if (template_id)
05838 {
05839 if (DECL_CLASS_TEMPLATE_P (val))
05840 val = lookup_template_class (val,
05841 TREE_OPERAND (template_id, 1),
05842 NULL_TREE,
05843 NULL_TREE,
05844 0,
05845 tf_error | tf_warning);
05846 else if (DECL_FUNCTION_TEMPLATE_P (val)
05847 || TREE_CODE (val) == OVERLOAD)
05848 val = lookup_template_function (val,
05849 TREE_OPERAND (template_id, 1));
05850 else
05851 {
05852 error ("`%D::%D' is not a template",
05853 namespace, name);
05854 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
05855 }
05856 }
05857
05858
05859 if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val))
05860 val = OVL_FUNCTION (val);
05861
05862
05863 if (!val || !DECL_P(val)
05864 || !DECL_LANG_SPECIFIC(val)
05865 || !DECL_ANTICIPATED (val))
05866 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
05867 }
05868
05869 error ("`%D' undeclared in namespace `%D'", name, namespace);
05870 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
05871 }
05872
05873
05874
05875 static hashval_t
05876 typename_hash (k)
05877 const void * k;
05878 {
05879 hashval_t hash;
05880 tree t = (tree) k;
05881
05882 hash = (htab_hash_pointer (TYPE_CONTEXT (t))
05883 ^ htab_hash_pointer (DECL_NAME (TYPE_NAME (t))));
05884
05885 return hash;
05886 }
05887
05888
05889
05890 static int
05891 typename_compare (k1, k2)
05892 const void * k1;
05893 const void * k2;
05894 {
05895 tree t1;
05896 tree t2;
05897 tree d1;
05898 tree d2;
05899
05900 t1 = (tree) k1;
05901 t2 = (tree) k2;
05902 d1 = TYPE_NAME (t1);
05903 d2 = TYPE_NAME (t2);
05904
05905 return (DECL_NAME (d1) == DECL_NAME (d2)
05906 && TYPE_CONTEXT (t1) == TYPE_CONTEXT (t2)
05907 && ((TREE_TYPE (t1) != NULL_TREE)
05908 == (TREE_TYPE (t2) != NULL_TREE))
05909 && same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
05910 && TYPENAME_TYPE_FULLNAME (t1) == TYPENAME_TYPE_FULLNAME (t2));
05911 }
05912
05913
05914
05915
05916
05917
05918
05919
05920
05921 static GTY ((param_is (union tree_node))) htab_t typename_htab;
05922
05923 tree
05924 build_typename_type (context, name, fullname, base_type)
05925 tree context;
05926 tree name;
05927 tree fullname;
05928 tree base_type;
05929 {
05930 tree t;
05931 tree d;
05932 PTR *e;
05933
05934 if (typename_htab == NULL)
05935 {
05936 typename_htab = htab_create_ggc (61, &typename_hash,
05937 &typename_compare, NULL);
05938 }
05939
05940
05941 t = make_aggr_type (TYPENAME_TYPE);
05942 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
05943 TYPENAME_TYPE_FULLNAME (t) = fullname;
05944 TREE_TYPE (t) = base_type;
05945
05946
05947 d = build_decl (TYPE_DECL, name, t);
05948 TYPE_NAME (TREE_TYPE (d)) = d;
05949 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
05950 DECL_CONTEXT (d) = FROB_CONTEXT (context);
05951 DECL_ARTIFICIAL (d) = 1;
05952
05953
05954 e = htab_find_slot (typename_htab, t, INSERT);
05955 if (*e)
05956 t = (tree) *e;
05957 else
05958 *e = t;
05959
05960 return t;
05961 }
05962
05963
05964
05965
05966
05967
05968
05969
05970 tree
05971 make_typename_type (context, name, complain)
05972 tree context, name;
05973 tsubst_flags_t complain;
05974 {
05975 tree fullname;
05976
05977 if (TYPE_P (name))
05978 {
05979 if (!(TYPE_LANG_SPECIFIC (name)
05980 && (CLASSTYPE_IS_TEMPLATE (name)
05981 || CLASSTYPE_USE_TEMPLATE (name))))
05982 name = TYPE_IDENTIFIER (name);
05983 else
05984
05985 name = build_nt (TEMPLATE_ID_EXPR,
05986 CLASSTYPE_TI_TEMPLATE (name),
05987 CLASSTYPE_TI_ARGS (name));
05988 }
05989 else if (TREE_CODE (name) == TYPE_DECL)
05990 name = DECL_NAME (name);
05991
05992 fullname = name;
05993
05994 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
05995 {
05996 name = TREE_OPERAND (name, 0);
05997 if (TREE_CODE (name) == TEMPLATE_DECL)
05998 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
05999 }
06000 if (TREE_CODE (name) == TEMPLATE_DECL)
06001 {
06002 error ("`%D' used without template parameters", name);
06003 return error_mark_node;
06004 }
06005 if (TREE_CODE (name) != IDENTIFIER_NODE)
06006 abort ();
06007
06008 if (TREE_CODE (context) == NAMESPACE_DECL)
06009 {
06010
06011
06012 if (complain & tf_error)
06013 error ("no class template named `%#T' in `%#T'",
06014 name, context);
06015 return error_mark_node;
06016 }
06017
06018 if (! uses_template_parms (context)
06019 || currently_open_class (context))
06020 {
06021 if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
06022 {
06023 tree tmpl = NULL_TREE;
06024 if (IS_AGGR_TYPE (context))
06025 tmpl = lookup_field (context, name, 0, 0);
06026 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
06027 {
06028 if (complain & tf_error)
06029 error ("no class template named `%#T' in `%#T'",
06030 name, context);
06031 return error_mark_node;
06032 }
06033
06034 if (complain & tf_error)
06035 {
06036 if (complain & tf_parsing)
06037 type_access_control (context, tmpl);
06038 else
06039 enforce_access (context, tmpl);
06040 }
06041
06042 return lookup_template_class (tmpl,
06043 TREE_OPERAND (fullname, 1),
06044 NULL_TREE, context,
06045 0,
06046 tf_error | tf_warning);
06047 }
06048 else
06049 {
06050 tree t;
06051
06052 if (!IS_AGGR_TYPE (context))
06053 {
06054 if (complain & tf_error)
06055 error ("no type named `%#T' in `%#T'", name, context);
06056 return error_mark_node;
06057 }
06058
06059 t = lookup_field (context, name, 0, 1);
06060 if (t)
06061 {
06062 if (TREE_CODE (t) != TYPE_DECL)
06063 {
06064 if (complain & tf_error)
06065 error ("no type named `%#T' in `%#T'", name, context);
06066 return error_mark_node;
06067 }
06068
06069 if (complain & tf_error)
06070 {
06071 if (complain & tf_parsing)
06072 type_access_control (context, t);
06073 else
06074 enforce_access (context, t);
06075 }
06076
06077 if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
06078 t = TREE_TYPE (t);
06079 if (IMPLICIT_TYPENAME_P (t))
06080 {
06081
06082
06083
06084
06085
06086 t = copy_node (t);
06087 TREE_TYPE (t) = NULL_TREE;
06088 }
06089
06090 return t;
06091 }
06092 }
06093 }
06094
06095
06096
06097 if (!uses_template_parms (context))
06098 {
06099 if (complain & tf_error)
06100 error ("no type named `%#T' in `%#T'", name, context);
06101 return error_mark_node;
06102 }
06103
06104 return build_typename_type (context, name, fullname, NULL_TREE);
06105 }
06106
06107
06108
06109
06110
06111
06112
06113 tree
06114 make_unbound_class_template (context, name, complain)
06115 tree context, name;
06116 tsubst_flags_t complain;
06117 {
06118 tree t;
06119 tree d;
06120
06121 if (TYPE_P (name))
06122 name = TYPE_IDENTIFIER (name);
06123 else if (DECL_P (name))
06124 name = DECL_NAME (name);
06125 if (TREE_CODE (name) != IDENTIFIER_NODE)
06126 abort ();
06127
06128 if (!uses_template_parms (context)
06129 || currently_open_class (context))
06130 {
06131 tree tmpl = NULL_TREE;
06132
06133 if (IS_AGGR_TYPE (context))
06134 tmpl = lookup_field (context, name, 0, 0);
06135
06136 if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
06137 {
06138 if (complain & tf_error)
06139 error ("no class template named `%#T' in `%#T'", name, context);
06140 return error_mark_node;
06141 }
06142
06143 if (complain & tf_error)
06144 {
06145 if (complain & tf_parsing)
06146 type_access_control (context, tmpl);
06147 else
06148 enforce_access (context, tmpl);
06149 }
06150
06151 return tmpl;
06152 }
06153
06154
06155 t = make_aggr_type (UNBOUND_CLASS_TEMPLATE);
06156 TYPE_CONTEXT (t) = FROB_CONTEXT (context);
06157 TREE_TYPE (t) = NULL_TREE;
06158
06159
06160 d = build_decl (TEMPLATE_DECL, name, t);
06161 TYPE_NAME (TREE_TYPE (d)) = d;
06162 TYPE_STUB_DECL (TREE_TYPE (d)) = d;
06163 DECL_CONTEXT (d) = FROB_CONTEXT (context);
06164 DECL_ARTIFICIAL (d) = 1;
06165
06166 return t;
06167 }
06168
06169
06170
06171 static tree
06172 select_decl (cxx_binding *binding, int flags)
06173 {
06174 tree val;
06175
06176 timevar_push (TV_NAME_LOOKUP);
06177
06178 val = BINDING_VALUE (binding);
06179
06180 if (LOOKUP_NAMESPACES_ONLY (flags))
06181 {
06182
06183 if (val && TREE_CODE (val) == NAMESPACE_DECL)
06184 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
06185 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
06186 }
06187
06188
06189
06190 if (BINDING_TYPE (binding)
06191 && (!val || ((flags & LOOKUP_PREFER_TYPES)
06192 && TREE_CODE (val) != TYPE_DECL)))
06193 val = TYPE_STUB_DECL (BINDING_TYPE (binding));
06194
06195 else if (val && LOOKUP_TYPES_ONLY (flags) && TREE_CODE (val) != TYPE_DECL
06196 && (TREE_CODE (val) != TEMPLATE_DECL
06197 || !DECL_CLASS_TEMPLATE_P (val)))
06198 val = NULL_TREE;
06199
06200 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
06201 }
06202
06203
06204
06205
06206
06207 tree
06208 unqualified_namespace_lookup (name, flags, spacesp)
06209 tree name;
06210 int flags;
06211 tree *spacesp;
06212 {
06213 tree initial = current_decl_namespace ();
06214 tree scope = initial;
06215 tree siter;
06216 struct cp_binding_level *level;
06217 tree val = NULL_TREE;
06218 cxx_binding binding;
06219
06220 timevar_push (TV_NAME_LOOKUP);
06221 cxx_binding_clear (&binding);
06222 if (spacesp)
06223 *spacesp = NULL_TREE;
06224
06225 for (; !val; scope = CP_DECL_CONTEXT (scope))
06226 {
06227 cxx_binding *b;
06228 if (spacesp)
06229 *spacesp = tree_cons (scope, NULL_TREE, *spacesp);
06230 b = cxx_scope_find_binding_for_name (scope, name);
06231
06232
06233 if (b && BINDING_VALUE (b) && DECL_P (BINDING_VALUE (b))
06234 && DECL_LANG_SPECIFIC (BINDING_VALUE (b))
06235 && DECL_ANTICIPATED (BINDING_VALUE (b)))
06236 ;
06237 else if (b)
06238 {
06239
06240 binding.value = BINDING_VALUE (b);
06241 binding.type = BINDING_TYPE (b);
06242 }
06243
06244
06245 for (level = current_binding_level;
06246 !level->namespace_p;
06247 level = level->level_chain)
06248 if (!lookup_using_namespace (name, &binding, level->using_directives,
06249 scope, flags, spacesp))
06250
06251 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
06252
06253
06254
06255 siter = initial;
06256 while (1)
06257 {
06258 if (!lookup_using_namespace (name, &binding,
06259 DECL_NAMESPACE_USING (siter),
06260 scope, flags, spacesp))
06261
06262 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
06263 if (siter == scope) break;
06264 siter = CP_DECL_CONTEXT (siter);
06265 }
06266
06267 val = select_decl (&binding, flags);
06268 if (scope == global_namespace)
06269 break;
06270 }
06271 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
06272 }
06273
06274
06275
06276 static int
06277 lookup_flags (prefer_type, namespaces_only)
06278 int prefer_type, namespaces_only;
06279 {
06280 if (namespaces_only)
06281 return LOOKUP_PREFER_NAMESPACES;
06282 if (prefer_type > 1)
06283 return LOOKUP_PREFER_TYPES;
06284 if (prefer_type > 0)
06285 return LOOKUP_PREFER_BOTH;
06286 return 0;
06287 }
06288
06289
06290
06291
06292 static tree
06293 qualify_lookup (val, flags)
06294 tree val;
06295 int flags;
06296 {
06297 if (val == NULL_TREE)
06298 return val;
06299 if ((flags & LOOKUP_PREFER_NAMESPACES) && TREE_CODE (val) == NAMESPACE_DECL)
06300 return val;
06301 if ((flags & LOOKUP_PREFER_TYPES)
06302 && (TREE_CODE (val) == TYPE_DECL
06303 || ((flags & LOOKUP_TEMPLATES_EXPECTED)
06304 && DECL_CLASS_TEMPLATE_P (val))))
06305 return val;
06306 if (flags & (LOOKUP_PREFER_NAMESPACES | LOOKUP_PREFER_TYPES))
06307 return NULL_TREE;
06308 return val;
06309 }
06310
06311
06312
06313
06314 static void
06315 warn_about_implicit_typename_lookup (typename, binding)
06316 tree typename;
06317 tree binding;
06318 {
06319 tree subtype = TREE_TYPE (TREE_TYPE (typename));
06320 tree name = DECL_NAME (typename);
06321
06322 if (! (TREE_CODE (binding) == TEMPLATE_DECL
06323 && CLASS_TYPE_P (subtype)
06324 && CLASSTYPE_TEMPLATE_INFO (subtype)
06325 && CLASSTYPE_TI_TEMPLATE (subtype) == binding)
06326 && ! (TREE_CODE (binding) == TYPE_DECL
06327 && same_type_p (TREE_TYPE (binding), subtype)))
06328 {
06329 warning ("lookup of `%D' finds `%#D'",
06330 name, binding);
06331 warning (" instead of `%D' from dependent base class",
06332 typename);
06333 warning (" (use `typename %T::%D' if that's what you meant)",
06334 constructor_name (current_class_type), name);
06335 }
06336 }
06337
06338
06339
06340
06341
06342
06343
06344
06345 tree
06346 check_for_out_of_scope_variable (tree decl)
06347 {
06348 tree shadowed;
06349
06350
06351 if (!(TREE_CODE (decl) == VAR_DECL && DECL_DEAD_FOR_LOCAL (decl)))
06352 return decl;
06353
06354 shadowed = DECL_SHADOWED_FOR_VAR (decl);
06355 while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
06356 && DECL_DEAD_FOR_LOCAL (shadowed))
06357 shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
06358 if (!shadowed)
06359 shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (decl));
06360 if (shadowed)
06361 {
06362 if (!DECL_ERROR_REPORTED (decl))
06363 {
06364 warning ("name lookup of `%D' changed",
06365 DECL_NAME (decl));
06366 cp_warning_at (" matches this `%D' under ISO standard rules",
06367 shadowed);
06368 cp_warning_at (" matches this `%D' under old rules", decl);
06369 DECL_ERROR_REPORTED (decl) = 1;
06370 }
06371 return shadowed;
06372 }
06373
06374
06375
06376 if (DECL_ERROR_REPORTED (decl))
06377 return decl;
06378
06379 DECL_ERROR_REPORTED (decl) = 1;
06380 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
06381 {
06382 error ("name lookup of `%D' changed for new ISO `for' scoping",
06383 DECL_NAME (decl));
06384 cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", decl);
06385 return error_mark_node;
06386 }
06387 else
06388 {
06389 pedwarn ("name lookup of `%D' changed for new ISO `for' scoping",
06390 DECL_NAME (decl));
06391 cp_pedwarn_at (" using obsolete binding at `%D'", decl);
06392 }
06393
06394 return decl;
06395 }
06396
06397
06398
06399
06400
06401
06402
06403
06404
06405
06406
06407
06408
06409
06410
06411 static tree
06412 lookup_name_real (name, prefer_type, nonclass, namespaces_only)
06413 tree name;
06414 int prefer_type, nonclass, namespaces_only;
06415 {
06416 tree t;
06417 tree val = NULL_TREE;
06418 int yylex = 0;
06419 tree from_obj = NULL_TREE;
06420 int flags;
06421 int val_is_implicit_typename = 0;
06422 cxx_binding *iter;
06423
06424 timevar_push (TV_NAME_LOOKUP);
06425
06426
06427 if (only_namespace_names)
06428 namespaces_only = 1;
06429
06430 if (prefer_type == -2)
06431 {
06432 extern int looking_for_typename;
06433 tree type = NULL_TREE;
06434
06435 yylex = 1;
06436 prefer_type = looking_for_typename;
06437
06438 flags = lookup_flags (prefer_type, namespaces_only);
06439
06440 if (looking_for_template)
06441 flags |= LOOKUP_TEMPLATES_EXPECTED;
06442
06443 if (got_scope)
06444 type = got_scope;
06445 else if (got_object != error_mark_node)
06446 type = got_object;
06447
06448 if (type)
06449 {
06450 if (type == error_mark_node)
06451 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
06452 if (IMPLICIT_TYPENAME_P (type))
06453 type = TREE_TYPE (type);
06454
06455 if (TYPE_P (type))
06456 type = complete_type (type);
06457
06458 if (TREE_CODE (type) == VOID_TYPE)
06459 type = global_namespace;
06460 if (TREE_CODE (type) == NAMESPACE_DECL)
06461 {
06462 cxx_binding b;
06463 cxx_binding_clear (&b);
06464 flags |= LOOKUP_COMPLAIN;
06465 if (!qualified_lookup_using_namespace (name, type, &b, flags))
06466 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
06467 val = select_decl (&b, flags);
06468 }
06469 else if (! IS_AGGR_TYPE (type)
06470 || TREE_CODE (type) == TEMPLATE_TYPE_PARM
06471 || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
06472 || TREE_CODE (type) == TYPENAME_TYPE)
06473
06474 val = NULL_TREE;
06475 else if (type == current_class_type)
06476 val = IDENTIFIER_CLASS_VALUE (name);
06477 else
06478 {
06479 val = lookup_member (type, name, 0, prefer_type);
06480 if (!uses_template_parms (type))
06481 type_access_control (type, val);
06482
06483
06484
06485 if (got_scope && got_scope != type
06486 && val && TREE_CODE (val) == TYPE_DECL
06487 && TREE_CODE (TREE_TYPE (val)) == TYPENAME_TYPE)
06488 {
06489 val = TREE_TYPE (val);
06490 val = build_typename_type (got_scope, name,
06491 TYPENAME_TYPE_FULLNAME (val),
06492 TREE_TYPE (val));
06493 val = TYPE_STUB_DECL (val);
06494 }
06495 }
06496 }
06497 else
06498 val = NULL_TREE;
06499
06500 if (got_scope)
06501 goto done;
06502 else if (got_object && val)
06503 {
06504 from_obj = val;
06505 val = NULL_TREE;
06506 }
06507 }
06508 else
06509 {
06510 flags = lookup_flags (prefer_type, namespaces_only);
06511
06512 flags |= LOOKUP_COMPLAIN;
06513 }
06514
06515
06516
06517
06518 if (IDENTIFIER_TYPENAME_P (name))
06519 {
06520 struct cp_binding_level *level;
06521
06522 for (level = current_binding_level;
06523 level && !level->namespace_p;
06524 level = level->level_chain)
06525 {
06526 tree class_type;
06527 tree operators;
06528
06529
06530
06531 if (level->parm_flag != 2)
06532 continue;
06533
06534
06535 class_type = level->this_class;
06536 operators = lookup_fnfields (class_type, name, 0);
06537 if (operators)
06538 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, operators);
06539 }
06540
06541 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
06542 }
06543
06544
06545
06546 if (current_class_type == NULL_TREE)
06547 nonclass = 1;
06548
06549 for (iter = IDENTIFIER_BINDING (name); iter; iter = iter->previous)
06550 {
06551 tree binding;
06552
06553 if (!LOCAL_BINDING_P (iter) && nonclass)
06554
06555 continue;
06556
06557
06558 if (qualify_lookup (BINDING_VALUE (iter), flags))
06559 binding = BINDING_VALUE (iter);
06560 else if ((flags & LOOKUP_PREFER_TYPES)
06561 && qualify_lookup (BINDING_TYPE (iter), flags))
06562 binding = BINDING_TYPE (iter);
06563 else
06564 binding = NULL_TREE;
06565
06566
06567 if (binding && ! yylex
06568 && BINDING_LEVEL (iter) && BINDING_LEVEL (iter)->parm_flag == 2)
06569 type_access_control (BINDING_LEVEL (iter)->this_class, binding);
06570
06571 if (binding
06572 && (!val || !IMPLICIT_TYPENAME_TYPE_DECL_P (binding)))
06573 {
06574 if (val_is_implicit_typename && !yylex)
06575 warn_about_implicit_typename_lookup (val, binding);
06576 val = binding;
06577 val_is_implicit_typename
06578 = IMPLICIT_TYPENAME_TYPE_DECL_P (val);
06579 if (!val_is_implicit_typename)
06580 break;
06581 }
06582 }
06583
06584
06585 if (!val && !nonclass && current_class_type)
06586 val = qualify_lookup (lookup_nested_field (name, !yylex), flags);
06587
06588
06589 if (!val || val_is_implicit_typename)
06590 {
06591 t = unqualified_namespace_lookup (name, flags, 0);
06592 if (t)
06593 {
06594 if (val_is_implicit_typename && !yylex)
06595 warn_about_implicit_typename_lookup (val, t);
06596 val = t;
06597 }
06598 }
06599
06600 done:
06601 if (val)
06602 {
06603
06604 if (from_obj && from_obj != val)
06605 {
06606 if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL
06607 && TREE_CODE (val) == TYPE_DECL
06608 && ! same_type_p (TREE_TYPE (from_obj), TREE_TYPE (val)))
06609 pedwarn ("\
06610 lookup of `%D' in the scope of `%#T' (`%#D') \
06611 does not match lookup in the current scope (`%#D')",
06612 name, got_object, from_obj, val);
06613
06614
06615
06616
06617 if (! uses_template_parms (got_object))
06618 val = from_obj;
06619 }
06620
06621
06622 if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val))
06623 val = OVL_FUNCTION (val);
06624 }
06625 else if (from_obj)
06626 val = from_obj;
06627
06628 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
06629 }
06630
06631 tree
06632 lookup_name_nonclass (name)
06633 tree name;
06634 {
06635 return lookup_name_real (name, 0, 1, 0);
06636 }
06637
06638 tree
06639 lookup_function_nonclass (name, args)
06640 tree name;
06641 tree args;
06642 {
06643 return lookup_arg_dependent (name, lookup_name_nonclass (name), args);
06644 }
06645
06646 tree
06647 lookup_name_namespace_only (name)
06648 tree name;
06649 {
06650
06651 return lookup_name_real (name, 1, 1, 1);
06652 }
06653
06654 tree
06655 lookup_name (name, prefer_type)
06656 tree name;
06657 int prefer_type;
06658 {
06659 return lookup_name_real (name, prefer_type, 0, 0);
06660 }
06661
06662
06663
06664
06665 tree
06666 lookup_name_current_level (name)
06667 tree name;
06668 {
06669 struct cp_binding_level *b;
06670 tree t = NULL_TREE;
06671
06672 timevar_push (TV_NAME_LOOKUP);
06673
06674 b = current_binding_level;
06675 while (b->parm_flag == 2)
06676 b = b->level_chain;
06677
06678 if (b->namespace_p)
06679 {
06680 t = IDENTIFIER_NAMESPACE_VALUE (name);
06681
06682
06683 if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
06684 t = TREE_VALUE (t);
06685 }
06686 else if (IDENTIFIER_BINDING (name)
06687 && LOCAL_BINDING_P (IDENTIFIER_BINDING (name)))
06688 {
06689 while (1)
06690 {
06691 if (BINDING_LEVEL (IDENTIFIER_BINDING (name)) == b)
06692 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, IDENTIFIER_VALUE (name));
06693
06694 if (b->keep == 2)
06695 b = b->level_chain;
06696 else
06697 break;
06698 }
06699 }
06700
06701 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
06702 }
06703
06704
06705
06706 tree
06707 lookup_type_current_level (name)
06708 tree name;
06709 {
06710 register tree t = NULL_TREE;
06711
06712 timevar_push (TV_NAME_LOOKUP);
06713
06714 my_friendly_assert (! current_binding_level->namespace_p, 980716);
06715
06716 if (REAL_IDENTIFIER_TYPE_VALUE (name) != NULL_TREE
06717 && REAL_IDENTIFIER_TYPE_VALUE (name) != global_type_node)
06718 {
06719 struct cp_binding_level *b = current_binding_level;
06720 while (1)
06721 {
06722 if (purpose_member (name, b->type_shadowed))
06723 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP,
06724 REAL_IDENTIFIER_TYPE_VALUE (name));
06725 if (b->keep == 2)
06726 b = b->level_chain;
06727 else
06728 break;
06729 }
06730 }
06731
06732 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
06733 }
06734
06735 void
06736 begin_only_namespace_names ()
06737 {
06738 only_namespace_names = 1;
06739 }
06740
06741 void
06742 end_only_namespace_names ()
06743 {
06744 only_namespace_names = 0;
06745 }
06746
06747
06748
06749
06750
06751
06752 void
06753 record_builtin_type (rid_index, name, type)
06754 enum rid rid_index;
06755 const char *name;
06756 tree type;
06757 {
06758 tree rname = NULL_TREE, tname = NULL_TREE;
06759 tree tdecl = NULL_TREE;
06760
06761 if ((int) rid_index < (int) RID_MAX)
06762 rname = ridpointers[(int) rid_index];
06763 if (name)
06764 tname = get_identifier (name);
06765
06766 TYPE_BUILT_IN (type) = 1;
06767
06768 if (tname)
06769 {
06770 tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
06771 set_identifier_type_value (tname, NULL_TREE);
06772 if ((int) rid_index < (int) RID_MAX)
06773
06774 SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
06775 }
06776 if (rname != NULL_TREE)
06777 {
06778 if (tname != NULL_TREE)
06779 {
06780 set_identifier_type_value (rname, NULL_TREE);
06781 SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl);
06782 }
06783 else
06784 {
06785 tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
06786 set_identifier_type_value (rname, NULL_TREE);
06787 }
06788 }
06789 }
06790
06791
06792
06793
06794
06795
06796 static tree
06797 record_builtin_java_type (name, size)
06798 const char *name;
06799 int size;
06800 {
06801 tree type, decl;
06802 if (size > 0)
06803 type = make_signed_type (size);
06804 else if (size > -32)
06805 {
06806 type = make_unsigned_type (-size);
06807
06808 }
06809 else
06810 {
06811 type = make_node (REAL_TYPE);
06812 TYPE_PRECISION (type) = - size;
06813 layout_type (type);
06814 }
06815 record_builtin_type (RID_MAX, name, type);
06816 decl = TYPE_NAME (type);
06817
06818
06819
06820
06821 DECL_IGNORED_P (decl) = 1;
06822
06823 TYPE_FOR_JAVA (type) = 1;
06824 return type;
06825 }
06826
06827
06828
06829 static void
06830 record_unknown_type (type, name)
06831 tree type;
06832 const char *name;
06833 {
06834 tree decl = pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
06835
06836 DECL_IGNORED_P (decl) = 1;
06837 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
06838 TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
06839 TYPE_ALIGN (type) = 1;
06840 TYPE_USER_ALIGN (type) = 0;
06841 TYPE_MODE (type) = TYPE_MODE (void_type_node);
06842 }
06843
06844
06845
06846
06847 typedef struct predefined_identifier
06848 {
06849
06850 const char *const name;
06851
06852 tree *const node;
06853
06854 const int ctor_or_dtor_p;
06855 } predefined_identifier;
06856
06857
06858
06859 static void
06860 initialize_predefined_identifiers ()
06861 {
06862 const predefined_identifier *pid;
06863
06864
06865 static const predefined_identifier predefined_identifiers[] = {
06866 { "C++", &lang_name_cplusplus, 0 },
06867 { "C", &lang_name_c, 0 },
06868 { "Java", &lang_name_java, 0 },
06869 { CTOR_NAME, &ctor_identifier, 1 },
06870 { "__base_ctor", &base_ctor_identifier, 1 },
06871 { "__comp_ctor", &complete_ctor_identifier, 1 },
06872 { DTOR_NAME, &dtor_identifier, 1 },
06873 { "__comp_dtor", &complete_dtor_identifier, 1 },
06874 { "__base_dtor", &base_dtor_identifier, 1 },
06875 { "__deleting_dtor", &deleting_dtor_identifier, 1 },
06876 { IN_CHARGE_NAME, &in_charge_identifier, 0 },
06877 { "nelts", &nelts_identifier, 0 },
06878 { THIS_NAME, &this_identifier, 0 },
06879 { VTABLE_DELTA_NAME, &delta_identifier, 0 },
06880 { VTABLE_PFN_NAME, &pfn_identifier, 0 },
06881 { "_vptr", &vptr_identifier, 0 },
06882 { "__vtt_parm", &vtt_parm_identifier, 0 },
06883 { "std", &std_identifier, 0 },
06884 { NULL, NULL, 0 }
06885 };
06886
06887 for (pid = predefined_identifiers; pid->name; ++pid)
06888 {
06889 *pid->node = get_identifier (pid->name);
06890 if (pid->ctor_or_dtor_p)
06891 IDENTIFIER_CTOR_OR_DTOR_P (*pid->node) = 1;
06892 }
06893 }
06894
06895
06896
06897
06898
06899
06900 void
06901 cxx_init_decl_processing ()
06902 {
06903 tree void_ftype;
06904 tree void_ftype_ptr;
06905
06906
06907 initialize_predefined_identifiers ();
06908
06909
06910 lang_missing_noreturn_ok_p = &cp_missing_noreturn_ok_p;
06911
06912
06913 push_to_top_level ();
06914
06915
06916 my_friendly_assert (global_namespace == NULL_TREE, 375);
06917 push_namespace (get_identifier ("::"));
06918 global_namespace = current_namespace;
06919 current_lang_name = NULL_TREE;
06920
06921
06922 if (!flag_permissive)
06923 flag_pedantic_errors = 1;
06924 if (!flag_no_inline)
06925 {
06926 flag_inline_trees = 1;
06927 flag_no_inline = 1;
06928 }
06929 if (flag_inline_functions)
06930 {
06931 flag_inline_trees = 2;
06932 flag_inline_functions = 0;
06933 }
06934
06935
06936
06937 if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
06938 && force_align_functions_log < 1)
06939 force_align_functions_log = 1;
06940
06941
06942 current_lang_name = lang_name_c;
06943
06944 current_function_decl = NULL_TREE;
06945 current_binding_level = NULL_BINDING_LEVEL;
06946 free_binding_level = NULL_BINDING_LEVEL;
06947
06948 build_common_tree_nodes (flag_signed_char);
06949
06950 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
06951 TREE_TYPE (error_mark_list) = error_mark_node;
06952
06953
06954 pushlevel (0);
06955 current_binding_level->type_decls = binding_table_new (GLOBAL_SCOPE_HT_SIZE);
06956
06957 NAMESPACE_LEVEL (global_namespace) = current_binding_level;
06958 declare_namespace_level ();
06959
06960 VARRAY_TREE_INIT (current_binding_level->static_decls,
06961 200,
06962 "Static declarations");
06963
06964
06965 push_namespace (std_identifier);
06966 std_node = current_namespace;
06967 pop_namespace ();
06968
06969 c_common_nodes_and_builtins ();
06970
06971 java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
06972 java_short_type_node = record_builtin_java_type ("__java_short", 16);
06973 java_int_type_node = record_builtin_java_type ("__java_int", 32);
06974 java_long_type_node = record_builtin_java_type ("__java_long", 64);
06975 java_float_type_node = record_builtin_java_type ("__java_float", -32);
06976 java_double_type_node = record_builtin_java_type ("__java_double", -64);
06977 java_char_type_node = record_builtin_java_type ("__java_char", -16);
06978 java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
06979
06980 integer_two_node = build_int_2 (2, 0);
06981 TREE_TYPE (integer_two_node) = integer_type_node;
06982 integer_three_node = build_int_2 (3, 0);
06983 TREE_TYPE (integer_three_node) = integer_type_node;
06984
06985 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
06986 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
06987 TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0);
06988 TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node;
06989 TYPE_PRECISION (boolean_type_node) = 1;
06990 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
06991 boolean_false_node = build_int_2 (0, 0);
06992 TREE_TYPE (boolean_false_node) = boolean_type_node;
06993 boolean_true_node = build_int_2 (1, 0);
06994 TREE_TYPE (boolean_true_node) = boolean_type_node;
06995
06996 empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
06997
06998 #if 0
06999 record_builtin_type (RID_MAX, NULL, string_type_node);
07000 #endif
07001
07002 delta_type_node = ptrdiff_type_node;
07003 vtable_index_type = ptrdiff_type_node;
07004
07005 vtt_parm_type = build_pointer_type (const_ptr_type_node);
07006 void_ftype = build_function_type (void_type_node, void_list_node);
07007 void_ftype_ptr = build_function_type (void_type_node,
07008 tree_cons (NULL_TREE,
07009 ptr_type_node,
07010 void_list_node));
07011 void_ftype_ptr
07012 = build_exception_variant (void_ftype_ptr, empty_except_spec);
07013
07014
07015
07016 unknown_type_node = make_node (UNKNOWN_TYPE);
07017 record_unknown_type (unknown_type_node, "unknown type");
07018
07019
07020 TREE_TYPE (unknown_type_node) = unknown_type_node;
07021
07022
07023
07024 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
07025 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
07026
07027 {
07028
07029
07030 tree vfunc_type = make_node (FUNCTION_TYPE);
07031 TREE_TYPE (vfunc_type) = integer_type_node;
07032 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
07033 layout_type (vfunc_type);
07034
07035 vtable_entry_type = build_pointer_type (vfunc_type);
07036 }
07037 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
07038
07039 vtbl_type_node
07040 = build_cplus_array_type (vtable_entry_type, NULL_TREE);
07041 layout_type (vtbl_type_node);
07042 vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
07043 record_builtin_type (RID_MAX, NULL, vtbl_type_node);
07044 vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
07045 layout_type (vtbl_ptr_type_node);
07046 record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
07047
07048 push_namespace (get_identifier ("__cxxabiv1"));
07049 abi_node = current_namespace;
07050 pop_namespace ();
07051
07052 global_type_node = make_node (LANG_TYPE);
07053 record_unknown_type (global_type_node, "global type");
07054
07055
07056 current_lang_name = lang_name_cplusplus;
07057
07058 {
07059 tree bad_alloc_type_node, newtype, deltype;
07060 tree ptr_ftype_sizetype;
07061
07062 push_namespace (std_identifier);
07063 bad_alloc_type_node
07064 = xref_tag (class_type, get_identifier ("bad_alloc"),
07065 NULL_TREE, 1);
07066 pop_namespace ();
07067 ptr_ftype_sizetype
07068 = build_function_type (ptr_type_node,
07069 tree_cons (NULL_TREE,
07070 size_type_node,
07071 void_list_node));
07072 newtype = build_exception_variant
07073 (ptr_ftype_sizetype, add_exception_specifier
07074 (NULL_TREE, bad_alloc_type_node, -1));
07075 deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
07076 push_cp_library_fn (NEW_EXPR, newtype);
07077 push_cp_library_fn (VEC_NEW_EXPR, newtype);
07078 global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype);
07079 push_cp_library_fn (VEC_DELETE_EXPR, deltype);
07080 }
07081
07082 abort_fndecl
07083 = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype);
07084
07085
07086 init_class_processing ();
07087 init_search_processing ();
07088 init_rtti_processing ();
07089
07090 if (flag_exceptions)
07091 init_exception_processing ();
07092
07093 if (! supports_one_only ())
07094 flag_weak = 0;
07095
07096 make_fname_decl = cp_make_fname_decl;
07097 start_fname_decls ();
07098
07099
07100 using_eh_for_cleanups ();
07101
07102
07103
07104 if (flag_writable_strings)
07105 flag_const_strings = 0;
07106 }
07107
07108
07109
07110
07111
07112 tree
07113 cp_fname_init (name)
07114 const char *name;
07115 {
07116 tree domain = NULL_TREE;
07117 tree type;
07118 tree init = NULL_TREE;
07119 size_t length = 0;
07120
07121 if (name)
07122 {
07123 length = strlen (name);
07124 domain = build_index_type (size_int (length));
07125 init = build_string (length + 1, name);
07126 }
07127
07128 type = build_qualified_type (char_type_node, TYPE_QUAL_CONST);
07129 type = build_cplus_array_type (type, domain);
07130
07131 if (init)
07132 TREE_TYPE (init) = type;
07133 else
07134
07135
07136 init = build (ERROR_MARK, type);
07137
07138 return init;
07139 }
07140
07141
07142
07143
07144
07145
07146
07147 static tree
07148 cp_make_fname_decl (id, type_dep)
07149 tree id;
07150 int type_dep;
07151 {
07152 const char *const name = (type_dep && processing_template_decl
07153 ? NULL : fname_as_string (type_dep));
07154 tree init = cp_fname_init (name);
07155 tree decl = build_decl (VAR_DECL, id, TREE_TYPE (init));
07156
07157
07158 DECL_CONTEXT (decl) = current_function_decl;
07159 DECL_PRETTY_FUNCTION_P (decl) = type_dep;
07160
07161 TREE_STATIC (decl) = 1;
07162 TREE_READONLY (decl) = 1;
07163 DECL_ARTIFICIAL (decl) = 1;
07164 DECL_INITIAL (decl) = init;
07165
07166 TREE_USED (decl) = 1;
07167
07168 cp_finish_decl (decl, init, NULL_TREE, LOOKUP_ONLYCONVERTING);
07169
07170 if (!current_function_decl)
07171 rest_of_decl_compilation (decl, 0, 1, 0);
07172
07173 return decl;
07174 }
07175
07176
07177
07178
07179
07180
07181
07182
07183
07184
07185
07186
07187
07188 static tree
07189 builtin_function_1 (name, type, context, code, class, libname, attrs)
07190 const char *name;
07191 tree type;
07192 tree context;
07193 int code;
07194 enum built_in_class class;
07195 const char *libname;
07196 tree attrs;
07197 {
07198 tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type);
07199 DECL_BUILT_IN_CLASS (decl) = class;
07200 DECL_FUNCTION_CODE (decl) = code;
07201 DECL_CONTEXT (decl) = context;
07202
07203 pushdecl (decl);
07204
07205
07206
07207
07208 if (libname)
07209 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
07210 make_decl_rtl (decl, NULL);
07211
07212
07213
07214 if (name[0] != '_' || name[1] != '_')
07215 DECL_ANTICIPATED (decl) = 1;
07216
07217
07218 if (attrs)
07219 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
07220 else
07221 decl_attributes (&decl, NULL_TREE, 0);
07222
07223 return decl;
07224 }
07225
07226
07227
07228
07229
07230
07231
07232
07233
07234
07235
07236
07237
07238
07239
07240
07241
07242 tree
07243 builtin_function (name, type, code, class, libname, attrs)
07244 const char *name;
07245 tree type;
07246 int code;
07247 enum built_in_class class;
07248 const char *libname;
07249 tree attrs;
07250 {
07251
07252
07253 if (name[0] != '_')
07254 {
07255 push_namespace (std_identifier);
07256 builtin_function_1 (name, type, std_node, code, class, libname, attrs);
07257 pop_namespace ();
07258 }
07259
07260 return builtin_function_1 (name, type, NULL_TREE, code,
07261 class, libname, attrs);
07262 }
07263
07264
07265
07266
07267 static tree
07268 build_library_fn_1 (name, operator_code, type)
07269 tree name;
07270 enum tree_code operator_code;
07271 tree type;
07272 {
07273 tree fn = build_lang_decl (FUNCTION_DECL, name, type);
07274 DECL_EXTERNAL (fn) = 1;
07275 TREE_PUBLIC (fn) = 1;
07276 DECL_ARTIFICIAL (fn) = 1;
07277 TREE_NOTHROW (fn) = 1;
07278 SET_OVERLOADED_OPERATOR_CODE (fn, operator_code);
07279 SET_DECL_LANGUAGE (fn, lang_c);
07280 return fn;
07281 }
07282
07283
07284
07285
07286
07287 tree
07288 build_library_fn (name, type)
07289 tree name;
07290 tree type;
07291 {
07292 return build_library_fn_1 (name, ERROR_MARK, type);
07293 }
07294
07295
07296
07297 static tree
07298 build_cp_library_fn (name, operator_code, type)
07299 tree name;
07300 enum tree_code operator_code;
07301 tree type;
07302 {
07303 tree fn = build_library_fn_1 (name, operator_code, type);
07304 TREE_NOTHROW (fn) = TYPE_NOTHROW_P (type);
07305 DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
07306 SET_DECL_LANGUAGE (fn, lang_cplusplus);
07307 set_mangled_name_for_decl (fn);
07308 return fn;
07309 }
07310
07311
07312
07313
07314 tree
07315 build_library_fn_ptr (name, type)
07316 const char *name;
07317 tree type;
07318 {
07319 return build_library_fn (get_identifier (name), type);
07320 }
07321
07322
07323
07324
07325 tree
07326 build_cp_library_fn_ptr (name, type)
07327 const char *name;
07328 tree type;
07329 {
07330 return build_cp_library_fn (get_identifier (name), ERROR_MARK, type);
07331 }
07332
07333
07334
07335
07336 tree
07337 push_library_fn (name, type)
07338 tree name, type;
07339 {
07340 tree fn = build_library_fn (name, type);
07341 pushdecl_top_level (fn);
07342 return fn;
07343 }
07344
07345
07346
07347
07348 static tree
07349 push_cp_library_fn (operator_code, type)
07350 enum tree_code operator_code;
07351 tree type;
07352 {
07353 tree fn = build_cp_library_fn (ansi_opname (operator_code),
07354 operator_code,
07355 type);
07356 pushdecl (fn);
07357 return fn;
07358 }
07359
07360
07361
07362
07363 tree
07364 push_void_library_fn (name, parmtypes)
07365 tree name, parmtypes;
07366 {
07367 tree type = build_function_type (void_type_node, parmtypes);
07368 return push_library_fn (name, type);
07369 }
07370
07371
07372
07373
07374 tree
07375 push_throw_library_fn (name, type)
07376 tree name, type;
07377 {
07378 tree fn = push_library_fn (name, type);
07379 TREE_THIS_VOLATILE (fn) = 1;
07380 TREE_NOTHROW (fn) = 0;
07381 return fn;
07382 }
07383
07384
07385
07386
07387 void
07388 cxx_insert_default_attributes (decl)
07389 tree decl;
07390 {
07391 if (!DECL_EXTERN_C_FUNCTION_P (decl))
07392 return;
07393 if (!TREE_PUBLIC (decl))
07394 return;
07395 c_common_insert_default_attributes (decl);
07396 }
07397
07398
07399
07400
07401
07402
07403
07404
07405
07406
07407
07408 void
07409 fixup_anonymous_aggr (t)
07410 tree t;
07411 {
07412 tree *q;
07413
07414
07415 TYPE_HAS_CONSTRUCTOR (t) = 0;
07416 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
07417 TYPE_HAS_INIT_REF (t) = 0;
07418 TYPE_HAS_CONST_INIT_REF (t) = 0;
07419 TYPE_HAS_ASSIGN_REF (t) = 0;
07420 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
07421
07422
07423
07424 q = &TYPE_METHODS (t);
07425 while (*q)
07426 {
07427 if (DECL_ARTIFICIAL (*q))
07428 *q = TREE_CHAIN (*q);
07429 else
07430 q = &TREE_CHAIN (*q);
07431 }
07432
07433
07434 if (TYPE_METHODS (t))
07435 cp_error_at ("an anonymous union cannot have function members", t);
07436
07437
07438
07439
07440
07441 if (TREE_CODE (t) != UNION_TYPE)
07442 {
07443 tree field, type;
07444
07445 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
07446 if (TREE_CODE (field) == FIELD_DECL)
07447 {
07448 type = TREE_TYPE (field);
07449 if (CLASS_TYPE_P (type))
07450 {
07451 if (TYPE_NEEDS_CONSTRUCTING (type))
07452 cp_error_at ("member %#D' with constructor not allowed in anonymous aggregate",
07453 field);
07454 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
07455 cp_error_at ("member %#D' with destructor not allowed in anonymous aggregate",
07456 field);
07457 if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
07458 cp_error_at ("member %#D' with copy assignment operator not allowed in anonymous aggregate",
07459 field);
07460 }
07461 }
07462 }
07463 }
07464
07465
07466
07467
07468
07469
07470 tree
07471 check_tag_decl (declspecs)
07472 tree declspecs;
07473 {
07474 int found_type = 0;
07475 int saw_friend = 0;
07476 int saw_typedef = 0;
07477 tree ob_modifier = NULL_TREE;
07478 register tree link;
07479 register tree t = NULL_TREE;
07480
07481 for (link = declspecs; link; link = TREE_CHAIN (link))
07482 {
07483 register tree value = TREE_VALUE (link);
07484
07485 if (TYPE_P (value)
07486 || TREE_CODE (value) == TYPE_DECL
07487 || (TREE_CODE (value) == IDENTIFIER_NODE
07488 && IDENTIFIER_GLOBAL_VALUE (value)
07489 && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (value)) == TYPE_DECL))
07490 {
07491 ++found_type;
07492
07493 if (found_type == 2 && TREE_CODE (value) == IDENTIFIER_NODE)
07494 {
07495 if (! in_system_header)
07496 pedwarn ("redeclaration of C++ built-in type `%T'", value);
07497 return NULL_TREE;
07498 }
07499
07500 if (TYPE_P (value)
07501 && ((TREE_CODE (value) != TYPENAME_TYPE && IS_AGGR_TYPE (value))
07502 || TREE_CODE (value) == ENUMERAL_TYPE))
07503 {
07504 my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261);
07505 t = value;
07506 }
07507 }
07508 else if (value == ridpointers[(int) RID_TYPEDEF])
07509 saw_typedef = 1;
07510 else if (value == ridpointers[(int) RID_FRIEND])
07511 {
07512 if (current_class_type == NULL_TREE
07513 || current_scope () != current_class_type)
07514 ob_modifier = value;
07515 else
07516 saw_friend = 1;
07517 }
07518 else if (value == ridpointers[(int) RID_STATIC]
07519 || value == ridpointers[(int) RID_EXTERN]
07520 || value == ridpointers[(int) RID_AUTO]
07521 || value == ridpointers[(int) RID_REGISTER]
07522 || value == ridpointers[(int) RID_INLINE]
07523 || value == ridpointers[(int) RID_VIRTUAL]
07524 || value == ridpointers[(int) RID_CONST]
07525 || value == ridpointers[(int) RID_VOLATILE]
07526 || value == ridpointers[(int) RID_EXPLICIT]
07527 || value == ridpointers[(int) RID_THREAD])
07528 ob_modifier = value;
07529 }
07530
07531 if (found_type > 1)
07532 error ("multiple types in one declaration");
07533
07534 if (t == NULL_TREE && ! saw_friend)
07535 pedwarn ("declaration does not declare anything");
07536
07537