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_spos = {"POSITION", " pos = %e", BT_INTEGER},
56 tag_format = {"FORMAT", NULL, BT_CHARACTER},
57 tag_iomsg = {"IOMSG", " iomsg = %e", BT_CHARACTER},
58 tag_iostat = {"IOSTAT", " iostat = %v", BT_INTEGER},
59 tag_size = {"SIZE", " size = %v", BT_INTEGER},
60 tag_exist = {"EXIST", " exist = %v", BT_LOGICAL},
61 tag_opened = {"OPENED", " opened = %v", BT_LOGICAL},
62 tag_named = {"NAMED", " named = %v", BT_LOGICAL},
63 tag_name = {"NAME", " name = %v", BT_CHARACTER},
64 tag_number = {"NUMBER", " number = %v", BT_INTEGER},
65 tag_s_access = {"ACCESS", " access = %v", BT_CHARACTER},
66 tag_sequential = {"SEQUENTIAL", " sequential = %v", BT_CHARACTER},
67 tag_direct = {"DIRECT", " direct = %v", BT_CHARACTER},
68 tag_s_form = {"FORM", " form = %v", BT_CHARACTER},
69 tag_formatted = {"FORMATTED", " formatted = %v", BT_CHARACTER},
70 tag_unformatted = {"UNFORMATTED", " unformatted = %v", BT_CHARACTER},
71 tag_s_recl = {"RECL", " recl = %v", BT_INTEGER},
72 tag_nextrec = {"NEXTREC", " nextrec = %v", BT_INTEGER},
73 tag_s_blank = {"BLANK", " blank = %v", BT_CHARACTER},
74 tag_s_position = {"POSITION", " position = %v", BT_CHARACTER},
75 tag_s_action = {"ACTION", " action = %v", BT_CHARACTER},
76 tag_read = {"READ", " read = %v", BT_CHARACTER},
77 tag_write = {"WRITE", " write = %v", BT_CHARACTER},
78 tag_readwrite = {"READWRITE", " readwrite = %v", BT_CHARACTER},
79 tag_s_delim = {"DELIM", " delim = %v", BT_CHARACTER},
80 tag_s_pad = {"PAD", " pad = %v", BT_CHARACTER},
81 tag_iolength = {"IOLENGTH", " iolength = %v", BT_INTEGER},
82 tag_convert = {"CONVERT", " convert = %e", BT_CHARACTER},
83 tag_strm_out = {"POS", " pos = %v", BT_INTEGER},
84 tag_err = {"ERR", " err = %l", BT_UNKNOWN},
85 tag_end = {"END", " end = %l", BT_UNKNOWN},
86 tag_eor = {"EOR", " eor = %l", BT_UNKNOWN};
88 static gfc_dt *current_dt;
90 #define RESOLVE_TAG(x, y) if (resolve_tag(x, y) == FAILURE) return FAILURE;
93 /**************** Fortran 95 FORMAT parser *****************/
95 /* FORMAT tokens returned by format_lex(). */
98 FMT_NONE, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
99 FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_POS, FMT_LPAREN,
100 FMT_RPAREN, FMT_X, FMT_SIGN, FMT_BLANK, FMT_CHAR, FMT_P, FMT_IBOZ, FMT_F,
101 FMT_E, FMT_EXT, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END
105 /* Local variables for checking format strings. The saved_token is
106 used to back up by a single format token during the parsing
108 static char *format_string;
109 static int format_length, use_last_char;
111 static format_token saved_token;
114 { MODE_STRING, MODE_FORMAT, MODE_COPY }
118 /* Return the next character in the format string. */
121 next_char (int in_string)
133 if (mode == MODE_STRING)
134 c = *format_string++;
137 c = gfc_next_char_literal (in_string);
141 if (mode == MODE_COPY)
142 *format_string++ = c;
150 /* Back up one character position. Only works once. */
159 /* Eat up the spaces and return a character. */
162 next_char_not_space(void)
169 while (gfc_is_whitespace (c));
173 static int value = 0;
175 /* Simple lexical analyzer for getting the next token in a FORMAT
186 if (saved_token != FMT_NONE)
189 saved_token = FMT_NONE;
193 c = next_char_not_space ();
201 c = next_char_not_space ();
212 c = next_char_not_space ();
214 value = 10 * value + c - '0';
223 token = FMT_SIGNED_INT;
242 c = next_char_not_space ();
246 value = 10 * value + c - '0';
251 token = zflag ? FMT_ZERO : FMT_POSINT;
275 c = next_char_not_space ();
276 if (c != 'L' && c != 'R')
295 c = next_char_not_space ();
296 if (c != 'P' && c != 'S')
303 c = next_char_not_space ();
304 if (c == 'N' || c == 'Z')
365 c = next_char_not_space ();
366 if (c == 'N' || c == 'S')
409 /* Check a format statement. The format string, either from a FORMAT
410 statement or a constant in an I/O statement has already been parsed
411 by itself, and we are checking it for validity. The dual origin
412 means that the warning message is a little less than great. */
417 const char *posint_required = _("Positive width required");
418 const char *nonneg_required = _("Nonnegative width required");
419 const char *unexpected_element = _("Unexpected element");
420 const char *unexpected_end = _("Unexpected end of format string");
429 saved_token = FMT_NONE;
437 error = _("Missing leading left parenthesis");
443 goto finished; /* Empty format is legal */
447 /* In this state, the next thing has to be a format item. */
471 /* Signed integer can only precede a P format. */
475 error = _("Expected P edit descriptor");
482 /* P requires a prior number. */
483 error = _("P descriptor requires leading scale factor");
487 /* X requires a prior number if we're being pedantic. */
488 if (gfc_notify_std (GFC_STD_GNU, "Extension: X descriptor "
489 "requires leading space count at %C")
499 goto extension_optional_comma;
508 if (gfc_notify_std (GFC_STD_GNU, "Extension: $ descriptor at %C")
511 if (t != FMT_RPAREN || level > 0)
513 error = _("$ must be the last specifier");
534 error = unexpected_end;
538 error = unexpected_element;
543 /* In this state, t must currently be a data descriptor.
544 Deal with things that can/must follow the descriptor. */
558 error = _("Repeat count cannot follow P descriptor");
573 switch (gfc_notification_std (GFC_STD_GNU))
577 ("Extension: Missing positive width after L descriptor at %C");
582 error = posint_required;
607 error = posint_required;
614 /* Warn if -std=legacy, otherwise error. */
615 if (gfc_option.warn_std != 0)
616 gfc_error_now ("Period required in format specifier at %C");
618 gfc_warning ("Period required in format specifier at %C");
624 if (u != FMT_ZERO && u != FMT_POSINT)
626 error = nonneg_required;
633 /* Look for optional exponent. */
644 error = _("Positive exponent width required");
653 if (t != FMT_ZERO && t != FMT_POSINT)
655 error = nonneg_required;
662 /* Warn if -std=legacy, otherwise error. */
663 if (gfc_option.warn_std != 0)
664 gfc_error_now ("Period required in format specifier at %C");
666 gfc_warning ("Period required in format specifier at %C");
672 if (t != FMT_ZERO && t != FMT_POSINT)
674 error = nonneg_required;
681 if(mode == MODE_STRING)
683 format_string += value;
684 format_length -= value;
698 if (t != FMT_ZERO && t != FMT_POSINT)
700 error = nonneg_required;
712 if (t != FMT_ZERO && t != FMT_POSINT)
714 error = nonneg_required;
722 error = unexpected_element;
727 /* Between a descriptor and what comes next. */
746 error = unexpected_end;
750 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
757 /* Optional comma is a weird between state where we've just finished
758 reading a colon, slash or P descriptor. */
772 /* Assume that we have another format item. */
779 extension_optional_comma:
780 /* As a GNU extension, permit a missing comma after a string literal. */
798 error = unexpected_end;
802 if (gfc_notify_std (GFC_STD_GNU, "Extension: Missing comma at %C")
812 /* Something went wrong. If the format we're checking is a string,
813 generate a warning, since the program is correct. If the format
814 is in a FORMAT statement, this messes up parsing, which is an
816 if (mode != MODE_STRING)
817 gfc_error ("%s in format string at %C", error);
820 gfc_warning ("%s in format string at %C", error);
822 /* TODO: More elaborate measures are needed to show where a problem
823 is within a format string that has been calculated. */
833 /* Given an expression node that is a constant string, see if it looks
834 like a format string. */
837 check_format_string (gfc_expr * e)
841 format_string = e->value.character.string;
846 /************ Fortran 95 I/O statement matchers *************/
848 /* Match a FORMAT statement. This amounts to actually parsing the
849 format descriptors in order to correctly locate the end of the
853 gfc_match_format (void)
858 if (gfc_current_ns->proc_name
859 && gfc_current_ns->proc_name->attr.flavor == FL_MODULE)
861 gfc_error ("Format statement in module main block at %C.");
865 if (gfc_statement_label == NULL)
867 gfc_error ("Missing format label at %C");
870 gfc_gobble_whitespace ();
875 start = gfc_current_locus;
877 if (check_format () == FAILURE)
880 if (gfc_match_eos () != MATCH_YES)
882 gfc_syntax_error (ST_FORMAT);
886 /* The label doesn't get created until after the statement is done
887 being matched, so we have to leave the string for later. */
889 gfc_current_locus = start; /* Back to the beginning */
892 new_st.op = EXEC_NOP;
895 e->expr_type = EXPR_CONSTANT;
896 e->ts.type = BT_CHARACTER;
897 e->ts.kind = gfc_default_character_kind;
899 e->value.character.string = format_string = gfc_getmem(format_length+1);
900 e->value.character.length = format_length;
901 gfc_statement_label->format = e;
904 check_format (); /* Guaranteed to succeed */
905 gfc_match_eos (); /* Guaranteed to succeed */
911 /* Match an expression I/O tag of some sort. */
914 match_etag (const io_tag * tag, gfc_expr ** v)
919 m = gfc_match (tag->spec, &result);
925 gfc_error ("Duplicate %s specification at %C", tag->name);
926 gfc_free_expr (result);
935 /* Match a variable I/O tag of some sort. */
938 match_vtag (const io_tag * tag, gfc_expr ** v)
943 m = gfc_match (tag->spec, &result);
949 gfc_error ("Duplicate %s specification at %C", tag->name);
950 gfc_free_expr (result);
954 if (result->symtree->n.sym->attr.intent == INTENT_IN)
956 gfc_error ("Variable tag cannot be INTENT(IN) at %C");
957 gfc_free_expr (result);
961 if (gfc_pure (NULL) && gfc_impure_variable (result->symtree->n.sym))
963 gfc_error ("Variable tag cannot be assigned in PURE procedure at %C");
964 gfc_free_expr (result);
973 /* Match I/O tags that cause variables to become redefined. */
976 match_out_tag(const io_tag *tag, gfc_expr **result)
980 m = match_vtag(tag, result);
982 gfc_check_do_variable((*result)->symtree);
988 /* Match a label I/O tag. */
991 match_ltag (const io_tag * tag, gfc_st_label ** label)
997 m = gfc_match (tag->spec, label);
998 if (m == MATCH_YES && old != 0)
1000 gfc_error ("Duplicate %s label specification at %C", tag->name);
1005 && gfc_reference_st_label (*label, ST_LABEL_TARGET) == FAILURE)
1012 /* Do expression resolution and type-checking on an expression tag. */
1015 resolve_tag (const io_tag * tag, gfc_expr * e)
1021 if (gfc_resolve_expr (e) == FAILURE)
1024 if (e->ts.type != tag->type && tag != &tag_format)
1026 gfc_error ("%s tag at %L must be of type %s", tag->name,
1027 &e->where, gfc_basic_typename (tag->type));
1031 if (tag == &tag_format)
1033 if (e->expr_type == EXPR_CONSTANT
1034 && (e->ts.type != BT_CHARACTER
1035 || e->ts.kind != gfc_default_character_kind))
1037 gfc_error ("Constant expression in FORMAT tag at %L must be "
1038 "of type default CHARACTER", &e->where);
1042 /* If e's rank is zero and e is not an element of an array, it should be
1043 of integer or character type. The integer variable should be
1045 if (e->symtree == NULL || e->symtree->n.sym->as == NULL
1046 || e->symtree->n.sym->as->rank == 0)
1048 if (e->ts.type != BT_CHARACTER && e->ts.type != BT_INTEGER)
1050 gfc_error ("%s tag at %L must be of type %s or %s", tag->name,
1051 &e->where, gfc_basic_typename (BT_CHARACTER),
1052 gfc_basic_typename (BT_INTEGER));
1055 else if (e->ts.type == BT_INTEGER && e->expr_type == EXPR_VARIABLE)
1057 if (gfc_notify_std (GFC_STD_F95_DEL,
1058 "Obsolete: ASSIGNED variable in FORMAT tag at %L",
1059 &e->where) == FAILURE)
1061 if (e->symtree->n.sym->attr.assign != 1)
1063 gfc_error ("Variable '%s' at %L has not been assigned a "
1064 "format label", e->symtree->n.sym->name, &e->where);
1068 else if (e->ts.type == BT_INTEGER)
1070 gfc_error ("scalar '%s' FORMAT tag at %L is not an ASSIGNED "
1071 "variable", gfc_basic_typename (e->ts.type), &e->where);
1079 /* if rank is nonzero, we allow the type to be character under
1080 GFC_STD_GNU and other type under GFC_STD_LEGACY. It may be
1081 assigned an Hollerith constant. */
1082 if (e->ts.type == BT_CHARACTER)
1084 if (gfc_notify_std (GFC_STD_GNU,
1085 "Extension: Character array in FORMAT tag at %L",
1086 &e->where) == FAILURE)
1091 if (gfc_notify_std (GFC_STD_LEGACY,
1092 "Extension: Non-character in FORMAT tag at %L",
1093 &e->where) == FAILURE)
1103 gfc_error ("%s tag at %L must be scalar", tag->name, &e->where);
1107 if (tag == &tag_iomsg)
1109 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: IOMSG tag at %L",
1110 &e->where) == FAILURE)
1114 if (tag == &tag_iostat && e->ts.kind != gfc_default_integer_kind)
1116 if (gfc_notify_std (GFC_STD_GNU, "Fortran 95 requires default "
1117 "INTEGER in IOSTAT tag at %L",
1118 &e->where) == FAILURE)
1122 if (tag == &tag_size && e->ts.kind != gfc_default_integer_kind)
1124 if (gfc_notify_std (GFC_STD_GNU, "Fortran 95 requires default "
1125 "INTEGER in SIZE tag at %L",
1126 &e->where) == FAILURE)
1130 if (tag == &tag_convert)
1132 if (gfc_notify_std (GFC_STD_GNU, "Extension: CONVERT tag at %L",
1133 &e->where) == FAILURE)
1142 /* Match a single tag of an OPEN statement. */
1145 match_open_element (gfc_open * open)
1149 m = match_etag (&tag_unit, &open->unit);
1152 m = match_out_tag (&tag_iomsg, &open->iomsg);
1155 m = match_out_tag (&tag_iostat, &open->iostat);
1158 m = match_etag (&tag_file, &open->file);
1161 m = match_etag (&tag_status, &open->status);
1164 m = match_etag (&tag_e_access, &open->access);
1167 m = match_etag (&tag_e_form, &open->form);
1170 m = match_etag (&tag_e_recl, &open->recl);
1173 m = match_etag (&tag_e_blank, &open->blank);
1176 m = match_etag (&tag_e_position, &open->position);
1179 m = match_etag (&tag_e_action, &open->action);
1182 m = match_etag (&tag_e_delim, &open->delim);
1185 m = match_etag (&tag_e_pad, &open->pad);
1188 m = match_ltag (&tag_err, &open->err);
1191 m = match_etag (&tag_convert, &open->convert);
1199 /* Free the gfc_open structure and all the expressions it contains. */
1202 gfc_free_open (gfc_open * open)
1208 gfc_free_expr (open->unit);
1209 gfc_free_expr (open->iomsg);
1210 gfc_free_expr (open->iostat);
1211 gfc_free_expr (open->file);
1212 gfc_free_expr (open->status);
1213 gfc_free_expr (open->access);
1214 gfc_free_expr (open->form);
1215 gfc_free_expr (open->recl);
1216 gfc_free_expr (open->blank);
1217 gfc_free_expr (open->position);
1218 gfc_free_expr (open->action);
1219 gfc_free_expr (open->delim);
1220 gfc_free_expr (open->pad);
1221 gfc_free_expr (open->convert);
1227 /* Resolve everything in a gfc_open structure. */
1230 gfc_resolve_open (gfc_open * open)
1233 RESOLVE_TAG (&tag_unit, open->unit);
1234 RESOLVE_TAG (&tag_iomsg, open->iomsg);
1235 RESOLVE_TAG (&tag_iostat, open->iostat);
1236 RESOLVE_TAG (&tag_file, open->file);
1237 RESOLVE_TAG (&tag_status, open->status);
1238 RESOLVE_TAG (&tag_e_access, open->access);
1239 RESOLVE_TAG (&tag_e_form, open->form);
1240 RESOLVE_TAG (&tag_e_recl, open->recl);
1242 RESOLVE_TAG (&tag_e_blank, open->blank);
1243 RESOLVE_TAG (&tag_e_position, open->position);
1244 RESOLVE_TAG (&tag_e_action, open->action);
1245 RESOLVE_TAG (&tag_e_delim, open->delim);
1246 RESOLVE_TAG (&tag_e_pad, open->pad);
1247 RESOLVE_TAG (&tag_convert, open->convert);
1249 if (gfc_reference_st_label (open->err, ST_LABEL_TARGET) == FAILURE)
1256 /* Match an OPEN statement. */
1259 gfc_match_open (void)
1264 m = gfc_match_char ('(');
1268 open = gfc_getmem (sizeof (gfc_open));
1270 m = match_open_element (open);
1272 if (m == MATCH_ERROR)
1276 m = gfc_match_expr (&open->unit);
1279 if (m == MATCH_ERROR)
1285 if (gfc_match_char (')') == MATCH_YES)
1287 if (gfc_match_char (',') != MATCH_YES)
1290 m = match_open_element (open);
1291 if (m == MATCH_ERROR)
1297 if (gfc_match_eos () == MATCH_NO)
1300 if (gfc_pure (NULL))
1302 gfc_error ("OPEN statement not allowed in PURE procedure at %C");
1306 new_st.op = EXEC_OPEN;
1307 new_st.ext.open = open;
1311 gfc_syntax_error (ST_OPEN);
1314 gfc_free_open (open);
1319 /* Free a gfc_close structure an all its expressions. */
1322 gfc_free_close (gfc_close * close)
1328 gfc_free_expr (close->unit);
1329 gfc_free_expr (close->iomsg);
1330 gfc_free_expr (close->iostat);
1331 gfc_free_expr (close->status);
1337 /* Match elements of a CLOSE statement. */
1340 match_close_element (gfc_close * close)
1344 m = match_etag (&tag_unit, &close->unit);
1347 m = match_etag (&tag_status, &close->status);
1350 m = match_out_tag (&tag_iomsg, &close->iomsg);
1353 m = match_out_tag (&tag_iostat, &close->iostat);
1356 m = match_ltag (&tag_err, &close->err);
1364 /* Match a CLOSE statement. */
1367 gfc_match_close (void)
1372 m = gfc_match_char ('(');
1376 close = gfc_getmem (sizeof (gfc_close));
1378 m = match_close_element (close);
1380 if (m == MATCH_ERROR)
1384 m = gfc_match_expr (&close->unit);
1387 if (m == MATCH_ERROR)
1393 if (gfc_match_char (')') == MATCH_YES)
1395 if (gfc_match_char (',') != MATCH_YES)
1398 m = match_close_element (close);
1399 if (m == MATCH_ERROR)
1405 if (gfc_match_eos () == MATCH_NO)
1408 if (gfc_pure (NULL))
1410 gfc_error ("CLOSE statement not allowed in PURE procedure at %C");
1414 new_st.op = EXEC_CLOSE;
1415 new_st.ext.close = close;
1419 gfc_syntax_error (ST_CLOSE);
1422 gfc_free_close (close);
1427 /* Resolve everything in a gfc_close structure. */
1430 gfc_resolve_close (gfc_close * close)
1433 RESOLVE_TAG (&tag_unit, close->unit);
1434 RESOLVE_TAG (&tag_iomsg, close->iomsg);
1435 RESOLVE_TAG (&tag_iostat, close->iostat);
1436 RESOLVE_TAG (&tag_status, close->status);
1438 if (gfc_reference_st_label (close->err, ST_LABEL_TARGET) == FAILURE)
1445 /* Free a gfc_filepos structure. */
1448 gfc_free_filepos (gfc_filepos * fp)
1451 gfc_free_expr (fp->unit);
1452 gfc_free_expr (fp->iomsg);
1453 gfc_free_expr (fp->iostat);
1458 /* Match elements of a REWIND, BACKSPACE, ENDFILE, or FLUSH statement. */
1461 match_file_element (gfc_filepos * fp)
1465 m = match_etag (&tag_unit, &fp->unit);
1468 m = match_out_tag (&tag_iomsg, &fp->iomsg);
1471 m = match_out_tag (&tag_iostat, &fp->iostat);
1474 m = match_ltag (&tag_err, &fp->err);
1482 /* Match the second half of the file-positioning statements, REWIND,
1483 BACKSPACE, ENDFILE, or the FLUSH statement. */
1486 match_filepos (gfc_statement st, gfc_exec_op op)
1491 fp = gfc_getmem (sizeof (gfc_filepos));
1493 if (gfc_match_char ('(') == MATCH_NO)
1495 m = gfc_match_expr (&fp->unit);
1496 if (m == MATCH_ERROR)
1504 m = match_file_element (fp);
1505 if (m == MATCH_ERROR)
1509 m = gfc_match_expr (&fp->unit);
1510 if (m == MATCH_ERROR)
1518 if (gfc_match_char (')') == MATCH_YES)
1520 if (gfc_match_char (',') != MATCH_YES)
1523 m = match_file_element (fp);
1524 if (m == MATCH_ERROR)
1531 if (gfc_match_eos () != MATCH_YES)
1534 if (gfc_pure (NULL))
1536 gfc_error ("%s statement not allowed in PURE procedure at %C",
1537 gfc_ascii_statement (st));
1543 new_st.ext.filepos = fp;
1547 gfc_syntax_error (st);
1550 gfc_free_filepos (fp);
1556 gfc_resolve_filepos (gfc_filepos * fp)
1559 RESOLVE_TAG (&tag_unit, fp->unit);
1560 RESOLVE_TAG (&tag_iostat, fp->iostat);
1561 RESOLVE_TAG (&tag_iomsg, fp->iomsg);
1562 if (gfc_reference_st_label (fp->err, ST_LABEL_TARGET) == FAILURE)
1569 /* Match the file positioning statements: ENDFILE, BACKSPACE, REWIND,
1570 and the FLUSH statement. */
1573 gfc_match_endfile (void)
1576 return match_filepos (ST_END_FILE, EXEC_ENDFILE);
1580 gfc_match_backspace (void)
1583 return match_filepos (ST_BACKSPACE, EXEC_BACKSPACE);
1587 gfc_match_rewind (void)
1590 return match_filepos (ST_REWIND, EXEC_REWIND);
1594 gfc_match_flush (void)
1596 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: FLUSH statement at %C") == FAILURE)
1599 return match_filepos (ST_FLUSH, EXEC_FLUSH);
1602 /******************** Data Transfer Statements *********************/
1605 { M_READ, M_WRITE, M_PRINT, M_INQUIRE }
1609 /* Return a default unit number. */
1612 default_unit (io_kind k)
1621 return gfc_int_expr (unit);
1625 /* Match a unit specification for a data transfer statement. */
1628 match_dt_unit (io_kind k, gfc_dt * dt)
1632 if (gfc_match_char ('*') == MATCH_YES)
1634 if (dt->io_unit != NULL)
1637 dt->io_unit = default_unit (k);
1641 if (gfc_match_expr (&e) == MATCH_YES)
1643 if (dt->io_unit != NULL)
1656 gfc_error ("Duplicate UNIT specification at %C");
1661 /* Match a format specification. */
1664 match_dt_format (gfc_dt * dt)
1668 gfc_st_label *label;
1670 where = gfc_current_locus;
1672 if (gfc_match_char ('*') == MATCH_YES)
1674 if (dt->format_expr != NULL || dt->format_label != NULL)
1677 dt->format_label = &format_asterisk;
1681 if (gfc_match_st_label (&label) == MATCH_YES)
1683 if (dt->format_expr != NULL || dt->format_label != NULL)
1685 gfc_free_st_label (label);
1689 if (gfc_reference_st_label (label, ST_LABEL_FORMAT) == FAILURE)
1692 dt->format_label = label;
1696 if (gfc_match_expr (&e) == MATCH_YES)
1698 if (dt->format_expr != NULL || dt->format_label != NULL)
1703 dt->format_expr = e;
1707 gfc_current_locus = where; /* The only case where we have to restore */
1712 gfc_error ("Duplicate format specification at %C");
1717 /* Traverse a namelist that is part of a READ statement to make sure
1718 that none of the variables in the namelist are INTENT(IN). Returns
1719 nonzero if we find such a variable. */
1722 check_namelist (gfc_symbol * sym)
1726 for (p = sym->namelist; p; p = p->next)
1727 if (p->sym->attr.intent == INTENT_IN)
1729 gfc_error ("Symbol '%s' in namelist '%s' is INTENT(IN) at %C",
1730 p->sym->name, sym->name);
1738 /* Match a single data transfer element. */
1741 match_dt_element (io_kind k, gfc_dt * dt)
1743 char name[GFC_MAX_SYMBOL_LEN + 1];
1747 if (gfc_match (" unit =") == MATCH_YES)
1749 m = match_dt_unit (k, dt);
1754 if (gfc_match (" fmt =") == MATCH_YES)
1756 m = match_dt_format (dt);
1761 if (gfc_match (" nml = %n", name) == MATCH_YES)
1763 if (dt->namelist != NULL)
1765 gfc_error ("Duplicate NML specification at %C");
1769 if (gfc_find_symbol (name, NULL, 1, &sym))
1772 if (sym == NULL || sym->attr.flavor != FL_NAMELIST)
1774 gfc_error ("Symbol '%s' at %C must be a NAMELIST group name",
1775 sym != NULL ? sym->name : name);
1780 if (k == M_READ && check_namelist (sym))
1786 m = match_etag (&tag_rec, &dt->rec);
1789 m = match_etag (&tag_spos, &dt->rec);
1792 m = match_out_tag (&tag_iomsg, &dt->iomsg);
1795 m = match_out_tag (&tag_iostat, &dt->iostat);
1798 m = match_ltag (&tag_err, &dt->err);
1800 dt->err_where = gfc_current_locus;
1803 m = match_etag (&tag_advance, &dt->advance);
1806 m = match_out_tag (&tag_size, &dt->size);
1810 m = match_ltag (&tag_end, &dt->end);
1815 gfc_error ("END tag at %C not allowed in output statement");
1818 dt->end_where = gfc_current_locus;
1823 m = match_ltag (&tag_eor, &dt->eor);
1825 dt->eor_where = gfc_current_locus;
1833 /* Free a data transfer structure and everything below it. */
1836 gfc_free_dt (gfc_dt * dt)
1842 gfc_free_expr (dt->io_unit);
1843 gfc_free_expr (dt->format_expr);
1844 gfc_free_expr (dt->rec);
1845 gfc_free_expr (dt->advance);
1846 gfc_free_expr (dt->iomsg);
1847 gfc_free_expr (dt->iostat);
1848 gfc_free_expr (dt->size);
1854 /* Resolve everything in a gfc_dt structure. */
1857 gfc_resolve_dt (gfc_dt * dt)
1861 RESOLVE_TAG (&tag_format, dt->format_expr);
1862 RESOLVE_TAG (&tag_rec, dt->rec);
1863 RESOLVE_TAG (&tag_spos, dt->rec);
1864 RESOLVE_TAG (&tag_advance, dt->advance);
1865 RESOLVE_TAG (&tag_iomsg, dt->iomsg);
1866 RESOLVE_TAG (&tag_iostat, dt->iostat);
1867 RESOLVE_TAG (&tag_size, dt->size);
1870 if (gfc_resolve_expr (e) == SUCCESS
1871 && (e->ts.type != BT_INTEGER
1872 && (e->ts.type != BT_CHARACTER
1873 || e->expr_type != EXPR_VARIABLE)))
1876 ("UNIT specification at %L must be an INTEGER expression or a "
1877 "CHARACTER variable", &e->where);
1881 if (e->ts.type == BT_CHARACTER)
1883 if (gfc_has_vector_index (e))
1885 gfc_error ("Internal unit with vector subscript at %L",
1891 if (e->rank && e->ts.type != BT_CHARACTER)
1893 gfc_error ("External IO UNIT cannot be an array at %L", &e->where);
1899 if (gfc_reference_st_label (dt->err, ST_LABEL_TARGET) == FAILURE)
1901 if (dt->err->defined == ST_LABEL_UNKNOWN)
1903 gfc_error ("ERR tag label %d at %L not defined",
1904 dt->err->value, &dt->err_where);
1911 if (gfc_reference_st_label (dt->end, ST_LABEL_TARGET) == FAILURE)
1913 if (dt->end->defined == ST_LABEL_UNKNOWN)
1915 gfc_error ("END tag label %d at %L not defined",
1916 dt->end->value, &dt->end_where);
1923 if (gfc_reference_st_label (dt->eor, ST_LABEL_TARGET) == FAILURE)
1925 if (dt->eor->defined == ST_LABEL_UNKNOWN)
1927 gfc_error ("EOR tag label %d at %L not defined",
1928 dt->eor->value, &dt->eor_where);
1933 /* Check the format label actually exists. */
1934 if (dt->format_label && dt->format_label != &format_asterisk
1935 && dt->format_label->defined == ST_LABEL_UNKNOWN)
1937 gfc_error ("FORMAT label %d at %L not defined", dt->format_label->value,
1938 &dt->format_label->where);
1945 /* Given an io_kind, return its name. */
1948 io_kind_name (io_kind k)
1967 gfc_internal_error ("io_kind_name(): bad I/O-kind");
1974 /* Match an IO iteration statement of the form:
1976 ( [<IO element> ,] <IO element>, I = <expr>, <expr> [, <expr> ] )
1978 which is equivalent to a single IO element. This function is
1979 mutually recursive with match_io_element(). */
1981 static match match_io_element (io_kind k, gfc_code **);
1984 match_io_iterator (io_kind k, gfc_code ** result)
1986 gfc_code *head, *tail, *new;
1994 old_loc = gfc_current_locus;
1996 if (gfc_match_char ('(') != MATCH_YES)
1999 m = match_io_element (k, &head);
2002 if (m != MATCH_YES || gfc_match_char (',') != MATCH_YES)
2008 /* Can't be anything but an IO iterator. Build a list. */
2009 iter = gfc_get_iterator ();
2013 m = gfc_match_iterator (iter, 0);
2014 if (m == MATCH_ERROR)
2018 gfc_check_do_variable (iter->var->symtree);
2022 m = match_io_element (k, &new);
2023 if (m == MATCH_ERROR)
2032 tail = gfc_append_code (tail, new);
2034 if (gfc_match_char (',') != MATCH_YES)
2043 if (gfc_match_char (')') != MATCH_YES)
2046 new = gfc_get_code ();
2048 new->ext.iterator = iter;
2050 new->block = gfc_get_code ();
2051 new->block->op = EXEC_DO;
2052 new->block->next = head;
2058 gfc_error ("Syntax error in I/O iterator at %C");
2062 gfc_free_iterator (iter, 1);
2063 gfc_free_statements (head);
2064 gfc_current_locus = old_loc;
2069 /* Match a single element of an IO list, which is either a single
2070 expression or an IO Iterator. */
2073 match_io_element (io_kind k, gfc_code ** cpp)
2081 m = match_io_iterator (k, cpp);
2087 m = gfc_match_variable (&expr, 0);
2089 gfc_error ("Expected variable in READ statement at %C");
2093 m = gfc_match_expr (&expr);
2095 gfc_error ("Expected expression in %s statement at %C",
2103 if (expr->symtree->n.sym->attr.intent == INTENT_IN)
2106 ("Variable '%s' in input list at %C cannot be INTENT(IN)",
2107 expr->symtree->n.sym->name);
2112 && gfc_impure_variable (expr->symtree->n.sym)
2113 && current_dt->io_unit->ts.type == BT_CHARACTER)
2115 gfc_error ("Cannot read to variable '%s' in PURE procedure at %C",
2116 expr->symtree->n.sym->name);
2120 if (gfc_check_do_variable (expr->symtree))
2126 if (current_dt->io_unit->ts.type == BT_CHARACTER
2128 && current_dt->io_unit->expr_type == EXPR_VARIABLE
2129 && gfc_impure_variable (current_dt->io_unit->symtree->n.sym))
2132 ("Cannot write to internal file unit '%s' at %C inside a "
2133 "PURE procedure", current_dt->io_unit->symtree->n.sym->name);
2145 gfc_free_expr (expr);
2149 cp = gfc_get_code ();
2150 cp->op = EXEC_TRANSFER;
2158 /* Match an I/O list, building gfc_code structures as we go. */
2161 match_io_list (io_kind k, gfc_code ** head_p)
2163 gfc_code *head, *tail, *new;
2166 *head_p = head = tail = NULL;
2167 if (gfc_match_eos () == MATCH_YES)
2172 m = match_io_element (k, &new);
2173 if (m == MATCH_ERROR)
2178 tail = gfc_append_code (tail, new);
2182 if (gfc_match_eos () == MATCH_YES)
2184 if (gfc_match_char (',') != MATCH_YES)
2192 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
2195 gfc_free_statements (head);
2200 /* Attach the data transfer end node. */
2203 terminate_io (gfc_code * io_code)
2207 if (io_code == NULL)
2208 io_code = new_st.block;
2210 c = gfc_get_code ();
2211 c->op = EXEC_DT_END;
2213 /* Point to structure that is already there */
2214 c->ext.dt = new_st.ext.dt;
2215 gfc_append_code (io_code, c);
2219 /* Check the constraints for a data transfer statement. The majority of the
2220 constraints appearing in 9.4 of the standard appear here. Some are handled
2221 in resolve_tag and others in gfc_resolve_dt. */
2224 check_io_constraints (io_kind k, gfc_dt *dt, gfc_code * io_code, locus * spec_end)
2226 #define io_constraint(condition,msg,arg)\
2229 gfc_error(msg,arg);\
2235 gfc_symbol * sym = NULL;
2240 if (expr && expr->expr_type == EXPR_VARIABLE
2241 && expr->ts.type == BT_CHARACTER)
2243 sym = expr->symtree->n.sym;
2245 io_constraint (k == M_WRITE && sym->attr.intent == INTENT_IN,
2246 "Internal file at %L must not be INTENT(IN)",
2249 io_constraint (gfc_has_vector_index (dt->io_unit),
2250 "Internal file incompatible with vector subscript at %L",
2253 io_constraint (dt->rec != NULL,
2254 "REC tag at %L is incompatible with internal file",
2257 io_constraint (dt->namelist != NULL,
2258 "Internal file at %L is incompatible with namelist",
2261 io_constraint (dt->advance != NULL,
2262 "ADVANCE tag at %L is incompatible with internal file",
2263 &dt->advance->where);
2266 if (expr && expr->ts.type != BT_CHARACTER)
2269 io_constraint (gfc_pure (NULL)
2270 && (k == M_READ || k == M_WRITE),
2271 "IO UNIT in %s statement at %C must be "
2272 "an internal file in a PURE procedure",
2279 io_constraint (dt->end,
2280 "END tag not allowed with output at %L",
2283 io_constraint (dt->eor,
2284 "EOR tag not allowed with output at %L",
2287 io_constraint (k != M_READ && dt->size,
2288 "SIZE=specifier not allowed with output at %L",
2293 io_constraint (dt->size && dt->advance == NULL,
2294 "SIZE tag at %L requires an ADVANCE tag",
2297 io_constraint (dt->eor && dt->advance == NULL,
2298 "EOR tag at %L requires an ADVANCE tag",
2306 io_constraint (io_code && dt->namelist,
2307 "NAMELIST cannot be followed by IO-list at %L",
2310 io_constraint (dt->format_expr,
2311 "IO spec-list cannot contain both NAMELIST group name "
2312 "and format specification at %L.",
2313 &dt->format_expr->where);
2315 io_constraint (dt->format_label,
2316 "IO spec-list cannot contain both NAMELIST group name "
2317 "and format label at %L", spec_end);
2319 io_constraint (dt->rec,
2320 "NAMELIST IO is not allowed with a REC=specifier "
2321 "at %L.", &dt->rec->where);
2323 io_constraint (dt->advance,
2324 "NAMELIST IO is not allowed with a ADVANCE=specifier "
2325 "at %L.", &dt->advance->where);
2330 io_constraint (dt->end,
2331 "An END tag is not allowed with a "
2332 "REC=specifier at %L.", &dt->end_where);
2335 io_constraint (dt->format_label == &format_asterisk,
2336 "FMT=* is not allowed with a REC=specifier "
2337 "at %L.", spec_end);
2342 int not_yes, not_no;
2345 io_constraint (dt->format_label == &format_asterisk,
2346 "List directed format(*) is not allowed with a "
2347 "ADVANCE=specifier at %L.", &expr->where);
2349 io_constraint (dt->format_expr == NULL
2350 && dt->format_label == NULL
2351 && dt->namelist == NULL,
2352 "the ADVANCE=specifier at %L must appear with an "
2353 "explicit format expression", &expr->where);
2355 if (expr->expr_type == EXPR_CONSTANT && expr->ts.type == BT_CHARACTER)
2357 const char * advance = expr->value.character.string;
2358 not_no = strncasecmp (advance, "no", 2) != 0;
2359 not_yes = strncasecmp (advance, "yes", 2) != 0;
2367 io_constraint (not_no && not_yes,
2368 "ADVANCE=specifier at %L must have value = "
2369 "YES or NO.", &expr->where);
2371 io_constraint (dt->size && not_no && k == M_READ,
2372 "SIZE tag at %L requires an ADVANCE = 'NO'",
2375 io_constraint (dt->eor && not_no && k == M_READ,
2376 "EOR tag at %L requires an ADVANCE = 'NO'",
2380 expr = dt->format_expr;
2381 if (expr != NULL && expr->expr_type == EXPR_CONSTANT)
2382 check_format_string (expr);
2386 #undef io_constraint
2388 /* Match a READ, WRITE or PRINT statement. */
2391 match_io (io_kind k)
2393 char name[GFC_MAX_SYMBOL_LEN + 1];
2402 where = gfc_current_locus;
2404 current_dt = dt = gfc_getmem (sizeof (gfc_dt));
2405 if (gfc_match_char ('(') == MATCH_NO)
2407 where = gfc_current_locus;
2410 else if (k == M_PRINT)
2412 /* Treat the non-standard case of PRINT namelist. */
2413 if ((gfc_current_form == FORM_FIXED || gfc_peek_char () == ' ')
2414 && gfc_match_name (name) == MATCH_YES)
2416 gfc_find_symbol (name, NULL, 1, &sym);
2417 if (sym && sym->attr.flavor == FL_NAMELIST)
2419 if (gfc_notify_std (GFC_STD_GNU, "PRINT namelist at "
2420 "%C is an extension") == FAILURE)
2426 dt->io_unit = default_unit (k);
2431 gfc_current_locus = where;
2435 if (gfc_current_form == FORM_FREE)
2437 c = gfc_peek_char();
2438 if (c != ' ' && c != '*' && c != '\'' && c != '"')
2445 m = match_dt_format (dt);
2446 if (m == MATCH_ERROR)
2452 dt->io_unit = default_unit (k);
2457 /* Error for constructs like print (1,*). */
2462 /* Match a control list */
2463 if (match_dt_element (k, dt) == MATCH_YES)
2465 if (match_dt_unit (k, dt) != MATCH_YES)
2468 if (gfc_match_char (')') == MATCH_YES)
2470 if (gfc_match_char (',') != MATCH_YES)
2473 m = match_dt_element (k, dt);
2476 if (m == MATCH_ERROR)
2479 m = match_dt_format (dt);
2482 if (m == MATCH_ERROR)
2485 where = gfc_current_locus;
2487 m = gfc_match_name (name);
2490 gfc_find_symbol (name, NULL, 1, &sym);
2491 if (sym && sym->attr.flavor == FL_NAMELIST)
2494 if (k == M_READ && check_namelist (sym))
2503 gfc_current_locus = where;
2505 goto loop; /* No matches, try regular elements */
2508 if (gfc_match_char (')') == MATCH_YES)
2510 if (gfc_match_char (',') != MATCH_YES)
2516 m = match_dt_element (k, dt);
2519 if (m == MATCH_ERROR)
2522 if (gfc_match_char (')') == MATCH_YES)
2524 if (gfc_match_char (',') != MATCH_YES)
2530 /* Used in check_io_constraints, where no locus is available. */
2531 spec_end = gfc_current_locus;
2533 /* Optional leading comma (non-standard). */
2535 && gfc_match_char (',') == MATCH_YES
2537 && gfc_notify_std (GFC_STD_GNU, "Extension: Comma before output "
2538 "item list at %C is an extension") == FAILURE)
2542 if (gfc_match_eos () != MATCH_YES)
2544 if (comma_flag && gfc_match_char (',') != MATCH_YES)
2546 gfc_error ("Expected comma in I/O list at %C");
2551 m = match_io_list (k, &io_code);
2552 if (m == MATCH_ERROR)
2558 /* A full IO statement has been matched. Check the constraints. spec_end is
2559 supplied for cases where no locus is supplied. */
2560 m = check_io_constraints (k, dt, io_code, &spec_end);
2562 if (m == MATCH_ERROR)
2565 new_st.op = (k == M_READ) ? EXEC_READ : EXEC_WRITE;
2567 new_st.block = gfc_get_code ();
2568 new_st.block->op = new_st.op;
2569 new_st.block->next = io_code;
2571 terminate_io (io_code);
2576 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k));
2586 gfc_match_read (void)
2588 return match_io (M_READ);
2592 gfc_match_write (void)
2594 return match_io (M_WRITE);
2598 gfc_match_print (void)
2602 m = match_io (M_PRINT);
2606 if (gfc_pure (NULL))
2608 gfc_error ("PRINT statement at %C not allowed within PURE procedure");
2616 /* Free a gfc_inquire structure. */
2619 gfc_free_inquire (gfc_inquire * inquire)
2622 if (inquire == NULL)
2625 gfc_free_expr (inquire->unit);
2626 gfc_free_expr (inquire->file);
2627 gfc_free_expr (inquire->iomsg);
2628 gfc_free_expr (inquire->iostat);
2629 gfc_free_expr (inquire->exist);
2630 gfc_free_expr (inquire->opened);
2631 gfc_free_expr (inquire->number);
2632 gfc_free_expr (inquire->named);
2633 gfc_free_expr (inquire->name);
2634 gfc_free_expr (inquire->access);
2635 gfc_free_expr (inquire->sequential);
2636 gfc_free_expr (inquire->direct);
2637 gfc_free_expr (inquire->form);
2638 gfc_free_expr (inquire->formatted);
2639 gfc_free_expr (inquire->unformatted);
2640 gfc_free_expr (inquire->recl);
2641 gfc_free_expr (inquire->nextrec);
2642 gfc_free_expr (inquire->blank);
2643 gfc_free_expr (inquire->position);
2644 gfc_free_expr (inquire->action);
2645 gfc_free_expr (inquire->read);
2646 gfc_free_expr (inquire->write);
2647 gfc_free_expr (inquire->readwrite);
2648 gfc_free_expr (inquire->delim);
2649 gfc_free_expr (inquire->pad);
2650 gfc_free_expr (inquire->iolength);
2651 gfc_free_expr (inquire->convert);
2652 gfc_free_expr (inquire->strm_pos);
2658 /* Match an element of an INQUIRE statement. */
2660 #define RETM if (m != MATCH_NO) return m;
2663 match_inquire_element (gfc_inquire * inquire)
2667 m = match_etag (&tag_unit, &inquire->unit);
2668 RETM m = match_etag (&tag_file, &inquire->file);
2669 RETM m = match_ltag (&tag_err, &inquire->err);
2670 RETM m = match_out_tag (&tag_iomsg, &inquire->iomsg);
2671 RETM m = match_out_tag (&tag_iostat, &inquire->iostat);
2672 RETM m = match_vtag (&tag_exist, &inquire->exist);
2673 RETM m = match_vtag (&tag_opened, &inquire->opened);
2674 RETM m = match_vtag (&tag_named, &inquire->named);
2675 RETM m = match_vtag (&tag_name, &inquire->name);
2676 RETM m = match_out_tag (&tag_number, &inquire->number);
2677 RETM m = match_vtag (&tag_s_access, &inquire->access);
2678 RETM m = match_vtag (&tag_sequential, &inquire->sequential);
2679 RETM m = match_vtag (&tag_direct, &inquire->direct);
2680 RETM m = match_vtag (&tag_s_form, &inquire->form);
2681 RETM m = match_vtag (&tag_formatted, &inquire->formatted);
2682 RETM m = match_vtag (&tag_unformatted, &inquire->unformatted);
2683 RETM m = match_out_tag (&tag_s_recl, &inquire->recl);
2684 RETM m = match_out_tag (&tag_nextrec, &inquire->nextrec);
2685 RETM m = match_vtag (&tag_s_blank, &inquire->blank);
2686 RETM m = match_vtag (&tag_s_position, &inquire->position);
2687 RETM m = match_vtag (&tag_s_action, &inquire->action);
2688 RETM m = match_vtag (&tag_read, &inquire->read);
2689 RETM m = match_vtag (&tag_write, &inquire->write);
2690 RETM m = match_vtag (&tag_readwrite, &inquire->readwrite);
2691 RETM m = match_vtag (&tag_s_delim, &inquire->delim);
2692 RETM m = match_vtag (&tag_s_pad, &inquire->pad);
2693 RETM m = match_vtag (&tag_iolength, &inquire->iolength);
2694 RETM m = match_vtag (&tag_convert, &inquire->convert);
2695 RETM m = match_out_tag (&tag_strm_out, &inquire->strm_pos);
2696 RETM return MATCH_NO;
2703 gfc_match_inquire (void)
2705 gfc_inquire *inquire;
2710 m = gfc_match_char ('(');
2714 inquire = gfc_getmem (sizeof (gfc_inquire));
2716 loc = gfc_current_locus;
2718 m = match_inquire_element (inquire);
2719 if (m == MATCH_ERROR)
2723 m = gfc_match_expr (&inquire->unit);
2724 if (m == MATCH_ERROR)
2730 /* See if we have the IOLENGTH form of the inquire statement. */
2731 if (inquire->iolength != NULL)
2733 if (gfc_match_char (')') != MATCH_YES)
2736 m = match_io_list (M_INQUIRE, &code);
2737 if (m == MATCH_ERROR)
2742 new_st.op = EXEC_IOLENGTH;
2743 new_st.expr = inquire->iolength;
2744 new_st.ext.inquire = inquire;
2746 if (gfc_pure (NULL))
2748 gfc_free_statements (code);
2749 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
2753 new_st.block = gfc_get_code ();
2754 new_st.block->op = EXEC_IOLENGTH;
2755 terminate_io (code);
2756 new_st.block->next = code;
2760 /* At this point, we have the non-IOLENGTH inquire statement. */
2763 if (gfc_match_char (')') == MATCH_YES)
2765 if (gfc_match_char (',') != MATCH_YES)
2768 m = match_inquire_element (inquire);
2769 if (m == MATCH_ERROR)
2774 if (inquire->iolength != NULL)
2776 gfc_error ("IOLENGTH tag invalid in INQUIRE statement at %C");
2781 if (gfc_match_eos () != MATCH_YES)
2784 if (inquire->unit != NULL && inquire->file != NULL)
2786 gfc_error ("INQUIRE statement at %L cannot contain both FILE and"
2787 " UNIT specifiers", &loc);
2791 if (inquire->unit == NULL && inquire->file == NULL)
2793 gfc_error ("INQUIRE statement at %L requires either FILE or"
2794 " UNIT specifier", &loc);
2798 if (gfc_pure (NULL))
2800 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
2804 new_st.op = EXEC_INQUIRE;
2805 new_st.ext.inquire = inquire;
2809 gfc_syntax_error (ST_INQUIRE);
2812 gfc_free_inquire (inquire);
2817 /* Resolve everything in a gfc_inquire structure. */
2820 gfc_resolve_inquire (gfc_inquire * inquire)
2823 RESOLVE_TAG (&tag_unit, inquire->unit);
2824 RESOLVE_TAG (&tag_file, inquire->file);
2825 RESOLVE_TAG (&tag_iomsg, inquire->iomsg);
2826 RESOLVE_TAG (&tag_iostat, inquire->iostat);
2827 RESOLVE_TAG (&tag_exist, inquire->exist);
2828 RESOLVE_TAG (&tag_opened, inquire->opened);
2829 RESOLVE_TAG (&tag_number, inquire->number);
2830 RESOLVE_TAG (&tag_named, inquire->named);
2831 RESOLVE_TAG (&tag_name, inquire->name);
2832 RESOLVE_TAG (&tag_s_access, inquire->access);
2833 RESOLVE_TAG (&tag_sequential, inquire->sequential);
2834 RESOLVE_TAG (&tag_direct, inquire->direct);
2835 RESOLVE_TAG (&tag_s_form, inquire->form);
2836 RESOLVE_TAG (&tag_formatted, inquire->formatted);
2837 RESOLVE_TAG (&tag_unformatted, inquire->unformatted);
2838 RESOLVE_TAG (&tag_s_recl, inquire->recl);
2839 RESOLVE_TAG (&tag_nextrec, inquire->nextrec);
2840 RESOLVE_TAG (&tag_s_blank, inquire->blank);
2841 RESOLVE_TAG (&tag_s_position, inquire->position);
2842 RESOLVE_TAG (&tag_s_action, inquire->action);
2843 RESOLVE_TAG (&tag_read, inquire->read);
2844 RESOLVE_TAG (&tag_write, inquire->write);
2845 RESOLVE_TAG (&tag_readwrite, inquire->readwrite);
2846 RESOLVE_TAG (&tag_s_delim, inquire->delim);
2847 RESOLVE_TAG (&tag_s_pad, inquire->pad);
2848 RESOLVE_TAG (&tag_iolength, inquire->iolength);
2849 RESOLVE_TAG (&tag_convert, inquire->convert);
2850 RESOLVE_TAG (&tag_strm_out, inquire->strm_pos);
2852 if (gfc_reference_st_label (inquire->err, ST_LABEL_TARGET) == FAILURE)