From 719e72fb6f663ba626875c8333b6bfe289c5140e Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Sun, 12 Aug 2007 21:21:08 +0000 Subject: [PATCH] re PR fortran/29600 ([F03] MINLOC and MAXLOC take an optional KIND argument) PR fortran/29600 * intrinsic.c (add_functions): Add optional KIND argument to ACHAR. * iresolve.c (gfc_resolve_achar): Handle the KIND argument. * check.c (gfc_check_achar): Check for the optional KIND argument. * simplify.c (gfc_simplify_achar): Use KIND argument. * intrinsic.h (gfc_check_achar, gfc_simplify_achar, gfc_resolve_achar): Adjust prototypes. * gfortran.dg/intrinsics_kind_argument_1.f90: Add test for ACHAR intrinsic. From-SVN: r127385 --- gcc/fortran/ChangeLog | 10 ++++++++++ gcc/fortran/check.c | 4 +++- gcc/fortran/intrinsic.c | 5 +++-- gcc/fortran/intrinsic.h | 6 +++--- gcc/fortran/iresolve.c | 11 ++++++----- gcc/fortran/simplify.c | 11 +++++++---- gcc/testsuite/ChangeLog | 6 ++++++ .../gfortran.dg/intrinsics_kind_argument_1.f90 | 2 ++ 8 files changed, 40 insertions(+), 15 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index acbe9a7cf77..7ea4735fbea 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,13 @@ +2007-08-12 Francois-Xavier Coudert + + PR fortran/29600 + * intrinsic.c (add_functions): Add optional KIND argument to ACHAR. + * iresolve.c (gfc_resolve_achar): Handle the KIND argument. + * check.c (gfc_check_achar): Check for the optional KIND argument. + * simplify.c (gfc_simplify_achar): Use KIND argument. + * intrinsic.h (gfc_check_achar, gfc_simplify_achar, + gfc_resolve_achar): Adjust prototypes. + 2007-08-12 Francois-Xavier Coudert PR fortran/30964 diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index 23955deab9d..634d6b4f05b 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -443,10 +443,12 @@ gfc_check_abs (gfc_expr *a) try -gfc_check_achar (gfc_expr *a) +gfc_check_achar (gfc_expr *a, gfc_expr *kind) { if (type_check (a, 0, BT_INTEGER) == FAILURE) return FAILURE; + if (kind_check (kind, 1, BT_CHARACTER) == FAILURE) + return FAILURE; return SUCCESS; } diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index 7f02245c7fb..3f999b4210c 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -946,9 +946,10 @@ add_functions (void) make_generic ("access", GFC_ISYM_ACCESS, GFC_STD_GNU); - add_sym_1 ("achar", GFC_ISYM_ACHAR, CLASS_ELEMENTAL, ACTUAL_NO, BT_CHARACTER, dc, GFC_STD_F95, + add_sym_2 ("achar", GFC_ISYM_ACHAR, CLASS_ELEMENTAL, ACTUAL_NO, + BT_CHARACTER, dc, GFC_STD_F95, gfc_check_achar, gfc_simplify_achar, gfc_resolve_achar, - i, BT_INTEGER, di, REQUIRED); + i, BT_INTEGER, di, REQUIRED, kind, BT_INTEGER, di, OPTIONAL); make_generic ("achar", GFC_ISYM_ACHAR, GFC_STD_F95); diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h index 1e03e0cdd30..cf242b8995d 100644 --- a/gcc/fortran/intrinsic.h +++ b/gcc/fortran/intrinsic.h @@ -32,7 +32,7 @@ try gfc_check_a_p (gfc_expr *, gfc_expr *); try gfc_check_abs (gfc_expr *); try gfc_check_access_func (gfc_expr *, gfc_expr *); -try gfc_check_achar (gfc_expr *); +try gfc_check_achar (gfc_expr *, gfc_expr *); try gfc_check_all_any (gfc_expr *, gfc_expr *); try gfc_check_allocated (gfc_expr *); try gfc_check_associated (gfc_expr *, gfc_expr *); @@ -185,7 +185,7 @@ try gfc_check_unlink_sub (gfc_expr *, gfc_expr *); /* Simplification functions. */ gfc_expr *gfc_simplify_abs (gfc_expr *); -gfc_expr *gfc_simplify_achar (gfc_expr *); +gfc_expr *gfc_simplify_achar (gfc_expr *, gfc_expr *); gfc_expr *gfc_simplify_acos (gfc_expr *); gfc_expr *gfc_simplify_acosh (gfc_expr *); gfc_expr *gfc_simplify_adjustl (gfc_expr *); @@ -303,7 +303,7 @@ gfc_expr *gfc_convert_constant (gfc_expr *, bt, int); /* Resolution functions. */ void gfc_resolve_abs (gfc_expr *, gfc_expr *); void gfc_resolve_access (gfc_expr *, gfc_expr *, gfc_expr *); -void gfc_resolve_achar (gfc_expr *, gfc_expr *); +void gfc_resolve_achar (gfc_expr *, gfc_expr *, gfc_expr *); void gfc_resolve_acos (gfc_expr *, gfc_expr *); void gfc_resolve_acosh (gfc_expr *, gfc_expr *); void gfc_resolve_aimag (gfc_expr *, gfc_expr *); diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c index 6232374161e..c030898a43b 100644 --- a/gcc/fortran/iresolve.c +++ b/gcc/fortran/iresolve.c @@ -133,18 +133,19 @@ gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED, void -gfc_resolve_achar (gfc_expr *f, gfc_expr *x) +gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind) { - f->ts.type = BT_CHARACTER; - f->ts.kind = gfc_default_character_kind; + f->ts.kind = (kind == NULL) + ? gfc_default_character_kind : mpz_get_si (kind->value.integer); f->ts.cl = gfc_get_charlen (); f->ts.cl->next = gfc_current_ns->cl_list; gfc_current_ns->cl_list = f->ts.cl; f->ts.cl->length = gfc_int_expr (1); - f->value.function.name - = gfc_get_string ("__achar_%c%d", gfc_type_letter (x->ts.type), x->ts.kind); + f->value.function.name = gfc_get_string ("__achar_%d_%c%d", f->ts.kind, + gfc_type_letter (x->ts.type), + x->ts.kind); } diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index c3c23cb9215..a395b04a599 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -257,15 +257,19 @@ gfc_simplify_abs (gfc_expr *e) systems that gfortran currently works on are ASCII. */ gfc_expr * -gfc_simplify_achar (gfc_expr *e) +gfc_simplify_achar (gfc_expr *e, gfc_expr *k) { gfc_expr *result; - int c; + int c, kind; const char *ch; if (e->expr_type != EXPR_CONSTANT) return NULL; + kind = get_kind (BT_CHARACTER, k, "ACHAR", gfc_default_character_kind); + if (kind == -1) + return &gfc_bad_expr; + ch = gfc_extract_int (e, &c); if (ch != NULL) @@ -275,8 +279,7 @@ gfc_simplify_achar (gfc_expr *e) gfc_warning ("Argument of ACHAR function at %L outside of range [0,127]", &e->where); - result = gfc_constant_result (BT_CHARACTER, gfc_default_character_kind, - &e->where); + result = gfc_constant_result (BT_CHARACTER, kind, &e->where); result->value.character.string = gfc_getmem (2); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6640aee6794..b039444e0f9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-08-12 Francois-Xavier Coudert + + PR fortran/29600 + * gfortran.dg/intrinsics_kind_argument_1.f90: Add test for ACHAR + intrinsic. + 2007-08-12 Francois-Xavier Coudert PR fortran/30964 diff --git a/gcc/testsuite/gfortran.dg/intrinsics_kind_argument_1.f90 b/gcc/testsuite/gfortran.dg/intrinsics_kind_argument_1.f90 index b02ff749aed..0a3ca079127 100644 --- a/gcc/testsuite/gfortran.dg/intrinsics_kind_argument_1.f90 +++ b/gcc/testsuite/gfortran.dg/intrinsics_kind_argument_1.f90 @@ -21,6 +21,8 @@ program test call check (ichar (s, k), 117) call check (ichar (s, kind=k), 117) + if (achar(107) /= achar(107,1)) call abort + call check (index (t, s, .true., k), 7) call check (index (t, s, kind=k, back=.false.), 5)