From 7a28353e36d0c2b1dc81883437d2064a50c00e8e Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Tue, 13 Dec 2016 19:55:20 +0100 Subject: [PATCH] re PR fortran/78798 ([cleanup] some int-valued functions should be bool) 2016-12-13 Janus Weil 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. From-SVN: r243621 --- gcc/fortran/ChangeLog | 9 +++++++++ gcc/fortran/array.c | 12 +++++------- gcc/fortran/expr.c | 23 +++++++++++------------ gcc/fortran/gfortran.h | 6 +++--- gcc/fortran/resolve.c | 14 +++++++------- 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d25fc9702ef..40b578325d1 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2016-12-13 Janus Weil + + 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. + 2016-12-13 Andre Vehreschild PR fortran/77785 diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index e6917a53850..154b8606897 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -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; } diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index c4a6ae10de6..f57198fc35b 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -882,17 +882,16 @@ 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; 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; } } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index f0189840f27..da653363712 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -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, bool); 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 *); diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index ce1d9ea0f98..2c70e6cfe9b 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -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,14 +14722,14 @@ 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; 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 -- 2.30.2