diff mbox

[Fortran,cleanup] PR 78798: some int-valued functions should be bool

Message ID CAKwh3qiV=6F1SxPp=HP1H1r2j21wWFHxp+himusLUMY7ytTVUw@mail.gmail.com
State New
Headers show

Commit Message

Janus Weil Dec. 13, 2016, 6:13 p.m. UTC
Hi all,

here is a straightforward cleanup patch that makes a few functions
return a bool instead of an int. Regtests cleanly on x86_64-linux-gnu.
Ok for trunk?

Cheers,
Janus



2016-12-13  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/78798
    * gfortran.h (gfc_is_constant_expr, gfc_is_formal_arg,
    gfc_is_compile_time_shape): Return bool instead of int.
    * array.c (gfc_is_compile_time_shape): Ditto.
    * expr.c (gfc_is_constant_expr): Ditto.
    * resolve.c (gfc_is_formal_arg): Ditto. Make formal_arg_flag bool.

Comments

Janne Blomqvist Dec. 13, 2016, 6:19 p.m. UTC | #1
On Tue, Dec 13, 2016 at 8:13 PM, Janus Weil <janus@gcc.gnu.org> wrote:
> Hi all,
>
> here is a straightforward cleanup patch that makes a few functions
> return a bool instead of an int. Regtests cleanly on x86_64-linux-gnu.
> Ok for trunk?

Ok, thanks.
Janus Weil Dec. 13, 2016, 6:55 p.m. UTC | #2
2016-12-13 19:19 GMT+01:00 Janne Blomqvist <blomqvist.janne@gmail.com>:
> On Tue, Dec 13, 2016 at 8:13 PM, Janus Weil <janus@gcc.gnu.org> wrote:
>> Hi all,
>>
>> here is a straightforward cleanup patch that makes a few functions
>> return a bool instead of an int. Regtests cleanly on x86_64-linux-gnu.
>> Ok for trunk?
>
> Ok, thanks.

Thanks, Janne. Committed as r243621.

Cheers,
Janus
diff mbox

Patch

Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(revision 243609)
+++ gcc/fortran/array.c	(working copy)
@@ -2581,18 +2581,16 @@  gfc_find_array_ref (gfc_expr *e)
 
 /* Find out if an array shape is known at compile time.  */
 
-int
+bool
 gfc_is_compile_time_shape (gfc_array_spec *as)
 {
-  int i;
-
   if (as->type != AS_EXPLICIT)
-    return 0;
+    return false;
 
-  for (i = 0; i < as->rank; i++)
+  for (int i = 0; i < as->rank; i++)
     if (!gfc_is_constant_expr (as->lower[i])
 	|| !gfc_is_constant_expr (as->upper[i]))
-      return 0;
+      return false;
 
-  return 1;
+  return true;
 }
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 243609)
+++ gcc/fortran/expr.c	(working copy)
@@ -882,10 +882,9 @@  done:
 
 
 /* Determine if an expression is constant in the sense of F08:7.1.12.
- * This function expects that the expression has already been simplified.
- * FIXME: Return a bool, not an int.  */
+ * This function expects that the expression has already been simplified.  */
 
-int
+bool
 gfc_is_constant_expr (gfc_expr *e)
 {
   gfc_constructor *c;
@@ -892,7 +891,7 @@  gfc_is_constant_expr (gfc_expr *e)
   gfc_actual_arglist *arg;
 
   if (e == NULL)
-    return 1;
+    return true;
 
   switch (e->expr_type)
     {
@@ -902,7 +901,7 @@  gfc_is_constant_expr (gfc_expr *e)
 		  || gfc_is_constant_expr (e->value.op.op2)));
 
     case EXPR_VARIABLE:
-      return 0;
+      return false;
 
     case EXPR_FUNCTION:
     case EXPR_PPC:
@@ -915,7 +914,7 @@  gfc_is_constant_expr (gfc_expr *e)
 	{
 	  for (arg = e->value.function.actual; arg; arg = arg->next)
 	    if (!gfc_is_constant_expr (arg->expr))
-	      return 0;
+	      return false;
 	}
 
       if (e->value.function.isym
@@ -923,13 +922,13 @@  gfc_is_constant_expr (gfc_expr *e)
 	      || e->value.function.isym->pure
 	      || e->value.function.isym->inquiry
 	      || e->value.function.isym->transformational))
-	return 1;
+	return true;
 
-      return 0;
+      return false;
 
     case EXPR_CONSTANT:
     case EXPR_NULL:
