OSDN Git Service

* cp-tree.h (DECL_PARM_LEVEL): New.
[pf3gnuchains/gcc-fork.git] / gcc / cp / name-lookup.h
index 8c8b040..bfcac69 100644 (file)
@@ -1,12 +1,13 @@
 /* Declarations for C++ name lookup routines.
 /* Declarations for C++ name lookup routines.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GCC is distributed in the hope that it will be useful,
 any later version.
 
 GCC is distributed in the hope that it will be useful,
@@ -15,14 +16,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #ifndef GCC_CP_NAME_LOOKUP_H
 #define GCC_CP_NAME_LOOKUP_H
 
 
 #ifndef GCC_CP_NAME_LOOKUP_H
 #define GCC_CP_NAME_LOOKUP_H
 
-#include "c-common.h"
+#include "c-family/c-common.h"
 
 /* The type of dictionary used to map names to types declared at
    a given scope.  */
 
 /* The type of dictionary used to map names to types declared at
    a given scope.  */
@@ -32,29 +32,22 @@ typedef struct binding_entry_s *binding_entry;
 /* The type of a routine repeatedly called by binding_table_foreach.  */
 typedef void (*bt_foreach_proc) (binding_entry, void *);
 
 /* The type of a routine repeatedly called by binding_table_foreach.  */
 typedef void (*bt_foreach_proc) (binding_entry, void *);
 
-struct binding_entry_s GTY(())
-{
+struct GTY(()) binding_entry_s {
   binding_entry chain;
   tree name;
   tree type;
 };
 
 /* These macros indicate the initial chains count for binding_table.  */
   binding_entry chain;
   tree name;
   tree type;
 };
 
 /* These macros indicate the initial chains count for binding_table.  */
-#define SCOPE_DEFAULT_HT_SIZE                        (1 << 3)
-#define CLASS_SCOPE_HT_SIZE                          (1 << 3)
-#define NAMESPACE_ORDINARY_HT_SIZE                   (1 << 5)
-#define NAMESPACE_STD_HT_SIZE                        (1 << 8)
-#define GLOBAL_SCOPE_HT_SIZE                         (1 << 8)
+#define SCOPE_DEFAULT_HT_SIZE          (1 << 3)
+#define CLASS_SCOPE_HT_SIZE            (1 << 3)
+#define NAMESPACE_ORDINARY_HT_SIZE     (1 << 5)
+#define NAMESPACE_STD_HT_SIZE          (1 << 8)
+#define GLOBAL_SCOPE_HT_SIZE           (1 << 8)
 
 
-extern void binding_table_remove_anonymous_types (binding_table);
 extern void binding_table_foreach (binding_table, bt_foreach_proc, void *);
 extern binding_entry binding_table_find (binding_table, tree);
 extern void binding_table_foreach (binding_table, bt_foreach_proc, void *);
 extern binding_entry binding_table_find (binding_table, tree);
-extern void cxx_remember_type_decls (binding_table);
 \f
 \f
-/* Datatype used to temporarily save C++ bindings (for implicit
-   instantiations purposes and like).  Implemented in decl.c.  */
-typedef struct cxx_saved_binding cxx_saved_binding;
-
 /* Datatype that represents binding established by a declaration between
    a name and a C++ entity.  */
 typedef struct cxx_binding cxx_binding;
 /* Datatype that represents binding established by a declaration between
    a name and a C++ entity.  */
 typedef struct cxx_binding cxx_binding;
@@ -70,8 +63,7 @@ typedef struct cp_binding_level cxx_scope;
    currently being defined.  */
 #define INHERITED_VALUE_BINDING_P(NODE) ((NODE)->value_is_inherited)
 
    currently being defined.  */
 #define INHERITED_VALUE_BINDING_P(NODE) ((NODE)->value_is_inherited)
 
-struct cxx_binding GTY(())
-{
+struct GTY(()) cxx_binding {
   /* Link to chain together various bindings for this name.  */
   cxx_binding *previous;
   /* The non-type entity this name is bound to.  */
   /* Link to chain together various bindings for this name.  */
   cxx_binding *previous;
   /* The non-type entity this name is bound to.  */
@@ -84,11 +76,22 @@ struct cxx_binding GTY(())
   unsigned is_local : 1;
 };
 
   unsigned is_local : 1;
 };
 
