OSDN Git Service

PR fortran/28585
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 8 Oct 2006 13:21:42 +0000 (13:21 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 8 Oct 2006 13:21:42 +0000 (13:21 +0000)
* 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 (gfc_check_new_line): New function.
* simplify.c (gfc_simplify_new_line): New function.
* intrinsic.texi: Document new_line intrinsic.

* gfortran.dg/new_line.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117555 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/check.c
gcc/fortran/intrinsic.c
gcc/fortran/intrinsic.h
gcc/fortran/intrinsic.texi
gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/new_line.f90 [new file with mode: 0644]

index fa073c9..e9b52e4 100644 (file)
@@ -1,3 +1,13 @@
+2006-10-08  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 (gfc_check_new_line): New function.
+       * simplify.c (gfc_simplify_new_line): New function.
+       * intrinsic.texi: Document new_line intrinsic.
+
 2006-10-07  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
        PR fortran/16580
index 2365822..4884265 100644 (file)
@@ -1827,6 +1827,14 @@ gfc_check_nearest (gfc_expr * x, gfc_expr * s)
   return SUCCESS;
 }
 
+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)
index f95326f..9c30205 100644 (file)
@@ -1910,6 +1910,10 @@ add_functions (void)
 
   make_generic ("nearest", GFC_ISYM_NEAREST, GFC_STD_F95);
 
+  add_sym_1 ("new_line", 0, 0, BT_CHARACTER, dc, GFC_STD_F2003,
+             gfc_check_new_line, gfc_simplify_new_line, NULL,
+             i, 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 3e7ad39..a7cdd85 100644 (file)
@@ -98,6 +98,7 @@ try gfc_check_merge (gfc_expr *, gfc_expr *, gfc_expr *);
 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_modulo (gfc_expr *, gfc_expr *);
 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 e3d8cc8..ebb5e53 100644 (file)
@@ -183,6 +183,7 @@ Some intrinsics have documentation yet to be completed as indicated by 'document
 * @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
@@ -5879,6 +5880,45 @@ end program test_nearest
 
 
 
+@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 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 c9ca230..9d35bae 100644 (file)
@@ -2615,6 +2615,25 @@ simplify_nint (const char *name, gfc_expr * e, gfc_expr * k)
 
 
 gfc_expr *
+gfc_simplify_new_line (gfc_expr * e)
+{
+  gfc_expr *result;
+
+  if (e->expr_type != EXPR_CONSTANT)
+    return NULL;
+
+  result = gfc_constant_result (BT_CHARACTER, e->ts.kind, &e->where);
+
+  result->value.character.string = gfc_getmem (2);
+
+  result->value.character.length = 1;
+  result->value.character.string[0] = '\n';
+  result->value.character.string[1] = '\0';     /* For debugger */
+  return result;
+}
+
+
+gfc_expr *
 gfc_simplify_nint (gfc_expr * e, gfc_expr * k)
 {
   return simplify_nint ("NINT", e, k);
index e9b3ec9..9446d21 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-08  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/28585
+       * gfortran.dg/new_line.f90: New test.
+
 2006-10-07  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * gcc.dg/builtins-config.h: Ensure we use -std=c99 on solaris2.
diff --git a/gcc/testsuite/gfortran.dg/new_line.f90 b/gcc/testsuite/gfortran.dg/new_line.f90
new file mode 100644 (file)
index 0000000..355ca30
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do run }
+! Checks Fortran 2003's new_line intrinsic function
+! PR fortran/28585
+program new_line_check
+    implicit none
+    if(achar(10) /= new_line('a')) call abort()
+end program new_line_check