OSDN Git Service

04c6161dbc44b365f95be88cfb8ec9138a5e42b1
[pf3gnuchains/gcc-fork.git] / gcc / cp / name-lookup.h
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
5 This file is part of GCC.
6
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)
10 any later version.
11
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.
16
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.  */
21
22 #ifndef GCC_CP_NAME_LOOKUP_H
23 #define GCC_CP_NAME_LOOKUP_H
24
25 #include "c-common.h"
26
27 /* The type of dictionary used to map names to types declared at
28    a given scope.  */
29 typedef struct binding_table_s *binding_table;
30 typedef struct binding_entry_s *binding_entry;
31
32 /* The type of a routine repeatedly called by binding_table_foreach.  */
33 typedef void (*bt_foreach_proc) (binding_entry, void *);
34
35 struct 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
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,
54                                                         tree, tree);
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);
59 \f
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;
63
64 /* Datatype that represents binding established by a declaration between
65    a name and a C++ entity.  */
66 typedef struct cxx_binding cxx_binding;
67
68 /* The datatype used to implement C++ scope.  */
69 typedef struct cp_binding_level cxx_scope;
70
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
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)
78
79 /* Zero out a cxx_binding pointed to by B.  */
80 #define cxx_binding_clear(B) memset ((B), 0, sizeof (cxx_binding))
81
82 struct 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;
90   /* The scope at which this binding was made.  */
91   cxx_scope *scope;
92   unsigned value_is_inherited : 1;
93   unsigned is_local : 1;
94 };
95
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);
99 \f
100 /* The tree node representing the global scope.  */
101 extern GTY(()) tree global_namespace;
102
103 /* True if SCOPE designates the global scope binding contour.  */
104 #define global_scope_p(SCOPE) \
105   ((SCOPE) == NAMESPACE_LEVEL (global_namespace))
106
107 extern cxx_binding *cxx_scope_find_binding_for_name (cxx_scope *, tree);
108 extern cxx_binding *binding_for_name (cxx_scope *, tree);
109 \f
110 extern tree namespace_binding (tree, tree);
111 extern void set_namespace_binding (tree, tree, tree);
112
113
114 /* Set *DECL to the (non-hidden) declaration for ID at global scope,
115    if present and return true; otherwise return false.  */
116
117 static inline bool
118 get_global_value_if_present (tree id, tree *decl)
119 {
120   tree global_value = namespace_binding (id, global_namespace);
121
122   if (global_value)
123     *decl = global_value;
124   return global_value != NULL;
125 }
126
127 /* True is the binding of IDENTIFIER at global scope names a type.  */
128
129 static inline bool
130 is_typename_at_global_scope (tree id)
131 {
132   tree global_value = namespace_binding (id, global_namespace);
133
134   return global_value && TREE_CODE (global_value) == TYPE_DECL;
135 }
136
137 #endif /* GCC_CP_NAME_LOOKUP_H */