FMT_NONE, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_LPAREN,
FMT_RPAREN, FMT_X, FMT_SIGN, FMT_BLANK, FMT_CHAR, FMT_P, FMT_IBOZ, FMT_F,
- FMT_E, FMT_EXT, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END, FMT_ERROR, FMT_DC,
- FMT_DP, FMT_T, FMT_TR, FMT_TL
+ FMT_E, FMT_EN, FMT_ES, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END,
+ FMT_ERROR, FMT_DC, FMT_DP, FMT_T, FMT_TR, FMT_TL, FMT_STAR, FMT_RC,
+ FMT_RD, FMT_RN, FMT_RP, FMT_RU, FMT_RZ
}
format_token;
case 'E':
c = next_char_not_space (&error);
- if (c == 'N' || c == 'S')
- token = FMT_EXT;
+ if (c == 'N' )
+ token = FMT_EN;
+ else if (c == 'S')
+ token = FMT_ES;
else
{
token = FMT_E;
}
break;
+ case 'R':
+ c = next_char_not_space (&error);
+ switch (c)
+ {
+ case 'C':
+ token = FMT_RC;
+ break;
+ case 'D':
+ token = FMT_RD;
+ break;
+ case 'N':
+ token = FMT_RN;
+ break;
+ case 'P':
+ token = FMT_RP;
+ break;
+ case 'U':
+ token = FMT_RU;
+ break;
+ case 'Z':
+ token = FMT_RZ;
+ break;
+ default:
+ token = FMT_UNKNOWN;
+ unget_char ();
+ break;
+ }
+ break;
+
case '\0':
token = FMT_END;
break;
+ case '*':
+ token = FMT_STAR;
+ break;
+
default:
token = FMT_UNKNOWN;
break;
}
+static const char *
+token_to_string (format_token t)
+{
+ switch (t)
+ {
+ case FMT_D:
+ return "D";
+ case FMT_G:
+ return "G";
+ case FMT_E:
+ return "E";
+ case FMT_EN:
+ return "EN";
+ case FMT_ES:
+ return "ES";
+ default:
+ return "";
+ }
+}
+
/* Check a format statement. The format string, either from a FORMAT
statement or a constant in an I/O statement has already been parsed
by itself, and we are checking it for validity. The dual origin
format_item_1:
switch (t)
{
+ case FMT_STAR:
+ repeat = -1;
+ t = format_lex ();
+ if (t == FMT_ERROR)
+ goto fail;
+ if (t == FMT_LPAREN)
+ {
+ level++;
+ goto format_item;
+ }
+ error = _("Left parenthesis required after '*'");
+ goto syntax;
+
case FMT_POSINT:
repeat = value;
t = format_lex ();
case FMT_X:
/* X requires a prior number if we're being pedantic. */
+ if (mode != MODE_FORMAT)
+ format_locus.nextc += format_string_pos;
if (gfc_notify_std (GFC_STD_GNU, "Extension: X descriptor "
- "requires leading space count at %C")
+ "requires leading space count at %L", &format_locus)
== FAILURE)
return FAILURE;
goto between_desc;
case FMT_BLANK:
case FMT_DP:
case FMT_DC:
+ case FMT_RC:
+ case FMT_RD:
+ case FMT_RN:
+ case FMT_RP:
+ case FMT_RU:
+ case FMT_RZ:
goto between_desc;
case FMT_CHAR:
if (t == FMT_ERROR)
goto fail;
- if (gfc_notify_std (GFC_STD_GNU, "Extension: $ descriptor at %C")
- == FAILURE)
+ if (gfc_notify_std (GFC_STD_GNU, "Extension: $ descriptor at %L",
+ &format_locus) == FAILURE)
return FAILURE;
if (t != FMT_RPAREN || level > 0)
{
- gfc_warning ("$ should be the last specifier in format at %C");
+ gfc_warning ("$ should be the last specifier in format at %L",
+ &format_locus);
goto optional_comma_1;
}
case FMT_IBOZ:
case FMT_F:
case FMT_E:
- case FMT_EXT:
+ case FMT_EN:
+ case FMT_ES:
case FMT_G:
case FMT_L:
case FMT_A:
break;
case FMT_P:
- if (pedantic)
+ /* No comma after P allowed only for F, E, EN, ES, D, or G.
+ 10.1.1 (1). */
+ t = format_lex ();
+ if (t == FMT_ERROR)
+ goto fail;
+ if (gfc_option.allow_std < GFC_STD_F2003 && t != FMT_COMMA
+ && t != FMT_F && t != FMT_E && t != FMT_EN && t != FMT_ES
+ && t != FMT_D && t != FMT_G && t != FMT_RPAREN && t != FMT_SLASH)
+ {
+ error = _("Comma required after P descriptor");
+ goto syntax;
+ }
+ if (t != FMT_COMMA)
{
- t = format_lex ();
- if (t == FMT_ERROR)
- goto fail;
if (t == FMT_POSINT)
{
- error = _("Repeat count cannot follow P descriptor");
+ t = format_lex ();
+ if (t == FMT_ERROR)
+ goto fail;
+ }
+ if (t != FMT_F && t != FMT_E && t != FMT_EN && t != FMT_ES && t != FMT_D
+ && t != FMT_G && t != FMT_RPAREN && t != FMT_SLASH)
+ {
+ error = _("Comma required after P descriptor");
goto syntax;
}
-
- saved_token = t;
}
+ saved_token = t;
goto optional_comma;
case FMT_T:
switch (gfc_notification_std (GFC_STD_GNU))
{
case WARNING:
+ if (mode != MODE_FORMAT)
+ format_locus.nextc += format_string_pos;
gfc_warning ("Extension: Missing positive width after L "
- "descriptor at %C");
+ "descriptor at %L", &format_locus);
saved_token = t;
break;
case FMT_D:
case FMT_E:
case FMT_G:
- case FMT_EXT:
+ case FMT_EN:
+ case FMT_ES:
u = format_lex ();
if (t == FMT_G && u == FMT_ZERO)
{
goto syntax;
}
if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: 'G0' in "
- "format at %C") == FAILURE)
+ "format at %L", &format_locus) == FAILURE)
return FAILURE;
u = format_lex ();
if (u != FMT_PERIOD)
break;
}
+ if (u != FMT_POSINT)
+ {
+ format_locus.nextc += format_string_pos;
+ gfc_error ("Positive width required in format "
+ "specifier %s at %L", token_to_string (t),
+ &format_locus);
+ saved_token = u;
+ goto fail;
+ }
+
u = format_lex ();
if (u == FMT_ERROR)
goto fail;
if (u != FMT_PERIOD)
{
/* Warn if -std=legacy, otherwise error. */
+ format_locus.nextc += format_string_pos;
if (gfc_option.warn_std != 0)
- gfc_error_now ("Period required in format specifier at %C");
+ {
+ gfc_error ("Period required in format "
+ "specifier %s at %L", token_to_string (t),
+ &format_locus);
+ saved_token = u;
+ goto fail;
+ }
else
- gfc_warning ("Period required in format specifier at %C");
+ gfc_warning ("Period required in format "
+ "specifier %s at %L", token_to_string (t),
+ &format_locus);
+ /* If we go to finished, we need to unwind this
+ before the next round. */
+ format_locus.nextc -= format_string_pos;
saved_token = u;
break;
}
{
/* Warn if -std=legacy, otherwise error. */
if (gfc_option.warn_std != 0)
- gfc_error_now ("Period required in format specifier at %C");
- else
- gfc_warning ("Period required in format specifier at %C");
+ {
+ error = _("Period required in format specifier");
+ goto syntax;
+ }
+ if (mode != MODE_FORMAT)
+ format_locus.nextc += format_string_pos;
+ gfc_warning ("Period required in format specifier at %L",
+ &format_locus);
saved_token = t;
break;
}
case FMT_H:
if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
- gfc_warning ("The H format specifier at %C is"
- " a Fortran 95 deleted feature");
-
+ {
+ if (mode != MODE_FORMAT)
+ format_locus.nextc += format_string_pos;
+ gfc_warning ("The H format specifier at %L is"
+ " a Fortran 95 deleted feature", &format_locus);
+ }
if (mode == MODE_STRING)
{
format_string += value;
format_length -= value;
+ format_string_pos += repeat;
}
else
{
goto syntax;
default:
- if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
- == FAILURE)
+ if (mode != MODE_FORMAT)
+ format_locus.nextc += format_string_pos - 1;
+ if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %L",
+ &format_locus) == FAILURE)
return FAILURE;
+ /* If we do not actually return a failure, we need to unwind this
+ before the next round. */
+ if (mode != MODE_FORMAT)
+ format_locus.nextc -= format_string_pos;
goto format_item_1;
}
goto syntax;
default:
- if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
- == FAILURE)
+ if (mode != MODE_FORMAT)
+ format_locus.nextc += format_string_pos;
+ if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %L",
+ &format_locus) == FAILURE)
return FAILURE;
+ /* If we do not actually return a failure, we need to unwind this
+ before the next round. */
+ if (mode != MODE_FORMAT)
+ format_locus.nextc -= format_string_pos;
saved_token = t;
break;
}
goto format_item;
-
+
syntax:
if (mode != MODE_FORMAT)
format_locus.nextc += format_string_pos;
static gfc_try
check_format_string (gfc_expr *e, bool is_input)
{
+ gfc_try rv;
+ int i;
if (!e || e->ts.type != BT_CHARACTER || e->expr_type != EXPR_CONSTANT)
return SUCCESS;
format string that has been calculated, but that's probably not worth the
effort. */
format_locus = e->where;
-
- return check_format (is_input);
+ rv = check_format (is_input);
+ /* check for extraneous characters at the end of an otherwise valid format
+ string, like '(A10,I3)F5'
+ start at the end and move back to the last character processed,
+ spaces are OK */
+ if (rv == SUCCESS && e->value.character.length > format_string_pos)
+ for (i=e->value.character.length-1;i>format_string_pos-1;i--)
+ if (e->value.character.string[i] != ' ')
+ {
+ format_locus.nextc += format_length + 1;
+ gfc_warning ("Extraneous characters in format at %L", &format_locus);
+ break;
+ }
+ return rv;
}
/* Checks on the ROUND specifier. */
if (open->round)
{
- /* When implemented, change the following to use gfc_notify_std F2003. */
- gfc_error ("Fortran F2003: ROUND= specifier at %C not implemented");
+ if (gfc_notify_std (GFC_STD_F2003, "Fortran F2003: ROUND= at %C "
+ "not allowed in Fortran 95") == FAILURE)
goto cleanup;
if (open->round->expr_type == EXPR_CONSTANT)
/* Resolve everything in a gfc_dt structure. */
gfc_try
-gfc_resolve_dt (gfc_dt *dt)
+gfc_resolve_dt (gfc_dt *dt, locus *loc)
{
gfc_expr *e;
RESOLVE_TAG (&tag_e_async, dt->asynchronous);
e = dt->io_unit;
+ if (e == NULL)
+ {
+ gfc_error ("UNIT not specified at %L", loc);
+ return FAILURE;
+ }
+
if (gfc_resolve_expr (e) == SUCCESS
&& (e->ts.type != BT_INTEGER
&& (e->ts.type != BT_CHARACTER || e->expr_type != EXPR_VARIABLE)))
&& mpz_sgn (e->value.integer) < 0)
{
gfc_error ("UNIT number in statement at %L must be non-negative", &e->where);
+ return FAILURE;
}
if (dt->extra_comma
if (gfc_pure (NULL)
&& gfc_impure_variable (expr->symtree->n.sym)
+ && current_dt->io_unit
&& current_dt->io_unit->ts.type == BT_CHARACTER)
{
gfc_error ("Cannot read to variable '%s' in PURE procedure at %C",
break;
case M_WRITE:
- if (current_dt->io_unit->ts.type == BT_CHARACTER
+ if (current_dt->io_unit
+ && current_dt->io_unit->ts.type == BT_CHARACTER
&& gfc_pure (NULL)
&& current_dt->io_unit->expr_type == EXPR_VARIABLE
&& gfc_impure_variable (current_dt->io_unit->symtree->n.sym))
if (dt->round)
{
- /* When implemented, change the following to use gfc_notify_std F2003.
if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ROUND= at %C "
"not allowed in Fortran 95") == FAILURE)
- return MATCH_ERROR; */
- gfc_error ("F2003 Feature: ROUND= specifier at %C not implemented");
- return MATCH_ERROR;
+ return MATCH_ERROR;
if (dt->round->expr_type == EXPR_CONSTANT)
{
{
gfc_wait *wait;
match m;
- locus loc;
m = gfc_match_char ('(');
if (m == MATCH_NO)
wait = XCNEW (gfc_wait);
- loc = gfc_current_locus;
-
m = match_wait_element (wait);
if (m == MATCH_ERROR)
goto cleanup;