diff options
author | Roger Sayle <roger@eyesopen.com> | 2005-06-01 19:17:37 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2005-06-01 19:17:37 +0000 |
commit | c3a29423de8cfb7e2b5642b9d44eb21e4b286aec (patch) | |
tree | aca5715d2e2402e23f8d6fcb8a69bdb7516dab2e /gcc/fortran | |
parent | cdeee6d28017c9c881d2395645b3314fa575e59b (diff) | |
download | gcc-c3a29423de8cfb7e2b5642b9d44eb21e4b286aec.zip gcc-c3a29423de8cfb7e2b5642b9d44eb21e4b286aec.tar.gz gcc-c3a29423de8cfb7e2b5642b9d44eb21e4b286aec.tar.bz2 |
intrinsic.c (add_conv): No longer take a "simplify" argument as its always gfc_convert_constant...
* intrinsic.c (add_conv): No longer take a "simplify" argument as
its always gfc_convert_constant, instead take a "standard" argument.
(add_conversions): Change all existing calls of add_conv to pass
GFC_STD_F77 as appropriate. Additionally, if we're allowing GNU
extensions support integer-logical and logical-integer conversions.
(gfc_convert_type_warn): Warn about use the use of these conversions
as a extension when appropriate, i.e. with -pedantic.
* simplify.c (gfc_convert_constant): Add support for integer to
logical and logical to integer conversions, using gfc_int2log and
gfc_log2int.
* arith.c (gfc_log2int, gfc_int2log): New functions.
* arith.h (gfc_log2int, gfc_int2log): Prototype here.
* gfortran.texi: Document this new GNU extension.
* gfortran.dg/logint-1.f: New test case.
* gfortran.dg/logint-2.f: Likewise.
* gfortran.dg/logint-3.f: Likewise.
From-SVN: r100461
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/fortran/arith.c | 23 | ||||
-rw-r--r-- | gcc/fortran/arith.h | 2 | ||||
-rw-r--r-- | gcc/fortran/gfortran.texi | 17 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.c | 44 | ||||
-rw-r--r-- | gcc/fortran/simplify.c | 17 |
6 files changed, 101 insertions, 18 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f4cc96b..e7c0c95 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,19 @@ +2005-06-01 Roger Sayle <roger@eyesopen.com> + + * intrinsic.c (add_conv): No longer take a "simplify" argument as + its always gfc_convert_constant, instead take a "standard" argument. + (add_conversions): Change all existing calls of add_conv to pass + GFC_STD_F77 as appropriate. Additionally, if we're allowing GNU + extensions support integer-logical and logical-integer conversions. + (gfc_convert_type_warn): Warn about use the use of these conversions + as a extension when appropriate, i.e. with -pedantic. + * simplify.c (gfc_convert_constant): Add support for integer to + logical and logical to integer conversions, using gfc_int2log and + gfc_log2int. + * arith.c (gfc_log2int, gfc_int2log): New functions. + * arith.h (gfc_log2int, gfc_int2log): Prototype here. + * gfortran.texi: Document this new GNU extension. + 2005-06-01 Paul Thomas <pault@gcc.gnu.org> * fortran/trans-expr.c (gfc_conv_variable): Clean up bracketting. diff --git a/gcc/fortran/arith.c b/gcc/fortran/arith.c index 88b6c36..684ae7b 100644 --- a/gcc/fortran/arith.c +++ b/gcc/fortran/arith.c @@ -2191,3 +2191,26 @@ gfc_log2log (gfc_expr * src, int kind) return result; } + +/* Convert logical to integer. */ + +gfc_expr * +gfc_log2int (gfc_expr *src, int kind) +{ + gfc_expr *result; + result = gfc_constant_result (BT_INTEGER, kind, &src->where); + mpz_set_si (result->value.integer, src->value.logical); + return result; +} + +/* Convert integer to logical. */ + +gfc_expr * +gfc_int2log (gfc_expr *src, int kind) +{ + gfc_expr *result; + result = gfc_constant_result (BT_LOGICAL, kind, &src->where); + result->value.logical = (mpz_cmp_si (src->value.integer, 0) != 0); + return result; +} + diff --git a/gcc/fortran/arith.h b/gcc/fortran/arith.h index 1a718d4..f75b826 100644 --- a/gcc/fortran/arith.h +++ b/gcc/fortran/arith.h @@ -80,6 +80,8 @@ gfc_expr *gfc_complex2int (gfc_expr *, int); gfc_expr *gfc_complex2real (gfc_expr *, int); gfc_expr *gfc_complex2complex (gfc_expr *, int); gfc_expr *gfc_log2log (gfc_expr *, int); +gfc_expr *gfc_log2int (gfc_expr *, int); +gfc_expr *gfc_int2log (gfc_expr *, int); #endif /* GFC_ARITH_H */ diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 7ea5909..50b6499 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -637,6 +637,7 @@ of extensions, and @option{-std=legacy} allows both without warning. * Hexadecimal constants:: * Real array indices:: * Unary operators:: +* Implicitly interconvert LOGICAL and INTEGER:: @end menu @node Old-style kind specifications @@ -793,6 +794,22 @@ operators without the need for parenthesis. X = Y * -Z @end smallexample +@node Implicitly interconvert LOGICAL and INTEGER +@section Implicitly interconvert LOGICAL and INTEGER +@cindex Implicitly interconvert LOGICAL and INTEGER + +As a GNU extension for backwards compatability with other compilers, +@command{gfortran} allows the implicit conversion of LOGICALs to INTEGERs +and vice versa. When converting from a LOGICAL to an INTEGER, the numeric +value of @code{.FALSE.} is zero, and that of @code{.TRUE.} is one. When +converting from INTEGER to LOGICAL, the value zero is interpreted as +@code{.FALSE.} and any non-zero value is interpreted as @code{.TRUE.}. + +@smallexample + INTEGER*4 i + i = .FALSE. +@end smallexample + @include intrinsic.texi @c --------------------------------------------------------------------- @c Contributing diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index 0b50cdc..66cf190 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -2227,8 +2227,7 @@ add_subroutines (void) /* Add a function to the list of conversion symbols. */ static void -add_conv (bt from_type, int from_kind, bt to_type, int to_kind, - gfc_expr * (*simplify) (gfc_expr *, bt, int)) +add_conv (bt from_type, int from_kind, bt to_type, int to_kind, int standard) { gfc_typespec from, to; @@ -2250,9 +2249,10 @@ add_conv (bt from_type, int from_kind, bt to_type, int to_kind, sym = conversion + nconv; - sym->name = conv_name (&from, &to); + sym->name = conv_name (&from, &to); sym->lib_name = sym->name; - sym->simplify.cc = simplify; + sym->simplify.cc = gfc_convert_constant; + sym->standard = standard; sym->elemental = 1; sym->ts = to; sym->generic_id = GFC_ISYM_CONVERSION; @@ -2277,7 +2277,7 @@ add_conversions (void) continue; add_conv (BT_INTEGER, gfc_integer_kinds[i].kind, - BT_INTEGER, gfc_integer_kinds[j].kind, gfc_convert_constant); + BT_INTEGER, gfc_integer_kinds[j].kind, GFC_STD_F77); } /* Integer-Real/Complex conversions. */ @@ -2285,16 +2285,16 @@ add_conversions (void) for (j = 0; gfc_real_kinds[j].kind != 0; j++) { add_conv (BT_INTEGER, gfc_integer_kinds[i].kind, - BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant); + BT_REAL, gfc_real_kinds[j].kind, GFC_STD_F77); add_conv (BT_REAL, gfc_real_kinds[j].kind, - BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant); + BT_INTEGER, gfc_integer_kinds[i].kind, GFC_STD_F77); add_conv (BT_INTEGER, gfc_integer_kinds[i].kind, - BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant); + BT_COMPLEX, gfc_real_kinds[j].kind, GFC_STD_F77); add_conv (BT_COMPLEX, gfc_real_kinds[j].kind, - BT_INTEGER, gfc_integer_kinds[i].kind, gfc_convert_constant); + BT_INTEGER, gfc_integer_kinds[i].kind, GFC_STD_F77); } /* Real/Complex - Real/Complex conversions. */ @@ -2304,17 +2304,17 @@ add_conversions (void) if (i != j) { add_conv (BT_REAL, gfc_real_kinds[i].kind, - BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant); + BT_REAL, gfc_real_kinds[j].kind, GFC_STD_F77); add_conv (BT_COMPLEX, gfc_real_kinds[i].kind, - BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant); + BT_COMPLEX, gfc_real_kinds[j].kind, GFC_STD_F77); } add_conv (BT_REAL, gfc_real_kinds[i].kind, - BT_COMPLEX, gfc_real_kinds[j].kind, gfc_convert_constant); + BT_COMPLEX, gfc_real_kinds[j].kind, GFC_STD_F77); add_conv (BT_COMPLEX, gfc_real_kinds[i].kind, - BT_REAL, gfc_real_kinds[j].kind, gfc_convert_constant); + BT_REAL, gfc_real_kinds[j].kind, GFC_STD_F77); } /* Logical/Logical kind conversion. */ @@ -2325,8 +2325,19 @@ add_conversions (void) continue; add_conv (BT_LOGICAL, gfc_logical_kinds[i].kind, - BT_LOGICAL, gfc_logical_kinds[j].kind, gfc_convert_constant); + BT_LOGICAL, gfc_logical_kinds[j].kind, GFC_STD_F77); } + + /* Integer-Logical and Logical-Integer conversions. */ + if ((gfc_option.allow_std & GFC_STD_LEGACY) != 0) + for (i=0; gfc_integer_kinds[i].kind; i++) + for (j=0; gfc_logical_kinds[j].kind; j++) + { + add_conv (BT_INTEGER, gfc_integer_kinds[i].kind, + BT_LOGICAL, gfc_logical_kinds[j].kind, GFC_STD_LEGACY); + add_conv (BT_LOGICAL, gfc_logical_kinds[j].kind, + BT_INTEGER, gfc_integer_kinds[i].kind, GFC_STD_LEGACY); + } } @@ -3142,7 +3153,10 @@ gfc_convert_type_warn (gfc_expr * expr, gfc_typespec * ts, int eflag, goto bad; /* At this point, a conversion is necessary. A warning may be needed. */ - if (wflag && gfc_option.warn_conversion) + if ((gfc_option.warn_std & sym->standard) != 0) + gfc_warning_now ("Extension: Conversion from %s to %s at %L", + gfc_typename (&from_ts), gfc_typename (ts), &expr->where); + else if (wflag && gfc_option.warn_conversion) gfc_warning_now ("Conversion from %s to %s at %L", gfc_typename (&from_ts), gfc_typename (ts), &expr->where); diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index fa6c2c6..6797bca 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -3659,6 +3659,9 @@ gfc_convert_constant (gfc_expr * e, bt type, int kind) case BT_COMPLEX: f = gfc_int2complex; break; + case BT_LOGICAL: + f = gfc_int2log; + break; default: goto oops; } @@ -3700,9 +3703,17 @@ gfc_convert_constant (gfc_expr * e, bt type, int kind) break; case BT_LOGICAL: - if (type != BT_LOGICAL) - goto oops; - f = gfc_log2log; + switch (type) + { + case BT_INTEGER: + f = gfc_log2int; + break; + case BT_LOGICAL: + f = gfc_log2log; + break; + default: + goto oops; + } break; default: |