1 /* Declarations for C++ name lookup routines.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #ifndef GCC_CP_NAME_LOOKUP_H
23 #define GCC_CP_NAME_LOOKUP_H
27 /* The type of dictionary used to map names to types declared at
29 typedef struct binding_table_s *binding_table;
30 typedef struct binding_entry_s *binding_entry;
32 /* The type of a routine repeatedly called by binding_table_foreach. */
33 typedef void (*bt_foreach_proc) (binding_entry, void *);
35 struct binding_entry_s GTY(())
42 /* These macros indicate the initial chains count for binding_table. */
43 #define SCOPE_DEFAULT_HT_SIZE (1 << 3)
44 #define CLASS_SCOPE_HT_SIZE (1 << 3)
45 #define NAMESPACE_ORDINARY_HT_SIZE (1 << 5)
46 #define NAMESPACE_STD_HT_SIZE (1 << 8)
47 #define GLOBAL_SCOPE_HT_SIZE (1 << 8)
49 extern binding_table binding_table_new (size_t);
50 extern void binding_table_free (binding_table);
51 extern void binding_table_insert (binding_table, tree, tree);
52 extern tree binding_table_find_anon_type (binding_table, tree);
53 extern binding_entry binding_table_reverse_maybe_remap (binding_table,
55 extern void binding_table_remove_anonymous_types (binding_table);
56 extern void binding_table_foreach (binding_table, bt_foreach_proc, void *);
57 extern binding_entry binding_table_find (binding_table, tree);
58 extern void cxx_remember_type_decls (binding_table);
60 /* Datatype used to temporarily save C++ bindings (for implicit
61 instantiations purposes and like). Implemented in decl.c. */
62 typedef struct cxx_saved_binding cxx_saved_binding;
64 /* Datatype that represents binding established by a declaration between
65 a name and a C++ entity. */
66 typedef struct cxx_binding cxx_binding;
68 /* The datatype used to implement C++ scope. */
69 typedef struct cp_binding_level cxx_scope;
71 /* Nonzero if this binding is for a local scope, as opposed to a class
72 or namespace scope. */
73 #define LOCAL_BINDING_P(NODE) ((NODE)->is_local)
75 /* True if NODE->value is from a base class of the class which is
76 currently being defined. */
77 #define INHERITED_VALUE_BINDING_P(NODE) ((NODE)->value_is_inherited)
79 /* Zero out a cxx_binding pointed to by B. */
80 #define cxx_binding_clear(B) memset ((B), 0, sizeof (cxx_binding))
82 struct cxx_binding GTY(())
84 /* Link to chain together various bindings for this name. */
85 cxx_binding *previous;
86 /* The non-type entity this name is bound to. */
88 /* The type entity this name is bound to. */
90 /* The scope at which this binding was made. */
92 unsigned value_is_inherited : 1;
93 unsigned is_local : 1;
96 extern cxx_binding *cxx_binding_make (tree, tree);
97 extern void cxx_binding_free (cxx_binding *);
98 extern bool supplement_binding (cxx_binding *, tree);
100 /* The tree node representing the global scope. */
101 extern GTY(()) tree global_namespace;
103 /* True if SCOPE designates the global scope binding contour. */
104 #define global_scope_p(SCOPE) \
105 ((SCOPE) == NAMESPACE_LEVEL (global_namespace))
107 extern cxx_binding *cxx_scope_find_binding_for_name (cxx_scope *, tree);
108 extern cxx_binding *binding_for_name (cxx_scope *, tree);
110 extern tree namespace_binding (tree, tree);
111 extern void set_namespace_binding (tree, tree, tree);
114 /* Set *DECL to the (non-hidden) declaration for ID at global scope,
115 if present and return true; otherwise return false. */
118 get_global_value_if_present (tree id, tree *decl)
120 tree global_value = namespace_binding (id, global_namespace);
123 *decl = global_value;
124 return global_value != NULL;
127 /* True is the binding of IDENTIFIER at global scope names a type. */
130 is_typename_at_global_scope (tree id)
132 tree global_value = namespace_binding (id, global_namespace);
134 return global_value && TREE_CODE (global_value) == TYPE_DECL;
137 #endif /* GCC_CP_NAME_LOOKUP_H */