diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index fa073c9c57e..e9b52e435e9 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,13 @@ +2006-10-08 Tobias Burnus + + 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 PR fortran/16580 diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index 23658221705..4884265a329 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -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) diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index f95326f035e..9c30205b3e4 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -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); diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h index 3e7ad393455..a7cdd85b3c3 100644 --- a/gcc/fortran/intrinsic.h +++ b/gcc/fortran/intrinsic.h @@ -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 *); diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi index e3d8cc8eda8..ebb5e53b585 100644 --- a/gcc/fortran/intrinsic.texi +++ b/gcc/fortran/intrinsic.texi @@ -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 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index c9ca2300a67..9d35bae749e 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -2614,6 +2614,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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e9b3ec9bf6f..9446d216437 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-10-08 Tobias Burnus + + PR fortran/28585 + * gfortran.dg/new_line.f90: New test. + 2006-10-07 Kaveh R. Ghazi * 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 index 00000000000..355ca30209b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/new_line.f90 @@ -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