This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] C++ builtins go in std and global namespaces
- From: Roger Sayle <roger at eyesopen dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 3 Dec 2001 21:12:43 -0700 (MST)
- Subject: [PATCH] C++ builtins go in std and global namespaces
This patch changes the C++ front-end to declare builtins not prefixed
with an underscore in both the global and std namespaces. This is
needed as the location of a builtin depends upon the header file used
to declare it, #include <string.h> defines ::strlen, where as #include
<cstring> defines std::strlen.
At the moment, this fix is moot as builtins are currently disabled in
the C++ front-end. However accepting this patch now will simplify the
process of reviewing a patch to enable builtins in C++, once all of
the type-checking and semantic issues have been fixed (basically the
DECL_ANTICIPATED flag needs to be honored, so that a builtin doesn't
exist until it is prototyped).
Tested by "make bootstrap" and "make -k check" on i686-pc-linux-gnu
with no new regressions, both with and without builtins disabled in
the C++ front-end. There will be a large number of testcases once
C++ builtins are re-enabled. Ok for mainline?
2001-12-03 Roger Sayle <roger@eyesopen.com>
* cp/decl.c (builtin_function_1): New function to create a
builtin in the current namespace (formerly builtin_function).
(buitin_function): Use it to create builtins in the global
and std namespaces if appropriate.
*** gcc/gcc/cp/decl.c Mon Dec 3 09:56:48 2001
--- patch5/gcc/cp/decl.c Mon Dec 3 16:10:13 2001
*************** static tree lookup_tag PARAMS ((enum tre
*** 84,89 ****
--- 84,91 ----
static void set_identifier_type_value_with_scope
PARAMS ((tree, tree, struct binding_level *));
static void record_unknown_type PARAMS ((tree, const char *));
+ static tree builtin_function_1 PARAMS ((const char *, tree, int,
+ enum built_in_class, const char *));
static tree build_library_fn_1 PARAMS ((tree, enum tree_code, tree));
static int member_function_or_else PARAMS ((tree, tree, enum overload_flags));
static void bad_specifiers PARAMS ((tree, const char *, int, int, int, int,
*************** cp_make_fname_decl (id, type_dep)
*** 6706,6714 ****
return decl;
}
! /* Entry point for the benefit of c_common_nodes_and_builtins.
!
! Make a definition for a builtin function named NAME and whose data type
is TYPE. TYPE should be a function type with argument types.
CLASS and CODE tell later passes how to compile calls to this function.
--- 6708,6714 ----
return decl;
}
! /* Make a definition for a builtin function named NAME and whose data type
is TYPE. TYPE should be a function type with argument types.
CLASS and CODE tell later passes how to compile calls to this function.
*************** cp_make_fname_decl (id, type_dep)
*** 6717,6724 ****
If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME,
the name to be called if we can't opencode the function. */
! tree
! builtin_function (name, type, code, class, libname)
const char *name;
tree type;
int code;
--- 6717,6724 ----
If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME,
the name to be called if we can't opencode the function. */
! static tree
! builtin_function_1 (name, type, code, class, libname)
const char *name;
tree type;
int code;
*************** builtin_function (name, type, code, clas
*** 6729,6746 ****
DECL_BUILT_IN_CLASS (decl) = class;
DECL_FUNCTION_CODE (decl) = code;
- my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392);
-
- /* All builtins that don't begin with an `_' should go in the `std'
- namespace. */
- if (name[0] != '_')
- {
- push_namespace (std_identifier);
- DECL_CONTEXT (decl) = std_node;
- }
pushdecl (decl);
- if (name[0] != '_')
- pop_namespace ();
/* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
we cannot change DECL_ASSEMBLER_NAME until we have installed this
--- 6729,6735 ----
*************** builtin_function (name, type, code, clas
*** 6759,6764 ****
--- 6748,6784 ----
return decl;
}
+
+ /* Entry point for the benefit of c_common_nodes_and_builtins.
+ This function wraps the function builtin_function_1 so that
+ the appropriate functions can be entered in both the global
+ and standard namespaces. */
+
+ tree
+ builtin_function (name, type, code, class, libname)
+ const char *name;
+ tree type;
+ int code;
+ enum built_in_class class;
+ const char *libname;
+ {
+ tree decl;
+
+ /* All builtins that don't begin with an `_' should additionally
+ go in the `std' namespace. */
+ if (name[0] != '_')
+ {
+ push_namespace (std_identifier);
+ decl = builtin_function_1 (name, type, code, class, libname);
+ DECL_CONTEXT (decl) = std_node;
+ pop_namespace ();
+ }
+
+ decl = builtin_function_1 (name, type, code, class, libname);
+ my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392);
+ return decl;
+ }
+
/* Generate a FUNCTION_DECL with the typical flags for a runtime library
function. Not called directly. */
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-438-3470