aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-09-24 12:50:29 -0700
committerNathan Sidwell <nathan@acm.org>2020-09-24 12:56:59 -0700
commitd13c0ae859fbb5bb937692548e5860e4cb39e26b (patch)
treea626f5797c0268417dbd9864fe484c1b06c0a1fc /gcc
parent6b6c89b37bc26791943ea79191891e77591de2b8 (diff)
downloadgcc-d13c0ae859fbb5bb937692548e5860e4cb39e26b.zip
gcc-d13c0ae859fbb5bb937692548e5860e4cb39e26b.tar.gz
gcc-d13c0ae859fbb5bb937692548e5860e4cb39e26b.tar.bz2
c++: Cleanup some decl pushing apis
In cleaning up local decl handling, here's an initial patch that takes advantage of C++'s default args for the is_friend parm of pushdecl, duplicate_decls and push_template_decl_real and the scope & tpl_header parms of xref_tag. Then many of the calls simply not mention these. I also rename push_template_decl_real to push_template_decl, deleting the original forwarding function. This'll make my later patches changing their types less intrusive. There are 2 functional changes: 1) push_template_decl requires is_friend to be correct, it doesn't go checking for a friend function (an assert is added). 2) debug_overload prints out Hidden and Using markers for the overload set. gcc/cp/ * cp-tree.h (duplicate_decls): Default is_friend to false. (xref_tag): Default tag_scope & tpl_header_p to ts_current & false. (push_template_decl_real): Default is_friend to false. Rename to ... (push_template_decl): ... here. Delete original decl. * name-lookup.h (pushdecl_namespace_level): Default is_friend to false. (pushtag): Default tag_scope to ts_current. * coroutines.cc (morph_fn_to_coro): Drop default args to xref_tag. * decl.c (start_decl): Drop default args to duplicate_decls. (start_enum): Drop default arg to pushtag & xref_tag. (start_preparsed_function): Pass DECL_FRIEND_P to push_template_decl. (grokmethod): Likewise. * friend.c (do_friend): Rename push_template_decl_real calls. * lambda.c (begin_lamnbda_type): Drop default args to xref_tag. (vla_capture_type): Likewise. * name-lookup.c (maybe_process_template_type_declaration): Rename push_template_decl_real call. (pushdecl_top_level_and_finish): Drop default arg to pushdecl_namespace_level. * pt.c (push_template_decl_real): Assert no surprising friend functions. Rename to ... (push_template_decl): ... here. Delete original function. (lookup_template_class_1): Drop default args from pushtag. (instantiate_class_template_1): Likewise. * ptree.c (debug_overload): Print hidden and using markers. * rtti.c (init_rtti_processing): Drop refault args from xref_tag. (build_dynamic_cast_1, tinfo_base_init): Likewise. * semantics.c (begin_class_definition): Drop default args to pushtag. gcc/objcp/ * objcp-decl.c (objcp_start_struct): Drop default args to xref_tag. (objcp_xref_tag): Likewise. libcc1/ * libcp1plugin.cc (supplement_binding): Drop default args to duplicate_decls. (safe_pushtag): Drop scope parm. Drop default args to pushtag. (safe_pushdecl_maybe_friend): Rename to ... (safe_pushdecl): ... here. Drop is_friend parm. Drop default args to pushdecl. (plugin_build_decl): Adjust safe_pushdecl & safe_pushtag calls. (plugin_build_constant): Adjust safe_pushdecl call.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/coroutines.cc2
-rw-r--r--gcc/cp/cp-tree.h10
-rw-r--r--gcc/cp/decl.c15
-rw-r--r--gcc/cp/friend.c4
-rw-r--r--gcc/cp/lambda.c5
-rw-r--r--gcc/cp/name-lookup.c8
-rw-r--r--gcc/cp/name-lookup.h4
-rw-r--r--gcc/cp/pt.c19
-rw-r--r--gcc/cp/ptree.c6
-rw-r--r--gcc/cp/rtti.c11
-rw-r--r--gcc/cp/semantics.c4
-rw-r--r--gcc/objcp/objcp-decl.c4
12 files changed, 43 insertions, 49 deletions
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 898b88b..ba81345 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4011,7 +4011,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
/* 2. Types we need to define or look up. */
tree fr_name = get_fn_local_identifier (orig, "frame");
- tree coro_frame_type = xref_tag (record_type, fr_name, ts_current, false);
+ tree coro_frame_type = xref_tag (record_type, fr_name);
DECL_CONTEXT (TYPE_NAME (coro_frame_type)) = current_scope ();
tree coro_frame_ptr = build_pointer_type (coro_frame_type);
tree act_des_fn_type
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 029a165..3ae4874 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6461,7 +6461,8 @@ extern void note_iteration_stmt_body_end (bool);
extern void determine_local_discriminator (tree);
extern int decls_match (tree, tree, bool = true);
extern bool maybe_version_functions (tree, tree, bool);
-extern tree duplicate_decls (tree, tree, bool);
+extern tree duplicate_decls (tree, tree,
+ bool is_friend = false);
extern tree declare_local_label (tree);
extern tree define_label (location_t, tree);
extern void check_goto (tree);
@@ -6501,7 +6502,9 @@ extern tree get_scope_of_declarator (const cp_declarator *);
extern void grok_special_member_properties (tree);
extern bool grok_ctor_properties (const_tree, const_tree);
extern bool grok_op_properties (tree, bool);
-extern tree xref_tag (enum tag_types, tree, tag_scope, bool);
+extern tree xref_tag (tag_types, tree,
+ tag_scope = ts_current,
+ bool tpl_header_p = false);
extern void xref_basetypes (tree, tree);
extern tree start_enum (tree, tree, tree, tree, bool, bool *);
extern void finish_enum_value_list (tree);
@@ -6849,8 +6852,7 @@ extern void end_template_parm_list (void);
extern void end_template_decl (void);
extern tree maybe_update_decl_type (tree, tree);
extern bool check_default_tmpl_args (tree, tree, bool, bool, int);
-extern tree push_template_decl (tree);
-extern tree push_template_decl_real (tree, bool);
+extern tree push_template_decl (tree, bool is_friend = false);
extern tree add_inherited_template_parms (tree, tree);
extern void template_parm_level_and_index (tree, int*, int*);
extern bool redeclare_class_template (tree, tree, tree);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index f3fdfe3..6019051 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5361,8 +5361,7 @@ start_decl (const cp_declarator *declarator,
about this situation, and so we check here. */
if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
error ("duplicate initialization of %qD", decl);
- field = duplicate_decls (decl, field,
- /*newdecl_is_friend=*/false);
+ field = duplicate_decls (decl, field);
if (field == error_mark_node)
return error_mark_node;
else if (field)
@@ -5376,8 +5375,7 @@ start_decl (const cp_declarator *declarator,
? current_template_parms
: NULL_TREE);
if (field && field != error_mark_node
- && duplicate_decls (decl, field,
- /*newdecl_is_friend=*/false))
+ && duplicate_decls (decl, field))
decl = field;
}
@@ -15476,7 +15474,7 @@ start_enum (tree name, tree enumtype, tree underlying_type,
|| TREE_CODE (enumtype) != ENUMERAL_TYPE)
{
enumtype = cxx_make_type (ENUMERAL_TYPE);
- enumtype = pushtag (name, enumtype, /*tag_scope=*/ts_current);
+ enumtype = pushtag (name, enumtype);
/* std::byte aliases anything. */
if (enumtype != error_mark_node
@@ -15485,8 +15483,7 @@ start_enum (tree name, tree enumtype, tree underlying_type,
TYPE_ALIAS_SET (enumtype) = 0;
}
else
- enumtype = xref_tag (enum_type, name, /*tag_scope=*/ts_current,
- false);
+ enumtype = xref_tag (enum_type, name);
if (enumtype == error_mark_node)
return error_mark_node;
@@ -16257,7 +16254,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
by push_nested_class.) */
if (processing_template_decl)
{
- tree newdecl1 = push_template_decl (decl1);
+ tree newdecl1 = push_template_decl (decl1, DECL_FRIEND_P (decl1));
if (newdecl1 == error_mark_node)
{
if (ctype || DECL_STATIC_FUNCTION_P (decl1))
@@ -17362,7 +17359,7 @@ grokmethod (cp_decl_specifier_seq *declspecs,
/* We process method specializations in finish_struct_1. */
if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
{
- fndecl = push_template_decl (fndecl);
+ fndecl = push_template_decl (fndecl, DECL_FRIEND_P (fndecl));
if (fndecl == error_mark_node)
return fndecl;
}
diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c
index fa20a93..e484134 100644
--- a/gcc/cp/friend.c
+++ b/gcc/cp/friend.c
@@ -558,7 +558,7 @@ do_friend (tree ctype, tree declarator, tree decl,
else if (class_template_depth)
/* We rely on tsubst_friend_function to check the
validity of the declaration later. */
- decl = push_template_decl_real (decl, /*is_friend=*/true);
+ decl = push_template_decl (decl, /*is_friend=*/true);
else
decl = check_classfn (ctype, decl,
template_member_p
@@ -611,7 +611,7 @@ do_friend (tree ctype, tree declarator, tree decl,
general, such a declaration depends on template
parameters. Instead, we call pushdecl when the class
is instantiated. */
- decl = push_template_decl_real (decl, /*is_friend=*/true);
+ decl = push_template_decl (decl, /*is_friend=*/true);
else if (current_function_decl)
/* pushdecl will check there's a local decl already. */
decl = pushdecl (decl, /*is_friend=*/true);
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 7fccccc..07a5401 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -134,8 +134,7 @@ begin_lambda_type (tree lambda)
IDENTIFIER_LAMBDA_P (name) = true;
/* Create the new RECORD_TYPE for this lambda. */
- tree type = xref_tag (/*tag_code=*/record_type, name,
- /*scope=*/ts_current, /*template_header_p=*/false);
+ tree type = xref_tag (/*tag_code=*/record_type, name);
if (type == error_mark_node)
return error_mark_node;
@@ -476,7 +475,7 @@ static GTY(()) tree max_id;
static tree
vla_capture_type (tree array_type)
{
- tree type = xref_tag (record_type, make_anon_name (), ts_current, false);
+ tree type = xref_tag (record_type, make_anon_name ());
xref_basetypes (type, NULL_TREE);
type = begin_class_definition (type);
if (!ptr_id)
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index bbeaf64..e7764ab 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -6723,11 +6723,11 @@ maybe_process_template_type_declaration (tree type, int is_friend,
if (processing_template_decl)
{
- /* This may change after the call to
- push_template_decl_real, but we want the original value. */
+ /* This may change after the call to push_template_decl, but
+ we want the original value. */
tree name = DECL_NAME (decl);
- decl = push_template_decl_real (decl, is_friend);
+ decl = push_template_decl (decl, is_friend);
if (decl == error_mark_node)
return error_mark_node;
@@ -7301,7 +7301,7 @@ pushdecl_top_level_and_finish (tree x, tree init)
{
bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
do_push_to_top_level ();
- x = pushdecl_namespace_level (x, false);
+ x = pushdecl_namespace_level (x);
cp_finish_decl (x, init, false, NULL_TREE, 0);
do_pop_from_top_level ();
timevar_cond_stop (TV_NAME_LOOKUP, subtime);
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index 5d2d364f..76ec8f2 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -341,7 +341,7 @@ extern tree lookup_qualified_name (tree scope, const char *name,
bool = true);
extern bool is_local_extern (tree);
extern bool pushdecl_class_level (tree);
-extern tree pushdecl_namespace_level (tree, bool);
+extern tree pushdecl_namespace_level (tree, bool is_friend = false);
extern bool push_class_level_binding (tree, tree);
extern tree get_local_decls ();
extern int function_parm_depth (void);
@@ -371,7 +371,7 @@ extern tree pushdecl (tree, bool is_friend = false);
extern tree pushdecl_outermost_localscope (tree);
extern tree pushdecl_top_level (tree, bool is_friend = false);
extern tree pushdecl_top_level_and_finish (tree, tree);
-extern tree pushtag (tree, tree, tag_scope);
+extern tree pushtag (tree, tree, tag_scope = ts_current);
extern int push_namespace (tree, bool make_inline = false);
extern void pop_namespace (void);
extern void push_nested_namespace (tree);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 62e8509..6f8dbc3 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5669,7 +5669,7 @@ template_parm_outer_level (tree t, void *data)
If IS_FRIEND is true, DECL is a friend declaration. */
tree
-push_template_decl_real (tree decl, bool is_friend)
+push_template_decl (tree decl, bool is_friend)
{
tree tmpl;
tree args;
@@ -5694,8 +5694,10 @@ push_template_decl_real (tree decl, bool is_friend)
&& DECL_TEMPLATE_SPECIALIZATION (decl)
&& TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (decl))));
- if (TREE_CODE (decl) == FUNCTION_DECL && DECL_FRIEND_P (decl))
- is_friend = true;
+ /* No surprising friend functions. */
+ gcc_checking_assert (is_friend
+ || !(TREE_CODE (decl) == FUNCTION_DECL
+ && DECL_FRIEND_P (decl)));
if (is_friend)
/* For a friend, we want the context of the friend, not
@@ -6096,12 +6098,6 @@ push_template_decl_real (tree decl, bool is_friend)
return DECL_TEMPLATE_RESULT (tmpl);
}
-tree
-push_template_decl (tree decl)
-{
- return push_template_decl_real (decl, false);
-}
-
/* FN is an inheriting constructor that inherits from the constructor
template INHERITED; turn FN into a constructor template with a matching
template header. */
@@ -9943,7 +9939,7 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
/* A local class. Make sure the decl gets registered properly. */
if (context == current_function_decl)
- if (pushtag (DECL_NAME (gen_tmpl), t, /*tag_scope=*/ts_current)
+ if (pushtag (DECL_NAME (gen_tmpl), t)
== error_mark_node)
return error_mark_node;
@@ -11897,7 +11893,7 @@ instantiate_class_template_1 (tree type)
tsubst_enum. */
if (name)
SET_IDENTIFIER_TYPE_VALUE (name, newtag);
- pushtag (name, newtag, /*tag_scope=*/ts_current);
+ pushtag (name, newtag);
}
}
else if (DECL_DECLARES_FUNCTION_P (t))
@@ -12077,6 +12073,7 @@ instantiate_class_template_1 (tree type)
/* friend class C<T>; */
friend_type = tsubst (friend_type, args,
tf_warning_or_error, NULL_TREE);
+
/* Otherwise it's
friend class C;
diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c
index 11833e3..a28b722 100644
--- a/gcc/cp/ptree.c
+++ b/gcc/cp/ptree.c
@@ -332,8 +332,12 @@ debug_overload (tree node)
tree decl = *iter;
auto xloc = expand_location (DECL_SOURCE_LOCATION (decl));
auto fullname = decl_as_string (decl, 0);
+ bool using_p = iter.using_p ();
+ bool hidden_p = iter.hidden_p ();
- fprintf (file, "%p: %s:%d:%d \"%s\"\n", (void *)decl,
+ fprintf (file, "%p:%c%c %s:%d:%d \"%s\"\n", (void *)decl,
+ hidden_p ? 'H' : '-',
+ using_p ? 'U' : '-',
xloc.file, xloc.line, xloc.column, fullname);
}
}
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 0ab3c42..7c4bff7 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -169,8 +169,7 @@ init_rtti_processing (void)
tree type_info_type;
push_nested_namespace (std_node);
- type_info_type = xref_tag (class_type, get_identifier ("type_info"),
- /*tag_scope=*/ts_current, false);
+ type_info_type = xref_tag (class_type, get_identifier ("type_info"));
pop_nested_namespace (std_node);
const_type_info_type_node
= cp_build_qualified_type (type_info_type, TYPE_QUAL_CONST);
@@ -761,9 +760,7 @@ build_dynamic_cast_1 (location_t loc, tree type, tree expr,
push_abi_namespace ();
tinfo_ptr = xref_tag (class_type,
- get_identifier ("__class_type_info"),
- /*tag_scope=*/ts_current, false);
-
+ get_identifier ("__class_type_info"));
tinfo_ptr = build_pointer_type
(cp_build_qualified_type
(tinfo_ptr, TYPE_QUAL_CONST));
@@ -948,10 +945,8 @@ tinfo_base_init (tinfo_s *ti, tree target)
vtable_ptr = ti->vtable;
if (!vtable_ptr)
{
- tree real_type;
push_abi_namespace ();
- real_type = xref_tag (class_type, ti->name,
- /*tag_scope=*/ts_current, false);
+ tree real_type = xref_tag (class_type, ti->name);
pop_abi_namespace ();
if (!COMPLETE_TYPE_P (real_type))
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 11996c9..b093044 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3216,13 +3216,13 @@ begin_class_definition (tree t)
if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
{
t = make_class_type (RECORD_TYPE);
- pushtag (make_anon_name (), t, /*tag_scope=*/ts_current);
+ pushtag (make_anon_name (), t);
}
if (TYPE_BEING_DEFINED (t))
{
t = make_class_type (TREE_CODE (t));
- pushtag (TYPE_IDENTIFIER (t), t, /*tag_scope=*/ts_current);
+ pushtag (TYPE_IDENTIFIER (t), t);
}
maybe_process_partial_specialization (t);
pushclass (t);
diff --git a/gcc/objcp/objcp-decl.c b/gcc/objcp/objcp-decl.c
index 9ae7f23..087b5d5 100644
--- a/gcc/objcp/objcp-decl.c
+++ b/gcc/objcp/objcp-decl.c
@@ -41,7 +41,7 @@ objcp_start_struct (location_t loc ATTRIBUTE_UNUSED,
if (!name)
name = make_anon_name ();
- s = xref_tag (record_type, name, ts_global, 0);
+ s = xref_tag (record_type, name, ts_global);
CLASSTYPE_DECLARED_CLASS (s) = 0; /* this is a 'struct', not a 'class'. */
xref_basetypes (s, NULL_TREE); /* no base classes here! */
@@ -84,7 +84,7 @@ objcp_finish_function (void)
tree
objcp_xref_tag (enum tree_code code ATTRIBUTE_UNUSED, tree name)
{
- return xref_tag (record_type, name, ts_global, false);
+ return xref_tag (record_type, name, ts_global);
}
int