diff mbox series

[C++] Consistently use FUNC_OR_METHOD_TYPE_P

Message ID 0839714f-4cf8-f56c-377c-8c87d96ae013@oracle.com
State New
Headers show
Series [C++] Consistently use FUNC_OR_METHOD_TYPE_P | expand

Commit Message

Paolo Carlini May 6, 2019, 9:13 a.m. UTC
Hi,

one of most straightforward changes in my pending queue. Tested 
x86_64-linux.

Thanks, Paolo.

/////////////////////
2019-05-06  Paolo Carlini  <paolo.carlini@oracle.com>

	* call.c (build_call_a): Use FUNC_OR_METHOD_TYPE_P.
	* cp-gimplify.c (cp_fold): Likewise.
	* cp-objcp-common.c (cp_type_dwarf_attribute): Likewise.
	* cp-tree.h (TYPE_OBJ_P, TYPE_PTROBV_P): Likewise.
	* cvt.c (perform_qualification_conversions): Likewise.
	* decl.c (grokdeclarator): Likewise.
	* decl2.c (build_memfn_type): Likewise.
	* mangle.c (canonicalize_for_substitution, write_type): Likewise.
	* parser.c (cp_parser_omp_declare_reduction): Likewise.
	* pt.c (check_explicit_specialization, uses_deducible_template_parms,
	check_cv_quals_for_unify, dependent_type_p_r): Likewise.
	* rtti.c (ptr_initializer): Likewise.
	* semantics.c (finish_asm_stmt, finish_offsetof,
	cp_check_omp_declare_reduction): Likewise.
	* tree.c (cp_build_qualified_type_real,
	cp_build_type_attribute_variant, cxx_type_hash_eq,
	cxx_copy_lang_qualifiers, cp_free_lang_data): Likewise.
	* typeck.c (structural_comptypes, convert_arguments,
	cp_build_addr_expr_1, unary_complex_lvalue, cp_build_c_cast,
	cp_build_modify_expr, comp_ptr_ttypes_real, type_memfn_rqual):
	Likewise.

Comments

Jason Merrill May 10, 2019, 2:44 p.m. UTC | #1
On 5/6/19 5:13 AM, Paolo Carlini wrote:
> Hi,
> 
> one of most straightforward changes in my pending queue. Tested 
> x86_64-linux.

OK.

Jason
diff mbox series

Patch

