[patch,fortran] PR33268 read ('(f3.3)'), a rejected due to the extra (...)
Jerry DeLisle
jvdelisle@verizon.net
Mon Apr 28 07:05:00 GMT 2008
Hi Folks,
This patch provides for the "format" form of the READ and PRINT statements. By
"format" form I mean with no UNIT specified. The patch also rejects the WRITE
statement with this form. See section 9.5 of the F2003 Standard.
By example:
print('a'), 'Hello' ! Invalid, missing parens inside format string
write(*,('(a)')) 'Hello' ! Valid
write (*,'(f8.3)'), 3.141597 ! Extension, comma after the ')'
write ('(a)'), "invalid" ! Invalid, "format" form not allowed for WRITE
print ('(a)'), "valid" ! Valid, "format" form accepted
read ('(f3.3)')), a ! Valid, "format form accepted
To accomplish this, I added a new expression pointer, extra_comma, to pass the
io_kind and locus to gfc_resolve_dt. If this pointer is non-NULL, it indicates
that an extra comma preceding the I/O list was encountered. This signals a
possible alternate form of the I/O statement.
If the alternate form was used, the io_unit expression will come in as a
character type of expression. If so, it is assumed to be a format expression
and not a unit, and the pointers involved are adjusted so that the format
expression refers to the character expression in io_unit, and the io_unit is
pointed to the default unit for the io_kind.
The io_kind is passed in extra_comma->value.logical. I used this since it is an
int and can hold the enumerator type without problem. Another option would be
to add "io_kind k" to the union for value in gfc_expr, giving more readable code.
Regression tested on x86-64.
OK for trunk?
Jerry
2008-04-27 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/33268
* gfortran.h: Add extra_comma pointer to gfc_dt structure.
* io.c (gfc_free_dt): Free extra_comma.
(gfc_resolve_dt): If an extra comma was encountered and io_unit is type
BT_CHARACTER, resolve to format_expr and set default unit. Error if
io_kind is M_WRITE. (match_io): Match the extra comma and set new
pointer, extra_comma.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr33268.diff
Type: text/x-patch
Size: 2774 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20080428/cdadc8d1/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: io_constraints_4.f90
Type: text/x-fortran
Size: 389 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20080428/cdadc8d1/attachment-0001.bin>
More information about the Fortran
mailing list