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 *period_required = _("Period required");
417 const char *nonneg_required = _("Nonnegative width required");
418 const char *unexpected_element = _("Unexpected element");
419 const char *unexpected_end = _("Unexpected end of format string");
428 saved_token = FMT_NONE;
436 error = _("Missing leading left parenthesis");
442 goto finished; /* Empty format is legal */
446 /* In this state, the next thing has to be a format item. */
470 /* Signed integer can only precede a P format. */
474 error = _("Expected P edit descriptor");
481 /* P requires a prior number. */
482 error = _("P descriptor requires leading scale factor");
486 /* X requires a prior number if we're being pedantic. */
487 if (gfc_notify_std (GFC_STD_GNU, "Extension: X descriptor "
488 "requires leading space count at %C")
498 goto extension_optional_comma;
507 if (gfc_notify_std (GFC_STD_GNU, "Extension: $ descriptor at %C")
510 if (t != FMT_RPAREN || level > 0)
512 error = _("$ must be the last specifier");
533 error = unexpected_end;
537 error = unexpected_element;
542 /* In this state, t must currently be a data descriptor.
543 Deal with things that can/must follow the descriptor. */
557 error = _("Repeat count cannot follow P descriptor");
572 switch (gfc_notification_std (GFC_STD_GNU))
576 ("Extension: Missing positive width after L descriptor at %C");
581 error = posint_required;
606 error = posint_required;
613 error = period_required;
618 if (u != FMT_ZERO && u != FMT_POSINT)
620 error = nonneg_required;
627 /* Look for optional exponent. */
638 error = _("Positive exponent width required");
647 if (t != FMT_ZERO && t != FMT_POSINT)
649 error = nonneg_required;
656 error = period_required;
661 if (t != FMT_ZERO && t != FMT_POSINT)
663 error = nonneg_required;
670 if(mode == MODE_STRING)
672 format_string += value;
673 format_length -= value;
687 if (t != FMT_ZERO && t != FMT_POSINT)
689 error = nonneg_required;
701 if (t != FMT_ZERO && t != FMT_POSINT)
703 error = nonneg_required;
711 error = unexpected_element;
716 /* Between a descriptor and what comes next. */
735 error = unexpected_end;
739 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
746 /* Optional comma is a weird between state where we've just finished
747 reading a colon, slash or P descriptor. */
761 /* Assume that we have another format item. */
768 extension_optional_comma:
769 /* As a GNU extension, permit a missing comma after a string literal. */
787 error = unexpected_end;
791 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
801 /* Something went wrong. If the format we're checking is a string,
802 generate a warning, since the program is correct. If the format
803 is in a FORMAT statement, this messes up parsing, which is an
805 if (mode != MODE_STRING)
806 gfc_error ("%s in format string at %C", error);
809 gfc_warning ("%s in format string at %C", error);
811 /* TODO: More elaborate measures are needed to show where a problem
812 is within a format string that has been calculated. */
822 /* Given an expression node that is a constant string, see if it looks
823 like a format string. */
826 check_format_string (gfc_expr * e)
830 format_string = e->value.character.string;
835 /************ Fortran 95 I/O statement matchers *************/
837 /* Match a FORMAT statement. This amounts to actually parsing the
838 format descriptors in order to correctly locate the end of the
842 gfc_match_format (void)
847 if (gfc_current_ns->proc_name
848 && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
850 gfc_error ("Format statement in module main block at %C.");
854 if (gfc_statement_label == NULL)
856 gfc_error ("Missing format label at %C");
859 gfc_gobble_whitespace ();
864 start = gfc_current_locus;
866 if (check_format () == FAILURE)
869 if (gfc_match_eos () != MATCH_YES)
871 gfc_syntax_error (ST_FORMAT);
875 /* The label doesn't get created until after the statement is done
876 being matched, so we have to leave the string for later. */
878 gfc_current_locus = start; /* Back to the beginning */
881 new_st.op = EXEC_NOP;
884 e->expr_type = EXPR_CONSTANT;
885 e->ts.type = BT_CHARACTER;
886 e->ts.kind = gfc_default_character_kind;
888 e->value.character.string = format_string = gfc_getmem(format_length+1);
889 e->value.character.length = format_length;
890 gfc_statement_label->format = e;
893 check_format (); /* Guaranteed to succeed */
894 gfc_match_eos (); /* Guaranteed to succeed */
900 /* Match an expression I/O tag of some sort. */
903 match_etag (const io_tag * tag, gfc_expr ** v)
908 m = gfc_match (tag->spec, &result);
914 gfc_error ("Duplicate %s specification at %C", tag->name);
915 gfc_free_expr (result);
924 /* Match a variable I/O tag of some sort. */
927 match_vtag (const io_tag * tag, gfc_expr ** v)
932 m = gfc_match (tag->spec, &result);
938 gfc_error ("Duplicate %s specification at %C", tag->name);
939 gfc_free_expr (result);
943 if (result->symtree->n.sym->attr.intent == INTENT_IN)
945 gfc_error ("Variable tag cannot be INTENT(IN) at %C");
946 gfc_free_expr (result);
950 if (gfc_pure (NULL) && gfc_impure_variable (result->symtree->n.sym))
952 gfc_error ("Variable tag cannot be assigned in PURE procedure at %C");
953 gfc_free_expr (result);
962 /* Match I/O tags that cause variables to become redefined. */
965 match_out_tag(const io_tag *tag, gfc_expr **result)
969 m = match_vtag(tag, result);
971 gfc_check_do_variable((*result)->symtree);
977 /* Match a label I/O tag. */
980 match_ltag (const io_tag * tag, gfc_st_label ** label)
986 m = gfc_match (tag->spec, label);
987 if (m == MATCH_YES && old != 0)
989 gfc_error ("Duplicate %s label specification at %C", tag->name);
994 && gfc_reference_st_label (*label, ST_LABEL_TARGET) == FAILURE)
1001 /* Do expression resolution and type-checking on an expression tag. */
1004 resolve_tag (const io_tag * tag, gfc_expr * e)
1010 if (gfc_resolve_expr (e) == FAILURE)
1013 if (e->ts.type != tag->type && tag != &tag_format)
1015 gfc_error ("%s tag at %L must be of type %s", tag->name,
1016 &e->where, gfc_basic_typename (tag->type));
1020 if (tag == &tag_format)
1022 if (e->expr_type == EXPR_CONSTANT
1023 && (e->ts.type != BT_CHARACTER
1024 || e->ts.kind != gfc_default_character_kind))
1026 gfc_error ("Constant expression in FORMAT tag at %L must be "
1027 "of type default CHARACTER", &e->where);
1031 /* If e's rank is zero and e is not an element of an array, it should be
1032 of integer or character type. The integer variable should be
1034 if (e->symtree == NULL || e->symtree->n.sym->as == NULL
1035 || e->symtree->n.sym->as->rank == 0)
1037 if (e->ts.type != BT_CHARACTER && e->ts.type != BT_INTEGER)
1039 gfc_error ("%s tag at %L must be of type %s or %s", tag->name,
1040 &e->where, gfc_basic_typename (BT_CHARACTER),
1041 gfc_basic_typename (BT_INTEGER));
1044 else if (e->ts.type == BT_INTEGER && e->expr_type == EXPR_VARIABLE)
1046 if (gfc_notify_std (GFC_STD_F95_DEL,
1047 "Obsolete: ASSIGNED variable in FORMAT tag at %L",
1048 &e->where) == FAILURE)
1050 if (e->symtree->n.sym->attr.assign != 1)
1052 gfc_error ("Variable '%s' at %L has not been assigned a "
1053 "format label", e->symtree->n.sym->name, &e->where);
1061 /* if rank is nonzero, we allow the type to be character under
1062 GFC_STD_GNU and other type under GFC_STD_LEGACY. It may be
1063 assigned an Hollerith constant. */
1064 if (e->ts.type == BT_CHARACTER)
1066 if (gfc_notify_std (GFC_STD_GNU,
1067 "Extension: Character array in FORMAT tag at %L",
1068 &e->where) == FAILURE)
1073 if (gfc_notify_std (GFC_STD_LEGACY,
1074 "Extension: Non-character in FORMAT tag at %L",
1075 &e->where) == FAILURE)
1085 gfc_error ("%s tag at %L must be scalar", tag->name, &e->where);
1089 if (tag == &tag_iomsg)
1091 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: IOMSG tag at %L",
1092 &e->where) == FAILURE)
1096 if (tag == &tag_iostat && e->ts.kind != gfc_default_integer_kind)
1098 if (gfc_notify_std (GFC_STD_GNU, "Fortran 95 requires default "
1099 "INTEGER in IOSTAT tag at %L",
1100 &e->where) == FAILURE)
1104 if (tag == &tag_size && e->ts.kind != gfc_default_integer_kind)
1106 if (gfc_notify_std (GFC_STD_GNU, "Fortran 95 requires default "
1107 "INTEGER in SIZE tag at %L",
1108 &e->where) == FAILURE)
1112 if (tag == &tag_convert)
1114 if (gfc_notify_std (GFC_STD_GNU, "Extension: CONVERT tag at %L",
1115 &e->where) == FAILURE)
1124 /* Match a single tag of an OPEN statement. */
1127 match_open_element (gfc_open * open)
1131 m = match_etag (&tag_unit, &open->unit);
1134 m = match_out_tag (&tag_iomsg, &open->iomsg);
1137 m = match_out_tag (&tag_iostat, &open->iostat);
1140 m = match_etag (&tag_file, &open->file);
1143 m = match_etag (&tag_status, &open->status);
1146 m = match_etag (&tag_e_access, &open->access);
1149 m = match_etag (&tag_e_form, &open->form);
1152 m = match_etag (&tag_e_recl, &open->recl);
1155 m = match_etag (&tag_e_blank, &open->blank);
1158 m = match_etag (&tag_e_position, &open->position);
1161 m = match_etag (&tag_e_action, &open->action);
1164 m = match_etag (&tag_e_delim, &open->delim);
1167 m = match_etag (&tag_e_pad, &open->pad);
1170 m = match_ltag (&tag_err, &open->err);
1173 m = match_etag (&tag_convert, &open->convert);
1181 /* Free the gfc_open structure and all the expressions it contains. */
1184 gfc_free_open (gfc_open * open)
1190 gfc_free_expr (open->unit);
1191 gfc_free_expr (open->iomsg);
1192 gfc_free_expr (open->iostat);
1193 gfc_free_expr (open->file);
1194 gfc_free_expr (open->status);
1195 gfc_free_expr (open->access);
1196 gfc_free_expr (open->form);
1197 gfc_free_expr (open->recl);
1198 gfc_free_expr (open->blank);
1199 gfc_free_expr (open->position);
1200 gfc_free_expr (open->action);
1201 gfc_free_expr (open->delim);
1202 gfc_free_expr (open->pad);
1203 gfc_free_expr (open->convert);
1209 /* Resolve everything in a gfc_open structure. */
1212 gfc_resolve_open (gfc_open * open)
1215 RESOLVE_TAG (&tag_unit, open->unit);
1216 RESOLVE_TAG (&tag_iomsg, open->iomsg);
1217 RESOLVE_TAG (&tag_iostat, open->iostat);
1218 RESOLVE_TAG (&tag_file, open->file);
1219 RESOLVE_TAG (&tag_status, open->status);
1220 RESOLVE_TAG (&tag_e_access, open->access);
1221 RESOLVE_TAG (&tag_e_form, open->form);
1222 RESOLVE_TAG (&tag_e_recl, open->recl);
1224 RESOLVE_TAG (&tag_e_blank, open->blank);
1225 RESOLVE_TAG (&tag_e_position, open->position);
1226 RESOLVE_TAG (&tag_e_action, open->action);
1227 RESOLVE_TAG (&tag_e_delim, open->delim);
1228 RESOLVE_TAG (&tag_e_pad, open->pad);
1229 RESOLVE_TAG (&tag_convert, open->convert);
1231 if (gfc_reference_st_label (open->err, ST_LABEL_TARGET) == FAILURE)
1238 /* Match an OPEN statement. */
1241 gfc_match_open (void)
1246 m = gfc_match_char ('(');
1250 open = gfc_getmem (sizeof (gfc_open));
1252 m = match_open_element (open);
1254 if (m == MATCH_ERROR)
1258 m = gfc_match_expr (&open->unit);
1261 if (m == MATCH_ERROR)
1267 if (gfc_match_char (')') == MATCH_YES)
1269 if (gfc_match_char (',') != MATCH_YES)
1272 m = match_open_element (open);
1273 if (m == MATCH_ERROR)
1279 if (gfc_match_eos () == MATCH_NO)
1282 if (gfc_pure (NULL))
1284 gfc_error ("OPEN statement not allowed in PURE procedure at %C");
1288 new_st.op = EXEC_OPEN;
1289 new_st.ext.open = open;
1293 gfc_syntax_error (ST_OPEN);
1296 gfc_free_open (open);
1301 /* Free a gfc_close structure an all its expressions. */
1304 gfc_free_close (gfc_close * close)
1310 gfc_free_expr (close->unit);
1311 gfc_free_expr (close->iomsg);
1312 gfc_free_expr (close->iostat);
1313 gfc_free_expr (close->status);
1319 /* Match elements of a CLOSE statement. */
1322 match_close_element (gfc_close * close)
1326 m = match_etag (&tag_unit, &close->unit);
1329 m = match_etag (&tag_status, &close->status);
1332 m = match_out_tag (&tag_iomsg, &close->iomsg);
1335 m = match_out_tag (&tag_iostat, &close->iostat);
1338 m = match_ltag (&tag_err, &close->err);
1346 /* Match a CLOSE statement. */
1349 gfc_match_close (void)
1354 m = gfc_match_char ('(');
1358 close = gfc_getmem (sizeof (gfc_close));
1360 m = match_close_element (close);
1362 if (m == MATCH_ERROR)
1366 m = gfc_match_expr (&close->unit);
1369 if (m == MATCH_ERROR)
1375 if (gfc_match_char (')') == MATCH_YES)
1377 if (gfc_match_char (',') != MATCH_YES)
1380 m = match_close_element (close);
1381 if (m == MATCH_ERROR)
1387 if (gfc_match_eos () == MATCH_NO)
1390 if (gfc_pure (NULL))
1392 gfc_error ("CLOSE statement not allowed in PURE procedure at %C");
1396 new_st.op = EXEC_CLOSE;
1397 new_st.ext.close = close;
1401 gfc_syntax_error (ST_CLOSE);
1404 gfc_free_close (close);
1409 /* Resolve everything in a gfc_close structure. */
1412 gfc_resolve_close (gfc_close * close)
1415 RESOLVE_TAG (&tag_unit, close->unit);
1416 RESOLVE_TAG (&tag_iomsg, close->iomsg);
1417 RESOLVE_TAG (&tag_iostat, close->iostat);
1418 RESOLVE_TAG (&tag_status, close->status);
1420 if (gfc_reference_st_label (close->err, ST_LABEL_TARGET) == FAILURE)
1427 /* Free a gfc_filepos structure. */
1430 gfc_free_filepos (gfc_filepos * fp)
1433 gfc_free_expr (fp->unit);
1434 gfc_free_expr (fp->iomsg);
1435 gfc_free_expr (fp->iostat);
1440 /* Match elements of a REWIND, BACKSPACE, ENDFILE, or FLUSH statement. */
1443 match_file_element (gfc_filepos * fp)
1447 m = match_etag (&tag_unit, &fp->unit);
1450 m = match_out_tag (&tag_iomsg, &fp->iomsg);
1453 m = match_out_tag (&tag_iostat, &fp->iostat);
1456 m = match_ltag (&tag_err, &fp->err);
1464 /* Match the second half of the file-positioning statements, REWIND,
1465 BACKSPACE, ENDFILE, or the FLUSH statement. */
1468 match_filepos (gfc_statement st, gfc_exec_op op)
1473 fp = gfc_getmem (sizeof (gfc_filepos));
1475 if (gfc_match_char ('(') == MATCH_NO)
1477 m = gfc_match_expr (&fp->unit);
1478 if (m == MATCH_ERROR)
1486 m = match_file_element (fp);
1487 if (m == MATCH_ERROR)
1491 m = gfc_match_expr (&fp->unit);
1492 if (m == MATCH_ERROR)
1500 if (gfc_match_char (')') == MATCH_YES)
1502 if (gfc_match_char (',') != MATCH_YES)
1505 m = match_file_element (fp);
1506 if (m == MATCH_ERROR)
1513 if (gfc_match_eos () != MATCH_YES)
1516 if (gfc_pure (NULL))
1518 gfc_error ("%s statement not allowed in PURE procedure at %C",
1519 gfc_ascii_statement (st));
1525 new_st.ext.filepos = fp;
1529 gfc_syntax_error (st);
1532 gfc_free_filepos (fp);
1538 gfc_resolve_filepos (gfc_filepos * fp)
1541 RESOLVE_TAG (&tag_unit, fp->unit);
1542 RESOLVE_TAG (&tag_iostat, fp->iostat);
1543 RESOLVE_TAG (&tag_iomsg, fp->iomsg);
1544 if (gfc_reference_st_label (fp->err, ST_LABEL_TARGET) == FAILURE)
1551 /* Match the file positioning statements: ENDFILE, BACKSPACE, REWIND,
1552 and the FLUSH statement. */
1555 gfc_match_endfile (void)
1558 return match_filepos (ST_END_FILE, EXEC_ENDFILE);
1562 gfc_match_backspace (void)
1565 return match_filepos (ST_BACKSPACE, EXEC_BACKSPACE);
1569 gfc_match_rewind (void)
1572 return match_filepos (ST_REWIND, EXEC_REWIND);
1576 gfc_match_flush (void)
1578 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: FLUSH statement at %C") == FAILURE)
1581 return match_filepos (ST_FLUSH, EXEC_FLUSH);
1584 /******************** Data Transfer Statements *********************/
1587 { M_READ, M_WRITE, M_PRINT, M_INQUIRE }
1591 /* Return a default unit number. */
1594 default_unit (io_kind k)
1603 return gfc_int_expr (unit);
1607 /* Match a unit specification for a data transfer statement. */
1610 match_dt_unit (io_kind k, gfc_dt * dt)
1614 if (gfc_match_char ('*') == MATCH_YES)
1616 if (dt->io_unit != NULL)
1619 dt->io_unit = default_unit (k);
1623 if (gfc_match_expr (&e) == MATCH_YES)
1625 if (dt->io_unit != NULL)
1638 gfc_error ("Duplicate UNIT specification at %C");
1643 /* Match a format specification. */
1646 match_dt_format (gfc_dt * dt)
1650 gfc_st_label *label;
1652 where = gfc_current_locus;
1654 if (gfc_match_char ('*') == MATCH_YES)
1656 if (dt->format_expr != NULL || dt->format_label != NULL)
1659 dt->format_label = &format_asterisk;
1663 if (gfc_match_st_label (&label) == MATCH_YES)
1665 if (dt->format_expr != NULL || dt->format_label != NULL)
1667 gfc_free_st_label (label);
1671 if (gfc_reference_st_label (label, ST_LABEL_FORMAT) == FAILURE)
1674 dt->format_label = label;
1678 if (gfc_match_expr (&e) == MATCH_YES)
1680 if (dt->format_expr != NULL || dt->format_label != NULL)
1685 dt->format_expr = e;
1689 gfc_current_locus = where; /* The only case where we have to restore */
1694 gfc_error ("Duplicate format specification at %C");
1699 /* Traverse a namelist that is part of a READ statement to make sure
1700 that none of the variables in the namelist are INTENT(IN). Returns
1701 nonzero if we find such a variable. */
1704 check_namelist (gfc_symbol * sym)
1708 for (p = sym->namelist; p; p = p->next)
1709 if (p->sym->attr.intent == INTENT_IN)
1711 gfc_error ("Symbol '%s' in namelist '%s' is INTENT(IN) at %C",
1712 p->sym->name, sym->name);
1720 /* Match a single data transfer element. */
1723 match_dt_element (io_kind k, gfc_dt * dt)
1725 char name[GFC_MAX_SYMBOL_LEN + 1];
1729 if (gfc_match (" unit =") == MATCH_YES)
1731 m = match_dt_unit (k, dt);
1736 if (gfc_match (" fmt =") == MATCH_YES)
1738 m = match_dt_format (dt);
1743 if (gfc_match (" nml = %n", name) == MATCH_YES)
1745 if (dt->namelist != NULL)
1747 gfc_error ("Duplicate NML specification at %C");
1751 if (gfc_find_symbol (name, NULL, 1, &sym))
1754 if (sym == NULL || sym->attr.flavor != FL_NAMELIST)
1756 gfc_error ("Symbol '%s' at %C must be a NAMELIST group name",
1757 sym != NULL ? sym->name : name);
1762 if (k == M_READ && check_namelist (sym))
1768 m = match_etag (&tag_rec, &dt->rec);
1771 m = match_out_tag (&tag_iomsg, &dt->iomsg);
1774 m = match_out_tag (&tag_iostat, &dt->iostat);
1777 m = match_ltag (&tag_err, &dt->err);
1779 dt->err_where = gfc_current_locus;
1782 m = match_etag (&tag_advance, &dt->advance);
1785 m = match_out_tag (&tag_size, &dt->size);
1789 m = match_ltag (&tag_end, &dt->end);
1794 gfc_error ("END tag at %C not allowed in output statement");
1797 dt->end_where = gfc_current_locus;
1802 m = match_ltag (&tag_eor, &dt->eor);
1804 dt->eor_where = gfc_current_locus;
1812 /* Free a data transfer structure and everything below it. */
1815 gfc_free_dt (gfc_dt * dt)
1821 gfc_free_expr (dt->io_unit);
1822 gfc_free_expr (dt->format_expr);
1823 gfc_free_expr (dt->rec);
1824 gfc_free_expr (dt->advance);
1825 gfc_free_expr (dt->iomsg);
1826 gfc_free_expr (dt->iostat);
1827 gfc_free_expr (dt->size);
1833 /* Resolve everything in a gfc_dt structure. */
1836 gfc_resolve_dt (gfc_dt * dt)
1840 RESOLVE_TAG (&tag_format, dt->format_expr);
1841 RESOLVE_TAG (&tag_rec, dt->rec);
1842 RESOLVE_TAG (&tag_advance, dt->advance);
1843 RESOLVE_TAG (&tag_iomsg, dt->iomsg);
1844 RESOLVE_TAG (&tag_iostat, dt->iostat);
1845 RESOLVE_TAG (&tag_size, dt->size);
1848 if (gfc_resolve_expr (e) == SUCCESS
1849 && (e->ts.type != BT_INTEGER
1850 && (e->ts.type != BT_CHARACTER
1851 || e->expr_type != EXPR_VARIABLE)))
1854 ("UNIT specification at %L must be an INTEGER expression or a "
1855 "CHARACTER variable", &e->where);
1859 if (e->ts.type == BT_CHARACTER)
1861 if (gfc_has_vector_index (e))
1863 gfc_error ("Internal unit with vector subscript at %L",
1869 if (e->rank && e->ts.type != BT_CHARACTER)
1871 gfc_error ("External IO UNIT cannot be an array at %L", &e->where);
1877 if (gfc_reference_st_label (dt->err, ST_LABEL_TARGET) == FAILURE)
1879 if (dt->err->defined == ST_LABEL_UNKNOWN)
1881 gfc_error ("ERR tag label %d at %L not defined",
1882 dt->err->value, &dt->err_where);
1889 if (gfc_reference_st_label (dt->end, ST_LABEL_TARGET) == FAILURE)
1891 if (dt->end->defined == ST_LABEL_UNKNOWN)
1893 gfc_error ("END tag label %d at %L not defined",
1894 dt->end->value, &dt->end_where);
1901 if (gfc_reference_st_label (dt->eor, ST_LABEL_TARGET) == FAILURE)
1903 if (dt->eor->defined == ST_LABEL_UNKNOWN)
1905 gfc_error ("EOR tag label %d at %L not defined",
1906 dt->eor->value, &dt->eor_where);
1911 /* Check the format label actually exists. */
1912 if (dt->format_label && dt->format_label != &format_asterisk
1913 && dt->format_label->defined == ST_LABEL_UNKNOWN)
1915 gfc_error ("FORMAT label %d at %L not defined", dt->format_label->value,
1916 &dt->format_label->where);
1923 /* Given an io_kind, return its name. */
1926 io_kind_name (io_kind k)
1945 gfc_internal_error ("io_kind_name(): bad I/O-kind");
1952 /* Match an IO iteration statement of the form:
1954 ( [<IO element> ,] <IO element>, I = <expr>, <expr> [, <expr> ] )
1956 which is equivalent to a single IO element. This function is
1957 mutually recursive with match_io_element(). */
1959 static match match_io_element (io_kind k, gfc_code **);
1962 match_io_iterator (io_kind k, gfc_code ** result)
1964 gfc_code *head, *tail, *new;
1972 old_loc = gfc_current_locus;
1974 if (gfc_match_char ('(') != MATCH_YES)
1977 m = match_io_element (k, &head);
1980 if (m != MATCH_YES || gfc_match_char (',') != MATCH_YES)
1986 /* Can't be anything but an IO iterator. Build a list. */
1987 iter = gfc_get_iterator ();
1991 m = gfc_match_iterator (iter, 0);
1992 if (m == MATCH_ERROR)
1996 gfc_check_do_variable (iter->var->symtree);
2000 m = match_io_element (k, &new);
2001 if (m == MATCH_ERROR)
2010 tail = gfc_append_code (tail, new);
2012 if (gfc_match_char (',') != MATCH_YES)
2021 if (gfc_match_char (')') != MATCH_YES)
2024 new = gfc_get_code ();
2026 new->ext.iterator = iter;
2028 new->block = gfc_get_code ();
2029 new->block->op = EXEC_DO;
2030 new->block->next = head;
2036 gfc_error ("Syntax error in I/O iterator at %C");
2040 gfc_free_iterator (iter, 1);
2041 gfc_free_statements (head);
2042 gfc_current_locus = old_loc;
2047 /* Match a single element of an IO list, which is either a single
2048 expression or an IO Iterator. */
2051 match_io_element (io_kind k, gfc_code ** cpp)
2059 m = match_io_iterator (k, cpp);
2065 m = gfc_match_variable (&expr, 0);
2067 gfc_error ("Expected variable in READ statement at %C");
2071 m = gfc_match_expr (&expr);
2073 gfc_error ("Expected expression in %s statement at %C",
2081 if (expr->symtree->n.sym->attr.intent == INTENT_IN)
2084 ("Variable '%s' in input list at %C cannot be INTENT(IN)",
2085 expr->symtree->n.sym->name);
2090 && gfc_impure_variable (expr->symtree->n.sym)
2091 && current_dt->io_unit->ts.type == BT_CHARACTER)
2093 gfc_error ("Cannot read to variable '%s' in PURE procedure at %C",
2094 expr->symtree->n.sym->name);
2098 if (gfc_check_do_variable (expr->symtree))
2104 if (current_dt->io_unit->ts.type == BT_CHARACTER
2106 && current_dt->io_unit->expr_type == EXPR_VARIABLE
2107 && gfc_impure_variable (current_dt->io_unit->symtree->n.sym))
2110 ("Cannot write to internal file unit '%s' at %C inside a "
2111 "PURE procedure", current_dt->io_unit->symtree->n.sym->name);
2123 gfc_free_expr (expr);
2127 cp = gfc_get_code ();
2128 cp->op = EXEC_TRANSFER;
2136 /* Match an I/O list, building gfc_code structures as we go. */
2139 match_io_list (io_kind k, gfc_code ** head_p)
2141 gfc_code *head, *tail, *new;
2144 *head_p = head = tail = NULL;
2145 if (gfc_match_eos () == MATCH_YES)
2150 m = match_io_element (k, &new);
2151 if (m == MATCH_ERROR)
2156 tail = gfc_append_code (tail, new);
2160 if (gfc_match_eos () == MATCH_YES)
2162 if (gfc_match_char (',') != MATCH_YES)
2170 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
2173 gfc_free_statements (head);
2178 /* Attach the data transfer end node. */
2181 terminate_io (gfc_code * io_code)
2185 if (io_code == NULL)
2186 io_code = new_st.block;
2188 c = gfc_get_code ();
2189 c->op = EXEC_DT_END;
2191 /* Point to structure that is already there */
2192 c->ext.dt = new_st.ext.dt;
2193 gfc_append_code (io_code, c);
2197 /* Check the constraints for a data transfer statement. The majority of the
2198 constraints appearing in 9.4 of the standard appear here. Some are handled
2199 in resolve_tag and others in gfc_resolve_dt. */
2202 check_io_constraints (io_kind k, gfc_dt *dt, gfc_code * io_code, locus * spec_end)
2204 #define io_constraint(condition,msg,arg)\
2207 gfc_error(msg,arg);\
2213 gfc_symbol * sym = NULL;
2218 if (expr && expr->expr_type == EXPR_VARIABLE
2219 && expr->ts.type == BT_CHARACTER)
2221 sym = expr->symtree->n.sym;
2223 io_constraint (k == M_WRITE && sym->attr.intent == INTENT_IN,
2224 "Internal file at %L must not be INTENT(IN)",
2227 io_constraint (gfc_has_vector_index (dt->io_unit),
2228 "Internal file incompatible with vector subscript at %L",
2231 io_constraint (dt->rec != NULL,
2232 "REC tag at %L is incompatible with internal file",
2235 io_constraint (dt->namelist != NULL,
2236 "Internal file at %L is incompatible with namelist",
2239 io_constraint (dt->advance != NULL,
2240 "ADVANCE tag at %L is incompatible with internal file",
2241 &dt->advance->where);
2244 if (expr && expr->ts.type != BT_CHARACTER)
2247 io_constraint (gfc_pure (NULL)
2248 && (k == M_READ || k == M_WRITE),
2249 "IO UNIT in %s statement at %C must be "
2250 "an internal file in a PURE procedure",
2257 io_constraint (dt->end,
2258 "END tag not allowed with output at %L",
2261 io_constraint (dt->eor,
2262 "EOR tag not allowed with output at %L",
2265 io_constraint (k != M_READ && dt->size,
2266 "SIZE=specifier not allowed with output at %L",
2271 io_constraint (dt->size && dt->advance == NULL,
2272 "SIZE tag at %L requires an ADVANCE tag",
2275 io_constraint (dt->eor && dt->advance == NULL,
2276 "EOR tag at %L requires an ADVANCE tag",
2284 io_constraint (io_code && dt->namelist,
2285 "NAMELIST cannot be followed by IO-list at %L",
2288 io_constraint (dt->format_expr,
2289 "IO spec-list cannot contain both NAMELIST group name "
2290 "and format specification at %L.",
2291 &dt->format_expr->where);
2293 io_constraint (dt->format_label,
2294 "IO spec-list cannot contain both NAMELIST group name "
2295 "and format label at %L", spec_end);
2297 io_constraint (dt->rec,
2298 "NAMELIST IO is not allowed with a REC=specifier "
2299 "at %L.", &dt->rec->where);
2301 io_constraint (dt->advance,
2302 "NAMELIST IO is not allowed with a ADVANCE=specifier "
2303 "at %L.", &dt->advance->where);
2308 io_constraint (dt->end,
2309 "An END tag is not allowed with a "
2310 "REC=specifier at %L.", &dt->end_where);
2313 io_constraint (dt->format_label == &format_asterisk,
2314 "FMT=* is not allowed with a REC=specifier "
2315 "at %L.", spec_end);
2320 int not_yes, not_no;
2323 io_constraint (dt->format_label == &format_asterisk,
2324 "List directed format(*) is not allowed with a "
2325 "ADVANCE=specifier at %L.", &expr->where);
2327 if (expr->expr_type == EXPR_CONSTANT && expr->ts.type == BT_CHARACTER)
2329 const char * advance = expr->value.character.string;
2330 not_no = strncasecmp (advance, "no", 2) != 0;
2331 not_yes = strncasecmp (advance, "yes", 2) != 0;
2339 io_constraint (not_no && not_yes,
2340 "ADVANCE=specifier at %L must have value = "
2341 "YES or NO.", &expr->where);
2343 io_constraint (dt->size && not_no && k == M_READ,
2344 "SIZE tag at %L requires an ADVANCE = 'NO'",
2347 io_constraint (dt->eor && not_no && k == M_READ,
2348 "EOR tag at %L requires an ADVANCE = 'NO'",
2352 expr = dt->format_expr;
2353 if (expr != NULL && expr->expr_type == EXPR_CONSTANT)
2354 check_format_string (expr);
2358 #undef io_constraint
2360 /* Match a READ, WRITE or PRINT statement. */
2363 match_io (io_kind k)
2365 char name[GFC_MAX_SYMBOL_LEN + 1];
2374 where = gfc_current_locus;
2376 current_dt = dt = gfc_getmem (sizeof (gfc_dt));
2377 if (gfc_match_char ('(') == MATCH_NO)
2379 where = gfc_current_locus;
2382 else if (k == M_PRINT)
2384 /* Treat the non-standard case of PRINT namelist. */
2385 if ((gfc_current_form == FORM_FIXED || gfc_peek_char () == ' ')
2386 && gfc_match_name (name) == MATCH_YES)
2388 gfc_find_symbol (name, NULL, 1, &sym);
2389 if (sym && sym->attr.flavor == FL_NAMELIST)
2391 if (gfc_notify_std (GFC_STD_GNU, "PRINT namelist at "
2392 "%C is an extension") == FAILURE)
2398 dt->io_unit = default_unit (k);
2403 gfc_current_locus = where;
2407 if (gfc_current_form == FORM_FREE)
2409 c = gfc_peek_char();
2410 if (c != ' ' && c != '*' && c != '\'' && c != '"')
2417 m = match_dt_format (dt);
2418 if (m == MATCH_ERROR)
2424 dt->io_unit = default_unit (k);
2428 /* Match a control list */
2429 if (match_dt_element (k, dt) == MATCH_YES)
2431 if (match_dt_unit (k, dt) != MATCH_YES)
2434 if (gfc_match_char (')') == MATCH_YES)
2436 if (gfc_match_char (',') != MATCH_YES)
2439 m = match_dt_element (k, dt);
2442 if (m == MATCH_ERROR)
2445 m = match_dt_format (dt);
2448 if (m == MATCH_ERROR)
2451 where = gfc_current_locus;
2453 m = gfc_match_name (name);
2456 gfc_find_symbol (name, NULL, 1, &sym);
2457 if (sym && sym->attr.flavor == FL_NAMELIST)
2460 if (k == M_READ && check_namelist (sym))
2469 gfc_current_locus = where;
2471 goto loop; /* No matches, try regular elements */
2474 if (gfc_match_char (')') == MATCH_YES)
2476 if (gfc_match_char (',') != MATCH_YES)
2482 m = match_dt_element (k, dt);
2485 if (m == MATCH_ERROR)
2488 if (gfc_match_char (')') == MATCH_YES)
2490 if (gfc_match_char (',') != MATCH_YES)
2496 /* Used in check_io_constraints, where no locus is available. */
2497 spec_end = gfc_current_locus;
2499 /* Optional leading comma (non-standard). */
2501 && gfc_match_char (',') == MATCH_YES
2503 && gfc_notify_std (GFC_STD_GNU, "Extension: Comma before output "
2504 "item list at %C is an extension") == FAILURE)
2508 if (gfc_match_eos () != MATCH_YES)
2510 if (comma_flag && gfc_match_char (',') != MATCH_YES)
2512 gfc_error ("Expected comma in I/O list at %C");
2517 m = match_io_list (k, &io_code);
2518 if (m == MATCH_ERROR)
2524 /* A full IO statement has been matched. Check the constraints. spec_end is
2525 supplied for cases where no locus is supplied. */
2526 m = check_io_constraints (k, dt, io_code, &spec_end);
2528 if (m == MATCH_ERROR)
2531 new_st.op = (k == M_READ) ? EXEC_READ : EXEC_WRITE;
2533 new_st.block = gfc_get_code ();
2534 new_st.block->op = new_st.op;
2535 new_st.block->next = io_code;
2537 terminate_io (io_code);
2542 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
2552 gfc_match_read (void)
2554 return match_io (M_READ);
2558 gfc_match_write (void)
2560 return match_io (M_WRITE);
2564 gfc_match_print (void)
2568 m = match_io (M_PRINT);
2572 if (gfc_pure (NULL))
2574 gfc_error ("PRINT statement at %C not allowed within PURE procedure");
2582 /* Free a gfc_inquire structure. */
2585 gfc_free_inquire (gfc_inquire * inquire)
2588 if (inquire == NULL)
2591 gfc_free_expr (inquire->unit);
2592 gfc_free_expr (inquire->file);
2593 gfc_free_expr (inquire->iomsg);
2594 gfc_free_expr (inquire->iostat);
2595 gfc_free_expr (inquire->exist);
2596 gfc_free_expr (inquire->opened);
2597 gfc_free_expr (inquire->number);
2598 gfc_free_expr (inquire->named);
2599 gfc_free_expr (inquire->name);
2600 gfc_free_expr (inquire->access);
2601 gfc_free_expr (inquire->sequential);
2602 gfc_free_expr (inquire->direct);
2603 gfc_free_expr (inquire->form);
2604 gfc_free_expr (inquire->formatted);
2605 gfc_free_expr (inquire->unformatted);
2606 gfc_free_expr (inquire->recl);
2607 gfc_free_expr (inquire->nextrec);
2608 gfc_free_expr (inquire->blank);
2609 gfc_free_expr (inquire->position);
2610 gfc_free_expr (inquire->action);
2611 gfc_free_expr (inquire->read);
2612 gfc_free_expr (inquire->write);
2613 gfc_free_expr (inquire->readwrite);
2614 gfc_free_expr (inquire->delim);
2615 gfc_free_expr (inquire->pad);
2616 gfc_free_expr (inquire->iolength);
2617 gfc_free_expr (inquire->convert);
2623 /* Match an element of an INQUIRE statement. */
2625 #define RETM if (m != MATCH_NO) return m;
2628 match_inquire_element (gfc_inquire * inquire)
2632 m = match_etag (&tag_unit, &inquire->unit);
2633 RETM m = match_etag (&tag_file, &inquire->file);
2634 RETM m = match_ltag (&tag_err, &inquire->err);
2635 RETM m = match_out_tag (&tag_iomsg, &inquire->iomsg);
2636 RETM m = match_out_tag (&tag_iostat, &inquire->iostat);
2637 RETM m = match_vtag (&tag_exist, &inquire->exist);
2638 RETM m = match_vtag (&tag_opened, &inquire->opened);
2639 RETM m = match_vtag (&tag_named, &inquire->named);
2640 RETM m = match_vtag (&tag_name, &inquire->name);
2641 RETM m = match_out_tag (&tag_number, &inquire->number);
2642 RETM m = match_vtag (&tag_s_access, &inquire->access);
2643 RETM m = match_vtag (&tag_sequential, &inquire->sequential);
2644 RETM m = match_vtag (&tag_direct, &inquire->direct);
2645 RETM m = match_vtag (&tag_s_form, &inquire->form);
2646 RETM m = match_vtag (&tag_formatted, &inquire->formatted);
2647 RETM m = match_vtag (&tag_unformatted, &inquire->unformatted);
2648 RETM m = match_out_tag (&tag_s_recl, &inquire->recl);
2649 RETM m = match_out_tag (&tag_nextrec, &inquire->nextrec);
2650 RETM m = match_vtag (&tag_s_blank, &inquire->blank);
2651 RETM m = match_vtag (&tag_s_position, &inquire->position);
2652 RETM m = match_vtag (&tag_s_action, &inquire->action);
2653 RETM m = match_vtag (&tag_read, &inquire->read);
2654 RETM m = match_vtag (&tag_write, &inquire->write);
2655 RETM m = match_vtag (&tag_readwrite, &inquire->readwrite);
2656 RETM m = match_vtag (&tag_s_delim, &inquire->delim);
2657 RETM m = match_vtag (&tag_s_pad, &inquire->pad);
2658 RETM m = match_vtag (&tag_iolength, &inquire->iolength);
2659 RETM m = match_vtag (&tag_convert, &inquire->convert);
2660 RETM return MATCH_NO;
2667 gfc_match_inquire (void)
2669 gfc_inquire *inquire;
2674 m = gfc_match_char ('(');
2678 inquire = gfc_getmem (sizeof (gfc_inquire));
2680 loc = gfc_current_locus;
2682 m = match_inquire_element (inquire);
2683 if (m == MATCH_ERROR)
2687 m = gfc_match_expr (&inquire->unit);
2688 if (m == MATCH_ERROR)
2694 /* See if we have the IOLENGTH form of the inquire statement. */
2695 if (inquire->iolength != NULL)
2697 if (gfc_match_char (')') != MATCH_YES)
2700 m = match_io_list (M_INQUIRE, &code);
2701 if (m == MATCH_ERROR)
2706 new_st.op = EXEC_IOLENGTH;
2707 new_st.expr = inquire->iolength;
2708 new_st.ext.inquire = inquire;
2710 if (gfc_pure (NULL))
2712 gfc_free_statements (code);
2713 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
2717 new_st.block = gfc_get_code ();
2718 new_st.block->op = EXEC_IOLENGTH;
2719 terminate_io (code);
2720 new_st.block->next = code;
2724 /* At this point, we have the non-IOLENGTH inquire statement. */
2727 if (gfc_match_char (')') == MATCH_YES)
2729 if (gfc_match_char (',') != MATCH_YES)
2732 m = match_inquire_element (inquire);
2733 if (m == MATCH_ERROR)
2738 if (inquire->iolength != NULL)
2740 gfc_error ("IOLENGTH tag invalid in INQUIRE statement at %C");
2745 if (gfc_match_eos () != MATCH_YES)
2748 if (inquire->unit != NULL && inquire->file != NULL)
2750 gfc_error ("INQUIRE statement at %L cannot contain both FILE and"
2751 " UNIT specifiers", &loc);
2755 if (inquire->unit == NULL && inquire->file == NULL)
2757 gfc_error ("INQUIRE statement at %L requires either FILE or"
2758 " UNIT specifier", &loc);
2762 if (gfc_pure (NULL))
2764 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
2768 new_st.op = EXEC_INQUIRE;
2769 new_st.ext.inquire = inquire;
2773 gfc_syntax_error (ST_INQUIRE);
2776 gfc_free_inquire (inquire);
2781 /* Resolve everything in a gfc_inquire structure. */
2784 gfc_resolve_inquire (gfc_inquire * inquire)
2787 RESOLVE_TAG (&tag_unit, inquire->unit);
2788 RESOLVE_TAG (&tag_file, inquire->file);
2789 RESOLVE_TAG (&tag_iomsg, inquire->iomsg);
2790 RESOLVE_TAG (&tag_iostat, inquire->iostat);
2791 RESOLVE_TAG (&tag_exist, inquire->exist);
2792 RESOLVE_TAG (&tag_opened, inquire->opened);
2793 RESOLVE_TAG (&tag_number, inquire->number);
2794 RESOLVE_TAG (&tag_named, inquire->named);
2795 RESOLVE_TAG (&tag_name, inquire->name);
2796 RESOLVE_TAG (&tag_s_access, inquire->access);
2797 RESOLVE_TAG (&tag_sequential, inquire->sequential);
2798 RESOLVE_TAG (&tag_direct, inquire->direct);
2799 RESOLVE_TAG (&tag_s_form, inquire->form);
2800 RESOLVE_TAG (&tag_formatted, inquire->formatted);
2801 RESOLVE_TAG (&tag_unformatted, inquire->unformatted);
2802 RESOLVE_TAG (&tag_s_recl, inquire->recl);
2803 RESOLVE_TAG (&tag_nextrec, inquire->nextrec);
2804 RESOLVE_TAG (&tag_s_blank, inquire->blank);
2805 RESOLVE_TAG (&tag_s_position, inquire->position);
2806 RESOLVE_TAG (&tag_s_action, inquire->action);
2807 RESOLVE_TAG (&tag_read, inquire->read);
2808 RESOLVE_TAG (&tag_write, inquire->write);
2809 RESOLVE_TAG (&tag_readwrite, inquire->readwrite);
2810 RESOLVE_TAG (&tag_s_delim, inquire->delim);
2811 RESOLVE_TAG (&tag_s_pad, inquire->pad);
2812 RESOLVE_TAG (&tag_iolength, inquire->iolength);
2813 RESOLVE_TAG (&tag_convert, inquire->convert);
2815 if (gfc_reference_st_label (inquire->err, ST_LABEL_TARGET) == FAILURE)