|
|
f61693 |
From 8bcc0f85ed1718c0dd9033ad4a34df181aabaffe Mon Sep 17 00:00:00 2001
|
|
|
f61693 |
From: Mark Eggleston <markeggleston@gcc.gnu.org>
|
|
|
f61693 |
Date: Fri, 22 Jan 2021 13:11:06 +0000
|
|
|
f61693 |
Subject: [PATCH 05/10] Allow old-style initializers in derived types
|
|
|
f61693 |
|
|
|
f61693 |
This allows simple declarations in derived types and structures, such as:
|
|
|
f61693 |
LOGICAL*1 NIL /0/
|
|
|
f61693 |
Only single value expressions are allowed at the moment.
|
|
|
f61693 |
|
|
|
f61693 |
Use -fdec-old-init to enable. Also enabled by -fdec.
|
|
|
f61693 |
---
|
|
|
f61693 |
gcc/fortran/decl.c | 27 +++++++++++++++----
|
|
|
f61693 |
gcc/fortran/lang.opt | 4 +++
|
|
|
f61693 |
gcc/fortran/options.c | 1 +
|
|
|
f61693 |
...ec_derived_types_initialised_old_style_1.f | 25 +++++++++++++++++
|
|
|
f61693 |
...ec_derived_types_initialised_old_style_2.f | 25 +++++++++++++++++
|
|
|
f61693 |
...ec_derived_types_initialised_old_style_3.f | 26 ++++++++++++++++++
|
|
|
f61693 |
6 files changed, 103 insertions(+), 5 deletions(-)
|
|
|
f61693 |
create mode 100644 gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_1.f
|
|
|
f61693 |
create mode 100644 gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_2.f
|
|
|
f61693 |
create mode 100644 gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_3.f
|
|
|
f61693 |
|
|
|
f61693 |
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
|
|
|
f61693 |
index 723915822f3..5c8c1b7981b 100644
|
|
|
f61693 |
--- a/gcc/fortran/decl.c
|
|
|
f61693 |
+++ b/gcc/fortran/decl.c
|
|
|
f61693 |
@@ -2827,12 +2827,29 @@ variable_decl (int elem)
|
|
|
f61693 |
but not components of derived types. */
|
|
|
f61693 |
else if (gfc_current_state () == COMP_DERIVED)
|
|
|
f61693 |
{
|
|
|
f61693 |
- gfc_error ("Invalid old style initialization for derived type "
|
|
|
f61693 |
- "component at %C");
|
|
|
f61693 |
- m = MATCH_ERROR;
|
|
|
f61693 |
- goto cleanup;
|
|
|
f61693 |
+ if (flag_dec_old_init)
|
|
|
f61693 |
+ {
|
|
|
f61693 |
+ /* Attempt to match an old-style initializer which is a simple
|
|
|
f61693 |
+ integer or character expression; this will not work with
|
|
|
f61693 |
+ multiple values. */
|
|
|
f61693 |
+ m = gfc_match_init_expr (&initializer);
|
|
|
f61693 |
+ if (m == MATCH_ERROR)
|
|
|
f61693 |
+ goto cleanup;
|
|
|
f61693 |
+ else if (m == MATCH_YES)
|
|
|
f61693 |
+ {
|
|
|
f61693 |
+ m = gfc_match ("/");
|
|
|
f61693 |
+ if (m != MATCH_YES)
|
|
|
f61693 |
+ goto cleanup;
|
|
|
f61693 |
+ }
|
|
|
f61693 |
+ }
|
|
|
f61693 |
+ else
|
|
|
f61693 |
+ {
|
|
|
f61693 |
+ gfc_error ("Invalid old style initialization for derived type "
|
|
|
f61693 |
+ "component at %C");
|
|
|
f61693 |
+ m = MATCH_ERROR;
|
|
|
f61693 |
+ goto cleanup;
|
|
|
f61693 |
+ }
|
|
|
f61693 |
}
|
|
|
f61693 |
-
|
|
|
f61693 |
/* For structure components, read the initializer as a special
|
|
|
f61693 |
expression and let the rest of this function apply the initializer
|
|
|
f61693 |
as usual. */
|
|
|
f61693 |
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
|
|
|
f61693 |
index d527c106bd6..25cc948699b 100644
|
|
|
f61693 |
--- a/gcc/fortran/lang.opt
|
|
|
f61693 |
+++ b/gcc/fortran/lang.opt
|
|
|
f61693 |
@@ -493,6 +493,10 @@ fdec-non-integer-index
|
|
|
f61693 |
Fortran Var(flag_dec_non_integer_index)
|
|
|
f61693 |
Enable support for non-integer substring indexes.
|
|
|
f61693 |
|
|
|
f61693 |
+fdec-old-init
|
|
|
f61693 |
+Fortran Var(flag_dec_old_init)
|
|
|
f61693 |
+Enable support for old style initializers in derived types.
|
|
|
f61693 |
+
|
|
|
f61693 |
fdec-structure
|
|
|
f61693 |
Fortran Var(flag_dec_structure)
|
|
|
f61693 |
Enable support for DEC STRUCTURE/RECORD.
|
|
|
f61693 |
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
|
|
|
f61693 |
index 9a042f64881..d6bd36c3a8a 100644
|
|
|
f61693 |
--- a/gcc/fortran/options.c
|
|
|
f61693 |
+++ b/gcc/fortran/options.c
|
|
|
f61693 |
@@ -79,6 +79,7 @@ set_dec_flags (int value)
|
|
|
f61693 |
SET_BITFLAG (flag_dec_char_conversions, value, value);
|
|
|
f61693 |
SET_BITFLAG (flag_dec_duplicates, value, value);
|
|
|
f61693 |
SET_BITFLAG (flag_dec_non_integer_index, value, value);
|
|
|
f61693 |
+ SET_BITFLAG (flag_dec_old_init, value, value);
|
|
|
f61693 |
}
|
|
|
f61693 |
|
|
|
f61693 |
/* Finalize DEC flags. */
|
|
|
f61693 |
diff --git a/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_1.f b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_1.f
|
|
|
f61693 |
new file mode 100644
|
|
|
f61693 |
index 00000000000..eac4f9bfcf1
|
|
|
f61693 |
--- /dev/null
|
|
|
f61693 |
+++ b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_1.f
|
|
|
f61693 |
@@ -0,0 +1,25 @@
|
|
|
f61693 |
+! { dg-do run }
|
|
|
f61693 |
+! { dg-options "-fdec" }
|
|
|
f61693 |
+!
|
|
|
f61693 |
+! Test old style initializers in derived types
|
|
|
f61693 |
+!
|
|
|
f61693 |
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
f61693 |
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
f61693 |
+!
|
|
|
f61693 |
+ PROGRAM spec_in_var
|
|
|
f61693 |
+ TYPE STRUCT1
|
|
|
f61693 |
+ INTEGER*4 ID /8/
|
|
|
f61693 |
+ INTEGER*4 TYPE /5/
|
|
|
f61693 |
+ INTEGER*8 DEFVAL /0/
|
|
|
f61693 |
+ CHARACTER*(5) NAME /'tests'/
|
|
|
f61693 |
+ LOGICAL*1 NIL /0/
|
|
|
f61693 |
+ END TYPE STRUCT1
|
|
|
f61693 |
+
|
|
|
f61693 |
+ TYPE (STRUCT1) SINST
|
|
|
f61693 |
+
|
|
|
f61693 |
+ IF(SINST%ID.NE.8) STOP 1
|
|
|
f61693 |
+ IF(SINST%TYPE.NE.5) STOP 2
|
|
|
f61693 |
+ IF(SINST%DEFVAL.NE.0) STOP 3
|
|
|
f61693 |
+ IF(SINST%NAME.NE.'tests') STOP 4
|
|
|
f61693 |
+ IF(SINST%NIL) STOP 5
|
|
|
f61693 |
+ END
|
|
|
f61693 |
diff --git a/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_2.f b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_2.f
|
|
|
f61693 |
new file mode 100644
|
|
|
f61693 |
index 00000000000..d904c8b2974
|
|
|
f61693 |
--- /dev/null
|
|
|
f61693 |
+++ b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_2.f
|
|
|
f61693 |
@@ -0,0 +1,25 @@
|
|
|
f61693 |
+! { dg-do run }
|
|
|
f61693 |
+! { dg-options "-std=legacy -fdec-old-init" }
|
|
|
f61693 |
+!
|
|
|
f61693 |
+! Test old style initializers in derived types
|
|
|
f61693 |
+!
|
|
|
f61693 |
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
f61693 |
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
f61693 |
+!
|
|
|
f61693 |
+ PROGRAM spec_in_var
|
|
|
f61693 |
+ TYPE STRUCT1
|
|
|
f61693 |
+ INTEGER*4 ID /8/
|
|
|
f61693 |
+ INTEGER*4 TYPE /5/
|
|
|
f61693 |
+ INTEGER*8 DEFVAL /0/
|
|
|
f61693 |
+ CHARACTER*(5) NAME /'tests'/
|
|
|
f61693 |
+ LOGICAL*1 NIL /0/
|
|
|
f61693 |
+ END TYPE STRUCT1
|
|
|
f61693 |
+
|
|
|
f61693 |
+ TYPE (STRUCT1) SINST
|
|
|
f61693 |
+
|
|
|
f61693 |
+ IF(SINST%ID.NE.8) STOP 1
|
|
|
f61693 |
+ IF(SINST%TYPE.NE.5) STOP 2
|
|
|
f61693 |
+ IF(SINST%DEFVAL.NE.0) STOP 3
|
|
|
f61693 |
+ IF(SINST%NAME.NE.'tests') STOP 4
|
|
|
f61693 |
+ IF(SINST%NIL) STOP 5
|
|
|
f61693 |
+ END
|
|
|
f61693 |
diff --git a/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_3.f b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_3.f
|
|
|
f61693 |
new file mode 100644
|
|
|
f61693 |
index 00000000000..58c2b4b66cf
|
|
|
f61693 |
--- /dev/null
|
|
|
f61693 |
+++ b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style_3.f
|
|
|
f61693 |
@@ -0,0 +1,26 @@
|
|
|
f61693 |
+! { dg-do compile }
|
|
|
f61693 |
+! { dg-options "-std=legacy -fdec -fno-dec-old-init" }
|
|
|
f61693 |
+!
|
|
|
f61693 |
+! Test old style initializers in derived types
|
|
|
f61693 |
+!
|
|
|
f61693 |
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
f61693 |
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
|
|
|
f61693 |
+!
|
|
|
f61693 |
+
|
|
|
f61693 |
+ PROGRAM spec_in_var
|
|
|
f61693 |
+ TYPE STRUCT1
|
|
|
f61693 |
+ INTEGER*4 ID /8/ ! { dg-error "Invalid old style initialization" }
|
|
|
f61693 |
+ INTEGER*4 TYPE /5/ ! { dg-error "Invalid old style initialization" }
|
|
|
f61693 |
+ INTEGER*8 DEFVAL /0/ ! { dg-error "Invalid old style initialization" }
|
|
|
f61693 |
+ CHARACTER*(5) NAME /'tests'/ ! { dg-error "Invalid old style initialization" }
|
|
|
f61693 |
+ LOGICAL*1 NIL /0/ ! { dg-error "Invalid old style initialization" }
|
|
|
f61693 |
+ END TYPE STRUCT1
|
|
|
f61693 |
+
|
|
|
f61693 |
+ TYPE (STRUCT1) SINST
|
|
|
f61693 |
+
|
|
|
f61693 |
+ IF(SINST%ID.NE.8) STOP 1 ! { dg-error "'id' at \\(1\\) is not a member" }
|
|
|
f61693 |
+ IF(SINST%TYPE.NE.5) STOP 2 ! { dg-error "'type' at \\(1\\) is not a member" }
|
|
|
f61693 |
+ IF(SINST%DEFVAL.NE.0) STOP 3 ! { dg-error "'defval' at \\(1\\) is not a member" }
|
|
|
f61693 |
+ IF(SINST%NAME.NE.'tests') STOP 4 ! { dg-error "'name' at \\(1\\) is not a member" }
|
|
|
f61693 |
+ IF(SINST%NIL) STOP 5 ! { dg-error "'nil' at \\(1\\) is not a member" }
|
|
|
f61693 |
+ END
|
|
|
f61693 |
--
|
|
|
f61693 |
2.27.0
|
|
|
f61693 |
|