+/* Datatype used to temporarily save C++ bindings (for implicit
+   instantiations purposes and like).  Implemented in decl.c.  */
+typedef struct GTY(()) cxx_saved_binding {
+  /* The name of the current binding.  */
+  tree identifier;
+  /* The binding we're saving.  */
+  cxx_binding *binding;
+  tree real_type_value;
+} cxx_saved_binding;
+
+DEF_VEC_O(cxx_saved_binding);
+DEF_VEC_ALLOC_O(cxx_saved_binding,gc);
+
 extern tree identifier_type_value (tree);
 extern void set_identifier_type_value (tree, tree);
 extern void pop_binding (tree, tree);
 extern tree identifier_type_value (tree);
 extern void set_identifier_type_value (tree, tree);
 extern void pop_binding (tree, tree);
-extern void clear_identifier_class_values (void);
-extern tree constructor_name_full (tree);
 extern tree constructor_name (tree);
 extern bool constructor_name_p (tree, tree);
 \f
 extern tree constructor_name (tree);
 extern bool constructor_name_p (tree, tree);
 \f
@@ -99,24 +102,62 @@ typedef enum scope_kind {
                        is initialized by using "memset" to set the
                        contents to zero, and the default scope kind
                        is "sk_block".  */
                        is initialized by using "memset" to set the
                        contents to zero, and the default scope kind
                        is "sk_block".  */
-  sk_cleanup,        /* A scope for (pseudo-)scope for cleanup.  It is
-                        peusdo in that it is transparent to name lookup
-                        activities.  */
+  sk_cleanup,       /* A scope for (pseudo-)scope for cleanup.  It is
+                       pseudo in that it is transparent to name lookup
+                       activities.  */
   sk_try,           /* A try-block.  */
   sk_try,           /* A try-block.  */
-  sk_catch,          /* A catch-block.  */
-  sk_for,            /* The scope of the variable declared in a
+  sk_catch,         /* A catch-block.  */
+  sk_for,           /* The scope of the variable declared in a
                        for-init-statement.  */
   sk_function_parms, /* The scope containing function parameters.  */
                        for-init-statement.  */
   sk_function_parms, /* The scope containing function parameters.  */
-  sk_class,          /* The scope containing the members of a class.  */
-  sk_namespace,      /* The scope containing the members of a
+  sk_class,         /* The scope containing the members of a class.  */
+  sk_scoped_enum,    /* The scope containing the enumertors of a C++0x
+                        scoped enumeration.  */
+  sk_namespace,             /* The scope containing the members of a
                        namespace, including the global scope.  */
   sk_template_parms, /* A scope for template parameters.  */
                        namespace, including the global scope.  */
   sk_template_parms, /* A scope for template parameters.  */
-  sk_template_spec   /* Like sk_template_parms, but for an explicit
+  sk_template_spec,  /* Like sk_template_parms, but for an explicit
                        specialization.  Since, by definition, an
                        explicit specialization is introduced by
                        "template <>", this scope is always empty.  */
                        specialization.  Since, by definition, an
                        explicit specialization is introduced by
                        "template <>", this scope is always empty.  */
+  sk_omp            /* An OpenMP structured block.  */
 } scope_kind;
 
 } scope_kind;
 
