• Main Page
  • Modules
  • Data Types
  • Files

osprey/kg++fe/gnu/cp/decl.c

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