1 /* Deal with I/O statements & related stuff.
2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
30 format_asterisk
= {0, NULL
, NULL
, -1, ST_LABEL_FORMAT
, ST_LABEL_FORMAT
, NULL
,
35 const char *name
, *spec
, *value
;
41 tag_file
= {"FILE", " file =", " %e", BT_CHARACTER
},
42 tag_status
= {"STATUS", " status =", " %e", BT_CHARACTER
},
43 tag_e_access
= {"ACCESS", " access =", " %e", BT_CHARACTER
},
44 tag_e_form
= {"FORM", " form =", " %e", BT_CHARACTER
},
45 tag_e_recl
= {"RECL", " recl =", " %e", BT_INTEGER
},
46 tag_e_blank
= {"BLANK", " blank =", " %e", BT_CHARACTER
},
47 tag_e_position
= {"POSITION", " position =", " %e", BT_CHARACTER
},
48 tag_e_action
= {"ACTION", " action =", " %e", BT_CHARACTER
},
49 tag_e_delim
= {"DELIM", " delim =", " %e", BT_CHARACTER
},
50 tag_e_pad
= {"PAD", " pad =", " %e", BT_CHARACTER
},
51 tag_e_decimal
= {"DECIMAL", " decimal =", " %e", BT_CHARACTER
},
52 tag_e_encoding
= {"ENCODING", " encoding =", " %e", BT_CHARACTER
},
53 tag_e_async
= {"ASYNCHRONOUS", " asynchronous =", " %e", BT_CHARACTER
},
54 tag_e_round
= {"ROUND", " round =", " %e", BT_CHARACTER
},
55 tag_e_sign
= {"SIGN", " sign =", " %e", BT_CHARACTER
},
56 tag_unit
= {"UNIT", " unit =", " %e", BT_INTEGER
},
57 tag_advance
= {"ADVANCE", " advance =", " %e", BT_CHARACTER
},
58 tag_rec
= {"REC", " rec =", " %e", BT_INTEGER
},
59 tag_spos
= {"POSITION", " pos =", " %e", BT_INTEGER
},
60 tag_format
= {"FORMAT", NULL
, NULL
, BT_CHARACTER
},
61 tag_iomsg
= {"IOMSG", " iomsg =", " %e", BT_CHARACTER
},
62 tag_iostat
= {"IOSTAT", " iostat =", " %v", BT_INTEGER
},
63 tag_size
= {"SIZE", " size =", " %v", BT_INTEGER
},
64 tag_exist
= {"EXIST", " exist =", " %v", BT_LOGICAL
},
65 tag_opened
= {"OPENED", " opened =", " %v", BT_LOGICAL
},
66 tag_named
= {"NAMED", " named =", " %v", BT_LOGICAL
},
67 tag_name
= {"NAME", " name =", " %v", BT_CHARACTER
},
68 tag_number
= {"NUMBER", " number =", " %v", BT_INTEGER
},
69 tag_s_access
= {"ACCESS", " access =", " %v", BT_CHARACTER
},
70 tag_sequential
= {"SEQUENTIAL", " sequential =", " %v", BT_CHARACTER
},
71 tag_direct
= {"DIRECT", " direct =", " %v", BT_CHARACTER
},
72 tag_s_form
= {"FORM", " form =", " %v", BT_CHARACTER
},
73 tag_formatted
= {"FORMATTED", " formatted =", " %v", BT_CHARACTER
},
74 tag_unformatted
= {"UNFORMATTED", " unformatted =", " %v", BT_CHARACTER
},
75 tag_s_recl
= {"RECL", " recl =", " %v", BT_INTEGER
},
76 tag_nextrec
= {"NEXTREC", " nextrec =", " %v", BT_INTEGER
},
77 tag_s_blank
= {"BLANK", " blank =", " %v", BT_CHARACTER
},
78 tag_s_position
= {"POSITION", " position =", " %v", BT_CHARACTER
},
79 tag_s_action
= {"ACTION", " action =", " %v", BT_CHARACTER
},
80 tag_read
= {"READ", " read =", " %v", BT_CHARACTER
},
81 tag_write
= {"WRITE", " write =", " %v", BT_CHARACTER
},
82 tag_readwrite
= {"READWRITE", " readwrite =", " %v", BT_CHARACTER
},
83 tag_s_delim
= {"DELIM", " delim =", " %v", BT_CHARACTER
},
84 tag_s_pad
= {"PAD", " pad =", " %v", BT_CHARACTER
},
85 tag_s_decimal
= {"DECIMAL", " decimal =", " %v", BT_CHARACTER
},
86 tag_s_encoding
= {"ENCODING", " encoding =", " %v", BT_CHARACTER
},
87 tag_s_async
= {"ASYNCHRONOUS", " asynchronous =", " %v", BT_CHARACTER
},
88 tag_s_round
= {"ROUND", " round =", " %v", BT_CHARACTER
},
89 tag_s_sign
= {"SIGN", " sign =", " %v", BT_CHARACTER
},
90 tag_iolength
= {"IOLENGTH", " iolength =", " %v", BT_INTEGER
},
91 tag_convert
= {"CONVERT", " convert =", " %e", BT_CHARACTER
},
92 tag_strm_out
= {"POS", " pos =", " %v", BT_INTEGER
},
93 tag_err
= {"ERR", " err =", " %l", BT_UNKNOWN
},
94 tag_end
= {"END", " end =", " %l", BT_UNKNOWN
},
95 tag_eor
= {"EOR", " eor =", " %l", BT_UNKNOWN
},
96 tag_id
= {"ID", " id =", " %v", BT_INTEGER
},
97 tag_pending
= {"PENDING", " pending =", " %v", BT_LOGICAL
},
98 tag_newunit
= {"NEWUNIT", " newunit =", " %v", BT_INTEGER
},
99 tag_s_iqstream
= {"STREAM", " stream =", " %v", BT_CHARACTER
};
101 static gfc_dt
*current_dt
;
103 #define RESOLVE_TAG(x, y) if (!resolve_tag (x, y)) return false;
106 /**************** Fortran 95 FORMAT parser *****************/
108 /* FORMAT tokens returned by format_lex(). */
111 FMT_NONE
, FMT_UNKNOWN
, FMT_SIGNED_INT
, FMT_ZERO
, FMT_POSINT
, FMT_PERIOD
,
112 FMT_COMMA
, FMT_COLON
, FMT_SLASH
, FMT_DOLLAR
, FMT_LPAREN
,
113 FMT_RPAREN
, FMT_X
, FMT_SIGN
, FMT_BLANK
, FMT_CHAR
, FMT_P
, FMT_IBOZ
, FMT_F
,
114 FMT_E
, FMT_EN
, FMT_ES
, FMT_G
, FMT_L
, FMT_A
, FMT_D
, FMT_H
, FMT_END
,
115 FMT_ERROR
, FMT_DC
, FMT_DP
, FMT_T
, FMT_TR
, FMT_TL
, FMT_STAR
, FMT_RC
,
116 FMT_RD
, FMT_RN
, FMT_RP
, FMT_RU
, FMT_RZ
120 /* Local variables for checking format strings. The saved_token is
121 used to back up by a single format token during the parsing
123 static gfc_char_t
*format_string
;
124 static int format_string_pos
;
125 static int format_length
, use_last_char
;
126 static char error_element
;
127 static locus format_locus
;
129 static format_token saved_token
;
132 { MODE_STRING
, MODE_FORMAT
, MODE_COPY
}
136 /* Return the next character in the format string. */
139 next_char (gfc_instring in_string
)
151 if (mode
== MODE_STRING
)
152 c
= *format_string
++;
155 c
= gfc_next_char_literal (in_string
);
160 if (flag_backslash
&& c
== '\\')
162 locus old_locus
= gfc_current_locus
;
164 if (gfc_match_special_char (&c
) == MATCH_NO
)
165 gfc_current_locus
= old_locus
;
167 if (!(gfc_option
.allow_std
& GFC_STD_GNU
) && !inhibit_warnings
)
168 gfc_warning (0, "Extension: backslash character at %C");
171 if (mode
== MODE_COPY
)
172 *format_string
++ = c
;
174 if (mode
!= MODE_STRING
)
175 format_locus
= gfc_current_locus
;
179 c
= gfc_wide_toupper (c
);
184 /* Back up one character position. Only works once. */
192 /* Eat up the spaces and return a character. */
195 next_char_not_space (bool *error
)
200 error_element
= c
= next_char (NONSTRING
);
203 if (gfc_option
.allow_std
& GFC_STD_GNU
)
204 gfc_warning (0, "Extension: Tab character in format at %C");
207 gfc_error ("Extension: Tab character in format at %C");
213 while (gfc_is_whitespace (c
));
217 static int value
= 0;
219 /* Simple lexical analyzer for getting the next token in a FORMAT
231 if (saved_token
!= FMT_NONE
)
234 saved_token
= FMT_NONE
;
238 c
= next_char_not_space (&error
);
248 c
= next_char_not_space (&error
);
259 c
= next_char_not_space (&error
);
261 value
= 10 * value
+ c
- '0';
270 token
= FMT_SIGNED_INT
;
289 c
= next_char_not_space (&error
);
292 value
= 10 * value
+ c
- '0';
300 token
= zflag
? FMT_ZERO
: FMT_POSINT
;
324 c
= next_char_not_space (&error
);
352 c
= next_char_not_space (&error
);
353 if (c
!= 'P' && c
!= 'S')
360 c
= next_char_not_space (&error
);
361 if (c
== 'N' || c
== 'Z')
379 c
= next_char (INSTRING_WARN
);
388 c
= next_char (NONSTRING
);
422 c
= next_char_not_space (&error
);
452 c
= next_char_not_space (&error
);
455 if (!gfc_notify_std (GFC_STD_F2003
, "DP format "
456 "specifier not allowed at %C"))
462 if (!gfc_notify_std (GFC_STD_F2003
, "DC format "
463 "specifier not allowed at %C"))
475 c
= next_char_not_space (&error
);
524 token_to_string (format_token t
)
543 /* Check a format statement. The format string, either from a FORMAT
544 statement or a constant in an I/O statement has already been parsed
545 by itself, and we are checking it for validity. The dual origin
546 means that the warning message is a little less than great. */
549 check_format (bool is_input
)
551 const char *posint_required
= _("Positive width required");
552 const char *nonneg_required
= _("Nonnegative width required");
553 const char *unexpected_element
= _("Unexpected element %<%c%> in format "
555 const char *unexpected_end
= _("Unexpected end of format string");
556 const char *zero_width
= _("Zero width in format descriptor");
565 saved_token
= FMT_NONE
;
569 format_string_pos
= 0;
576 error
= _("Missing leading left parenthesis");
584 goto finished
; /* Empty format is legal */
588 /* In this state, the next thing has to be a format item. */
605 error
= _("Left parenthesis required after %<*%>");
630 /* Signed integer can only precede a P format. */
636 error
= _("Expected P edit descriptor");
643 /* P requires a prior number. */
644 error
= _("P descriptor requires leading scale factor");
648 /* X requires a prior number if we're being pedantic. */
649 if (mode
!= MODE_FORMAT
)
650 format_locus
.nextc
+= format_string_pos
;
651 if (!gfc_notify_std (GFC_STD_GNU
, "X descriptor requires leading "
652 "space count at %L", &format_locus
))
669 goto extension_optional_comma
;
680 if (!gfc_notify_std (GFC_STD_GNU
, "$ descriptor at %L", &format_locus
))
682 if (t
!= FMT_RPAREN
|| level
> 0)
684 gfc_warning (0, "$ should be the last specifier in format at %L",
686 goto optional_comma_1
;
707 error
= unexpected_end
;
711 error
= unexpected_element
;
716 /* In this state, t must currently be a data descriptor.
717 Deal with things that can/must follow the descriptor. */
728 /* No comma after P allowed only for F, E, EN, ES, D, or G.
733 if (!(gfc_option
.allow_std
& GFC_STD_F2003
) && t
!= FMT_COMMA
734 && t
!= FMT_F
&& t
!= FMT_E
&& t
!= FMT_EN
&& t
!= FMT_ES
735 && t
!= FMT_D
&& t
!= FMT_G
&& t
!= FMT_RPAREN
&& t
!= FMT_SLASH
)
737 error
= _("Comma required after P descriptor");
748 if (t
!= FMT_F
&& t
!= FMT_E
&& t
!= FMT_EN
&& t
!= FMT_ES
&& t
!= FMT_D
749 && t
!= FMT_G
&& t
!= FMT_RPAREN
&& t
!= FMT_SLASH
)
751 error
= _("Comma required after P descriptor");
765 error
= _("Positive width required with T descriptor");
777 switch (gfc_notification_std (GFC_STD_GNU
))
780 if (mode
!= MODE_FORMAT
)
781 format_locus
.nextc
+= format_string_pos
;
782 gfc_warning (0, "Extension: Missing positive width after L "
783 "descriptor at %L", &format_locus
);
788 error
= posint_required
;
819 if (t
== FMT_G
&& u
== FMT_ZERO
)
826 if (!gfc_notify_std (GFC_STD_F2008
, "%<G0%> in format at %L",
838 error
= posint_required
;
844 error
= _("E specifier not allowed with g0 descriptor");
853 format_locus
.nextc
+= format_string_pos
;
854 gfc_error ("Positive width required in format "
855 "specifier %s at %L", token_to_string (t
),
866 /* Warn if -std=legacy, otherwise error. */
867 format_locus
.nextc
+= format_string_pos
;
868 if (gfc_option
.warn_std
!= 0)
870 gfc_error ("Period required in format "
871 "specifier %s at %L", token_to_string (t
),
877 gfc_warning (0, "Period required in format "
878 "specifier %s at %L", token_to_string (t
),
880 /* If we go to finished, we need to unwind this
881 before the next round. */
882 format_locus
.nextc
-= format_string_pos
;
890 if (u
!= FMT_ZERO
&& u
!= FMT_POSINT
)
892 error
= nonneg_required
;
899 /* Look for optional exponent. */
914 error
= _("Positive exponent width required");
925 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
927 error
= nonneg_required
;
930 else if (is_input
&& t
== FMT_ZERO
)
932 error
= posint_required
;
941 /* Warn if -std=legacy, otherwise error. */
942 if (gfc_option
.warn_std
!= 0)
944 error
= _("Period required in format specifier");
947 if (mode
!= MODE_FORMAT
)
948 format_locus
.nextc
+= format_string_pos
;
949 gfc_warning (0, "Period required in format specifier at %L",
958 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
960 error
= nonneg_required
;
967 if (!(gfc_option
.allow_std
& GFC_STD_GNU
) && !inhibit_warnings
)
969 if (mode
!= MODE_FORMAT
)
970 format_locus
.nextc
+= format_string_pos
;
971 gfc_warning (0, "The H format specifier at %L is"
972 " a Fortran 95 deleted feature", &format_locus
);
974 if (mode
== MODE_STRING
)
976 format_string
+= value
;
977 format_length
-= value
;
978 format_string_pos
+= repeat
;
984 next_char (INSTRING_WARN
);
994 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
996 error
= nonneg_required
;
999 else if (is_input
&& t
== FMT_ZERO
)
1001 error
= posint_required
;
1008 if (t
!= FMT_PERIOD
)
1017 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1019 error
= nonneg_required
;
1027 error
= unexpected_element
;
1032 /* Between a descriptor and what comes next. */
1050 goto optional_comma
;
1053 error
= unexpected_end
;
1057 if (mode
!= MODE_FORMAT
)
1058 format_locus
.nextc
+= format_string_pos
- 1;
1059 if (!gfc_notify_std (GFC_STD_GNU
, "Missing comma at %L", &format_locus
))
1061 /* If we do not actually return a failure, we need to unwind this
1062 before the next round. */
1063 if (mode
!= MODE_FORMAT
)
1064 format_locus
.nextc
-= format_string_pos
;
1069 /* Optional comma is a weird between state where we've just finished
1070 reading a colon, slash, dollar or P descriptor. */
1087 /* Assume that we have another format item. */
1094 extension_optional_comma
:
1095 /* As a GNU extension, permit a missing comma after a string literal. */
1112 goto optional_comma
;
1115 error
= unexpected_end
;
1119 if (mode
!= MODE_FORMAT
)
1120 format_locus
.nextc
+= format_string_pos
;
1121 if (!gfc_notify_std (GFC_STD_GNU
, "Missing comma at %L", &format_locus
))
1123 /* If we do not actually return a failure, we need to unwind this
1124 before the next round. */
1125 if (mode
!= MODE_FORMAT
)
1126 format_locus
.nextc
-= format_string_pos
;
1134 if (mode
!= MODE_FORMAT
)
1135 format_locus
.nextc
+= format_string_pos
;
1136 if (error
== unexpected_element
)
1137 gfc_error (error
, error_element
, &format_locus
);
1139 gfc_error ("%s in format string at %L", error
, &format_locus
);
1148 /* Given an expression node that is a constant string, see if it looks
1149 like a format string. */
1152 check_format_string (gfc_expr
*e
, bool is_input
)
1156 if (!e
|| e
->ts
.type
!= BT_CHARACTER
|| e
->expr_type
!= EXPR_CONSTANT
)
1160 format_string
= e
->value
.character
.string
;
1162 /* More elaborate measures are needed to show where a problem is within a
1163 format string that has been calculated, but that's probably not worth the
1165 format_locus
= e
->where
;
1166 rv
= check_format (is_input
);
1167 /* check for extraneous characters at the end of an otherwise valid format
1168 string, like '(A10,I3)F5'
1169 start at the end and move back to the last character processed,
1171 if (rv
&& e
->value
.character
.length
> format_string_pos
)
1172 for (i
=e
->value
.character
.length
-1;i
>format_string_pos
-1;i
--)
1173 if (e
->value
.character
.string
[i
] != ' ')
1175 format_locus
.nextc
+= format_length
+ 1;
1177 "Extraneous characters in format at %L", &format_locus
);
1184 /************ Fortran I/O statement matchers *************/
1186 /* Match a FORMAT statement. This amounts to actually parsing the
1187 format descriptors in order to correctly locate the end of the
1191 gfc_match_format (void)
1196 if (gfc_current_ns
->proc_name
1197 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
1199 gfc_error ("Format statement in module main block at %C");
1203 if (gfc_statement_label
== NULL
)
1205 gfc_error ("Missing format label at %C");
1208 gfc_gobble_whitespace ();
1213 start
= gfc_current_locus
;
1215 if (!check_format (false))
1218 if (gfc_match_eos () != MATCH_YES
)
1220 gfc_syntax_error (ST_FORMAT
);
1224 /* The label doesn't get created until after the statement is done
1225 being matched, so we have to leave the string for later. */
1227 gfc_current_locus
= start
; /* Back to the beginning */
1230 new_st
.op
= EXEC_NOP
;
1232 e
= gfc_get_character_expr (gfc_default_character_kind
, &start
,
1233 NULL
, format_length
);
1234 format_string
= e
->value
.character
.string
;
1235 gfc_statement_label
->format
= e
;
1238 check_format (false); /* Guaranteed to succeed */
1239 gfc_match_eos (); /* Guaranteed to succeed */
1245 /* Check for a CHARACTER variable. The check for scalar is done in
1249 check_char_variable (gfc_expr
*e
)
1251 if (e
->expr_type
!= EXPR_VARIABLE
|| e
->ts
.type
!= BT_CHARACTER
)
1253 gfc_error("IOMSG must be a scalar-default-char-variable at %L", &e
->where
);
1261 is_char_type (const char *name
, gfc_expr
*e
)
1263 gfc_resolve_expr (e
);
1265 if (e
->ts
.type
!= BT_CHARACTER
)
1267 gfc_error ("%s requires a scalar-default-char-expr at %L",
1275 /* Match an expression I/O tag of some sort. */
1278 match_etag (const io_tag
*tag
, gfc_expr
**v
)
1283 m
= gfc_match (tag
->spec
);
1287 m
= gfc_match (tag
->value
, &result
);
1290 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1296 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1297 gfc_free_expr (result
);
1306 /* Match a variable I/O tag of some sort. */
1309 match_vtag (const io_tag
*tag
, gfc_expr
**v
)
1314 m
= gfc_match (tag
->spec
);
1318 m
= gfc_match (tag
->value
, &result
);
1321 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1327 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1328 gfc_free_expr (result
);
1332 if (result
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
1334 gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag
->name
);
1335 gfc_free_expr (result
);
1339 bool impure
= gfc_impure_variable (result
->symtree
->n
.sym
);
1340 if (impure
&& gfc_pure (NULL
))
1342 gfc_error ("Variable %s cannot be assigned in PURE procedure at %C",
1344 gfc_free_expr (result
);
1349 gfc_unset_implicit_pure (NULL
);
1356 /* Match I/O tags that cause variables to become redefined. */
1359 match_out_tag (const io_tag
*tag
, gfc_expr
**result
)
1363 m
= match_vtag (tag
, result
);
1365 gfc_check_do_variable ((*result
)->symtree
);
1371 /* Match a label I/O tag. */
1374 match_ltag (const io_tag
*tag
, gfc_st_label
** label
)
1380 m
= gfc_match (tag
->spec
);
1384 m
= gfc_match (tag
->value
, label
);
1387 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1393 gfc_error ("Duplicate %s label specification at %C", tag
->name
);
1397 if (!gfc_reference_st_label (*label
, ST_LABEL_TARGET
))
1404 /* Resolution of the FORMAT tag, to be called from resolve_tag. */
1407 resolve_tag_format (const gfc_expr
*e
)
1409 if (e
->expr_type
== EXPR_CONSTANT
1410 && (e
->ts
.type
!= BT_CHARACTER
1411 || e
->ts
.kind
!= gfc_default_character_kind
))
1413 gfc_error ("Constant expression in FORMAT tag at %L must be "
1414 "of type default CHARACTER", &e
->where
);
1418 /* If e's rank is zero and e is not an element of an array, it should be
1419 of integer or character type. The integer variable should be
1422 && (e
->expr_type
!= EXPR_VARIABLE
1423 || e
->symtree
== NULL
1424 || e
->symtree
->n
.sym
->as
== NULL
1425 || e
->symtree
->n
.sym
->as
->rank
== 0))
1427 if ((e
->ts
.type
!= BT_CHARACTER
1428 || e
->ts
.kind
!= gfc_default_character_kind
)
1429 && e
->ts
.type
!= BT_INTEGER
)
1431 gfc_error ("FORMAT tag at %L must be of type default-kind CHARACTER "
1432 "or of INTEGER", &e
->where
);
1435 else if (e
->ts
.type
== BT_INTEGER
&& e
->expr_type
== EXPR_VARIABLE
)
1437 if (!gfc_notify_std (GFC_STD_F95_DEL
, "ASSIGNED variable in "
1438 "FORMAT tag at %L", &e
->where
))
1440 if (e
->symtree
->n
.sym
->attr
.assign
!= 1)
1442 gfc_error ("Variable %qs at %L has not been assigned a "
1443 "format label", e
->symtree
->n
.sym
->name
, &e
->where
);
1447 else if (e
->ts
.type
== BT_INTEGER
)
1449 gfc_error ("Scalar %qs in FORMAT tag at %L is not an ASSIGNED "
1450 "variable", gfc_basic_typename (e
->ts
.type
), &e
->where
);
1457 /* If rank is nonzero and type is not character, we allow it under GFC_STD_LEGACY.
1458 It may be assigned an Hollerith constant. */
1459 if (e
->ts
.type
!= BT_CHARACTER
)
1461 if (!gfc_notify_std (GFC_STD_LEGACY
, "Non-character in FORMAT tag "
1462 "at %L", &e
->where
))
1465 if (e
->rank
== 0 && e
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SHAPE
)
1467 gfc_error ("Non-character assumed shape array element in FORMAT"
1468 " tag at %L", &e
->where
);
1472 if (e
->rank
== 0 && e
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
)
1474 gfc_error ("Non-character assumed size array element in FORMAT"
1475 " tag at %L", &e
->where
);
1479 if (e
->rank
== 0 && e
->symtree
->n
.sym
->attr
.pointer
)
1481 gfc_error ("Non-character pointer array element in FORMAT tag at %L",
1491 /* Do expression resolution and type-checking on an expression tag. */
1494 resolve_tag (const io_tag
*tag
, gfc_expr
*e
)
1499 if (!gfc_resolve_expr (e
))
1502 if (tag
== &tag_format
)
1503 return resolve_tag_format (e
);
1505 if (e
->ts
.type
!= tag
->type
)
1507 gfc_error ("%s tag at %L must be of type %s", tag
->name
,
1508 &e
->where
, gfc_basic_typename (tag
->type
));
1512 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= gfc_default_character_kind
)
1514 gfc_error ("%s tag at %L must be a character string of default kind",
1515 tag
->name
, &e
->where
);
1521 gfc_error ("%s tag at %L must be scalar", tag
->name
, &e
->where
);
1525 if (tag
== &tag_iomsg
)
1527 if (!gfc_notify_std (GFC_STD_F2003
, "IOMSG tag at %L", &e
->where
))
1531 if ((tag
== &tag_iostat
|| tag
== &tag_size
|| tag
== &tag_iolength
1532 || tag
== &tag_number
|| tag
== &tag_nextrec
|| tag
== &tag_s_recl
)
1533 && e
->ts
.kind
!= gfc_default_integer_kind
)
1535 if (!gfc_notify_std (GFC_STD_F2003
, "Fortran 95 requires default "
1536 "INTEGER in %s tag at %L", tag
->name
, &e
->where
))
1540 if (e
->ts
.kind
!= gfc_default_logical_kind
&&
1541 (tag
== &tag_exist
|| tag
== &tag_named
|| tag
== &tag_opened
1542 || tag
== &tag_pending
))
1544 if (!gfc_notify_std (GFC_STD_F2008
, "Non-default LOGICAL kind "
1545 "in %s tag at %L", tag
->name
, &e
->where
))
1549 if (tag
== &tag_newunit
)
1551 if (!gfc_notify_std (GFC_STD_F2008
, "NEWUNIT specifier at %L",
1556 /* NEWUNIT, IOSTAT, SIZE and IOMSG are variable definition contexts. */
1557 if (tag
== &tag_newunit
|| tag
== &tag_iostat
1558 || tag
== &tag_size
|| tag
== &tag_iomsg
)
1562 sprintf (context
, _("%s tag"), tag
->name
);
1563 if (!gfc_check_vardef_context (e
, false, false, false, context
))
1567 if (tag
== &tag_convert
)
1569 if (!gfc_notify_std (GFC_STD_GNU
, "CONVERT tag at %L", &e
->where
))
1577 /* Match a single tag of an OPEN statement. */
1580 match_open_element (gfc_open
*open
)
1584 m
= match_etag (&tag_e_async
, &open
->asynchronous
);
1585 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", open
->asynchronous
))
1589 m
= match_etag (&tag_unit
, &open
->unit
);
1592 m
= match_etag (&tag_iomsg
, &open
->iomsg
);
1593 if (m
== MATCH_YES
&& !check_char_variable (open
->iomsg
))
1597 m
= match_out_tag (&tag_iostat
, &open
->iostat
);
1600 m
= match_etag (&tag_file
, &open
->file
);
1603 m
= match_etag (&tag_status
, &open
->status
);
1606 m
= match_etag (&tag_e_access
, &open
->access
);
1609 m
= match_etag (&tag_e_form
, &open
->form
);
1612 m
= match_etag (&tag_e_recl
, &open
->recl
);
1615 m
= match_etag (&tag_e_blank
, &open
->blank
);
1618 m
= match_etag (&tag_e_position
, &open
->position
);
1621 m
= match_etag (&tag_e_action
, &open
->action
);
1624 m
= match_etag (&tag_e_delim
, &open
->delim
);
1627 m
= match_etag (&tag_e_pad
, &open
->pad
);
1630 m
= match_etag (&tag_e_decimal
, &open
->decimal
);
1633 m
= match_etag (&tag_e_encoding
, &open
->encoding
);
1636 m
= match_etag (&tag_e_round
, &open
->round
);
1639 m
= match_etag (&tag_e_sign
, &open
->sign
);
1642 m
= match_ltag (&tag_err
, &open
->err
);
1645 m
= match_etag (&tag_convert
, &open
->convert
);
1648 m
= match_out_tag (&tag_newunit
, &open
->newunit
);
1656 /* Free the gfc_open structure and all the expressions it contains. */
1659 gfc_free_open (gfc_open
*open
)
1664 gfc_free_expr (open
->unit
);
1665 gfc_free_expr (open
->iomsg
);
1666 gfc_free_expr (open
->iostat
);
1667 gfc_free_expr (open
->file
);
1668 gfc_free_expr (open
->status
);
1669 gfc_free_expr (open
->access
);
1670 gfc_free_expr (open
->form
);
1671 gfc_free_expr (open
->recl
);
1672 gfc_free_expr (open
->blank
);
1673 gfc_free_expr (open
->position
);
1674 gfc_free_expr (open
->action
);
1675 gfc_free_expr (open
->delim
);
1676 gfc_free_expr (open
->pad
);
1677 gfc_free_expr (open
->decimal
);
1678 gfc_free_expr (open
->encoding
);
1679 gfc_free_expr (open
->round
);
1680 gfc_free_expr (open
->sign
);
1681 gfc_free_expr (open
->convert
);
1682 gfc_free_expr (open
->asynchronous
);
1683 gfc_free_expr (open
->newunit
);
1688 /* Resolve everything in a gfc_open structure. */
1691 gfc_resolve_open (gfc_open
*open
)
1694 RESOLVE_TAG (&tag_unit
, open
->unit
);
1695 RESOLVE_TAG (&tag_iomsg
, open
->iomsg
);
1696 RESOLVE_TAG (&tag_iostat
, open
->iostat
);
1697 RESOLVE_TAG (&tag_file
, open
->file
);
1698 RESOLVE_TAG (&tag_status
, open
->status
);
1699 RESOLVE_TAG (&tag_e_access
, open
->access
);
1700 RESOLVE_TAG (&tag_e_form
, open
->form
);
1701 RESOLVE_TAG (&tag_e_recl
, open
->recl
);
1702 RESOLVE_TAG (&tag_e_blank
, open
->blank
);
1703 RESOLVE_TAG (&tag_e_position
, open
->position
);
1704 RESOLVE_TAG (&tag_e_action
, open
->action
);
1705 RESOLVE_TAG (&tag_e_delim
, open
->delim
);
1706 RESOLVE_TAG (&tag_e_pad
, open
->pad
);
1707 RESOLVE_TAG (&tag_e_decimal
, open
->decimal
);
1708 RESOLVE_TAG (&tag_e_encoding
, open
->encoding
);
1709 RESOLVE_TAG (&tag_e_async
, open
->asynchronous
);
1710 RESOLVE_TAG (&tag_e_round
, open
->round
);
1711 RESOLVE_TAG (&tag_e_sign
, open
->sign
);
1712 RESOLVE_TAG (&tag_convert
, open
->convert
);
1713 RESOLVE_TAG (&tag_newunit
, open
->newunit
);
1715 if (!gfc_reference_st_label (open
->err
, ST_LABEL_TARGET
))
1722 /* Check if a given value for a SPECIFIER is either in the list of values
1723 allowed in F95 or F2003, issuing an error message and returning a zero
1724 value if it is not allowed. */
1727 compare_to_allowed_values (const char *specifier
, const char *allowed
[],
1728 const char *allowed_f2003
[],
1729 const char *allowed_gnu
[], gfc_char_t
*value
,
1730 const char *statement
, bool warn
)
1735 len
= gfc_wide_strlen (value
);
1738 for (len
--; len
> 0; len
--)
1739 if (value
[len
] != ' ')
1744 for (i
= 0; allowed
[i
]; i
++)
1745 if (len
== strlen (allowed
[i
])
1746 && gfc_wide_strncasecmp (value
, allowed
[i
], strlen (allowed
[i
])) == 0)
1749 for (i
= 0; allowed_f2003
&& allowed_f2003
[i
]; i
++)
1750 if (len
== strlen (allowed_f2003
[i
])
1751 && gfc_wide_strncasecmp (value
, allowed_f2003
[i
],
1752 strlen (allowed_f2003
[i
])) == 0)
1754 notification n
= gfc_notification_std (GFC_STD_F2003
);
1756 if (n
== WARNING
|| (warn
&& n
== ERROR
))
1758 gfc_warning (0, "Fortran 2003: %s specifier in %s statement at %C "
1759 "has value %qs", specifier
, statement
,
1766 gfc_notify_std (GFC_STD_F2003
, "%s specifier in "
1767 "%s statement at %C has value %qs", specifier
,
1768 statement
, allowed_f2003
[i
]);
1776 for (i
= 0; allowed_gnu
&& allowed_gnu
[i
]; i
++)
1777 if (len
== strlen (allowed_gnu
[i
])
1778 && gfc_wide_strncasecmp (value
, allowed_gnu
[i
],
1779 strlen (allowed_gnu
[i
])) == 0)
1781 notification n
= gfc_notification_std (GFC_STD_GNU
);
1783 if (n
== WARNING
|| (warn
&& n
== ERROR
))
1785 gfc_warning (0, "Extension: %s specifier in %s statement at %C "
1786 "has value %qs", specifier
, statement
,
1793 gfc_notify_std (GFC_STD_GNU
, "%s specifier in "
1794 "%s statement at %C has value %qs", specifier
,
1795 statement
, allowed_gnu
[i
]);
1805 char *s
= gfc_widechar_to_char (value
, -1);
1807 "%s specifier in %s statement at %C has invalid value %qs",
1808 specifier
, statement
, s
);
1814 char *s
= gfc_widechar_to_char (value
, -1);
1815 gfc_error ("%s specifier in %s statement at %C has invalid value %qs",
1816 specifier
, statement
, s
);
1823 /* Match an OPEN statement. */
1826 gfc_match_open (void)
1832 m
= gfc_match_char ('(');
1836 open
= XCNEW (gfc_open
);
1838 m
= match_open_element (open
);
1840 if (m
== MATCH_ERROR
)
1844 m
= gfc_match_expr (&open
->unit
);
1845 if (m
== MATCH_ERROR
)
1851 if (gfc_match_char (')') == MATCH_YES
)
1853 if (gfc_match_char (',') != MATCH_YES
)
1856 m
= match_open_element (open
);
1857 if (m
== MATCH_ERROR
)
1863 if (gfc_match_eos () == MATCH_NO
)
1866 if (gfc_pure (NULL
))
1868 gfc_error ("OPEN statement not allowed in PURE procedure at %C");
1872 gfc_unset_implicit_pure (NULL
);
1874 warn
= (open
->err
|| open
->iostat
) ? true : false;
1876 /* Checks on NEWUNIT specifier. */
1881 gfc_error ("UNIT specifier not allowed with NEWUNIT at %C");
1885 if (!(open
->file
|| (open
->status
1886 && gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
1887 "scratch", 7) == 0)))
1889 gfc_error ("NEWUNIT specifier must have FILE= "
1890 "or STATUS='scratch' at %C");
1894 else if (!open
->unit
)
1896 gfc_error ("OPEN statement at %C must have UNIT or NEWUNIT specified");
1900 /* Checks on the ACCESS specifier. */
1901 if (open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
)
1903 static const char *access_f95
[] = { "SEQUENTIAL", "DIRECT", NULL
};
1904 static const char *access_f2003
[] = { "STREAM", NULL
};
1905 static const char *access_gnu
[] = { "APPEND", NULL
};
1907 if (!is_char_type ("ACCESS", open
->access
))
1910 if (!compare_to_allowed_values ("ACCESS", access_f95
, access_f2003
,
1912 open
->access
->value
.character
.string
,
1917 /* Checks on the ACTION specifier. */
1918 if (open
->action
&& open
->action
->expr_type
== EXPR_CONSTANT
)
1920 static const char *action
[] = { "READ", "WRITE", "READWRITE", NULL
};
1922 if (!is_char_type ("ACTION", open
->action
))
1925 if (!compare_to_allowed_values ("ACTION", action
, NULL
, NULL
,
1926 open
->action
->value
.character
.string
,
1931 /* Checks on the ASYNCHRONOUS specifier. */
1932 if (open
->asynchronous
)
1934 if (!gfc_notify_std (GFC_STD_F2003
, "ASYNCHRONOUS= at %C "
1935 "not allowed in Fortran 95"))
1938 if (!is_char_type ("ASYNCHRONOUS", open
->asynchronous
))
1941 if (open
->asynchronous
->expr_type
== EXPR_CONSTANT
)
1943 static const char * asynchronous
[] = { "YES", "NO", NULL
};
1945 if (!compare_to_allowed_values ("ASYNCHRONOUS", asynchronous
,
1946 NULL
, NULL
, open
->asynchronous
->value
.character
.string
,
1952 /* Checks on the BLANK specifier. */
1955 if (!gfc_notify_std (GFC_STD_F2003
, "BLANK= at %C "
1956 "not allowed in Fortran 95"))
1959 if (!is_char_type ("BLANK", open
->blank
))
1962 if (open
->blank
->expr_type
== EXPR_CONSTANT
)
1964 static const char *blank
[] = { "ZERO", "NULL", NULL
};
1966 if (!compare_to_allowed_values ("BLANK", blank
, NULL
, NULL
,
1967 open
->blank
->value
.character
.string
,
1973 /* Checks on the DECIMAL specifier. */
1976 if (!gfc_notify_std (GFC_STD_F2003
, "DECIMAL= at %C "
1977 "not allowed in Fortran 95"))
1980 if (!is_char_type ("DECIMAL", open
->decimal
))
1983 if (open
->decimal
->expr_type
== EXPR_CONSTANT
)
1985 static const char * decimal
[] = { "COMMA", "POINT", NULL
};
1987 if (!compare_to_allowed_values ("DECIMAL", decimal
, NULL
, NULL
,
1988 open
->decimal
->value
.character
.string
,
1994 /* Checks on the DELIM specifier. */
1997 if (open
->delim
->expr_type
== EXPR_CONSTANT
)
1999 static const char *delim
[] = { "APOSTROPHE", "QUOTE", "NONE", NULL
};
2001 if (!is_char_type ("DELIM", open
->delim
))
2004 if (!compare_to_allowed_values ("DELIM", delim
, NULL
, NULL
,
2005 open
->delim
->value
.character
.string
,
2011 /* Checks on the ENCODING specifier. */
2014 if (!gfc_notify_std (GFC_STD_F2003
, "ENCODING= at %C "
2015 "not allowed in Fortran 95"))
2018 if (!is_char_type ("ENCODING", open
->encoding
))
2021 if (open
->encoding
->expr_type
== EXPR_CONSTANT
)
2023 static const char * encoding
[] = { "DEFAULT", "UTF-8", NULL
};
2025 if (!compare_to_allowed_values ("ENCODING", encoding
, NULL
, NULL
,
2026 open
->encoding
->value
.character
.string
,
2032 /* Checks on the FORM specifier. */
2033 if (open
->form
&& open
->form
->expr_type
== EXPR_CONSTANT
)
2035 static const char *form
[] = { "FORMATTED", "UNFORMATTED", NULL
};
2037 if (!is_char_type ("FORM", open
->form
))
2040 if (!compare_to_allowed_values ("FORM", form
, NULL
, NULL
,
2041 open
->form
->value
.character
.string
,
2046 /* Checks on the PAD specifier. */
2047 if (open
->pad
&& open
->pad
->expr_type
== EXPR_CONSTANT
)
2049 static const char *pad
[] = { "YES", "NO", NULL
};
2051 if (!is_char_type ("PAD", open
->pad
))
2054 if (!compare_to_allowed_values ("PAD", pad
, NULL
, NULL
,
2055 open
->pad
->value
.character
.string
,
2060 /* Checks on the POSITION specifier. */
2061 if (open
->position
&& open
->position
->expr_type
== EXPR_CONSTANT
)
2063 static const char *position
[] = { "ASIS", "REWIND", "APPEND", NULL
};
2065 if (!is_char_type ("POSITION", open
->position
))
2068 if (!compare_to_allowed_values ("POSITION", position
, NULL
, NULL
,
2069 open
->position
->value
.character
.string
,
2074 /* Checks on the ROUND specifier. */
2077 if (!gfc_notify_std (GFC_STD_F2003
, "ROUND= at %C "
2078 "not allowed in Fortran 95"))
2081 if (!is_char_type ("ROUND", open
->round
))
2084 if (open
->round
->expr_type
== EXPR_CONSTANT
)
2086 static const char * round
[] = { "UP", "DOWN", "ZERO", "NEAREST",
2087 "COMPATIBLE", "PROCESSOR_DEFINED",
2090 if (!compare_to_allowed_values ("ROUND", round
, NULL
, NULL
,
2091 open
->round
->value
.character
.string
,
2097 /* Checks on the SIGN specifier. */
2100 if (!gfc_notify_std (GFC_STD_F2003
, "SIGN= at %C "
2101 "not allowed in Fortran 95"))
2104 if (!is_char_type ("SIGN", open
->sign
))
2107 if (open
->sign
->expr_type
== EXPR_CONSTANT
)
2109 static const char * sign
[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
2112 if (!compare_to_allowed_values ("SIGN", sign
, NULL
, NULL
,
2113 open
->sign
->value
.character
.string
,
2119 #define warn_or_error(...) \
2122 gfc_warning (0, __VA_ARGS__); \
2125 gfc_error (__VA_ARGS__); \
2130 /* Checks on the RECL specifier. */
2131 if (open
->recl
&& open
->recl
->expr_type
== EXPR_CONSTANT
2132 && open
->recl
->ts
.type
== BT_INTEGER
2133 && mpz_sgn (open
->recl
->value
.integer
) != 1)
2135 warn_or_error ("RECL in OPEN statement at %C must be positive");
2138 /* Checks on the STATUS specifier. */
2139 if (open
->status
&& open
->status
->expr_type
== EXPR_CONSTANT
)
2141 static const char *status
[] = { "OLD", "NEW", "SCRATCH",
2142 "REPLACE", "UNKNOWN", NULL
};
2144 if (!is_char_type ("STATUS", open
->status
))
2147 if (!compare_to_allowed_values ("STATUS", status
, NULL
, NULL
,
2148 open
->status
->value
.character
.string
,
2152 /* F2003, 9.4.5: If the STATUS= specifier has the value NEW or REPLACE,
2153 the FILE= specifier shall appear. */
2154 if (open
->file
== NULL
2155 && (gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2157 || gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2160 char *s
= gfc_widechar_to_char (open
->status
->value
.character
.string
,
2162 warn_or_error ("The STATUS specified in OPEN statement at %C is "
2163 "%qs and no FILE specifier is present", s
);
2167 /* F2003, 9.4.5: If the STATUS= specifier has the value SCRATCH,
2168 the FILE= specifier shall not appear. */
2169 if (gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2170 "scratch", 7) == 0 && open
->file
)
2172 warn_or_error ("The STATUS specified in OPEN statement at %C "
2173 "cannot have the value SCRATCH if a FILE specifier "
2178 /* Things that are not allowed for unformatted I/O. */
2179 if (open
->form
&& open
->form
->expr_type
== EXPR_CONSTANT
2180 && (open
->delim
|| open
->decimal
|| open
->encoding
|| open
->round
2181 || open
->sign
|| open
->pad
|| open
->blank
)
2182 && gfc_wide_strncasecmp (open
->form
->value
.character
.string
,
2183 "unformatted", 11) == 0)
2185 const char *spec
= (open
->delim
? "DELIM "
2186 : (open
->pad
? "PAD " : open
->blank
2189 warn_or_error ("%s specifier at %C not allowed in OPEN statement for "
2190 "unformatted I/O", spec
);
2193 if (open
->recl
&& open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
2194 && gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2197 warn_or_error ("RECL specifier not allowed in OPEN statement at %C for "
2202 && open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
2203 && !(gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2204 "sequential", 10) == 0
2205 || gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2207 || gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2210 warn_or_error ("POSITION specifier in OPEN statement at %C only allowed "
2211 "for stream or sequential ACCESS");
2214 #undef warn_or_error
2216 new_st
.op
= EXEC_OPEN
;
2217 new_st
.ext
.open
= open
;
2221 gfc_syntax_error (ST_OPEN
);
2224 gfc_free_open (open
);
2229 /* Free a gfc_close structure an all its expressions. */
2232 gfc_free_close (gfc_close
*close
)
2237 gfc_free_expr (close
->unit
);
2238 gfc_free_expr (close
->iomsg
);
2239 gfc_free_expr (close
->iostat
);
2240 gfc_free_expr (close
->status
);
2245 /* Match elements of a CLOSE statement. */
2248 match_close_element (gfc_close
*close
)
2252 m
= match_etag (&tag_unit
, &close
->unit
);
2255 m
= match_etag (&tag_status
, &close
->status
);
2258 m
= match_etag (&tag_iomsg
, &close
->iomsg
);
2259 if (m
== MATCH_YES
&& !check_char_variable (close
->iomsg
))
2263 m
= match_out_tag (&tag_iostat
, &close
->iostat
);
2266 m
= match_ltag (&tag_err
, &close
->err
);
2274 /* Match a CLOSE statement. */
2277 gfc_match_close (void)
2283 m
= gfc_match_char ('(');
2287 close
= XCNEW (gfc_close
);
2289 m
= match_close_element (close
);
2291 if (m
== MATCH_ERROR
)
2295 m
= gfc_match_expr (&close
->unit
);
2298 if (m
== MATCH_ERROR
)
2304 if (gfc_match_char (')') == MATCH_YES
)
2306 if (gfc_match_char (',') != MATCH_YES
)
2309 m
= match_close_element (close
);
2310 if (m
== MATCH_ERROR
)
2316 if (gfc_match_eos () == MATCH_NO
)
2319 if (gfc_pure (NULL
))
2321 gfc_error ("CLOSE statement not allowed in PURE procedure at %C");
2325 gfc_unset_implicit_pure (NULL
);
2327 warn
= (close
->iostat
|| close
->err
) ? true : false;
2329 /* Checks on the STATUS specifier. */
2330 if (close
->status
&& close
->status
->expr_type
== EXPR_CONSTANT
)
2332 static const char *status
[] = { "KEEP", "DELETE", NULL
};
2334 if (!is_char_type ("STATUS", close
->status
))
2337 if (!compare_to_allowed_values ("STATUS", status
, NULL
, NULL
,
2338 close
->status
->value
.character
.string
,
2343 new_st
.op
= EXEC_CLOSE
;
2344 new_st
.ext
.close
= close
;
2348 gfc_syntax_error (ST_CLOSE
);
2351 gfc_free_close (close
);
2356 /* Resolve everything in a gfc_close structure. */
2359 gfc_resolve_close (gfc_close
*close
)
2361 RESOLVE_TAG (&tag_unit
, close
->unit
);
2362 RESOLVE_TAG (&tag_iomsg
, close
->iomsg
);
2363 RESOLVE_TAG (&tag_iostat
, close
->iostat
);
2364 RESOLVE_TAG (&tag_status
, close
->status
);
2366 if (!gfc_reference_st_label (close
->err
, ST_LABEL_TARGET
))
2369 if (close
->unit
== NULL
)
2371 /* Find a locus from one of the arguments to close, when UNIT is
2373 locus loc
= gfc_current_locus
;
2375 loc
= close
->status
->where
;
2376 else if (close
->iostat
)
2377 loc
= close
->iostat
->where
;
2378 else if (close
->iomsg
)
2379 loc
= close
->iomsg
->where
;
2380 else if (close
->err
)
2381 loc
= close
->err
->where
;
2383 gfc_error ("CLOSE statement at %L requires a UNIT number", &loc
);
2387 if (close
->unit
->expr_type
== EXPR_CONSTANT
2388 && close
->unit
->ts
.type
== BT_INTEGER
2389 && mpz_sgn (close
->unit
->value
.integer
) < 0)
2391 gfc_error ("UNIT number in CLOSE statement at %L must be non-negative",
2392 &close
->unit
->where
);
2399 /* Free a gfc_filepos structure. */
2402 gfc_free_filepos (gfc_filepos
*fp
)
2404 gfc_free_expr (fp
->unit
);
2405 gfc_free_expr (fp
->iomsg
);
2406 gfc_free_expr (fp
->iostat
);
2411 /* Match elements of a REWIND, BACKSPACE, ENDFILE, or FLUSH statement. */
2414 match_file_element (gfc_filepos
*fp
)
2418 m
= match_etag (&tag_unit
, &fp
->unit
);
2421 m
= match_etag (&tag_iomsg
, &fp
->iomsg
);
2422 if (m
== MATCH_YES
&& !check_char_variable (fp
->iomsg
))
2426 m
= match_out_tag (&tag_iostat
, &fp
->iostat
);
2429 m
= match_ltag (&tag_err
, &fp
->err
);
2437 /* Match the second half of the file-positioning statements, REWIND,
2438 BACKSPACE, ENDFILE, or the FLUSH statement. */
2441 match_filepos (gfc_statement st
, gfc_exec_op op
)
2446 fp
= XCNEW (gfc_filepos
);
2448 if (gfc_match_char ('(') == MATCH_NO
)
2450 m
= gfc_match_expr (&fp
->unit
);
2451 if (m
== MATCH_ERROR
)
2459 m
= match_file_element (fp
);
2460 if (m
== MATCH_ERROR
)
2464 m
= gfc_match_expr (&fp
->unit
);
2465 if (m
== MATCH_ERROR
|| m
== MATCH_NO
)
2471 if (gfc_match_char (')') == MATCH_YES
)
2473 if (gfc_match_char (',') != MATCH_YES
)
2476 m
= match_file_element (fp
);
2477 if (m
== MATCH_ERROR
)
2484 if (gfc_match_eos () != MATCH_YES
)
2487 if (gfc_pure (NULL
))
2489 gfc_error ("%s statement not allowed in PURE procedure at %C",
2490 gfc_ascii_statement (st
));
2495 gfc_unset_implicit_pure (NULL
);
2498 new_st
.ext
.filepos
= fp
;
2502 gfc_syntax_error (st
);
2505 gfc_free_filepos (fp
);
2511 gfc_resolve_filepos (gfc_filepos
*fp
)
2513 RESOLVE_TAG (&tag_unit
, fp
->unit
);
2514 RESOLVE_TAG (&tag_iostat
, fp
->iostat
);
2515 RESOLVE_TAG (&tag_iomsg
, fp
->iomsg
);
2516 if (!gfc_reference_st_label (fp
->err
, ST_LABEL_TARGET
))
2519 if (fp
->unit
->expr_type
== EXPR_CONSTANT
2520 && fp
->unit
->ts
.type
== BT_INTEGER
2521 && mpz_sgn (fp
->unit
->value
.integer
) < 0)
2523 gfc_error ("UNIT number in statement at %L must be non-negative",
2531 /* Match the file positioning statements: ENDFILE, BACKSPACE, REWIND,
2532 and the FLUSH statement. */
2535 gfc_match_endfile (void)
2537 return match_filepos (ST_END_FILE
, EXEC_ENDFILE
);
2541 gfc_match_backspace (void)
2543 return match_filepos (ST_BACKSPACE
, EXEC_BACKSPACE
);
2547 gfc_match_rewind (void)
2549 return match_filepos (ST_REWIND
, EXEC_REWIND
);
2553 gfc_match_flush (void)
2555 if (!gfc_notify_std (GFC_STD_F2003
, "FLUSH statement at %C"))
2558 return match_filepos (ST_FLUSH
, EXEC_FLUSH
);
2561 /******************** Data Transfer Statements *********************/
2563 /* Return a default unit number. */
2566 default_unit (io_kind k
)
2575 return gfc_get_int_expr (gfc_default_integer_kind
, NULL
, unit
);
2579 /* Match a unit specification for a data transfer statement. */
2582 match_dt_unit (io_kind k
, gfc_dt
*dt
)
2586 if (gfc_match_char ('*') == MATCH_YES
)
2588 if (dt
->io_unit
!= NULL
)
2591 dt
->io_unit
= default_unit (k
);
2595 if (gfc_match_expr (&e
) == MATCH_YES
)
2597 if (dt
->io_unit
!= NULL
)
2610 gfc_error ("Duplicate UNIT specification at %C");
2615 /* Match a format specification. */
2618 match_dt_format (gfc_dt
*dt
)
2622 gfc_st_label
*label
;
2625 where
= gfc_current_locus
;
2627 if (gfc_match_char ('*') == MATCH_YES
)
2629 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2632 dt
->format_label
= &format_asterisk
;
2636 if ((m
= gfc_match_st_label (&label
)) == MATCH_YES
)
2640 /* Need to check if the format label is actually either an operand
2641 to a user-defined operator or is a kind type parameter. That is,
2642 print 2.ip.8 ! .ip. is a user-defined operator return CHARACTER.
2643 print 1_'(I0)', i ! 1_'(I0)' is a default character string. */
2645 gfc_gobble_whitespace ();
2646 c
= gfc_peek_ascii_char ();
2647 if (c
== '.' || c
== '_')
2648 gfc_current_locus
= where
;
2651 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2653 gfc_free_st_label (label
);
2657 if (!gfc_reference_st_label (label
, ST_LABEL_FORMAT
))
2660 dt
->format_label
= label
;
2664 else if (m
== MATCH_ERROR
)
2665 /* The label was zero or too large. Emit the correct diagnosis. */
2668 if (gfc_match_expr (&e
) == MATCH_YES
)
2670 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2675 dt
->format_expr
= e
;
2679 gfc_current_locus
= where
; /* The only case where we have to restore */
2684 gfc_error ("Duplicate format specification at %C");
2689 /* Traverse a namelist that is part of a READ statement to make sure
2690 that none of the variables in the namelist are INTENT(IN). Returns
2691 nonzero if we find such a variable. */
2694 check_namelist (gfc_symbol
*sym
)
2698 for (p
= sym
->namelist
; p
; p
= p
->next
)
2699 if (p
->sym
->attr
.intent
== INTENT_IN
)
2701 gfc_error ("Symbol %qs in namelist %qs is INTENT(IN) at %C",
2702 p
->sym
->name
, sym
->name
);
2710 /* Match a single data transfer element. */
2713 match_dt_element (io_kind k
, gfc_dt
*dt
)
2715 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2719 if (gfc_match (" unit =") == MATCH_YES
)
2721 m
= match_dt_unit (k
, dt
);
2726 if (gfc_match (" fmt =") == MATCH_YES
)
2728 m
= match_dt_format (dt
);
2733 if (gfc_match (" nml = %n", name
) == MATCH_YES
)
2735 if (dt
->namelist
!= NULL
)
2737 gfc_error ("Duplicate NML specification at %C");
2741 if (gfc_find_symbol (name
, NULL
, 1, &sym
))
2744 if (sym
== NULL
|| sym
->attr
.flavor
!= FL_NAMELIST
)
2746 gfc_error ("Symbol %qs at %C must be a NAMELIST group name",
2747 sym
!= NULL
? sym
->name
: name
);
2752 if (k
== M_READ
&& check_namelist (sym
))
2758 m
= match_etag (&tag_e_async
, &dt
->asynchronous
);
2759 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", dt
->asynchronous
))
2763 m
= match_etag (&tag_e_blank
, &dt
->blank
);
2766 m
= match_etag (&tag_e_delim
, &dt
->delim
);
2769 m
= match_etag (&tag_e_pad
, &dt
->pad
);
2772 m
= match_etag (&tag_e_sign
, &dt
->sign
);
2775 m
= match_etag (&tag_e_round
, &dt
->round
);
2778 m
= match_out_tag (&tag_id
, &dt
->id
);
2781 m
= match_etag (&tag_e_decimal
, &dt
->decimal
);
2784 m
= match_etag (&tag_rec
, &dt
->rec
);
2787 m
= match_etag (&tag_spos
, &dt
->pos
);
2790 m
= match_etag (&tag_iomsg
, &dt
->iomsg
);
2791 if (m
== MATCH_YES
&& !check_char_variable (dt
->iomsg
))
2796 m
= match_out_tag (&tag_iostat
, &dt
->iostat
);
2799 m
= match_ltag (&tag_err
, &dt
->err
);
2801 dt
->err_where
= gfc_current_locus
;
2804 m
= match_etag (&tag_advance
, &dt
->advance
);
2807 m
= match_out_tag (&tag_size
, &dt
->size
);
2811 m
= match_ltag (&tag_end
, &dt
->end
);
2816 gfc_error ("END tag at %C not allowed in output statement");
2819 dt
->end_where
= gfc_current_locus
;
2824 m
= match_ltag (&tag_eor
, &dt
->eor
);
2826 dt
->eor_where
= gfc_current_locus
;
2834 /* Free a data transfer structure and everything below it. */
2837 gfc_free_dt (gfc_dt
*dt
)
2842 gfc_free_expr (dt
->io_unit
);
2843 gfc_free_expr (dt
->format_expr
);
2844 gfc_free_expr (dt
->rec
);
2845 gfc_free_expr (dt
->advance
);
2846 gfc_free_expr (dt
->iomsg
);
2847 gfc_free_expr (dt
->iostat
);
2848 gfc_free_expr (dt
->size
);
2849 gfc_free_expr (dt
->pad
);
2850 gfc_free_expr (dt
->delim
);
2851 gfc_free_expr (dt
->sign
);
2852 gfc_free_expr (dt
->round
);
2853 gfc_free_expr (dt
->blank
);
2854 gfc_free_expr (dt
->decimal
);
2855 gfc_free_expr (dt
->pos
);
2856 gfc_free_expr (dt
->dt_io_kind
);
2857 /* dt->extra_comma is a link to dt_io_kind if it is set. */
2862 /* Resolve everything in a gfc_dt structure. */
2865 gfc_resolve_dt (gfc_dt
*dt
, locus
*loc
)
2870 /* This is set in any case. */
2871 gcc_assert (dt
->dt_io_kind
);
2872 k
= dt
->dt_io_kind
->value
.iokind
;
2874 RESOLVE_TAG (&tag_format
, dt
->format_expr
);
2875 RESOLVE_TAG (&tag_rec
, dt
->rec
);
2876 RESOLVE_TAG (&tag_spos
, dt
->pos
);
2877 RESOLVE_TAG (&tag_advance
, dt
->advance
);
2878 RESOLVE_TAG (&tag_id
, dt
->id
);
2879 RESOLVE_TAG (&tag_iomsg
, dt
->iomsg
);
2880 RESOLVE_TAG (&tag_iostat
, dt
->iostat
);
2881 RESOLVE_TAG (&tag_size
, dt
->size
);
2882 RESOLVE_TAG (&tag_e_pad
, dt
->pad
);
2883 RESOLVE_TAG (&tag_e_delim
, dt
->delim
);
2884 RESOLVE_TAG (&tag_e_sign
, dt
->sign
);
2885 RESOLVE_TAG (&tag_e_round
, dt
->round
);
2886 RESOLVE_TAG (&tag_e_blank
, dt
->blank
);
2887 RESOLVE_TAG (&tag_e_decimal
, dt
->decimal
);
2888 RESOLVE_TAG (&tag_e_async
, dt
->asynchronous
);
2893 gfc_error ("UNIT not specified at %L", loc
);
2897 if (gfc_resolve_expr (e
)
2898 && (e
->ts
.type
!= BT_INTEGER
2899 && (e
->ts
.type
!= BT_CHARACTER
|| e
->expr_type
!= EXPR_VARIABLE
)))
2901 /* If there is no extra comma signifying the "format" form of the IO
2902 statement, then this must be an error. */
2903 if (!dt
->extra_comma
)
2905 gfc_error ("UNIT specification at %L must be an INTEGER expression "
2906 "or a CHARACTER variable", &e
->where
);
2911 /* At this point, we have an extra comma. If io_unit has arrived as
2912 type character, we assume its really the "format" form of the I/O
2913 statement. We set the io_unit to the default unit and format to
2914 the character expression. See F95 Standard section 9.4. */
2915 if (e
->ts
.type
== BT_CHARACTER
&& (k
== M_READ
|| k
== M_PRINT
))
2917 dt
->format_expr
= dt
->io_unit
;
2918 dt
->io_unit
= default_unit (k
);
2920 /* Nullify this pointer now so that a warning/error is not
2921 triggered below for the "Extension". */
2922 dt
->extra_comma
= NULL
;
2927 gfc_error ("Invalid form of WRITE statement at %L, UNIT required",
2928 &dt
->extra_comma
->where
);
2934 if (e
->ts
.type
== BT_CHARACTER
)
2936 if (gfc_has_vector_index (e
))
2938 gfc_error ("Internal unit with vector subscript at %L", &e
->where
);
2942 /* If we are writing, make sure the internal unit can be changed. */
2943 gcc_assert (k
!= M_PRINT
);
2945 && !gfc_check_vardef_context (e
, false, false, false,
2946 _("internal unit in WRITE")))
2950 if (e
->rank
&& e
->ts
.type
!= BT_CHARACTER
)
2952 gfc_error ("External IO UNIT cannot be an array at %L", &e
->where
);
2956 if (e
->expr_type
== EXPR_CONSTANT
&& e
->ts
.type
== BT_INTEGER
2957 && mpz_sgn (e
->value
.integer
) < 0)
2959 gfc_error ("UNIT number in statement at %L must be non-negative",
2964 /* If we are reading and have a namelist, check that all namelist symbols
2965 can appear in a variable definition context. */
2966 if (k
== M_READ
&& dt
->namelist
)
2969 for (n
= dt
->namelist
->namelist
; n
; n
= n
->next
)
2974 e
= gfc_get_variable_expr (gfc_find_sym_in_symtree (n
->sym
));
2975 t
= gfc_check_vardef_context (e
, false, false, false, NULL
);
2980 gfc_error ("NAMELIST %qs in READ statement at %L contains"
2981 " the symbol %qs which may not appear in a"
2982 " variable definition context",
2983 dt
->namelist
->name
, loc
, n
->sym
->name
);
2990 && !gfc_notify_std (GFC_STD_GNU
, "Comma before i/o item list at %L",
2991 &dt
->extra_comma
->where
))
2996 if (!gfc_reference_st_label (dt
->err
, ST_LABEL_TARGET
))
2998 if (dt
->err
->defined
== ST_LABEL_UNKNOWN
)
3000 gfc_error ("ERR tag label %d at %L not defined",
3001 dt
->err
->value
, &dt
->err_where
);
3008 if (!gfc_reference_st_label (dt
->end
, ST_LABEL_TARGET
))
3010 if (dt
->end
->defined
== ST_LABEL_UNKNOWN
)
3012 gfc_error ("END tag label %d at %L not defined",
3013 dt
->end
->value
, &dt
->end_where
);
3020 if (!gfc_reference_st_label (dt
->eor
, ST_LABEL_TARGET
))
3022 if (dt
->eor
->defined
== ST_LABEL_UNKNOWN
)
3024 gfc_error ("EOR tag label %d at %L not defined",
3025 dt
->eor
->value
, &dt
->eor_where
);
3030 /* Check the format label actually exists. */
3031 if (dt
->format_label
&& dt
->format_label
!= &format_asterisk
3032 && dt
->format_label
->defined
== ST_LABEL_UNKNOWN
)
3034 gfc_error ("FORMAT label %d at %L not defined", dt
->format_label
->value
,
3035 &dt
->format_label
->where
);
3043 /* Given an io_kind, return its name. */
3046 io_kind_name (io_kind k
)
3065 gfc_internal_error ("io_kind_name(): bad I/O-kind");
3072 /* Match an IO iteration statement of the form:
3074 ( [<IO element> ,] <IO element>, I = <expr>, <expr> [, <expr> ] )
3076 which is equivalent to a single IO element. This function is
3077 mutually recursive with match_io_element(). */
3079 static match
match_io_element (io_kind
, gfc_code
**);
3082 match_io_iterator (io_kind k
, gfc_code
**result
)
3084 gfc_code
*head
, *tail
, *new_code
;
3092 old_loc
= gfc_current_locus
;
3094 if (gfc_match_char ('(') != MATCH_YES
)
3097 m
= match_io_element (k
, &head
);
3100 if (m
!= MATCH_YES
|| gfc_match_char (',') != MATCH_YES
)
3106 /* Can't be anything but an IO iterator. Build a list. */
3107 iter
= gfc_get_iterator ();
3111 m
= gfc_match_iterator (iter
, 0);
3112 if (m
== MATCH_ERROR
)
3116 gfc_check_do_variable (iter
->var
->symtree
);
3120 m
= match_io_element (k
, &new_code
);
3121 if (m
== MATCH_ERROR
)
3130 tail
= gfc_append_code (tail
, new_code
);
3132 if (gfc_match_char (',') != MATCH_YES
)
3141 if (gfc_match_char (')') != MATCH_YES
)
3144 new_code
= gfc_get_code (EXEC_DO
);
3145 new_code
->ext
.iterator
= iter
;
3147 new_code
->block
= gfc_get_code (EXEC_DO
);
3148 new_code
->block
->next
= head
;
3154 gfc_error ("Syntax error in I/O iterator at %C");
3158 gfc_free_iterator (iter
, 1);
3159 gfc_free_statements (head
);
3160 gfc_current_locus
= old_loc
;
3165 /* Match a single element of an IO list, which is either a single
3166 expression or an IO Iterator. */
3169 match_io_element (io_kind k
, gfc_code
**cpp
)
3177 m
= match_io_iterator (k
, cpp
);
3183 m
= gfc_match_variable (&expr
, 0);
3185 gfc_error ("Expected variable in READ statement at %C");
3189 m
= gfc_match_expr (&expr
);
3191 gfc_error ("Expected expression in %s statement at %C",
3195 if (m
== MATCH_YES
&& k
== M_READ
&& gfc_check_do_variable (expr
->symtree
))
3200 gfc_free_expr (expr
);
3204 cp
= gfc_get_code (EXEC_TRANSFER
);
3207 cp
->ext
.dt
= current_dt
;
3214 /* Match an I/O list, building gfc_code structures as we go. */
3217 match_io_list (io_kind k
, gfc_code
**head_p
)
3219 gfc_code
*head
, *tail
, *new_code
;
3222 *head_p
= head
= tail
= NULL
;
3223 if (gfc_match_eos () == MATCH_YES
)
3228 m
= match_io_element (k
, &new_code
);
3229 if (m
== MATCH_ERROR
)
3234 tail
= gfc_append_code (tail
, new_code
);
3238 if (gfc_match_eos () == MATCH_YES
)
3240 if (gfc_match_char (',') != MATCH_YES
)
3248 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k
));
3251 gfc_free_statements (head
);
3256 /* Attach the data transfer end node. */
3259 terminate_io (gfc_code
*io_code
)
3263 if (io_code
== NULL
)
3264 io_code
= new_st
.block
;
3266 c
= gfc_get_code (EXEC_DT_END
);
3268 /* Point to structure that is already there */
3269 c
->ext
.dt
= new_st
.ext
.dt
;
3270 gfc_append_code (io_code
, c
);
3274 /* Check the constraints for a data transfer statement. The majority of the
3275 constraints appearing in 9.4 of the standard appear here. Some are handled
3276 in resolve_tag and others in gfc_resolve_dt. */
3279 check_io_constraints (io_kind k
, gfc_dt
*dt
, gfc_code
*io_code
,
3282 #define io_constraint(condition,msg,arg)\
3285 gfc_error(msg,arg);\
3291 gfc_symbol
*sym
= NULL
;
3292 bool warn
, unformatted
;
3294 warn
= (dt
->err
|| dt
->iostat
) ? true : false;
3295 unformatted
= dt
->format_expr
== NULL
&& dt
->format_label
== NULL
3296 && dt
->namelist
== NULL
;
3301 if (expr
&& expr
->expr_type
== EXPR_VARIABLE
3302 && expr
->ts
.type
== BT_CHARACTER
)
3304 sym
= expr
->symtree
->n
.sym
;
3306 io_constraint (k
== M_WRITE
&& sym
->attr
.intent
== INTENT_IN
,
3307 "Internal file at %L must not be INTENT(IN)",
3310 io_constraint (gfc_has_vector_index (dt
->io_unit
),
3311 "Internal file incompatible with vector subscript at %L",
3314 io_constraint (dt
->rec
!= NULL
,
3315 "REC tag at %L is incompatible with internal file",
3318 io_constraint (dt
->pos
!= NULL
,
3319 "POS tag at %L is incompatible with internal file",
3322 io_constraint (unformatted
,
3323 "Unformatted I/O not allowed with internal unit at %L",
3324 &dt
->io_unit
->where
);
3326 io_constraint (dt
->asynchronous
!= NULL
,
3327 "ASYNCHRONOUS tag at %L not allowed with internal file",
3328 &dt
->asynchronous
->where
);
3330 if (dt
->namelist
!= NULL
)
3332 if (!gfc_notify_std (GFC_STD_F2003
, "Internal file at %L with "
3333 "namelist", &expr
->where
))
3337 io_constraint (dt
->advance
!= NULL
,
3338 "ADVANCE tag at %L is incompatible with internal file",
3339 &dt
->advance
->where
);
3342 if (expr
&& expr
->ts
.type
!= BT_CHARACTER
)
3345 io_constraint (gfc_pure (NULL
) && (k
== M_READ
|| k
== M_WRITE
),
3346 "IO UNIT in %s statement at %C must be "
3347 "an internal file in a PURE procedure",
3350 if (k
== M_READ
|| k
== M_WRITE
)
3351 gfc_unset_implicit_pure (NULL
);
3356 io_constraint (dt
->end
, "END tag not allowed with output at %L",
3359 io_constraint (dt
->eor
, "EOR tag not allowed with output at %L",
3362 io_constraint (dt
->blank
, "BLANK= specifier not allowed with output at %L",
3365 io_constraint (dt
->pad
, "PAD= specifier not allowed with output at %L",
3368 io_constraint (dt
->size
, "SIZE= specifier not allowed with output at %L",
3373 io_constraint (dt
->size
&& dt
->advance
== NULL
,
3374 "SIZE tag at %L requires an ADVANCE tag",
3377 io_constraint (dt
->eor
&& dt
->advance
== NULL
,
3378 "EOR tag at %L requires an ADVANCE tag",
3382 if (dt
->asynchronous
)
3384 static const char * asynchronous
[] = { "YES", "NO", NULL
};
3386 if (!gfc_reduce_init_expr (dt
->asynchronous
))
3388 gfc_error ("ASYNCHRONOUS= specifier at %L must be an initialization "
3389 "expression", &dt
->asynchronous
->where
);
3393 if (!is_char_type ("ASYNCHRONOUS", dt
->asynchronous
))
3396 if (!compare_to_allowed_values
3397 ("ASYNCHRONOUS", asynchronous
, NULL
, NULL
,
3398 dt
->asynchronous
->value
.character
.string
,
3399 io_kind_name (k
), warn
))
3407 || gfc_wide_strlen (dt
->asynchronous
->value
.character
.string
) != 3
3408 || gfc_wide_strncasecmp (dt
->asynchronous
->value
.character
.string
,
3410 io_constraint (not_yes
,
3411 "ID= specifier at %L must be with ASYNCHRONOUS='yes' "
3412 "specifier", &dt
->id
->where
);
3417 if (!gfc_notify_std (GFC_STD_F2003
, "DECIMAL= at %C "
3418 "not allowed in Fortran 95"))
3421 if (dt
->decimal
->expr_type
== EXPR_CONSTANT
)
3423 static const char * decimal
[] = { "COMMA", "POINT", NULL
};
3425 if (!is_char_type ("DECIMAL", dt
->decimal
))
3428 if (!compare_to_allowed_values ("DECIMAL", decimal
, NULL
, NULL
,
3429 dt
->decimal
->value
.character
.string
,
3430 io_kind_name (k
), warn
))
3433 io_constraint (unformatted
,
3434 "the DECIMAL= specifier at %L must be with an "
3435 "explicit format expression", &dt
->decimal
->where
);
3441 if (!gfc_notify_std (GFC_STD_F2003
, "BLANK= at %C "
3442 "not allowed in Fortran 95"))
3445 if (!is_char_type ("BLANK", dt
->blank
))
3448 if (dt
->blank
->expr_type
== EXPR_CONSTANT
)
3450 static const char * blank
[] = { "NULL", "ZERO", NULL
};
3453 if (!compare_to_allowed_values ("BLANK", blank
, NULL
, NULL
,
3454 dt
->blank
->value
.character
.string
,
3455 io_kind_name (k
), warn
))
3458 io_constraint (unformatted
,
3459 "the BLANK= specifier at %L must be with an "
3460 "explicit format expression", &dt
->blank
->where
);
3466 if (!gfc_notify_std (GFC_STD_F2003
, "PAD= at %C "
3467 "not allowed in Fortran 95"))
3470 if (!is_char_type ("PAD", dt
->pad
))
3473 if (dt
->pad
->expr_type
== EXPR_CONSTANT
)
3475 static const char * pad
[] = { "YES", "NO", NULL
};
3477 if (!compare_to_allowed_values ("PAD", pad
, NULL
, NULL
,
3478 dt
->pad
->value
.character
.string
,
3479 io_kind_name (k
), warn
))
3482 io_constraint (unformatted
,
3483 "the PAD= specifier at %L must be with an "
3484 "explicit format expression", &dt
->pad
->where
);
3490 if (!gfc_notify_std (GFC_STD_F2003
, "ROUND= at %C "
3491 "not allowed in Fortran 95"))
3494 if (!is_char_type ("ROUND", dt
->round
))
3497 if (dt
->round
->expr_type
== EXPR_CONSTANT
)
3499 static const char * round
[] = { "UP", "DOWN", "ZERO", "NEAREST",
3500 "COMPATIBLE", "PROCESSOR_DEFINED",
3503 if (!compare_to_allowed_values ("ROUND", round
, NULL
, NULL
,
3504 dt
->round
->value
.character
.string
,
3505 io_kind_name (k
), warn
))
3512 /* When implemented, change the following to use gfc_notify_std F2003.
3513 if (gfc_notify_std (GFC_STD_F2003, "SIGN= at %C "
3514 "not allowed in Fortran 95") == false)
3515 return MATCH_ERROR; */
3517 if (!is_char_type ("SIGN", dt
->sign
))
3520 if (dt
->sign
->expr_type
== EXPR_CONSTANT
)
3522 static const char * sign
[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
3525 if (!compare_to_allowed_values ("SIGN", sign
, NULL
, NULL
,
3526 dt
->sign
->value
.character
.string
,
3527 io_kind_name (k
), warn
))
3530 io_constraint (unformatted
,
3531 "SIGN= specifier at %L must be with an "
3532 "explicit format expression", &dt
->sign
->where
);
3534 io_constraint (k
== M_READ
,
3535 "SIGN= specifier at %L not allowed in a "
3536 "READ statement", &dt
->sign
->where
);
3542 if (!gfc_notify_std (GFC_STD_F2003
, "DELIM= at %C "
3543 "not allowed in Fortran 95"))
3546 if (!is_char_type ("DELIM", dt
->delim
))
3549 if (dt
->delim
->expr_type
== EXPR_CONSTANT
)
3551 static const char *delim
[] = { "APOSTROPHE", "QUOTE", "NONE", NULL
};
3553 if (!compare_to_allowed_values ("DELIM", delim
, NULL
, NULL
,
3554 dt
->delim
->value
.character
.string
,
3555 io_kind_name (k
), warn
))
3558 io_constraint (k
== M_READ
,
3559 "DELIM= specifier at %L not allowed in a "
3560 "READ statement", &dt
->delim
->where
);
3562 io_constraint (dt
->format_label
!= &format_asterisk
3563 && dt
->namelist
== NULL
,
3564 "DELIM= specifier at %L must have FMT=*",
3567 io_constraint (unformatted
&& dt
->namelist
== NULL
,
3568 "DELIM= specifier at %L must be with FMT=* or "
3569 "NML= specifier ", &dt
->delim
->where
);
3575 io_constraint (io_code
&& dt
->namelist
,
3576 "NAMELIST cannot be followed by IO-list at %L",
3579 io_constraint (dt
->format_expr
,
3580 "IO spec-list cannot contain both NAMELIST group name "
3581 "and format specification at %L",
3582 &dt
->format_expr
->where
);
3584 io_constraint (dt
->format_label
,
3585 "IO spec-list cannot contain both NAMELIST group name "
3586 "and format label at %L", spec_end
);
3588 io_constraint (dt
->rec
,
3589 "NAMELIST IO is not allowed with a REC= specifier "
3590 "at %L", &dt
->rec
->where
);
3592 io_constraint (dt
->advance
,
3593 "NAMELIST IO is not allowed with a ADVANCE= specifier "
3594 "at %L", &dt
->advance
->where
);
3599 io_constraint (dt
->end
,
3600 "An END tag is not allowed with a "
3601 "REC= specifier at %L", &dt
->end_where
);
3603 io_constraint (dt
->format_label
== &format_asterisk
,
3604 "FMT=* is not allowed with a REC= specifier "
3607 io_constraint (dt
->pos
,
3608 "POS= is not allowed with REC= specifier "
3609 "at %L", &dt
->pos
->where
);
3614 int not_yes
, not_no
;
3617 io_constraint (dt
->format_label
== &format_asterisk
,
3618 "List directed format(*) is not allowed with a "
3619 "ADVANCE= specifier at %L.", &expr
->where
);
3621 io_constraint (unformatted
,
3622 "the ADVANCE= specifier at %L must appear with an "
3623 "explicit format expression", &expr
->where
);
3625 if (expr
->expr_type
== EXPR_CONSTANT
&& expr
->ts
.type
== BT_CHARACTER
)
3627 const gfc_char_t
*advance
= expr
->value
.character
.string
;
3628 not_no
= gfc_wide_strlen (advance
) != 2
3629 || gfc_wide_strncasecmp (advance
, "no", 2) != 0;
3630 not_yes
= gfc_wide_strlen (advance
) != 3
3631 || gfc_wide_strncasecmp (advance
, "yes", 3) != 0;
3639 io_constraint (not_no
&& not_yes
,
3640 "ADVANCE= specifier at %L must have value = "
3641 "YES or NO.", &expr
->where
);
3643 io_constraint (dt
->size
&& not_no
&& k
== M_READ
,
3644 "SIZE tag at %L requires an ADVANCE = %<NO%>",
3647 io_constraint (dt
->eor
&& not_no
&& k
== M_READ
,
3648 "EOR tag at %L requires an ADVANCE = %<NO%>",
3652 expr
= dt
->format_expr
;
3653 if (!gfc_simplify_expr (expr
, 0)
3654 || !check_format_string (expr
, k
== M_READ
))
3659 #undef io_constraint
3662 /* Match a READ, WRITE or PRINT statement. */
3665 match_io (io_kind k
)
3667 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3676 where
= gfc_current_locus
;
3678 current_dt
= dt
= XCNEW (gfc_dt
);
3679 m
= gfc_match_char ('(');
3682 where
= gfc_current_locus
;
3685 else if (k
== M_PRINT
)
3687 /* Treat the non-standard case of PRINT namelist. */
3688 if ((gfc_current_form
== FORM_FIXED
|| gfc_peek_ascii_char () == ' ')
3689 && gfc_match_name (name
) == MATCH_YES
)
3691 gfc_find_symbol (name
, NULL
, 1, &sym
);
3692 if (sym
&& sym
->attr
.flavor
== FL_NAMELIST
)
3694 if (!gfc_notify_std (GFC_STD_GNU
, "PRINT namelist at "
3695 "%C is an extension"))
3701 dt
->io_unit
= default_unit (k
);
3706 gfc_current_locus
= where
;
3710 if (gfc_current_form
== FORM_FREE
)
3712 char c
= gfc_peek_ascii_char ();
3713 if (c
!= ' ' && c
!= '*' && c
!= '\'' && c
!= '"')
3720 m
= match_dt_format (dt
);
3721 if (m
== MATCH_ERROR
)
3727 dt
->io_unit
= default_unit (k
);
3732 /* Before issuing an error for a malformed 'print (1,*)' type of
3733 error, check for a default-char-expr of the form ('(I0)'). */
3734 if (k
== M_PRINT
&& m
== MATCH_YES
)
3736 /* Reset current locus to get the initial '(' in an expression. */
3737 gfc_current_locus
= where
;
3738 dt
->format_expr
= NULL
;
3739 m
= match_dt_format (dt
);
3741 if (m
== MATCH_ERROR
)
3743 if (m
== MATCH_NO
|| dt
->format_expr
== NULL
)
3747 dt
->io_unit
= default_unit (k
);
3752 /* Match a control list */
3753 if (match_dt_element (k
, dt
) == MATCH_YES
)
3755 if (match_dt_unit (k
, dt
) != MATCH_YES
)
3758 if (gfc_match_char (')') == MATCH_YES
)
3760 if (gfc_match_char (',') != MATCH_YES
)
3763 m
= match_dt_element (k
, dt
);
3766 if (m
== MATCH_ERROR
)
3769 m
= match_dt_format (dt
);
3772 if (m
== MATCH_ERROR
)
3775 where
= gfc_current_locus
;
3777 m
= gfc_match_name (name
);
3780 gfc_find_symbol (name
, NULL
, 1, &sym
);
3781 if (sym
&& sym
->attr
.flavor
== FL_NAMELIST
)
3784 if (k
== M_READ
&& check_namelist (sym
))
3793 gfc_current_locus
= where
;
3795 goto loop
; /* No matches, try regular elements */
3798 if (gfc_match_char (')') == MATCH_YES
)
3800 if (gfc_match_char (',') != MATCH_YES
)
3806 m
= match_dt_element (k
, dt
);
3809 if (m
== MATCH_ERROR
)
3812 if (gfc_match_char (')') == MATCH_YES
)
3814 if (gfc_match_char (',') != MATCH_YES
)
3820 /* Used in check_io_constraints, where no locus is available. */
3821 spec_end
= gfc_current_locus
;
3823 /* Save the IO kind for later use. */
3824 dt
->dt_io_kind
= gfc_get_iokind_expr (&gfc_current_locus
, k
);
3826 /* Optional leading comma (non-standard). We use a gfc_expr structure here
3827 to save the locus. This is used later when resolving transfer statements
3828 that might have a format expression without unit number. */
3829 if (!comma_flag
&& gfc_match_char (',') == MATCH_YES
)
3830 dt
->extra_comma
= dt
->dt_io_kind
;
3833 if (gfc_match_eos () != MATCH_YES
)
3835 if (comma_flag
&& gfc_match_char (',') != MATCH_YES
)
3837 gfc_error ("Expected comma in I/O list at %C");
3842 m
= match_io_list (k
, &io_code
);
3843 if (m
== MATCH_ERROR
)
3849 /* A full IO statement has been matched. Check the constraints. spec_end is
3850 supplied for cases where no locus is supplied. */
3851 m
= check_io_constraints (k
, dt
, io_code
, &spec_end
);
3853 if (m
== MATCH_ERROR
)
3856 new_st
.op
= (k
== M_READ
) ? EXEC_READ
: EXEC_WRITE
;
3858 new_st
.block
= gfc_get_code (new_st
.op
);
3859 new_st
.block
->next
= io_code
;
3861 terminate_io (io_code
);
3866 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k
));
3876 gfc_match_read (void)
3878 return match_io (M_READ
);
3883 gfc_match_write (void)
3885 return match_io (M_WRITE
);
3890 gfc_match_print (void)
3894 m
= match_io (M_PRINT
);
3898 if (gfc_pure (NULL
))
3900 gfc_error ("PRINT statement at %C not allowed within PURE procedure");
3904 gfc_unset_implicit_pure (NULL
);
3910 /* Free a gfc_inquire structure. */
3913 gfc_free_inquire (gfc_inquire
*inquire
)
3916 if (inquire
== NULL
)
3919 gfc_free_expr (inquire
->unit
);
3920 gfc_free_expr (inquire
->file
);
3921 gfc_free_expr (inquire
->iomsg
);
3922 gfc_free_expr (inquire
->iostat
);
3923 gfc_free_expr (inquire
->exist
);
3924 gfc_free_expr (inquire
->opened
);
3925 gfc_free_expr (inquire
->number
);
3926 gfc_free_expr (inquire
->named
);
3927 gfc_free_expr (inquire
->name
);
3928 gfc_free_expr (inquire
->access
);
3929 gfc_free_expr (inquire
->sequential
);
3930 gfc_free_expr (inquire
->direct
);
3931 gfc_free_expr (inquire
->form
);
3932 gfc_free_expr (inquire
->formatted
);
3933 gfc_free_expr (inquire
->unformatted
);
3934 gfc_free_expr (inquire
->recl
);
3935 gfc_free_expr (inquire
->nextrec
);
3936 gfc_free_expr (inquire
->blank
);
3937 gfc_free_expr (inquire
->position
);
3938 gfc_free_expr (inquire
->action
);
3939 gfc_free_expr (inquire
->read
);
3940 gfc_free_expr (inquire
->write
);
3941 gfc_free_expr (inquire
->readwrite
);
3942 gfc_free_expr (inquire
->delim
);
3943 gfc_free_expr (inquire
->encoding
);
3944 gfc_free_expr (inquire
->pad
);
3945 gfc_free_expr (inquire
->iolength
);
3946 gfc_free_expr (inquire
->convert
);
3947 gfc_free_expr (inquire
->strm_pos
);
3948 gfc_free_expr (inquire
->asynchronous
);
3949 gfc_free_expr (inquire
->decimal
);
3950 gfc_free_expr (inquire
->pending
);
3951 gfc_free_expr (inquire
->id
);
3952 gfc_free_expr (inquire
->sign
);
3953 gfc_free_expr (inquire
->size
);
3954 gfc_free_expr (inquire
->round
);
3959 /* Match an element of an INQUIRE statement. */
3961 #define RETM if (m != MATCH_NO) return m;
3964 match_inquire_element (gfc_inquire
*inquire
)
3968 m
= match_etag (&tag_unit
, &inquire
->unit
);
3969 RETM m
= match_etag (&tag_file
, &inquire
->file
);
3970 RETM m
= match_ltag (&tag_err
, &inquire
->err
);
3971 RETM m
= match_etag (&tag_iomsg
, &inquire
->iomsg
);
3972 if (m
== MATCH_YES
&& !check_char_variable (inquire
->iomsg
))
3974 RETM m
= match_out_tag (&tag_iostat
, &inquire
->iostat
);
3975 RETM m
= match_vtag (&tag_exist
, &inquire
->exist
);
3976 RETM m
= match_vtag (&tag_opened
, &inquire
->opened
);
3977 RETM m
= match_vtag (&tag_named
, &inquire
->named
);
3978 RETM m
= match_vtag (&tag_name
, &inquire
->name
);
3979 RETM m
= match_out_tag (&tag_number
, &inquire
->number
);
3980 RETM m
= match_vtag (&tag_s_access
, &inquire
->access
);
3981 RETM m
= match_vtag (&tag_sequential
, &inquire
->sequential
);
3982 RETM m
= match_vtag (&tag_direct
, &inquire
->direct
);
3983 RETM m
= match_vtag (&tag_s_form
, &inquire
->form
);
3984 RETM m
= match_vtag (&tag_formatted
, &inquire
->formatted
);
3985 RETM m
= match_vtag (&tag_unformatted
, &inquire
->unformatted
);
3986 RETM m
= match_out_tag (&tag_s_recl
, &inquire
->recl
);
3987 RETM m
= match_out_tag (&tag_nextrec
, &inquire
->nextrec
);
3988 RETM m
= match_vtag (&tag_s_blank
, &inquire
->blank
);
3989 RETM m
= match_vtag (&tag_s_position
, &inquire
->position
);
3990 RETM m
= match_vtag (&tag_s_action
, &inquire
->action
);
3991 RETM m
= match_vtag (&tag_read
, &inquire
->read
);
3992 RETM m
= match_vtag (&tag_write
, &inquire
->write
);
3993 RETM m
= match_vtag (&tag_readwrite
, &inquire
->readwrite
);
3994 RETM m
= match_vtag (&tag_s_async
, &inquire
->asynchronous
);
3995 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", inquire
->asynchronous
))
3997 RETM m
= match_vtag (&tag_s_delim
, &inquire
->delim
);
3998 RETM m
= match_vtag (&tag_s_decimal
, &inquire
->decimal
);
3999 RETM m
= match_out_tag (&tag_size
, &inquire
->size
);
4000 RETM m
= match_vtag (&tag_s_encoding
, &inquire
->encoding
);
4001 RETM m
= match_vtag (&tag_s_round
, &inquire
->round
);
4002 RETM m
= match_vtag (&tag_s_sign
, &inquire
->sign
);
4003 RETM m
= match_vtag (&tag_s_pad
, &inquire
->pad
);
4004 RETM m
= match_out_tag (&tag_iolength
, &inquire
->iolength
);
4005 RETM m
= match_vtag (&tag_convert
, &inquire
->convert
);
4006 RETM m
= match_out_tag (&tag_strm_out
, &inquire
->strm_pos
);
4007 RETM m
= match_vtag (&tag_pending
, &inquire
->pending
);
4008 RETM m
= match_vtag (&tag_id
, &inquire
->id
);
4009 RETM m
= match_vtag (&tag_s_iqstream
, &inquire
->iqstream
);
4010 RETM
return MATCH_NO
;
4017 gfc_match_inquire (void)
4019 gfc_inquire
*inquire
;
4024 m
= gfc_match_char ('(');
4028 inquire
= XCNEW (gfc_inquire
);
4030 loc
= gfc_current_locus
;
4032 m
= match_inquire_element (inquire
);
4033 if (m
== MATCH_ERROR
)
4037 m
= gfc_match_expr (&inquire
->unit
);
4038 if (m
== MATCH_ERROR
)
4044 /* See if we have the IOLENGTH form of the inquire statement. */
4045 if (inquire
->iolength
!= NULL
)
4047 if (gfc_match_char (')') != MATCH_YES
)
4050 m
= match_io_list (M_INQUIRE
, &code
);
4051 if (m
== MATCH_ERROR
)
4056 new_st
.op
= EXEC_IOLENGTH
;
4057 new_st
.expr1
= inquire
->iolength
;
4058 new_st
.ext
.inquire
= inquire
;
4060 if (gfc_pure (NULL
))
4062 gfc_free_statements (code
);
4063 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
4067 gfc_unset_implicit_pure (NULL
);
4069 new_st
.block
= gfc_get_code (EXEC_IOLENGTH
);
4070 terminate_io (code
);
4071 new_st
.block
->next
= code
;
4075 /* At this point, we have the non-IOLENGTH inquire statement. */
4078 if (gfc_match_char (')') == MATCH_YES
)
4080 if (gfc_match_char (',') != MATCH_YES
)
4083 m
= match_inquire_element (inquire
);
4084 if (m
== MATCH_ERROR
)
4089 if (inquire
->iolength
!= NULL
)
4091 gfc_error ("IOLENGTH tag invalid in INQUIRE statement at %C");
4096 if (gfc_match_eos () != MATCH_YES
)
4099 if (inquire
->unit
!= NULL
&& inquire
->file
!= NULL
)
4101 gfc_error ("INQUIRE statement at %L cannot contain both FILE and "
4102 "UNIT specifiers", &loc
);
4106 if (inquire
->unit
== NULL
&& inquire
->file
== NULL
)
4108 gfc_error ("INQUIRE statement at %L requires either FILE or "
4109 "UNIT specifier", &loc
);
4113 if (inquire
->unit
!= NULL
&& inquire
->unit
->expr_type
== EXPR_CONSTANT
4114 && inquire
->unit
->ts
.type
== BT_INTEGER
4115 && mpz_get_si (inquire
->unit
->value
.integer
) == GFC_INTERNAL_UNIT
)
4117 gfc_error ("UNIT number in INQUIRE statement at %L can not be -1", &loc
);
4121 if (gfc_pure (NULL
))
4123 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
4127 gfc_unset_implicit_pure (NULL
);
4129 if (inquire
->id
!= NULL
&& inquire
->pending
== NULL
)
4131 gfc_error ("INQUIRE statement at %L requires a PENDING= specifier with "
4132 "the ID= specifier", &loc
);
4136 new_st
.op
= EXEC_INQUIRE
;
4137 new_st
.ext
.inquire
= inquire
;
4141 gfc_syntax_error (ST_INQUIRE
);
4144 gfc_free_inquire (inquire
);
4149 /* Resolve everything in a gfc_inquire structure. */
4152 gfc_resolve_inquire (gfc_inquire
*inquire
)
4154 RESOLVE_TAG (&tag_unit
, inquire
->unit
);
4155 RESOLVE_TAG (&tag_file
, inquire
->file
);
4156 RESOLVE_TAG (&tag_id
, inquire
->id
);
4158 /* For INQUIRE, all tags except FILE, ID and UNIT are variable definition
4159 contexts. Thus, use an extended RESOLVE_TAG macro for that. */
4160 #define INQUIRE_RESOLVE_TAG(tag, expr) \
4161 RESOLVE_TAG (tag, expr); \
4165 sprintf (context, _("%s tag with INQUIRE"), (tag)->name); \
4166 if (gfc_check_vardef_context ((expr), false, false, false, \
4167 context) == false) \
4170 INQUIRE_RESOLVE_TAG (&tag_iomsg
, inquire
->iomsg
);
4171 INQUIRE_RESOLVE_TAG (&tag_iostat
, inquire
->iostat
);
4172 INQUIRE_RESOLVE_TAG (&tag_exist
, inquire
->exist
);
4173 INQUIRE_RESOLVE_TAG (&tag_opened
, inquire
->opened
);
4174 INQUIRE_RESOLVE_TAG (&tag_number
, inquire
->number
);
4175 INQUIRE_RESOLVE_TAG (&tag_named
, inquire
->named
);
4176 INQUIRE_RESOLVE_TAG (&tag_name
, inquire
->name
);
4177 INQUIRE_RESOLVE_TAG (&tag_s_access
, inquire
->access
);
4178 INQUIRE_RESOLVE_TAG (&tag_sequential
, inquire
->sequential
);
4179 INQUIRE_RESOLVE_TAG (&tag_direct
, inquire
->direct
);
4180 INQUIRE_RESOLVE_TAG (&tag_s_form
, inquire
->form
);
4181 INQUIRE_RESOLVE_TAG (&tag_formatted
, inquire
->formatted
);
4182 INQUIRE_RESOLVE_TAG (&tag_unformatted
, inquire
->unformatted
);
4183 INQUIRE_RESOLVE_TAG (&tag_s_recl
, inquire
->recl
);
4184 INQUIRE_RESOLVE_TAG (&tag_nextrec
, inquire
->nextrec
);
4185 INQUIRE_RESOLVE_TAG (&tag_s_blank
, inquire
->blank
);
4186 INQUIRE_RESOLVE_TAG (&tag_s_position
, inquire
->position
);
4187 INQUIRE_RESOLVE_TAG (&tag_s_action
, inquire
->action
);
4188 INQUIRE_RESOLVE_TAG (&tag_read
, inquire
->read
);
4189 INQUIRE_RESOLVE_TAG (&tag_write
, inquire
->write
);
4190 INQUIRE_RESOLVE_TAG (&tag_readwrite
, inquire
->readwrite
);
4191 INQUIRE_RESOLVE_TAG (&tag_s_delim
, inquire
->delim
);
4192 INQUIRE_RESOLVE_TAG (&tag_s_pad
, inquire
->pad
);
4193 INQUIRE_RESOLVE_TAG (&tag_s_encoding
, inquire
->encoding
);
4194 INQUIRE_RESOLVE_TAG (&tag_s_round
, inquire
->round
);
4195 INQUIRE_RESOLVE_TAG (&tag_iolength
, inquire
->iolength
);
4196 INQUIRE_RESOLVE_TAG (&tag_convert
, inquire
->convert
);
4197 INQUIRE_RESOLVE_TAG (&tag_strm_out
, inquire
->strm_pos
);
4198 INQUIRE_RESOLVE_TAG (&tag_s_async
, inquire
->asynchronous
);
4199 INQUIRE_RESOLVE_TAG (&tag_s_sign
, inquire
->sign
);
4200 INQUIRE_RESOLVE_TAG (&tag_s_round
, inquire
->round
);
4201 INQUIRE_RESOLVE_TAG (&tag_pending
, inquire
->pending
);
4202 INQUIRE_RESOLVE_TAG (&tag_size
, inquire
->size
);
4203 INQUIRE_RESOLVE_TAG (&tag_s_decimal
, inquire
->decimal
);
4204 INQUIRE_RESOLVE_TAG (&tag_s_iqstream
, inquire
->iqstream
);
4205 #undef INQUIRE_RESOLVE_TAG
4207 if (!gfc_reference_st_label (inquire
->err
, ST_LABEL_TARGET
))
4215 gfc_free_wait (gfc_wait
*wait
)
4220 gfc_free_expr (wait
->unit
);
4221 gfc_free_expr (wait
->iostat
);
4222 gfc_free_expr (wait
->iomsg
);
4223 gfc_free_expr (wait
->id
);
4229 gfc_resolve_wait (gfc_wait
*wait
)
4231 RESOLVE_TAG (&tag_unit
, wait
->unit
);
4232 RESOLVE_TAG (&tag_iomsg
, wait
->iomsg
);
4233 RESOLVE_TAG (&tag_iostat
, wait
->iostat
);
4234 RESOLVE_TAG (&tag_id
, wait
->id
);
4236 if (!gfc_reference_st_label (wait
->err
, ST_LABEL_TARGET
))
4239 if (!gfc_reference_st_label (wait
->end
, ST_LABEL_TARGET
))
4245 /* Match an element of a WAIT statement. */
4247 #define RETM if (m != MATCH_NO) return m;
4250 match_wait_element (gfc_wait
*wait
)
4254 m
= match_etag (&tag_unit
, &wait
->unit
);
4255 RETM m
= match_ltag (&tag_err
, &wait
->err
);
4256 RETM m
= match_ltag (&tag_end
, &wait
->eor
);
4257 RETM m
= match_ltag (&tag_eor
, &wait
->end
);
4258 RETM m
= match_etag (&tag_iomsg
, &wait
->iomsg
);
4259 if (m
== MATCH_YES
&& !check_char_variable (wait
->iomsg
))
4261 RETM m
= match_out_tag (&tag_iostat
, &wait
->iostat
);
4262 RETM m
= match_etag (&tag_id
, &wait
->id
);
4263 RETM
return MATCH_NO
;
4270 gfc_match_wait (void)
4275 m
= gfc_match_char ('(');
4279 wait
= XCNEW (gfc_wait
);
4281 m
= match_wait_element (wait
);
4282 if (m
== MATCH_ERROR
)
4286 m
= gfc_match_expr (&wait
->unit
);
4287 if (m
== MATCH_ERROR
)
4295 if (gfc_match_char (')') == MATCH_YES
)
4297 if (gfc_match_char (',') != MATCH_YES
)
4300 m
= match_wait_element (wait
);
4301 if (m
== MATCH_ERROR
)
4307 if (!gfc_notify_std (GFC_STD_F2003
, "WAIT at %C "
4308 "not allowed in Fortran 95"))
4311 if (gfc_pure (NULL
))
4313 gfc_error ("WAIT statement not allowed in PURE procedure at %C");
4317 gfc_unset_implicit_pure (NULL
);
4319 new_st
.op
= EXEC_WAIT
;
4320 new_st
.ext
.wait
= wait
;
4325 gfc_syntax_error (ST_WAIT
);
4328 gfc_free_wait (wait
);