1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/* Definitions for C++ name lookup routines.
Copyright (C) 2003 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
the Free Software Foundation; either version 2, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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
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. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "cp-tree.h"
#include "name-lookup.h"
#include "timevar.h"
/* A free list of "cxx_binding"s, connected by their PREVIOUS. */
static GTY((deletable (""))) cxx_binding *free_bindings;
/* (GC)-allocate a binding object with VALUE and TYPE member initialized. */
cxx_binding *
cxx_binding_make (tree value, tree type)
{
cxx_binding *binding;
if (free_bindings)
{
binding = free_bindings;
free_bindings = binding->previous;
}
else
binding = ggc_alloc_cleared (sizeof (cxx_binding));
binding->value = value;
binding->type = type;
return binding;
}
/* Put BINDING back on the free list. */
void
cxx_binding_free (cxx_binding *binding)
{
binding->previous = free_bindings;
free_bindings = binding;
}
/* Return (from the stack of) the BINDING, if any, establihsed at SCOPE. */
static inline cxx_binding *
find_binding (cxx_scope *scope, cxx_binding *binding)
{
timevar_push (TV_NAME_LOOKUP);
for (; binding != NULL; binding = binding->previous)
if (BINDING_SCOPE (binding) == scope)
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, binding);
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, (cxx_binding *)0);
}
/* Return the binding for NAME in SCOPE, if any. Otherwise, return NULL. */
cxx_binding *
cxx_scope_find_binding_for_name (cxx_scope *scope, tree name)
{
cxx_binding *b = IDENTIFIER_NAMESPACE_BINDINGS (name);
if (b)
{
/* Fold-in case where NAME is used only once. */
if (scope == BINDING_SCOPE (b) && b->previous == NULL)
return b;
return find_binding (scope, b);
}
return NULL;
}
/* Always returns a binding for name in scope. If no binding is
found, make a new one. */
cxx_binding *
binding_for_name (cxx_scope *scope, tree name)
{
cxx_binding *result;
result = cxx_scope_find_binding_for_name (scope, name);
if (result)
return result;
/* Not found, make a new one. */
result = cxx_binding_make (NULL, NULL);
result->previous = IDENTIFIER_NAMESPACE_BINDINGS (name);
BINDING_SCOPE (result) = scope;
result->is_local = false;
result->value_is_inherited = false;
IDENTIFIER_NAMESPACE_BINDINGS (name) = result;
return result;
}
/* Namespace-scope manipulation routines. */
/* Return the binding value for name in scope. */
tree
namespace_binding (tree name, tree scope)
{
cxx_binding *binding;
if (scope == NULL)
scope = global_namespace;
scope = ORIGINAL_NAMESPACE (scope);
binding = cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (scope), name);
return binding ? binding->value : NULL_TREE;
}
/* Set the binding value for name in scope. */
void
set_namespace_binding (tree name, tree scope, tree val)
{
cxx_binding *b;
timevar_push (TV_NAME_LOOKUP);
if (scope == NULL_TREE)
scope = global_namespace;
b = binding_for_name (NAMESPACE_LEVEL (scope), name);
BINDING_VALUE (b) = val;
timevar_pop (TV_NAME_LOOKUP);
}
#include "gt-cp-name-lookup.h"
|