[C++ PATCH] overloaded operator fns [8/N]

https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00031.html
	* cp-tree.h (enum cp_identifier_kind): Delete cik_newdel_op.
	Renumber and reserve udlit value.
	(IDENTIFIER_NEWDEL_OP): Delete.
	(IDENTIFIER_OVL_OP): New.
	(IDENTIFIER_ASSIGN_OP): Adjust.
	(IDENTIFIER_CONV_OP): Adjust.
	(IDENTIFIER_OVL_OP_INFO): Adjust.
	(IDENTIFIER_OVL_OP_FLAGS): New.
	* decl.c (grokdeclarator): Use IDENTIFIER_OVL_OP_FLAGS.
	* lex.c (get_identifier_kind_name): Adjust.
	(init_operators): Don't special case new/delete ops.
	* mangle.c (write_unqualified_id): Use IDENTIFIER_OVL_OP.
	* pt.c (push_template_decl_real): Use IDENTIFIER_OVL_OP_FLAGS.
	* typeck.c (check_return_expr): Likewise.

From-SVN: r254322
This commit is contained in:
Nathan Sidwell 2017-11-01 18:30:42 +00:00 committed by Nathan Sidwell
parent d4b51b8ba0
commit 183e687af1
7 changed files with 46 additions and 27 deletions

View File

@ -1,5 +1,20 @@
2017-11-01 Nathan Sidwell <nathan@acm.org>
* cp-tree.h (enum cp_identifier_kind): Delete cik_newdel_op.
Renumber and reserve udlit value.
(IDENTIFIER_NEWDEL_OP): Delete.
(IDENTIFIER_OVL_OP): New.
(IDENTIFIER_ASSIGN_OP): Adjust.
(IDENTIFIER_CONV_OP): Adjust.
(IDENTIFIER_OVL_OP_INFO): Adjust.
(IDENTIFIER_OVL_OP_FLAGS): New.
* decl.c (grokdeclarator): Use IDENTIFIER_OVL_OP_FLAGS.
* lex.c (get_identifier_kind_name): Adjust.
(init_operators): Don't special case new/delete ops.
* mangle.c (write_unqualified_id): Use IDENTIFIER_OVL_OP.
* pt.c (push_template_decl_real): Use IDENTIFIER_OVL_OP_FLAGS.
* typeck.c (check_return_expr): Likewise.
* cp-tree.h (assign_op_identifier, call_op_identifier): Use
compressed code.
(struct lang_decl_fn): Use compressed operator code.

View File

