This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, fortran] PR28585: Add Fortran 2003 NEW_LINE intrinsic function
- From: Tobias Burnus <burnus at net-b dot de>
- To: fortran at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 18 Sep 2006 22:26:55 +0200
- Subject: Re: [Patch, fortran] PR28585: Add Fortran 2003 NEW_LINE intrinsic function
- References: <4504A704.70502@net-b.de>
Hello,
Tobias Burnus wrote on 2006-08-26:
> The new_line implementation is based on achar, I hope thus that it is simple enough that it can be committed while I wait for the reply from assign@gnu.org.
>
(Still no (e)mail regarding the copyright assignment)
> Remarks:
> (a) I use '\n', for Windows one probably would like to have '\r\n', but the Fortran 2003 standard requires that only a length-one character is returned.
> (b) One can pass either a scalar character or a character array to new_line function.
> The patch below does not work with arrays (ICE in gfc_conv_intrinsic_function). I fail to see how one allows arrays.
>
This is now fixed; new patch below.
2006-09-18 Tobias Burnus <burnus@net-b.de>
PR fortran/28585
* intrinsic.c(add_functions): Add new_line Fortran 2003 intrinsic
intrinsic.h: Add gfc_simplify_new_line and gfc_check_new_line prototypes
check.c: Add gfc_check_new_line
simplify.c: Add gfc_simplify_new_line
* gfortran.texi: Include Fortran 2003 in the goals for gfortran
* intrinsic.text: Document new_line intrinsic;
cross reference INQUIRE from ACCESS intrinsic.
Tobias
Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c (Revision 117031)
+++ gcc/fortran/intrinsic.c (Arbeitskopie)
@@ -1881,6 +1881,10 @@
make_generic ("nearest", GFC_ISYM_NEAREST, GFC_STD_F95);
+ add_sym_1 ("new_line", 1, 1, BT_CHARACTER, dc, GFC_STD_F2003,
+ gfc_check_new_line, gfc_simplify_new_line, NULL,
+ a, BT_CHARACTER, dc, REQUIRED);
+
add_sym_2 ("nint", 1, 1, BT_INTEGER, di, GFC_STD_F77,
gfc_check_a_ikind, gfc_simplify_nint, gfc_resolve_nint,
a, BT_REAL, dr, REQUIRED, kind, BT_INTEGER, di, OPTIONAL);
Index: gcc/fortran/intrinsic.h
===================================================================
--- gcc/fortran/intrinsic.h (Revision 117031)
+++ gcc/fortran/intrinsic.h (Arbeitskopie)
@@ -98,6 +98,7 @@
try gfc_check_minloc_maxloc (gfc_actual_arglist *);
try gfc_check_minval_maxval (gfc_actual_arglist *);
try gfc_check_nearest (gfc_expr *, gfc_expr *);
+try gfc_check_new_line (gfc_expr *);
try gfc_check_null (gfc_expr *);
try gfc_check_pack (gfc_expr *, gfc_expr *, gfc_expr *);
try gfc_check_precision (gfc_expr *);
@@ -255,6 +256,7 @@
gfc_expr *gfc_simplify_mvbits (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *,
gfc_expr *);
gfc_expr *gfc_simplify_nearest (gfc_expr *, gfc_expr *);
+gfc_expr *gfc_simplify_new_line (gfc_expr *);
gfc_expr *gfc_simplify_nint (gfc_expr *, gfc_expr *);
gfc_expr *gfc_simplify_null (gfc_expr *);
gfc_expr *gfc_simplify_idnint (gfc_expr *);
Index: gcc/fortran/gfortran.texi
===================================================================
--- gcc/fortran/gfortran.texi (Revision 117031)
+++ gcc/fortran/gfortran.texi (Arbeitskopie)
@@ -161,7 +161,7 @@
@item
Read a user's program,
stored in a file and containing instructions written
-in Fortran 77, Fortran 90 or Fortran 95.
+in Fortran 77, Fortran 90, Fortran 95 or Fortran 2003.
This file contains @dfn{source code}.
@item
Index: gcc/fortran/check.c
===================================================================
--- gcc/fortran/check.c (Revision 117031)
+++ gcc/fortran/check.c (Arbeitskopie)
@@ -1829,6 +1829,16 @@
try
+gfc_check_new_line (gfc_expr * a)
+{
+ if (type_check (a, 0, BT_CHARACTER) == FAILURE)
+ return FAILURE;
+
+ return SUCCESS;
+}
+
+
+try
gfc_check_null (gfc_expr * mold)
{
symbol_attribute attr;
Index: gcc/fortran/intrinsic.texi
===================================================================
--- gcc/fortran/intrinsic.texi (Revision 117031)
+++ gcc/fortran/intrinsic.texi (Arbeitskopie)
@@ -183,6 +183,7 @@
* @code{MODULO}: MODULO, Modulo function
* @code{MVBITS}: MVBITS, Move bits from one integer to another
* @code{NEAREST}: NEAREST, Nearest representable number
+* @code{NEW_LINE}: NEW_LINE, New line character
* @code{NINT}: NINT, Nearest whole number
* @code{NOT}: NOT, Logical negation
* @code{NULL}: NULL, Function that returns an disassociated pointer
@@ -386,7 +387,8 @@
@findex @code{ACCESS}
@cindex file system functions
-Not yet implemented in gfortran.
+Not yet implemented in gfortran. Except for querying the executable state,
+the Fortran 95 intrinsic statement @code{INQUIRE} can be used instead.
@table @asis
@item @emph{Description}:
@@ -396,13 +398,14 @@
@item @emph{Class}:
@item @emph{Syntax}:
+Checks whether the file associated with the given file name exists, is
+readable, writeable or executable.
@item @emph{Arguments}:
@item @emph{Return value}:
@item @emph{Example}:
@item @emph{Specific names}:
@item @emph{See also}:
@uref{http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19292, g77 features lacking in gfortran}
-
@end table
@@ -438,7 +441,8 @@
@smallexample
program test_achar
character c
- c = achar(32)
+ c = achar(70)
+ print *, c ! prints 'F'
end program test_achar
@end smallexample
@end table
@@ -5879,6 +5883,43 @@
+@node NEW_LINE
+@section @code{NEW_LINE} --- New line character
+@findex @code{NEW_LINE} intrinsic
+@findex @code{NEW_LINE} intrinsic
+
+@table @asis
+@item @emph{Description}:
+@code{NEW_LINE(C)} returns the new-line character
+
+@item @emph{Standard}:
+F2003 and later
+
+@item @emph{Class}:
+Elemental function
+
+@item @emph{Syntax}:
+@code{C = NEW_LINE(C)}
+
+@item @emph{Arguments}:
+@multitable @columnfractions .15 .80
+@item @var{C} @tab The type of the argument shall be a scalar or array of the
+ type @code{CHARACTER}.
+@end multitable
+
+@item @emph{Return value}:
+Returns a @var{CHARACTER} scalar of length one with the new-line character of
+the same kind as parameter @var{C}.
+
+@item @emph{Example}:
+@smallexample
+program newline
+ implicit none
+ write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'
+end program newline
+@end smallexample
+@end table
+
@node NINT
@section @code{NINT} --- Nearest whole number
@findex @code{NINT} intrinsic
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c (Revision 117031)
+++ gcc/fortran/simplify.c (Arbeitskopie)
@@ -2543,7 +2532,23 @@
return range_check (result, "NEAREST");
}
+gfc_expr *
+gfc_simplify_new_line (gfc_expr * e)
+{
+ gfc_expr *result;
+ result = gfc_constant_result (BT_CHARACTER, gfc_default_character_kind,
+ &e->where);
+
+ result->value.character.string = gfc_getmem (2);
+
+ result->value.character.length = 1; /* f2003 allows only one character */
+ result->value.character.string[0] = '\n';
+ result->value.character.string[1] = '\0'; /* For debugger */
+ return result;
+}
+
static gfc_expr *
simplify_nint (const char *name, gfc_expr * e, gfc_expr * k)
{