+/* The scope where the class/struct/union/enum tag applies.  */
+typedef enum tag_scope {
+  ts_current = 0,      /* Current scope only.  This is for the
+                            class-key identifier;
+                          case mentioned in [basic.lookup.elab]/2,
+                          or the class/enum definition
+                            class-key identifier { ... };  */
+  ts_global = 1,       /* All scopes.  This is the 3.4.1
+                          [basic.lookup.unqual] lookup mentioned
+                          in [basic.lookup.elab]/2.  */
+  ts_within_enclosing_non_class = 2    /* Search within enclosing non-class
+                                          only, for friend class lookup
+                                          according to [namespace.memdef]/3
+                                          and [class.friend]/9.  */
+} tag_scope;
+
+typedef struct GTY(()) cp_class_binding {
+  cxx_binding base;
+  /* The bound name.  */
+  tree identifier;
+} cp_class_binding;
+
+DEF_VEC_O(cp_class_binding);
+DEF_VEC_ALLOC_O(cp_class_binding,gc);
+
+typedef struct GTY(()) cp_label_binding {
+  /* The bound LABEL_DECL.  */
+  tree label;
+  /* The previous IDENTIFIER_LABEL_VALUE.  */
+  tree prev_value;
+} cp_label_binding;
+
+DEF_VEC_O(cp_label_binding);
+DEF_VEC_ALLOC_O(cp_label_binding,gc);
+
 /* For each binding contour we allocate a binding_level structure
    which records the names defined in that contour.
    Contours include:
 /* For each binding contour we allocate a binding_level structure
    which records the names defined in that contour.
    Contours include:
@@ -141,8 +182,7 @@ typedef enum scope_kind {
 /* Note that the information in the `names' component of the global contour
    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
 
 /* Note that the information in the `names' component of the global contour
    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
 
-struct cp_binding_level GTY(())
-  {
+struct GTY(()) cp_binding_level {
     /* A chain of _DECL nodes for all variables, constants, functions,
        and typedef types.  These are in the reverse of the order
        supplied.  There may be OVERLOADs on this list, too, but they
     /* A chain of _DECL nodes for all variables, constants, functions,
        and typedef types.  These are in the reverse of the order
        supplied.  There may be OVERLOADs on this list, too, but they
@@ -156,13 +196,7 @@ struct cp_binding_level GTY(())
     tree namespaces;
 
     /* An array of static functions and variables (for namespaces only) */
     tree namespaces;
 
     /* An array of static functions and variables (for namespaces only) */
-    varray_type static_decls;
-
-    /* A chain of VTABLE_DECL nodes.  */
-    tree vtables; 
-
-    /* A dictionary for looking up user-defined-types.  */
-    binding_table type_decls;
+    VEC(tree,gc) *static_decls;
 
     /* A list of USING_DECL nodes.  */
     tree usings;
 
     /* A list of USING_DECL nodes.  */
     tree usings;
@@ -171,21 +205,20 @@ struct cp_binding_level GTY(())
        VALUE the common ancestor with this binding_level's namespace.  */
     tree using_directives;
 
        VALUE the common ancestor with this binding_level's namespace.  */
     tree using_directives;
 
-    /* If this binding level is the binding level for a class, then
-       class_shadowed is a TREE_LIST.  The TREE_PURPOSE of each node
-       is the name of an entity bound in the class.  The TREE_TYPE is
-       the DECL bound by this name in the class.  */
-    tree class_shadowed;
+    /* For the binding level corresponding to a class, the entities
+       declared in the class or its base classes.  */
+    VEC(cp_class_binding,gc) *class_shadowed;
 
     /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and
 
     /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and
-       is used for all binding levels. In addition the TREE_VALUE is the
-       IDENTIFIER_TYPE_VALUE before we entered the class.  */
+       is used for all binding levels. The TREE_PURPOSE is the name of
+       the entity, the TREE_TYPE is the associated type.  In addition
+       the TREE_VALUE is the IDENTIFIER_TYPE_VALUE before we entered
+       the class.  */
     tree type_shadowed;
 
     tree type_shadowed;
 
