]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/name-lookup.h
re PR target/12538 (%l7 is call-clobbered with -mflat -fpic)
[thirdparty/gcc.git] / gcc / cp / name-lookup.h
CommitLineData
aed81407
GDR
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>
4
ed3cf953 5This file is part of GCC.
aed81407 6
ed3cf953 7GCC is free software; you can redistribute it and/or modify
aed81407
GDR
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
ed3cf953 12GCC is distributed in the hope that it will be useful,
aed81407
GDR
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
ed3cf953 18along with GCC; see the file COPYING. If not, write to
aed81407
GDR
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22#ifndef GCC_CP_NAME_LOOKUP_H
23#define GCC_CP_NAME_LOOKUP_H
24
25#include "c-common.h"
26
5e0c54e5
GDR
27/* The type of dictionary used to map names to types declared at
28 a given scope. */
29typedef struct binding_table_s *binding_table;
30typedef struct binding_entry_s *binding_entry;
31
32/* The type of a routine repeatedly called by binding_table_foreach. */
33typedef void (*bt_foreach_proc) (binding_entry, void *);
34
35struct binding_entry_s GTY(())
36{
37 binding_entry chain;
38 tree name;
39 tree type;
40};
41
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)
48
49extern binding_table binding_table_new (size_t);
50extern void binding_table_free (binding_table);
51extern void binding_table_insert (binding_table, tree, tree);
52extern tree binding_table_find_anon_type (binding_table, tree);
53extern binding_entry binding_table_reverse_maybe_remap (binding_table,
54 tree, tree);
55extern void binding_table_remove_anonymous_types (binding_table);
56extern void binding_table_foreach (binding_table, bt_foreach_proc, void *);
57extern binding_entry binding_table_find (binding_table, tree);
58extern void cxx_remember_type_decls (binding_table);
59\f
aed81407
GDR
60/* Datatype used to temporarily save C++ bindings (for implicit
61 instantiations purposes and like). Implemented in decl.c. */
62typedef struct cxx_saved_binding cxx_saved_binding;
63
64/* Datatype that represents binding established by a declaration between
65 a name and a C++ entity. */
66typedef struct cxx_binding cxx_binding;
67
ed3cf953
GDR
68/* The datatype used to implement C++ scope. */
69typedef struct cp_binding_level cxx_scope;
70
aed81407
GDR
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)
74
147135cc 75/* True if NODE->value is from a base class of the class which is
aed81407
GDR
76 currently being defined. */
77#define INHERITED_VALUE_BINDING_P(NODE) ((NODE)->value_is_inherited)
78
aed81407
GDR
79/* Zero out a cxx_binding pointed to by B. */
80#define cxx_binding_clear(B) memset ((B), 0, sizeof (cxx_binding))
81
82struct cxx_binding GTY(())
83{
84 /* Link to chain together various bindings for this name. */
85 cxx_binding *previous;
86 /* The non-type entity this name is bound to. */
87 tree value;
88 /* The type entity this name is bound to. */
89 tree type;
ed3cf953
GDR
90 /* The scope at which this binding was made. */
91 cxx_scope *scope;
aed81407
GDR
92 unsigned value_is_inherited : 1;
93 unsigned is_local : 1;
94};
95
96extern cxx_binding *cxx_binding_make (tree, tree);
97extern void cxx_binding_free (cxx_binding *);
c87ceb13 98extern bool supplement_binding (cxx_binding *, tree);
aed81407 99\f
1ec57cf0
GDR
100/* The kinds of scopes we recognize. */
101typedef enum scope_kind {
102 sk_block = 0, /* An ordinary block scope. This enumerator must
103 have the value zero because "cp_binding_level"
104 is initialized by using "memset" to set the
105 contents to zero, and the default scope kind
106 is "sk_block". */
107 sk_cleanup, /* A scope for (pseudo-)scope for cleanup. It is
108 peusdo in that it is transparent to name lookup
109 activities. */
110 sk_try, /* A try-block. */
111 sk_catch, /* A catch-block. */
112 sk_for, /* The scope of the variable declared in a
113 for-init-statement. */
114 sk_function_parms, /* The scope containing function parameters. */
115 sk_class, /* The scope containing the members of a class. */
116 sk_namespace, /* The scope containing the members of a
117 namespace, including the global scope. */
118 sk_template_parms, /* A scope for template parameters. */
119 sk_template_spec /* Like sk_template_parms, but for an explicit
120 specialization. Since, by definition, an
121 explicit specialization is introduced by
122 "template <>", this scope is always empty. */
123} scope_kind;
124
125/* For each binding contour we allocate a binding_level structure
126 which records the names defined in that contour.
127 Contours include:
128 0) the global one
129 1) one for each function definition,
130 where internal declarations of the parameters appear.
131 2) one for each compound statement,
132 to record its declarations.
133
134 The current meaning of a name can be found by searching the levels
135 from the current one out to the global one.
136
137 Off to the side, may be the class_binding_level. This exists only
138 to catch class-local declarations. It is otherwise nonexistent.
139
140 Also there may be binding levels that catch cleanups that must be
141 run when exceptions occur. Thus, to see whether a name is bound in
142 the current scope, it is not enough to look in the
143 CURRENT_BINDING_LEVEL. You should use lookup_name_current_level
144 instead. */
145
146/* Note that the information in the `names' component of the global contour
147 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
148
149struct cp_binding_level GTY(())
150 {
151 /* A chain of _DECL nodes for all variables, constants, functions,
152 and typedef types. These are in the reverse of the order
153 supplied. There may be OVERLOADs on this list, too, but they
154 are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD. */
155 tree names;
156
157 /* Count of elements in names chain. */
158 size_t names_size;
159
160 /* A chain of NAMESPACE_DECL nodes. */
161 tree namespaces;
162
163 /* An array of static functions and variables (for namespaces only) */
164 varray_type static_decls;
165
166 /* A chain of VTABLE_DECL nodes. */
167 tree vtables;
168
169 /* A dictionary for looking up user-defined-types. */
170 binding_table type_decls;
171
172 /* A list of USING_DECL nodes. */
173 tree usings;
174
175 /* A list of used namespaces. PURPOSE is the namespace,
176 VALUE the common ancestor with this binding_level's namespace. */
177 tree using_directives;
178
179 /* If this binding level is the binding level for a class, then
180 class_shadowed is a TREE_LIST. The TREE_PURPOSE of each node
181 is the name of an entity bound in the class. The TREE_TYPE is
182 the DECL bound by this name in the class. */
183 tree class_shadowed;
184
185 /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and
186 is used for all binding levels. In addition the TREE_VALUE is the
187 IDENTIFIER_TYPE_VALUE before we entered the class. */
188 tree type_shadowed;
189
190 /* A TREE_LIST. Each TREE_VALUE is the LABEL_DECL for a local
191 label in this scope. The TREE_PURPOSE is the previous value of
192 the IDENTIFIER_LABEL VALUE. */
193 tree shadowed_labels;
194
195 /* For each level (except not the global one),
196 a chain of BLOCK nodes for all the levels
197 that were entered and exited one level down. */
198 tree blocks;
199
200 /* The entity (namespace, class, function) the scope of which this
201 binding contour corresponds to. Otherwise NULL. */
202 tree this_entity;
203
204 /* The binding level which this one is contained in (inherits from). */
205 struct cp_binding_level *level_chain;
206
207 /* List of VAR_DECLS saved from a previous for statement.
208 These would be dead in ISO-conforming code, but might
209 be referenced in ARM-era code. These are stored in a
210 TREE_LIST; the TREE_VALUE is the actual declaration. */
211 tree dead_vars_from_for;
212
213 /* Binding depth at which this level began. */
214 int binding_depth;
215
216 /* The kind of scope that this object represents. However, a
217 SK_TEMPLATE_SPEC scope is represented with KIND set to
218 SK_TEMPALTE_PARMS and EXPLICIT_SPEC_P set to true. */
219 enum scope_kind kind : 4;
220
221 /* True if this scope is an SK_TEMPLATE_SPEC scope. This field is
222 only valid if KIND == SK_TEMPLATE_PARMS. */
223 bool explicit_spec_p : 1;
224
225 /* true means make a BLOCK for this level regardless of all else. */
226 unsigned keep : 1;
227
228 /* Nonzero if this level can safely have additional
229 cleanup-needing variables added to it. */
230 unsigned more_cleanups_ok : 1;
231 unsigned have_cleanups : 1;
232
233 /* 22 bits left to fill a 32-bit word. */
234 };
235
236/* The binding level currently in effect. */
237
238#define current_binding_level \
239 (*(cfun && cp_function_chain->bindings \
240 ? &cp_function_chain->bindings \
241 : &scope_chain->bindings))
242
243/* The binding level of the current class, if any. */
244
245#define class_binding_level scope_chain->class_bindings
246
c003e212
GDR
247/* The tree node representing the global scope. */
248extern GTY(()) tree global_namespace;
249
5f52c0e0
GDR
250/* True if SCOPE designates the global scope binding contour. */
251#define global_scope_p(SCOPE) \
252 ((SCOPE) == NAMESPACE_LEVEL (global_namespace))
aed81407 253
ed3cf953
GDR
254extern cxx_binding *cxx_scope_find_binding_for_name (cxx_scope *, tree);
255extern cxx_binding *binding_for_name (cxx_scope *, tree);
256\f
257extern tree namespace_binding (tree, tree);
258extern void set_namespace_binding (tree, tree, tree);
aed81407 259
c003e212
GDR
260
261/* Set *DECL to the (non-hidden) declaration for ID at global scope,
262 if present and return true; otherwise return false. */
263
264static inline bool
265get_global_value_if_present (tree id, tree *decl)
266{
267 tree global_value = namespace_binding (id, global_namespace);
268
269 if (global_value)
270 *decl = global_value;
271 return global_value != NULL;
272}
273
274/* True is the binding of IDENTIFIER at global scope names a type. */
275
276static inline bool
277is_typename_at_global_scope (tree id)
278{
279 tree global_value = namespace_binding (id, global_namespace);
280
281 return global_value && TREE_CODE (global_value) == TYPE_DECL;
282}
283
aed81407 284#endif /* GCC_CP_NAME_LOOKUP_H */