Blame SOURCES/0009-Allow-old-style-initializers-in-derived-types.patch

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