• Main Page
  • Modules
  • Data Types
  • Files

osprey/kgccfe/gnu/cp/decl.c

Go to the documentation of this file.
00001 /* Process declarations and variables for C compiler.
00002    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
00003    2001, 2002, 2003  Free Software Foundation, Inc.
00004    Contributed by Michael Tiemann (tiemann@cygnus.com)
00005 
00006 This file is part of GNU CC.
00007 
00008 GNU CC is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2, or (at your option)
00011 any later version.
00012 
00013 GNU CC is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with GNU CC; see the file COPYING.  If not, write to
00020 the Free Software Foundation, 59 Temple Place - Suite 330,
00021 Boston, MA 02111-1307, USA.  */
00022 
00023 
00024 /* Process declarations and symbol lookup for C front end.
00025    Also constructs types; the standard scalar types at initialization,
00026    and structure, union, array and enum types when they are declared.  */
00027 
00028 /* ??? not all decl nodes are given the most useful possible
00029    line numbers.  For example, the CONST_DECLs for enum values.  */
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 /* Erroneous argument lists can use this *IFF* they do not modify it.  */
00153 tree error_mark_list;
00154 
00155 /* The following symbols are subsumed in the cp_global_trees array, and
00156    listed here individually for documentation purposes.
00157 
00158    C++ extensions
00159   tree wchar_decl_node;
00160 
00161   tree vtable_entry_type;
00162   tree delta_type_node;
00163   tree __t_desc_type_node;
00164         tree ti_desc_type_node;
00165   tree bltn_desc_type_node, ptr_desc_type_node;
00166   tree ary_desc_type_node, func_desc_type_node, enum_desc_type_node;
00167   tree class_desc_type_node, si_class_desc_type_node, vmi_class_desc_type_node;
00168   tree ptm_desc_type_node;
00169   tree base_desc_type_node;
00170 
00171   tree class_type_node, record_type_node, union_type_node, enum_type_node;
00172   tree unknown_type_node;
00173 
00174    Array type `vtable_entry_type[]'
00175 
00176   tree vtbl_type_node;
00177   tree vtbl_ptr_type_node;
00178 
00179    Namespaces,
00180 
00181   tree std_node;
00182   tree abi_node;
00183 
00184    A FUNCTION_DECL which can call `abort'.  Not necessarily the
00185    one that the user will declare, but sufficient to be called
00186    by routines that want to abort the program.
00187 
00188   tree abort_fndecl;
00189 
00190    The FUNCTION_DECL for the default `::operator delete'.
00191 
00192   tree global_delete_fndecl;
00193 
00194    Used by RTTI
00195   tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
00196   tree tinfo_var_id;
00197 
00198 */
00199 
00200 tree cp_global_trees[CPTI_MAX];
00201 
00202 /* Indicates that there is a type value in some namespace, although
00203    that is not necessarily in scope at the moment.  */
00204 
00205 static GTY(()) tree global_type_node;
00206 
00207 /* Expect only namespace names now.  */
00208 static int only_namespace_names;
00209 
00210 /* Used only for jumps to as-yet undefined labels, since jumps to
00211    defined labels can have their validity checked immediately.  */
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 /* A list of objects which have constructors or destructors
00228    which reside in the global scope.  The decl is stored in
00229    the TREE_VALUE slot and the initializer is stored
00230    in the TREE_PURPOSE slot.  */
00231 tree static_aggregates;
00232 
00233 /* -- end of C++ */
00234 
00235 /* A node for the integer constants 2, and 3.  */
00236 
00237 tree integer_two_node, integer_three_node;
00238 
00239 /* Similar, for last_function_parm_tags.  */
00240 tree last_function_parms;
00241 
00242 /* A list of all LABEL_DECLs in the function that have names.  Here so
00243    we can clear out their names' definitions at the end of the
00244    function, and so we can check the validity of jumps to these labels.  */
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 /* The name of the anonymous namespace, throughout this translation
00261    unit.  */
00262 tree anonymous_namespace_name;
00263 
00264 /* The number of function bodies which we are currently processing.
00265    (Zero if we are at namespace scope, one inside the body of a
00266    function, two inside the body of a function in a local class, etc.)  */
00267 int function_depth;
00268 
00269 /* States indicating how grokdeclarator() should handle declspecs marked
00270    with __attribute__((deprecated)).  An object declared as
00271    __attribute__((deprecated)) suppresses warnings of uses of other
00272    deprecated items.  */
00273    
00274 enum deprecated_states {
00275   DEPRECATED_NORMAL,
00276   DEPRECATED_SUPPRESS
00277 };
00278 
00279 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
00280 
00281 /* Set by add_implicitly_declared_members() to keep those members from
00282    being flagged as deprecated or reported as using deprecated
00283    types.  */
00284 int adding_implicit_members = 0;
00285 
00286 /* True if a declaration with an `extern' linkage specifier is being
00287    processed.  */
00288 bool have_extern_spec;
00289 
00290 
00291 /* Compute the chain index of a binding_entry given the HASH value of its
00292    name and the total COUNT of chains.  COUNT is assumed to be a power
00293    of 2.  */
00294 #define ENTRY_INDEX(HASH, COUNT) (((HASH) >> 3) & ((COUNT) - 1))
00295 
00296 /* A free list of "binding_entry"s awaiting for re-use.  */
00297 static GTY((deletable("")))  binding_entry free_binding_entry;
00298 
00299 /* Create a binding_entry object for (NAME, TYPE).  */
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 /* Put ENTRY back on the free list.  */
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 /* The datatype used to implement the mapping from names to types at
00328    a given scope.  */
00329 struct binding_table_s GTY(())
00330 {
00331   /* Array of chains of "binding_entry"s  */
00332   binding_entry * GTY((length ("%h.chain_count"))) chain;
00333 
00334   /* The number of chains in this table.  This is the length of the
00335      the member "chaiin" considered as an array.  */
00336   size_t chain_count;
00337 
00338   /* Number of "binding_entry"s in this table.  */
00339   size_t entry_count;
00340 };
00341 
00342 /* These macros indicate the initial chains count for binding_table.  */
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 /* Construct TABLE with an initial CHAIN_COUNT.  */
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 /* Free TABLE by making its entries ready for reuse. */
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 /* Allocate a table with CHAIN_COUNT, assumed to be a power of two.  */
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 /* Expand TABLE to twice its current chain_count.  */
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 /* Insert a binding for NAME to TYPe into TABLE.  */
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 /* Return the binding_entry, if any, that maps NAME.  */
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 /* Return the binding_entry, if any, that maps name to an anonymous type.  */
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 /* Return the binding_entry, if any, that has TYPE as target.  If NAME
00458    is non-null, then set the domain and rehash that entry.  */
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       /* Remove the bucket from the previous chain.  */
00480       *p = (*p)->chain;
00481 
00482       /* Remap the name type to type.  */
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 /* Remove from TABLE all entries that map to anonymous enums or
00493    class-types.  */
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 /* Apply PROC -- with DATA -- to all entries in TABLE.  */
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 /* For each binding contour we allocate a binding_level structure
00534    which records the names defined in that contour.
00535    Contours include:
00536     0) the global one
00537     1) one for each function definition,
00538        where internal declarations of the parameters appear.
00539     2) one for each compound statement,
00540        to record its declarations.
00541 
00542    The current meaning of a name can be found by searching the levels
00543    from the current one out to the global one.
00544 
00545    Off to the side, may be the class_binding_level.  This exists only
00546    to catch class-local declarations.  It is otherwise nonexistent.
00547 
00548    Also there may be binding levels that catch cleanups that must be
00549    run when exceptions occur.  Thus, to see whether a name is bound in
00550    the current scope, it is not enough to look in the
00551    CURRENT_BINDING_LEVEL.  You should use lookup_name_current_level
00552    instead.  */
00553 
00554 /* Note that the information in the `names' component of the global contour
00555    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
00556 
00557 struct cp_binding_level GTY(())
00558   {
00559     /* A chain of _DECL nodes for all variables, constants, functions,
00560        and typedef types.  These are in the reverse of the order
00561        supplied.  There may be OVERLOADs on this list, too, but they
00562        are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD.  */
00563     tree names;
00564 
00565     /* Count of elements in names chain.  */
00566     size_t names_size;
00567 
00568     /* A chain of NAMESPACE_DECL nodes.  */
00569     tree namespaces;
00570 
00571     /* An array of static functions and variables (for namespaces only) */
00572     varray_type static_decls;
00573 
00574     /* A chain of VTABLE_DECL nodes.  */
00575     tree vtables; 
00576 
00577     /* A dictionary for looking up enums or class-types names.  */
00578     binding_table type_decls;
00579 
00580     /* A list of USING_DECL nodes.  */
00581     tree usings;
00582 
00583     /* A list of used namespaces. PURPOSE is the namespace,
00584        VALUE the common ancestor with this binding_level's namespace.  */
00585     tree using_directives;
00586 
00587     /* If this binding level is the binding level for a class, then
00588        class_shadowed is a TREE_LIST.  The TREE_PURPOSE of each node
00589        is the name of an entity bound in the class.  The TREE_TYPE is
00590        the DECL bound by this name in the class.  */
00591     tree class_shadowed;
00592 
00593     /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and
00594        is used for all binding levels. In addition the TREE_VALUE is the
00595        IDENTIFIER_TYPE_VALUE before we entered the class.  */
00596     tree type_shadowed;
00597 
00598     /* A TREE_LIST.  Each TREE_VALUE is the LABEL_DECL for a local
00599        label in this scope.  The TREE_PURPOSE is the previous value of
00600        the IDENTIFIER_LABEL VALUE.  */
00601     tree shadowed_labels;
00602 
00603     /* For each level (except not the global one),
00604        a chain of BLOCK nodes for all the levels
00605        that were entered and exited one level down.  */
00606     tree blocks;
00607 
00608     /* The _TYPE node for this level, if parm_flag == 2.  */
00609     tree this_class;
00610 
00611     /* The binding level which this one is contained in (inherits from).  */
00612     struct cp_binding_level *level_chain;
00613 
00614     /* List of VAR_DECLS saved from a previous for statement.
00615        These would be dead in ISO-conforming code, but might
00616        be referenced in ARM-era code.  These are stored in a
00617        TREE_LIST; the TREE_VALUE is the actual declaration.  */
00618     tree dead_vars_from_for;
00619 
00620     /* 1 for the level that holds the parameters of a function.
00621        2 for the level that holds a class declaration.  */
00622     unsigned parm_flag : 2;
00623 
00624     /* 1 means make a BLOCK for this level regardless of all else.
00625        2 for temporary binding contours created by the compiler.  */
00626     unsigned keep : 2;
00627 
00628     /* Nonzero if this level "doesn't exist" for tags.  */
00629     unsigned tag_transparent : 1;
00630 
00631     /* Nonzero if this level can safely have additional
00632        cleanup-needing variables added to it.  */
00633     unsigned more_cleanups_ok : 1;
00634     unsigned have_cleanups : 1;
00635 
00636     /* Nonzero if this scope is for storing the decls for template
00637        parameters and generic decls; these decls will be discarded and
00638        replaced with a TEMPLATE_DECL.  */
00639     unsigned template_parms_p : 1;
00640 
00641     /* Nonzero if this scope corresponds to the `<>' in a
00642        `template <>' clause.  Whenever this flag is set,
00643        TEMPLATE_PARMS_P will be set as well.  */
00644     unsigned template_spec_p : 1;
00645 
00646     /* This is set for a namespace binding level.  */
00647     unsigned namespace_p : 1;
00648 
00649     /* True if this level is that of a for-statement where we need to
00650        worry about ambiguous (ARM or ISO) scope rules.  */
00651     unsigned is_for_scope : 1;
00652 
00653     /* True if this level corresponds to a TRY block.  Currently this
00654        information is only available while building the tree structure.  */
00655     unsigned is_try_scope : 1;
00656 
00657     /* True if this level corresponds to a CATCH block.  Currently this
00658        information is only available while building the tree structure.  */
00659     unsigned is_catch_scope : 1;
00660 
00661     /* Three bits left for this word.  */
00662 
00663     /* Binding depth at which this level began.  */
00664     unsigned binding_depth;
00665   };
00666 
00667 #define NULL_BINDING_LEVEL ((struct cp_binding_level *) NULL)
00668 
00669 /* True if SCOPE designates the global scope binding contour.  */
00670 #define global_scope_p(SCOPE)  \
00671   ((SCOPE) == NAMESPACE_LEVEL (global_namespace))
00672 
00673 /* The binding level currently in effect.  */
00674 
00675 #define current_binding_level     \
00676   (cfun && cp_function_chain->bindings    \
00677    ? cp_function_chain->bindings    \
00678    : scope_chain->bindings)
00679 
00680 /* The binding level of the current class, if any.  */
00681 
00682 #define class_binding_level scope_chain->class_bindings
00683 
00684 /* A chain of binding_level structures awaiting reuse.  */
00685 
00686 static GTY((deletable (""))) struct cp_binding_level *free_binding_level;
00687 
00688 /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
00689 
00690 static int keep_next_level_flag;
00691 
00692 /* A TREE_LIST of VAR_DECLs.  The TREE_PURPOSE is a RECORD_TYPE or
00693    UNION_TYPE; the TREE_VALUE is a VAR_DECL with that type.  At the
00694    time the VAR_DECL was declared, the type was incomplete.  */
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   /* Add this level to the front of the chain (stack) of levels that
00724      are active.  */
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 /* Find the innermost enclosing class scope, and reset
00745    CLASS_BINDING_LEVEL appropriately.  */
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     /* Cannot pop a level, if there are none left to pop.  */
00765     my_friendly_assert (!global_scope_p (current_binding_level), 20030527);
00766   /* Pop the current level, and free the structure for reuse.  */
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   /* Suspend the current level.  */
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   /* Resuming binding levels is meant only for namespaces,
00828      and those cannot nest into classes.  */
00829   my_friendly_assert(!class_binding_level, 386);
00830   /* Also, resuming a non-directly nested namespace is a no-no.  */
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 /* Create a new `struct cp_binding_level'.  */
00845 
00846 static
00847 struct cp_binding_level *
00848 make_binding_level ()
00849 {
00850   /* NOSTRICT */
00851   return (struct cp_binding_level *) ggc_alloc (sizeof (struct cp_binding_level));
00852 }
00853 
00854 /* Nonzero if we are currently in the global binding level.  */
00855 
00856 int
00857 global_bindings_p ()
00858 {
00859   return global_scope_p (current_binding_level);
00860 }
00861 
00862 /* Return the innermost binding level that is not for a class scope.  */
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 /* Nonzero if we are currently in a toplevel binding level.  This
00877    means either the global binding level or a namespace in a toplevel
00878    binding level.  Since there are no non-toplevel namespace levels,
00879    this really means any namespace or template parameter level.  We
00880    also include a class whose context is toplevel.  */
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 /* Nonzero if this is a namespace scope, or if we are defining a class
00891    which is itself at namespace scope, or whose enclosing class is
00892    such a class, etc.  */
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 /* If KEEP is nonzero, make a BLOCK node for the next binding level,
00903    unconditionally.  Otherwise, use the normal logic to decide whether
00904    or not to create a BLOCK.  */
00905 
00906 void
00907 keep_next_level (keep)
00908      int keep;
00909 {
00910   keep_next_level_flag = keep;
00911 }
00912 
00913 /* Nonzero if the current level needs to have a BLOCK made.  */
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 /* Returns the kind of the innermost scope.  */
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 /* Returns nonzero if this scope was created to store template
00940    parameters.  */
00941 
00942 int
00943 template_parm_scope_p ()
00944 {
00945   return current_binding_level->template_parms_p;
00946 }
00947 
00948 /* Returns the kind of template specialization we are currently
00949    processing, given that it's declaration contained N_CLASS_SCOPES
00950    explicit scope qualifications.  */
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   /* Scan through the template parameter scopes.  */
00962   for (b = current_binding_level; b->template_parms_p; b = b->level_chain)
00963     {
00964       /* If we see a specialization scope inside a parameter scope,
00965    then something is wrong.  That corresponds to a declaration
00966    like:
00967 
00968       template <class T> template <> ...
00969 
00970    which is always invalid since [temp.expl.spec] forbids the
00971    specialization of a class member template if the enclosing
00972    class templates are not explicitly specialized as well.  */
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   /* Handle explicit instantiations.  */
00987   if (processing_explicit_instantiation)
00988     {
00989       if (n_template_parm_scopes != 0)
00990   /* We've seen a template parameter list during an explicit
00991      instantiation.  For example:
00992 
00993        template <class T> template void f(int);
00994 
00995      This is erroneous.  */
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     /* We've not seen enough template headers to match all the
01003        specialized classes present.  For example:
01004 
01005          template <class T> void R<T>::S<T>::f(int);
01006 
01007        This is invalid; there needs to be one set of template
01008        parameters for each class.  */
01009     return tsk_insufficient_parms;
01010   else if (n_template_parm_scopes == n_class_scopes)
01011     /* We're processing a non-template declaration (even though it may
01012        be a member of a template class.)  For example:
01013 
01014          template <class T> void S<T>::f(int);
01015 
01016        The `class T' maches the `S<T>', leaving no template headers
01017        corresponding to the `f'.  */
01018     return tsk_none;
01019   else if (n_template_parm_scopes > n_class_scopes + 1)
01020     /* We've got too many template headers.  For example:
01021 
01022          template <> template <class T> void f (T);
01023 
01024        There need to be more enclosing classes.  */
01025     return tsk_excessive_parms;
01026   else
01027     /* This must be a template.  It's of the form:
01028 
01029          template <class T> template <class U> void S<T>::f(U);
01030 
01031        This is a specialization if the innermost level was a
01032        specialization; otherwise it's just a definition of the
01033        template.  */
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 /* Enter a new binding level.
01045    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
01046    not for that of tags.  */
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   /* Reuse or create a struct for this binding level.  */
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 /* We're defining an object of type TYPE.  If it needs a cleanup, but
01071    we're not allowed to add any more objects with cleanups to the current
01072    scope, create a new binding level.  */
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 (/*begin_p=*/1, /*partial_p=*/1);
01085     }
01086 }
01087   
01088 /* Enter a new scope.  The KIND indicates what kind of scope is being
01089    created.  */
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       /* Fall through.  */
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 /* Exit the current scope.  */
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 /* Record that the current binding level represents a try block.  */
01127 
01128 void
01129 note_level_for_try ()
01130 {
01131   current_binding_level->is_try_scope = 1;
01132 }
01133 
01134 /* Record that the current binding level represents a catch block.  */
01135 
01136 void
01137 note_level_for_catch ()
01138 {
01139   current_binding_level->is_catch_scope = 1;
01140 }
01141 
01142 /* For a binding between a name and an entity at a block scope,
01143    this is the `struct cp_binding_level' for the block.  */
01144 #define BINDING_LEVEL(NODE) ((NODE)->scope.level)
01145 
01146 /* A free list of "cxx_binding"s, connected by their PREVIOUS.  */
01147 
01148 static GTY((deletable (""))) cxx_binding *free_bindings;
01149 
01150 /* Make DECL the innermost binding for ID.  The LEVEL is the binding
01151    level at which this declaration is being bound.  */
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   /* Now, fill in the binding information.  */
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   /* And put it on the front of the list of bindings for ID.  */
01178   binding->previous = IDENTIFIER_BINDING (id);
01179   IDENTIFIER_BINDING (id) = binding;
01180 }
01181 
01182 /* ID is already bound in the current scope.  But, DECL is an
01183    additional binding for ID in the same scope.  This is the `struct
01184    stat' hack whereby a non-typedef class-name or enum-name can be
01185    bound at the same level as some other kind of entity.  It's the
01186    responsibility of the caller to check that inserting this name is
01187    valid here.  Returns nonzero if the new binding was successful.  */
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     /* The new name is the type name.  */
01199     BINDING_TYPE (binding) = decl;
01200   else if (!BINDING_VALUE (binding))
01201     /* This situation arises when push_class_level_binding moves an
01202        inherited type-binding out of the way to make room for a new
01203        value binding.  */
01204     BINDING_VALUE (binding) = decl;
01205   else if (TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL
01206      && DECL_ARTIFICIAL (BINDING_VALUE (binding)))
01207     {
01208       /* The old binding was a type name.  It was placed in
01209    BINDING_VALUE because it was thought, at the point it was
01210    declared, to be the only entity with such a name.  Move the
01211    type name into the type slot; it is now hidden by the new
01212    binding.  */
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          /* If either type involves template parameters, we must
01223       wait until instantiation.  */
01224          || uses_template_parms (TREE_TYPE (decl))
01225          || uses_template_parms (TREE_TYPE (BINDING_VALUE (binding)))))
01226     /* We have two typedef-names, both naming the same type to have
01227        the same name.  This is OK because of:
01228 
01229          [dcl.typedef]
01230 
01231    In a given scope, a typedef specifier can be used to redefine
01232    the name of any type declared in that scope to refer to the
01233    type to which it already refers.  */
01234     ok = 0;
01235   /* There can be two block-scope declarations of the same variable,
01236      so long as they are `extern' declarations.  However, there cannot
01237      be two declarations of the same static data member:
01238 
01239        [class.mem]
01240 
01241        A member shall not be declared twice in the
01242        member-specification.  */
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 /* Add DECL to the list of things declared in B.  */
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       /* We build up the list in reverse order, and reverse it later if
01284          necessary.  */
01285       TREE_CHAIN (decl) = b->names;
01286       b->names = decl;
01287       b->names_size++;
01288 
01289       /* If appropriate, add decl to separate list of statics */
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 /* Bind DECL to ID in the current_binding_level, assumed to be a local
01299    binding level.  If PUSH_USING is set in FLAGS, we know that DECL
01300    doesn't really belong to this binding level, that it got here
01301    through a using-declaration.  */
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   /* Skip over any local classes.  This makes sense if we call
01312      push_local_binding with a friend decl of a local class.  */
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       /* Supplement the existing binding.  */
01320       if (!add_binding (id, decl))
01321   /* It didn't work.  Something else must be bound at this
01322      level.  Do not add DECL to the list of things to pop
01323      later.  */
01324   return;
01325     }
01326   else
01327     /* Create a new binding.  */
01328     push_binding (id, decl, b);
01329 
01330   if (TREE_CODE (decl) == OVERLOAD || (flags & PUSH_USING))
01331     /* We must put the OVERLOAD into a TREE_LIST since the
01332        TREE_CHAIN of an OVERLOAD is already used.  Similarly for
01333        decls that got here through a using-declaration.  */
01334     decl = build_tree_list (NULL_TREE, decl);
01335 
01336   /* And put DECL on the list of things declared by the current
01337      binding level.  */
01338   add_decl_to_level (decl, b);
01339 }
01340 
01341 /* Bind DECL to ID in the class_binding_level.  Returns nonzero if the
01342    binding was successful.  */
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   /* Note that we declared this value so that we can issue an error if
01355      this is an invalid redeclaration of a name already used for some
01356      other purpose.  */
01357   note_name_declared_in_class (id, decl);
01358 
01359   if (binding && BINDING_LEVEL (binding) == class_binding_level)
01360     /* Supplement the existing binding.  */
01361     result = add_binding (id, decl);
01362   else
01363     /* Create a new binding.  */
01364     push_binding (id, decl, class_binding_level);
01365 
01366   /* Update the IDENTIFIER_CLASS_VALUE for this ID to be the
01367      class-level declaration.  Note that we do not use DECL here
01368      because of the possibility of the `struct stat' hack; if DECL is
01369      a class-name or enum-name we might prefer a field-name, or some
01370      such.  */
01371   IDENTIFIER_CLASS_VALUE (id) = BINDING_VALUE (IDENTIFIER_BINDING (id));
01372 
01373   /* If this is a binding from a base class, mark it as such.  */
01374   binding = IDENTIFIER_BINDING (id);
01375   if (BINDING_VALUE (binding) == decl && TREE_CODE (decl) != TREE_LIST)
01376     {
01377       /* Any implicit typename must be from a base-class.  The
01378    context for an implicit typename declaration is always
01379    the derived class in which the lookup was done, so the checks
01380    based on the context of DECL below will not trigger.  */
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     /* We only encounter a TREE_LIST when push_class_decls detects an
01401        ambiguity.  Such an ambiguity can be overridden by a definition
01402        in this class.  */
01403     INHERITED_VALUE_BINDING_P (binding) = 1;
01404 
01405   POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, result);
01406 }
01407 
01408 /* Remove the binding for DECL which should be the innermost binding
01409    for ID.  */
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     /* It's easiest to write the loops that call this function without
01420        checking whether or not the entities involved have names.  We
01421        get here for such an entity.  */
01422     return;
01423 
01424   /* Get the innermost binding for ID.  */
01425   binding = IDENTIFIER_BINDING (id);
01426 
01427   /* The name should be bound.  */
01428   my_friendly_assert (binding != NULL, 0);
01429 
01430   /* The DECL will be either the ordinary binding or the type
01431      binding for this identifier.  Remove that binding.  */
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       /* We're completely done with the innermost binding for this
01442    identifier.  Unhook it from the list of bindings.  */
01443       IDENTIFIER_BINDING (id) = binding->previous;
01444 
01445       /* Add it to the free list.  */
01446       binding->previous = free_bindings;
01447       free_bindings = binding;
01448 
01449       /* Clear the BINDING_LEVEL so the garbage collector doesn't walk
01450    it.  */
01451       BINDING_LEVEL (binding) = NULL;
01452     }
01453 }
01454 
01455 /* When a label goes out of scope, check to see if that label was used
01456    in a valid manner, and issue any appropriate warnings or errors.  */
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     /* Avoid crashing later.  */
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 /* At the end of a function, all labels declared within the function
01479    go out of scope.  BLOCK is the top-level block for the
01480    function.  */
01481 
01482 static void
01483 pop_labels (block)
01484      tree block;
01485 {
01486   struct named_label_list *link;
01487 
01488   /* Clear out the definitions of all label names, since their scopes
01489      end here.  */
01490   for (link = named_labels; link; link = link->next)
01491     {
01492       pop_label (link->label_decl, link->old_value);
01493       /* Put the labels into the "variables" of the top-level block,
01494    so debugger can see them.  */
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 /* Exit a binding level.
01503    Pop the level off, and restore the state of the identifier-decl mappings
01504    that were in effect when this level was entered.
01505 
01506    If KEEP == 1, this level had explicit declarations, so
01507    and create a "block" (a BLOCK node) for the level
01508    to record its declarations and subblocks for symbol table output.
01509 
01510    If FUNCTIONBODY is nonzero, this level is the body of a function,
01511    so create a block as if KEEP were set and also clear out all
01512    label names.
01513 
01514    If REVERSE is nonzero, reverse the order of decls before putting
01515    them into the BLOCK.  */
01516 
01517 tree
01518 poplevel (keep, reverse, functionbody)
01519      int keep;
01520      int reverse;
01521      int functionbody;
01522 {
01523   register tree link;
01524   /* The chain of decls was accumulated in reverse order.
01525      Put it into forward order, just for cleanliness.  */
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   /* We used to use KEEP == 2 to indicate that the new block should go
01550      at the beginning of the list of blocks at this binding level,
01551      rather than the end.  This hack is no longer used.  */
01552   my_friendly_assert (keep == 0 || keep == 1, 0);
01553 
01554   if (current_binding_level->keep == 1)
01555     keep = 1;
01556 
01557   /* Any uses of undefined labels, and any defined labels, now operate
01558      under constraints of next binding contour.  */
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   /* Get the decls in the order they were written.
01594      Usually current_binding_level->names is in reverse order.
01595      But parameter decls were previously put in forward order.  */
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   /* Output any nested inline functions within this block
01604      if they weren't already output.  */
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   /* If this decl was copied from a file-scope decl
01613      on account of a block-scope extern decl,
01614      propagate TREE_ADDRESSABLE to the file-scope decl.  */
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   /* When not in function-at-a-time mode, expand_end_bindings will
01626      warn about unused variables.  But, in function-at-a-time mode
01627      expand_end_bindings is not passed the list of variables in the
01628      current scope, and therefore no warning is emitted.  So, we
01629      explicitly warn here.  */
01630   if (!processing_template_decl)
01631     warn_about_unused_variables (getdecls ());
01632 
01633   /* If there were any declarations or structure tags in that level,
01634      or if this level is a function body,
01635      create a BLOCK to record them for the life of this function.  */
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   /* In each subblock, record that this is its superior.  */
01646   if (keep >= 0)
01647     for (link = subblocks; link; link = TREE_CHAIN (link))
01648       BLOCK_SUPERCONTEXT (link) = block;
01649 
01650   /* We still support the old for-scope rules, whereby the variables
01651      in a for-init statement were in scope after the for-statement
01652      ended.  We only use the new rules in flag_new_for_scope is
01653      nonzero.  */
01654   leaving_for_scope
01655     = current_binding_level->is_for_scope && flag_new_for_scope == 1;
01656 
01657   /* Remove declarations for all the DECLs in this level.  */
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       /* We have something like:
01676 
01677            int i;
01678            for (int i; ;);
01679 
01680          and we are leaving the `for' scope.  There's no reason to
01681          keep the binding of the inner `i' in this case.  */
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       /* Here, we have something like:
01689 
01690      typedef int I;
01691 
01692      void f () {
01693        for (int I; ;);
01694      }
01695 
01696          We must pop the for-scope binding so we know what's a
01697          type and what isn't.  */
01698       pop_binding (DECL_NAME (link), link);
01699     else
01700       {
01701         /* Mark this VAR_DECL as dead so that we can tell we left it
01702      there only for backward compatibility.  */
01703         DECL_DEAD_FOR_LOCAL (link) = 1;
01704 
01705         /* Keep track of what should of have happenned when we
01706      popped the binding.  */
01707         if (outer_binding && BINDING_VALUE (outer_binding))
01708     DECL_SHADOWED_FOR_VAR (link)
01709       = BINDING_VALUE (outer_binding);
01710 
01711         /* Add it to the list of dead variables in the next
01712      outermost binding to that we can remove these when we
01713      leave that binding.  */
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         /* Although we don't pop the cxx_binding, we do clear
01720      its BINDING_LEVEL since the level is going away now.  */
01721         BINDING_LEVEL (IDENTIFIER_BINDING (DECL_NAME (link)))
01722     = 0;
01723       }
01724   }
01725       else
01726   {
01727     /* Remove the binding.  */
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   /* Remove declarations for any `for' variables from inner scopes
01741      that we kept around.  */
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   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
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   /* Restore the IDENTIFIER_LABEL_VALUEs for local labels.  */
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   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
01758      list if a `using' declaration put them there.  The debugging
01759      back-ends won't understand OVERLOAD, so we remove them here.
01760      Because the BLOCK_VARS are (temporarily) shared with
01761      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
01762      popped all the bindings.  */
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   /* If the level being exited is the top level of a function,
01777      check over all the labels.  */
01778   if (functionbody)
01779     {
01780       /* Since this is the top level block of a function, the vars are
01781    the function's parameters.  Don't leave them in the BLOCK
01782    because they are found in the FUNCTION_DECL instead.  */
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   /* If we did not make a block for the level just exited,
01797      any blocks made for inner levels
01798      (since they cannot be recorded as subblocks in that level)
01799      must be carried forward so they will later become subblocks
01800      of something else.  */
01801   else if (subblocks)
01802     current_binding_level->blocks
01803       = chainon (current_binding_level->blocks, subblocks);
01804 
01805   /* Each and every BLOCK node created here in `poplevel' is important
01806      (e.g. for proper debugging information) so if we created one
01807      earlier, mark it as "used".  */
01808   if (block)
01809     TREE_USED (block) = 1;
01810 
01811   /* Take care of compiler's internal binding structures.  */
01812   if (tmp == 2)
01813     {
01814       tree scope_stmts;
01815 
01816       scope_stmts
01817   = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/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 /* Delete the node BLOCK from the current binding level.
01831    This is used for the block inside a stmt expr ({...})
01832    so that the block can be reinserted where appropriate.  */
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   /* Clear TREE_USED which is always set by poplevel.
01850      The flag is set again if insert_block is called.  */
01851   TREE_USED (block) = 0;
01852 }
01853 
01854 /* Insert BLOCK at the end of the list of subblocks of the
01855    current binding level.  This is used when a BIND_EXPR is expanded,
01856    to handle the BLOCK node inside the BIND_EXPR.  */
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 /* Set the BLOCK node for the innermost scope
01868    (the one we are currently in).  */
01869 
01870 void
01871 set_block (block)
01872     tree block ATTRIBUTE_UNUSED;
01873 {
01874   /* The RTL expansion machinery requires us to provide this callback,
01875      but it is not applicable in function-at-a-time mode.  */
01876   my_friendly_assert (cfun && !doing_semantic_analysis_p (), 20000911);
01877 }
01878 
01879 /* Do a pushlevel for class declarations.  */
01880 
01881 void
01882 pushlevel_class ()
01883 {
01884   register struct cp_binding_level *newlevel;
01885 
01886   /* Reuse or create a struct for this binding level.  */
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 /* ...and a poplevel for class declarations.  */
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   /* If we're leaving a toplevel class, don't bother to do the setting
01918      of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot
01919      shouldn't even be used when current_class_type isn't set, and second,
01920      if we don't touch it here, we're able to use the cache effect if the
01921      next time we're entering a class scope, it is the same class.  */
01922   if (current_class_depth != 1)
01923     {
01924       struct cp_binding_level* b;
01925 
01926       /* Clear out our IDENTIFIER_CLASS_VALUEs.  */
01927       for (shadowed = level->class_shadowed;
01928      shadowed;
01929      shadowed = TREE_CHAIN (shadowed))
01930   IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = NULL_TREE;
01931 
01932       /* Find the next enclosing class, and recreate
01933    IDENTIFIER_CLASS_VALUEs appropriate for that class.  */
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     /* Remember to save what IDENTIFIER's were bound in this scope so we
01956        can recover from cache misses.  */
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   /* Remove the bindings for all of the class-level declarations.  */
01967   for (shadowed = level->class_shadowed;
01968        shadowed;
01969        shadowed = TREE_CHAIN (shadowed))
01970     pop_binding (TREE_PURPOSE (shadowed), TREE_TYPE (shadowed));
01971 
01972   /* Now, pop out of the binding level which we created up in the
01973      `pushlevel_class' routine.  */
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 /* We are entering the scope of a class.  Clear IDENTIFIER_CLASS_VALUE
01983    for any names in enclosing classes.  */
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 /* Returns nonzero if T is a virtual function table.  */
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 /* Returns nonzero if T is a TYPE_DECL for a type with virtual
02010    functions.  */
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 /* Return the declarations that are members of the namespace NS.  */
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 /* Walk the vtable declarations in NAMESPACE.  Whenever one is found
02038    for which P returns nonzero, call F with its address.  If any call
02039    to F returns a nonzero value, return a nonzero value.  */
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 /* Walk the vtable declarations.  Whenever one is found for which P
02059    returns nonzero, call F with its address.  If any call to F
02060    returns a nonzero value, return a nonzero value.  */
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 /* Walk all the namespaces contained NAMESPACE, including NAMESPACE
02076    itself, calling F for each.  The DATA is passed to F as well.  */
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 /* Walk all the namespaces, calling F for each.  The DATA is passed to
02096    F as well.  */
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 /* Walk the global declarations in NAMESPACE.  Whenever one is found
02107    for which P returns nonzero, call F with its address.  If any call
02108    to F returns a nonzero value, return a nonzero value.  */
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       /* If F changed *T, then *T still points at the next item to
02132    examine.  */
02133       if (*t == glbl)
02134   t = &TREE_CHAIN (*t);
02135     }
02136 
02137   return result;
02138 }
02139 
02140 /* Walk the global declarations.  Whenever one is found for which P
02141    returns nonzero, call F with its address.  If any call to F
02142    returns a nonzero value, return a nonzero value.  */
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 /* Call wrapup_globals_declarations for the globals in NAMESPACE.  If
02159    DATA is non-NULL, this is the last time we will call
02160    wrapup_global_declarations for this NAMESPACE.  */
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   /* Write out any globals that need to be output.  */
02180   return wrapup_global_declarations (vec, len);
02181 }
02182 
02183 
02184 /* For debugging.  */
02185 static int no_print_functions = 0;
02186 static int no_print_builtins = 0;
02187 
02188 /* Called from print_binding_level through binding_table_foreach to
02189    print the content of binding ENTRY.  DATA is a pointer to line offset
02190    marker.  */
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       /* We can probably fit 3 names to a line?  */
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     /* Function decls tend to have longer names.  */
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 /* Namespace binding access routines.   */
02344 
02345 /* Check whether the a binding for the name to scope is known.
02346    Returns the binding found, or NULL.  */
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     /* Move binding found to the front of the list, so
02361              subsequent lookups will find it faster.  */
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 /* Return the binding for NAME in SCOPE, if any.  Otherwise, return NULL.  */
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       /* Fold-in case where NAME is used only once.  */
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 /* Always returns a binding for name in scope.
02393    If no binding is found, make a new one.  */
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   /* Not found, make a new one.  */
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 /* Return the binding value for name in scope.  */
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 /* Set the binding value for name in scope.  */
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 /* Push into the scope of the NAME namespace.  If NAME is NULL_TREE, then we
02448    select a name that is unique to this compilation unit.  */
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       /* This must be ::.  */
02464       my_friendly_assert (name == get_identifier ("::"), 377);
02465       global = 1;
02466     }
02467   else if (!name)
02468     {
02469       /* The name of anonymous namespace is unique for the translation
02470          unit.  */
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         /* Reopening anonymous namespace.  */
02477         need_new = 0;
02478       implicit_use = 1;
02479     }
02480   else
02481     {
02482       /* Check whether this is an extended namespace definition.  */
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       /* Make a new namespace, binding the name to it.  */
02499       d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
02500       /* The global namespace is not pushed, and the global binding
02501    level is set elsewhere.  */
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   /* Enter the name space.  */
02524   current_namespace = d;
02525 
02526   timevar_pop (TV_NAME_LOOKUP);
02527 }
02528 
02529 /* Pop from the scope of the current namespace.  */
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   /* The binding level is not popped, as it might be re-opened later.  */
02537   suspend_binding_level ();
02538 }
02539 
02540 /* Push into the scope of the namespace NS, even if it is deeply
02541    nested within another namespace.  */
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 /* Pop back from the scope of the namespace NS, which was previously
02557    entered with push_nested_namespace.  */
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 /* Allocate storage for saving a C++ binding.  */
02576 #define cxx_saved_binding_make() \
02577   (ggc_alloc (sizeof (cxx_saved_binding)))
02578 
02579 struct cxx_saved_binding GTY(())
02580 {
02581   /* Link that chains saved C++ bindings for a given name into a stack.  */
02582   cxx_saved_binding *previous;
02583   /* The name of the current binding.  */
02584   tree identifier;
02585   /* The binding we're saving.  */
02586   cxx_binding *binding;
02587   tree class_value;
02588   tree real_type_value;
02589 };
02590 
02591 /* Subroutines for reverting temporarily to top-level for instantiation
02592    of templates and such.  We actually need to clear out the class- and
02593    local-value slots of all identifiers, so that only the global values
02594    are at all visible.  Simply setting current_binding_level to the global
02595    scope isn't enough, because more binding levels may be pushed.  */
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     /* Note that we may have an IDENTIFIER_CLASS_VALUE even when
02618        we have no IDENTIFIER_BINDING if we have left the class
02619        scope, but cached the class-level declarations.  */
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   /* If we're in the middle of some function, save our state.  */
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   /* Have to include the global scope, because class-scope decls
02672      aren't listed anywhere useful.  */
02673   for (; b; b = b->level_chain)
02674     {
02675       tree t;
02676 
02677       /* Template IDs are inserted into the global level. If they were
02678    inserted into namespace level, finish_file wouldn't find them
02679    when doing pending instantiations. Therefore, don't stop at
02680    namespace level, but continue until :: .  */
02681       if (global_scope_p (b) || (pseudo && b->template_parms_p))
02682   break;
02683 
02684       old_bindings = store_bindings (b->names, old_bindings);
02685       /* We also need to check class_shadowed to save class-level type
02686    bindings, since pushclass doesn't fill in b->names.  */
02687       if (b->parm_flag == 2)
02688   old_bindings = store_bindings (b->class_shadowed, old_bindings);
02689 
02690       /* Unwind type-value slots back to top level.  */
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   /* Clear out class-level bindings cache.  */
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   /* If we were in the middle of compiling a function, restore our
02740      state.  */
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 /* Push a definition of struct, union or enum tag "name".
02750    into binding_level "b".   "type" should be the type node,
02751    We assume that the tag "name" is not already defined.
02752 
02753    Note that the definition may really be just a forward reference.
02754    In that case, the TYPE_SIZE will be a NULL_TREE.
02755 
02756    C++ gratuitously puts all these tags in the name space.  */
02757 
02758 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
02759    record the shadowed value for this binding contour.  TYPE is
02760    the type that ID maps to.  */
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       /* Shadow the marker, not the real thing, so that the marker
02771    gets restored later.  */
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       /* Store marker instead of real type.  */
02781       type = global_type_node;
02782     }
02783   SET_IDENTIFIER_TYPE_VALUE (id, type);
02784 }
02785 
02786 /* As set_identifier_type_value_with_scope, but using current_binding_level.  */
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 /* Return the type associated with id.  */
02797 
02798 tree
02799 identifier_type_value (id)
02800      tree id;
02801 {
02802   timevar_push (TV_NAME_LOOKUP);
02803   /* There is no type with that name, anywhere.  */
02804   if (REAL_IDENTIFIER_TYPE_VALUE (id) == NULL_TREE)
02805     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
02806   /* This is not the type marker, but the real thing.  */
02807   if (REAL_IDENTIFIER_TYPE_VALUE (id) != global_type_node)
02808     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, REAL_IDENTIFIER_TYPE_VALUE (id));
02809   /* Have to search for it. It must be on the global level, now.
02810      Ask lookup_name not to return non-types.  */
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 /* Pop off extraneous binding levels left over due to syntax errors.
02818 
02819    We don't pop past namespaces, as they might be valid.  */
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 /* The type TYPE is being declared.  If it is a class template, or a
02838    specialization of a class template, do any processing required and
02839    perform error-checking.  If IS_FRIEND is nonzero, this TYPE is
02840    being declared a friend.  B is the binding level at which this TYPE
02841    should be bound.
02842 
02843    Returns the TYPE_DECL for TYPE, which may have been altered by this
02844    processing.  */
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     /* You can't declare a new template type in a template parameter
02856        list.  But, you can declare a non-template type:
02857 
02858          template <class A*> struct S;
02859 
02860        is a forward-declaration of `A'.  */
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     /* This may change after the call to
02873        push_template_decl_real, but we want the original value.  */
02874     tree name = DECL_NAME (decl);
02875 
02876     decl = push_template_decl_real (decl, globalize);
02877     /* If the current binding level is the binding level for the
02878        template parameters (see the comment in
02879        begin_template_parm_list) and the enclosing level is a class
02880        scope, and we're not looking at a friend, push the
02881        declaration of the member class into the class scope.  In the
02882        friend case, push_template_decl will already have put the
02883        friend into global scope, if appropriate.  */
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         /* Put this tag on the list of tags for the class, since
02890      that won't happen below because B is not the class
02891      binding level, but is instead the pseudo-global level.  */
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, /*friend_p=*/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 /* In C++, you don't have to write `struct S' to refer to `S'; you
02911    can just use `S'.  We accomplish this by creating a TYPE_DECL as
02912    if the user had written `typedef struct S S'.  Create and return
02913    the TYPE_DECL for TYPE.  */
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   /* There are other implicit type declarations, like the one *within*
02925      a class that allows you to write `S::S'.  We must distinguish
02926      amongst these.  */
02927   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
02928   TYPE_NAME (type) = decl;
02929 
02930   return decl;
02931 }
02932 
02933 /* Remember a local name for name-mangling purposes.  */
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 /* Push a tag name NAME for struct/class/union/enum type TYPE.
02973    Normally put it into the inner-most non-tag-transparent scope,
02974    but if GLOBALIZE is true, put it in the inner-most non-class scope.
02975    The latter is needed for implicit declarations.  */
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      /* We may be defining a new type in the initializer
02991         of a static member variable. We allow this when
02992         not pedantic, and it is particularly useful for
02993         type punning via an anonymous union.  */
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       /* Do C++ gratuitous typedefing.  */
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     /* When declaring a friend class of a local class, we want
03018        to inject the newly named class into the scope
03019        containing the local class, not the namespace scope.  */
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     /* Put this TYPE_DECL on the TYPE_FIELDS list for the
03044        class.  But if it's a member template class, we
03045        want the TEMPLATE_DECL, not the TYPE_DECL, so this
03046        is done later.  */
03047     finish_member_declaration (d);
03048         else
03049     pushdecl_class_level (d);
03050       }
03051     else
03052       d = pushdecl_with_scope (d, b);
03053 
03054     /* FIXME what if it gets a name from typedef?  */
03055     if (ANON_AGGRNAME_P (name))
03056       DECL_IGNORED_P (d) = 1;
03057 
03058     TYPE_CONTEXT (type) = DECL_CONTEXT (d);
03059 
03060     /* If this is a local class, keep track of it.  We need this
03061        information for name-mangling, and so that it is possible to find
03062        all function definitions in a translation unit in a convenient
03063        way.  (It's otherwise tricky to find a member function definition
03064        it's only pointed to from within a local class.)  */
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, /*friend_p=*/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     /* Use the canonical TYPE_DECL for this node.  */
03083     TYPE_STUB_DECL (type) = TYPE_NAME (type);
03084   else
03085     {
03086       /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
03087    will be the tagged type we just added to the current
03088    binding level.  This fake NULL-named TYPE_DECL node helps
03089    dwarfout.c to know when it needs to output a
03090    representation of a tagged type, and it also gives us a
03091    convenient place to record the "scope start" address for
03092    the tagged type.  */
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 /* Counter used to create anonymous type names.  */
03102 
03103 static int anon_cnt = 0;
03104 
03105 /* Return an IDENTIFIER which can be used as a name for
03106    anonymous structs and unions.  */
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 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
03118    This keeps dbxout from getting confused.  */
03119 
03120 void
03121 clear_anon_tags ()
03122 {
03123   register struct cp_binding_level *b;
03124   static int last_cnt = 0;
03125 
03126   /* Fast out if no new anon names were declared.  */
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 /* Subroutine of duplicate_decls: return truthvalue of whether
03139    or not types of these decls match.
03140 
03141    For C++, we must compare the parameter list so that `int' can match
03142    `int&' in a parameter position, but `int&' is not confused with
03143    `const int&'.  */
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     /* If the two DECLs are not even the same kind of thing, we're not
03156        interested in their types.  */
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 /* If NEWDECL is `static' and an `extern' was seen previously,
03241    warn about it.  OLDDECL is the previous declaration.
03242 
03243    Note that this does not apply to the C++ case of declaring
03244    a variable `extern const' and then later `const'.
03245 
03246    Don't complain about built-in functions, since they are beyond
03247    the user's control.  */
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   /* Don't get confused by static member functions; that's a different
03266      use of `static'.  */
03267   if (TREE_CODE (newdecl) == FUNCTION_DECL
03268       && DECL_STATIC_FUNCTION_P (newdecl))
03269     return;
03270 
03271   /* If the old declaration was `static', or the new one isn't, then
03272      then everything is OK.  */
03273   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
03274     return;
03275 
03276   /* It's OK to declare a builtin function as `static'.  */
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 /* Handle when a new declaration NEWDECL has the same name as an old
03289    one OLDDECL in the same binding contour.  Prints an error message
03290    if appropriate.
03291 
03292    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
03293    Otherwise, return 0.  */
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   /* If either the type of the new decl or the type of the old decl is an
03309      error_mark_node, then that implies that we have already issued an
03310      error (earlier) for some bogus type specification, and in that case,
03311      it is rather pointless to harass the user with yet more error message
03312      about the same declaration, so just pretend the types match here.  */
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   /* Already warned elsewhere.  */;
03326       else if (DECL_DECLARED_INLINE_P (olddecl)
03327          && DECL_UNINLINABLE (olddecl)
03328          && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
03329   /* Already warned.  */;
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   /* Check for redeclaration and other discrepancies.  */
03351   if (TREE_CODE (olddecl) == FUNCTION_DECL
03352       && DECL_ARTIFICIAL (olddecl))
03353     {
03354       if (TREE_CODE (newdecl) != FUNCTION_DECL)
03355   {
03356           /* Avoid warnings redeclaring anticipated built-ins.  */
03357           if (DECL_ANTICIPATED (olddecl))
03358             return 0;
03359 
03360     /* If you declare a built-in or predefined function name as static,
03361        the old definition is overridden, but optionally warn this was a
03362        bad choice of name.  */
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         /* Discard the old built-in function.  */
03370         return 0;
03371       }
03372     /* If the built-in is not ansi, then programs can override
03373        it even globally without an error.  */
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           /* Avoid warnings redeclaring anticipated built-ins.  */
03388           if (DECL_ANTICIPATED (olddecl))
03389             ;  /* Do nothing yet.  */
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         /* A near match; override the builtin.  */
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       /* Discard the old built-in function.  */
03410       return 0;
03411 
03412     /* Replace the old RTL to avoid problems with inlining.  */
03413     SET_DECL_RTL (olddecl, DECL_RTL (newdecl));
03414   }
03415       /* Even if the types match, prefer the new declarations type
03416    for anitipated built-ins, for exception lists, etc...  */
03417       else if (DECL_ANTICIPATED (olddecl))
03418   TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
03419 
03420       /* Whether or not the builtin can throw exceptions has no
03421    bearing on this declarator.  */
03422       TREE_NOTHROW (olddecl) = 0;
03423 
03424       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
03425   {
03426     /* If a builtin function is redeclared as `static', merge
03427        the declarations, but make the original one static.  */
03428     DECL_THIS_STATIC (olddecl) = 1;
03429     TREE_PUBLIC (olddecl) = 0;
03430 
03431     /* Make the old declaration consistent with the new one so
03432        that all remnants of the builtin-ness of this function
03433        will be banished.  */
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     /* We do nothing special here, because C++ does such nasty
03451        things with TYPE_DECLs.  Instead, just let the TYPE_DECL
03452        get shadowed, and know that if we need to find a TYPE_DECL
03453        for a given name, we can look in the IDENTIFIER_TYPE_VALUE
03454        slot of the identifier.  */
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       /* New decl is completely inconsistent with the old one =>
03470    tell caller to replace the old one.  */
03471 
03472       return 0;
03473     }
03474   else if (!types_match)
03475     {
03476       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
03477   /* These are certainly not duplicate declarations; they're
03478      from different scopes.  */
03479   return 0;
03480 
03481       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
03482   {
03483     /* The name of a class template may not be declared to refer to
03484        any other template, class, function, object, namespace, value,
03485        or type in the same scope.  */
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        /* Template functions can be disambiguated by
03500           return type.  */
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       /* Already complained about this, so don't do so again.  */
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     /* It's OK to have a template specialization and a non-template
03547        with the same type, or to have specializations of two
03548        different templates with the same type.  Note that if one is a
03549        specialization, and the other is an instantiation of the same
03550        template, that we do not exit at this point.  That situation
03551        can occur if we instantiate a template class, and then
03552        specialize one of its methods.  This situation is valid, but
03553        the declarations must be merged in the usual way.  */
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     /* One of the declarations is a template instantiation, and the
03561        other is not a template at all.  That's OK.  */
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     /* Redeclaration of namespace alias, ignore it.  */
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     /* Prototype decl follows defn w/o prototype.  */
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     /* extern "C" int foo ();
03594        int foo () { bar (); }
03595        is OK.  */
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   /* Do not merge an implicit typedef with an explicit one.  In:
03652 
03653        class A;
03654        ...
03655        typedef class A A __attribute__ ((foo));
03656 
03657      the attribute should apply only to the typedef.  */
03658   if (TREE_CODE (olddecl) == TYPE_DECL
03659       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
03660     || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
03661     return 0;
03662 
03663   /* If new decl is `static' and an `extern' was seen previously,
03664      warn about it.  */
03665   warn_extern_redeclared_static (newdecl, olddecl);
03666 
03667   /* We have committed to returning 1 at this point.  */
03668   if (TREE_CODE (newdecl) == FUNCTION_DECL)
03669     {
03670       /* Now that functions must hold information normally held
03671    by field decls, there is extra work to do so that
03672    declaration information does not get destroyed during
03673    definition.  */
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       /* Optionally warn about more than one declaration for the same
03690          name, but don't warn about a function declaration followed by a
03691          definition.  */
03692       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
03693     && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
03694     /* Don't warn about extern decl followed by definition.  */
03695     && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
03696     /* Don't warn about friends, let add_friend take care of it.  */
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   /* Deal with C++: must preserve virtual function table size.  */
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   /* Copy all the DECL_... slots specified in the new decl
03719      except for any that we copy here from the old type.  */
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       /* If the new declaration is a definition, update the file and
03731    line information on the declaration.  */
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       /* Automatically handles default parameters.  */
03746       tree oldtype = TREE_TYPE (olddecl);
03747       tree newtype;
03748 
03749       /* Merge the data types specified in the two decls.  */
03750       newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
03751 
03752       /* If merge_types produces a non-typedef type, just use the old type.  */
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       /* Do this after calling `merge_types' so that default
03764    parameters don't confuse us.  */
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       /* Lay the type out, unless already done.  */
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       /* Merge the type qualifiers.  */
03802       if (TREE_READONLY (newdecl))
03803   TREE_READONLY (olddecl) = 1;
03804       if (TREE_THIS_VOLATILE (newdecl))
03805   TREE_THIS_VOLATILE (olddecl) = 1;
03806 
03807       /* Merge the initialization information.  */
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       /* Merge the section attribute.
03820          We want to issue an error if the sections conflict but that must be
03821    done later in decl_attributes since we are called before attributes
03822    are assigned.  */
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     /* Keep the old RTL.  */
03833     COPY_DECL_RTL (olddecl, newdecl);
03834   }
03835       else if (TREE_CODE (newdecl) == VAR_DECL 
03836          && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
03837   {
03838     /* Keep the old RTL.  We cannot keep the old RTL if the old
03839        declaration was for an incomplete object and the new
03840        declaration is not since many attributes of the RTL will
03841        change.  */
03842     COPY_DECL_RTL (olddecl, newdecl);
03843   }
03844     }
03845   /* If cannot merge, then use the new type and qualifiers,
03846      and don't preserve the old rtl.  */
03847   else
03848     {
03849       /* Clean out any memory we had of the old declaration.  */
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   /* Merge the storage class information.  */
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       /* Don't really know how much of the language-specific
03878    values we should copy from old to new.  */
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       /* Only functions have DECL_BEFRIENDING_CLASSES.  */
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     /* DECL_THUNKS is only valid for virtual functions,
03896        otherwise it is a DECL_FRIEND_CONTEXT.  */
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     /* If newdecl is not a specialization, then it is not a
03908        template-related function at all.  And that means that we
03909        shoud have exited above, returning 0.  */
03910     my_friendly_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl),
03911             0);
03912 
03913     if (TREE_USED (olddecl))
03914       /* From [temp.expl.spec]:
03915 
03916          If a template, a member template or the member of a class
03917          template is explicitly specialized then that
03918          specialization shall be declared before the first use of
03919          that specialization that would cause an implicit
03920          instantiation to take place, in every translation unit in
03921          which such a use occurs.  */
03922       error ("explicit specialization of %D after first use",
03923           olddecl);
03924 
03925     SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
03926 
03927     /* [temp.expl.spec/14] We don't inline explicit specialization
03928        just because the primary template says so.  */
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     /* If either decl says `inline', this fn is inline, unless 
03938        its definition was passed already.  */
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       /* Preserve abstractness on cloned [cd]tors.  */
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     /* These need to be copied so that the names are available.
03959        Note that if the types do match, we'll preserve inline
03960        info and other bits, but if not, we won't.  */
03961     DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
03962     DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
03963   }
03964       if (new_defines_function)
03965   /* If defining a function declared with other language
03966      linkage, use the previously declared language linkage.  */
03967   SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
03968       else if (types_match)
03969   {
03970     /* If redeclaring a builtin function, and not a definition,
03971        it stays built in.  */
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         /* If we're keeping the built-in definition, keep the rtl,
03977      regardless of declaration matches.  */
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     /* Don't clear out the arguments if we're redefining a function.  */
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   /* Now preserve various other info from the definition.  */
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     /* If newdecl is a template instantiation, it is possible that
04011        the following sequence of events has occurred:
04012 
04013        o A friend function was declared in a class template.  The
04014        class template was instantiated.
04015 
04016        o The instantiation of the friend declaration was
04017        recorded on the instantiation list, and is newdecl.
04018 
04019        o Later, however, instantiate_class_template called pushdecl
04020        on the newdecl to perform name injection.  But, pushdecl in
04021        turn called duplicate_decls when it discovered that another
04022        declaration of a global function with the same name already
04023        existed.
04024 
04025        o Here, in duplicate_decls, we decided to clobber newdecl.
04026 
04027        If we're going to do that, we'd better make sure that
04028        olddecl, and not newdecl, is on the list of
04029        instantiations so that if we try to do the instantiation
04030        again we won't get the clobbered declaration.  */
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   /* NEWDECL contains the merged attribute lists.
04053      Update OLDDECL to be the same.  */
04054   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
04055 
04056   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
04057      so that encode_section_info has a chance to look at the new decl
04058      flags and attributes.  */
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 /* Record a decl-node X as belonging to the current lexical scope.
04069    Check for errors (such as an incompatible declaration for the same
04070    name already seen in the same scope).
04071 
04072    Returns either X or an old decl for the same name.
04073    If an old decl is returned, it may have been smashed
04074    to agree with what X says.  */
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   /* We shouldn't be calling pushdecl when we're generating RTL for a
04087      function that we already did semantic analysis on previously.  */
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     /* Template parameters have no context; they are not X::T even
04095        when declared within a class or namespace.  */
04096     ;
04097   else
04098     {
04099       if (current_function_decl && x != current_function_decl
04100     /* A local declaration for a function doesn't constitute
04101              nesting.  */
04102     && !(TREE_CODE (x) == FUNCTION_DECL && !DECL_INITIAL (x))
04103     /* A local declaration for an `extern' variable is in the
04104        scope of the current namespace, not the current
04105        function.  */
04106     && !(TREE_CODE (x) == VAR_DECL && DECL_EXTERNAL (x))
04107     && !DECL_CONTEXT (x))
04108   DECL_CONTEXT (x) = current_function_decl;
04109 
04110       /* If this is the declaration for a namespace-scope function,
04111    but the declaration itself is in a local scope, mark the
04112    declaration.  */
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       /* In case this decl was explicitly namespace-qualified, look it
04129    up in its namespace context.  */
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       /* [basic.link] If there is a visible declaration of an entity
04137    with linkage having the same name and type, ignoring entities
04138    declared outside the innermost enclosing namespace scope, the
04139    block scope declaration declares that same entity and
04140    receives the linkage of the previous declaration.  */
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     /* Look in block scope.  */
04146     t = IDENTIFIER_VALUE (name);
04147     /* Or in the innermost namespace.  */
04148     if (! t)
04149       t = namespace_binding (name, DECL_CONTEXT (x));
04150     /* Does it have linkage?  Note that if this isn't a DECL, it's an
04151        OVERLOAD, which is OK.  */
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       /* If we are declaring a function, and the result of name-lookup
04159    was an OVERLOAD, look for an overloaded instance that is
04160    actually the same as the function we are declaring.  (If
04161    there is one, we have to merge our declaration with the
04162    previous declaration.)  */
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       /* Just choose one.  */
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     /* error_mark_node is 0 for a while during initialization!  */
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     /* The standard only says that the local extern
04195        inherits linkage from the previous decl; in
04196        particular, default args are not shared.  It would
04197        be nice to propagate inlining info, though.  FIXME.  */
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     /* This is probaby caused by too many errors, but calling
04204        abort will say that if errors have occurred.  */
04205     abort ();
04206 
04207         /* Check for duplicate params.  */
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       /* Don't do anything just yet.  */;
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         /* Throw away the redeclaration.  */
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         /* A redeclaration of main, but not a duplicate of the
04241      previous one.
04242 
04243      [basic.start.main]
04244 
04245            This function shall not be overloaded.  */
04246         cp_error_at ("invalid redeclaration of `%D'", t);
04247         error ("as `%D'", x);
04248         /* We don't try to push this declaration since that
04249      causes a crash.  */
04250         POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, x);
04251       }
04252   }
04253 
04254       check_template_shadow (x);
04255 
04256       /* If this is a function conjured up by the backend, massage it
04257    so it looks friendly.  */
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       /* We do not need to create a binding for this name;
04271          push_overloaded_decl will have already done so if
04272          necessary.  */
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       /* If declaring a type as a typedef, copy the type (unless we're
04284    at line 0), and install this TYPE_DECL as the new type's typedef
04285    name.  See the extensive comment in ../c-decl.c (pushdecl).  */
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        /* We don't want to copy the type when all we're
04296           doing is making a TYPE_DECL for the purposes of
04297           inlining.  */
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       /* Multiple external decls of the same identifier ought to match.
04317 
04318    We get warnings about inline functions where they are defined.
04319    We get warnings about other functions from push_overloaded_decl.
04320 
04321    Avoid duplicate warnings where they are used.  */
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         /* If different sort of thing, we already gave an error.  */
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       /* This name is new in its binding level.
04342    Install the new declaration and return it.  */
04343       if (namespace_bindings_p ())
04344   {
04345     /* Install a global value.  */
04346 
04347     /* If the first global decl has external linkage,
04348        warn if we later see static one.  */
04349     if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
04350       TREE_PUBLIC (name) = 1;
04351 
04352     /* Bind the name for the entity.  */
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     /* Don't forget if the function was used via an implicit decl.  */
04363     if (IDENTIFIER_IMPLICIT_DECL (name)
04364         && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
04365       TREE_USED (x) = 1;
04366 
04367     /* Don't forget if its address was taken in that way.  */
04368     if (IDENTIFIER_IMPLICIT_DECL (name)
04369         && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
04370       TREE_ADDRESSABLE (x) = 1;
04371 
04372     /* Warn about mismatches against previous implicit decl.  */
04373     if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
04374         /* If this real decl matches the implicit, don't complain.  */
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     /* If new decl is `static' and an `extern' was seen previously,
04381        warn about it.  */
04382     if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
04383       warn_extern_redeclared_static (x, t);
04384   }
04385       else
04386   {
04387     /* Here to install a non-global value.  */
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         /* Because push_local_binding will hook X on to the
04395      current_binding_level's name list, we don't want to
04396      do that again below.  */
04397         need_new_binding = 0;
04398       }
04399 
04400     /* If this is a TYPE_DECL, push it into the type value slot.  */
04401     if (TREE_CODE (x) == TYPE_DECL)
04402       set_identifier_type_value_with_scope (name, TREE_TYPE (x),
04403               current_binding_level);
04404 
04405     /* Clear out any TYPE_DECL shadowed by a namespace so that
04406        we won't think this is a type.  The C struct hack doesn't
04407        go through namespaces.  */
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     /* If this is an extern function declaration, see if we
04426        have a global definition or declaration for the function.  */
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         /* We have one.  Their types must agree.  */
04434         if (decls_match (x, oldglobal))
04435     /* OK */;
04436         else
04437     {
04438       warning ("extern declaration of `%#D' doesn't match", x);
04439       cp_warning_at ("global declaration `%#D'", oldglobal);
04440     }
04441       }
04442     /* If we have a local external declaration,
04443        and no file-scope declaration has yet been seen,
04444        then if we later have a file-scope decl it must not be static.  */
04445     if (oldlocal == NULL_TREE
04446         && oldglobal == NULL_TREE
04447         && DECL_EXTERNAL (x)
04448         && TREE_PUBLIC (x))
04449       TREE_PUBLIC (name) = 1;
04450 
04451     /* Warn if shadowing an argument at the top level of the body.  */
04452     if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
04453         /* Inline decls shadow nothing.  */
04454         && !DECL_FROM_INLINE (x)
04455         && TREE_CODE (oldlocal) == PARM_DECL
04456         /* Don't check the `this' parameter.  */
04457         && !DECL_ARTIFICIAL (oldlocal))
04458       {
04459         bool err = false;
04460 
04461         /* Don't complain if it's from an enclosing function.  */
04462         if (DECL_CONTEXT (oldlocal) == current_function_decl
04463       && TREE_CODE (x) != PARM_DECL)
04464     {
04465       /* Go to where the parms should be and see if we find
04466          them there.  */
04467       struct cp_binding_level *b = current_binding_level->level_chain;
04468 
04469       /* ARM $8.3 */
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     /* Maybe warn if shadowing something else.  */
04483     else if (warn_shadow && !DECL_EXTERNAL (x)
04484         /* No shadow warnings for internally generated vars.  */
04485         && ! DECL_ARTIFICIAL (x)
04486         /* No shadow warnings for vars made for inlining.  */
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     /* XXX shadow warnings in outer-more namespaces */
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 /* Same as pushdecl, but define X in binding-level LEVEL.  We rely on the
04521    caller to set DECL_CONTEXT properly.  */
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 /* Like pushdecl, only it places X in the current namespace,
04553    if appropriate.  */
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   /* Now, the type_shadowed stack may screw us.  Munge it so it does
04566      what we want.  */
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     /* Can't break out of the loop here because sometimes
04580        a binding level will have duplicate bindings for
04581        PT names.  It's gross, but I haven't time to fix it.  */
04582               }
04583         }
04584       newval = TREE_TYPE (x);
04585       if (ptr == (tree *)0)
04586         {
04587           /* @@ This shouldn't be needed.  My test case "zstring.cc" trips
04588              up here if this is changed to an assertion.  --KR  */
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 /* Like pushdecl, only it places X in the global scope if appropriate.
04600    Calls cp_finish_decl to register the variable, initializing it with
04601    *INIT, if INIT is non-NULL.  */
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 /* Like pushdecl, only it places X in the global scope if appropriate.  */
04616 
04617 tree
04618 pushdecl_top_level (tree x)
04619 {
04620   return pushdecl_top_level_1 (x, NULL);
04621 }
04622 
04623 /* Like pushdecl, only it places X in the global scope if
04624    appropriate.  Calls cp_finish_decl to register the variable,
04625    initializing it with INIT.  */
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 /* Make the declaration of X appear in CLASS scope.  */
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   /* Get the name of X.  */
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       /* If X is an anonymous aggregate, all of its members are
04658    treated as if they were members of the class containing the
04659    aggregate, for naming purposes.  */
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 /* Enter DECL into the symbol table, if that's appropriate.  Returns
04676    DECL, or a modified version thereof.  */
04677 
04678 tree
04679 maybe_push_decl (decl)
04680      tree decl;
04681 {
04682   tree type = TREE_TYPE (decl);
04683 
04684   /* Add this decl to the current binding level, but not if it comes
04685      from another scope, e.g. a static member variable.  TEM may equal
04686      DECL or it may be a previous decl of the same name.  */
04687   if (decl == error_mark_node
04688       || (TREE_CODE (decl) != PARM_DECL
04689     && DECL_CONTEXT (decl) != NULL_TREE
04690     /* Definitions of namespace members outside their namespace are
04691        possible.  */
04692     && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL)
04693       || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ())
04694       || TREE_CODE (type) == UNKNOWN_TYPE
04695       /* The declaration of a template specialization does not affect
04696    the functions available for overload resolution, so we do not
04697    call pushdecl.  */
04698       || (TREE_CODE (decl) == FUNCTION_DECL
04699     && DECL_TEMPLATE_SPECIALIZATION (decl)))
04700     return decl;
04701   else
04702     return pushdecl (decl);
04703 }
04704 
04705 /* Make the declaration(s) of X appear in CLASS scope under the name
04706    NAME.  Returns true if the binding is valid.  */
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   /* The class_binding_level will be NULL if x is a template
04715      parameter name in a member template.  */
04716   if (!class_binding_level)
04717     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
04718 
04719   /* Make sure that this new member does not have the same name
04720      as a template parameter.  */
04721   if (TYPE_BEING_DEFINED (current_class_type))
04722     check_template_shadow (x);
04723 
04724   /* If this declaration shadows a declaration from an enclosing
04725      class, then we will need to restore IDENTIFIER_CLASS_VALUE when
04726      we leave this class.  Record the shadowed declaration here.  */
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       /* If the old binding was from a base class, and was for a tag
04738    name, slide it over to make room for the new binding.  The
04739    old binding is still visible if explicitly qualified with a
04740    class-key.  */
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       /* Find the previous binding of name on the class-shadowed
04756          list, and update it.  */
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   /* If we didn't replace an existing binding, put the binding on the
04772      stack of bindings for the identifier, and update the shadowed list.  */
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       /* Record the value we are binding NAME to so that we can know
04779    what to pop later.  */
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 /* Insert another USING_DECL into the current binding level, returning
04788    this declaration. If this is a redeclaration, do nothing, and
04789    return NULL_TREE if this not in namespace scope (in namespace
04790    scope, a using decl might extend any previous bindings).  */
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 /* Add namespace to using_directives. Return NULL_TREE if nothing was
04817    changed (i.e. there was already a directive), or the fresh
04818    TREE_LIST otherwise.  */
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   /* Check if we already have this.  */
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   /* Recursively add all namespaces used.  */
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 /* DECL is a FUNCTION_DECL for a non-member function, which may have
04846    other definitions already in place.  We get around this by making
04847    the value of the identifier point to a list of all the things that
04848    want to be referenced by that name.  It is then up to the users of
04849    that name to decide what to do with that list.
04850 
04851    DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its
04852    DECL_TEMPLATE_RESULT.  It is dealt with the same way.
04853 
04854    FLAGS is a bitwise-or of the following values:
04855      PUSH_LOCAL: Bind DECL in the current scope, rather than at
04856                  namespace scope.
04857      PUSH_USING: DECL is being pushed as the result of a using
04858                  declaration.
04859 
04860    The value returned may be a previous declaration if we guessed wrong
04861    about what language DECL should belong to (C or C++).  Otherwise,
04862    it's always DECL (and never something that's not a _DECL).  */
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   /* Ignore the undefined symbol marker.  */
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     /* NAME is not ambiguous.  */
04933     new_binding = decl;
04934 
04935   if (doing_global)
04936     set_namespace_binding (name, current_namespace, new_binding);
04937   else
04938     {
04939       /* We only create an OVERLOAD if there was a previous binding at
04940    this level, or if decl is a template. In the former case, we
04941    need to remove the old binding and replace it with the new
04942    binding.  We must also run through the NAMES on the binding
04943    level where the name was bound to update the chain.  */
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       /* Just replace the old binding with the new.  */
04958       TREE_VALUE (*d) = new_binding;
04959     else
04960       /* Build a TREE_LIST to wrap the OVERLOAD.  */
04961       *d = tree_cons (NULL_TREE, new_binding,
04962           TREE_CHAIN (*d));
04963 
04964     /* And update the cxx_binding node.  */
04965     BINDING_VALUE (IDENTIFIER_BINDING (name))
04966       = new_binding;
04967     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
04968         }
04969 
04970     /* We should always find a previous binding in this case.  */
04971     abort ();
04972   }
04973 
04974       /* Install the new binding.  */
04975       push_local_binding (name, new_binding, flags);
04976     }
04977 
04978   POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
04979 }
04980 
04981 /* Generate an implicit declaration for identifier FUNCTIONID
04982    as a function of type int ().  Print a warning if appropriate.  */
04983 
04984 tree
04985 implicitly_declare (functionid)
04986      tree functionid;
04987 {
04988   register tree decl;
04989 
04990   /* We used to reuse an old implicit decl here,
04991      but this loses with inline functions because it can clobber
04992      the saved decl chains.  */
04993   decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
04994 
04995   DECL_EXTERNAL (decl) = 1;
04996   TREE_PUBLIC (decl) = 1;
04997 
04998   /* ISO standard says implicit declarations are in the innermost block.
04999      So we record the decl in the standard fashion.  */
05000   pushdecl (decl);
05001   rest_of_decl_compilation (decl, NULL, 0, 0);
05002 
05003   if (warn_implicit
05004       /* Only one warning per identifier.  */
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 /* Return zero if the declaration NEWDECL is valid
05016    when the declaration OLDDECL (assumed to be for the same name)
05017    has already been seen.
05018    Otherwise return an error message format string with a %s
05019    where the identifier should go.  */
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       /* Because C++ can put things into name space for free,
05028    constructs like "typedef struct foo { ... } foo"
05029    would look like an erroneous redeclaration.  */
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       /* If this is a pure function, its olddecl will actually be
05038    the original initialization to `0' (which we force to call
05039    abort()).  Don't complain about redefinition in this case.  */
05040       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl))
05041   return 0;
05042 
05043       /* If both functions come from different namespaces, this is not
05044    a redeclaration - this is a conflict with a used function.  */
05045       if (DECL_NAMESPACE_SCOPE_P (olddecl)
05046     && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl))
05047   return "`%D' conflicts with used function";
05048 
05049       /* We'll complain about linkage mismatches in
05050          warn_extern_redeclared_static.  */
05051 
05052       /* Defining the same name twice is no good.  */
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       /* Objects declared at top level:  */
05079       /* If at least one is a reference, it's ok.  */
05080       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
05081   return 0;
05082       /* Reject two definitions.  */
05083       return "redefinition of `%#D'";
05084     }
05085   else
05086     {
05087       /* Objects declared with block scope:  */
05088       /* Reject two definitions, and reject a definition
05089    together with an external reference.  */
05090       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
05091   return "redeclaration of `%#D'";
05092       return 0;
05093     }
05094 }
05095 
05096 /* Create a new label, named ID.  */
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     /* Make sure every label has an rtx.  */
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   /* Say where one reference is to the label, for the sake of the
05115      error if it is not defined.  */
05116   DECL_SOURCE_LINE (decl) = lineno;
05117   DECL_SOURCE_FILE (decl) = input_filename;
05118 
05119   /* Record the fact that this identifier is bound to this label.  */
05120   SET_IDENTIFIER_LABEL_VALUE (id, decl);
05121 
05122   return decl;
05123 }
05124 
05125 /* Record this label on the list of used labels so that we can check
05126    at the end of the function to see whether or not the label was
05127    actually defined, and so we can check when the label is defined whether
05128    this use is valid.  */
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 /* Look for a label named ID in the current function.  If one cannot
05152    be found, create one.  (We keep track of used, but undefined,
05153    labels, and complain about them at the end of a function.)  */
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   /* You can't use labels at global scope.  */
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   /* See if we've already got this label.  */
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   /* Record this label on the list of labels used in this function.
05178      We do this before calling make_label_decl so that we get the
05179      IDENTIFIER_LABEL_VALUE before the new label is declared.  */
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   /* We need a new label.  */
05187   decl = make_label_decl (id, /*local_p=*/0);
05188 
05189   /* Now fill in the information we didn't have before.  */
05190   ent->label_decl = decl;
05191 
05192   POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, decl);
05193 }
05194 
05195 /* Declare a local label named ID.  */
05196 
05197 tree
05198 declare_local_label (id)
05199      tree id;
05200 {
05201   tree decl;
05202 
05203   /* Add a new entry to the SHADOWED_LABELS list so that when we leave
05204      this scope we can restore the old value of
05205      IDENTIFIER_TYPE_VALUE.  */
05206   current_binding_level->shadowed_labels
05207     = tree_cons (IDENTIFIER_LABEL_VALUE (id), NULL_TREE,
05208      current_binding_level->shadowed_labels);
05209   /* Look for the label.  */
05210   decl = make_label_decl (id, /*local_p=*/1);
05211   /* Now fill in the information we didn't have before.  */
05212   TREE_VALUE (current_binding_level->shadowed_labels) = decl;
05213 
05214   return decl;
05215 }
05216 
05217 /* Returns nonzero if it is ill-formed to jump past the declaration of
05218    DECL.  Returns 2 if it's also a real problem.  */
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   /* This is really only important if we're crossing an initialization.
05232      The POD stuff is just pedantry; why should it matter if the class
05233      contains a field of pointer to member type?  */
05234   if (DECL_INITIAL (decl)
05235       || (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))
05236     return 2;
05237   return 1;
05238 }
05239 
05240 /* Check that a single previously seen jump to a newly defined label
05241    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
05242    the jump context; NAMES are the names in scope in LEVEL at the jump
05243    context; FILE and LINE are the source position of the jump or 0.  */
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 /* Check that any previously seen jumps to a newly defined label DECL
05328    are OK.  Called by define_label.  */
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 /* Check that a new jump to a label DECL is OK.  Called by
05353    finish_goto_stmt.  */
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   /* We can't know where a computed goto is jumping.  So we assume
05364      that it's OK.  */
05365   if (! DECL_P (decl))
05366     return;
05367 
05368   /* If the label hasn't been defined yet, defer checking.  */
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   /* If the label is not on named_labels it's a gcc local label, so
05380      it must be in an outer scope, so jumping to it is always OK.  */
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   /* Can't skip init of __exception_info.  */
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 /* Define a label, specifying the location in the source file.
05413    Return the LABEL_DECL node for the label.  */
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   /* After labels, make any new cleanups in the function go into their
05432      own new (temporary) binding contour.  */
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       /* Mark label as having been defined.  */
05444       DECL_INITIAL (decl) = error_mark_node;
05445       /* Say where in the source.  */
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   /* The SWITCH_STMT being built.  */
05465   tree switch_stmt;
05466   /* A splay-tree mapping the low element of a case range to the high
05467      element, or NULL_TREE if there is no high element.  Used to
05468      determine whether or not a new case label duplicates an old case
05469      label.  We need a tree, rather than simply a hash table, because
05470      of the GNU case range extension.  */
05471   splay_tree cases;
05472 };
05473 
05474 /* A stack of the currently active switch statements.  The innermost
05475    switch statement is on the top of the stack.  There is no need to
05476    mark the stack for garbage collection because it is only active
05477    during the processing of the body of a function, and we never
05478    collect at that point.  */
05479 
05480 static struct cp_switch *switch_stack;
05481 
05482 /* Called right after a switch-statement condition is parsed.
05483    SWITCH_STMT is the switch statement being parsed.  */
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 /* Note that we've seen a definition of a case label, and complain if this
05510    is a bad place for one.  */
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       /* For templates, just add the case label; we'll do semantic
05537    analysis at instantiation-time.  */
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   /* Find the condition on which this switch statement depends.  */
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   /* After labels, make any new cleanups in the function go into their
05554      own new (temporary) binding contour.  */
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 /* Return the list of declarations of the current level.
05562    Note that this list is in reverse order unless/until
05563    you nreverse it; and when you do nreverse it, you must
05564    store the result back using `storedecls' or you will lose.  */
05565 
05566 tree
05567 getdecls ()
05568 {
05569   return current_binding_level->names;
05570 }
05571 
05572 /* Store the list of declarations of the current level.
05573    This is done for the parameter declarations of a function being defined,
05574    after they are modified in the light of any missing parameters.  */
05575 
05576 static void
05577 storedecls (decls)
05578      tree decls;
05579 {
05580   current_binding_level->names = decls;
05581 }
05582 
05583 /* Set the current binding TABLE for type declarations..  This is a
05584    temporary workaround of the fact that the data structure classtypes
05585    does not currently carry its allocated cxx_scope structure.  */
05586 void
05587 cxx_remember_type_decls (binding_table table)
05588 {
05589   current_binding_level->type_decls = table;
05590 }
05591 
05592 
05593 /* Return the type that should be used when TYPE's name is preceded
05594    by a tag such as 'struct' or 'union', or null if the name cannot
05595    be used in this way.
05596 
05597    For example, when processing the third line of:
05598 
05599   struct A;
05600   typedef struct A A;
05601   struct A;
05602 
05603    lookup of A will find the typedef.  Given A's typedef, this function
05604    will return the type associated with "struct A".  For the tag to be
05605    anything other than TYPE, TYPE must be a typedef whose original type
05606    has the same name and context as TYPE itself.
05607 
05608    It is not valid for a typedef of an anonymous type to be used with
05609    an explicit tag:
05610 
05611        typedef struct { ... } B;
05612        struct B;
05613 
05614    Return null for this case.  */
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 /* Given NAME, an IDENTIFIER_NODE,
05635    return the structure (or union or enum) definition for that name.
05636    Searches binding levels from BINDING_LEVEL up to the global level.
05637    If THISLEVEL_ONLY is nonzero, searches only the specified context
05638    (but skips any tag-transparent contexts to find one that is
05639    meaningful for tags).
05640    FORM says which kind of type the caller wants;
05641    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
05642    If the wrong kind of type is found, and it's not a template, an error is
05643    reported.  */
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   /* Nonzero if, we should look past a template parameter level, even
05654      if THISLEVEL_ONLY.  */
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           /* There's no need for error checking here, because
05667              anon names are unique throughout the compilation.  */
05668           if (type != NULL)
05669             POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, type);
05670         }
05671       else if (level->namespace_p)
05672   /* Do namespace lookup.  */
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       /* If we just skipped past a template parameter level,
05680          even though THISLEVEL_ONLY, and we find a template
05681          class declaration, then we use the _TYPE node for the
05682          template.  See the example below.  */
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     /* We've found something at this binding level.  If it is
05695        a typedef, extract the tag it refers to.  Lookup fails
05696        if the typedef doesn't refer to a taggable type.  */
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                   /* Definition isn't the kind we were looking for.  */
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         /* We must deal with cases like this:
05734 
05735              template <class T> struct S;
05736        template <class T> struct S {};
05737 
05738      When looking up `S', for the second declaration, we
05739      would like to find the first declaration.  But, we
05740      are in the pseudo-global level created for the
05741      template parameters, rather than the (surrounding)
05742      namespace level.  Thus, we keep going one more level,
05743      even though THISLEVEL_ONLY is nonzero.  */
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 /* Given a type, find the tag that was defined for it and return the tag name.
05764    Otherwise return 0.  However, the value can never be 0
05765    in the cases in which this is used.
05766 
05767    C++: If NAME is nonzero, this is the new name to install.  This is
05768    done when replacing anonymous tags with real tag names.  */
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 /* Look up NAME in the NAMESPACE.  */
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     /* This happens for A::B<int> when B is a namespace.  */
05806     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, name);
05807   else if (TREE_CODE (name) == TEMPLATE_DECL)
05808     {
05809       /* This happens for A::B where B is a template, and there are no
05810    template arguments.  */
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            /*in_decl=*/NULL_TREE,
05843            /*context=*/NULL_TREE,
05844            /*entering_scope=*/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       /* If we have a single function from a using decl, pull it out.  */
05859       if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val))
05860   val = OVL_FUNCTION (val);
05861 
05862       /* Ignore built-in functions that haven't been prototyped yet.  */
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 /* Hash a TYPENAME_TYPE.  K is really of type `tree'.  */
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 /* Compare two TYPENAME_TYPEs.  K1 and K2 are really of type `tree'.  */
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 /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
05914    the type of `T', NAME is the IDENTIFIER_NODE for `t'.  If BASE_TYPE
05915    is non-NULL, this type is being created by the implicit typename
05916    extension, and BASE_TYPE is a type named `t' in some base class of
05917    `T' which depends on template parameters.
05918 
05919    Returns the new TYPENAME_TYPE.  */
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   /* Build the TYPENAME_TYPE.  */
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   /* Build the corresponding TYPE_DECL.  */
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   /* See if we already have this type.  */
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 /* Resolve `typename CONTEXT::NAME'.  Returns an appropriate type,
05964    unless an error occurs, in which case error_mark_node is returned.
05965    If we locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is
05966    set, we return that, rather than the _TYPE it corresponds to, in
05967    other cases we look through the type decl.  If TF_ERROR is set,
05968    complain about errors, otherwise be quiet.  */
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   /* Create a TEMPLATE_ID_EXPR for the type.  */
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       /* We can get here from typename_sub0 in the explicit_template_type
06011    expansion.  Just fail.  */
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           /*entering_scope=*/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       /* Lookup found an implicit typename that we had
06082          injected into the current scope. Doing things
06083          properly would have located the exact same type,
06084          so there is no error here.  We must remove the
06085          implicitness so that we do not warn about it.  */
06086       t = copy_node (t);
06087       TREE_TYPE (t) = NULL_TREE;
06088     }
06089         
06090         return t;
06091       }
06092   }
06093     }
06094 
06095   /* If the CONTEXT is not a template type, then either the field is
06096      there now or its never going to be.  */
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 /* Resolve `CONTEXT::template NAME'.  Returns an appropriate type,
06108    unless an error occurs, in which case error_mark_node is returned.
06109    If we locate a TYPE_DECL, we return that, rather than the _TYPE it
06110    corresponds to.  If COMPLAIN zero, don't complain about any errors
06111    that occur.  */
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   /* Build the UNBOUND_CLASS_TEMPLATE.  */
06155   t = make_aggr_type (UNBOUND_CLASS_TEMPLATE);
06156   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
06157   TREE_TYPE (t) = NULL_TREE;
06158 
06159   /* Build the corresponding TEMPLATE_DECL.  */
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 /* Select the right _DECL from multiple choices.  */
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       /* We are not interested in types.  */
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   /* If we could have a type and
06189      we have nothing or we need a type and have none.  */
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   /* Don't return non-types if we really prefer types.  */
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 /* Unscoped lookup of a global: iterate over current namespaces,
06204    considering using-directives.  If SPACESP is non-NULL, store a list
06205    of the namespaces we've considered in it.  */
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       /* Ignore anticipated built-in functions.  */
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         /* Keep binding cleared.  */;
06237       else if (b)
06238         {
06239           /* Initialize binding for this context.  */
06240           binding.value = BINDING_VALUE (b);
06241           binding.type = BINDING_TYPE (b);
06242         }
06243 
06244       /* Add all _DECLs seen through local using-directives.  */
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     /* Give up because of error.  */
06251     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
06252 
06253       /* Add all _DECLs seen through global using-directives.  */
06254       /* XXX local and global using lists should work equally.  */
06255       siter = initial;
06256       while (1)
06257   {
06258     if (!lookup_using_namespace (name, &binding,
06259                                        DECL_NAMESPACE_USING (siter),
06260                scope, flags, spacesp))
06261       /* Give up because of error.  */
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 /* Combine prefer_type and namespaces_only into flags.  */
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 /* Given a lookup that returned VAL, use FLAGS to decide if we want to
06290    ignore it or not.  Subroutine of lookup_name_real.  */
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 /* Any other BINDING overrides an implicit TYPENAME.  Warn about
06312    that.  */
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 /* Check to see whether or not DECL is a variable that would have been
06339    in scope under the ARM, but is not in scope under the ANSI/ISO
06340    standard.  If so, issue an error message.  If name lookup would
06341    work in both cases, but return a different result, this function
06342    returns the result of ANSI/ISO lookup.  Otherwise, it returns
06343    DECL.  */
06344 
06345 tree
06346 check_for_out_of_scope_variable (tree decl)
06347 {
06348   tree shadowed;
06349 
06350   /* We only care about out of scope variables.  */
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   /* If we have already complained about this declaration, there's no
06375      need to do it again.  */
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 /* Look up NAME in the current binding level and its superiors in the
06398    namespace of variables, functions and typedefs.  Return a ..._DECL
06399    node of some kind representing its definition if there is only one
06400    such declaration, or return a TREE_LIST with all the overloaded
06401    definitions if there are many, or return 0 if it is undefined.
06402 
06403    If PREFER_TYPE is > 0, we prefer TYPE_DECLs or namespaces.
06404    If PREFER_TYPE is > 1, we reject non-type decls (e.g. namespaces).
06405    If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
06406    Otherwise we prefer non-TYPE_DECLs.
06407 
06408    If NONCLASS is nonzero, we don't look for the NAME in class scope,
06409    using IDENTIFIER_CLASS_VALUE.  */
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   /* Hack: copy flag set by parser, if set.  */
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       /* If the next thing is '<', class templates are types.  */
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       /* Someone else will give an error about this if needed.  */
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         /* Restore the containing TYPENAME_TYPE if we looked
06484      through it before.  */
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       /* If we're not parsing, we need to complain.  */
06512       flags |= LOOKUP_COMPLAIN;
06513     }
06514 
06515   /* Conversion operators are handled specially because ordinary
06516      unqualified name lookup will not find template conversion
06517      operators.  */
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     /* A conversion operator can only be declared in a class 
06530        scope.  */
06531     if (level->parm_flag != 2)
06532       continue;
06533     
06534     /* Lookup the conversion operator in the class.  */
06535     class_type = level->this_class;
06536     operators = lookup_fnfields (class_type, name, /*protect=*/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   /* First, look in non-namespace scopes.  */
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   /* We're not looking for class-scoped bindings, so keep going.  */
06555   continue;
06556 
06557       /* If this is the kind of thing we're looking for, we're done.  */
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       /* Handle access control on types from enclosing or base classes.  */
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   /* The name might be from an enclosing class of the current scope.  */
06585   if (!val && !nonclass && current_class_type)
06586     val = qualify_lookup (lookup_nested_field (name, !yylex), flags);
06587 
06588   /* Now lookup in namespace scopes.  */
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       /* This should only warn about types used in qualified-ids.  */
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     /* We don't change val to from_obj if got_object depends on
06615        template parms because that breaks implicit typename for
06616        destructor calls.  */
06617     if (! uses_template_parms (got_object))
06618       val = from_obj;
06619   }
06620 
06621       /* If we have a single function from a using decl, pull it out.  */
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   /* type-or-namespace, nonclass, namespace_only */
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 /* Similar to `lookup_name' but look only in the innermost non-class
06663    binding level.  */
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       /* extern "C" function() */
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 /* Like lookup_name_current_level, but for types.  */
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 /* Push the declarations of builtin types into the namespace.
06748    RID_INDEX is the index of the builtin type
06749    in the array RID_POINTERS.  NAME is the name used when looking
06750    up the builtin type.  TYPE is the _TYPE node for the builtin type.  */
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   /* Built-in types live in the global namespace.  */
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 /* Record one of the standard Java types.
06792  * Declare it as having the given NAME.
06793  * If SIZE > 0, it is the size of one of the integral types;
06794  * otherwise it is the negative of the size of one of the other types.  */
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     { /* "__java_char" or ""__java_boolean".  */
06806       type = make_unsigned_type (-size);
06807       /*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/
06808     }
06809   else
06810     { /* "__java_float" or ""__java_double".  */
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   /* Suppress generate debug symbol entries for these types,
06819      since for normal C++ they are just clutter.
06820      However, push_lang_context undoes this if extern "Java" is seen.  */
06821   DECL_IGNORED_P (decl) = 1;
06822 
06823   TYPE_FOR_JAVA (type) = 1;
06824   return type;
06825 }
06826 
06827 /* Push a type into the namespace so that the back-ends ignore it.  */
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   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
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 /* An string for which we should create an IDENTIFIER_NODE at
06845    startup.  */
06846 
06847 typedef struct predefined_identifier
06848 {
06849   /* The name of the identifier.  */
06850   const char *const name;
06851   /* The place where the IDENTIFIER_NODE should be stored.  */
06852   tree *const node;
06853   /* Nonzero if this is the name of a constructor or destructor.  */
06854   const int ctor_or_dtor_p;
06855 } predefined_identifier;
06856 
06857 /* Create all the predefined identifiers.  */
06858 
06859 static void
06860 initialize_predefined_identifiers ()
06861 {
06862   const predefined_identifier *pid;
06863 
06864   /* A table of identifiers to create at startup.  */
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 /* Create the predefined scalar types of C,
06896    and some nodes representing standard constants (0, 1, (void *)0).
06897    Initialize the global binding level.
06898    Make definitions for built-in primitive functions.  */
06899 
06900 void
06901 cxx_init_decl_processing ()
06902 {
06903   tree void_ftype;
06904   tree void_ftype_ptr;
06905 
06906   /* Create all the identifiers we need.  */
06907   initialize_predefined_identifiers ();
06908 
06909   /* Fill in back-end hooks.  */
06910   lang_missing_noreturn_ok_p = &cp_missing_noreturn_ok_p;
06911 
06912   /* Create the global variables.  */
06913   push_to_top_level ();
06914 
06915   /* Enter the global namespace.  */
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   /* Adjust various flags based on command-line settings.  */
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   /* Force minimum function alignment if using the least significant
06936      bit of function pointers to store the virtual bit.  */
06937   if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
06938       && force_align_functions_log < 1)
06939     force_align_functions_log = 1;
06940 
06941   /* Initially, C.  */
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   /* Make the binding_level structure for global names.  */
06954   pushlevel (0);
06955   current_binding_level->type_decls = binding_table_new (GLOBAL_SCOPE_HT_SIZE);
06956   /* The global level is the namespace level of ::.  */
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   /* Create the `std' namespace.  */
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   /* C++ extensions */
07015 
07016   unknown_type_node = make_node (UNKNOWN_TYPE);
07017   record_unknown_type (unknown_type_node, "unknown type");
07018 
07019   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
07020   TREE_TYPE (unknown_type_node) = unknown_type_node;
07021 
07022   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
07023      result.  */
07024   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
07025   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
07026 
07027   {
07028     /* Make sure we get a unique function type, so we can give
07029        its pointer type a name.  (This wins for gdb.) */
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   /* Now, C++.  */
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       /*attributes=*/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   /* Perform other language dependent initializations.  */
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   /* Show we use EH for cleanups.  */
07100   using_eh_for_cleanups ();
07101 
07102   /* Maintain consistency.  Perhaps we should just complain if they
07103      say -fwritable-strings?  */
07104   if (flag_writable_strings)
07105     flag_const_strings = 0;
07106 }
07107 
07108 /* Generate an initializer for a function naming variable from
07109    NAME. NAME may be NULL, in which case we generate a special
07110    ERROR_MARK node which should be replaced later.  */
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     /* We don't know the value until instantiation time. Make
07135        something which will be digested now, but replaced later.  */
07136     init = build (ERROR_MARK, type);
07137   
07138   return init;
07139 }
07140 
07141 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
07142    decl, NAME is the initialization string and TYPE_DEP indicates whether
07143    NAME depended on the type of the function. We make use of that to detect
07144    __PRETTY_FUNCTION__ inside a template fn. This is being done
07145    lazily at the point of first use, so we musn't push the decl now.  */
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   /* As we don't push the decl here, we must set the context.  */
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 /* Make a definition for a builtin function named NAME in the current
07177    namespace, whose data type is TYPE and whose context is CONTEXT.
07178    TYPE should be a function type with argument types.
07179 
07180    CLASS and CODE tell later passes how to compile calls to this function.
07181    See tree.h for possible values.
07182 
07183    If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME,
07184    the name to be called if we can't opencode the function.
07185    If ATTRS is nonzero, use that for the function's attribute
07186    list.  */
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   /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
07206      we cannot change DECL_ASSEMBLER_NAME until we have installed this
07207      function in the namespace.  */
07208   if (libname)
07209     SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
07210   make_decl_rtl (decl, NULL);
07211 
07212   /* Warn if a function in the namespace for users
07213      is used without an occasion to consider it declared.  */
07214   if (name[0] != '_' || name[1] != '_')
07215     DECL_ANTICIPATED (decl) = 1;
07216 
07217   /* Possibly apply some default attributes to this built-in function.  */
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 /* Entry point for the benefit of c_common_nodes_and_builtins.
07227 
07228    Make a defintion for a builtin function named NAME and whose data type
07229    is TYPE.  TYPE should be a function type with argument types.  This
07230    function places the anticipated declaration in the global namespace
07231    and additionally in the std namespace if appropriate.
07232 
07233    CLASS and CODE tell later passes how to compile calls to this function.
07234    See tree.h for possible values.
07235 
07236    If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME,
07237    the name to be called if we can't opencode the function.
07238 
07239    If ATTRS is nonzero, use that for the function's attribute
07240    list.  */
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   /* All builtins that don't begin with an '_' should additionally
07252      go in the 'std' namespace.  */
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 /* Generate a FUNCTION_DECL with the typical flags for a runtime library
07265    function.  Not called directly.  */
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 /* Returns the _DECL for a library function with C linkage.
07284    We assume that such functions never throw; if this is incorrect,
07285    callers should unset TREE_NOTHROW.  */
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 /* Returns the _DECL for a library function with C++ linkage.  */
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 /* Like build_library_fn, but takes a C string instead of an
07312    IDENTIFIER_NODE.  */
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 /* Like build_cp_library_fn, but takes a C string instead of an
07323    IDENTIFIER_NODE.  */
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 /* Like build_library_fn, but also pushes the function so that we will
07334    be able to find it via IDENTIFIER_GLOBAL_VALUE.  */
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 /* Like build_cp_library_fn, but also pushes the function so that it
07346    will be found by normal lookup.  */
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 /* Like push_library_fn, but takes a TREE_LIST of parm types rather than
07361    a FUNCTION_TYPE.  */
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 /* Like push_library_fn, but also note that this function throws
07372    and does not return.  Used for __throw_foo and the like.  */
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 /* Apply default attributes to a function, if a system function with default
07385    attributes.  */
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 /* When we call finish_struct for an anonymous union, we create
07399    default copy constructors and such.  But, an anonymous union
07400    shouldn't have such things; this function undoes the damage to the
07401    anonymous union type T.
07402 
07403    (The reason that we create the synthesized methods is that we don't
07404    distinguish `union { int i; }' from `typedef union { int i; } U'.
07405    The first is an anonymous union; the second is just an ordinary
07406    union type.)  */
07407 
07408 void
07409 fixup_anonymous_aggr (t)
07410      tree t;
07411 {
07412   tree *q;
07413 
07414   /* Wipe out memory of synthesized methods */
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   /* Splice the implicitly generated functions out of the TYPE_METHODS
07423      list.  */
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   /* ISO C++ 9.5.3.  Anonymous unions may not have function members.  */
07434   if (TYPE_METHODS (t))
07435     cp_error_at ("an anonymous union cannot have function members", t);
07436 
07437   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
07438      assignment operators (because they cannot have these methods themselves).
07439      For anonymous unions this is already checked because they are not allowed
07440      in any union, otherwise we have to check it.  */
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 /* Make sure that a declaration with no declarator is well-formed, i.e.
07466    just defines a tagged type or anonymous union.
07467 
07468    Returns the type defined, if any.  */
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   /* Check for an