* c++: Simplify __FUNCTION__ creation
@ 2020-10-02 12:01 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-10-02 12:01 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
I had reason to wander into cp_make_fname, and noticed it's the only
caller of cp_fname_init. Folding it in makes the code simpler.
gcc/cp/
* cp-tree.h (cp_fname_init): Delete declaration.
* decl.c (cp_fname_init): Merge into only caller ...
(cp_make_fname): ... here & refactor.
pushing to trunk
nathan
--
Nathan Sidwell
[-- Attachment #2: __FUNCTION__.diff --]
[-- Type: text/x-patch, Size: 4252 bytes --]
diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h
index 3ccd54ce24b..aa93b11b91f 100644
--- i/gcc/cp/cp-tree.h
+++ w/gcc/cp/cp-tree.h
@@ -6520,7 +6520,6 @@ extern tree create_implicit_typedef (tree, tree);
extern int local_variable_p (const_tree);
extern tree register_dtor_fn (tree);
extern tmpl_spec_kind current_tmpl_spec_kind (int);
-extern tree cp_fname_init (const char *, tree *);
extern tree cxx_builtin_function (tree decl);
extern tree cxx_builtin_function_ext_scope (tree decl);
extern tree cxx_simulate_builtin_function_decl (tree);
diff --git i/gcc/cp/decl.c w/gcc/cp/decl.c
index d2a8d4012ab..6b306ee4667 100644
--- i/gcc/cp/decl.c
+++ w/gcc/cp/decl.c
@@ -4592,38 +4592,6 @@ cxx_init_decl_processing (void)
using_eh_for_cleanups ();
}
-/* Generate an initializer for a function naming variable from
- NAME. NAME may be NULL, to indicate a dependent name. TYPE_P is
- filled in with the type of the init. */
-
-tree
-cp_fname_init (const char* name, tree *type_p)
-{
- tree domain = NULL_TREE;
- tree type;
- tree init = NULL_TREE;
- size_t length = 0;
-
- if (name)
- {
- length = strlen (name);
- domain = build_index_type (size_int (length));
- init = build_string (length + 1, name);
- }
-
- type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
- type = build_cplus_array_type (type, domain);
-
- *type_p = type;
-
- if (init)
- TREE_TYPE (init) = type;
- else
- init = error_mark_node;
-
- return init;
-}
-
/* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
the decl, LOC is the location to give the decl, NAME is the
initialization string and TYPE_DEP indicates whether NAME depended
@@ -4634,31 +4602,45 @@ cp_fname_init (const char* name, tree *type_p)
static tree
cp_make_fname_decl (location_t loc, tree id, int type_dep)
{
- const char * name = NULL;
- bool release_name = false;
+ tree domain = NULL_TREE;
+ tree init = NULL_TREE;
+
if (!(type_dep && in_template_function ()))
{
+ const char *name = NULL;
+ bool release_name = false;
+
if (current_function_decl == NULL_TREE)
name = "top level";
- else if (type_dep == 1) /* __PRETTY_FUNCTION__ */
- name = cxx_printable_name (current_function_decl, 2);
- else if (type_dep == 0) /* __FUNCTION__ */
+ else if (type_dep == 0)
{
+ /* __FUNCTION__ */
name = fname_as_string (type_dep);
release_name = true;
}
else
- gcc_unreachable ();
+ {
+ /* __PRETTY_FUNCTION__ */
+ gcc_checking_assert (type_dep == 1);
+ name = cxx_printable_name (current_function_decl, 2);
+ }
+
+ size_t length = strlen (name);
+ domain = build_index_type (size_int (length));
+ init = build_string (length + 1, name);
+ if (release_name)
+ free (const_cast<char *> (name));
}
- tree type;
- tree init = cp_fname_init (name, &type);
- tree decl = build_decl (loc, VAR_DECL, id, type);
- if (release_name)
- free (CONST_CAST (char *, name));
+ tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
+ type = build_cplus_array_type (type, domain);
- /* As we're using pushdecl_with_scope, we must set the context. */
- DECL_CONTEXT (decl) = current_function_decl;
+ if (init)
+ TREE_TYPE (init) = type;
+ else
+ init = error_mark_node;
+
+ tree decl = build_decl (loc, VAR_DECL, id, type);
TREE_READONLY (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
@@ -4667,13 +4649,10 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
TREE_USED (decl) = 1;
- if (init)
- {
- SET_DECL_VALUE_EXPR (decl, init);
- DECL_HAS_VALUE_EXPR_P (decl) = 1;
- /* For decl_constant_var_p. */
- DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
- }
+ SET_DECL_VALUE_EXPR (decl, init);
+ DECL_HAS_VALUE_EXPR_P (decl) = 1;
+ /* For decl_constant_var_p. */
+ DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
if (current_function_decl)
{
@@ -4685,7 +4664,7 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
else
{
DECL_THIS_STATIC (decl) = true;
- pushdecl_top_level_and_finish (decl, NULL_TREE);
+ decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
}
return decl;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-02 12:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 12:01 c++: Simplify __FUNCTION__ creation Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).