1 /* Deal with I/O statements & related stuff.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
30 gfc_st_label format_asterisk =
31 {0, NULL, NULL, -1, ST_LABEL_FORMAT, ST_LABEL_FORMAT, NULL,
36 const char *name, *spec;
42 tag_file = { "FILE", " file = %e", BT_CHARACTER },
43 tag_status = { "STATUS", " status = %e", BT_CHARACTER},
44 tag_e_access = {"ACCESS", " access = %e", BT_CHARACTER},
45 tag_e_form = {"FORM", " form = %e", BT_CHARACTER},
46 tag_e_recl = {"RECL", " recl = %e", BT_INTEGER},
47 tag_e_blank = {"BLANK", " blank = %e", BT_CHARACTER},
48 tag_e_position = {"POSITION", " position = %e", BT_CHARACTER},
49 tag_e_action = {"ACTION", " action = %e", BT_CHARACTER},
50 tag_e_delim = {"DELIM", " delim = %e", BT_CHARACTER},
51 tag_e_pad = {"PAD", " pad = %e", BT_CHARACTER},
52 tag_unit = {"UNIT", " unit = %e", BT_INTEGER},
53 tag_advance = {"ADVANCE", " advance = %e", BT_CHARACTER},
54 tag_rec = {"REC", " rec = %e", BT_INTEGER},
55 tag_format = {"FORMAT", NULL, BT_CHARACTER},
56 tag_iomsg = {"IOMSG", " iomsg = %e", BT_CHARACTER},
57 tag_iostat = {"IOSTAT", " iostat = %v", BT_INTEGER},
58 tag_size = {"SIZE", " size = %v", BT_INTEGER},
59 tag_exist = {"EXIST", " exist = %v", BT_LOGICAL},
60 tag_opened = {"OPENED", " opened = %v", BT_LOGICAL},
61 tag_named = {"NAMED", " named = %v", BT_LOGICAL},
62 tag_name = {"NAME", " name = %v", BT_CHARACTER},
63 tag_number = {"NUMBER", " number = %v", BT_INTEGER},
64 tag_s_access = {"ACCESS", " access = %v", BT_CHARACTER},
65 tag_sequential = {"SEQUENTIAL", " sequential = %v", BT_CHARACTER},
66 tag_direct = {"DIRECT", " direct = %v", BT_CHARACTER},
67 tag_s_form = {"FORM", " form = %v", BT_CHARACTER},
68 tag_formatted = {"FORMATTED", " formatted = %v", BT_CHARACTER},
69 tag_unformatted = {"UNFORMATTED", " unformatted = %v", BT_CHARACTER},
70 tag_s_recl = {"RECL", " recl = %v", BT_INTEGER},
71 tag_nextrec = {"NEXTREC", " nextrec = %v", BT_INTEGER},
72 tag_s_blank = {"BLANK", " blank = %v", BT_CHARACTER},
73 tag_s_position = {"POSITION", " position = %v", BT_CHARACTER},
74 tag_s_action = {"ACTION", " action = %v", BT_CHARACTER},
75 tag_read = {"READ", " read = %v", BT_CHARACTER},
76 tag_write = {"WRITE", " write = %v", BT_CHARACTER},
77 tag_readwrite = {"READWRITE", " readwrite = %v", BT_CHARACTER},
78 tag_s_delim = {"DELIM", " delim = %v", BT_CHARACTER},
79 tag_s_pad = {"PAD", " pad = %v", BT_CHARACTER},
80 tag_iolength = {"IOLENGTH", " iolength = %v", BT_INTEGER},
81 tag_convert = {"CONVERT", " convert = %e", BT_CHARACTER},
82 tag_err = {"ERR", " err = %l", BT_UNKNOWN},
83 tag_end = {"END", " end = %l", BT_UNKNOWN},
84 tag_eor = {"EOR", " eor = %l", BT_UNKNOWN};
86 static gfc_dt *current_dt;
88 #define RESOLVE_TAG(x, y) if (resolve_tag(x, y) == FAILURE) return FAILURE;
91 /**************** Fortran 95 FORMAT parser *****************/
93 /* FORMAT tokens returned by format_lex(). */
96 FMT_NONE, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
97 FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_POS, FMT_LPAREN,
98 FMT_RPAREN, FMT_X, FMT_SIGN, FMT_BLANK, FMT_CHAR, FMT_P, FMT_IBOZ, FMT_F,
99 FMT_E, FMT_EXT, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END
103 /* Local variables for checking format strings. The saved_token is
104 used to back up by a single format token during the parsing
106 static char *format_string;
107 static int format_length, use_last_char;
109 static format_token saved_token;
112 { MODE_STRING, MODE_FORMAT, MODE_COPY }
116 /* Return the next character in the format string. */
119 next_char (int in_string)
131 if (mode == MODE_STRING)
132 c = *format_string++;
135 c = gfc_next_char_literal (in_string);
139 if (mode == MODE_COPY)
140 *format_string++ = c;
148 /* Back up one character position. Only works once. */
157 /* Eat up the spaces and return a character. */
160 next_char_not_space(void)
167 while (gfc_is_whitespace (c));
171 static int value = 0;
173 /* Simple lexical analyzer for getting the next token in a FORMAT
184 if (saved_token != FMT_NONE)
187 saved_token = FMT_NONE;
191 c = next_char_not_space ();
199 c = next_char_not_space ();
210 c = next_char_not_space ();
212 value = 10 * value + c - '0';
221 token = FMT_SIGNED_INT;
240 c = next_char_not_space ();
244 value = 10 * value + c - '0';
249 token = zflag ? FMT_ZERO : FMT_POSINT;
273 c = next_char_not_space ();
274 if (c != 'L' && c != 'R')
293 c = next_char_not_space ();
294 if (c != 'P' && c != 'S')
301 c = next_char_not_space ();
302 if (c == 'N' || c == 'Z')
363 c = next_char_not_space ();
364 if (c == 'N' || c == 'S')
407 /* Check a format statement. The format string, either from a FORMAT
408 statement or a constant in an I/O statement has already been parsed
409 by itself, and we are checking it for validity. The dual origin
410 means that the warning message is a little less than great. */
415 const char *posint_required = _("Positive width required");
416 const char *nonneg_required = _("Nonnegative width required");
417 const char *unexpected_element = _("Unexpected element");
418 const char *unexpected_end = _("Unexpected end of format string");
427 saved_token = FMT_NONE;
435 error = _("Missing leading left parenthesis");
441 goto finished; /* Empty format is legal */
445 /* In this state, the next thing has to be a format item. */
469 /* Signed integer can only precede a P format. */
473 error = _("Expected P edit descriptor");
480 /* P requires a prior number. */
481 error = _("P descriptor requires leading scale factor");
485 /* X requires a prior number if we're being pedantic. */
486 if (gfc_notify_std (GFC_STD_GNU, "Extension: X descriptor "
487 "requires leading space count at %C")
497 goto extension_optional_comma;
506 if (gfc_notify_std (GFC_STD_GNU, "Extension: $ descriptor at %C")
509 if (t != FMT_RPAREN || level > 0)
511 error = _("$ must be the last specifier");
532 error = unexpected_end;
536 error = unexpected_element;
541 /* In this state, t must currently be a data descriptor.
542 Deal with things that can/must follow the descriptor. */
556 error = _("Repeat count cannot follow P descriptor");
571 switch (gfc_notification_std (GFC_STD_GNU))
575 ("Extension: Missing positive width after L descriptor at %C");
580 error = posint_required;
605 error = posint_required;
612 /* Warn if -std=legacy, otherwise error. */
613 if (gfc_option.warn_std != 0)
614 gfc_error_now ("Period required in format specifier at %C");
616 gfc_warning ("Period required in format specifier at %C");
622 if (u != FMT_ZERO && u != FMT_POSINT)
624 error = nonneg_required;
631 /* Look for optional exponent. */
642 error = _("Positive exponent width required");
651 if (t != FMT_ZERO && t != FMT_POSINT)
653 error = nonneg_required;
660 /* Warn if -std=legacy, otherwise error. */
661 if (gfc_option.warn_std != 0)
662 gfc_error_now ("Period required in format specifier at %C");
664 gfc_warning ("Period required in format specifier at %C");
670 if (t != FMT_ZERO && t != FMT_POSINT)
672 error = nonneg_required;
679 if(mode == MODE_STRING)
681 format_string += value;
682 format_length -= value;
696 if (t != FMT_ZERO && t != FMT_POSINT)
698 error = nonneg_required;
710 if (t != FMT_ZERO && t != FMT_POSINT)
712 error = nonneg_required;
720 error = unexpected_element;
725 /* Between a descriptor and what comes next. */
744 error = unexpected_end;
748 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
755 /* Optional comma is a weird between state where we've just finished
756 reading a colon, slash or P descriptor. */
770 /* Assume that we have another format item. */
777 extension_optional_comma:
778 /* As a GNU extension, permit a missing comma after a string literal. */
796 error = unexpected_end;
800 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
810 /* Something went wrong. If the format we're checking is a string,
811 generate a warning, since the program is correct. If the format
812 is in a FORMAT statement, this messes up parsing, which is an
814 if (mode != MODE_STRING)
815 gfc_error ("%s in format string at %C", error);
818 gfc_warning ("%s in format string at %C", error);
820 /* TODO: More elaborate measures are needed to show where a problem
821 is within a format string that has been calculated. */
831 /* Given an expression node that is a constant string, see if it looks
832 like a format string. */
835 check_format_string (gfc_expr * e)
839 format_string = e->value.character.string;
844 /************ Fortran 95 I/O statement matchers *************/
846 /* Match a FORMAT statement. This amounts to actually parsing the
847 format descriptors in order to correctly locate the end of the
851 gfc_match_format (void)
856 if (gfc_current_ns->proc_name
857 && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
859 gfc_error ("Format statement in module main block at %C.");
863 if (gfc_statement_label == NULL)
865 gfc_error ("Missing format label at %C");
868 gfc_gobble_whitespace ();
873 start = gfc_current_locus;
875 if (check_format () == FAILURE)
878 if (gfc_match_eos () != MATCH_YES)
880 gfc_syntax_error (ST_FORMAT);
884 /* The label doesn't get created until after the statement is done
885 being matched, so we have to leave the string for later. */
887 gfc_current_locus = start; /* Back to the beginning */
890 new_st.op = EXEC_NOP;
893 e->expr_type = EXPR_CONSTANT;
894 e->ts.type = BT_CHARACTER;
895 e->ts.kind = gfc_default_character_kind;
897 e->value.character.string = format_string = gfc_getmem(format_length+1);
898 e->value.character.length = format_length;
899 gfc_statement_label->format = e;
902 check_format (); /* Guaranteed to succeed */
903 gfc_match_eos (); /* Guaranteed to succeed */
909 /* Match an expression I/O tag of some sort. */
912 match_etag (const io_tag * tag, gfc_expr ** v)
917 m = gfc_match (tag->spec, &result);
923 gfc_error ("Duplicate %s specification at %C", tag->name);
924 gfc_free_expr (result);
933 /* Match a variable I/O tag of some sort. */
936 match_vtag (const io_tag * tag, gfc_expr ** v)
941 m = gfc_match (tag->spec, &result);
947 gfc_error ("Duplicate %s specification at %C", tag->name);
948 gfc_free_expr (result);
952 if (result->symtree->n.sym->attr.intent == INTENT_IN)
954 gfc_error ("Variable tag cannot be INTENT(IN) at %C");
955 gfc_free_expr (result);
959 if (gfc_pure (NULL) && gfc_impure_variable (result->symtree->n.sym))
961 gfc_error ("Variable tag cannot be assigned in PURE procedure at %C");
962 gfc_free_expr (result);
971 /* Match I/O tags that cause variables to become redefined. */
974 match_out_tag(const io_tag *tag, gfc_expr **result)
978 m = match_vtag(tag, result);
980 gfc_check_do_variable((*result)->symtree);
986 /* Match a label I/O tag. */
989 match_ltag (const io_tag * tag, gfc_st_label ** label)
995 m = gfc_match (tag->spec, label);
996 if (m == MATCH_YES && old != 0)
998 gfc_error ("Duplicate %s label specification at %C", tag->name);
1003 && gfc_reference_st_label (*label, ST_LABEL_TARGET) == FAILURE)
1010 /* Do expression resolution and type-checking on an expression tag. */
1013 resolve_tag (const io_tag * tag, gfc_expr * e)
1019 if (gfc_resolve_expr (e) == FAILURE)
1022 if (e->ts.type != tag->type && tag != &tag_format)
1024 gfc_error ("%s tag at %L must be of type %s", tag->name,
1025 &e->where, gfc_basic_typename (tag->type));
1029 if (tag == &tag_format)
1031 if (e->expr_type == EXPR_CONSTANT
1032 && (e->ts.type != BT_CHARACTER
1033 || e->ts.kind != gfc_default_character_kind))
1035 gfc_error ("Constant expression in FORMAT tag at %L must be "
1036 "of type default CHARACTER", &e->where);
1040 /* If e's rank is zero and e is not an element of an array, it should be
1041 of integer or character type. The integer variable should be
1043 if (e->symtree == NULL || e->symtree->n.sym->as == NULL
1044 || e->symtree->n.sym->as->rank == 0)
1046 if (e->ts.type != BT_CHARACTER && e->ts.type != BT_INTEGER)
1048 gfc_error ("%s tag at %L must be of type %s or %s", tag->name,
1049 &e->where, gfc_basic_typename (BT_CHARACTER),
1050 gfc_basic_typename (BT_INTEGER));
1053 else if (e->ts.type == BT_INTEGER && e->expr_type == EXPR_VARIABLE)
1055 if (gfc_notify_std (GFC_STD_F95_DEL,
1056 "Obsolete: ASSIGNED variable in FORMAT tag at %L",
1057 &e->where) == FAILURE)
1059 if (e->symtree->n.sym->attr.assign != 1)
1061 gfc_error ("Variable '%s' at %L has not been assigned a "
1062 "format label", e->symtree->n.sym->name, &e->where);
1066 else if (e->ts.type == BT_INTEGER)
1068 gfc_error ("scalar '%s' FORMAT tag at %L is not an ASSIGNED "
1069 "variable", gfc_basic_typename (e->ts.type), &e->where);
1077 /* if rank is nonzero, we allow the type to be character under
1078 GFC_STD_GNU and other type under GFC_STD_LEGACY. It may be
1079 assigned an Hollerith constant. */
1080 if (e->ts.type == BT_CHARACTER)
1082 if (gfc_notify_std (GFC_STD_GNU,
1083 "Extension: Character array in FORMAT tag at %L",
1084 &e->where) == FAILURE)
1089 if (gfc_notify_std (GFC_STD_LEGACY,
1090 "Extension: Non-character in FORMAT tag at %L",
1091 &e->where) == FAILURE)
1101 gfc_error ("%s tag at %L must be scalar", tag->name, &e->where);
1105 if (tag == &tag_iomsg)
1107 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: IOMSG tag at %L",
1108 &e->where) == FAILURE)
1112 if (tag == &tag_iostat && e->ts.kind != gfc_default_integer_kind)
1114 if (gfc_notify_std (GFC_STD_GNU, "Fortran 95 requires default "
1115 "INTEGER in IOSTAT tag at %L",
1116 &e->where) == FAILURE)
1120 if (tag == &tag_size && e->ts.kind != gfc_default_integer_kind)
1122 if (gfc_notify_std (GFC_STD_GNU, "Fortran 95 requires default "
1123 "INTEGER in SIZE tag at %L",
1124 &e->where) == FAILURE)
1128 if (tag == &tag_convert)
1130 if (gfc_notify_std (GFC_STD_GNU, "Extension: CONVERT tag at %L",
1131 &e->where) == FAILURE)
1140 /* Match a single tag of an OPEN statement. */
1143 match_open_element (gfc_open * open)
1147 m = match_etag (&tag_unit, &open->unit);
1150 m = match_out_tag (&tag_iomsg, &open->iomsg);
1153 m = match_out_tag (&tag_iostat, &open->iostat);
1156 m = match_etag (&tag_file, &open->file);
1159 m = match_etag (&tag_status, &open->status);
1162 m = match_etag (&tag_e_access, &open->access);
1165 m = match_etag (&tag_e_form, &open->form);
1168 m = match_etag (&tag_e_recl, &open->recl);
1171 m = match_etag (&tag_e_blank, &open->blank);
1174 m = match_etag (&tag_e_position, &open->position);
1177 m = match_etag (&tag_e_action, &open->action);
1180 m = match_etag (&tag_e_delim, &open->delim);
1183 m = match_etag (&tag_e_pad, &open->pad);
1186 m = match_ltag (&tag_err, &open->err);
1189 m = match_etag (&tag_convert, &open->convert);
1197 /* Free the gfc_open structure and all the expressions it contains. */
1200 gfc_free_open (gfc_open * open)
1206 gfc_free_expr (open->unit);
1207 gfc_free_expr (open->iomsg);
1208 gfc_free_expr (open->iostat);
1209 gfc_free_expr (open->file);
1210 gfc_free_expr (open->status);
1211 gfc_free_expr (open->access);
1212 gfc_free_expr (open->form);
1213 gfc_free_expr (open->recl);
1214 gfc_free_expr (open->blank);
1215 gfc_free_expr (open->position);
1216 gfc_free_expr (open->action);
1217 gfc_free_expr (open->delim);
1218 gfc_free_expr (open->pad);
1219 gfc_free_expr (open->convert);
1225 /* Resolve everything in a gfc_open structure. */
1228 gfc_resolve_open (gfc_open * open)
1231 RESOLVE_TAG (&tag_unit, open->unit);
1232 RESOLVE_TAG (&tag_iomsg, open->iomsg);
1233 RESOLVE_TAG (&tag_iostat, open->iostat);
1234 RESOLVE_TAG (&tag_file, open->file);
1235 RESOLVE_TAG (&tag_status, open->status);
1236 RESOLVE_TAG (&tag_e_access, open->access);
1237 RESOLVE_TAG (&tag_e_form, open->form);
1238 RESOLVE_TAG (&tag_e_recl, open->recl);
1240 RESOLVE_TAG (&tag_e_blank, open->blank);
1241 RESOLVE_TAG (&tag_e_position, open->position);
1242 RESOLVE_TAG (&tag_e_action, open->action);
1243 RESOLVE_TAG (&tag_e_delim, open->delim);
1244 RESOLVE_TAG (&tag_e_pad, open->pad);
1245 RESOLVE_TAG (&tag_convert, open->convert);
1247 if (gfc_reference_st_label (open->err, ST_LABEL_TARGET) == FAILURE)
1254 /* Match an OPEN statement. */
1257 gfc_match_open (void)
1262 m = gfc_match_char ('(');
1266 open = gfc_getmem (sizeof (gfc_open));
1268 m = match_open_element (open);
1270 if (m == MATCH_ERROR)
1274 m = gfc_match_expr (&open->unit);
1277 if (m == MATCH_ERROR)
1283 if (gfc_match_char (')') == MATCH_YES)
1285 if (gfc_match_char (',') != MATCH_YES)
1288 m = match_open_element (open);
1289 if (m == MATCH_ERROR)
1295 if (gfc_match_eos () == MATCH_NO)
1298 if (gfc_pure (NULL))
1300 gfc_error ("OPEN statement not allowed in PURE procedure at %C");
1304 new_st.op = EXEC_OPEN;
1305 new_st.ext.open = open;
1309 gfc_syntax_error (ST_OPEN);
1312 gfc_free_open (open);
1317 /* Free a gfc_close structure an all its expressions. */
1320 gfc_free_close (gfc_close * close)
1326 gfc_free_expr (close->unit);
1327 gfc_free_expr (close->iomsg);
1328 gfc_free_expr (close->iostat);
1329 gfc_free_expr (close->status);
1335 /* Match elements of a CLOSE statement. */
1338 match_close_element (gfc_close * close)
1342 m = match_etag (&tag_unit, &close->unit);
1345 m = match_etag (&tag_status, &close->status);
1348 m = match_out_tag (&tag_iomsg, &close->iomsg);
1351 m = match_out_tag (&tag_iostat, &close->iostat);
1354 m = match_ltag (&tag_err, &close->err);
1362 /* Match a CLOSE statement. */
1365 gfc_match_close (void)
1370 m = gfc_match_char ('(');
1374 close = gfc_getmem (sizeof (gfc_close));
1376 m = match_close_element (close);
1378 if (m == MATCH_ERROR)
1382 m = gfc_match_expr (&close->unit);
1385 if (m == MATCH_ERROR)
1391 if (gfc_match_char (')') == MATCH_YES)
1393 if (gfc_match_char (',') != MATCH_YES)
1396 m = match_close_element (close);
1397 if (m == MATCH_ERROR)
1403 if (gfc_match_eos () == MATCH_NO)
1406 if (gfc_pure (NULL))
1408 gfc_error ("CLOSE statement not allowed in PURE procedure at %C");
1412 new_st.op = EXEC_CLOSE;
1413 new_st.ext.close = close;
1417 gfc_syntax_error (ST_CLOSE);
1420 gfc_free_close (close);
1425 /* Resolve everything in a gfc_close structure. */
1428 gfc_resolve_close (gfc_close * close)
1431 RESOLVE_TAG (&tag_unit, close->unit);
1432 RESOLVE_TAG (&tag_iomsg, close->iomsg);
1433 RESOLVE_TAG (&tag_iostat, close->iostat);
1434 RESOLVE_TAG (&tag_status, close->status);
1436 if (gfc_reference_st_label (close->err, ST_LABEL_TARGET) == FAILURE)
1443 /* Free a gfc_filepos structure. */
1446 gfc_free_filepos (gfc_filepos * fp)
1449 gfc_free_expr (fp->unit);
1450 gfc_free_expr (fp->iomsg);
1451 gfc_free_expr (fp->iostat);
1456 /* Match elements of a REWIND, BACKSPACE, ENDFILE, or FLUSH statement. */
1459 match_file_element (gfc_filepos * fp)
1463 m = match_etag (&tag_unit, &fp->unit);
1466 m = match_out_tag (&tag_iomsg, &fp->iomsg);
1469 m = match_out_tag (&tag_iostat, &fp->iostat);
1472 m = match_ltag (&tag_err, &fp->err);
1480 /* Match the second half of the file-positioning statements, REWIND,
1481 BACKSPACE, ENDFILE, or the FLUSH statement. */
1484 match_filepos (gfc_statement st, gfc_exec_op op)
1489 fp = gfc_getmem (sizeof (gfc_filepos));
1491 if (gfc_match_char ('(') == MATCH_NO)
1493 m = gfc_match_expr (&fp->unit);
1494 if (m == MATCH_ERROR)
1502 m = match_file_element (fp);
1503 if (m == MATCH_ERROR)
1507 m = gfc_match_expr (&fp->unit);
1508 if (m == MATCH_ERROR)
1516 if (gfc_match_char (')') == MATCH_YES)
1518 if (gfc_match_char (',') != MATCH_YES)
1521 m = match_file_element (fp);
1522 if (m == MATCH_ERROR)
1529 if (gfc_match_eos () != MATCH_YES)
1532 if (gfc_pure (NULL))
1534 gfc_error ("%s statement not allowed in PURE procedure at %C",
1535 gfc_ascii_statement (st));
1541 new_st.ext.filepos = fp;
1545 gfc_syntax_error (st);
1548 gfc_free_filepos (fp);
1554 gfc_resolve_filepos (gfc_filepos * fp)
1557 RESOLVE_TAG (&tag_unit, fp->unit);
1558 RESOLVE_TAG (&tag_iostat, fp->iostat);
1559 RESOLVE_TAG (&tag_iomsg, fp->iomsg);
1560 if (gfc_reference_st_label (fp->err, ST_LABEL_TARGET) == FAILURE)
1567 /* Match the file positioning statements: ENDFILE, BACKSPACE, REWIND,
1568 and the FLUSH statement. */
1571 gfc_match_endfile (void)
1574 return match_filepos (ST_END_FILE, EXEC_ENDFILE);
1578 gfc_match_backspace (void)
1581 return match_filepos (ST_BACKSPACE, EXEC_BACKSPACE);
1585 gfc_match_rewind (void)
1588 return match_filepos (ST_REWIND, EXEC_REWIND);
1592 gfc_match_flush (void)
1594 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: FLUSH statement at %C") == FAILURE)
1597 return match_filepos (ST_FLUSH, EXEC_FLUSH);
1600 /******************** Data Transfer Statements *********************/
1603 { M_READ, M_WRITE, M_PRINT, M_INQUIRE }
1607 /* Return a default unit number. */
1610 default_unit (io_kind k)
1619 return gfc_int_expr (unit);
1623 /* Match a unit specification for a data transfer statement. */
1626 match_dt_unit (io_kind k, gfc_dt * dt)
1630 if (gfc_match_char ('*') == MATCH_YES)
1632 if (dt->io_unit != NULL)
1635 dt->io_unit = default_unit (k);
1639 if (gfc_match_expr (&e) == MATCH_YES)
1641 if (dt->io_unit != NULL)
1654 gfc_error ("Duplicate UNIT specification at %C");
1659 /* Match a format specification. */
1662 match_dt_format (gfc_dt * dt)
1666 gfc_st_label *label;
1668 where = gfc_current_locus;
1670 if (gfc_match_char ('*') == MATCH_YES)
1672 if (dt->format_expr != NULL || dt->format_label != NULL)
1675 dt->format_label = &format_asterisk;
1679 if (gfc_match_st_label (&label) == MATCH_YES)
1681 if (dt->format_expr != NULL || dt->format_label != NULL)
1683 gfc_free_st_label (label);
1687 if (gfc_reference_st_label (label, ST_LABEL_FORMAT) == FAILURE)
1690 dt->format_label = label;
1694 if (gfc_match_expr (&e) == MATCH_YES)
1696 if (dt->format_expr != NULL || dt->format_label != NULL)
1701 dt->format_expr = e;
1705 gfc_current_locus = where; /* The only case where we have to restore */
1710 gfc_error ("Duplicate format specification at %C");
1715 /* Traverse a namelist that is part of a READ statement to make sure
1716 that none of the variables in the namelist are INTENT(IN). Returns
1717 nonzero if we find such a variable. */
1720 check_namelist (gfc_symbol * sym)
1724 for (p = sym->namelist; p; p = p->next)
1725 if (p->sym->attr.intent == INTENT_IN)
1727 gfc_error ("Symbol '%s' in namelist '%s' is INTENT(IN) at %C",
1728 p->sym->name, sym->name);
1736 /* Match a single data transfer element. */
1739 match_dt_element (io_kind k, gfc_dt * dt)
1741 char name[GFC_MAX_SYMBOL_LEN + 1];
1745 if (gfc_match (" unit =") == MATCH_YES)
1747 m = match_dt_unit (k, dt);
1752 if (gfc_match (" fmt =") == MATCH_YES)
1754 m = match_dt_format (dt);
1759 if (gfc_match (" nml = %n", name) == MATCH_YES)
1761 if (dt->namelist != NULL)
1763 gfc_error ("Duplicate NML specification at %C");
1767 if (gfc_find_symbol (name, NULL, 1, &sym))
1770 if (sym == NULL || sym->attr.flavor != FL_NAMELIST)
1772 gfc_error ("Symbol '%s' at %C must be a NAMELIST group name",
1773 sym != NULL ? sym->name : name);
1778 if (k == M_READ && check_namelist (sym))
1784 m = match_etag (&tag_rec, &dt->rec);
1787 m = match_out_tag (&tag_iomsg, &dt->iomsg);
1790 m = match_out_tag (&tag_iostat, &dt->iostat);
1793 m = match_ltag (&tag_err, &dt->err);
1795 dt->err_where = gfc_current_locus;
1798 m = match_etag (&tag_advance, &dt->advance);
1801 m = match_out_tag (&tag_size, &dt->size);
1805 m = match_ltag (&tag_end, &dt->end);
1810 gfc_error ("END tag at %C not allowed in output statement");
1813 dt->end_where = gfc_current_locus;
1818 m = match_ltag (&tag_eor, &dt->eor);
1820 dt->eor_where = gfc_current_locus;
1828 /* Free a data transfer structure and everything below it. */
1831 gfc_free_dt (gfc_dt * dt)
1837 gfc_free_expr (dt->io_unit);
1838 gfc_free_expr (dt->format_expr);
1839 gfc_free_expr (dt->rec);
1840 gfc_free_expr (dt->advance);
1841 gfc_free_expr (dt->iomsg);
1842 gfc_free_expr (dt->iostat);
1843 gfc_free_expr (dt->size);
1849 /* Resolve everything in a gfc_dt structure. */
1852 gfc_resolve_dt (gfc_dt * dt)
1856 RESOLVE_TAG (&tag_format, dt->format_expr);
1857 RESOLVE_TAG (&tag_rec, dt->rec);
1858 RESOLVE_TAG (&tag_advance, dt->advance);
1859 RESOLVE_TAG (&tag_iomsg, dt->iomsg);
1860 RESOLVE_TAG (&tag_iostat, dt->iostat);
1861 RESOLVE_TAG (&tag_size, dt->size);
1864 if (gfc_resolve_expr (e) == SUCCESS
1865 && (e->ts.type != BT_INTEGER
1866 && (e->ts.type != BT_CHARACTER
1867 || e->expr_type != EXPR_VARIABLE)))
1870 ("UNIT specification at %L must be an INTEGER expression or a "
1871 "CHARACTER variable", &e->where);
1875 if (e->ts.type == BT_CHARACTER)
1877 if (gfc_has_vector_index (e))
1879 gfc_error ("Internal unit with vector subscript at %L",
1885 if (e->rank && e->ts.type != BT_CHARACTER)
1887 gfc_error ("External IO UNIT cannot be an array at %L", &e->where);
1893 if (gfc_reference_st_label (dt->err, ST_LABEL_TARGET) == FAILURE)
1895 if (dt->err->defined == ST_LABEL_UNKNOWN)
1897 gfc_error ("ERR tag label %d at %L not defined",
1898 dt->err->value, &dt->err_where);
1905 if (gfc_reference_st_label (dt->end, ST_LABEL_TARGET) == FAILURE)
1907 if (dt->end->defined == ST_LABEL_UNKNOWN)
1909 gfc_error ("END tag label %d at %L not defined",
1910 dt->end->value, &dt->end_where);
1917 if (gfc_reference_st_label (dt->eor, ST_LABEL_TARGET) == FAILURE)
1919 if (dt->eor->defined == ST_LABEL_UNKNOWN)
1921 gfc_error ("EOR tag label %d at %L not defined",
1922 dt->eor->value, &dt->eor_where);
1927 /* Check the format label actually exists. */
1928 if (dt->format_label && dt->format_label != &format_asterisk
1929 && dt->format_label->defined == ST_LABEL_UNKNOWN)
1931 gfc_error ("FORMAT label %d at %L not defined", dt->format_label->value,
1932 &dt->format_label->where);
1939 /* Given an io_kind, return its name. */
1942 io_kind_name (io_kind k)
1961 gfc_internal_error ("io_kind_name(): bad I/O-kind");
1968 /* Match an IO iteration statement of the form:
1970 ( [<IO element> ,] <IO element>, I = <expr>, <expr> [, <expr> ] )
1972 which is equivalent to a single IO element. This function is
1973 mutually recursive with match_io_element(). */
1975 static match match_io_element (io_kind k, gfc_code **);
1978 match_io_iterator (io_kind k, gfc_code ** result)
1980 gfc_code *head, *tail, *new;
1988 old_loc = gfc_current_locus;
1990 if (gfc_match_char ('(') != MATCH_YES)
1993 m = match_io_element (k, &head);
1996 if (m != MATCH_YES || gfc_match_char (',') != MATCH_YES)
2002 /* Can't be anything but an IO iterator. Build a list. */
2003 iter = gfc_get_iterator ();
2007 m = gfc_match_iterator (iter, 0);
2008 if (m == MATCH_ERROR)
2012 gfc_check_do_variable (iter->var->symtree);
2016 m = match_io_element (k, &new);
2017 if (m == MATCH_ERROR)
2026 tail = gfc_append_code (tail, new);
2028 if (gfc_match_char (',') != MATCH_YES)
2037 if (gfc_match_char (')') != MATCH_YES)
2040 new = gfc_get_code ();
2042 new->ext.iterator = iter;
2044 new->block = gfc_get_code ();
2045 new->block->op = EXEC_DO;
2046 new->block->next = head;
2052 gfc_error ("Syntax error in I/O iterator at %C");
2056 gfc_free_iterator (iter, 1);
2057 gfc_free_statements (head);
2058 gfc_current_locus = old_loc;
2063 /* Match a single element of an IO list, which is either a single
2064 expression or an IO Iterator. */
2067 match_io_element (io_kind k, gfc_code ** cpp)
2075 m = match_io_iterator (k, cpp);
2081 m = gfc_match_variable (&expr, 0);
2083 gfc_error ("Expected variable in READ statement at %C");
2087 m = gfc_match_expr (&expr);
2089 gfc_error ("Expected expression in %s statement at %C",
2097 if (expr->symtree->n.sym->attr.intent == INTENT_IN)
2100 ("Variable '%s' in input list at %C cannot be INTENT(IN)",
2101 expr->symtree->n.sym->name);
2106 && gfc_impure_variable (expr->symtree->n.sym)
2107 && current_dt->io_unit->ts.type == BT_CHARACTER)
2109 gfc_error ("Cannot read to variable '%s' in PURE procedure at %C",
2110 expr->symtree->n.sym->name);
2114 if (gfc_check_do_variable (expr->symtree))
2120 if (current_dt->io_unit->ts.type == BT_CHARACTER
2122 && current_dt->io_unit->expr_type == EXPR_VARIABLE
2123 && gfc_impure_variable (current_dt->io_unit->symtree->n.sym))
2126 ("Cannot write to internal file unit '%s' at %C inside a "
2127 "PURE procedure", current_dt->io_unit->symtree->n.sym->name);
2139 gfc_free_expr (expr);
2143 cp = gfc_get_code ();
2144 cp->op = EXEC_TRANSFER;
2152 /* Match an I/O list, building gfc_code structures as we go. */
2155 match_io_list (io_kind k, gfc_code ** head_p)
2157 gfc_code *head, *tail, *new;
2160 *head_p = head = tail = NULL;
2161 if (gfc_match_eos () == MATCH_YES)
2166 m = match_io_element (k, &new);
2167 if (m == MATCH_ERROR)
2172 tail = gfc_append_code (tail, new);
2176 if (gfc_match_eos () == MATCH_YES)
2178 if (gfc_match_char (',') != MATCH_YES)
2186 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
2189 gfc_free_statements (head);
2194 /* Attach the data transfer end node. */
2197 terminate_io (gfc_code * io_code)
2201 if (io_code == NULL)
2202 io_code = new_st.block;
2204 c = gfc_get_code ();
2205 c->op = EXEC_DT_END;
2207 /* Point to structure that is already there */
2208 c->ext.dt = new_st.ext.dt;
2209 gfc_append_code (io_code, c);
2213 /* Check the constraints for a data transfer statement. The majority of the
2214 constraints appearing in 9.4 of the standard appear here. Some are handled
2215 in resolve_tag and others in gfc_resolve_dt. */
2218 check_io_constraints (io_kind k, gfc_dt *dt, gfc_code * io_code, locus * spec_end)
2220 #define io_constraint(condition,msg,arg)\
2223 gfc_error(msg,arg);\
2229 gfc_symbol * sym = NULL;
2234 if (expr && expr->expr_type == EXPR_VARIABLE
2235 && expr->ts.type == BT_CHARACTER)
2237 sym = expr->symtree->n.sym;
2239 io_constraint (k == M_WRITE && sym->attr.intent == INTENT_IN,
2240 "Internal file at %L must not be INTENT(IN)",
2243 io_constraint (gfc_has_vector_index (dt->io_unit),
2244 "Internal file incompatible with vector subscript at %L",
2247 io_constraint (dt->rec != NULL,
2248 "REC tag at %L is incompatible with internal file",
2251 io_constraint (dt->namelist != NULL,
2252 "Internal file at %L is incompatible with namelist",
2255 io_constraint (dt->advance != NULL,
2256 "ADVANCE tag at %L is incompatible with internal file",
2257 &dt->advance->where);
2260 if (expr && expr->ts.type != BT_CHARACTER)
2263 io_constraint (gfc_pure (NULL)
2264 && (k == M_READ || k == M_WRITE),
2265 "IO UNIT in %s statement at %C must be "
2266 "an internal file in a PURE procedure",
2273 io_constraint (dt->end,
2274 "END tag not allowed with output at %L",
2277 io_constraint (dt->eor,
2278 "EOR tag not allowed with output at %L",
2281 io_constraint (k != M_READ && dt->size,
2282 "SIZE=specifier not allowed with output at %L",
2287 io_constraint (dt->size && dt->advance == NULL,
2288 "SIZE tag at %L requires an ADVANCE tag",
2291 io_constraint (dt->eor && dt->advance == NULL,
2292 "EOR tag at %L requires an ADVANCE tag",
2300 io_constraint (io_code && dt->namelist,
2301 "NAMELIST cannot be followed by IO-list at %L",
2304 io_constraint (dt->format_expr,
2305 "IO spec-list cannot contain both NAMELIST group name "
2306 "and format specification at %L.",
2307 &dt->format_expr->where);
2309 io_constraint (dt->format_label,
2310 "IO spec-list cannot contain both NAMELIST group name "
2311 "and format label at %L", spec_end);
2313 io_constraint (dt->rec,
2314 "NAMELIST IO is not allowed with a REC=specifier "
2315 "at %L.", &dt->rec->where);
2317 io_constraint (dt->advance,
2318 "NAMELIST IO is not allowed with a ADVANCE=specifier "
2319 "at %L.", &dt->advance->where);
2324 io_constraint (dt->end,
2325 "An END tag is not allowed with a "
2326 "REC=specifier at %L.", &dt->end_where);
2329 io_constraint (dt->format_label == &format_asterisk,
2330 "FMT=* is not allowed with a REC=specifier "
2331 "at %L.", spec_end);
2336 int not_yes, not_no;
2339 io_constraint (dt->format_label == &format_asterisk,
2340 "List directed format(*) is not allowed with a "
2341 "ADVANCE=specifier at %L.", &expr->where);
2343 if (expr->expr_type == EXPR_CONSTANT && expr->ts.type == BT_CHARACTER)
2345 const char * advance = expr->value.character.string;
2346 not_no = strncasecmp (advance, "no", 2) != 0;
2347 not_yes = strncasecmp (advance, "yes", 2) != 0;
2355 io_constraint (not_no && not_yes,
2356 "ADVANCE=specifier at %L must have value = "
2357 "YES or NO.", &expr->where);
2359 io_constraint (dt->size && not_no && k == M_READ,
2360 "SIZE tag at %L requires an ADVANCE = 'NO'",
2363 io_constraint (dt->eor && not_no && k == M_READ,
2364 "EOR tag at %L requires an ADVANCE = 'NO'",
2368 expr = dt->format_expr;
2369 if (expr != NULL && expr->expr_type == EXPR_CONSTANT)
2370 check_format_string (expr);
2374 #undef io_constraint
2376 /* Match a READ, WRITE or PRINT statement. */
2379 match_io (io_kind k)
2381 char name[GFC_MAX_SYMBOL_LEN + 1];
2390 where = gfc_current_locus;
2392 current_dt = dt = gfc_getmem (sizeof (gfc_dt));
2393 if (gfc_match_char ('(') == MATCH_NO)
2395 where = gfc_current_locus;
2398 else if (k == M_PRINT)
2400 /* Treat the non-standard case of PRINT namelist. */
2401 if ((gfc_current_form == FORM_FIXED || gfc_peek_char () == ' ')
2402 && gfc_match_name (name) == MATCH_YES)
2404 gfc_find_symbol (name, NULL, 1, &sym);
2405 if (sym && sym->attr.flavor == FL_NAMELIST)
2407 if (gfc_notify_std (GFC_STD_GNU, "PRINT namelist at "
2408 "%C is an extension") == FAILURE)
2414 dt->io_unit = default_unit (k);
2419 gfc_current_locus = where;
2423 if (gfc_current_form == FORM_FREE)
2425 c = gfc_peek_char();
2426 if (c != ' ' && c != '*' && c != '\'' && c != '"')
2433 m = match_dt_format (dt);
2434 if (m == MATCH_ERROR)
2440 dt->io_unit = default_unit (k);
2445 /* Error for constructs like print (1,*). */
2450 /* Match a control list */
2451 if (match_dt_element (k, dt) == MATCH_YES)
2453 if (match_dt_unit (k, dt) != MATCH_YES)
2456 if (gfc_match_char (')') == MATCH_YES)
2458 if (gfc_match_char (',') != MATCH_YES)
2461 m = match_dt_element (k, dt);
2464 if (m == MATCH_ERROR)
2467 m = match_dt_format (dt);
2470 if (m == MATCH_ERROR)
2473 where = gfc_current_locus;
2475 m = gfc_match_name (name);
2478 gfc_find_symbol (name, NULL, 1, &sym);
2479 if (sym && sym->attr.flavor == FL_NAMELIST)
2482 if (k == M_READ && check_namelist (sym))
2491 gfc_current_locus = where;
2493 goto loop; /* No matches, try regular elements */
2496 if (gfc_match_char (')') == MATCH_YES)
2498 if (gfc_match_char (',') != MATCH_YES)
2504 m = match_dt_element (k, dt);
2507 if (m == MATCH_ERROR)
2510 if (gfc_match_char (')') == MATCH_YES)
2512 if (gfc_match_char (',') != MATCH_YES)
2518 /* Used in check_io_constraints, where no locus is available. */
2519 spec_end = gfc_current_locus;
2521 /* Optional leading comma (non-standard). */
2523 && gfc_match_char (',') == MATCH_YES
2525 && gfc_notify_std (GFC_STD_GNU, "Extension: Comma before output "
2526 "item list at %C is an extension") == FAILURE)
2530 if (gfc_match_eos () != MATCH_YES)
2532 if (comma_flag && gfc_match_char (',') != MATCH_YES)
2534 gfc_error ("Expected comma in I/O list at %C");
2539 m = match_io_list (k, &io_code);
2540 if (m == MATCH_ERROR)
2546 /* A full IO statement has been matched. Check the constraints. spec_end is
2547 supplied for cases where no locus is supplied. */
2548 m = check_io_constraints (k, dt, io_code, &spec_end);
2550 if (m == MATCH_ERROR)
2553 new_st.op = (k == M_READ) ? EXEC_READ : EXEC_WRITE;
2555 new_st.block = gfc_get_code ();
2556 new_st.block->op = new_st.op;
2557 new_st.block->next = io_code;
2559 terminate_io (io_code);
2564 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
2574 gfc_match_read (void)
2576 return match_io (M_READ);
2580 gfc_match_write (void)
2582 return match_io (M_WRITE);
2586 gfc_match_print (void)
2590 m = match_io (M_PRINT);
2594 if (gfc_pure (NULL))
2596 gfc_error ("PRINT statement at %C not allowed within PURE procedure");
2604 /* Free a gfc_inquire structure. */
2607 gfc_free_inquire (gfc_inquire * inquire)
2610 if (inquire == NULL)
2613 gfc_free_expr (inquire->unit);
2614 gfc_free_expr (inquire->file);
2615 gfc_free_expr (inquire->iomsg);
2616 gfc_free_expr (inquire->iostat);
2617 gfc_free_expr (inquire->exist);
2618 gfc_free_expr (inquire->opened);
2619 gfc_free_expr (inquire->number);
2620 gfc_free_expr (inquire->named);
2621 gfc_free_expr (inquire->name);
2622 gfc_free_expr (inquire->access);
2623 gfc_free_expr (inquire->sequential);
2624 gfc_free_expr (inquire->direct);
2625 gfc_free_expr (inquire->form);
2626 gfc_free_expr (inquire->formatted);
2627 gfc_free_expr (inquire->unformatted);
2628 gfc_free_expr (inquire->recl);
2629 gfc_free_expr (inquire->nextrec);
2630 gfc_free_expr (inquire->blank);
2631 gfc_free_expr (inquire->position);
2632 gfc_free_expr (inquire->action);
2633 gfc_free_expr (inquire->read);
2634 gfc_free_expr (inquire->write);
2635 gfc_free_expr (inquire->readwrite);
2636 gfc_free_expr (inquire->delim);
2637 gfc_free_expr (inquire->pad);
2638 gfc_free_expr (inquire->iolength);
2639 gfc_free_expr (inquire->convert);
2645 /* Match an element of an INQUIRE statement. */
2647 #define RETM if (m != MATCH_NO) return m;
2650 match_inquire_element (gfc_inquire * inquire)
2654 m = match_etag (&tag_unit, &inquire->unit);
2655 RETM m = match_etag (&tag_file, &inquire->file);
2656 RETM m = match_ltag (&tag_err, &inquire->err);
2657 RETM m = match_out_tag (&tag_iomsg, &inquire->iomsg);
2658 RETM m = match_out_tag (&tag_iostat, &inquire->iostat);
2659 RETM m = match_vtag (&tag_exist, &inquire->exist);
2660 RETM m = match_vtag (&tag_opened, &inquire->opened);
2661 RETM m = match_vtag (&tag_named, &inquire->named);
2662 RETM m = match_vtag (&tag_name, &inquire->name);
2663 RETM m = match_out_tag (&tag_number, &inquire->number);
2664 RETM m = match_vtag (&tag_s_access, &inquire->access);
2665 RETM m = match_vtag (&tag_sequential, &inquire->sequential);
2666 RETM m = match_vtag (&tag_direct, &inquire->direct);
2667 RETM m = match_vtag (&tag_s_form, &inquire->form);
2668 RETM m = match_vtag (&tag_formatted, &inquire->formatted);
2669 RETM m = match_vtag (&tag_unformatted, &inquire->unformatted);
2670 RETM m = match_out_tag (&tag_s_recl, &inquire->recl);
2671 RETM m = match_out_tag (&tag_nextrec, &inquire->nextrec);
2672 RETM m = match_vtag (&tag_s_blank, &inquire->blank);
2673 RETM m = match_vtag (&tag_s_position, &inquire->position);
2674 RETM m = match_vtag (&tag_s_action, &inquire->action);
2675 RETM m = match_vtag (&tag_read, &inquire->read);
2676 RETM m = match_vtag (&tag_write, &inquire->write);
2677 RETM m = match_vtag (&tag_readwrite, &inquire->readwrite);
2678 RETM m = match_vtag (&tag_s_delim, &inquire->delim);
2679 RETM m = match_vtag (&tag_s_pad, &inquire->pad);
2680 RETM m = match_vtag (&tag_iolength, &inquire->iolength);
2681 RETM m = match_vtag (&tag_convert, &inquire->convert);
2682 RETM return MATCH_NO;
2689 gfc_match_inquire (void)
2691 gfc_inquire *inquire;
2696 m = gfc_match_char ('(');
2700 inquire = gfc_getmem (sizeof (gfc_inquire));
2702 loc = gfc_current_locus;
2704 m = match_inquire_element (inquire);
2705 if (m == MATCH_ERROR)
2709 m = gfc_match_expr (&inquire->unit);
2710 if (m == MATCH_ERROR)
2716 /* See if we have the IOLENGTH form of the inquire statement. */
2717 if (inquire->iolength != NULL)
2719 if (gfc_match_char (')') != MATCH_YES)
2722 m = match_io_list (M_INQUIRE, &code);
2723 if (m == MATCH_ERROR)
2728 new_st.op = EXEC_IOLENGTH;
2729 new_st.expr = inquire->iolength;
2730 new_st.ext.inquire = inquire;
2732 if (gfc_pure (NULL))
2734 gfc_free_statements (code);
2735 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
2739 new_st.block = gfc_get_code ();
2740 new_st.block->op = EXEC_IOLENGTH;
2741 terminate_io (code);
2742 new_st.block->next = code;
2746 /* At this point, we have the non-IOLENGTH inquire statement. */
2749 if (gfc_match_char (')') == MATCH_YES)
2751 if (gfc_match_char (',') != MATCH_YES)
2754 m = match_inquire_element (inquire);
2755 if (m == MATCH_ERROR)
2760 if (inquire->iolength != NULL)
2762 gfc_error ("IOLENGTH tag invalid in INQUIRE statement at %C");
2767 if (gfc_match_eos () != MATCH_YES)
2770 if (inquire->unit != NULL && inquire->file != NULL)
2772 gfc_error ("INQUIRE statement at %L cannot contain both FILE and"
2773 " UNIT specifiers", &loc);
2777 if (inquire->unit == NULL && inquire->file == NULL)
2779 gfc_error ("INQUIRE statement at %L requires either FILE or"
2780 " UNIT specifier", &loc);
2784 if (gfc_pure (NULL))
2786 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
2790 new_st.op = EXEC_INQUIRE;
2791 new_st.ext.inquire = inquire;
2795 gfc_syntax_error (ST_INQUIRE);
2798 gfc_free_inquire (inquire);
2803 /* Resolve everything in a gfc_inquire structure. */
2806 gfc_resolve_inquire (gfc_inquire * inquire)
2809 RESOLVE_TAG (&tag_unit, inquire->unit);
2810 RESOLVE_TAG (&tag_file, inquire->file);
2811 RESOLVE_TAG (&tag_iomsg, inquire->iomsg);
2812 RESOLVE_TAG (&tag_iostat, inquire->iostat);
2813 RESOLVE_TAG (&tag_exist, inquire->exist);
2814 RESOLVE_TAG (&tag_opened, inquire->opened);
2815 RESOLVE_TAG (&tag_number, inquire->number);
2816 RESOLVE_TAG (&tag_named, inquire->named);
2817 RESOLVE_TAG (&tag_name, inquire->name);
2818 RESOLVE_TAG (&tag_s_access, inquire->access);
2819 RESOLVE_TAG (&tag_sequential, inquire->sequential);
2820 RESOLVE_TAG (&tag_direct, inquire->direct);
2821 RESOLVE_TAG (&tag_s_form, inquire->form);
2822 RESOLVE_TAG (&tag_formatted, inquire->formatted);
2823 RESOLVE_TAG (&tag_unformatted, inquire->unformatted);
2824 RESOLVE_TAG (&tag_s_recl, inquire->recl);
2825 RESOLVE_TAG (&tag_nextrec, inquire->nextrec);
2826 RESOLVE_TAG (&tag_s_blank, inquire->blank);
2827 RESOLVE_TAG (&tag_s_position, inquire->position);
2828 RESOLVE_TAG (&tag_s_action, inquire->action);
2829 RESOLVE_TAG (&tag_read, inquire->read);
2830 RESOLVE_TAG (&tag_write, inquire->write);
2831 RESOLVE_TAG (&tag_readwrite, inquire->readwrite);
2832 RESOLVE_TAG (&tag_s_delim, inquire->delim);
2833 RESOLVE_TAG (&tag_s_pad, inquire->pad);
2834 RESOLVE_TAG (&tag_iolength, inquire->iolength);
2835 RESOLVE_TAG (&tag_convert, inquire->convert);
2837 if (gfc_reference_st_label (inquire->err, ST_LABEL_TARGET) == FAILURE)