diff mbox series

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

Message ID eda1fe89-a112-6240-b5c6-182cc9a3f98a@acm.org
State New
Headers show
Series [C++] overloaded operator fns [8/N] | expand

Commit Message

Nathan Sidwell Nov. 1, 2017, 6:29 p.m. UTC
This is the last of the overloaded operator reworking.  Now we can 
cheaply go from identifier->overload info, there's no need to specially 
mark identifiers as new or delete operators themselves.  Thus we can 
reorder the cp_identifier_kind enumeration and leave space in it for 
udlit operators.

This patch does that renumbering, and reserves a value for udlit 
operators.  Those are currently detected by string compare, which isn't 
the most satisfactory way to do it.  But it's a change for another day.

nathan

Comments

Jason Merrill Nov. 1, 2017, 8:08 p.m. UTC | #1
On Wed, Nov 1, 2017 at 2:29 PM, Nathan Sidwell <nathan@acm.org> wrote:
> This is the last of the overloaded operator reworking.  Now we can cheaply
> go from identifier->overload info, there's no need to specially mark
> identifiers as new or delete operators themselves.  Thus we can reorder the
> cp_identifier_kind enumeration and leave space in it for udlit operators.
>
> This patch does that renumbering, and reserves a value for udlit operators.
> Those are currently detected by string compare, which isn't the most
> satisfactory way to do it.  But it's a change for another day.

> -    && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
> +    && IDENTIFIER_OVL_OP_P (unqualified_id)
> +    && (IDENTIFIER_OVL_OP_FLAGS (unqualified_id) & OVL_OP_FLAG_ALLOC)))

Why not keep the name IDENTIFIER_NEWDEL_OP_P, which expands to this?

Jason
Nathan Sidwell Nov. 2, 2017, 2:15 p.m. UTC | #2
On 11/01/2017 04:08 PM, Jason Merrill wrote:
> On Wed, Nov 1, 2017 at 2:29 PM, Nathan Sidwell <nathan@acm.org> wrote:

>> -    && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
>> +    && IDENTIFIER_OVL_OP_P (unqualified_id)
>> +    && (IDENTIFIER_OVL_OP_FLAGS (unqualified_id) & OVL_OP_FLAG_ALLOC)))
> 
> Why not keep the name IDENTIFIER_NEWDEL_OP_P, which expands to this?

Hm, I guess that would be better.  This patch does that, and introduces 
IDENTIFIER_NEW_OP_P, for when we just want the new operators.

nathan
diff mbox series

Patch

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.

Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 254314)
+++ cp-tree.h	(working copy)
@@ -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_alte
 #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.  */
Index: decl.c
===================================================================
--- decl.c	(revision 254314)
+++ decl.c	(working copy)
@@ -11744,7 +11744,8 @@  grokdeclarator (const cp_declarator *dec
 
   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 *dec
 
 		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);
Index: lex.c
===================================================================
--- lex.c	(revision 254314)
+++ lex.c	(working copy)
@@ -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)
Index: mangle.c
===================================================================
--- mangle.c	(revision 254314)
+++ mangle.c	(working copy)
@@ -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);
Index: pt.c
===================================================================
--- pt.c	(revision 254314)
+++ pt.c	(working copy)
@@ -5329,7 +5329,9 @@  push_template_decl_real (tree decl, bool
 	      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)))
Index: typeck.c
===================================================================
--- typeck.c	(revision 254314)
+++ typeck.c	(working copy)
@@ -9073,9 +9073,9 @@  check_return_expr (tree retval, bool *no
     }
 
   /* 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))