-      return 1;
+      return true;
 
     case EXPR_SUBSTRING:
       return e->ref == NULL || (gfc_is_constant_expr (e->ref->u.ss.start)
@@ -943,14 +942,14 @@  gfc_is_constant_expr (gfc_expr *e)
 
       for (; c; c = gfc_constructor_next (c))
 	if (!gfc_is_constant_expr (c->expr))
-	  return 0;
+	  return false;
 
-      return 1;
+      return true;
 
 
     default:
       gfc_internal_error ("gfc_is_constant_expr(): Unknown expression type");
-      return 0;
+      return false;
     }
 }
 
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 243609)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -3088,7 +3088,7 @@  bool gfc_check_init_expr (gfc_expr *);
 gfc_expr *gfc_build_conversion (gfc_expr *);
 void gfc_free_ref_list (gfc_ref *);
 void gfc_type_convert_binary (gfc_expr *, int);
-int gfc_is_constant_expr (gfc_expr *);
+bool gfc_is_constant_expr (gfc_expr *);
 bool gfc_simplify_expr (gfc_expr *, int);
 int gfc_has_vector_index (gfc_expr *);
 
@@ -3180,7 +3180,7 @@  bool gfc_resolve_iterator (gfc_iterator *, bool, b
 bool find_forall_index (gfc_expr *, gfc_symbol *, int);
 bool gfc_resolve_index (gfc_expr *, int);
 bool gfc_resolve_dim_arg (gfc_expr *);
-int gfc_is_formal_arg (void);
+bool gfc_is_formal_arg (void);
 void gfc_resolve_substring_charlen (gfc_expr *);
 match gfc_iso_c_sub_interface(gfc_code *, gfc_symbol *);
 gfc_expr *gfc_expr_to_initialize (gfc_expr *);
@@ -3218,7 +3218,7 @@  gfc_array_ref *gfc_find_array_ref (gfc_expr *);
 tree gfc_conv_array_initializer (tree type, gfc_expr *);
 bool spec_size (gfc_array_spec *, mpz_t *);
 bool spec_dimen_size (gfc_array_spec *, int, mpz_t *);
-int gfc_is_compile_time_shape (gfc_array_spec *);
+bool gfc_is_compile_time_shape (gfc_array_spec *);
 
 bool gfc_ref_dimen_size (gfc_array_ref *, int dimen, mpz_t *, mpz_t *);
 
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 243609)
+++ gcc/fortran/resolve.c	(working copy)
@@ -72,9 +72,9 @@  static bool first_actual_arg = false;
 
 static int omp_workshare_flag;
 
-/* Nonzero if we are processing a formal arglist. The corresponding function
+/* True if we are processing a formal arglist. The corresponding function
    resets the flag each time that it is read.  */
-static int formal_arg_flag = 0;
+static bool formal_arg_flag = false;
 
 /* True if we are resolving a specification expression.  */
 static bool specification_expr = false;
@@ -89,7 +89,7 @@  static bitmap_obstack labels_obstack;
 static bool inquiry_argument = false;
 
 
-int
+bool
 gfc_is_formal_arg (void)
 {
   return formal_arg_flag;
@@ -285,7 +285,7 @@  resolve_formal_arglist (gfc_symbol *proc)
       sym->attr.always_explicit = 1;
     }
 
-  formal_arg_flag = 1;
+  formal_arg_flag = true;
 
   for (f = proc->formal; f; f = f->next)
     {
@@ -530,7 +530,7 @@  resolve_formal_arglist (gfc_symbol *proc)
 	    }
 	}
     }
-  formal_arg_flag = 0;
+  formal_arg_flag = false;
 }
 
 
@@ -14722,7 +14722,7 @@  resolve_symbol (gfc_symbol *sym)
      an error for host associated variables in the specification
      expression for an array_valued function.  */
   if (sym->attr.function && sym->as)
-    formal_arg_flag = 1;
+    formal_arg_flag = true;
 
   saved_specification_expr = specification_expr;
   specification_expr = true;
@@ -14729,7 +14729,7 @@  resolve_symbol (gfc_symbol *sym)
   gfc_resolve_array_spec (sym->as, check_constant);
   specification_expr = saved_specification_expr;
 
-  formal_arg_flag = 0;
+  formal_arg_flag = false;
 
   /* Resolve formal namespaces.  */
   if (sym->formal_ns && sym->formal_ns != gfc_current_ns