C++ PATCH: Unify name lookup. 1/n
Gabriel Dos Reis
gdr@integrable-solutions.net
Sun Mar 30 13:31:00 GMT 2003
This patch starts unifying the name lookup implementation in cc1plus.
This patch, by itself, does nothing terrible: It just moves some bits
into new files. Ntex patch will get rid of some unneeded bits.
Bootstrapped and regtested on an i686-pc-linux-gnu. Applied on
mainline as obvious.
-- Gaby
2003-03-30 Gabriel Dos Reis <gdr@integrable-solutions.net>
* name-lookup.c: New file.
* name-lookup.h: Likewise..
* decl.c (push_binding): Adjust use cxx_binding_make.
(free_bindings): Move to name-lookup.c
(pop_binding): Use cxx_binding_free.
(binding_for_name): Tidy.
* cp-tree.h: Include "name-lookup.h"
(cxx_binding_make): Move to name-lookup.h
(cxx_binding_clear): Likewise.
(struct cxx_binding): Likewise.
(LOCAL_BINDING_P): Likewise.
(INHERITED_VALUE_BINDING_P): Likewise.
(BINDING_SCOPE): Likewise.
(BINDING_HAS_LEVEL_P): Likewise.
(BINDING_VALUE): Likewise.
(BINDING_TYPE): Likewise.
* config-lang.in (gtfiles): Add cp/name-lookup.h
* Make-lang.in (cp/name-lookup.o): New rule.
(CXX_OBJS): Add cp/name-lookup.o
(CXX_TREE_H): Add cp/name-lookup.h
Index: Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Make-lang.in,v
retrieving revision 1.142
diff -p -r1.142 Make-lang.in
*** Make-lang.in 20 Mar 2003 03:11:25 -0000 1.142
--- Make-lang.in 30 Mar 2003 13:15:11 -0000
*************** CXX_OBJS = cp/call.o cp/decl.o cp/expr.o
*** 87,93 ****
cp/class.o cp/decl2.o cp/error.o cp/lex.o cp/parser.o cp/ptree.o cp/rtti.o \
cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o \
cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o \
! cp/optimize.o cp/mangle.o cp/cp-lang.o
# Use loose warnings for this front end.
cp-warn = $(WERROR)
--- 87,93 ----
cp/class.o cp/decl2.o cp/error.o cp/lex.o cp/parser.o cp/ptree.o cp/rtti.o \
cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o \
cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o \
! cp/optimize.o cp/mangle.o cp/cp-lang.o cp/name-lookup.o
# Use loose warnings for this front end.
cp-warn = $(WERROR)
*************** c++.stage4: stage4-start
*** 221,227 ****
#
# .o: .h dependencies.
! CXX_TREE_H = $(TREE_H) cp/cp-tree.h c-common.h cp/cp-tree.def c-common.def \
function.h varray.h $(SYSTEM_H) coretypes.h $(CONFIG_H) $(TARGET_H) \
$(GGC_H) \
$(srcdir)/../include/hashtab.h $(srcdir)/../include/splay-tree.h
--- 221,228 ----
#
# .o: .h dependencies.
! CXX_TREE_H = $(TREE_H) cp/name-lookup.h cp/cp-tree.h c-common.h \
! cp/cp-tree.def c-common.def \
function.h varray.h $(SYSTEM_H) coretypes.h $(CONFIG_H) $(TARGET_H) \
$(GGC_H) \
$(srcdir)/../include/hashtab.h $(srcdir)/../include/splay-tree.h
*************** cp/optimize.o: cp/optimize.c $(CXX_TREE_
*** 274,276 ****
--- 275,279 ----
cp/mangle.o: cp/mangle.c $(CXX_TREE_H) $(TM_H) toplev.h real.h
cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) diagnostic.h gt-cp-parser.h output.h
+
+ cp/name-lookup.o: cp/name-lookup.c $(CXX_TREE_H)
Index: config-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/config-lang.in,v
retrieving revision 1.16
diff -p -r1.16 config-lang.in
*** config-lang.in 5 Mar 2003 06:14:08 -0000 1.16
--- config-lang.in 30 Mar 2003 13:15:11 -0000
*************** stagestuff="g++\$(exeext) g++-cross\$(ex
*** 34,37 ****
target_libs="target-libstdc++-v3 target-gperf"
! gtfiles="\$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/lex.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-pragma.c"
--- 34,37 ----
target_libs="target-libstdc++-v3 target-gperf"
! gtfiles="\$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/lex.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.c \$(srcdir)/c-common.c \$(srcdir)/c-common.h \$(srcdir)/c-pragma.c"
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.831
diff -p -r1.831 cp-tree.h
*** cp-tree.h 29 Mar 2003 00:49:34 -0000 1.831
--- cp-tree.h 30 Mar 2003 13:15:13 -0000
*************** Boston, MA 02111-1307, USA. */
*** 34,39 ****
--- 34,40 ----
#endif
#include "c-common.h"
+ #include "name-lookup.h"
struct diagnostic_context;
*************** struct diagnostic_context;
*** 217,254 ****
#define abi_version_at_least(N) \
(flag_abi_version == 0 || flag_abi_version >= (N))
-
-
- /* 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;
-
- /* (GC-)allocate a cxx_binding object. */
- #define cxx_binding_make() (ggc_alloc (sizeof (cxx_binding)))
-
- /* Zero out a cxx_binding pointed to by B. */
- #define cxx_binding_clear(B) memset ((B), 0, sizeof (cxx_binding))
-
- struct cxx_binding GTY(())
- {
- /* Link to chain together various bindings for this name. */
- cxx_binding *previous;
- /* The non-type entity this name is bound to. */
- tree value;
- /* The type entity this name is bound to. */
- tree type;
- union tree_binding_u {
- tree GTY ((tag ("0"))) scope;
- struct cp_binding_level * GTY ((tag ("1"))) level;
- } GTY ((desc ("%0.has_level"))) scope;
- unsigned has_level : 1;
- unsigned value_is_inherited : 1;
- unsigned is_local : 1;
- };
/* Language-dependent contents of an identifier. */
--- 218,223 ----
*************** struct ptrmem_cst GTY(())
*** 296,326 ****
tree member;
};
typedef struct ptrmem_cst * ptrmem_cst_t;
-
- /* Nonzero if this binding is for a local scope, as opposed to a class
- or namespace scope. */
- #define LOCAL_BINDING_P(NODE) ((NODE)->is_local)
-
- /* Nonzero if BINDING_VALUE is from a base class of the class which is
- currently being defined. */
- #define INHERITED_VALUE_BINDING_P(NODE) ((NODE)->value_is_inherited)
-
- /* For a binding between a name and an entity at a non-local scope,
- defines the scope where the binding is declared. (Either a class
- _TYPE node, or a NAMESPACE_DECL.) This macro should be used only
- for namespace-level bindings; on the IDENTIFIER_BINDING list
- BINDING_LEVEL is used instead. */
- #define BINDING_SCOPE(NODE) ((NODE)->scope.scope)
-
- /* Nonzero if NODE has BINDING_LEVEL, rather than BINDING_SCOPE. */
- #define BINDING_HAS_LEVEL_P(NODE) ((NODE)->has_level)
-
- /* This is the declaration bound to the name. Possible values:
- variable, overloaded function, namespace, template, enumerator. */
- #define BINDING_VALUE(NODE) ((NODE)->value)
-
- /* If name is bound to a type, this is the type (struct, union, enum). */
- #define BINDING_TYPE(NODE) ((NODE)->type)
#define IDENTIFIER_GLOBAL_VALUE(NODE) \
namespace_binding ((NODE), global_namespace)
--- 265,270 ----
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1027
diff -p -r1.1027 decl.c
*** decl.c 28 Mar 2003 21:18:39 -0000 1.1027
--- decl.c 30 Mar 2003 13:15:20 -0000
*************** finish_scope (void)
*** 889,919 ****
this is the `struct cp_binding_level' for the block. */
#define BINDING_LEVEL(NODE) ((NODE)->scope.level)
- /* A free list of cxx_binding nodes, connected by their
- TREE_CHAINs. */
-
- static GTY((deletable (""))) cxx_binding *free_bindings;
-
/* Make DECL the innermost binding for ID. The LEVEL is the binding
level at which this declaration is being bound. */
static void
push_binding (tree id, tree decl, struct cp_binding_level* level)
{
! cxx_binding *binding;
!
! if (free_bindings)
! {
! binding = free_bindings;
! free_bindings = binding->previous;
! }
! else
! binding = cxx_binding_make ();
/* Now, fill in the binding information. */
binding->previous = IDENTIFIER_BINDING (id);
- BINDING_VALUE (binding) = decl;
- BINDING_TYPE (binding) = NULL_TREE;
BINDING_LEVEL (binding) = level;
INHERITED_VALUE_BINDING_P (binding) = 0;
LOCAL_BINDING_P (binding) = (level != class_binding_level);
--- 889,904 ----
this is the `struct cp_binding_level' for the block. */
#define BINDING_LEVEL(NODE) ((NODE)->scope.level)
/* Make DECL the innermost binding for ID. The LEVEL is the binding
level at which this declaration is being bound. */
static void
push_binding (tree id, tree decl, struct cp_binding_level* level)
{
! cxx_binding *binding = cxx_binding_make (decl, NULL);
/* Now, fill in the binding information. */
binding->previous = IDENTIFIER_BINDING (id);
BINDING_LEVEL (binding) = level;
INHERITED_VALUE_BINDING_P (binding) = 0;
LOCAL_BINDING_P (binding) = (level != class_binding_level);
*************** pop_binding (tree id, tree decl)
*** 1161,1168 ****
IDENTIFIER_BINDING (id) = binding->previous;
/* Add it to the free list. */
! binding->previous = free_bindings;
! free_bindings = binding;
/* Clear the BINDING_LEVEL so the garbage collector doesn't walk
it. */
--- 1146,1152 ----
IDENTIFIER_BINDING (id) = binding->previous;
/* Add it to the free list. */
! cxx_binding_free (binding);
/* Clear the BINDING_LEVEL so the garbage collector doesn't walk
it. */
*************** binding_for_name (tree name, tree scope)
*** 2084,2093 ****
if (result)
return result;
/* Not found, make a new one. */
! result = cxx_binding_make ();
result->previous = IDENTIFIER_NAMESPACE_BINDINGS (name);
- BINDING_TYPE (result) = NULL_TREE;
- BINDING_VALUE (result) = NULL_TREE;
BINDING_SCOPE (result) = scope;
result->is_local = false;
result->value_is_inherited = false;
--- 2068,2075 ----
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;
Index: name-lookup.c
===================================================================
RCS file: name-lookup.c
diff -N name-lookup.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- name-lookup.c 30 Mar 2003 13:15:20 -0000
***************
*** 0 ****
--- 1,58 ----
+ /* 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 GNU CC.
+
+ GNU CC 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.
+
+ GNU CC 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 GNU CC; 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"
+
+ /* 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 (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;
+ }
Index: name-lookup.h
===================================================================
RCS file: name-lookup.h
diff -N name-lookup.h
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- name-lookup.h 30 Mar 2003 13:15:20 -0000
***************
*** 0 ****
--- 1,85 ----
+ /* Declarations 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 GNU CC.
+
+ GNU CC 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.
+
+ GNU CC 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 GNU CC; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ #ifndef GCC_CP_NAME_LOOKUP_H
+ #define GCC_CP_NAME_LOOKUP_H
+
+ #include "c-common.h"
+
+ /* 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;
+
+ /* Nonzero if this binding is for a local scope, as opposed to a class
+ or namespace scope. */
+ #define LOCAL_BINDING_P(NODE) ((NODE)->is_local)
+
+ /* Nonzero if BINDING_VALUE is from a base class of the class which is
+ currently being defined. */
+ #define INHERITED_VALUE_BINDING_P(NODE) ((NODE)->value_is_inherited)
+
+ /* For a binding between a name and an entity at a non-local scope,
+ defines the scope where the binding is declared. (Either a class
+ _TYPE node, or a NAMESPACE_DECL.) This macro should be used only
+ for namespace-level bindings; on the IDENTIFIER_BINDING list
+ BINDING_LEVEL is used instead. */
+ #define BINDING_SCOPE(NODE) ((NODE)->scope.scope)
+
+ /* Nonzero if NODE has BINDING_LEVEL, rather than BINDING_SCOPE. */
+ #define BINDING_HAS_LEVEL_P(NODE) ((NODE)->has_level)
+
+ /* This is the declaration bound to the name. Possible values:
+ variable, overloaded function, namespace, template, enumerator. */
+ #define BINDING_VALUE(NODE) ((NODE)->value)
+
+ /* If name is bound to a type, this is the type (struct, union, enum). */
+ #define BINDING_TYPE(NODE) ((NODE)->type)
+
+ /* Zero out a cxx_binding pointed to by B. */
+ #define cxx_binding_clear(B) memset ((B), 0, sizeof (cxx_binding))
+
+ struct cxx_binding GTY(())
+ {
+ /* Link to chain together various bindings for this name. */
+ cxx_binding *previous;
+ /* The non-type entity this name is bound to. */
+ tree value;
+ /* The type entity this name is bound to. */
+ tree type;
+ union tree_binding_u {
+ tree GTY ((tag ("0"))) scope;
+ struct cp_binding_level * GTY ((tag ("1"))) level;
+ } GTY ((desc ("%0.has_level"))) scope;
+ unsigned has_level : 1;
+ unsigned value_is_inherited : 1;
+ unsigned is_local : 1;
+ };
+
+ extern cxx_binding *cxx_binding_make (tree, tree);
+ extern void cxx_binding_free (cxx_binding *);
+
+
+
+ #endif /* GCC_CP_NAME_LOOKUP_H */
More information about the Gcc-patches
mailing list