@ -996,9 +996,9 @@ enum cp_identifier_kind {
cik_dtor = 3, /* Destructor (in-chg, deleting, complete or
base). */
cik_simple_op = 4, /* Non-assignment operator name. */
cik_newdel_op = 5, /* New or delete operator name. */
cik_assign_op = 6, /* An assignment operator name. */
cik_conv_op = 7, /* Conversion operator name. */
cik_assign_op = 5, /* An assignment operator name. */
cik_conv_op = 6, /* Conversion operator name. */
cik_reserved_for_udlit = 7, /* Not yet in use */
cik_max
};
@ -1053,24 +1053,22 @@ enum cp_identifier_kind {
#define IDENTIFIER_ANY_OP_P(NODE) \
(IDENTIFIER_KIND_BIT_2 (NODE))
/* True if this identifier is for new or delete operator. Value 5. */
#define IDENTIFIER_NEWDEL_OP_P(NODE) \
(IDENTIFIER_KIND_BIT_2 (NODE) \
& (!IDENTIFIER_KIND_BIT_1 (NODE)) \
& IDENTIFIER_KIND_BIT_0 (NODE))
/* True if this identifier is for an overloaded operator. Values 4, 5. */
#define IDENTIFIER_OVL_OP_P(NODE) \
(IDENTIFIER_ANY_OP_P (NODE) \
& (!IDENTIFIER_KIND_BIT_1 (NODE)))
/* True if this identifier is for any assignment. Values 6. */
/* True if this identifier is for any assignment. Values 5. */
#define IDENTIFIER_ASSIGN_OP_P(NODE) \
(IDENTIFIER_KIND_BIT_2 (NODE) \
& IDENTIFIER_KIND_BIT_1 (NODE) \
& (!IDENTIFIER_KIND_BIT_0 (NODE)))
(IDENTIFIER_OVL_OP_P (NODE) \
& IDENTIFIER_KIND_BIT_0 (NODE))
/* True if this identifier is the name of a type-conversion
operator. Value 7. */
#define IDENTIFIER_CONV_OP_P(NODE) \
(IDENTIFIER_KIND_BIT_2 (NODE) \
(IDENTIFIER_ANY_OP_P (NODE) \
& IDENTIFIER_KIND_BIT_1 (NODE) \
& IDENTIFIER_KIND_BIT_0 (NODE))
& (!IDENTIFIER_KIND_BIT_0 (NODE)))
/* Access a C++-specific index for identifier NODE.
Used to optimize operator mappings etc. */
@ -5529,9 +5527,11 @@ extern GTY(()) unsigned char ovl_op_alternate[OVL_OP_MAX];
#define OVL_OP_INFO(IS_ASS_P, TREE_CODE) \
(&ovl_op_info[(IS_ASS_P) != 0][ovl_op_mapping[(TREE_CODE)]])
/* Overloaded operator info for an identifier for which
IDENTIFIER_ANY_OP_P is true. */
IDENTIFIER_OVL_OP_P is true. */
#define IDENTIFIER_OVL_OP_INFO(NODE) \
(&ovl_op_info[IDENTIFIER_ASSIGN_OP_P (NODE)][IDENTIFIER_CP_INDEX (NODE)])
(&ovl_op_info[IDENTIFIER_KIND_BIT_0 (NODE)][IDENTIFIER_CP_INDEX (NODE)])
#define IDENTIFIER_OVL_OP_FLAGS(NODE) \
(IDENTIFIER_OVL_OP_INFO (NODE)->flags)
/* A type-qualifier, or bitmask therefore, using the TYPE_QUAL
constants. */

View File

@ -11744,7 +11744,8 @@ grokdeclarator (const cp_declarator *declarator,
if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
&& !(identifier_p (unqualified_id)
&& IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
&& IDENTIFIER_OVL_OP_P (unqualified_id)
&& (IDENTIFIER_OVL_OP_FLAGS (unqualified_id) & OVL_OP_FLAG_ALLOC)))
{
cp_cv_quals real_quals = memfn_quals;
if (cxx_dialect < cxx14 && constexpr_p
@ -11857,7 +11858,9 @@ grokdeclarator (const cp_declarator *declarator,
if (virtualp
&& identifier_p (unqualified_id)
&& IDENTIFIER_NEWDEL_OP_P (unqualified_id))
&& IDENTIFIER_OVL_OP_P (unqualified_id)
&& (IDENTIFIER_OVL_OP_FLAGS (unqualified_id)
& OVL_OP_FLAG_ALLOC))
{
error ("%qD cannot be declared %<virtual%>, since it "
"is always static", unqualified_id);

View File

@ -100,7 +100,8 @@ get_identifier_kind_name (tree id)
/* Keep in sync with cp_id_kind enumeration. */
static const char *const names[cik_max] = {
"normal", "keyword", "constructor", "destructor",
"assign-op", "op-assign-op", "simple-op", "conv-op", };
"simple-op", "assign-op", "conv-op", "<reserved>udlit-op"
};
unsigned kind = 0;
kind |= IDENTIFIER_KIND_BIT_2 (id) << 2;
@ -176,9 +177,7 @@ init_operators (void)
else
{
IDENTIFIER_CP_INDEX (ident) = ix;
set_identifier_kind (ident,
op_ptr->flags & OVL_OP_FLAG_ALLOC
? cik_newdel_op : cik_simple_op);
set_identifier_kind (ident, cik_simple_op);
}
}
if (op_ptr->tree_code)

View File

@ -1263,7 +1263,7 @@ write_unqualified_id (tree identifier)
{
if (IDENTIFIER_CONV_OP_P (identifier))
write_conversion_operator_name (TREE_TYPE (identifier));
else if (IDENTIFIER_ANY_OP_P (identifier))
else if (IDENTIFIER_OVL_OP_P (identifier))
{
const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (identifier);
write_string (ovl_op->mangled_name);

View File

@ -5329,7 +5329,9 @@ push_template_decl_real (tree decl, bool is_friend)
error ("destructor %qD declared as member template", decl);
return error_mark_node;
}
if (IDENTIFIER_NEWDEL_OP_P (DECL_NAME (decl))
if (IDENTIFIER_OVL_OP_P (DECL_NAME (decl))
&& (IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (decl))
& OVL_OP_FLAG_ALLOC)
&& (!prototype_p (TREE_TYPE (decl))
|| TYPE_ARG_TYPES (TREE_TYPE (decl)) == void_list_node
|| !TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))

View File

@ -9073,9 +9073,9 @@ check_return_expr (tree retval, bool *no_warning)
}
/* Only operator new(...) throw(), can return NULL [expr.new/13]. */
if (DECL_OVERLOADED_OPERATOR_P (current_function_decl)
&& (DECL_OVERLOADED_OPERATOR_IS (current_function_decl, NEW_EXPR)
|| DECL_OVERLOADED_OPERATOR_IS (current_function_decl, VEC_NEW_EXPR))
if (IDENTIFIER_OVL_OP_P (DECL_NAME (current_function_decl))
&& ((IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (current_function_decl))
& (OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE)) == OVL_OP_FLAG_ALLOC)
&& !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
&& ! flag_check_new
&& retval && null_ptr_cst_p (retval))