diff mbox series

[Fortran] Taking a BYTE out of type-spec

Message ID 20191024204335.GA26512@troutmask.apl.washington.edu
State New
Headers show
Series [Fortran] Taking a BYTE out of type-spec | expand

Commit Message

Steve Kargl Oct. 24, 2019, 8:43 p.m. UTC
The patch moves the matching of the nonstandard type-spec
BYTE to its own matching function.  During this move, a
check for invalid matching in free-form source code it
detected (see byte_4.f90).  OK to commit?

2019-10-24  Steven G. Kargl  <kargl@gcc.gnu.org>

	* decl.c (match_byte_typespec): New function.  Match BYTE type-spec.
	(gfc_match_decl_type_spec): Use it.

2019-10-24  Steven G. Kargl  <kargl@gcc.gnu.org>

	* gfortran.dg/byte_3.f: New test.
	* gfortran.dg/byte_4.f90: Ditto.

Comments

Tobias Burnus Oct. 25, 2019, 7:05 a.m. UTC | #1
On 10/24/19 10:43 PM, Steve Kargl wrote:
> The patch moves the matching of the nonstandard type-spec
> BYTE to its own matching function.  During this move, a
> check for invalid matching in free-form source code it
> detected (see byte_4.f90).  OK to commit?

OK with a nit.

> +      if (gfc_current_form == FORM_FREE)
> +	{
> +	  char c = gfc_peek_ascii_char ();
> +	  if (!gfc_is_whitespace (c) && c != ',')
> +	    return MATCH_NO;

You also want to permit "byte::var", hence: c == ':' is also okay – you 
can also add this as variant to the test case.

Cheers,

Tobias
Steve Kargl Oct. 25, 2019, 4:15 p.m. UTC | #2
On Fri, Oct 25, 2019 at 09:05:03AM +0200, Tobias Burnus wrote:
> On 10/24/19 10:43 PM, Steve Kargl wrote:
> > The patch moves the matching of the nonstandard type-spec
> > BYTE to its own matching function.  During this move, a
> > check for invalid matching in free-form source code it
> > detected (see byte_4.f90).  OK to commit?
> 
> OK with a nit.
> 
> > +      if (gfc_current_form == FORM_FREE)
> > +	{
> > +	  char c = gfc_peek_ascii_char ();
> > +	  if (!gfc_is_whitespace (c) && c != ',')
> > +	    return MATCH_NO;
> 
> You also want to permit "byte::var", hence: c == ':' is also okay – you 
> can also add this as variant to the test case.
> 
> Cheers,

Thanks and good catch.  I tend to think of BYTE as a legacy 
extension, which likely was used prior to the double colon
notation, so 'byte ::' won't appear.  But, it does hurt to
allow it.
diff mbox series

Patch

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 277420)
+++ gcc/fortran/decl.c	(working copy)
@@ -3980,6 +3980,38 @@  error_return:
 }
 
 
+/* Match a legacy nonstandard BYTE type-spec.  */
+
+static match
+match_byte_typespec (gfc_typespec *ts)
+{
+  if (gfc_match (" byte") == MATCH_YES)
+    {
+      if (!gfc_notify_std (GFC_STD_GNU, "BYTE type at %C"))
+	return MATCH_ERROR;
+
+      if (gfc_current_form == FORM_FREE)
+	{
+	  char c = gfc_peek_ascii_char ();
+	  if (!gfc_is_whitespace (c) && c != ',')
+	    return MATCH_NO;
+	}
+
+      if (gfc_validate_kind (BT_INTEGER, 1, true) < 0)
+	{
+	  gfc_error ("BYTE type used at %C "
+		     "is not available on the target machine");
+	  return MATCH_ERROR;
+	}
+
+      ts->type = BT_INTEGER;
+      ts->kind = 1;
+      return MATCH_YES;
+    }
+  return MATCH_NO;
+}
+
+
 /* Matches a declaration-type-spec (F03:R502).  If successful, sets the ts
    structure to the matched specification.  This is necessary for FUNCTION and
    IMPLICIT statements.
@@ -4012,22 +4044,10 @@  gfc_match_decl_type_spec (gfc_typespec *ts, int implic
   /* Clear the current binding label, in case one is given.  */
   curr_binding_label = NULL;
 
-  if (gfc_match (" byte") == MATCH_YES)
-    {
-      if (!gfc_notify_std (GFC_STD_GNU, "BYTE type at %C"))
-	return MATCH_ERROR;
-
-      if (gfc_validate_kind (BT_INTEGER, 1, true) < 0)
-	{
-	  gfc_error ("BYTE type used at %C "
-		     "is not available on the target machine");
-	  return MATCH_ERROR;
-	}
-
-      ts->type = BT_INTEGER;
-      ts->kind = 1;
-      return MATCH_YES;
-    }
+  /* Match BYTE type-spec.  */
+  m = match_byte_typespec (ts);
+  if (m != MATCH_NO)
+    return m;
 
   m = gfc_match (" type (");
   matched_type = (m == MATCH_YES);
Index: gcc/testsuite/gfortran.dg/byte_3.f
===================================================================
--- gcc/testsuite/gfortran.dg/byte_3.f	(nonexistent)
+++ gcc/testsuite/gfortran.dg/byte_3.f	(working copy)
@@ -0,0 +1,6 @@ 
+c { dg-do run }
+c { dg-options "-std=legacy" }
+      bytea
+      a = 1
+      if (a /= 1 .and. kind(a) /= a) stop 1
+      end
Index: gcc/testsuite/gfortran.dg/byte_4.f90
===================================================================
--- gcc/testsuite/gfortran.dg/byte_4.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/byte_4.f90	(working copy)
@@ -0,0 +1,5 @@ 
+! { dg-do compile }
+      bytea          ! { dg-error "Unclassifiable statement" }
+      a = 1
+      print '(I0)', a
+      end