-    /* A TREE_LIST.  Each TREE_VALUE is the LABEL_DECL for a local
-       label in this scope.  The TREE_PURPOSE is the previous value of
-       the IDENTIFIER_LABEL VALUE.  */
-    tree shadowed_labels;
+    /* Similar to class_shadowed, but for IDENTIFIER_LABEL_VALUE, and
+       used for all binding levels.  */
+    VEC(cp_label_binding,gc) *shadowed_labels;
 
     /* For each level (except not the global one),
        a chain of BLOCK nodes for all the levels
 
     /* For each level (except not the global one),
        a chain of BLOCK nodes for all the levels
@@ -201,21 +234,24 @@ struct cp_binding_level GTY(())
 
     /* List of VAR_DECLS saved from a previous for statement.
        These would be dead in ISO-conforming code, but might
 
     /* List of VAR_DECLS saved from a previous for statement.
        These would be dead in ISO-conforming code, but might
-       be referenced in ARM-era code.  These are stored in a
-       TREE_LIST; the TREE_VALUE is the actual declaration.  */
-    tree dead_vars_from_for;
+       be referenced in ARM-era code.  */
+    VEC(tree,gc) *dead_vars_from_for;
+
+    /* STATEMENT_LIST for statements in this binding contour.
+       Only used at present for SK_CLEANUP temporary bindings.  */
+    tree statement_list;
 
     /* Binding depth at which this level began.  */
     int binding_depth;
 
     /* The kind of scope that this object represents.  However, a
        SK_TEMPLATE_SPEC scope is represented with KIND set to
 
     /* Binding depth at which this level began.  */
     int binding_depth;
 
     /* The kind of scope that this object represents.  However, a
        SK_TEMPLATE_SPEC scope is represented with KIND set to
-       SK_TEMPALTE_PARMS and EXPLICIT_SPEC_P set to true.  */
+       SK_TEMPLATE_PARMS and EXPLICIT_SPEC_P set to true.  */
     ENUM_BITFIELD (scope_kind) kind : 4;
 
     /* True if this scope is an SK_TEMPLATE_SPEC scope.  This field is
        only valid if KIND == SK_TEMPLATE_PARMS.  */
     ENUM_BITFIELD (scope_kind) kind : 4;
 
     /* True if this scope is an SK_TEMPLATE_SPEC scope.  This field is
        only valid if KIND == SK_TEMPLATE_PARMS.  */
-    bool explicit_spec_p : 1;
+    BOOL_BITFIELD explicit_spec_p : 1;
 
     /* true means make a BLOCK for this level regardless of all else.  */
     unsigned keep : 1;
 
     /* true means make a BLOCK for this level regardless of all else.  */
     unsigned keep : 1;
@@ -225,13 +261,13 @@ struct cp_binding_level GTY(())
     unsigned more_cleanups_ok : 1;
     unsigned have_cleanups : 1;
 
     unsigned more_cleanups_ok : 1;
     unsigned have_cleanups : 1;
 
-    /* 22 bits left to fill a 32-bit word.  */
+    /* 24 bits left to fill a 32-bit word.  */
   };
 
 /* The binding level currently in effect.  */
 
 #define current_binding_level                  \
   };
 
 /* The binding level currently in effect.  */
 
 #define current_binding_level                  \
-  (*(cfun && cp_function_chain->bindings       \
+  (*(cfun && cp_function_chain && cp_function_chain->bindings \
    ? &cp_function_chain->bindings              \
    : &scope_chain->bindings))
 
    ? &cp_function_chain->bindings              \
    : &scope_chain->bindings))
 
@@ -261,54 +297,58 @@ extern bool template_parm_scope_p (void);
 extern scope_kind innermost_scope_kind (void);
 extern cxx_scope *begin_scope (scope_kind, tree);
 extern void print_binding_stack        (void);
 extern scope_kind innermost_scope_kind (void);
 extern cxx_scope *begin_scope (scope_kind, tree);
 extern void print_binding_stack        (void);
-extern void print_binding_level        (cxx_scope *);
 extern void push_to_top_level (void);
 extern void pop_from_top_level (void);
 extern void push_to_top_level (void);
 extern void pop_from_top_level (void);
-extern void maybe_push_to_top_level (int);
 extern void pop_everything (void);
 extern void keep_next_level (bool);
 extern bool is_ancestor (tree, tree);
 extern void pop_everything (void);
 extern void keep_next_level (bool);
 extern bool is_ancestor (tree, tree);
-extern void push_scope (tree);
+extern tree push_scope (tree);
 extern void pop_scope (tree);
 extern void pop_scope (tree);
+extern tree push_inner_scope (tree);
+extern void pop_inner_scope (tree, tree);
+extern void push_binding_level (struct cp_binding_level *);
 \f
 extern void push_namespace (tree);
 extern void pop_namespace (void);
 extern void push_nested_namespace (tree);
 extern void pop_nested_namespace (tree);
 \f
 extern void push_namespace (tree);
 extern void pop_namespace (void);
 extern void push_nested_namespace (tree);
 extern void pop_nested_namespace (tree);
+extern bool handle_namespace_attrs (tree, tree);
 extern void pushlevel_class (void);
 extern void poplevel_class (void);
 extern void pushlevel_class (void);
 extern void poplevel_class (void);
