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;
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_round = {"ROUND", " round = %e", BT_CHARACTER},
54 tag_e_sign = {"SIGN", " sign = %e", BT_CHARACTER},
55 tag_unit = {"UNIT", " unit = %e", BT_INTEGER},
56 tag_advance = {"ADVANCE", " advance = %e", BT_CHARACTER},
57 tag_rec = {"REC", " rec = %e", BT_INTEGER},
58 tag_spos = {"POSITION", " pos = %e", BT_INTEGER},
59 tag_format = {"FORMAT", NULL, BT_CHARACTER},
60 tag_iomsg = {"IOMSG", " iomsg = %e", BT_CHARACTER},
61 tag_iostat = {"IOSTAT", " iostat = %v", BT_INTEGER},
62 tag_size = {"SIZE", " size = %v", BT_INTEGER},
63 tag_exist = {"EXIST", " exist = %v", BT_LOGICAL},
64 tag_opened = {"OPENED", " opened = %v", BT_LOGICAL},
65 tag_named = {"NAMED", " named = %v", BT_LOGICAL},
66 tag_name = {"NAME", " name = %v", BT_CHARACTER},
67 tag_number = {"NUMBER", " number = %v", BT_INTEGER},
68 tag_s_access = {"ACCESS", " access = %v", BT_CHARACTER},
69 tag_sequential = {"SEQUENTIAL", " sequential = %v", BT_CHARACTER},
70 tag_direct = {"DIRECT", " direct = %v", BT_CHARACTER},
71 tag_s_form = {"FORM", " form = %v", BT_CHARACTER},
72 tag_formatted = {"FORMATTED", " formatted = %v", BT_CHARACTER},
73 tag_unformatted = {"UNFORMATTED", " unformatted = %v", BT_CHARACTER},
74 tag_s_recl = {"RECL", " recl = %v", BT_INTEGER},
75 tag_nextrec = {"NEXTREC", " nextrec = %v", BT_INTEGER},
76 tag_s_blank = {"BLANK", " blank = %v", BT_CHARACTER},
77 tag_s_position = {"POSITION", " position = %v", BT_CHARACTER},
78 tag_s_action = {"ACTION", " action = %v", BT_CHARACTER},
79 tag_read = {"READ", " read = %v", BT_CHARACTER},
80 tag_write = {"WRITE", " write = %v", BT_CHARACTER},
81 tag_readwrite = {"READWRITE", " readwrite = %v", BT_CHARACTER},
82 tag_s_delim = {"DELIM", " delim = %v", BT_CHARACTER},
83 tag_s_pad = {"PAD", " pad = %v", BT_CHARACTER},
84 tag_iolength = {"IOLENGTH", " iolength = %v", BT_INTEGER},
85 tag_convert = {"CONVERT", " convert = %e", BT_CHARACTER},
86 tag_strm_out = {"POS", " pos = %v", BT_INTEGER},
87 tag_err = {"ERR", " err = %l", BT_UNKNOWN},
88 tag_end = {"END", " end = %l", BT_UNKNOWN},
89 tag_eor = {"EOR", " eor = %l", BT_UNKNOWN},
90 tag_async = {"ASYNCHRONOUS", " asynchronous = %e", BT_CHARACTER},
91 tag_id = {"ID", " id = %v", BT_INTEGER};
93 static gfc_dt *current_dt;
95 #define RESOLVE_TAG(x, y) if (resolve_tag(x, y) == FAILURE) return FAILURE;
98 /**************** Fortran 95 FORMAT parser *****************/
100 /* FORMAT tokens returned by format_lex(). */
103 FMT_NONE, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
104 FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_POS, FMT_LPAREN,
105 FMT_RPAREN, FMT_X, FMT_SIGN, FMT_BLANK, FMT_CHAR, FMT_P, FMT_IBOZ, FMT_F,
106 FMT_E, FMT_EXT, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END, FMT_ERROR, FMT_DC,
111 /* Local variables for checking format strings. The saved_token is
112 used to back up by a single format token during the parsing
114 static char *format_string;
115 static int format_length, use_last_char;
117 static format_token saved_token;
120 { MODE_STRING, MODE_FORMAT, MODE_COPY }
124 /* Return the next character in the format string. */
127 next_char (int in_string)
139 if (mode == MODE_STRING)
140 c = *format_string++;
143 c = gfc_next_char_literal (in_string);
148 if (gfc_option.flag_backslash && c == '\\')
151 locus old_locus = gfc_current_locus;
153 /* Use a temp variable to avoid side effects from gfc_match_special_char
154 since it uses an int * for its argument. */
157 if (gfc_match_special_char (&tmp) == MATCH_NO)
158 gfc_current_locus = old_locus;
162 if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
163 gfc_warning ("Extension: backslash character at %C");
166 if (mode == MODE_COPY)
167 *format_string++ = c;
174 /* Back up one character position. Only works once. */
182 /* Eat up the spaces and return a character. */
185 next_char_not_space (bool *error)
193 if (gfc_option.allow_std & GFC_STD_GNU)
194 gfc_warning ("Extension: Tab character in format at %C");
197 gfc_error ("Extension: Tab character in format at %C");
203 while (gfc_is_whitespace (c));
207 static int value = 0;
209 /* Simple lexical analyzer for getting the next token in a FORMAT
221 if (saved_token != FMT_NONE)
224 saved_token = FMT_NONE;
228 c = next_char_not_space (&error);
236 c = next_char_not_space (&error);
247 c = next_char_not_space (&error);
249 value = 10 * value + c - '0';
258 token = FMT_SIGNED_INT;
277 c = next_char_not_space (&error);
280 value = 10 * value + c - '0';
288 token = zflag ? FMT_ZERO : FMT_POSINT;
312 c = next_char_not_space (&error);
313 if (c != 'L' && c != 'R')
332 c = next_char_not_space (&error);
333 if (c != 'P' && c != 'S')
340 c = next_char_not_space (&error);
341 if (c == 'N' || c == 'Z')
402 c = next_char_not_space (&error);
403 if (c == 'N' || c == 'S')
430 c = next_char_not_space (&error);
433 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DP format "
434 "specifier not allowed at %C") == FAILURE)
440 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DC format "
441 "specifier not allowed at %C") == FAILURE)
468 /* Check a format statement. The format string, either from a FORMAT
469 statement or a constant in an I/O statement has already been parsed
470 by itself, and we are checking it for validity. The dual origin
471 means that the warning message is a little less than great. */
474 check_format (bool is_input)
476 const char *posint_required = _("Positive width required");
477 const char *nonneg_required = _("Nonnegative width required");
478 const char *unexpected_element = _("Unexpected element");
479 const char *unexpected_end = _("Unexpected end of format string");
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;
689 error = posint_required;
698 /* Warn if -std=legacy, otherwise error. */
699 if (gfc_option.warn_std != 0)
700 gfc_error_now ("Period required in format specifier at %C");
702 gfc_warning ("Period required in format specifier at %C");
710 if (u != FMT_ZERO && u != FMT_POSINT)
712 error = nonneg_required;
719 /* Look for optional exponent. */
734 error = _("Positive exponent width required");
745 if (t != FMT_ZERO && t != FMT_POSINT)
747 error = nonneg_required;
750 else if (is_input && t == FMT_ZERO)
752 error = posint_required;
761 /* Warn if -std=legacy, otherwise error. */
762 if (gfc_option.warn_std != 0)
763 gfc_error_now ("Period required in format specifier at %C");
765 gfc_warning ("Period required in format specifier at %C");
773 if (t != FMT_ZERO && t != FMT_POSINT)
775 error = nonneg_required;
782 if (!(gfc_option.allow_std & GFC_STD_GNU) && !inhibit_warnings)
783 gfc_warning ("The H format specifier at %C is"
784 " a Fortran 95 deleted feature");
786 if(mode == MODE_STRING)
788 format_string += value;
789 format_length -= value;
805 if (t != FMT_ZERO && t != FMT_POSINT)
807 error = nonneg_required;
810 else if (is_input && t == FMT_ZERO)
812 error = posint_required;
828 if (t != FMT_ZERO && t != FMT_POSINT)
830 error = nonneg_required;
838 error = unexpected_element;
843 /* Between a descriptor and what comes next. */
864 error = unexpected_end;
868 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
875 /* Optional comma is a weird between state where we've just finished
876 reading a colon, slash, dollar or P descriptor. */
893 /* Assume that we have another format item. */
900 extension_optional_comma:
901 /* As a GNU extension, permit a missing comma after a string literal. */
921 error = unexpected_end;
925 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
935 gfc_error ("%s in format string at %C", error);
937 /* TODO: More elaborate measures are needed to show where a problem
938 is within a format string that has been calculated. */
946 /* Given an expression node that is a constant string, see if it looks
947 like a format string. */
950 check_format_string (gfc_expr *e, bool is_input)
952 if (!e || e->ts.type != BT_CHARACTER || e->expr_type != EXPR_CONSTANT)
956 format_string = e->value.character.string;
957 return check_format (is_input);
961 /************ Fortran 95 I/O statement matchers *************/
963 /* Match a FORMAT statement. This amounts to actually parsing the
964 format descriptors in order to correctly locate the end of the
968 gfc_match_format (void)
973 if (gfc_current_ns->proc_name
974 && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
976 gfc_error ("Format statement in module main block at %C");
980 if (gfc_statement_label == NULL)
982 gfc_error ("Missing format label at %C");
985 gfc_gobble_whitespace ();
990 start = gfc_current_locus;
992 if (check_format (false) == FAILURE)
995 if (gfc_match_eos () != MATCH_YES)
997 gfc_syntax_error (ST_FORMAT);
1001 /* The label doesn't get created until after the statement is done
1002 being matched, so we have to leave the string for later. */
1004 gfc_current_locus = start; /* Back to the beginning */
1007 new_st.op = EXEC_NOP;
1010 e->expr_type = EXPR_CONSTANT;
1011 e->ts.type = BT_CHARACTER;
1012 e->ts.kind = gfc_default_character_kind;
1014 e->value.character.string = format_string = gfc_getmem (format_length + 1);
1015 e->value.character.length = format_length;
1016 gfc_statement_label->format = e;
1019 check_format (false); /* Guaranteed to succeed */
1020 gfc_match_eos (); /* Guaranteed to succeed */
1026 /* Match an expression I/O tag of some sort. */
1029 match_etag (const io_tag *tag, gfc_expr **v)
1034 m = gfc_match (tag->spec, &result);
1040 gfc_error ("Duplicate %s specification at %C", tag->name);
1041 gfc_free_expr (result);
1050 /* Match a variable I/O tag of some sort. */
1053 match_vtag (const io_tag *tag, gfc_expr **v)
1058 m = gfc_match (tag->spec, &result);
1064 gfc_error ("Duplicate %s specification at %C", tag->name);
1065 gfc_free_expr (result);
1069 if (result->symtree->n.sym->attr.intent == INTENT_IN)
1071 gfc_error ("Variable tag cannot be INTENT(IN) at %C");
1072 gfc_free_expr (result);
1076 if (gfc_pure (NULL) && gfc_impure_variable (result->symtree->n.sym))
1078 gfc_error ("Variable tag cannot be assigned in PURE procedure at %C");
1079 gfc_free_expr (result);
1088 /* Match I/O tags that cause variables to become redefined. */
1091 match_out_tag(const io_tag *tag, gfc_expr **result)
1095 m = match_vtag(tag, result);
1097 gfc_check_do_variable((*result)->symtree);
1103 /* Match a label I/O tag. */
1106 match_ltag (const io_tag *tag, gfc_st_label ** label)
1112 m = gfc_match (tag->spec, label);
1113 if (m == MATCH_YES && old != 0)
1115 gfc_error ("Duplicate %s label specification at %C", tag->name);
1120 && gfc_reference_st_label (*label, ST_LABEL_TARGET) == FAILURE)
1127 /* Resolution of the FORMAT tag, to be called from resolve_tag. */
1130 resolve_tag_format (const gfc_expr *e)
1132 if (e->expr_type == EXPR_CONSTANT
1133 && (e->ts.type != BT_CHARACTER
1134 || e->ts.kind != gfc_default_character_kind))
1136 gfc_error ("Constant expression in FORMAT tag at %L must be "
1137 "of type default CHARACTER", &e->where);
1141 /* If e's rank is zero and e is not an element of an array, it should be
1142 of integer or character type. The integer variable should be
1144 if (e->symtree == NULL || e->symtree->n.sym->as == NULL
1145 || e->symtree->n.sym->as->rank == 0)
1147 if (e->ts.type != BT_CHARACTER && e->ts.type != BT_INTEGER)
1149 gfc_error ("FORMAT tag at %L must be of type CHARACTER or INTEGER",
1153 else if (e->ts.type == BT_INTEGER && e->expr_type == EXPR_VARIABLE)
1155 if (gfc_notify_std (GFC_STD_F95_DEL, "Deleted feature: ASSIGNED "
1156 "variable in FORMAT tag at %L", &e->where)
1159 if (e->symtree->n.sym->attr.assign != 1)
1161 gfc_error ("Variable '%s' at %L has not been assigned a "
1162 "format label", e->symtree->n.sym->name, &e->where);
1166 else if (e->ts.type == BT_INTEGER)
1168 gfc_error ("Scalar '%s' in FORMAT tag at %L is not an ASSIGNED "
1169 "variable", gfc_basic_typename (e->ts.type), &e->where);
1176 /* If rank is nonzero, we allow the type to be character under GFC_STD_GNU
1177 and other type under GFC_STD_LEGACY. It may be assigned an Hollerith
1179 if (e->ts.type == BT_CHARACTER)
1181 if (gfc_notify_std (GFC_STD_GNU, "Extension: Character array "
1182 "in FORMAT tag at %L", &e->where) == FAILURE)
1187 if (gfc_notify_std (GFC_STD_LEGACY, "Extension: Non-character "
1188 "in FORMAT tag at %L", &e->where) == FAILURE)
1196 /* Do expression resolution and type-checking on an expression tag. */
1199 resolve_tag (const io_tag *tag, gfc_expr *e)
1204 if (gfc_resolve_expr (e) == FAILURE)
1207 if (tag == &tag_format)
1208 return resolve_tag_format (e);
1210 if (e->ts.type != tag->type)
1212 gfc_error ("%s tag at %L must be of type %s", tag->name,
1213 &e->where, gfc_basic_typename (tag->type));
1219 gfc_error ("%s tag at %L must be scalar", tag->name, &e->where);
1223 if (tag == &tag_iomsg)
1225 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: IOMSG tag at %L",
1226 &e->where) == FAILURE)
1230 if ((tag == &tag_iostat || tag == &tag_size || tag == &tag_iolength)
1231 && e->ts.kind != gfc_default_integer_kind)
1233 if (gfc_notify_std (GFC_STD_F2003, "Fortran 95 requires default "
1234 "INTEGER in %s tag at %L", tag->name, &e->where)
1239 if (tag == &tag_convert)
1241 if (gfc_notify_std (GFC_STD_GNU, "Extension: CONVERT tag at %L",
1242 &e->where) == FAILURE)
1250 /* Match a single tag of an OPEN statement. */
1253 match_open_element (gfc_open *open)
1257 m = match_etag (&tag_async, &open->asynchronous);
1260 m = match_etag (&tag_unit, &open->unit);
1263 m = match_out_tag (&tag_iomsg, &open->iomsg);
1266 m = match_out_tag (&tag_iostat, &open->iostat);
1269 m = match_etag (&tag_file, &open->file);
1272 m = match_etag (&tag_status, &open->status);
1275 m = match_etag (&tag_e_access, &open->access);
1278 m = match_etag (&tag_e_form, &open->form);
1281 m = match_etag (&tag_e_recl, &open->recl);
1284 m = match_etag (&tag_e_blank, &open->blank);
1287 m = match_etag (&tag_e_position, &open->position);
1290 m = match_etag (&tag_e_action, &open->action);
1293 m = match_etag (&tag_e_delim, &open->delim);
1296 m = match_etag (&tag_e_pad, &open->pad);
1299 m = match_etag (&tag_e_decimal, &open->decimal);
1302 m = match_etag (&tag_e_encoding, &open->encoding);
1305 m = match_etag (&tag_e_round, &open->round);
1308 m = match_etag (&tag_e_sign, &open->sign);
1311 m = match_ltag (&tag_err, &open->err);
1314 m = match_etag (&tag_convert, &open->convert);
1322 /* Free the gfc_open structure and all the expressions it contains. */
1325 gfc_free_open (gfc_open *open)
1330 gfc_free_expr (open->unit);
1331 gfc_free_expr (open->iomsg);
1332 gfc_free_expr (open->iostat);
1333 gfc_free_expr (open->file);
1334 gfc_free_expr (open->status);
1335 gfc_free_expr (open->access);
1336 gfc_free_expr (open->form);
1337 gfc_free_expr (open->recl);
1338 gfc_free_expr (open->blank);
1339 gfc_free_expr (open->position);
1340 gfc_free_expr (open->action);
1341 gfc_free_expr (open->delim);
1342 gfc_free_expr (open->pad);
1343 gfc_free_expr (open->decimal);
1344 gfc_free_expr (open->encoding);
1345 gfc_free_expr (open->round);
1346 gfc_free_expr (open->sign);
1347 gfc_free_expr (open->convert);
1348 gfc_free_expr (open->asynchronous);
1353 /* Resolve everything in a gfc_open structure. */
1356 gfc_resolve_open (gfc_open *open)
1359 RESOLVE_TAG (&tag_unit, open->unit);
1360 RESOLVE_TAG (&tag_iomsg, open->iomsg);
1361 RESOLVE_TAG (&tag_iostat, open->iostat);
1362 RESOLVE_TAG (&tag_file, open->file);
1363 RESOLVE_TAG (&tag_status, open->status);
1364 RESOLVE_TAG (&tag_e_access, open->access);
1365 RESOLVE_TAG (&tag_e_form, open->form);
1366 RESOLVE_TAG (&tag_e_recl, open->recl);
1367 RESOLVE_TAG (&tag_e_blank, open->blank);
1368 RESOLVE_TAG (&tag_e_position, open->position);
1369 RESOLVE_TAG (&tag_e_action, open->action);
1370 RESOLVE_TAG (&tag_e_delim, open->delim);
1371 RESOLVE_TAG (&tag_e_pad, open->pad);
1372 RESOLVE_TAG (&tag_e_decimal, open->decimal);
1373 RESOLVE_TAG (&tag_e_encoding, open->encoding);
1374 RESOLVE_TAG (&tag_e_round, open->round);
1375 RESOLVE_TAG (&tag_e_sign, open->sign);
1376 RESOLVE_TAG (&tag_convert, open->convert);
1378 if (gfc_reference_st_label (open->err, ST_LABEL_TARGET) == FAILURE)
1385 /* Check if a given value for a SPECIFIER is either in the list of values
1386 allowed in F95 or F2003, issuing an error message and returning a zero
1387 value if it is not allowed. */
1390 compare_to_allowed_values (const char *specifier, const char *allowed[],
1391 const char *allowed_f2003[],
1392 const char *allowed_gnu[], char *value,
1393 const char *statement, bool warn)
1398 len = strlen (value);
1401 for (len--; len > 0; len--)
1402 if (value[len] != ' ')
1407 for (i = 0; allowed[i]; i++)
1408 if (len == strlen (allowed[i])
1409 && strncasecmp (value, allowed[i], strlen (allowed[i])) == 0)
1412 for (i = 0; allowed_f2003 && allowed_f2003[i]; i++)
1413 if (len == strlen (allowed_f2003[i])
1414 && strncasecmp (value, allowed_f2003[i], strlen (allowed_f2003[i]))
1417 notification n = gfc_notification_std (GFC_STD_F2003);
1419 if (n == WARNING || (warn && n == ERROR))
1421 gfc_warning ("Fortran 2003: %s specifier in %s statement at %C "
1422 "has value '%s'", specifier, statement,
1429 gfc_notify_std (GFC_STD_F2003, "Fortran 2003: %s specifier in "
1430 "%s statement at %C has value '%s'", specifier,
1431 statement, allowed_f2003[i]);
1439 for (i = 0; allowed_gnu && allowed_gnu[i]; i++)
1440 if (len == strlen (allowed_gnu[i])
1441 && strncasecmp (value, allowed_gnu[i], strlen (allowed_gnu[i])) == 0)
1443 notification n = gfc_notification_std (GFC_STD_GNU);
1445 if (n == WARNING || (warn && n == ERROR))
1447 gfc_warning ("Extension: %s specifier in %s statement at %C "
1448 "has value '%s'", specifier, statement,
1455 gfc_notify_std (GFC_STD_GNU, "Extension: %s specifier in "
1456 "%s statement at %C has value '%s'", specifier,
1457 statement, allowed_gnu[i]);
1467 gfc_warning ("%s specifier in %s statement at %C has invalid value '%s'",
1468 specifier, statement, value);
1473 gfc_error ("%s specifier in %s statement at %C has invalid value '%s'",
1474 specifier, statement, value);
1480 /* Match an OPEN statement. */
1483 gfc_match_open (void)
1489 m = gfc_match_char ('(');
1493 open = gfc_getmem (sizeof (gfc_open));
1495 m = match_open_element (open);
1497 if (m == MATCH_ERROR)
1501 m = gfc_match_expr (&open->unit);
1504 if (m == MATCH_ERROR)
1510 if (gfc_match_char (')') == MATCH_YES)
1512 if (gfc_match_char (',') != MATCH_YES)
1515 m = match_open_element (open);
1516 if (m == MATCH_ERROR)
1522 if (gfc_match_eos () == MATCH_NO)
1525 if (gfc_pure (NULL))
1527 gfc_error ("OPEN statement not allowed in PURE procedure at %C");
1531 warn = (open->err || open->iostat) ? true : false;
1532 /* Checks on the ACCESS specifier. */
1533 if (open->access && open->access->expr_type == EXPR_CONSTANT)
1535 static const char *access_f95[] = { "SEQUENTIAL", "DIRECT", NULL };
1536 static const char *access_f2003[] = { "STREAM", NULL };
1537 static const char *access_gnu[] = { "APPEND", NULL };
1539 if (!compare_to_allowed_values ("ACCESS", access_f95, access_f2003,
1541 open->access->value.character.string,
1546 /* Checks on the ACTION specifier. */
1547 if (open->action && open->action->expr_type == EXPR_CONSTANT)
1549 static const char *action[] = { "READ", "WRITE", "READWRITE", NULL };
1551 if (!compare_to_allowed_values ("ACTION", action, NULL, NULL,
1552 open->action->value.character.string,
1557 /* Checks on the ASYNCHRONOUS specifier. */
1558 if (open->asynchronous)
1560 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ASYNCHRONOUS= at %C "
1561 "not allowed in Fortran 95") == FAILURE)
1564 if (open->asynchronous->expr_type == EXPR_CONSTANT)
1566 static const char * asynchronous[] = { "YES", "NO", NULL };
1568 if (!compare_to_allowed_values ("ASYNCHRONOUS", asynchronous,
1569 NULL, NULL, open->asynchronous->value.character.string,
1575 /* Checks on the BLANK specifier. */
1578 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: BLANK= at %C "
1579 "not allowed in Fortran 95") == FAILURE)
1582 if (open->blank->expr_type == EXPR_CONSTANT)
1584 static const char *blank[] = { "ZERO", "NULL", NULL };
1586 if (!compare_to_allowed_values ("BLANK", blank, NULL, NULL,
1587 open->blank->value.character.string,
1593 /* Checks on the DECIMAL specifier. */
1596 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DECIMAL= at %C "
1597 "not allowed in Fortran 95") == FAILURE)
1600 if (open->decimal->expr_type == EXPR_CONSTANT)
1602 static const char * decimal[] = { "COMMA", "POINT", NULL };
1604 if (!compare_to_allowed_values ("DECIMAL", decimal, NULL, NULL,
1605 open->decimal->value.character.string,
1611 /* Checks on the DELIM specifier. */
1614 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DELIM= at %C "
1615 "not allowed in Fortran 95") == FAILURE)
1618 if (open->delim->expr_type == EXPR_CONSTANT)
1620 static const char *delim[] = { "APOSTROPHE", "QUOTE", "NONE", NULL };
1622 if (!compare_to_allowed_values ("DELIM", delim, NULL, NULL,
1623 open->delim->value.character.string,
1629 /* Checks on the ENCODING specifier. */
1632 /* When implemented, change the following to use gfc_notify_std F2003.
1633 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ENCODING= at %C "
1634 "not allowed in Fortran 95") == FAILURE)
1636 gfc_error ("F2003 Feature: ENCODING=specifier at %C not implemented");
1639 if (open->encoding->expr_type == EXPR_CONSTANT)
1641 static const char * encoding[] = { "UTF-8", "DEFAULT", NULL };
1643 if (!compare_to_allowed_values ("ENCODING", encoding, NULL, NULL,
1644 open->encoding->value.character.string,
1650 /* Checks on the FORM specifier. */
1651 if (open->form && open->form->expr_type == EXPR_CONSTANT)
1653 static const char *form[] = { "FORMATTED", "UNFORMATTED", NULL };
1655 if (!compare_to_allowed_values ("FORM", form, NULL, NULL,
1656 open->form->value.character.string,
1661 /* Checks on the PAD specifier. */
1662 if (open->pad && open->pad->expr_type == EXPR_CONSTANT)
1664 static const char *pad[] = { "YES", "NO", NULL };
1666 if (!compare_to_allowed_values ("PAD", pad, NULL, NULL,
1667 open->pad->value.character.string,
1672 /* Checks on the POSITION specifier. */
1673 if (open->position && open->position->expr_type == EXPR_CONSTANT)
1675 static const char *position[] = { "ASIS", "REWIND", "APPEND", NULL };
1677 if (!compare_to_allowed_values ("POSITION", position, NULL, NULL,
1678 open->position->value.character.string,
1683 /* Checks on the ROUND specifier. */
1686 /* When implemented, change the following to use gfc_notify_std F2003. */
1687 gfc_error ("F2003 Feature: ROUND=specifier at %C not implemented");
1690 if (open->round->expr_type == EXPR_CONSTANT)
1692 static const char * round[] = { "UP", "DOWN", "ZERO", "NEAREST",
1693 "COMPATIBLE", "PROCESSOR_DEFINED",
1696 if (!compare_to_allowed_values ("ROUND", round, NULL, NULL,
1697 open->round->value.character.string,
1703 /* Checks on the SIGN specifier. */
1706 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: SIGN= at %C "
1707 "not allowed in Fortran 95") == FAILURE)
1710 if (open->sign->expr_type == EXPR_CONSTANT)
1712 static const char * sign[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
1715 if (!compare_to_allowed_values ("SIGN", sign, NULL, NULL,
1716 open->sign->value.character.string,
1722 #define warn_or_error(...) \
1725 gfc_warning (__VA_ARGS__); \
1728 gfc_error (__VA_ARGS__); \
1733 /* Checks on the RECL specifier. */
1734 if (open->recl && open->recl->expr_type == EXPR_CONSTANT
1735 && open->recl->ts.type == BT_INTEGER
1736 && mpz_sgn (open->recl->value.integer) != 1)
1738 warn_or_error ("RECL in OPEN statement at %C must be positive");
1741 /* Checks on the STATUS specifier. */
1742 if (open->status && open->status->expr_type == EXPR_CONSTANT)
1744 static const char *status[] = { "OLD", "NEW", "SCRATCH",
1745 "REPLACE", "UNKNOWN", NULL };
1747 if (!compare_to_allowed_values ("STATUS", status, NULL, NULL,
1748 open->status->value.character.string,
1752 /* F2003, 9.4.5: If the STATUS=specifier has the value NEW or REPLACE,
1753 the FILE=specifier shall appear. */
1754 if (open->file == NULL
1755 && (strncasecmp (open->status->value.character.string, "replace", 7)
1757 || strncasecmp (open->status->value.character.string, "new", 3)
1760 warn_or_error ("The STATUS specified in OPEN statement at %C is "
1761 "'%s' and no FILE specifier is present",
1762 open->status->value.character.string);
1765 /* F2003, 9.4.5: If the STATUS=specifier has the value SCRATCH,
1766 the FILE=specifier shall not appear. */
1767 if (strncasecmp (open->status->value.character.string, "scratch", 7)
1770 warn_or_error ("The STATUS specified in OPEN statement at %C "
1771 "cannot have the value SCRATCH if a FILE specifier "
1776 /* Things that are not allowed for unformatted I/O. */
1777 if (open->form && open->form->expr_type == EXPR_CONSTANT
1778 && (open->delim || open->decimal || open->encoding || open->round
1779 || open->sign || open->pad || open->blank)
1780 && strncasecmp (open->form->value.character.string,
1781 "unformatted", 11) == 0)
1783 const char *spec = (open->delim ? "DELIM "
1784 : (open->pad ? "PAD " : open->blank
1787 warn_or_error ("%s specifier at %C not allowed in OPEN statement for "
1788 "unformatted I/O", spec);
1791 if (open->recl && open->access && open->access->expr_type == EXPR_CONSTANT
1792 && strncasecmp (open->access->value.character.string, "stream", 6) == 0)
1794 warn_or_error ("RECL specifier not allowed in OPEN statement at %C for "
1799 && open->access && open->access->expr_type == EXPR_CONSTANT
1800 && !(strncasecmp (open->access->value.character.string,
1801 "sequential", 10) == 0
1802 || strncasecmp (open->access->value.character.string,
1804 || strncasecmp (open->access->value.character.string,
1807 warn_or_error ("POSITION specifier in OPEN statement at %C only allowed "
1808 "for stream or sequential ACCESS");
1811 #undef warn_or_error
1813 new_st.op = EXEC_OPEN;
1814 new_st.ext.open = open;
1818 gfc_syntax_error (ST_OPEN);
1821 gfc_free_open (open);
1826 /* Free a gfc_close structure an all its expressions. */
1829 gfc_free_close (gfc_close *close)
1834 gfc_free_expr (close->unit);
1835 gfc_free_expr (close->iomsg);
1836 gfc_free_expr (close->iostat);
1837 gfc_free_expr (close->status);
1842 /* Match elements of a CLOSE statement. */
1845 match_close_element (gfc_close *close)
1849 m = match_etag (&tag_unit, &close->unit);
1852 m = match_etag (&tag_status, &close->status);
1855 m = match_out_tag (&tag_iomsg, &close->iomsg);
1858 m = match_out_tag (&tag_iostat, &close->iostat);
1861 m = match_ltag (&tag_err, &close->err);
1869 /* Match a CLOSE statement. */
1872 gfc_match_close (void)
1878 m = gfc_match_char ('(');
1882 close = gfc_getmem (sizeof (gfc_close));
1884 m = match_close_element (close);
1886 if (m == MATCH_ERROR)
1890 m = gfc_match_expr (&close->unit);
1893 if (m == MATCH_ERROR)
1899 if (gfc_match_char (')') == MATCH_YES)
1901 if (gfc_match_char (',') != MATCH_YES)
1904 m = match_close_element (close);
1905 if (m == MATCH_ERROR)
1911 if (gfc_match_eos () == MATCH_NO)
1914 if (gfc_pure (NULL))
1916 gfc_error ("CLOSE statement not allowed in PURE procedure at %C");
1920 warn = (close->iostat || close->err) ? true : false;
1922 /* Checks on the STATUS specifier. */
1923 if (close->status && close->status->expr_type == EXPR_CONSTANT)
1925 static const char *status[] = { "KEEP", "DELETE", NULL };
1927 if (!compare_to_allowed_values ("STATUS", status, NULL, NULL,
1928 close->status->value.character.string,
1933 new_st.op = EXEC_CLOSE;
1934 new_st.ext.close = close;
1938 gfc_syntax_error (ST_CLOSE);
1941 gfc_free_close (close);
1946 /* Resolve everything in a gfc_close structure. */
1949 gfc_resolve_close (gfc_close *close)
1951 RESOLVE_TAG (&tag_unit, close->unit);
1952 RESOLVE_TAG (&tag_iomsg, close->iomsg);
1953 RESOLVE_TAG (&tag_iostat, close->iostat);
1954 RESOLVE_TAG (&tag_status, close->status);
1956 if (gfc_reference_st_label (close->err, ST_LABEL_TARGET) == FAILURE)
1963 /* Free a gfc_filepos structure. */
1966 gfc_free_filepos (gfc_filepos *fp)
1968 gfc_free_expr (fp->unit);
1969 gfc_free_expr (fp->iomsg);
1970 gfc_free_expr (fp->iostat);
1975 /* Match elements of a REWIND, BACKSPACE, ENDFILE, or FLUSH statement. */
1978 match_file_element (gfc_filepos *fp)
1982 m = match_etag (&tag_unit, &fp->unit);
1985 m = match_out_tag (&tag_iomsg, &fp->iomsg);
1988 m = match_out_tag (&tag_iostat, &fp->iostat);
1991 m = match_ltag (&tag_err, &fp->err);
1999 /* Match the second half of the file-positioning statements, REWIND,
2000 BACKSPACE, ENDFILE, or the FLUSH statement. */
2003 match_filepos (gfc_statement st, gfc_exec_op op)
2008 fp = gfc_getmem (sizeof (gfc_filepos));
2010 if (gfc_match_char ('(') == MATCH_NO)
2012 m = gfc_match_expr (&fp->unit);
2013 if (m == MATCH_ERROR)
2021 m = match_file_element (fp);
2022 if (m == MATCH_ERROR)
2026 m = gfc_match_expr (&fp->unit);
2027 if (m == MATCH_ERROR)
2035 if (gfc_match_char (')') == MATCH_YES)
2037 if (gfc_match_char (',') != MATCH_YES)
2040 m = match_file_element (fp);
2041 if (m == MATCH_ERROR)
2048 if (gfc_match_eos () != MATCH_YES)
2051 if (gfc_pure (NULL))
2053 gfc_error ("%s statement not allowed in PURE procedure at %C",
2054 gfc_ascii_statement (st));
2060 new_st.ext.filepos = fp;
2064 gfc_syntax_error (st);
2067 gfc_free_filepos (fp);
2073 gfc_resolve_filepos (gfc_filepos *fp)
2075 RESOLVE_TAG (&tag_unit, fp->unit);
2076 RESOLVE_TAG (&tag_iostat, fp->iostat);
2077 RESOLVE_TAG (&tag_iomsg, fp->iomsg);
2078 if (gfc_reference_st_label (fp->err, ST_LABEL_TARGET) == FAILURE)
2085 /* Match the file positioning statements: ENDFILE, BACKSPACE, REWIND,
2086 and the FLUSH statement. */
2089 gfc_match_endfile (void)
2091 return match_filepos (ST_END_FILE, EXEC_ENDFILE);
2095 gfc_match_backspace (void)
2097 return match_filepos (ST_BACKSPACE, EXEC_BACKSPACE);
2101 gfc_match_rewind (void)
2103 return match_filepos (ST_REWIND, EXEC_REWIND);
2107 gfc_match_flush (void)
2109 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: FLUSH statement at %C")
2113 return match_filepos (ST_FLUSH, EXEC_FLUSH);
2116 /******************** Data Transfer Statements *********************/
2119 { M_READ, M_WRITE, M_PRINT, M_INQUIRE }
2123 /* Return a default unit number. */
2126 default_unit (io_kind k)
2135 return gfc_int_expr (unit);
2139 /* Match a unit specification for a data transfer statement. */
2142 match_dt_unit (io_kind k, gfc_dt *dt)
2146 if (gfc_match_char ('*') == MATCH_YES)
2148 if (dt->io_unit != NULL)
2151 dt->io_unit = default_unit (k);
2155 if (gfc_match_expr (&e) == MATCH_YES)
2157 if (dt->io_unit != NULL)
2170 gfc_error ("Duplicate UNIT specification at %C");
2175 /* Match a format specification. */
2178 match_dt_format (gfc_dt *dt)
2182 gfc_st_label *label;
2185 where = gfc_current_locus;
2187 if (gfc_match_char ('*') == MATCH_YES)
2189 if (dt->format_expr != NULL || dt->format_label != NULL)
2192 dt->format_label = &format_asterisk;
2196 if ((m = gfc_match_st_label (&label)) == MATCH_YES)
2198 if (dt->format_expr != NULL || dt->format_label != NULL)
2200 gfc_free_st_label (label);
2204 if (gfc_reference_st_label (label, ST_LABEL_FORMAT) == FAILURE)
2207 dt->format_label = label;
2210 else if (m == MATCH_ERROR)
2211 /* The label was zero or too large. Emit the correct diagnosis. */
2214 if (gfc_match_expr (&e) == MATCH_YES)
2216 if (dt->format_expr != NULL || dt->format_label != NULL)
2221 dt->format_expr = e;
2225 gfc_current_locus = where; /* The only case where we have to restore */
2230 gfc_error ("Duplicate format specification at %C");
2235 /* Traverse a namelist that is part of a READ statement to make sure
2236 that none of the variables in the namelist are INTENT(IN). Returns
2237 nonzero if we find such a variable. */
2240 check_namelist (gfc_symbol *sym)
2244 for (p = sym->namelist; p; p = p->next)
2245 if (p->sym->attr.intent == INTENT_IN)
2247 gfc_error ("Symbol '%s' in namelist '%s' is INTENT(IN) at %C",
2248 p->sym->name, sym->name);
2256 /* Match a single data transfer element. */
2259 match_dt_element (io_kind k, gfc_dt *dt)
2261 char name[GFC_MAX_SYMBOL_LEN + 1];
2265 if (gfc_match (" unit =") == MATCH_YES)
2267 m = match_dt_unit (k, dt);
2272 if (gfc_match (" fmt =") == MATCH_YES)
2274 m = match_dt_format (dt);
2279 if (gfc_match (" nml = %n", name) == MATCH_YES)
2281 if (dt->namelist != NULL)
2283 gfc_error ("Duplicate NML specification at %C");
2287 if (gfc_find_symbol (name, NULL, 1, &sym))
2290 if (sym == NULL || sym->attr.flavor != FL_NAMELIST)
2292 gfc_error ("Symbol '%s' at %C must be a NAMELIST group name",
2293 sym != NULL ? sym->name : name);
2298 if (k == M_READ && check_namelist (sym))
2304 m = match_etag (&tag_async, &dt->asynchronous);
2307 m = match_etag (&tag_e_blank, &dt->blank);
2310 m = match_etag (&tag_e_delim, &dt->delim);
2313 m = match_etag (&tag_e_pad, &dt->pad);
2316 m = match_etag (&tag_e_sign, &dt->sign);
2319 m = match_etag (&tag_e_round, &dt->round);
2322 m = match_out_tag (&tag_id, &dt->id);
2325 m = match_etag (&tag_e_decimal, &dt->decimal);
2328 m = match_etag (&tag_rec, &dt->rec);
2331 m = match_etag (&tag_spos, &dt->rec);
2334 m = match_out_tag (&tag_iomsg, &dt->iomsg);
2337 m = match_out_tag (&tag_iostat, &dt->iostat);
2340 m = match_ltag (&tag_err, &dt->err);
2342 dt->err_where = gfc_current_locus;
2345 m = match_etag (&tag_advance, &dt->advance);
2348 m = match_out_tag (&tag_size, &dt->size);
2352 m = match_ltag (&tag_end, &dt->end);
2357 gfc_error ("END tag at %C not allowed in output statement");
2360 dt->end_where = gfc_current_locus;
2365 m = match_ltag (&tag_eor, &dt->eor);
2367 dt->eor_where = gfc_current_locus;
2375 /* Free a data transfer structure and everything below it. */
2378 gfc_free_dt (gfc_dt *dt)
2383 gfc_free_expr (dt->io_unit);
2384 gfc_free_expr (dt->format_expr);
2385 gfc_free_expr (dt->rec);
2386 gfc_free_expr (dt->advance);
2387 gfc_free_expr (dt->iomsg);
2388 gfc_free_expr (dt->iostat);
2389 gfc_free_expr (dt->size);
2390 gfc_free_expr (dt->pad);
2391 gfc_free_expr (dt->delim);
2392 gfc_free_expr (dt->sign);
2393 gfc_free_expr (dt->round);
2394 gfc_free_expr (dt->blank);
2395 gfc_free_expr (dt->decimal);
2400 /* Resolve everything in a gfc_dt structure. */
2403 gfc_resolve_dt (gfc_dt *dt)
2407 RESOLVE_TAG (&tag_format, dt->format_expr);
2408 RESOLVE_TAG (&tag_rec, dt->rec);
2409 RESOLVE_TAG (&tag_spos, dt->rec);
2410 RESOLVE_TAG (&tag_advance, dt->advance);
2411 RESOLVE_TAG (&tag_iomsg, dt->iomsg);
2412 RESOLVE_TAG (&tag_iostat, dt->iostat);
2413 RESOLVE_TAG (&tag_size, dt->size);
2414 RESOLVE_TAG (&tag_e_pad, dt->pad);
2415 RESOLVE_TAG (&tag_e_delim, dt->delim);
2416 RESOLVE_TAG (&tag_e_sign, dt->sign);
2417 RESOLVE_TAG (&tag_e_round, dt->round);
2418 RESOLVE_TAG (&tag_e_blank, dt->blank);
2419 RESOLVE_TAG (&tag_e_decimal, dt->decimal);
2422 if (gfc_resolve_expr (e) == SUCCESS
2423 && (e->ts.type != BT_INTEGER
2424 && (e->ts.type != BT_CHARACTER || e->expr_type != EXPR_VARIABLE)))
2426 gfc_error ("UNIT specification at %L must be an INTEGER expression "
2427 "or a CHARACTER variable", &e->where);
2431 if (e->ts.type == BT_CHARACTER)
2433 if (gfc_has_vector_index (e))
2435 gfc_error ("Internal unit with vector subscript at %L", &e->where);
2440 if (e->rank && e->ts.type != BT_CHARACTER)
2442 gfc_error ("External IO UNIT cannot be an array at %L", &e->where);
2448 if (gfc_reference_st_label (dt->err, ST_LABEL_TARGET) == FAILURE)
2450 if (dt->err->defined == ST_LABEL_UNKNOWN)
2452 gfc_error ("ERR tag label %d at %L not defined",
2453 dt->err->value, &dt->err_where);
2460 if (gfc_reference_st_label (dt->end, ST_LABEL_TARGET) == FAILURE)
2462 if (dt->end->defined == ST_LABEL_UNKNOWN)
2464 gfc_error ("END tag label %d at %L not defined",
2465 dt->end->value, &dt->end_where);
2472 if (gfc_reference_st_label (dt->eor, ST_LABEL_TARGET) == FAILURE)
2474 if (dt->eor->defined == ST_LABEL_UNKNOWN)
2476 gfc_error ("EOR tag label %d at %L not defined",
2477 dt->eor->value, &dt->eor_where);
2482 /* Check the format label actually exists. */
2483 if (dt->format_label && dt->format_label != &format_asterisk
2484 && dt->format_label->defined == ST_LABEL_UNKNOWN)
2486 gfc_error ("FORMAT label %d at %L not defined", dt->format_label->value,
2487 &dt->format_label->where);
2494 /* Given an io_kind, return its name. */
2497 io_kind_name (io_kind k)
2516 gfc_internal_error ("io_kind_name(): bad I/O-kind");
2523 /* Match an IO iteration statement of the form:
2525 ( [<IO element> ,] <IO element>, I = <expr>, <expr> [, <expr> ] )
2527 which is equivalent to a single IO element. This function is
2528 mutually recursive with match_io_element(). */
2530 static match match_io_element (io_kind, gfc_code **);
2533 match_io_iterator (io_kind k, gfc_code **result)
2535 gfc_code *head, *tail, *new;
2543 old_loc = gfc_current_locus;
2545 if (gfc_match_char ('(') != MATCH_YES)
2548 m = match_io_element (k, &head);
2551 if (m != MATCH_YES || gfc_match_char (',') != MATCH_YES)
2557 /* Can't be anything but an IO iterator. Build a list. */
2558 iter = gfc_get_iterator ();
2562 m = gfc_match_iterator (iter, 0);
2563 if (m == MATCH_ERROR)
2567 gfc_check_do_variable (iter->var->symtree);
2571 m = match_io_element (k, &new);
2572 if (m == MATCH_ERROR)
2581 tail = gfc_append_code (tail, new);
2583 if (gfc_match_char (',') != MATCH_YES)
2592 if (gfc_match_char (')') != MATCH_YES)
2595 new = gfc_get_code ();
2597 new->ext.iterator = iter;
2599 new->block = gfc_get_code ();
2600 new->block->op = EXEC_DO;
2601 new->block->next = head;
2607 gfc_error ("Syntax error in I/O iterator at %C");
2611 gfc_free_iterator (iter, 1);
2612 gfc_free_statements (head);
2613 gfc_current_locus = old_loc;
2618 /* Match a single element of an IO list, which is either a single
2619 expression or an IO Iterator. */
2622 match_io_element (io_kind k, gfc_code **cpp)
2630 m = match_io_iterator (k, cpp);
2636 m = gfc_match_variable (&expr, 0);
2638 gfc_error ("Expected variable in READ statement at %C");
2642 m = gfc_match_expr (&expr);
2644 gfc_error ("Expected expression in %s statement at %C",
2652 if (expr->symtree->n.sym->attr.intent == INTENT_IN)
2654 gfc_error ("Variable '%s' in input list at %C cannot be "
2655 "INTENT(IN)", expr->symtree->n.sym->name);
2660 && gfc_impure_variable (expr->symtree->n.sym)
2661 && current_dt->io_unit->ts.type == BT_CHARACTER)
2663 gfc_error ("Cannot read to variable '%s' in PURE procedure at %C",
2664 expr->symtree->n.sym->name);
2668 if (gfc_check_do_variable (expr->symtree))
2674 if (current_dt->io_unit->ts.type == BT_CHARACTER
2676 && current_dt->io_unit->expr_type == EXPR_VARIABLE
2677 && gfc_impure_variable (current_dt->io_unit->symtree->n.sym))
2679 gfc_error ("Cannot write to internal file unit '%s' at %C "
2680 "inside a PURE procedure",
2681 current_dt->io_unit->symtree->n.sym->name);
2693 gfc_free_expr (expr);
2697 cp = gfc_get_code ();
2698 cp->op = EXEC_TRANSFER;
2706 /* Match an I/O list, building gfc_code structures as we go. */
2709 match_io_list (io_kind k, gfc_code **head_p)
2711 gfc_code *head, *tail, *new;
2714 *head_p = head = tail = NULL;
2715 if (gfc_match_eos () == MATCH_YES)
2720 m = match_io_element (k, &new);
2721 if (m == MATCH_ERROR)
2726 tail = gfc_append_code (tail, new);
2730 if (gfc_match_eos () == MATCH_YES)
2732 if (gfc_match_char (',') != MATCH_YES)
2740 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
2743 gfc_free_statements (head);
2748 /* Attach the data transfer end node. */
2751 terminate_io (gfc_code *io_code)
2755 if (io_code == NULL)
2756 io_code = new_st.block;
2758 c = gfc_get_code ();
2759 c->op = EXEC_DT_END;
2761 /* Point to structure that is already there */
2762 c->ext.dt = new_st.ext.dt;
2763 gfc_append_code (io_code, c);
2767 /* Check the constraints for a data transfer statement. The majority of the
2768 constraints appearing in 9.4 of the standard appear here. Some are handled
2769 in resolve_tag and others in gfc_resolve_dt. */
2772 check_io_constraints (io_kind k, gfc_dt *dt, gfc_code *io_code,
2775 #define io_constraint(condition,msg,arg)\
2778 gfc_error(msg,arg);\
2784 gfc_symbol *sym = NULL;
2785 bool warn, unformatted;
2787 warn = (dt->err || dt->iostat) ? true : false;
2788 unformatted = dt->format_expr == NULL && dt->format_label == NULL
2789 && dt->namelist == NULL;
2794 if (expr && expr->expr_type == EXPR_VARIABLE
2795 && expr->ts.type == BT_CHARACTER)
2797 sym = expr->symtree->n.sym;
2799 io_constraint (k == M_WRITE && sym->attr.intent == INTENT_IN,
2800 "Internal file at %L must not be INTENT(IN)",
2803 io_constraint (gfc_has_vector_index (dt->io_unit),
2804 "Internal file incompatible with vector subscript at %L",
2807 io_constraint (dt->rec != NULL,
2808 "REC tag at %L is incompatible with internal file",
2811 io_constraint (unformatted,
2812 "Unformatted I/O not allowed with internal unit at %L",
2813 &dt->io_unit->where);
2815 io_constraint (dt->asynchronous != NULL,
2816 "ASYNCHRONOUS tag at %L not allowed with internal file",
2817 &dt->asynchronous->where);
2819 if (dt->namelist != NULL)
2821 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Internal file "
2822 "at %L with namelist", &expr->where)
2827 io_constraint (dt->advance != NULL,
2828 "ADVANCE tag at %L is incompatible with internal file",
2829 &dt->advance->where);
2832 if (expr && expr->ts.type != BT_CHARACTER)
2835 io_constraint (gfc_pure (NULL) && (k == M_READ || k == M_WRITE),
2836 "IO UNIT in %s statement at %C must be "
2837 "an internal file in a PURE procedure",
2843 io_constraint (dt->end, "END tag not allowed with output at %L",
2846 io_constraint (dt->eor, "EOR tag not allowed with output at %L",
2849 io_constraint (dt->blank, "BLANK=specifier not allowed with output at %L",
2852 io_constraint (dt->pad, "PAD=specifier not allowed with output at %L",
2855 io_constraint (dt->size, "SIZE=specifier not allowed with output at %L",
2860 io_constraint (dt->size && dt->advance == NULL,
2861 "SIZE tag at %L requires an ADVANCE tag",
2864 io_constraint (dt->eor && dt->advance == NULL,
2865 "EOR tag at %L requires an ADVANCE tag",
2869 if (dt->asynchronous)
2871 static const char * asynchronous[] = { "YES", "NO", NULL };
2873 if (dt->asynchronous->expr_type != EXPR_CONSTANT)
2875 gfc_error ("ASYNCHRONOUS= specifier at %L must be an initialization "
2876 "expression", &dt->asynchronous->where);
2880 if (!compare_to_allowed_values
2881 ("ASYNCHRONOUS", asynchronous, NULL, NULL,
2882 dt->asynchronous->value.character.string,
2883 io_kind_name (k), warn))
2889 io_constraint (!dt->asynchronous
2890 || strcmp (dt->asynchronous->value.character.string,
2892 "ID=specifier at %L must be with ASYNCHRONOUS='yes' "
2893 "specifier", &dt->id->where);
2898 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DECIMAL= at %C "
2899 "not allowed in Fortran 95") == FAILURE)
2902 if (dt->decimal->expr_type == EXPR_CONSTANT)
2904 static const char * decimal[] = { "COMMA", "POINT", NULL };
2906 if (!compare_to_allowed_values ("DECIMAL", decimal, NULL, NULL,
2907 dt->decimal->value.character.string,
2908 io_kind_name (k), warn))
2911 io_constraint (unformatted,
2912 "the DECIMAL=specifier at %L must be with an "
2913 "explicit format expression", &dt->decimal->where);
2919 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: BLANK= at %C "
2920 "not allowed in Fortran 95") == FAILURE)
2923 if (dt->blank->expr_type == EXPR_CONSTANT)
2925 static const char * blank[] = { "NULL", "ZERO", NULL };
2927 if (!compare_to_allowed_values ("BLANK", blank, NULL, NULL,
2928 dt->blank->value.character.string,
2929 io_kind_name (k), warn))
2932 io_constraint (unformatted,
2933 "the BLANK=specifier at %L must be with an "
2934 "explicit format expression", &dt->blank->where);
2940 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: PAD= at %C "
2941 "not allowed in Fortran 95") == FAILURE)
2944 if (dt->pad->expr_type == EXPR_CONSTANT)
2946 static const char * pad[] = { "YES", "NO", NULL };
2948 if (!compare_to_allowed_values ("PAD", pad, NULL, NULL,
2949 dt->pad->value.character.string,
2950 io_kind_name (k), warn))
2953 io_constraint (unformatted,
2954 "the PAD=specifier at %L must be with an "
2955 "explicit format expression", &dt->pad->where);
2961 /* When implemented, change the following to use gfc_notify_std F2003.
2962 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ROUND= at %C "
2963 "not allowed in Fortran 95") == FAILURE)
2964 return MATCH_ERROR; */
2965 gfc_error ("F2003 Feature: ROUND=specifier at %C not implemented");
2968 if (dt->round->expr_type == EXPR_CONSTANT)
2970 static const char * round[] = { "UP", "DOWN", "ZERO", "NEAREST",
2971 "COMPATIBLE", "PROCESSOR_DEFINED",
2974 if (!compare_to_allowed_values ("ROUND", round, NULL, NULL,
2975 dt->round->value.character.string,
2976 io_kind_name (k), warn))
2983 /* When implemented, change the following to use gfc_notify_std F2003.
2984 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: SIGN= at %C "
2985 "not allowed in Fortran 95") == FAILURE)
2986 return MATCH_ERROR; */
2987 if (dt->sign->expr_type == EXPR_CONSTANT)
2989 static const char * sign[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
2992 if (!compare_to_allowed_values ("SIGN", sign, NULL, NULL,
2993 dt->sign->value.character.string,
2994 io_kind_name (k), warn))
2997 io_constraint (unformatted,
2998 "SIGN=specifier at %L must be with an "
2999 "explicit format expression", &dt->sign->where);
3001 io_constraint (k == M_READ,
3002 "SIGN=specifier at %L not allowed in a "
3003 "READ statement", &dt->sign->where);
3009 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: DELIM= at %C "
3010 "not allowed in Fortran 95") == FAILURE)
3013 if (dt->delim->expr_type == EXPR_CONSTANT)
3015 static const char *delim[] = { "APOSTROPHE", "QUOTE", "NONE", NULL };
3017 if (!compare_to_allowed_values ("DELIM", delim, NULL, NULL,
3018 dt->delim->value.character.string,
3019 io_kind_name (k), warn))
3022 io_constraint (k == M_READ,
3023 "DELIM=specifier at %L not allowed in a "
3024 "READ statement", &dt->delim->where);
3026 io_constraint (dt->format_label != &format_asterisk
3027 && dt->namelist == NULL,
3028 "DELIM=specifier at %L must have FMT=*",
3031 io_constraint (unformatted && dt->namelist == NULL,
3032 "DELIM=specifier at %L must be with FMT=* or "
3033 "NML=specifier ", &dt->delim->where);
3039 io_constraint (io_code && dt->namelist,
3040 "NAMELIST cannot be followed by IO-list at %L",
3043 io_constraint (dt->format_expr,
3044 "IO spec-list cannot contain both NAMELIST group name "
3045 "and format specification at %L.",
3046 &dt->format_expr->where);
3048 io_constraint (dt->format_label,
3049 "IO spec-list cannot contain both NAMELIST group name "
3050 "and format label at %L", spec_end);
3052 io_constraint (dt->rec,
3053 "NAMELIST IO is not allowed with a REC=specifier "
3054 "at %L.", &dt->rec->where);
3056 io_constraint (dt->advance,
3057 "NAMELIST IO is not allowed with a ADVANCE=specifier "
3058 "at %L.", &dt->advance->where);
3063 io_constraint (dt->end,
3064 "An END tag is not allowed with a "
3065 "REC=specifier at %L.", &dt->end_where);
3067 io_constraint (dt->format_label == &format_asterisk,
3068 "FMT=* is not allowed with a REC=specifier "
3069 "at %L.", spec_end);
3074 int not_yes, not_no;
3077 io_constraint (dt->format_label == &format_asterisk,
3078 "List directed format(*) is not allowed with a "
3079 "ADVANCE=specifier at %L.", &expr->where);
3081 io_constraint (unformatted,
3082 "the ADVANCE=specifier at %L must appear with an "
3083 "explicit format expression", &expr->where);
3085 if (expr->expr_type == EXPR_CONSTANT && expr->ts.type == BT_CHARACTER)
3087 const char * advance = expr->value.character.string;
3088 not_no = strcasecmp (advance, "no") != 0;
3089 not_yes = strcasecmp (advance, "yes") != 0;
3097 io_constraint (not_no && not_yes,
3098 "ADVANCE=specifier at %L must have value = "
3099 "YES or NO.", &expr->where);
3101 io_constraint (dt->size && not_no && k == M_READ,
3102 "SIZE tag at %L requires an ADVANCE = 'NO'",
3105 io_constraint (dt->eor && not_no && k == M_READ,
3106 "EOR tag at %L requires an ADVANCE = 'NO'",
3110 expr = dt->format_expr;
3111 if (gfc_simplify_expr (expr, 0) == FAILURE
3112 || check_format_string (expr, k == M_READ) == FAILURE)
3117 #undef io_constraint
3120 /* Match a READ, WRITE or PRINT statement. */
3123 match_io (io_kind k)
3125 char name[GFC_MAX_SYMBOL_LEN + 1];
3134 where = gfc_current_locus;
3136 current_dt = dt = gfc_getmem (sizeof (gfc_dt));
3137 m = gfc_match_char ('(');
3140 where = gfc_current_locus;
3143 else if (k == M_PRINT)
3145 /* Treat the non-standard case of PRINT namelist. */
3146 if ((gfc_current_form == FORM_FIXED || gfc_peek_char () == ' ')
3147 && gfc_match_name (name) == MATCH_YES)
3149 gfc_find_symbol (name, NULL, 1, &sym);
3150 if (sym && sym->attr.flavor == FL_NAMELIST)
3152 if (gfc_notify_std (GFC_STD_GNU, "PRINT namelist at "
3153 "%C is an extension") == FAILURE)
3159 dt->io_unit = default_unit (k);
3164 gfc_current_locus = where;
3168 if (gfc_current_form == FORM_FREE)
3170 c = gfc_peek_char();
3171 if (c != ' ' && c != '*' && c != '\'' && c != '"')
3178 m = match_dt_format (dt);
3179 if (m == MATCH_ERROR)
3185 dt->io_unit = default_unit (k);
3190 /* Before issuing an error for a malformed 'print (1,*)' type of
3191 error, check for a default-char-expr of the form ('(I0)'). */
3192 if (k == M_PRINT && m == MATCH_YES)
3194 /* Reset current locus to get the initial '(' in an expression. */
3195 gfc_current_locus = where;
3196 dt->format_expr = NULL;
3197 m = match_dt_format (dt);
3199 if (m == MATCH_ERROR)
3201 if (m == MATCH_NO || dt->format_expr == NULL)
3205 dt->io_unit = default_unit (k);
3210 /* Match a control list */
3211 if (match_dt_element (k, dt) == MATCH_YES)
3213 if (match_dt_unit (k, dt) != MATCH_YES)
3216 if (gfc_match_char (')') == MATCH_YES)
3218 if (gfc_match_char (',') != MATCH_YES)
3221 m = match_dt_element (k, dt);
3224 if (m == MATCH_ERROR)
3227 m = match_dt_format (dt);
3230 if (m == MATCH_ERROR)
3233 where = gfc_current_locus;
3235 m = gfc_match_name (name);
3238 gfc_find_symbol (name, NULL, 1, &sym);
3239 if (sym && sym->attr.flavor == FL_NAMELIST)
3242 if (k == M_READ && check_namelist (sym))
3251 gfc_current_locus = where;
3253 goto loop; /* No matches, try regular elements */
3256 if (gfc_match_char (')') == MATCH_YES)
3258 if (gfc_match_char (',') != MATCH_YES)
3264 m = match_dt_element (k, dt);
3267 if (m == MATCH_ERROR)
3270 if (gfc_match_char (')') == MATCH_YES)
3272 if (gfc_match_char (',') != MATCH_YES)
3278 /* Used in check_io_constraints, where no locus is available. */
3279 spec_end = gfc_current_locus;
3281 /* Optional leading comma (non-standard). */
3283 && gfc_match_char (',') == MATCH_YES
3284 && gfc_notify_std (GFC_STD_GNU, "Extension: Comma before i/o "
3285 "item list at %C") == FAILURE)
3289 if (gfc_match_eos () != MATCH_YES)
3291 if (comma_flag && gfc_match_char (',') != MATCH_YES)
3293 gfc_error ("Expected comma in I/O list at %C");
3298 m = match_io_list (k, &io_code);
3299 if (m == MATCH_ERROR)
3305 /* A full IO statement has been matched. Check the constraints. spec_end is
3306 supplied for cases where no locus is supplied. */
3307 m = check_io_constraints (k, dt, io_code, &spec_end);
3309 if (m == MATCH_ERROR)
3312 new_st.op = (k == M_READ) ? EXEC_READ : EXEC_WRITE;
3314 new_st.block = gfc_get_code ();
3315 new_st.block->op = new_st.op;
3316 new_st.block->next = io_code;
3318 terminate_io (io_code);
3323 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
3333 gfc_match_read (void)
3335 return match_io (M_READ);
3340 gfc_match_write (void)
3342 return match_io (M_WRITE);
3347 gfc_match_print (void)
3351 m = match_io (M_PRINT);
3355 if (gfc_pure (NULL))
3357 gfc_error ("PRINT statement at %C not allowed within PURE procedure");
3365 /* Free a gfc_inquire structure. */
3368 gfc_free_inquire (gfc_inquire *inquire)
3371 if (inquire == NULL)
3374 gfc_free_expr (inquire->unit);
3375 gfc_free_expr (inquire->file);
3376 gfc_free_expr (inquire->iomsg);
3377 gfc_free_expr (inquire->iostat);
3378 gfc_free_expr (inquire->exist);
3379 gfc_free_expr (inquire->opened);
3380 gfc_free_expr (inquire->number);
3381 gfc_free_expr (inquire->named);
3382 gfc_free_expr (inquire->name);
3383 gfc_free_expr (inquire->access);
3384 gfc_free_expr (inquire->sequential);
3385 gfc_free_expr (inquire->direct);
3386 gfc_free_expr (inquire->form);
3387 gfc_free_expr (inquire->formatted);
3388 gfc_free_expr (inquire->unformatted);
3389 gfc_free_expr (inquire->recl);
3390 gfc_free_expr (inquire->nextrec);
3391 gfc_free_expr (inquire->blank);
3392 gfc_free_expr (inquire->position);
3393 gfc_free_expr (inquire->action);
3394 gfc_free_expr (inquire->read);
3395 gfc_free_expr (inquire->write);
3396 gfc_free_expr (inquire->readwrite);
3397 gfc_free_expr (inquire->delim);
3398 gfc_free_expr (inquire->pad);
3399 gfc_free_expr (inquire->iolength);
3400 gfc_free_expr (inquire->convert);
3401 gfc_free_expr (inquire->strm_pos);
3406 /* Match an element of an INQUIRE statement. */
3408 #define RETM if (m != MATCH_NO) return m;
3411 match_inquire_element (gfc_inquire *inquire)
3415 m = match_etag (&tag_unit, &inquire->unit);
3416 RETM m = match_etag (&tag_file, &inquire->file);
3417 RETM m = match_ltag (&tag_err, &inquire->err);
3418 RETM m = match_out_tag (&tag_iomsg, &inquire->iomsg);
3419 RETM m = match_out_tag (&tag_iostat, &inquire->iostat);
3420 RETM m = match_vtag (&tag_exist, &inquire->exist);
3421 RETM m = match_vtag (&tag_opened, &inquire->opened);
3422 RETM m = match_vtag (&tag_named, &inquire->named);
3423 RETM m = match_vtag (&tag_name, &inquire->name);
3424 RETM m = match_out_tag (&tag_number, &inquire->number);
3425 RETM m = match_vtag (&tag_s_access, &inquire->access);
3426 RETM m = match_vtag (&tag_sequential, &inquire->sequential);
3427 RETM m = match_vtag (&tag_direct, &inquire->direct);
3428 RETM m = match_vtag (&tag_s_form, &inquire->form);
3429 RETM m = match_vtag (&tag_formatted, &inquire->formatted);
3430 RETM m = match_vtag (&tag_unformatted, &inquire->unformatted);
3431 RETM m = match_out_tag (&tag_s_recl, &inquire->recl);
3432 RETM m = match_out_tag (&tag_nextrec, &inquire->nextrec);
3433 RETM m = match_vtag (&tag_s_blank, &inquire->blank);
3434 RETM m = match_vtag (&tag_s_position, &inquire->position);
3435 RETM m = match_vtag (&tag_s_action, &inquire->action);
3436 RETM m = match_vtag (&tag_read, &inquire->read);
3437 RETM m = match_vtag (&tag_write, &inquire->write);
3438 RETM m = match_vtag (&tag_readwrite, &inquire->readwrite);
3439 RETM m = match_vtag (&tag_s_delim, &inquire->delim);
3440 RETM m = match_vtag (&tag_s_pad, &inquire->pad);
3441 RETM m = match_vtag (&tag_iolength, &inquire->iolength);
3442 RETM m = match_vtag (&tag_convert, &inquire->convert);
3443 RETM m = match_out_tag (&tag_strm_out, &inquire->strm_pos);
3444 RETM return MATCH_NO;
3451 gfc_match_inquire (void)
3453 gfc_inquire *inquire;
3458 m = gfc_match_char ('(');
3462 inquire = gfc_getmem (sizeof (gfc_inquire));
3464 loc = gfc_current_locus;
3466 m = match_inquire_element (inquire);
3467 if (m == MATCH_ERROR)
3471 m = gfc_match_expr (&inquire->unit);
3472 if (m == MATCH_ERROR)
3478 /* See if we have the IOLENGTH form of the inquire statement. */
3479 if (inquire->iolength != NULL)
3481 if (gfc_match_char (')') != MATCH_YES)
3484 m = match_io_list (M_INQUIRE, &code);
3485 if (m == MATCH_ERROR)
3490 new_st.op = EXEC_IOLENGTH;
3491 new_st.expr = inquire->iolength;
3492 new_st.ext.inquire = inquire;
3494 if (gfc_pure (NULL))
3496 gfc_free_statements (code);
3497 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
3501 new_st.block = gfc_get_code ();
3502 new_st.block->op = EXEC_IOLENGTH;
3503 terminate_io (code);
3504 new_st.block->next = code;
3508 /* At this point, we have the non-IOLENGTH inquire statement. */
3511 if (gfc_match_char (')') == MATCH_YES)
3513 if (gfc_match_char (',') != MATCH_YES)
3516 m = match_inquire_element (inquire);
3517 if (m == MATCH_ERROR)
3522 if (inquire->iolength != NULL)
3524 gfc_error ("IOLENGTH tag invalid in INQUIRE statement at %C");
3529 if (gfc_match_eos () != MATCH_YES)
3532 if (inquire->unit != NULL && inquire->file != NULL)
3534 gfc_error ("INQUIRE statement at %L cannot contain both FILE and "
3535 "UNIT specifiers", &loc);
3539 if (inquire->unit == NULL && inquire->file == NULL)
3541 gfc_error ("INQUIRE statement at %L requires either FILE or "
3542 "UNIT specifier", &loc);
3546 if (gfc_pure (NULL))
3548 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
3552 new_st.op = EXEC_INQUIRE;
3553 new_st.ext.inquire = inquire;
3557 gfc_syntax_error (ST_INQUIRE);
3560 gfc_free_inquire (inquire);
3565 /* Resolve everything in a gfc_inquire structure. */
3568 gfc_resolve_inquire (gfc_inquire *inquire)
3570 RESOLVE_TAG (&tag_unit, inquire->unit);
3571 RESOLVE_TAG (&tag_file, inquire->file);
3572 RESOLVE_TAG (&tag_iomsg, inquire->iomsg);
3573 RESOLVE_TAG (&tag_iostat, inquire->iostat);
3574 RESOLVE_TAG (&tag_exist, inquire->exist);
3575 RESOLVE_TAG (&tag_opened, inquire->opened);
3576 RESOLVE_TAG (&tag_number, inquire->number);
3577 RESOLVE_TAG (&tag_named, inquire->named);
3578 RESOLVE_TAG (&tag_name, inquire->name);
3579 RESOLVE_TAG (&tag_s_access, inquire->access);
3580 RESOLVE_TAG (&tag_sequential, inquire->sequential);
3581 RESOLVE_TAG (&tag_direct, inquire->direct);
3582 RESOLVE_TAG (&tag_s_form, inquire->form);
3583 RESOLVE_TAG (&tag_formatted, inquire->formatted);
3584 RESOLVE_TAG (&tag_unformatted, inquire->unformatted);
3585 RESOLVE_TAG (&tag_s_recl, inquire->recl);
3586 RESOLVE_TAG (&tag_nextrec, inquire->nextrec);
3587 RESOLVE_TAG (&tag_s_blank, inquire->blank);
3588 RESOLVE_TAG (&tag_s_position, inquire->position);
3589 RESOLVE_TAG (&tag_s_action, inquire->action);
3590 RESOLVE_TAG (&tag_read, inquire->read);
3591 RESOLVE_TAG (&tag_write, inquire->write);
3592 RESOLVE_TAG (&tag_readwrite, inquire->readwrite);
3593 RESOLVE_TAG (&tag_s_delim, inquire->delim);
3594 RESOLVE_TAG (&tag_s_pad, inquire->pad);
3595 RESOLVE_TAG (&tag_iolength, inquire->iolength);
3596 RESOLVE_TAG (&tag_convert, inquire->convert);
3597 RESOLVE_TAG (&tag_strm_out, inquire->strm_pos);
3599 if (gfc_reference_st_label (inquire->err, ST_LABEL_TARGET) == FAILURE)
3607 gfc_free_wait (gfc_wait *wait)
3612 gfc_free_expr (wait->unit);
3613 gfc_free_expr (wait->iostat);
3614 gfc_free_expr (wait->iomsg);
3615 gfc_free_expr (wait->id);
3620 gfc_resolve_wait (gfc_wait *wait)
3622 RESOLVE_TAG (&tag_unit, wait->unit);
3623 RESOLVE_TAG (&tag_iomsg, wait->iomsg);
3624 RESOLVE_TAG (&tag_iostat, wait->iostat);
3625 RESOLVE_TAG (&tag_id, wait->id);
3627 if (gfc_reference_st_label (wait->err, ST_LABEL_TARGET) == FAILURE)
3630 if (gfc_reference_st_label (wait->end, ST_LABEL_TARGET) == FAILURE)
3636 /* Match an element of a WAIT statement. */
3638 #define RETM if (m != MATCH_NO) return m;
3641 match_wait_element (gfc_wait *wait)
3645 m = match_etag (&tag_unit, &wait->unit);
3646 RETM m = match_ltag (&tag_err, &wait->err);
3647 RETM m = match_ltag (&tag_end, &wait->eor);
3648 RETM m = match_ltag (&tag_eor, &wait->end);
3649 RETM m = match_out_tag (&tag_iomsg, &wait->iomsg);
3650 RETM m = match_out_tag (&tag_iostat, &wait->iostat);
3651 RETM m = match_etag (&tag_id, &wait->id);
3652 RETM return MATCH_NO;
3659 gfc_match_wait (void)
3665 m = gfc_match_char ('(');
3669 wait = gfc_getmem (sizeof (gfc_wait));
3671 loc = gfc_current_locus;
3673 m = match_wait_element (wait);
3674 if (m == MATCH_ERROR)
3678 m = gfc_match_expr (&wait->unit);
3679 if (m == MATCH_ERROR)
3687 if (gfc_match_char (')') == MATCH_YES)
3689 if (gfc_match_char (',') != MATCH_YES)
3692 m = match_wait_element (wait);
3693 if (m == MATCH_ERROR)
3699 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: WAIT at %C "
3700 "not allowed in Fortran 95") == FAILURE)
3703 if (gfc_pure (NULL))
3705 gfc_error ("WAIT statement not allowed in PURE procedure at %C");
3709 new_st.op = EXEC_WAIT;
3710 new_st.ext.wait = wait;
3715 gfc_syntax_error (ST_WAIT);
3718 gfc_free_wait (wait);