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?