-extern tree pushdecl_with_scope (tree, cxx_scope *);
-extern tree lookup_tag (enum tree_code, tree, cxx_scope *, int);
-extern tree lookup_tag_reverse (tree, tree);
-extern tree lookup_name        (tree, int);
-extern tree lookup_name_real (tree, int, int, int, int);
+extern tree pushdecl_with_scope (tree, cxx_scope *, bool);
+extern tree lookup_name_prefer_type (tree, int);
+extern tree lookup_name_real (tree, int, int, bool, int, int);
+extern tree lookup_type_scope (tree, tag_scope);
 extern tree namespace_binding (tree, tree);
 extern void set_namespace_binding (tree, tree, tree);
 extern tree namespace_binding (tree, tree);
 extern void set_namespace_binding (tree, tree, tree);
-extern tree lookup_namespace_name (tree, tree);
+extern bool hidden_name_p (tree);
+extern tree remove_hidden_names (tree);
 extern tree lookup_qualified_name (tree, tree, bool, bool);
 extern tree lookup_name_nonclass (tree);
 extern tree lookup_qualified_name (tree, tree, bool, bool);
 extern tree lookup_name_nonclass (tree);
-extern tree lookup_function_nonclass (tree, tree);
-extern int push_class_binding (tree, tree);
+extern tree lookup_name_innermost_nonclass_level (tree);
+extern bool is_local_extern (tree);
+extern tree lookup_function_nonclass (tree, VEC(tree,gc) *, bool);
+extern void push_local_binding (tree, tree, int);
 extern bool pushdecl_class_level (tree);
 extern bool pushdecl_class_level (tree);
-extern tree pushdecl_namespace_level (tree);
+extern tree pushdecl_namespace_level (tree, bool);
 extern bool push_class_level_binding (tree, tree);
 extern bool push_class_level_binding (tree, tree);
-extern void storetags (tree);
 extern tree getdecls (void);
 extern tree getdecls (void);
+extern int function_parm_depth (void);
 extern tree cp_namespace_decls (tree);
 extern tree cp_namespace_decls (tree);
-extern void set_class_shadows (tree);
 extern void set_decl_namespace (tree, tree, bool);
 extern void set_decl_namespace (tree, tree, bool);
-extern tree current_decl_namespace (void);
 extern void push_decl_namespace (tree);
 extern void pop_decl_namespace (void);
 extern void do_namespace_alias (tree, tree);
 extern void push_decl_namespace (tree);
 extern void pop_decl_namespace (void);
 extern void do_namespace_alias (tree, tree);
-extern void do_toplevel_using_decl (tree);
-extern void do_local_using_decl (tree);
-extern tree do_class_using_decl (tree);
+extern void do_toplevel_using_decl (tree, tree, tree);
+extern void do_local_using_decl (tree, tree, tree);
+extern tree do_class_using_decl (tree, tree);
 extern void do_using_directive (tree);
 extern void do_using_directive (tree);
-extern tree lookup_arg_dependent (tree, tree, tree);
+extern tree lookup_arg_dependent (tree, tree, VEC(tree,gc) *, bool);
 extern bool is_associated_namespace (tree, tree);
 extern void parse_using_directive (tree, tree);
 extern bool is_associated_namespace (tree, tree);
 extern void parse_using_directive (tree, tree);
-
+extern tree innermost_non_namespace_value (tree);
+extern cxx_binding *outer_binding (tree, cxx_binding *, bool);
+extern void cp_emit_debug_info_for_using (tree, tree);
 
 /* Set *DECL to the (non-hidden) declaration for ID at global scope,
    if present and return true; otherwise return false.  */
 
 /* Set *DECL to the (non-hidden) declaration for ID at global scope,
    if present and return true; otherwise return false.  */
@@ -317,7 +357,6 @@ static inline bool
 get_global_value_if_present (tree id, tree *decl)
 {
   tree global_value = namespace_binding (id, global_namespace);
 get_global_value_if_present (tree id, tree *decl)
 {
   tree global_value = namespace_binding (id, global_namespace);
-
   if (global_value)
     *decl = global_value;
   return global_value != NULL;
   if (global_value)
     *decl = global_value;
   return global_value != NULL;