Index: call.c
===================================================================
--- call.c	(revision 266503)
+++ call.c	(working copy)
@@ -357,8 +357,7 @@  build_call_a (tree function, int n, tree *argarray
 
   gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
   fntype = TREE_TYPE (TREE_TYPE (function));
-  gcc_assert (TREE_CODE (fntype) == FUNCTION_TYPE
-	      || TREE_CODE (fntype) == METHOD_TYPE);
+  gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
   result_type = TREE_TYPE (fntype);
   /* An rvalue has no cv-qualifiers.  */
   if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
Index: cp-gimplify.c
===================================================================
--- cp-gimplify.c	(revision 266503)
+++ cp-gimplify.c	(working copy)
@@ -2306,8 +2306,7 @@  cp_fold (tree x)
 
       /* Cope with user tricks that amount to offsetof.  */
       if (op0 != error_mark_node
-	  && TREE_CODE (TREE_TYPE (op0)) != FUNCTION_TYPE
-	  && TREE_CODE (TREE_TYPE (op0)) != METHOD_TYPE)
+	  && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (op0)))
 	{
 	  tree val = get_base_address (op0);
 	  if (val
Index: cp-objcp-common.c
===================================================================
--- cp-objcp-common.c	(revision 266503)
+++ cp-objcp-common.c	(working copy)
@@ -248,8 +248,7 @@  cp_type_dwarf_attribute (const_tree type, int attr
   switch (attr)
     {
     case DW_AT_reference:
-      if ((TREE_CODE (type) == FUNCTION_TYPE
-	   || TREE_CODE (type) == METHOD_TYPE)
+      if (FUNC_OR_METHOD_TYPE_P (type)
 	  && FUNCTION_REF_QUALIFIED (type)
 	  && !FUNCTION_RVALUE_QUALIFIED (type))
 	return 1;
@@ -256,8 +255,7 @@  cp_type_dwarf_attribute (const_tree type, int attr
       break;
 
     case DW_AT_rvalue_reference:
-      if ((TREE_CODE (type) == FUNCTION_TYPE
-	   || TREE_CODE (type) == METHOD_TYPE)
+      if (FUNC_OR_METHOD_TYPE_P (type)
 	  && FUNCTION_REF_QUALIFIED (type)
 	  && FUNCTION_RVALUE_QUALIFIED (type))
 	return 1;
Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 266503)
+++ cp-tree.h	(working copy)
@@ -4313,8 +4313,7 @@  more_aggr_init_expr_args_p (const aggr_init_expr_a
 #define TYPE_OBJ_P(NODE)			\
   (!TYPE_REF_P (NODE)				\
    && !VOID_TYPE_P (NODE)  		        \
-   && TREE_CODE (NODE) != FUNCTION_TYPE		\
-   && TREE_CODE (NODE) != METHOD_TYPE)
+   && !FUNC_OR_METHOD_TYPE_P (NODE))
 
 /* Returns true if NODE is a pointer to an object.  Keep these checks
    in ascending tree code order.  */
@@ -4330,8 +4329,7 @@  more_aggr_init_expr_args_p (const aggr_init_expr_a
    void.  Keep these checks in ascending tree code order.  */
 #define TYPE_PTROBV_P(NODE)					\
   (TYPE_PTR_P (NODE)						\
-   && !(TREE_CODE (TREE_TYPE (NODE)) == FUNCTION_TYPE		\
-	|| TREE_CODE (TREE_TYPE (NODE)) == METHOD_TYPE))
+   && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (NODE)))
 
 /* Returns true if NODE is a pointer to function type.  */
 #define TYPE_PTRFN_P(NODE)				\
Index: cvt.c
===================================================================
--- cvt.c	(revision 266503)
+++ cvt.c	(working copy)
@@ -1979,8 +1979,7 @@  perform_qualification_conversions (tree type, tree
 bool
 tx_safe_fn_type_p (tree t)
 {
-  if (TREE_CODE (t) != FUNCTION_TYPE
-      && TREE_CODE (t) != METHOD_TYPE)
+  if (!FUNC_OR_METHOD_TYPE_P (t))
     return false;
   return !!lookup_attribute ("transaction_safe", TYPE_ATTRIBUTES (t));
 }
Index: decl.c
===================================================================
--- decl.c	(revision 266503)
+++ decl.c	(working copy)
@@ -11707,8 +11707,7 @@  grokdeclarator (const cp_declarator *declarator,
     }
 
   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
-      && TREE_CODE (type) != FUNCTION_TYPE
-      && TREE_CODE (type) != METHOD_TYPE
+      && !FUNC_OR_METHOD_TYPE_P (type)
       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
     {
       error ("template-id %qD used as a declarator",
@@ -11866,8 +11865,7 @@  grokdeclarator (const cp_declarator *declarator,
 	  error ("non-object member %qs cannot be declared %<mutable%>", name);
 	  storage_class = sc_none;
 	}
-      else if (TREE_CODE (type) == FUNCTION_TYPE
-	       || TREE_CODE (type) == METHOD_TYPE)
+      else if (FUNC_OR_METHOD_TYPE_P (type))
 	{
 	  error ("function %qs cannot be declared %<mutable%>", name);
 	  storage_class = sc_none;
@@ -12550,8 +12547,7 @@  grokdeclarator (const cp_declarator *declarator,
 			    declspecs->locations);
 	  }
       }
-    else if (TREE_CODE (type) == FUNCTION_TYPE
-	     || TREE_CODE (type) == METHOD_TYPE)
+    else if (FUNC_OR_METHOD_TYPE_P (type))
       {
 	tree original_name;
 	int publicp = 0;
Index: decl2.c
===================================================================
--- decl2.c	(revision 266503)
+++ decl2.c	(working copy)
@@ -158,8 +158,7 @@  build_memfn_type (tree fntype, tree ctype, cp_cv_q
   if (fntype == error_mark_node || ctype == error_mark_node)
     return error_mark_node;
 
-  gcc_assert (TREE_CODE (fntype) == FUNCTION_TYPE
-	      || TREE_CODE (fntype) == METHOD_TYPE);
+  gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype));
 
   cp_cv_quals type_quals = quals & ~TYPE_QUAL_RESTRICT;
   ctype = cp_build_qualified_type (ctype, type_quals);
Index: mangle.c
===================================================================
--- mangle.c	(revision 266503)
+++ mangle.c	(working copy)
@@ -414,8 +414,7 @@  canonicalize_for_substitution (tree node)
       else
 	node = cp_build_qualified_type (TYPE_MAIN_VARIANT (node),
 					cp_type_quals (node));
-      if (TREE_CODE (node) == FUNCTION_TYPE
-	  || TREE_CODE (node) == METHOD_TYPE)
+      if (FUNC_OR_METHOD_TYPE_P (node))
 	{
 	  node = build_ref_qualified_type (node, type_memfn_rqual (orig));
 	  tree r = canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (orig));
@@ -2071,8 +2070,7 @@  write_type (tree type)
 	  t = cp_build_type_attribute_variant (t, attrs);
 	}
       gcc_assert (t != type);
-      if (TREE_CODE (t) == FUNCTION_TYPE
-	  || TREE_CODE (t) == METHOD_TYPE)
+      if (FUNC_OR_METHOD_TYPE_P (t))
 	{
 	  t = build_ref_qualified_type (t, type_memfn_rqual (type));
 	  if (flag_noexcept_type)
@@ -2103,8 +2101,7 @@  write_type (tree type)
 
       /* See through any typedefs.  */
       type = TYPE_MAIN_VARIANT (type);
-      if (TREE_CODE (type) == FUNCTION_TYPE
-	  || TREE_CODE (type) == METHOD_TYPE)
+      if (FUNC_OR_METHOD_TYPE_P (type))
 	type = cxx_copy_lang_qualifiers (type, type_orig);
 
       /* According to the C++ ABI, some library classes are passed the
Index: parser.c
===================================================================
--- parser.c	(revision 266503)
+++ parser.c	(working copy)
@@ -39145,8 +39145,7 @@  cp_parser_omp_declare_reduction (cp_parser *parser
 			   || id_equal (orig_reduc_id, "max")))))
 	error_at (loc, "predeclared arithmetic type %qT in "
 		       "%<#pragma omp declare reduction%>", type);
-      else if (TREE_CODE (type) == FUNCTION_TYPE
-	       || TREE_CODE (type) == METHOD_TYPE
+      else if (FUNC_OR_METHOD_TYPE_P (type)
 	       || TREE_CODE (type) == ARRAY_TYPE)
 	error_at (loc, "function or array type %qT in "
 		       "%<#pragma omp declare reduction%>", type);
Index: pt.c
===================================================================
--- pt.c	(revision 266503)
+++ pt.c	(working copy)
@@ -2858,8 +2858,7 @@  check_explicit_specialization (tree declarator,
 
   if ((specialization || member_specialization)
       /* This doesn't apply to variable templates.  */
-      && (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE
-          || TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE))
+      && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (decl)))
     {
       tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
       for (; t; t = TREE_CHAIN (t))
@@ -20422,8 +20421,7 @@  uses_deducible_template_parms (tree type)
   /* type (T)
      T()
      T(T)  */
-  if (TREE_CODE (type) == FUNCTION_TYPE
-      || TREE_CODE (type) == METHOD_TYPE)
+  if (FUNC_OR_METHOD_TYPE_P (type))
     {
       if (uses_deducible_template_parms (TREE_TYPE (type)))
 	return true;
@@ -21379,8 +21377,7 @@  check_cv_quals_for_unify (int strict, tree arg, tr
 	  It is ok when we're allowing additional CV qualifiers
 	  at the outer level [14.8.2.1]/3,1st bullet.  */
       if ((TYPE_REF_P (arg)
-	   || TREE_CODE (arg) == FUNCTION_TYPE
-	   || TREE_CODE (arg) == METHOD_TYPE)
+	   || FUNC_OR_METHOD_TYPE_P (arg))
 	  && (parm_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)))
 	return 0;
 
@@ -24960,8 +24957,7 @@  dependent_type_p_r (tree type)
 					   (type)));
   else if (INDIRECT_TYPE_P (type))
     return dependent_type_p (TREE_TYPE (type));
-  else if (TREE_CODE (type) == FUNCTION_TYPE
-	   || TREE_CODE (type) == METHOD_TYPE)
+  else if (FUNC_OR_METHOD_TYPE_P (type))
     {
       tree arg_type;
 
Index: rtti.c
===================================================================
--- rtti.c	(revision 266503)
+++ rtti.c	(working copy)
@@ -1015,8 +1015,7 @@  ptr_initializer (tinfo_s *ti, tree target)
       to = tx_unsafe_fn_variant (to);
     }
   if (flag_noexcept_type
-      && (TREE_CODE (to) == FUNCTION_TYPE
-	  || TREE_CODE (to) == METHOD_TYPE)
+      && FUNC_OR_METHOD_TYPE_P (to)
       && TYPE_NOTHROW_P (to))
     {
       flags |= 0x40;
Index: semantics.c
===================================================================
--- semantics.c	(revision 266503)
+++ semantics.c	(working copy)
@@ -1528,8 +1528,7 @@  finish_asm_stmt (int volatile_p, tree string, tree
 		  || CP_TYPE_CONST_P (TREE_TYPE (operand))
 		  /* Functions are not modifiable, even though they are
 		     lvalues.  */
-		  || TREE_CODE (TREE_TYPE (operand)) == FUNCTION_TYPE
-		  || TREE_CODE (TREE_TYPE (operand)) == METHOD_TYPE
+		  || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
 		  /* If it's an aggregate and any field is const, then it is
 		     effectively const.  */
 		  || (CLASS_TYPE_P (TREE_TYPE (operand))
@@ -4063,8 +4062,7 @@  finish_offsetof (tree object_ptr, tree expr, locat
 	      TREE_OPERAND (expr, 2));
       return error_mark_node;
     }
-  if (TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
-      || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE
+  if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
       || TREE_TYPE (expr) == unknown_type_node)
     {
       while (TREE_CODE (expr) == COMPONENT_REF
@@ -5455,8 +5453,7 @@  cp_check_omp_declare_reduction (tree udr)
 	  return;
 	}
     }
-  else if (TREE_CODE (type) == FUNCTION_TYPE
-	   || TREE_CODE (type) == METHOD_TYPE
+  else if (FUNC_OR_METHOD_TYPE_P (type)
 	   || TREE_CODE (type) == ARRAY_TYPE)
     {
       error_at (loc, "function or array type %qT in "
Index: tree.c
===================================================================
--- tree.c	(revision 266503)
+++ tree.c	(working copy)
@@ -1306,8 +1306,7 @@  cp_build_qualified_type_real (tree type,
      (in CD1) we always ignore extra cv-quals on functions.  */
   if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
       && (TYPE_REF_P (type)
-	  || TREE_CODE (type) == FUNCTION_TYPE
-	  || TREE_CODE (type) == METHOD_TYPE))
+	  || FUNC_OR_METHOD_TYPE_P (type)))
     {
       if (TYPE_REF_P (type))
 	bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
@@ -4723,8 +4722,7 @@  cp_build_type_attribute_variant (tree type, tree a
   tree new_type;
 
   new_type = build_type_attribute_variant (type, attributes);
-  if (TREE_CODE (new_type) == FUNCTION_TYPE
-      || TREE_CODE (new_type) == METHOD_TYPE)
+  if (FUNC_OR_METHOD_TYPE_P (new_type))
     gcc_checking_assert (cxx_type_hash_eq (type, new_type));
 
   /* Making a new main variant of a class type is broken.  */
@@ -4739,8 +4737,7 @@  cp_build_type_attribute_variant (tree type, tree a
 bool
 cxx_type_hash_eq (const_tree typea, const_tree typeb)
 {
-  gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE
-	      || TREE_CODE (typea) == METHOD_TYPE);
+  gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
 
   if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
     return false;
@@ -4757,7 +4754,7 @@  tree
 cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
 {
   tree type = CONST_CAST_TREE (typea);
-  if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
+  if (FUNC_OR_METHOD_TYPE_P (type))
     type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
 				    TYPE_RAISES_EXCEPTIONS (typeb),
 				    TYPE_HAS_LATE_RETURN_TYPE (typeb));
@@ -5360,8 +5357,7 @@  cp_fix_function_decl_p (tree decl)
 void
 cp_free_lang_data (tree t)
 {
-  if (TREE_CODE (t) == METHOD_TYPE
-      || TREE_CODE (t) == FUNCTION_TYPE)
+  if (FUNC_OR_METHOD_TYPE_P (t))
     {
       /* Default args are not interesting anymore.  */
       tree argtypes = TYPE_ARG_TYPES (t);
Index: typeck.c
===================================================================
--- typeck.c	(revision 266503)
+++ typeck.c	(working copy)
@@ -1261,8 +1261,7 @@  structural_comptypes (tree t1, tree t2, int strict
     return false;
   /* Need to check this before TYPE_MAIN_VARIANT.
      FIXME function qualifiers should really change the main variant.  */
-  if (TREE_CODE (t1) == FUNCTION_TYPE
-      || TREE_CODE (t1) == METHOD_TYPE)
+  if (FUNC_OR_METHOD_TYPE_P (t1))
     {
       if (type_memfn_rqual (t1) != type_memfn_rqual (t2))
 	return false;
@@ -3990,8 +3989,7 @@  convert_arguments (tree typelist, vec<tree, va_gc>
       if (type == 0 || !TYPE_REF_P (type))
 	{
 	  if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
-	      || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
-	      || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
+	      || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (val)))
 	    val = decay_conversion (val, complain);
 	}
 
@@ -5949,8 +5947,7 @@  cp_build_addr_expr_1 (tree arg, bool strict_lvalue
 
   /* Anything not already handled and not a true memory reference
      is an error.  */
-  if (TREE_CODE (argtype) != FUNCTION_TYPE
-      && TREE_CODE (argtype) != METHOD_TYPE)
+  if (!FUNC_OR_METHOD_TYPE_P (argtype))
     {
       cp_lvalue_kind kind = lvalue_kind (arg);
       if (kind == clk_none)
@@ -6526,8 +6523,7 @@  unary_complex_lvalue (enum tree_code code, tree ar
       return arg;
     }
 
-  if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE
-      || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE
+  if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (arg))
       || TREE_CODE (arg) == OFFSET_REF)
     return NULL_TREE;
 
@@ -7887,8 +7883,7 @@  cp_build_c_cast (tree type, tree expr, tsubst_flag
 	}
     }
 
-  if (TREE_CODE (type) == FUNCTION_TYPE
-      || TREE_CODE (type) == METHOD_TYPE)
+  if (FUNC_OR_METHOD_TYPE_P (type))
     {
       if (complain & tf_error)
         error ("invalid cast to function type %qT", type);
@@ -8235,8 +8230,7 @@  cp_build_modify_expr (location_t loc, tree lhs, en
       && (TREE_READONLY (lhs) || CP_TYPE_CONST_P (lhstype)
 	  /* Functions are not modifiable, even though they are
 	     lvalues.  */
-	  || TREE_CODE (TREE_TYPE (lhs)) == FUNCTION_TYPE
-	  || TREE_CODE (TREE_TYPE (lhs)) == METHOD_TYPE
+	  || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (lhs))
 	  /* If it's an aggregate and any field is const, then it is
 	     effectively const.  */
 	  || (CLASS_TYPE_P (lhstype)
@@ -9714,7 +9708,7 @@  comp_ptr_ttypes_real (tree to, tree from, int cons
 
       /* Const and volatile mean something different for function types,
 	 so the usual checks are not appropriate.  */
-      if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
+      if (!FUNC_OR_METHOD_TYPE_P (to))
 	{
 	  if (!at_least_as_qualified_p (to, from))
 	    return 0;
@@ -9890,8 +9884,7 @@  cp_type_quals (const_tree type)
 cp_ref_qualifier
 type_memfn_rqual (const_tree type)
 {
-  gcc_assert (TREE_CODE (type) == FUNCTION_TYPE
-              || TREE_CODE (type) == METHOD_TYPE);
+  gcc_assert (FUNC_OR_METHOD_TYPE_P (type));
 
   if (!FUNCTION_REF_QUALIFIED (type))
     return REF_QUAL_NONE;