1 /* Deal with I/O statements & related stuff.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
30 format_asterisk = {0, NULL, NULL, -1, ST_LABEL_FORMAT, ST_LABEL_FORMAT, NULL,
35 const char *name, *spec, *value;
41 tag_file = { "FILE", " file =", " %e", BT_CHARACTER },
42 tag_status = { "STATUS", " status =", " %e", BT_CHARACTER},
43 tag_e_access = {"ACCESS", " access =", " %e", BT_CHARACTER},
44 tag_e_form = {"FORM", " form =", " %e", BT_CHARACTER},
45 tag_e_recl = {"RECL", " recl =", " %e", BT_INTEGER},
46 tag_e_blank = {"BLANK", " blank =", " %e", BT_CHARACTER},
47 tag_e_position = {"POSITION", " position =", " %e", BT_CHARACTER},
48 tag_e_action = {"ACTION", " action =", " %e", BT_CHARACTER},
49 tag_e_delim = {"DELIM", " delim =", " %e", BT_CHARACTER},
50 tag_e_pad = {"PAD", " pad =", " %e", BT_CHARACTER},
51 tag_e_decimal = {"DECIMAL", " decimal =", " %e", BT_CHARACTER},
52 tag_e_encoding = {"ENCODING", " encoding =", " %e", BT_CHARACTER},
53 tag_e_async = {"ASYNCHRONOUS", " asynchronous =", " %e", BT_CHARACTER},
54 tag_e_round = {"ROUND", " round =", " %e", BT_CHARACTER},
55 tag_e_sign = {"SIGN", " sign =", " %e", BT_CHARACTER},
56 tag_unit = {"UNIT", " unit =", " %e", BT_INTEGER},
57 tag_advance = {"ADVANCE", " advance =", " %e", BT_CHARACTER},
58 tag_rec = {"REC", " rec =", " %e", BT_INTEGER},
59 tag_spos = {"POSITION", " pos =", " %e", BT_INTEGER},
60 tag_format = {"FORMAT", NULL, NULL, BT_CHARACTER},
61 tag_iomsg = {"IOMSG", " iomsg =", " %e", BT_CHARACTER},
62 tag_iostat = {"IOSTAT", " iostat =", " %v", BT_INTEGER},
63 tag_size = {"SIZE", " size =", " %v", BT_INTEGER},
64 tag_exist = {"EXIST", " exist =", " %v", BT_LOGICAL},
65 tag_opened = {"OPENED", " opened =", " %v", BT_LOGICAL},
66 tag_named = {"NAMED", " named =", " %v", BT_LOGICAL},
67 tag_name = {"NAME", " name =", " %v", BT_CHARACTER},
68 tag_number = {"NUMBER", " number =", " %v", BT_INTEGER},
69 tag_s_access = {"ACCESS", " access =", " %v", BT_CHARACTER},
70 tag_sequential = {"SEQUENTIAL", " sequential =", " %v", BT_CHARACTER},
71 tag_direct = {"DIRECT", " direct =", " %v", BT_CHARACTER},
72 tag_s_form = {"FORM", " form =", " %v", BT_CHARACTER},
73 tag_formatted = {"FORMATTED", " formatted =", " %v", BT_CHARACTER},
74 tag_unformatted = {"UNFORMATTED", " unformatted =", " %v", BT_CHARACTER},
75 tag_s_recl = {"RECL", " recl =", " %v", BT_INTEGER},
76 tag_nextrec = {"NEXTREC", " nextrec =", " %v", BT_INTEGER},
77 tag_s_blank = {"BLANK", " blank =", " %v", BT_CHARACTER},
78 tag_s_position = {"POSITION", " position =", " %v", BT_CHARACTER},
79 tag_s_action = {"ACTION", " action =", " %v", BT_CHARACTER},
80 tag_read = {"READ", " read =", " %v", BT_CHARACTER},
81 tag_write = {"WRITE", " write =", " %v", BT_CHARACTER},
82 tag_readwrite = {"READWRITE", " readwrite =", " %v", BT_CHARACTER},
83 tag_s_delim = {"DELIM", " delim =", " %v", BT_CHARACTER},
84 tag_s_pad = {"PAD", " pad =", " %v", BT_CHARACTER},
85 tag_s_decimal = {"DECIMAL", " decimal =", " %v", BT_CHARACTER},
86 tag_s_encoding = {"ENCODING", " encoding =", " %v", BT_CHARACTER},
87 tag_s_async = {"ASYNCHRONOUS", " asynchronous =", " %v", BT_CHARACTER},
88 tag_s_round = {"ROUND", " round =", " %v", BT_CHARACTER},
89 tag_s_sign = {"SIGN", " sign =", " %v", BT_CHARACTER},
90 tag_iolength = {"IOLENGTH", " iolength =", " %v", BT_INTEGER},
91 tag_convert = {"CONVERT", " convert =", " %e", BT_CHARACTER},
92 tag_strm_out = {"POS", " pos =", " %v", BT_INTEGER},
93 tag_err = {"ERR", " err =", " %l", BT_UNKNOWN},
94 tag_end = {"END", " end =", " %l", BT_UNKNOWN},
95 tag_eor = {"EOR", " eor =", " %l", BT_UNKNOWN},
96 tag_id = {"ID", " id =", " %v", BT_INTEGER},
97 tag_pending = {"PENDING", " pending =", " %v", BT_LOGICAL};
99 static gfc_dt *current_dt;
101 #define RESOLVE_TAG(x, y) if (resolve_tag(x, y) == FAILURE) return FAILURE;
104 /**************** Fortran 95 FORMAT parser *****************/
106 /* FORMAT tokens returned by format_lex(). */
109 FMT_NONE, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
110 FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_POS, FMT_LPAREN,
111 FMT_RPAREN, FMT_X, FMT_SIGN, FMT_BLANK, FMT_CHAR, FMT_P, FMT_IBOZ, FMT_F,
112 FMT_E, FMT_EXT, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END, FMT_ERROR, FMT_DC,
117 /* Local variables for checking format strings. The saved_token is
118 used to back up by a single format token during the parsing
120 static gfc_char_t *format_string;
121 static int format_length, use_last_char;
123 static format_token saved_token;
126 { MODE_STRING, MODE_FORMAT, MODE_COPY }
130 /* Return the next character in the format string. */
133 next_char (int in_string)
145 if (mode == MODE_STRING)
146 c = *format_string++;
149 c = gfc_next_char_literal (in_string);
154 if (gfc_option.flag_backslash && c == '\\')
156 locus old_locus = gfc_current_locus;
158 if (gfc_match_special_char (&c) == MATCH_NO)
159 gfc_current_locus = old_locus;
161 if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
162 gfc_warning ("Extension: backslash character at %C");
165 if (mode == MODE_COPY)
166 *format_string++ = c;
168 c = gfc_wide_toupper (c);
173 /* Back up one character position. Only works once. */
181 /* Eat up the spaces and return a character. */
184 next_char_not_space (bool *error)
192 if (gfc_option.allow_std & GFC_STD_GNU)
193 gfc_warning ("Extension: Tab character in format at %C");
196 gfc_error ("Extension: Tab character in format at %C");
202 while (gfc_is_whitespace (c));
206 static int value = 0;
208 /* Simple lexical analyzer for getting the next token in a FORMAT
220 if (saved_token != FMT_NONE)
223 saved_token = FMT_NONE;
227 c = next_char_not_space (&error);
235 c = next_char_not_space (&error);
246 c = next_char_not_space (&error);
248 value = 10 * value + c - '0';
257 token = FMT_SIGNED_INT;
276 c = next_char_not_space (&error);
279 value = 10 * value + c - '0';
287 token = zflag ? FMT_ZERO : FMT_POSINT;
311 c = next_char_not_space (&error);
312 if (c != 'L' && c != 'R')
331 c = next_char_not_space (&error);
332 if (c != 'P' && c != 'S')
339 c = next_char_not_space (&error);
340 if (c == 'N' || c == 'Z')
401 c = next_char_not_space (&error);
402 if (c == 'N' || c == 'S')
429 c = next_char_not_space (&error);
432 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DP format "
433 "specifier not allowed at %C") == FAILURE)
439 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DC format "
440 "specifier not allowed at %C") == FAILURE)
467 /* Check a format statement. The format string, either from a FORMAT
468 statement or a constant in an I/O statement has already been parsed
469 by itself, and we are checking it for validity. The dual origin
470 means that the warning message is a little less than great. */
473 check_format (bool is_input)
475 const char *posint_required = _("Positive width required");
476 const char *nonneg_required = _("Nonnegative width required");
477 const char *unexpected_element = _("Unexpected element");
478 const char *unexpected_end = _("Unexpected end of format string");
479 const char *zero_width = _("Zero width in format descriptor");
488 saved_token = FMT_NONE;
498 error = _("Missing leading left parenthesis");
506 goto finished; /* Empty format is legal */
510 /* In this state, the next thing has to be a format item. */
539 /* Signed integer can only precede a P format. */
545 error = _("Expected P edit descriptor");
552 /* P requires a prior number. */
553 error = _("P descriptor requires leading scale factor");
557 /* X requires a prior number if we're being pedantic. */
558 if (gfc_notify_std (GFC_STD_GNU, "Extension: X descriptor "
559 "requires leading space count at %C")
571 goto extension_optional_comma;
582 if (gfc_notify_std (GFC_STD_GNU, "Extension: $ descriptor at %C")
585 if (t != FMT_RPAREN || level > 0)
587 gfc_warning ("$ should be the last specifier in format at %C");
588 goto optional_comma_1;
606 error = unexpected_end;
610 error = unexpected_element;
615 /* In this state, t must currently be a data descriptor.
616 Deal with things that can/must follow the descriptor. */
634 error = _("Repeat count cannot follow P descriptor");
651 switch (gfc_notification_std (GFC_STD_GNU))
654 gfc_warning ("Extension: Missing positive width after L "
660 error = posint_required;
690 if (t == FMT_G && u == FMT_ZERO)
698 return gfc_notify_std (GFC_STD_F2008, "Fortran F2008: 'G0' in "
706 error = posint_required;
715 /* Warn if -std=legacy, otherwise error. */
716 if (gfc_option.warn_std != 0)
717 gfc_error_now ("Period required in format specifier at %C");
719 gfc_warning ("Period required in format specifier at %C");
727 if (u != FMT_ZERO && u != FMT_POSINT)
729 error = nonneg_required;
736 /* Look for optional exponent. */
751 error = _("Positive exponent width required");
762 if (t != FMT_ZERO && t != FMT_POSINT)
764 error = nonneg_required;
767 else if (is_input && t == FMT_ZERO)
769 error = posint_required;
778 /* Warn if -std=legacy, otherwise error. */
779 if (gfc_option.warn_std != 0)
780 gfc_error_now ("Period required in format specifier at %C");
782 gfc_warning ("Period required in format specifier at %C");
790 if (t != FMT_ZERO && t != FMT_POSINT)
792 error = nonneg_required;
799 if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
800 gfc_warning ("The H format specifier at %C is"
801 " a Fortran 95 deleted feature");
803 if (mode == MODE_STRING)
805 format_string += value;
806 format_length -= value;
822 if (t != FMT_ZERO && t != FMT_POSINT)
824 error = nonneg_required;
827 else if (is_input && t == FMT_ZERO)
829 error = posint_required;
845 if (t != FMT_ZERO && t != FMT_POSINT)
847 error = nonneg_required;
855 error = unexpected_element;
860 /* Between a descriptor and what comes next. */
881 error = unexpected_end;
885 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
892 /* Optional comma is a weird between state where we've just finished
893 reading a colon, slash, dollar or P descriptor. */
910 /* Assume that we have another format item. */
917 extension_optional_comma:
918 /* As a GNU extension, permit a missing comma after a string literal. */
938 error = unexpected_end;
942 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
952 gfc_error ("%s in format string at %C", error);
954 /* TODO: More elaborate measures are needed to show where a problem
955 is within a format string that has been calculated. */
963 /* Given an expression node that is a constant string, see if it looks
964 like a format string. */
967 check_format_string (gfc_expr *e, bool is_input)
969 if (!e || e->ts.type != BT_CHARACTER || e->expr_type != EXPR_CONSTANT)
973 format_string = e->value.character.string;
974 return check_format (is_input);
978 /************ Fortran 95 I/O statement matchers *************/
980 /* Match a FORMAT statement. This amounts to actually parsing the
981 format descriptors in order to correctly locate the end of the
985 gfc_match_format (void)
990 if (gfc_current_ns->proc_name
991 && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
993 gfc_error ("Format statement in module main block at %C");
997 if (gfc_statement_label == NULL)
999 gfc_error ("Missing format label at %C");
1002 gfc_gobble_whitespace ();
1007 start = gfc_current_locus;
1009 if (check_format (false) == FAILURE)
1012 if (gfc_match_eos () != MATCH_YES)
1014 gfc_syntax_error (ST_FORMAT);
1018 /* The label doesn't get created until after the statement is done
1019 being matched, so we have to leave the string for later. */
1021 gfc_current_locus = start; /* Back to the beginning */
1024 new_st.op = EXEC_NOP;
1027 e->expr_type = EXPR_CONSTANT;
1028 e->ts.type = BT_CHARACTER;
1029 e->ts.kind = gfc_default_character_kind;
1031 e->value.character.string = format_string
1032 = gfc_get_wide_string (format_length + 1);
1033 e->value.character.length = format_length;
1034 gfc_statement_label->format = e;
1037 check_format (false); /* Guaranteed to succeed */
1038 gfc_match_eos (); /* Guaranteed to succeed */
1044 /* Match an expression I/O tag of some sort. */
1047 match_etag (const io_tag *tag, gfc_expr **v)
1052 m = gfc_match (tag->spec);
1056 m = gfc_match (tag->value, &result);
1059 gfc_error ("Invalid value for %s specification at %C", tag->name);
1065 gfc_error ("Duplicate %s specification at %C", tag->name);
1066 gfc_free_expr (result);
1075 /* Match a variable I/O tag of some sort. */
1078 match_vtag (const io_tag *tag, gfc_expr **v)
1083 m = gfc_match (tag->spec);
1087 m = gfc_match (tag->value, &result);
1090 gfc_error ("Invalid value for %s specification at %C", tag->name);
1096 gfc_error ("Duplicate %s specification at %C", tag->name);
1097 gfc_free_expr (result);
1101 if (result->symtree->n.sym->attr.intent == INTENT_IN)
1103 gfc_error ("Variable tag cannot be INTENT(IN) at %C");
1104 gfc_free_expr (result);
1108 if (gfc_pure (NULL) && gfc_impure_variable (result->symtree->n.sym))
1110 gfc_error ("Variable tag cannot be assigned in PURE procedure at %C");
1111 gfc_free_expr (result);
1120 /* Match I/O tags that cause variables to become redefined. */
1123 match_out_tag(const io_tag *tag, gfc_expr **result)
1127 m = match_vtag(tag, result);
1129 gfc_check_do_variable((*result)->symtree);
1135 /* Match a label I/O tag. */
1138 match_ltag (const io_tag *tag, gfc_st_label ** label)
1144 m = gfc_match (tag->spec);
1148 m = gfc_match (tag->value, label);
1151 gfc_error ("Invalid value for %s specification at %C", tag->name);
1157 gfc_error ("Duplicate %s label specification at %C", tag->name);
1161 if (gfc_reference_st_label (*label, ST_LABEL_TARGET) == FAILURE)
1168 /* Resolution of the FORMAT tag, to be called from resolve_tag. */
1171 resolve_tag_format (const gfc_expr *e)
1173 if (e->expr_type == EXPR_CONSTANT
1174 && (e->ts.type != BT_CHARACTER
1175 || e->ts.kind != gfc_default_character_kind))
1177 gfc_error ("Constant expression in FORMAT tag at %L must be "
1178 "of type default CHARACTER", &e->where);
1182 /* If e's rank is zero and e is not an element of an array, it should be
1183 of integer or character type. The integer variable should be
1185 if (e->symtree == NULL || e->symtree->n.sym->as == NULL
1186 || e->symtree->n.sym->as->rank == 0)
1188 if (e->ts.type != BT_CHARACTER && e->ts.type != BT_INTEGER)
1190 gfc_error ("FORMAT tag at %L must be of type CHARACTER or INTEGER",
1194 else if (e->ts.type == BT_INTEGER && e->expr_type == EXPR_VARIABLE)
1196 if (gfc_notify_std (GFC_STD_F95_DEL, "Deleted feature: ASSIGNED "
1197 "variable in FORMAT tag at %L", &e->where)
1200 if (e->symtree->n.sym->attr.assign != 1)
1202 gfc_error ("Variable '%s' at %L has not been assigned a "
1203 "format label", e->symtree->n.sym->name, &e->where);
1207 else if (e->ts.type == BT_INTEGER)
1209 gfc_error ("Scalar '%s' in FORMAT tag at %L is not an ASSIGNED "
1210 "variable", gfc_basic_typename (e->ts.type), &e->where);
1217 /* If rank is nonzero, we allow the type to be character under GFC_STD_GNU
1218 and other type under GFC_STD_LEGACY. It may be assigned an Hollerith
1220 if (e->ts.type == BT_CHARACTER)
1222 if (gfc_notify_std (GFC_STD_GNU, "Extension: Character array "
1223 "in FORMAT tag at %L", &e->where) == FAILURE)
1228 if (gfc_notify_std (GFC_STD_LEGACY, "Extension: Non-character "
1229 "in FORMAT tag at %L", &e->where) == FAILURE)
1237 /* Do expression resolution and type-checking on an expression tag. */
1240 resolve_tag (const io_tag *tag, gfc_expr *e)
1245 if (gfc_resolve_expr (e) == FAILURE)
1248 if (tag == &tag_format)
1249 return resolve_tag_format (e);
1251 if (e->ts.type != tag->type)
1253 gfc_error ("%s tag at %L must be of type %s", tag->name,
1254 &e->where, gfc_basic_typename (tag->type));
1260 gfc_error ("%s tag at %L must be scalar", tag->name, &e->where);
1264 if (tag == &tag_iomsg)
1266 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: IOMSG tag at %L",
1267 &e->where) == FAILURE)
1271 if ((tag == &tag_iostat || tag == &tag_size || tag == &tag_iolength)
1272 && e->ts.kind != gfc_default_integer_kind)
1274 if (gfc_notify_std (GFC_STD_F2003, "Fortran 95 requires default "
1275 "INTEGER in %s tag at %L", tag->name, &e->where)
1280 if (tag == &tag_convert)
1282 if (gfc_notify_std (GFC_STD_GNU, "Extension: CONVERT tag at %L",
1283 &e->where) == FAILURE)
1291 /* Match a single tag of an OPEN statement. */
1294 match_open_element (gfc_open *open)
1298 m = match_etag (&tag_e_async, &open->asynchronous);
1301 m = match_etag (&tag_unit, &open->unit);
1304 m = match_out_tag (&tag_iomsg, &open->iomsg);
1307 m = match_out_tag (&tag_iostat, &open->iostat);
1310 m = match_etag (&tag_file, &open->file);
1313 m = match_etag (&tag_status, &open->status);
1316 m = match_etag (&tag_e_access, &open->access);
1319 m = match_etag (&tag_e_form, &open->form);
1322 m = match_etag (&tag_e_recl, &open->recl);
1325 m = match_etag (&tag_e_blank, &open->blank);
1328 m = match_etag (&tag_e_position, &open->position);
1331 m = match_etag (&tag_e_action, &open->action);
1334 m = match_etag (&tag_e_delim, &open->delim);
1337 m = match_etag (&tag_e_pad, &open->pad);
1340 m = match_etag (&tag_e_decimal, &open->decimal);
1343 m = match_etag (&tag_e_encoding, &open->encoding);
1346 m = match_etag (&tag_e_round, &open->round);
1349 m = match_etag (&tag_e_sign, &open->sign);
1352 m = match_ltag (&tag_err, &open->err);
1355 m = match_etag (&tag_convert, &open->convert);
1363 /* Free the gfc_open structure and all the expressions it contains. */
1366 gfc_free_open (gfc_open *open)
1371 gfc_free_expr (open->unit);
1372 gfc_free_expr (open->iomsg);
1373 gfc_free_expr (open->iostat);
1374 gfc_free_expr (open->file);
1375 gfc_free_expr (open->status);
1376 gfc_free_expr (open->access);
1377 gfc_free_expr (open->form);
1378 gfc_free_expr (open->recl);
1379 gfc_free_expr (open->blank);
1380 gfc_free_expr (open->position);
1381 gfc_free_expr (open->action);
1382 gfc_free_expr (open->delim);
1383 gfc_free_expr (open->pad);
1384 gfc_free_expr (open->decimal);
1385 gfc_free_expr (open->encoding);
1386 gfc_free_expr (open->round);
1387 gfc_free_expr (open->sign);
1388 gfc_free_expr (open->convert);
1389 gfc_free_expr (open->asynchronous);
1394 /* Resolve everything in a gfc_open structure. */
1397 gfc_resolve_open (gfc_open *open)
1400 RESOLVE_TAG (&tag_unit, open->unit);
1401 RESOLVE_TAG (&tag_iomsg, open->iomsg);
1402 RESOLVE_TAG (&tag_iostat, open->iostat);
1403 RESOLVE_TAG (&tag_file, open->file);
1404 RESOLVE_TAG (&tag_status, open->status);
1405 RESOLVE_TAG (&tag_e_access, open->access);
1406 RESOLVE_TAG (&tag_e_form, open->form);
1407 RESOLVE_TAG (&tag_e_recl, open->recl);
1408 RESOLVE_TAG (&tag_e_blank, open->blank);
1409 RESOLVE_TAG (&tag_e_position, open->position);
1410 RESOLVE_TAG (&tag_e_action, open->action);
1411 RESOLVE_TAG (&tag_e_delim, open->delim);
1412 RESOLVE_TAG (&tag_e_pad, open->pad);
1413 RESOLVE_TAG (&tag_e_decimal, open->decimal);
1414 RESOLVE_TAG (&tag_e_encoding, open->encoding);
1415 RESOLVE_TAG (&tag_e_async, open->asynchronous);
1416 RESOLVE_TAG (&tag_e_round, open->round);
1417 RESOLVE_TAG (&tag_e_sign, open->sign);
1418 RESOLVE_TAG (&tag_convert, open->convert);
1420 if (gfc_reference_st_label (open->err, ST_LABEL_TARGET) == FAILURE)
1427 /* Check if a given value for a SPECIFIER is either in the list of values
1428 allowed in F95 or F2003, issuing an error message and returning a zero
1429 value if it is not allowed. */
1432 compare_to_allowed_values (const char *specifier, const char *allowed[],
1433 const char *allowed_f2003[],
1434 const char *allowed_gnu[], gfc_char_t *value,
1435 const char *statement, bool warn)
1440 len = gfc_wide_strlen (value);
1443 for (len--; len > 0; len--)
1444 if (value[len] != ' ')
1449 for (i = 0; allowed[i]; i++)
1450 if (len == strlen (allowed[i])
1451 && gfc_wide_strncasecmp (value, allowed[i], strlen (allowed[i])) == 0)
1454 for (i = 0; allowed_f2003 && allowed_f2003[i]; i++)
1455 if (len == strlen (allowed_f2003[i])
1456 && gfc_wide_strncasecmp (value, allowed_f2003[i],
1457 strlen (allowed_f2003[i])) == 0)
1459 notification n = gfc_notification_std (GFC_STD_F2003);
1461 if (n == WARNING || (warn && n == ERROR))
1463 gfc_warning ("Fortran 2003: %s specifier in %s statement at %C "
1464 "has value '%s'", specifier, statement,
1471 gfc_notify_std (GFC_STD_F2003, "Fortran 2003: %s specifier in "
1472 "%s statement at %C has value '%s'", specifier,
1473 statement, allowed_f2003[i]);
1481 for (i = 0; allowed_gnu && allowed_gnu[i]; i++)
1482 if (len == strlen (allowed_gnu[i])
1483 && gfc_wide_strncasecmp (value, allowed_gnu[i],
1484 strlen (allowed_gnu[i])) == 0)
1486 notification n = gfc_notification_std (GFC_STD_GNU);
1488 if (n == WARNING || (warn && n == ERROR))
1490 gfc_warning ("Extension: %s specifier in %s statement at %C "
1491 "has value '%s'", specifier, statement,
1498 gfc_notify_std (GFC_STD_GNU, "Extension: %s specifier in "
1499 "%s statement at %C has value '%s'", specifier,
1500 statement, allowed_gnu[i]);
1510 char *s = gfc_widechar_to_char (value, -1);
1511 gfc_warning ("%s specifier in %s statement at %C has invalid value '%s'",
1512 specifier, statement, s);
1518 char *s = gfc_widechar_to_char (value, -1);
1519 gfc_error ("%s specifier in %s statement at %C has invalid value '%s'",
1520 specifier, statement, s);
1527 /* Match an OPEN statement. */
1530 gfc_match_open (void)
1536 m = gfc_match_char ('(');
1540 open = XCNEW (gfc_open);
1542 m = match_open_element (open);
1544 if (m == MATCH_ERROR)
1548 m = gfc_match_expr (&open->unit);
1551 if (m == MATCH_ERROR)
1557 if (gfc_match_char (')') == MATCH_YES)
1559 if (gfc_match_char (',') != MATCH_YES)
1562 m = match_open_element (open);
1563 if (m == MATCH_ERROR)
1569 if (gfc_match_eos () == MATCH_NO)
1572 if (gfc_pure (NULL))
1574 gfc_error ("OPEN statement not allowed in PURE procedure at %C");
1578 warn = (open->err || open->iostat) ? true : false;
1579 /* Checks on the ACCESS specifier. */
1580 if (open->access && open->access->expr_type == EXPR_CONSTANT)
1582 static const char *access_f95[] = { "SEQUENTIAL", "DIRECT", NULL };
1583 static const char *access_f2003[] = { "STREAM", NULL };
1584 static const char *access_gnu[] = { "APPEND", NULL };
1586 if (!compare_to_allowed_values ("ACCESS", access_f95, access_f2003,
1588 open->access->value.character.string,
1593 /* Checks on the ACTION specifier. */
1594 if (open->action && open->action->expr_type == EXPR_CONSTANT)
1596 static const char *action[] = { "READ", "WRITE", "READWRITE", NULL };
1598 if (!compare_to_allowed_values ("ACTION", action, NULL, NULL,
1599 open->action->value.character.string,
1604 /* Checks on the ASYNCHRONOUS specifier. */
1605 if (open->asynchronous)
1607 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ASYNCHRONOUS= at %C "
1608 "not allowed in Fortran 95") == FAILURE)
1611 if (open->asynchronous->expr_type == EXPR_CONSTANT)
1613 static const char * asynchronous[] = { "YES", "NO", NULL };
1615 if (!compare_to_allowed_values ("ASYNCHRONOUS", asynchronous,
1616 NULL, NULL, open->asynchronous->value.character.string,
1622 /* Checks on the BLANK specifier. */
1625 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: BLANK= at %C "
1626 "not allowed in Fortran 95") == FAILURE)
1629 if (open->blank->expr_type == EXPR_CONSTANT)
1631 static const char *blank[] = { "ZERO", "NULL", NULL };
1633 if (!compare_to_allowed_values ("BLANK", blank, NULL, NULL,
1634 open->blank->value.character.string,
1640 /* Checks on the DECIMAL specifier. */
1643 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DECIMAL= at %C "
1644 "not allowed in Fortran 95") == FAILURE)
1647 if (open->decimal->expr_type == EXPR_CONSTANT)
1649 static const char * decimal[] = { "COMMA", "POINT", NULL };
1651 if (!compare_to_allowed_values ("DECIMAL", decimal, NULL, NULL,
1652 open->decimal->value.character.string,
1658 /* Checks on the DELIM specifier. */
1661 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DELIM= at %C "
1662 "not allowed in Fortran 95") == FAILURE)
1665 if (open->delim->expr_type == EXPR_CONSTANT)
1667 static const char *delim[] = { "APOSTROPHE", "QUOTE", "NONE", NULL };
1669 if (!compare_to_allowed_values ("DELIM", delim, NULL, NULL,
1670 open->delim->value.character.string,
1676 /* Checks on the ENCODING specifier. */
1679 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ENCODING= at %C "
1680 "not allowed in Fortran 95") == FAILURE)
1683 if (open->encoding->expr_type == EXPR_CONSTANT)
1685 /* TODO: Implement UTF-8 here. */
1686 static const char * encoding[] = { "DEFAULT", NULL };
1688 if (!compare_to_allowed_values ("ENCODING", encoding, NULL, NULL,
1689 open->encoding->value.character.string,
1695 /* Checks on the FORM specifier. */
1696 if (open->form && open->form->expr_type == EXPR_CONSTANT)
1698 static const char *form[] = { "FORMATTED", "UNFORMATTED", NULL };
1700 if (!compare_to_allowed_values ("FORM", form, NULL, NULL,
1701 open->form->value.character.string,
1706 /* Checks on the PAD specifier. */
1707 if (open->pad && open->pad->expr_type == EXPR_CONSTANT)
1709 static const char *pad[] = { "YES", "NO", NULL };
1711 if (!compare_to_allowed_values ("PAD", pad, NULL, NULL,
1712 open->pad->value.character.string,
1717 /* Checks on the POSITION specifier. */
1718 if (open->position && open->position->expr_type == EXPR_CONSTANT)
1720 static const char *position[] = { "ASIS", "REWIND", "APPEND", NULL };
1722 if (!compare_to_allowed_values ("POSITION", position, NULL, NULL,
1723 open->position->value.character.string,
1728 /* Checks on the ROUND specifier. */
1731 /* When implemented, change the following to use gfc_notify_std F2003. */
1732 gfc_error ("Fortran F2003: ROUND= specifier at %C not implemented");
1735 if (open->round->expr_type == EXPR_CONSTANT)
1737 static const char * round[] = { "UP", "DOWN", "ZERO", "NEAREST",
1738 "COMPATIBLE", "PROCESSOR_DEFINED",
1741 if (!compare_to_allowed_values ("ROUND", round, NULL, NULL,
1742 open->round->value.character.string,
1748 /* Checks on the SIGN specifier. */
1751 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: SIGN= at %C "
1752 "not allowed in Fortran 95") == FAILURE)
1755 if (open->sign->expr_type == EXPR_CONSTANT)
1757 static const char * sign[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
1760 if (!compare_to_allowed_values ("SIGN", sign, NULL, NULL,
1761 open->sign->value.character.string,
1767 #define warn_or_error(...) \
1770 gfc_warning (__VA_ARGS__); \
1773 gfc_error (__VA_ARGS__); \
1778 /* Checks on the RECL specifier. */
1779 if (open->recl && open->recl->expr_type == EXPR_CONSTANT
1780 && open->recl->ts.type == BT_INTEGER
1781 && mpz_sgn (open->recl->value.integer) != 1)
1783 warn_or_error ("RECL in OPEN statement at %C must be positive");
1786 /* Checks on the STATUS specifier. */
1787 if (open->status && open->status->expr_type == EXPR_CONSTANT)
1789 static const char *status[] = { "OLD", "NEW", "SCRATCH",
1790 "REPLACE", "UNKNOWN", NULL };
1792 if (!compare_to_allowed_values ("STATUS", status, NULL, NULL,
1793 open->status->value.character.string,
1797 /* F2003, 9.4.5: If the STATUS= specifier has the value NEW or REPLACE,
1798 the FILE= specifier shall appear. */
1799 if (open->file == NULL
1800 && (gfc_wide_strncasecmp (open->status->value.character.string,
1802 || gfc_wide_strncasecmp (open->status->value.character.string,
1805 char *s = gfc_widechar_to_char (open->status->value.character.string,
1807 warn_or_error ("The STATUS specified in OPEN statement at %C is "
1808 "'%s' and no FILE specifier is present", s);
1812 /* F2003, 9.4.5: If the STATUS= specifier has the value SCRATCH,
1813 the FILE= specifier shall not appear. */
1814 if (gfc_wide_strncasecmp (open->status->value.character.string,
1815 "scratch", 7) == 0 && open->file)
1817 warn_or_error ("The STATUS specified in OPEN statement at %C "
1818 "cannot have the value SCRATCH if a FILE specifier "
1823 /* Things that are not allowed for unformatted I/O. */
1824 if (open->form && open->form->expr_type == EXPR_CONSTANT
1825 && (open->delim || open->decimal || open->encoding || open->round
1826 || open->sign || open->pad || open->blank)
1827 && gfc_wide_strncasecmp (open->form->value.character.string,
1828 "unformatted", 11) == 0)
1830 const char *spec = (open->delim ? "DELIM "
1831 : (open->pad ? "PAD " : open->blank
1834 warn_or_error ("%s specifier at %C not allowed in OPEN statement for "
1835 "unformatted I/O", spec);
1838 if (open->recl && open->access && open->access->expr_type == EXPR_CONSTANT
1839 && gfc_wide_strncasecmp (open->access->value.character.string,
1842 warn_or_error ("RECL specifier not allowed in OPEN statement at %C for "
1847 && open->access && open->access->expr_type == EXPR_CONSTANT
1848 && !(gfc_wide_strncasecmp (open->access->value.character.string,
1849 "sequential", 10) == 0
1850 || gfc_wide_strncasecmp (open->access->value.character.string,
1852 || gfc_wide_strncasecmp (open->access->value.character.string,
1855 warn_or_error ("POSITION specifier in OPEN statement at %C only allowed "
1856 "for stream or sequential ACCESS");
1859 #undef warn_or_error
1861 new_st.op = EXEC_OPEN;
1862 new_st.ext.open = open;
1866 gfc_syntax_error (ST_OPEN);
1869 gfc_free_open (open);
1874 /* Free a gfc_close structure an all its expressions. */
1877 gfc_free_close (gfc_close *close)
1882 gfc_free_expr (close->unit);
1883 gfc_free_expr (close->iomsg);
1884 gfc_free_expr (close->iostat);
1885 gfc_free_expr (close->status);
1890 /* Match elements of a CLOSE statement. */
1893 match_close_element (gfc_close *close)
1897 m = match_etag (&tag_unit, &close->unit);
1900 m = match_etag (&tag_status, &close->status);
1903 m = match_out_tag (&tag_iomsg, &close->iomsg);
1906 m = match_out_tag (&tag_iostat, &close->iostat);
1909 m = match_ltag (&tag_err, &close->err);
1917 /* Match a CLOSE statement. */
1920 gfc_match_close (void)
1926 m = gfc_match_char ('(');
1930 close = XCNEW (gfc_close);
1932 m = match_close_element (close);
1934 if (m == MATCH_ERROR)
1938 m = gfc_match_expr (&close->unit);
1941 if (m == MATCH_ERROR)
1947 if (gfc_match_char (')') == MATCH_YES)
1949 if (gfc_match_char (',') != MATCH_YES)
1952 m = match_close_element (close);
1953 if (m == MATCH_ERROR)
1959 if (gfc_match_eos () == MATCH_NO)
1962 if (gfc_pure (NULL))
1964 gfc_error ("CLOSE statement not allowed in PURE procedure at %C");
1968 warn = (close->iostat || close->err) ? true : false;
1970 /* Checks on the STATUS specifier. */
1971 if (close->status && close->status->expr_type == EXPR_CONSTANT)
1973 static const char *status[] = { "KEEP", "DELETE", NULL };
1975 if (!compare_to_allowed_values ("STATUS", status, NULL, NULL,
1976 close->status->value.character.string,
1981 new_st.op = EXEC_CLOSE;
1982 new_st.ext.close = close;
1986 gfc_syntax_error (ST_CLOSE);
1989 gfc_free_close (close);
1994 /* Resolve everything in a gfc_close structure. */
1997 gfc_resolve_close (gfc_close *close)
1999 RESOLVE_TAG (&tag_unit, close->unit);
2000 RESOLVE_TAG (&tag_iomsg, close->iomsg);
2001 RESOLVE_TAG (&tag_iostat, close->iostat);
2002 RESOLVE_TAG (&tag_status, close->status);
2004 if (gfc_reference_st_label (close->err, ST_LABEL_TARGET) == FAILURE)
2011 /* Free a gfc_filepos structure. */
2014 gfc_free_filepos (gfc_filepos *fp)
2016 gfc_free_expr (fp->unit);
2017 gfc_free_expr (fp->iomsg);
2018 gfc_free_expr (fp->iostat);
2023 /* Match elements of a REWIND, BACKSPACE, ENDFILE, or FLUSH statement. */
2026 match_file_element (gfc_filepos *fp)
2030 m = match_etag (&tag_unit, &fp->unit);
2033 m = match_out_tag (&tag_iomsg, &fp->iomsg);
2036 m = match_out_tag (&tag_iostat, &fp->iostat);
2039 m = match_ltag (&tag_err, &fp->err);
2047 /* Match the second half of the file-positioning statements, REWIND,
2048 BACKSPACE, ENDFILE, or the FLUSH statement. */
2051 match_filepos (gfc_statement st, gfc_exec_op op)
2056 fp = XCNEW (gfc_filepos);
2058 if (gfc_match_char ('(') == MATCH_NO)
2060 m = gfc_match_expr (&fp->unit);
2061 if (m == MATCH_ERROR)
2069 m = match_file_element (fp);
2070 if (m == MATCH_ERROR)
2074 m = gfc_match_expr (&fp->unit);
2075 if (m == MATCH_ERROR)
2083 if (gfc_match_char (')') == MATCH_YES)
2085 if (gfc_match_char (',') != MATCH_YES)
2088 m = match_file_element (fp);
2089 if (m == MATCH_ERROR)
2096 if (gfc_match_eos () != MATCH_YES)
2099 if (gfc_pure (NULL))
2101 gfc_error ("%s statement not allowed in PURE procedure at %C",
2102 gfc_ascii_statement (st));
2108 new_st.ext.filepos = fp;
2112 gfc_syntax_error (st);
2115 gfc_free_filepos (fp);
2121 gfc_resolve_filepos (gfc_filepos *fp)
2123 RESOLVE_TAG (&tag_unit, fp->unit);
2124 RESOLVE_TAG (&tag_iostat, fp->iostat);
2125 RESOLVE_TAG (&tag_iomsg, fp->iomsg);
2126 if (gfc_reference_st_label (fp->err, ST_LABEL_TARGET) == FAILURE)
2133 /* Match the file positioning statements: ENDFILE, BACKSPACE, REWIND,
2134 and the FLUSH statement. */
2137 gfc_match_endfile (void)
2139 return match_filepos (ST_END_FILE, EXEC_ENDFILE);
2143 gfc_match_backspace (void)
2145 return match_filepos (ST_BACKSPACE, EXEC_BACKSPACE);
2149 gfc_match_rewind (void)
2151 return match_filepos (ST_REWIND, EXEC_REWIND);
2155 gfc_match_flush (void)
2157 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: FLUSH statement at %C")
2161 return match_filepos (ST_FLUSH, EXEC_FLUSH);
2164 /******************** Data Transfer Statements *********************/
2166 /* Return a default unit number. */
2169 default_unit (io_kind k)
2178 return gfc_int_expr (unit);
2182 /* Match a unit specification for a data transfer statement. */
2185 match_dt_unit (io_kind k, gfc_dt *dt)
2189 if (gfc_match_char ('*') == MATCH_YES)
2191 if (dt->io_unit != NULL)
2194 dt->io_unit = default_unit (k);
2198 if (gfc_match_expr (&e) == MATCH_YES)
2200 if (dt->io_unit != NULL)
2213 gfc_error ("Duplicate UNIT specification at %C");
2218 /* Match a format specification. */
2221 match_dt_format (gfc_dt *dt)
2225 gfc_st_label *label;
2228 where = gfc_current_locus;
2230 if (gfc_match_char ('*') == MATCH_YES)
2232 if (dt->format_expr != NULL || dt->format_label != NULL)
2235 dt->format_label = &format_asterisk;
2239 if ((m = gfc_match_st_label (&label)) == MATCH_YES)
2241 if (dt->format_expr != NULL || dt->format_label != NULL)
2243 gfc_free_st_label (label);
2247 if (gfc_reference_st_label (label, ST_LABEL_FORMAT) == FAILURE)
2250 dt->format_label = label;
2253 else if (m == MATCH_ERROR)
2254 /* The label was zero or too large. Emit the correct diagnosis. */
2257 if (gfc_match_expr (&e) == MATCH_YES)
2259 if (dt->format_expr != NULL || dt->format_label != NULL)
2264 dt->format_expr = e;
2268 gfc_current_locus = where; /* The only case where we have to restore */
2273 gfc_error ("Duplicate format specification at %C");
2278 /* Traverse a namelist that is part of a READ statement to make sure
2279 that none of the variables in the namelist are INTENT(IN). Returns
2280 nonzero if we find such a variable. */
2283 check_namelist (gfc_symbol *sym)
2287 for (p = sym->namelist; p; p = p->next)
2288 if (p->sym->attr.intent == INTENT_IN)
2290 gfc_error ("Symbol '%s' in namelist '%s' is INTENT(IN) at %C",
2291 p->sym->name, sym->name);
2299 /* Match a single data transfer element. */
2302 match_dt_element (io_kind k, gfc_dt *dt)
2304 char name[GFC_MAX_SYMBOL_LEN + 1];
2308 if (gfc_match (" unit =") == MATCH_YES)
2310 m = match_dt_unit (k, dt);
2315 if (gfc_match (" fmt =") == MATCH_YES)
2317 m = match_dt_format (dt);
2322 if (gfc_match (" nml = %n", name) == MATCH_YES)
2324 if (dt->namelist != NULL)
2326 gfc_error ("Duplicate NML specification at %C");
2330 if (gfc_find_symbol (name, NULL, 1, &sym))
2333 if (sym == NULL || sym->attr.flavor != FL_NAMELIST)
2335 gfc_error ("Symbol '%s' at %C must be a NAMELIST group name",
2336 sym != NULL ? sym->name : name);
2341 if (k == M_READ && check_namelist (sym))
2347 m = match_etag (&tag_e_async, &dt->asynchronous);
2350 m = match_etag (&tag_e_blank, &dt->blank);
2353 m = match_etag (&tag_e_delim, &dt->delim);
2356 m = match_etag (&tag_e_pad, &dt->pad);
2359 m = match_etag (&tag_e_sign, &dt->sign);
2362 m = match_etag (&tag_e_round, &dt->round);
2365 m = match_out_tag (&tag_id, &dt->id);
2368 m = match_etag (&tag_e_decimal, &dt->decimal);
2371 m = match_etag (&tag_rec, &dt->rec);
2374 m = match_etag (&tag_spos, &dt->rec);
2377 m = match_out_tag (&tag_iomsg, &dt->iomsg);
2380 m = match_out_tag (&tag_iostat, &dt->iostat);
2383 m = match_ltag (&tag_err, &dt->err);
2385 dt->err_where = gfc_current_locus;
2388 m = match_etag (&tag_advance, &dt->advance);
2391 m = match_out_tag (&tag_size, &dt->size);
2395 m = match_ltag (&tag_end, &dt->end);
2400 gfc_error ("END tag at %C not allowed in output statement");
2403 dt->end_where = gfc_current_locus;
2408 m = match_ltag (&tag_eor, &dt->eor);
2410 dt->eor_where = gfc_current_locus;
2418 /* Free a data transfer structure and everything below it. */
2421 gfc_free_dt (gfc_dt *dt)
2426 gfc_free_expr (dt->io_unit);
2427 gfc_free_expr (dt->format_expr);
2428 gfc_free_expr (dt->rec);
2429 gfc_free_expr (dt->advance);
2430 gfc_free_expr (dt->iomsg);
2431 gfc_free_expr (dt->iostat);
2432 gfc_free_expr (dt->size);
2433 gfc_free_expr (dt->pad);
2434 gfc_free_expr (dt->delim);
2435 gfc_free_expr (dt->sign);
2436 gfc_free_expr (dt->round);
2437 gfc_free_expr (dt->blank);
2438 gfc_free_expr (dt->decimal);
2439 gfc_free_expr (dt->extra_comma);
2444 /* Resolve everything in a gfc_dt structure. */
2447 gfc_resolve_dt (gfc_dt *dt)
2451 RESOLVE_TAG (&tag_format, dt->format_expr);
2452 RESOLVE_TAG (&tag_rec, dt->rec);
2453 RESOLVE_TAG (&tag_spos, dt->rec);
2454 RESOLVE_TAG (&tag_advance, dt->advance);
2455 RESOLVE_TAG (&tag_iomsg, dt->iomsg);
2456 RESOLVE_TAG (&tag_iostat, dt->iostat);
2457 RESOLVE_TAG (&tag_size, dt->size);
2458 RESOLVE_TAG (&tag_e_pad, dt->pad);
2459 RESOLVE_TAG (&tag_e_delim, dt->delim);
2460 RESOLVE_TAG (&tag_e_sign, dt->sign);
2461 RESOLVE_TAG (&tag_e_round, dt->round);
2462 RESOLVE_TAG (&tag_e_blank, dt->blank);
2463 RESOLVE_TAG (&tag_e_decimal, dt->decimal);
2466 if (gfc_resolve_expr (e) == SUCCESS
2467 && (e->ts.type != BT_INTEGER
2468 && (e->ts.type != BT_CHARACTER || e->expr_type != EXPR_VARIABLE)))
2470 /* If there is no extra comma signifying the "format" form of the IO
2471 statement, then this must be an error. */
2472 if (!dt->extra_comma)
2474 gfc_error ("UNIT specification at %L must be an INTEGER expression "
2475 "or a CHARACTER variable", &e->where);
2480 /* At this point, we have an extra comma. If io_unit has arrived as
2481 type chracter, we assume its really the "format" form of the I/O
2482 statement. We set the io_unit to the default unit and format to
2483 the chracter expression. See F95 Standard section 9.4. */
2485 k = dt->extra_comma->value.iokind;
2486 if (e->ts.type == BT_CHARACTER && (k == M_READ || k == M_PRINT))
2488 dt->format_expr = dt->io_unit;
2489 dt->io_unit = default_unit (k);
2491 /* Free this pointer now so that a warning/error is not triggered
2492 below for the "Extension". */
2493 gfc_free_expr (dt->extra_comma);
2494 dt->extra_comma = NULL;
2499 gfc_error ("Invalid form of WRITE statement at %L, UNIT required",
2500 &dt->extra_comma->where);
2506 if (e->ts.type == BT_CHARACTER)
2508 if (gfc_has_vector_index (e))
2510 gfc_error ("Internal unit with vector subscript at %L", &e->where);
2515 if (e->rank && e->ts.type != BT_CHARACTER)
2517 gfc_error ("External IO UNIT cannot be an array at %L", &e->where);
2522 && gfc_notify_std (GFC_STD_GNU, "Extension: Comma before i/o "
2523 "item list at %L", &dt->extra_comma->where) == FAILURE)
2528 if (gfc_reference_st_label (dt->err, ST_LABEL_TARGET) == FAILURE)
2530 if (dt->err->defined == ST_LABEL_UNKNOWN)
2532 gfc_error ("ERR tag label %d at %L not defined",
2533 dt->err->value, &dt->err_where);
2540 if (gfc_reference_st_label (dt->end, ST_LABEL_TARGET) == FAILURE)
2542 if (dt->end->defined == ST_LABEL_UNKNOWN)
2544 gfc_error ("END tag label %d at %L not defined",
2545 dt->end->value, &dt->end_where);
2552 if (gfc_reference_st_label (dt->eor, ST_LABEL_TARGET) == FAILURE)
2554 if (dt->eor->defined == ST_LABEL_UNKNOWN)
2556 gfc_error ("EOR tag label %d at %L not defined",
2557 dt->eor->value, &dt->eor_where);
2562 /* Check the format label actually exists. */
2563 if (dt->format_label && dt->format_label != &format_asterisk
2564 && dt->format_label->defined == ST_LABEL_UNKNOWN)
2566 gfc_error ("FORMAT label %d at %L not defined", dt->format_label->value,
2567 &dt->format_label->where);
2574 /* Given an io_kind, return its name. */
2577 io_kind_name (io_kind k)
2596 gfc_internal_error ("io_kind_name(): bad I/O-kind");
2603 /* Match an IO iteration statement of the form:
2605 ( [<IO element> ,] <IO element>, I = <expr>, <expr> [, <expr> ] )
2607 which is equivalent to a single IO element. This function is
2608 mutually recursive with match_io_element(). */
2610 static match match_io_element (io_kind, gfc_code **);
2613 match_io_iterator (io_kind k, gfc_code **result)
2615 gfc_code *head, *tail, *new;
2623 old_loc = gfc_current_locus;
2625 if (gfc_match_char ('(') != MATCH_YES)
2628 m = match_io_element (k, &head);
2631 if (m != MATCH_YES || gfc_match_char (',') != MATCH_YES)
2637 /* Can't be anything but an IO iterator. Build a list. */
2638 iter = gfc_get_iterator ();
2642 m = gfc_match_iterator (iter, 0);
2643 if (m == MATCH_ERROR)
2647 gfc_check_do_variable (iter->var->symtree);
2651 m = match_io_element (k, &new);
2652 if (m == MATCH_ERROR)
2661 tail = gfc_append_code (tail, new);
2663 if (gfc_match_char (',') != MATCH_YES)
2672 if (gfc_match_char (')') != MATCH_YES)
2675 new = gfc_get_code ();
2677 new->ext.iterator = iter;
2679 new->block = gfc_get_code ();
2680 new->block->op = EXEC_DO;
2681 new->block->next = head;
2687 gfc_error ("Syntax error in I/O iterator at %C");
2691 gfc_free_iterator (iter, 1);
2692 gfc_free_statements (head);
2693 gfc_current_locus = old_loc;
2698 /* Match a single element of an IO list, which is either a single
2699 expression or an IO Iterator. */
2702 match_io_element (io_kind k, gfc_code **cpp)
2710 m = match_io_iterator (k, cpp);
2716 m = gfc_match_variable (&expr, 0);
2718 gfc_error ("Expected variable in READ statement at %C");
2722 m = gfc_match_expr (&expr);
2724 gfc_error ("Expected expression in %s statement at %C",
2732 if (expr->symtree->n.sym->attr.intent == INTENT_IN)
2734 gfc_error ("Variable '%s' in input list at %C cannot be "
2735 "INTENT(IN)", expr->symtree->n.sym->name);
2740 && gfc_impure_variable (expr->symtree->n.sym)
2741 && current_dt->io_unit->ts.type == BT_CHARACTER)
2743 gfc_error ("Cannot read to variable '%s' in PURE procedure at %C",
2744 expr->symtree->n.sym->name);
2748 if (gfc_check_do_variable (expr->symtree))
2754 if (current_dt->io_unit->ts.type == BT_CHARACTER
2756 && current_dt->io_unit->expr_type == EXPR_VARIABLE
2757 && gfc_impure_variable (current_dt->io_unit->symtree->n.sym))
2759 gfc_error ("Cannot write to internal file unit '%s' at %C "
2760 "inside a PURE procedure",
2761 current_dt->io_unit->symtree->n.sym->name);
2773 gfc_free_expr (expr);
2777 cp = gfc_get_code ();
2778 cp->op = EXEC_TRANSFER;
2786 /* Match an I/O list, building gfc_code structures as we go. */
2789 match_io_list (io_kind k, gfc_code **head_p)
2791 gfc_code *head, *tail, *new;
2794 *head_p = head = tail = NULL;
2795 if (gfc_match_eos () == MATCH_YES)
2800 m = match_io_element (k, &new);
2801 if (m == MATCH_ERROR)
2806 tail = gfc_append_code (tail, new);
2810 if (gfc_match_eos () == MATCH_YES)
2812 if (gfc_match_char (',') != MATCH_YES)
2820 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
2823 gfc_free_statements (head);
2828 /* Attach the data transfer end node. */
2831 terminate_io (gfc_code *io_code)
2835 if (io_code == NULL)
2836 io_code = new_st.block;
2838 c = gfc_get_code ();
2839 c->op = EXEC_DT_END;
2841 /* Point to structure that is already there */
2842 c->ext.dt = new_st.ext.dt;
2843 gfc_append_code (io_code, c);
2847 /* Check the constraints for a data transfer statement. The majority of the
2848 constraints appearing in 9.4 of the standard appear here. Some are handled
2849 in resolve_tag and others in gfc_resolve_dt. */
2852 check_io_constraints (io_kind k, gfc_dt *dt, gfc_code *io_code,
2855 #define io_constraint(condition,msg,arg)\
2858 gfc_error(msg,arg);\
2864 gfc_symbol *sym = NULL;
2865 bool warn, unformatted;
2867 warn = (dt->err || dt->iostat) ? true : false;
2868 unformatted = dt->format_expr == NULL && dt->format_label == NULL
2869 && dt->namelist == NULL;
2874 if (expr && expr->expr_type == EXPR_VARIABLE
2875 && expr->ts.type == BT_CHARACTER)
2877 sym = expr->symtree->n.sym;
2879 io_constraint (k == M_WRITE && sym->attr.intent == INTENT_IN,
2880 "Internal file at %L must not be INTENT(IN)",
2883 io_constraint (gfc_has_vector_index (dt->io_unit),
2884 "Internal file incompatible with vector subscript at %L",
2887 io_constraint (dt->rec != NULL,
2888 "REC tag at %L is incompatible with internal file",
2891 io_constraint (unformatted,
2892 "Unformatted I/O not allowed with internal unit at %L",
2893 &dt->io_unit->where);
2895 io_constraint (dt->asynchronous != NULL,
2896 "ASYNCHRONOUS tag at %L not allowed with internal file",
2897 &dt->asynchronous->where);
2899 if (dt->namelist != NULL)
2901 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Internal file "
2902 "at %L with namelist", &expr->where)
2907 io_constraint (dt->advance != NULL,
2908 "ADVANCE tag at %L is incompatible with internal file",
2909 &dt->advance->where);
2912 if (expr && expr->ts.type != BT_CHARACTER)
2915 io_constraint (gfc_pure (NULL) && (k == M_READ || k == M_WRITE),
2916 "IO UNIT in %s statement at %C must be "
2917 "an internal file in a PURE procedure",
2923 io_constraint (dt->end, "END tag not allowed with output at %L",
2926 io_constraint (dt->eor, "EOR tag not allowed with output at %L",
2929 io_constraint (dt->blank, "BLANK= specifier not allowed with output at %L",
2932 io_constraint (dt->pad, "PAD= specifier not allowed with output at %L",
2935 io_constraint (dt->size, "SIZE= specifier not allowed with output at %L",
2940 io_constraint (dt->size && dt->advance == NULL,
2941 "SIZE tag at %L requires an ADVANCE tag",
2944 io_constraint (dt->eor && dt->advance == NULL,
2945 "EOR tag at %L requires an ADVANCE tag",
2949 if (dt->asynchronous)
2951 static const char * asynchronous[] = { "YES", "NO", NULL };
2953 if (dt->asynchronous->expr_type != EXPR_CONSTANT)
2955 gfc_error ("ASYNCHRONOUS= specifier at %L must be an initialization "
2956 "expression", &dt->asynchronous->where);
2960 if (!compare_to_allowed_values
2961 ("ASYNCHRONOUS", asynchronous, NULL, NULL,
2962 dt->asynchronous->value.character.string,
2963 io_kind_name (k), warn))
2971 || gfc_wide_strlen (dt->asynchronous->value.character.string) != 3
2972 || gfc_wide_strncasecmp (dt->asynchronous->value.character.string,
2974 io_constraint (not_yes,
2975 "ID= specifier at %L must be with ASYNCHRONOUS='yes' "
2976 "specifier", &dt->id->where);
2981 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DECIMAL= at %C "
2982 "not allowed in Fortran 95") == FAILURE)
2985 if (dt->decimal->expr_type == EXPR_CONSTANT)
2987 static const char * decimal[] = { "COMMA", "POINT", NULL };
2989 if (!compare_to_allowed_values ("DECIMAL", decimal, NULL, NULL,
2990 dt->decimal->value.character.string,
2991 io_kind_name (k), warn))
2994 io_constraint (unformatted,
2995 "the DECIMAL= specifier at %L must be with an "
2996 "explicit format expression", &dt->decimal->where);
3002 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: BLANK= at %C "
3003 "not allowed in Fortran 95") == FAILURE)
3006 if (dt->blank->expr_type == EXPR_CONSTANT)
3008 static const char * blank[] = { "NULL", "ZERO", NULL };
3010 if (!compare_to_allowed_values ("BLANK", blank, NULL, NULL,
3011 dt->blank->value.character.string,
3012 io_kind_name (k), warn))
3015 io_constraint (unformatted,
3016 "the BLANK= specifier at %L must be with an "
3017 "explicit format expression", &dt->blank->where);
3023 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: PAD= at %C "
3024 "not allowed in Fortran 95") == FAILURE)
3027 if (dt->pad->expr_type == EXPR_CONSTANT)
3029 static const char * pad[] = { "YES", "NO", NULL };
3031 if (!compare_to_allowed_values ("PAD", pad, NULL, NULL,
3032 dt->pad->value.character.string,
3033 io_kind_name (k), warn))
3036 io_constraint (unformatted,
3037 "the PAD= specifier at %L must be with an "
3038 "explicit format expression", &dt->pad->where);
3044 /* When implemented, change the following to use gfc_notify_std F2003.
3045 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ROUND= at %C "
3046 "not allowed in Fortran 95") == FAILURE)
3047 return MATCH_ERROR; */
3048 gfc_error ("F2003 Feature: ROUND= specifier at %C not implemented");
3051 if (dt->round->expr_type == EXPR_CONSTANT)
3053 static const char * round[] = { "UP", "DOWN", "ZERO", "NEAREST",
3054 "COMPATIBLE", "PROCESSOR_DEFINED",
3057 if (!compare_to_allowed_values ("ROUND", round, NULL, NULL,
3058 dt->round->value.character.string,
3059 io_kind_name (k), warn))
3066 /* When implemented, change the following to use gfc_notify_std F2003.
3067 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: SIGN= at %C "
3068 "not allowed in Fortran 95") == FAILURE)
3069 return MATCH_ERROR; */
3070 if (dt->sign->expr_type == EXPR_CONSTANT)
3072 static const char * sign[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
3075 if (!compare_to_allowed_values ("SIGN", sign, NULL, NULL,
3076 dt->sign->value.character.string,
3077 io_kind_name (k), warn))
3080 io_constraint (unformatted,
3081 "SIGN= specifier at %L must be with an "
3082 "explicit format expression", &dt->sign->where);
3084 io_constraint (k == M_READ,
3085 "SIGN= specifier at %L not allowed in a "
3086 "READ statement", &dt->sign->where);
3092 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DELIM= at %C "
3093 "not allowed in Fortran 95") == FAILURE)
3096 if (dt->delim->expr_type == EXPR_CONSTANT)
3098 static const char *delim[] = { "APOSTROPHE", "QUOTE", "NONE", NULL };
3100 if (!compare_to_allowed_values ("DELIM", delim, NULL, NULL,
3101 dt->delim->value.character.string,
3102 io_kind_name (k), warn))
3105 io_constraint (k == M_READ,
3106 "DELIM= specifier at %L not allowed in a "
3107 "READ statement", &dt->delim->where);
3109 io_constraint (dt->format_label != &format_asterisk
3110 && dt->namelist == NULL,
3111 "DELIM= specifier at %L must have FMT=*",
3114 io_constraint (unformatted && dt->namelist == NULL,
3115 "DELIM= specifier at %L must be with FMT=* or "
3116 "NML= specifier ", &dt->delim->where);
3122 io_constraint (io_code && dt->namelist,
3123 "NAMELIST cannot be followed by IO-list at %L",
3126 io_constraint (dt->format_expr,
3127 "IO spec-list cannot contain both NAMELIST group name "
3128 "and format specification at %L.",
3129 &dt->format_expr->where);
3131 io_constraint (dt->format_label,
3132 "IO spec-list cannot contain both NAMELIST group name "
3133 "and format label at %L", spec_end);
3135 io_constraint (dt->rec,
3136 "NAMELIST IO is not allowed with a REC= specifier "
3137 "at %L.", &dt->rec->where);
3139 io_constraint (dt->advance,
3140 "NAMELIST IO is not allowed with a ADVANCE= specifier "
3141 "at %L.", &dt->advance->where);
3146 io_constraint (dt->end,
3147 "An END tag is not allowed with a "
3148 "REC= specifier at %L.", &dt->end_where);
3150 io_constraint (dt->format_label == &format_asterisk,
3151 "FMT=* is not allowed with a REC= specifier "
3152 "at %L.", spec_end);
3157 int not_yes, not_no;
3160 io_constraint (dt->format_label == &format_asterisk,
3161 "List directed format(*) is not allowed with a "
3162 "ADVANCE= specifier at %L.", &expr->where);
3164 io_constraint (unformatted,
3165 "the ADVANCE= specifier at %L must appear with an "
3166 "explicit format expression", &expr->where);
3168 if (expr->expr_type == EXPR_CONSTANT && expr->ts.type == BT_CHARACTER)
3170 const gfc_char_t *advance = expr->value.character.string;
3171 not_no = gfc_wide_strlen (advance) != 2
3172 || gfc_wide_strncasecmp (advance, "no", 2) != 0;
3173 not_yes = gfc_wide_strlen (advance) != 3
3174 || gfc_wide_strncasecmp (advance, "yes", 3) != 0;
3182 io_constraint (not_no && not_yes,
3183 "ADVANCE= specifier at %L must have value = "
3184 "YES or NO.", &expr->where);
3186 io_constraint (dt->size && not_no && k == M_READ,
3187 "SIZE tag at %L requires an ADVANCE = 'NO'",
3190 io_constraint (dt->eor && not_no && k == M_READ,
3191 "EOR tag at %L requires an ADVANCE = 'NO'",
3195 expr = dt->format_expr;
3196 if (gfc_simplify_expr (expr, 0) == FAILURE
3197 || check_format_string (expr, k == M_READ) == FAILURE)
3202 #undef io_constraint
3205 /* Match a READ, WRITE or PRINT statement. */
3208 match_io (io_kind k)
3210 char name[GFC_MAX_SYMBOL_LEN + 1];
3219 where = gfc_current_locus;
3221 current_dt = dt = XCNEW (gfc_dt);
3222 m = gfc_match_char ('(');
3225 where = gfc_current_locus;
3228 else if (k == M_PRINT)
3230 /* Treat the non-standard case of PRINT namelist. */
3231 if ((gfc_current_form == FORM_FIXED || gfc_peek_ascii_char () == ' ')
3232 && gfc_match_name (name) == MATCH_YES)
3234 gfc_find_symbol (name, NULL, 1, &sym);
3235 if (sym && sym->attr.flavor == FL_NAMELIST)
3237 if (gfc_notify_std (GFC_STD_GNU, "PRINT namelist at "
3238 "%C is an extension") == FAILURE)
3244 dt->io_unit = default_unit (k);
3249 gfc_current_locus = where;
3253 if (gfc_current_form == FORM_FREE)
3255 char c = gfc_peek_ascii_char ();
3256 if (c != ' ' && c != '*' && c != '\'' && c != '"')
3263 m = match_dt_format (dt);
3264 if (m == MATCH_ERROR)
3270 dt->io_unit = default_unit (k);
3275 /* Before issuing an error for a malformed 'print (1,*)' type of
3276 error, check for a default-char-expr of the form ('(I0)'). */
3277 if (k == M_PRINT && m == MATCH_YES)
3279 /* Reset current locus to get the initial '(' in an expression. */
3280 gfc_current_locus = where;
3281 dt->format_expr = NULL;
3282 m = match_dt_format (dt);
3284 if (m == MATCH_ERROR)
3286 if (m == MATCH_NO || dt->format_expr == NULL)
3290 dt->io_unit = default_unit (k);
3295 /* Match a control list */
3296 if (match_dt_element (k, dt) == MATCH_YES)
3298 if (match_dt_unit (k, dt) != MATCH_YES)
3301 if (gfc_match_char (')') == MATCH_YES)
3303 if (gfc_match_char (',') != MATCH_YES)
3306 m = match_dt_element (k, dt);
3309 if (m == MATCH_ERROR)
3312 m = match_dt_format (dt);
3315 if (m == MATCH_ERROR)
3318 where = gfc_current_locus;
3320 m = gfc_match_name (name);
3323 gfc_find_symbol (name, NULL, 1, &sym);
3324 if (sym && sym->attr.flavor == FL_NAMELIST)
3327 if (k == M_READ && check_namelist (sym))
3336 gfc_current_locus = where;
3338 goto loop; /* No matches, try regular elements */
3341 if (gfc_match_char (')') == MATCH_YES)
3343 if (gfc_match_char (',') != MATCH_YES)
3349 m = match_dt_element (k, dt);
3352 if (m == MATCH_ERROR)
3355 if (gfc_match_char (')') == MATCH_YES)
3357 if (gfc_match_char (',') != MATCH_YES)
3363 /* Used in check_io_constraints, where no locus is available. */
3364 spec_end = gfc_current_locus;
3366 /* Optional leading comma (non-standard). We use a gfc_expr structure here
3367 to save the locus. This is used later when resolving transfer statements
3368 that might have a format expression without unit number. */
3369 if (!comma_flag && gfc_match_char (',') == MATCH_YES)
3371 dt->extra_comma = gfc_get_expr ();
3373 /* Set the types to something compatible with iokind. This is needed to
3374 get through gfc_free_expr later since iokind really has no Basic Type,
3376 dt->extra_comma->expr_type = EXPR_CONSTANT;
3377 dt->extra_comma->ts.type = BT_LOGICAL;
3379 /* Save the iokind and locus for later use in resolution. */
3380 dt->extra_comma->value.iokind = k;
3381 dt->extra_comma->where = gfc_current_locus;
3385 if (gfc_match_eos () != MATCH_YES)
3387 if (comma_flag && gfc_match_char (',') != MATCH_YES)
3389 gfc_error ("Expected comma in I/O list at %C");
3394 m = match_io_list (k, &io_code);
3395 if (m == MATCH_ERROR)
3401 /* A full IO statement has been matched. Check the constraints. spec_end is
3402 supplied for cases where no locus is supplied. */
3403 m = check_io_constraints (k, dt, io_code, &spec_end);
3405 if (m == MATCH_ERROR)
3408 new_st.op = (k == M_READ) ? EXEC_READ : EXEC_WRITE;
3410 new_st.block = gfc_get_code ();
3411 new_st.block->op = new_st.op;
3412 new_st.block->next = io_code;
3414 terminate_io (io_code);
3419 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
3429 gfc_match_read (void)
3431 return match_io (M_READ);
3436 gfc_match_write (void)
3438 return match_io (M_WRITE);
3443 gfc_match_print (void)
3447 m = match_io (M_PRINT);
3451 if (gfc_pure (NULL))
3453 gfc_error ("PRINT statement at %C not allowed within PURE procedure");
3461 /* Free a gfc_inquire structure. */
3464 gfc_free_inquire (gfc_inquire *inquire)
3467 if (inquire == NULL)
3470 gfc_free_expr (inquire->unit);
3471 gfc_free_expr (inquire->file);
3472 gfc_free_expr (inquire->iomsg);
3473 gfc_free_expr (inquire->iostat);
3474 gfc_free_expr (inquire->exist);
3475 gfc_free_expr (inquire->opened);
3476 gfc_free_expr (inquire->number);
3477 gfc_free_expr (inquire->named);
3478 gfc_free_expr (inquire->name);
3479 gfc_free_expr (inquire->access);
3480 gfc_free_expr (inquire->sequential);
3481 gfc_free_expr (inquire->direct);
3482 gfc_free_expr (inquire->form);
3483 gfc_free_expr (inquire->formatted);
3484 gfc_free_expr (inquire->unformatted);
3485 gfc_free_expr (inquire->recl);
3486 gfc_free_expr (inquire->nextrec);
3487 gfc_free_expr (inquire->blank);
3488 gfc_free_expr (inquire->position);
3489 gfc_free_expr (inquire->action);
3490 gfc_free_expr (inquire->read);
3491 gfc_free_expr (inquire->write);
3492 gfc_free_expr (inquire->readwrite);
3493 gfc_free_expr (inquire->delim);
3494 gfc_free_expr (inquire->encoding);
3495 gfc_free_expr (inquire->pad);
3496 gfc_free_expr (inquire->iolength);
3497 gfc_free_expr (inquire->convert);
3498 gfc_free_expr (inquire->strm_pos);
3499 gfc_free_expr (inquire->asynchronous);
3500 gfc_free_expr (inquire->pending);
3501 gfc_free_expr (inquire->id);
3502 gfc_free_expr (inquire->sign);
3503 gfc_free_expr (inquire->round);
3508 /* Match an element of an INQUIRE statement. */
3510 #define RETM if (m != MATCH_NO) return m;
3513 match_inquire_element (gfc_inquire *inquire)
3517 m = match_etag (&tag_unit, &inquire->unit);
3518 RETM m = match_etag (&tag_file, &inquire->file);
3519 RETM m = match_ltag (&tag_err, &inquire->err);
3520 RETM m = match_out_tag (&tag_iomsg, &inquire->iomsg);
3521 RETM m = match_out_tag (&tag_iostat, &inquire->iostat);
3522 RETM m = match_vtag (&tag_exist, &inquire->exist);
3523 RETM m = match_vtag (&tag_opened, &inquire->opened);
3524 RETM m = match_vtag (&tag_named, &inquire->named);
3525 RETM m = match_vtag (&tag_name, &inquire->name);
3526 RETM m = match_out_tag (&tag_number, &inquire->number);
3527 RETM m = match_vtag (&tag_s_access, &inquire->access);
3528 RETM m = match_vtag (&tag_sequential, &inquire->sequential);
3529 RETM m = match_vtag (&tag_direct, &inquire->direct);
3530 RETM m = match_vtag (&tag_s_form, &inquire->form);
3531 RETM m = match_vtag (&tag_formatted, &inquire->formatted);
3532 RETM m = match_vtag (&tag_unformatted, &inquire->unformatted);
3533 RETM m = match_out_tag (&tag_s_recl, &inquire->recl);
3534 RETM m = match_out_tag (&tag_nextrec, &inquire->nextrec);
3535 RETM m = match_vtag (&tag_s_blank, &inquire->blank);
3536 RETM m = match_vtag (&tag_s_position, &inquire->position);
3537 RETM m = match_vtag (&tag_s_action, &inquire->action);
3538 RETM m = match_vtag (&tag_read, &inquire->read);
3539 RETM m = match_vtag (&tag_write, &inquire->write);
3540 RETM m = match_vtag (&tag_readwrite, &inquire->readwrite);
3541 RETM m = match_vtag (&tag_s_async, &inquire->asynchronous);
3542 RETM m = match_vtag (&tag_s_delim, &inquire->delim);
3543 RETM m = match_vtag (&tag_s_decimal, &inquire->decimal);
3544 RETM m = match_vtag (&tag_s_blank, &inquire->blank);
3545 RETM m = match_vtag (&tag_s_encoding, &inquire->encoding);
3546 RETM m = match_vtag (&tag_s_round, &inquire->round);
3547 RETM m = match_vtag (&tag_s_sign, &inquire->sign);
3548 RETM m = match_vtag (&tag_s_pad, &inquire->pad);
3549 RETM m = match_vtag (&tag_iolength, &inquire->iolength);
3550 RETM m = match_vtag (&tag_convert, &inquire->convert);
3551 RETM m = match_out_tag (&tag_strm_out, &inquire->strm_pos);
3552 RETM m = match_vtag (&tag_pending, &inquire->pending);
3553 RETM m = match_vtag (&tag_id, &inquire->id);
3554 RETM return MATCH_NO;
3561 gfc_match_inquire (void)
3563 gfc_inquire *inquire;
3568 m = gfc_match_char ('(');
3572 inquire = XCNEW (gfc_inquire);
3574 loc = gfc_current_locus;
3576 m = match_inquire_element (inquire);
3577 if (m == MATCH_ERROR)
3581 m = gfc_match_expr (&inquire->unit);
3582 if (m == MATCH_ERROR)
3588 /* See if we have the IOLENGTH form of the inquire statement. */
3589 if (inquire->iolength != NULL)
3591 if (gfc_match_char (')') != MATCH_YES)
3594 m = match_io_list (M_INQUIRE, &code);
3595 if (m == MATCH_ERROR)
3600 new_st.op = EXEC_IOLENGTH;
3601 new_st.expr = inquire->iolength;
3602 new_st.ext.inquire = inquire;
3604 if (gfc_pure (NULL))
3606 gfc_free_statements (code);
3607 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
3611 new_st.block = gfc_get_code ();
3612 new_st.block->op = EXEC_IOLENGTH;
3613 terminate_io (code);
3614 new_st.block->next = code;
3618 /* At this point, we have the non-IOLENGTH inquire statement. */
3621 if (gfc_match_char (')') == MATCH_YES)
3623 if (gfc_match_char (',') != MATCH_YES)
3626 m = match_inquire_element (inquire);
3627 if (m == MATCH_ERROR)
3632 if (inquire->iolength != NULL)
3634 gfc_error ("IOLENGTH tag invalid in INQUIRE statement at %C");
3639 if (gfc_match_eos () != MATCH_YES)
3642 if (inquire->unit != NULL && inquire->file != NULL)
3644 gfc_error ("INQUIRE statement at %L cannot contain both FILE and "
3645 "UNIT specifiers", &loc);
3649 if (inquire->unit == NULL && inquire->file == NULL)
3651 gfc_error ("INQUIRE statement at %L requires either FILE or "
3652 "UNIT specifier", &loc);
3656 if (gfc_pure (NULL))
3658 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
3662 if (inquire->id != NULL && inquire->pending == NULL)
3664 gfc_error ("INQUIRE statement at %L requires a PENDING= specifier with "
3665 "the ID= specifier", &loc);
3669 new_st.op = EXEC_INQUIRE;
3670 new_st.ext.inquire = inquire;
3674 gfc_syntax_error (ST_INQUIRE);
3677 gfc_free_inquire (inquire);
3682 /* Resolve everything in a gfc_inquire structure. */
3685 gfc_resolve_inquire (gfc_inquire *inquire)
3687 RESOLVE_TAG (&tag_unit, inquire->unit);
3688 RESOLVE_TAG (&tag_file, inquire->file);
3689 RESOLVE_TAG (&tag_iomsg, inquire->iomsg);
3690 RESOLVE_TAG (&tag_iostat, inquire->iostat);
3691 RESOLVE_TAG (&tag_exist, inquire->exist);
3692 RESOLVE_TAG (&tag_opened, inquire->opened);
3693 RESOLVE_TAG (&tag_number, inquire->number);
3694 RESOLVE_TAG (&tag_named, inquire->named);
3695 RESOLVE_TAG (&tag_name, inquire->name);
3696 RESOLVE_TAG (&tag_s_access, inquire->access);
3697 RESOLVE_TAG (&tag_sequential, inquire->sequential);
3698 RESOLVE_TAG (&tag_direct, inquire->direct);
3699 RESOLVE_TAG (&tag_s_form, inquire->form);
3700 RESOLVE_TAG (&tag_formatted, inquire->formatted);
3701 RESOLVE_TAG (&tag_unformatted, inquire->unformatted);
3702 RESOLVE_TAG (&tag_s_recl, inquire->recl);
3703 RESOLVE_TAG (&tag_nextrec, inquire->nextrec);
3704 RESOLVE_TAG (&tag_s_blank, inquire->blank);
3705 RESOLVE_TAG (&tag_s_position, inquire->position);
3706 RESOLVE_TAG (&tag_s_action, inquire->action);
3707 RESOLVE_TAG (&tag_read, inquire->read);
3708 RESOLVE_TAG (&tag_write, inquire->write);
3709 RESOLVE_TAG (&tag_readwrite, inquire->readwrite);
3710 RESOLVE_TAG (&tag_s_delim, inquire->delim);
3711 RESOLVE_TAG (&tag_s_pad, inquire->pad);
3712 RESOLVE_TAG (&tag_s_encoding, inquire->encoding);
3713 RESOLVE_TAG (&tag_s_round, inquire->round);
3714 RESOLVE_TAG (&tag_iolength, inquire->iolength);
3715 RESOLVE_TAG (&tag_convert, inquire->convert);
3716 RESOLVE_TAG (&tag_strm_out, inquire->strm_pos);
3717 RESOLVE_TAG (&tag_s_async, inquire->asynchronous);
3718 RESOLVE_TAG (&tag_s_sign, inquire->sign);
3719 RESOLVE_TAG (&tag_s_round, inquire->round);
3720 RESOLVE_TAG (&tag_pending, inquire->pending);
3721 RESOLVE_TAG (&tag_id, inquire->id);
3723 if (gfc_reference_st_label (inquire->err, ST_LABEL_TARGET) == FAILURE)
3731 gfc_free_wait (gfc_wait *wait)
3736 gfc_free_expr (wait->unit);
3737 gfc_free_expr (wait->iostat);
3738 gfc_free_expr (wait->iomsg);
3739 gfc_free_expr (wait->id);
3744 gfc_resolve_wait (gfc_wait *wait)
3746 RESOLVE_TAG (&tag_unit, wait->unit);
3747 RESOLVE_TAG (&tag_iomsg, wait->iomsg);
3748 RESOLVE_TAG (&tag_iostat, wait->iostat);
3749 RESOLVE_TAG (&tag_id, wait->id);
3751 if (gfc_reference_st_label (wait->err, ST_LABEL_TARGET) == FAILURE)
3754 if (gfc_reference_st_label (wait->end, ST_LABEL_TARGET) == FAILURE)
3760 /* Match an element of a WAIT statement. */
3762 #define RETM if (m != MATCH_NO) return m;
3765 match_wait_element (gfc_wait *wait)
3769 m = match_etag (&tag_unit, &wait->unit);
3770 RETM m = match_ltag (&tag_err, &wait->err);
3771 RETM m = match_ltag (&tag_end, &wait->eor);
3772 RETM m = match_ltag (&tag_eor, &wait->end);
3773 RETM m = match_out_tag (&tag_iomsg, &wait->iomsg);
3774 RETM m = match_out_tag (&tag_iostat, &wait->iostat);
3775 RETM m = match_etag (&tag_id, &wait->id);
3776 RETM return MATCH_NO;
3783 gfc_match_wait (void)
3789 m = gfc_match_char ('(');
3793 wait = XCNEW (gfc_wait);
3795 loc = gfc_current_locus;
3797 m = match_wait_element (wait);
3798 if (m == MATCH_ERROR)
3802 m = gfc_match_expr (&wait->unit);
3803 if (m == MATCH_ERROR)
3811 if (gfc_match_char (')') == MATCH_YES)
3813 if (gfc_match_char (',') != MATCH_YES)
3816 m = match_wait_element (wait);
3817 if (m == MATCH_ERROR)
3823 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: WAIT at %C "
3824 "not allowed in Fortran 95") == FAILURE)
3827 if (gfc_pure (NULL))
3829 gfc_error ("WAIT statement not allowed in PURE procedure at %C");
3833 new_st.op = EXEC_WAIT;
3834 new_st.ext.wait = wait;
3839 gfc_syntax_error (ST_WAIT);
3842 gfc_free_wait (wait);