1 /* Deal with I/O statements & related stuff.
2 Copyright (C) 2000-2017 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
,
31 0, {NULL
, NULL
}, NULL
};
35 const char *name
, *spec
, *value
;
41 tag_readonly
= {"READONLY", " readonly", NULL
, BT_UNKNOWN
},
42 tag_shared
= {"SHARE", " shared", NULL
, BT_UNKNOWN
},
43 tag_noshared
= {"SHARE", " noshared", NULL
, BT_UNKNOWN
},
44 tag_e_share
= {"SHARE", " share =", " %e", BT_CHARACTER
},
45 tag_v_share
= {"SHARE", " share =", " %v", BT_CHARACTER
},
46 tag_cc
= {"CARRIAGECONTROL", " carriagecontrol =", " %e",
48 tag_v_cc
= {"CARRIAGECONTROL", " carriagecontrol =", " %v",
50 tag_file
= {"FILE", " file =", " %e", BT_CHARACTER
},
51 tag_status
= {"STATUS", " status =", " %e", BT_CHARACTER
},
52 tag_e_access
= {"ACCESS", " access =", " %e", BT_CHARACTER
},
53 tag_e_form
= {"FORM", " form =", " %e", BT_CHARACTER
},
54 tag_e_recl
= {"RECL", " recl =", " %e", BT_INTEGER
},
55 tag_e_blank
= {"BLANK", " blank =", " %e", BT_CHARACTER
},
56 tag_e_position
= {"POSITION", " position =", " %e", BT_CHARACTER
},
57 tag_e_action
= {"ACTION", " action =", " %e", BT_CHARACTER
},
58 tag_e_delim
= {"DELIM", " delim =", " %e", BT_CHARACTER
},
59 tag_e_pad
= {"PAD", " pad =", " %e", BT_CHARACTER
},
60 tag_e_decimal
= {"DECIMAL", " decimal =", " %e", BT_CHARACTER
},
61 tag_e_encoding
= {"ENCODING", " encoding =", " %e", BT_CHARACTER
},
62 tag_e_async
= {"ASYNCHRONOUS", " asynchronous =", " %e", BT_CHARACTER
},
63 tag_e_round
= {"ROUND", " round =", " %e", BT_CHARACTER
},
64 tag_e_sign
= {"SIGN", " sign =", " %e", BT_CHARACTER
},
65 tag_unit
= {"UNIT", " unit =", " %e", BT_INTEGER
},
66 tag_advance
= {"ADVANCE", " advance =", " %e", BT_CHARACTER
},
67 tag_rec
= {"REC", " rec =", " %e", BT_INTEGER
},
68 tag_spos
= {"POSITION", " pos =", " %e", BT_INTEGER
},
69 tag_format
= {"FORMAT", NULL
, NULL
, BT_CHARACTER
},
70 tag_iomsg
= {"IOMSG", " iomsg =", " %e", BT_CHARACTER
},
71 tag_iostat
= {"IOSTAT", " iostat =", " %v", BT_INTEGER
},
72 tag_size
= {"SIZE", " size =", " %v", BT_INTEGER
},
73 tag_exist
= {"EXIST", " exist =", " %v", BT_LOGICAL
},
74 tag_opened
= {"OPENED", " opened =", " %v", BT_LOGICAL
},
75 tag_named
= {"NAMED", " named =", " %v", BT_LOGICAL
},
76 tag_name
= {"NAME", " name =", " %v", BT_CHARACTER
},
77 tag_number
= {"NUMBER", " number =", " %v", BT_INTEGER
},
78 tag_s_access
= {"ACCESS", " access =", " %v", BT_CHARACTER
},
79 tag_sequential
= {"SEQUENTIAL", " sequential =", " %v", BT_CHARACTER
},
80 tag_direct
= {"DIRECT", " direct =", " %v", BT_CHARACTER
},
81 tag_s_form
= {"FORM", " form =", " %v", BT_CHARACTER
},
82 tag_formatted
= {"FORMATTED", " formatted =", " %v", BT_CHARACTER
},
83 tag_unformatted
= {"UNFORMATTED", " unformatted =", " %v", BT_CHARACTER
},
84 tag_s_recl
= {"RECL", " recl =", " %v", BT_INTEGER
},
85 tag_nextrec
= {"NEXTREC", " nextrec =", " %v", BT_INTEGER
},
86 tag_s_blank
= {"BLANK", " blank =", " %v", BT_CHARACTER
},
87 tag_s_position
= {"POSITION", " position =", " %v", BT_CHARACTER
},
88 tag_s_action
= {"ACTION", " action =", " %v", BT_CHARACTER
},
89 tag_read
= {"READ", " read =", " %v", BT_CHARACTER
},
90 tag_write
= {"WRITE", " write =", " %v", BT_CHARACTER
},
91 tag_readwrite
= {"READWRITE", " readwrite =", " %v", BT_CHARACTER
},
92 tag_s_delim
= {"DELIM", " delim =", " %v", BT_CHARACTER
},
93 tag_s_pad
= {"PAD", " pad =", " %v", BT_CHARACTER
},
94 tag_s_decimal
= {"DECIMAL", " decimal =", " %v", BT_CHARACTER
},
95 tag_s_encoding
= {"ENCODING", " encoding =", " %v", BT_CHARACTER
},
96 tag_s_async
= {"ASYNCHRONOUS", " asynchronous =", " %v", BT_CHARACTER
},
97 tag_s_round
= {"ROUND", " round =", " %v", BT_CHARACTER
},
98 tag_s_sign
= {"SIGN", " sign =", " %v", BT_CHARACTER
},
99 tag_iolength
= {"IOLENGTH", " iolength =", " %v", BT_INTEGER
},
100 tag_convert
= {"CONVERT", " convert =", " %e", BT_CHARACTER
},
101 tag_strm_out
= {"POS", " pos =", " %v", BT_INTEGER
},
102 tag_err
= {"ERR", " err =", " %l", BT_UNKNOWN
},
103 tag_end
= {"END", " end =", " %l", BT_UNKNOWN
},
104 tag_eor
= {"EOR", " eor =", " %l", BT_UNKNOWN
},
105 tag_id
= {"ID", " id =", " %v", BT_INTEGER
},
106 tag_pending
= {"PENDING", " pending =", " %v", BT_LOGICAL
},
107 tag_newunit
= {"NEWUNIT", " newunit =", " %v", BT_INTEGER
},
108 tag_s_iqstream
= {"STREAM", " stream =", " %v", BT_CHARACTER
};
110 static gfc_dt
*current_dt
;
112 #define RESOLVE_TAG(x, y) if (!resolve_tag (x, y)) return false;
115 /**************** Fortran 95 FORMAT parser *****************/
117 /* FORMAT tokens returned by format_lex(). */
120 FMT_NONE
, FMT_UNKNOWN
, FMT_SIGNED_INT
, FMT_ZERO
, FMT_POSINT
, FMT_PERIOD
,
121 FMT_COMMA
, FMT_COLON
, FMT_SLASH
, FMT_DOLLAR
, FMT_LPAREN
,
122 FMT_RPAREN
, FMT_X
, FMT_SIGN
, FMT_BLANK
, FMT_CHAR
, FMT_P
, FMT_IBOZ
, FMT_F
,
123 FMT_E
, FMT_EN
, FMT_ES
, FMT_G
, FMT_L
, FMT_A
, FMT_D
, FMT_H
, FMT_END
,
124 FMT_ERROR
, FMT_DC
, FMT_DP
, FMT_T
, FMT_TR
, FMT_TL
, FMT_STAR
, FMT_RC
,
125 FMT_RD
, FMT_RN
, FMT_RP
, FMT_RU
, FMT_RZ
, FMT_DT
128 /* Local variables for checking format strings. The saved_token is
129 used to back up by a single format token during the parsing
131 static gfc_char_t
*format_string
;
132 static int format_string_pos
;
133 static int format_length
, use_last_char
;
134 static char error_element
;
135 static locus format_locus
;
137 static format_token saved_token
;
140 { MODE_STRING
, MODE_FORMAT
, MODE_COPY
}
144 /* Return the next character in the format string. */
147 next_char (gfc_instring in_string
)
159 if (mode
== MODE_STRING
)
160 c
= *format_string
++;
163 c
= gfc_next_char_literal (in_string
);
168 if (flag_backslash
&& c
== '\\')
170 locus old_locus
= gfc_current_locus
;
172 if (gfc_match_special_char (&c
) == MATCH_NO
)
173 gfc_current_locus
= old_locus
;
175 if (!(gfc_option
.allow_std
& GFC_STD_GNU
) && !inhibit_warnings
)
176 gfc_warning (0, "Extension: backslash character at %C");
179 if (mode
== MODE_COPY
)
180 *format_string
++ = c
;
182 if (mode
!= MODE_STRING
)
183 format_locus
= gfc_current_locus
;
187 c
= gfc_wide_toupper (c
);
192 /* Back up one character position. Only works once. */
200 /* Eat up the spaces and return a character. */
203 next_char_not_space ()
208 error_element
= c
= next_char (NONSTRING
);
210 gfc_warning (OPT_Wtabs
, "Nonconforming tab character in format at %C");
212 while (gfc_is_whitespace (c
));
216 static int value
= 0;
218 /* Simple lexical analyzer for getting the next token in a FORMAT
229 if (saved_token
!= FMT_NONE
)
232 saved_token
= FMT_NONE
;
236 c
= next_char_not_space ();
246 c
= next_char_not_space ();
257 c
= next_char_not_space ();
259 value
= 10 * value
+ c
- '0';
268 token
= FMT_SIGNED_INT
;
287 c
= next_char_not_space ();
290 value
= 10 * value
+ c
- '0';
298 token
= zflag
? FMT_ZERO
: FMT_POSINT
;
322 c
= next_char_not_space ();
350 c
= next_char_not_space ();
351 if (c
!= 'P' && c
!= 'S')
358 c
= next_char_not_space ();
359 if (c
== 'N' || c
== 'Z')
377 c
= next_char (INSTRING_WARN
);
386 c
= next_char (NONSTRING
);
420 c
= next_char_not_space ();
450 c
= next_char_not_space ();
453 if (!gfc_notify_std (GFC_STD_F2003
, "DP format "
454 "specifier not allowed at %C"))
460 if (!gfc_notify_std (GFC_STD_F2003
, "DC format "
461 "specifier not allowed at %C"))
467 if (!gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: DT format "
468 "specifier not allowed at %C"))
471 c
= next_char_not_space ();
472 if (c
== '\'' || c
== '"')
479 c
= next_char (INSTRING_WARN
);
488 c
= next_char (NONSTRING
);
522 c
= next_char_not_space ();
568 token_to_string (format_token t
)
587 /* Check a format statement. The format string, either from a FORMAT
588 statement or a constant in an I/O statement has already been parsed
589 by itself, and we are checking it for validity. The dual origin
590 means that the warning message is a little less than great. */
593 check_format (bool is_input
)
595 const char *posint_required
= _("Positive width required");
596 const char *nonneg_required
= _("Nonnegative width required");
597 const char *unexpected_element
= _("Unexpected element %qc in format "
599 const char *unexpected_end
= _("Unexpected end of format string");
600 const char *zero_width
= _("Zero width in format descriptor");
602 const char *error
= NULL
;
609 saved_token
= FMT_NONE
;
613 format_string_pos
= 0;
620 error
= _("Missing leading left parenthesis");
628 goto finished
; /* Empty format is legal */
632 /* In this state, the next thing has to be a format item. */
649 error
= _("Left parenthesis required after %<*%>");
674 /* Signed integer can only precede a P format. */
680 error
= _("Expected P edit descriptor");
687 /* P requires a prior number. */
688 error
= _("P descriptor requires leading scale factor");
692 /* X requires a prior number if we're being pedantic. */
693 if (mode
!= MODE_FORMAT
)
694 format_locus
.nextc
+= format_string_pos
;
695 if (!gfc_notify_std (GFC_STD_GNU
, "X descriptor requires leading "
696 "space count at %L", &format_locus
))
713 goto extension_optional_comma
;
724 if (!gfc_notify_std (GFC_STD_GNU
, "$ descriptor at %L", &format_locus
))
726 if (t
!= FMT_RPAREN
|| level
> 0)
728 gfc_warning (0, "$ should be the last specifier in format at %L",
730 goto optional_comma_1
;
752 error
= unexpected_end
;
756 error
= unexpected_element
;
761 /* In this state, t must currently be a data descriptor.
762 Deal with things that can/must follow the descriptor. */
773 /* No comma after P allowed only for F, E, EN, ES, D, or G.
778 if (!(gfc_option
.allow_std
& GFC_STD_F2003
) && t
!= FMT_COMMA
779 && t
!= FMT_F
&& t
!= FMT_E
&& t
!= FMT_EN
&& t
!= FMT_ES
780 && t
!= FMT_D
&& t
!= FMT_G
&& t
!= FMT_RPAREN
&& t
!= FMT_SLASH
)
782 error
= _("Comma required after P descriptor");
793 if (t
!= FMT_F
&& t
!= FMT_E
&& t
!= FMT_EN
&& t
!= FMT_ES
&& t
!= FMT_D
794 && t
!= FMT_G
&& t
!= FMT_RPAREN
&& t
!= FMT_SLASH
)
796 error
= _("Comma required after P descriptor");
810 error
= _("Positive width required with T descriptor");
821 if (mode
!= MODE_FORMAT
)
822 format_locus
.nextc
+= format_string_pos
;
825 switch (gfc_notification_std (GFC_STD_GNU
))
828 gfc_warning (0, "Extension: Zero width after L "
829 "descriptor at %L", &format_locus
);
832 gfc_error ("Extension: Zero width after L "
833 "descriptor at %L", &format_locus
);
844 gfc_notify_std (GFC_STD_GNU
, "Missing positive width after "
845 "L descriptor at %L", &format_locus
);
868 if (t
== FMT_G
&& u
== FMT_ZERO
)
875 if (!gfc_notify_std (GFC_STD_F2008
, "%<G0%> in format at %L",
887 error
= posint_required
;
893 error
= _("E specifier not allowed with g0 descriptor");
902 format_locus
.nextc
+= format_string_pos
;
903 gfc_error ("Positive width required in format "
904 "specifier %s at %L", token_to_string (t
),
915 /* Warn if -std=legacy, otherwise error. */
916 format_locus
.nextc
+= format_string_pos
;
917 if (gfc_option
.warn_std
!= 0)
919 gfc_error ("Period required in format "
920 "specifier %s at %L", token_to_string (t
),
926 gfc_warning (0, "Period required in format "
927 "specifier %s at %L", token_to_string (t
),
929 /* If we go to finished, we need to unwind this
930 before the next round. */
931 format_locus
.nextc
-= format_string_pos
;
939 if (u
!= FMT_ZERO
&& u
!= FMT_POSINT
)
941 error
= nonneg_required
;
948 /* Look for optional exponent. */
963 error
= _("Positive exponent width required");
994 error
= posint_required
;
1004 if (t
!= FMT_RPAREN
)
1006 error
= _("Right parenthesis expected at %C");
1012 error
= unexpected_element
;
1021 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1023 error
= nonneg_required
;
1026 else if (is_input
&& t
== FMT_ZERO
)
1028 error
= posint_required
;
1035 if (t
!= FMT_PERIOD
)
1037 /* Warn if -std=legacy, otherwise error. */
1038 if (gfc_option
.warn_std
!= 0)
1040 error
= _("Period required in format specifier");
1043 if (mode
!= MODE_FORMAT
)
1044 format_locus
.nextc
+= format_string_pos
;
1045 gfc_warning (0, "Period required in format specifier at %L",
1054 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1056 error
= nonneg_required
;
1063 if (!(gfc_option
.allow_std
& GFC_STD_GNU
) && !inhibit_warnings
)
1065 if (mode
!= MODE_FORMAT
)
1066 format_locus
.nextc
+= format_string_pos
;
1067 gfc_warning (0, "The H format specifier at %L is"
1068 " a Fortran 95 deleted feature", &format_locus
);
1070 if (mode
== MODE_STRING
)
1072 format_string
+= value
;
1073 format_length
-= value
;
1074 format_string_pos
+= repeat
;
1080 next_char (INSTRING_WARN
);
1090 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1092 error
= nonneg_required
;
1095 else if (is_input
&& t
== FMT_ZERO
)
1097 error
= posint_required
;
1104 if (t
!= FMT_PERIOD
)
1113 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1115 error
= nonneg_required
;
1123 error
= unexpected_element
;
1128 /* Between a descriptor and what comes next. */
1146 goto optional_comma
;
1149 error
= unexpected_end
;
1153 if (mode
!= MODE_FORMAT
)
1154 format_locus
.nextc
+= format_string_pos
- 1;
1155 if (!gfc_notify_std (GFC_STD_GNU
, "Missing comma at %L", &format_locus
))
1157 /* If we do not actually return a failure, we need to unwind this
1158 before the next round. */
1159 if (mode
!= MODE_FORMAT
)
1160 format_locus
.nextc
-= format_string_pos
;
1165 /* Optional comma is a weird between state where we've just finished
1166 reading a colon, slash, dollar or P descriptor. */
1183 /* Assume that we have another format item. */
1190 extension_optional_comma
:
1191 /* As a GNU extension, permit a missing comma after a string literal. */
1208 goto optional_comma
;
1211 error
= unexpected_end
;
1215 if (mode
!= MODE_FORMAT
)
1216 format_locus
.nextc
+= format_string_pos
;
1217 if (!gfc_notify_std (GFC_STD_GNU
, "Missing comma at %L", &format_locus
))
1219 /* If we do not actually return a failure, we need to unwind this
1220 before the next round. */
1221 if (mode
!= MODE_FORMAT
)
1222 format_locus
.nextc
-= format_string_pos
;
1230 if (mode
!= MODE_FORMAT
)
1231 format_locus
.nextc
+= format_string_pos
;
1232 if (error
== unexpected_element
)
1233 gfc_error (error
, error_element
, &format_locus
);
1235 gfc_error ("%s in format string at %L", error
, &format_locus
);
1244 /* Given an expression node that is a constant string, see if it looks
1245 like a format string. */
1248 check_format_string (gfc_expr
*e
, bool is_input
)
1252 if (!e
|| e
->ts
.type
!= BT_CHARACTER
|| e
->expr_type
!= EXPR_CONSTANT
)
1256 format_string
= e
->value
.character
.string
;
1258 /* More elaborate measures are needed to show where a problem is within a
1259 format string that has been calculated, but that's probably not worth the
1261 format_locus
= e
->where
;
1262 rv
= check_format (is_input
);
1263 /* check for extraneous characters at the end of an otherwise valid format
1264 string, like '(A10,I3)F5'
1265 start at the end and move back to the last character processed,
1267 if (rv
&& e
->value
.character
.length
> format_string_pos
)
1268 for (i
=e
->value
.character
.length
-1;i
>format_string_pos
-1;i
--)
1269 if (e
->value
.character
.string
[i
] != ' ')
1271 format_locus
.nextc
+= format_length
+ 1;
1273 "Extraneous characters in format at %L", &format_locus
);
1280 /************ Fortran I/O statement matchers *************/
1282 /* Match a FORMAT statement. This amounts to actually parsing the
1283 format descriptors in order to correctly locate the end of the
1287 gfc_match_format (void)
1292 if (gfc_current_ns
->proc_name
1293 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
1295 gfc_error ("Format statement in module main block at %C");
1299 /* Before parsing the rest of a FORMAT statement, check F2008:c1206. */
1300 if ((gfc_current_state () == COMP_FUNCTION
1301 || gfc_current_state () == COMP_SUBROUTINE
)
1302 && gfc_state_stack
->previous
->state
== COMP_INTERFACE
)
1304 gfc_error ("FORMAT statement at %C cannot appear within an INTERFACE");
1308 if (gfc_statement_label
== NULL
)
1310 gfc_error ("Missing format label at %C");
1313 gfc_gobble_whitespace ();
1318 start
= gfc_current_locus
;
1320 if (!check_format (false))
1323 if (gfc_match_eos () != MATCH_YES
)
1325 gfc_syntax_error (ST_FORMAT
);
1329 /* The label doesn't get created until after the statement is done
1330 being matched, so we have to leave the string for later. */
1332 gfc_current_locus
= start
; /* Back to the beginning */
1335 new_st
.op
= EXEC_NOP
;
1337 e
= gfc_get_character_expr (gfc_default_character_kind
, &start
,
1338 NULL
, format_length
);
1339 format_string
= e
->value
.character
.string
;
1340 gfc_statement_label
->format
= e
;
1343 check_format (false); /* Guaranteed to succeed */
1344 gfc_match_eos (); /* Guaranteed to succeed */
1350 /* Check for a CHARACTER variable. The check for scalar is done in
1354 check_char_variable (gfc_expr
*e
)
1356 if (e
->expr_type
!= EXPR_VARIABLE
|| e
->ts
.type
!= BT_CHARACTER
)
1358 gfc_error("IOMSG must be a scalar-default-char-variable at %L", &e
->where
);
1366 is_char_type (const char *name
, gfc_expr
*e
)
1368 gfc_resolve_expr (e
);
1370 if (e
->ts
.type
!= BT_CHARACTER
)
1372 gfc_error ("%s requires a scalar-default-char-expr at %L",
1380 /* Match an expression I/O tag of some sort. */
1383 match_etag (const io_tag
*tag
, gfc_expr
**v
)
1388 m
= gfc_match (tag
->spec
);
1392 m
= gfc_match (tag
->value
, &result
);
1395 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1401 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1402 gfc_free_expr (result
);
1411 /* Match a variable I/O tag of some sort. */
1414 match_vtag (const io_tag
*tag
, gfc_expr
**v
)
1419 m
= gfc_match (tag
->spec
);
1423 m
= gfc_match (tag
->value
, &result
);
1426 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1432 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1433 gfc_free_expr (result
);
1437 if (result
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
1439 gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag
->name
);
1440 gfc_free_expr (result
);
1444 bool impure
= gfc_impure_variable (result
->symtree
->n
.sym
);
1445 if (impure
&& gfc_pure (NULL
))
1447 gfc_error ("Variable %s cannot be assigned in PURE procedure at %C",
1449 gfc_free_expr (result
);
1454 gfc_unset_implicit_pure (NULL
);
1461 /* Match I/O tags that cause variables to become redefined. */
1464 match_out_tag (const io_tag
*tag
, gfc_expr
**result
)
1468 m
= match_vtag (tag
, result
);
1470 gfc_check_do_variable ((*result
)->symtree
);
1476 /* Match a label I/O tag. */
1479 match_ltag (const io_tag
*tag
, gfc_st_label
** label
)
1485 m
= gfc_match (tag
->spec
);
1489 m
= gfc_match (tag
->value
, label
);
1492 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1498 gfc_error ("Duplicate %s label specification at %C", tag
->name
);
1502 if (!gfc_reference_st_label (*label
, ST_LABEL_TARGET
))
1509 /* Match a tag using match_etag, but only if -fdec is enabled. */
1511 match_dec_etag (const io_tag
*tag
, gfc_expr
**e
)
1513 match m
= match_etag (tag
, e
);
1514 if (flag_dec
&& m
!= MATCH_NO
)
1516 else if (m
!= MATCH_NO
)
1518 gfc_error ("%s at %C is a DEC extension, enable with "
1519 "%<-fdec%>", tag
->name
);
1526 /* Match a tag using match_vtag, but only if -fdec is enabled. */
1528 match_dec_vtag (const io_tag
*tag
, gfc_expr
**e
)
1530 match m
= match_vtag(tag
, e
);
1531 if (flag_dec
&& m
!= MATCH_NO
)
1533 else if (m
!= MATCH_NO
)
1535 gfc_error ("%s at %C is a DEC extension, enable with "
1536 "%<-fdec%>", tag
->name
);
1543 /* Match a DEC I/O flag tag - a tag with no expression such as READONLY. */
1546 match_dec_ftag (const io_tag
*tag
, gfc_open
*o
)
1550 m
= gfc_match (tag
->spec
);
1556 gfc_error ("%s at %C is a DEC extension, enable with "
1557 "%<-fdec%>", tag
->name
);
1561 /* Just set the READONLY flag, which we use at runtime to avoid delete on
1563 if (tag
== &tag_readonly
)
1569 /* Interpret SHARED as SHARE='DENYNONE' (read lock). */
1570 else if (tag
== &tag_shared
)
1572 if (o
->share
!= NULL
)
1574 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1577 o
->share
= gfc_get_character_expr (gfc_default_character_kind
,
1578 &gfc_current_locus
, "denynone", 8);
1582 /* Interpret NOSHARED as SHARE='DENYRW' (exclusive lock). */
1583 else if (tag
== &tag_noshared
)
1585 if (o
->share
!= NULL
)
1587 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1590 o
->share
= gfc_get_character_expr (gfc_default_character_kind
,
1591 &gfc_current_locus
, "denyrw", 6);
1595 /* We handle all DEC tags above. */
1600 /* Resolution of the FORMAT tag, to be called from resolve_tag. */
1603 resolve_tag_format (const gfc_expr
*e
)
1605 if (e
->expr_type
== EXPR_CONSTANT
1606 && (e
->ts
.type
!= BT_CHARACTER
1607 || e
->ts
.kind
!= gfc_default_character_kind
))
1609 gfc_error ("Constant expression in FORMAT tag at %L must be "
1610 "of type default CHARACTER", &e
->where
);
1614 /* If e's rank is zero and e is not an element of an array, it should be
1615 of integer or character type. The integer variable should be
1618 && (e
->expr_type
!= EXPR_VARIABLE
1619 || e
->symtree
== NULL
1620 || e
->symtree
->n
.sym
->as
== NULL
1621 || e
->symtree
->n
.sym
->as
->rank
== 0))
1623 if ((e
->ts
.type
!= BT_CHARACTER
1624 || e
->ts
.kind
!= gfc_default_character_kind
)
1625 && e
->ts
.type
!= BT_INTEGER
)
1627 gfc_error ("FORMAT tag at %L must be of type default-kind CHARACTER "
1628 "or of INTEGER", &e
->where
);
1631 else if (e
->ts
.type
== BT_INTEGER
&& e
->expr_type
== EXPR_VARIABLE
)
1633 if (!gfc_notify_std (GFC_STD_F95_DEL
, "ASSIGNED variable in "
1634 "FORMAT tag at %L", &e
->where
))
1636 if (e
->symtree
->n
.sym
->attr
.assign
!= 1)
1638 gfc_error ("Variable %qs at %L has not been assigned a "
1639 "format label", e
->symtree
->n
.sym
->name
, &e
->where
);
1643 else if (e
->ts
.type
== BT_INTEGER
)
1645 gfc_error ("Scalar %qs in FORMAT tag at %L is not an ASSIGNED "
1646 "variable", gfc_basic_typename (e
->ts
.type
), &e
->where
);
1653 /* If rank is nonzero and type is not character, we allow it under GFC_STD_LEGACY.
1654 It may be assigned an Hollerith constant. */
1655 if (e
->ts
.type
!= BT_CHARACTER
)
1657 if (!gfc_notify_std (GFC_STD_LEGACY
, "Non-character in FORMAT tag "
1658 "at %L", &e
->where
))
1661 if (e
->rank
== 0 && e
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SHAPE
)
1663 gfc_error ("Non-character assumed shape array element in FORMAT"
1664 " tag at %L", &e
->where
);
1668 if (e
->rank
== 0 && e
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
)
1670 gfc_error ("Non-character assumed size array element in FORMAT"
1671 " tag at %L", &e
->where
);
1675 if (e
->rank
== 0 && e
->symtree
->n
.sym
->attr
.pointer
)
1677 gfc_error ("Non-character pointer array element in FORMAT tag at %L",
1687 /* Do expression resolution and type-checking on an expression tag. */
1690 resolve_tag (const io_tag
*tag
, gfc_expr
*e
)
1695 if (!gfc_resolve_expr (e
))
1698 if (tag
== &tag_format
)
1699 return resolve_tag_format (e
);
1701 if (e
->ts
.type
!= tag
->type
)
1703 gfc_error ("%s tag at %L must be of type %s", tag
->name
,
1704 &e
->where
, gfc_basic_typename (tag
->type
));
1708 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= gfc_default_character_kind
)
1710 gfc_error ("%s tag at %L must be a character string of default kind",
1711 tag
->name
, &e
->where
);
1717 gfc_error ("%s tag at %L must be scalar", tag
->name
, &e
->where
);
1721 if (tag
== &tag_iomsg
)
1723 if (!gfc_notify_std (GFC_STD_F2003
, "IOMSG tag at %L", &e
->where
))
1727 if ((tag
== &tag_iostat
|| tag
== &tag_size
|| tag
== &tag_iolength
1728 || tag
== &tag_number
|| tag
== &tag_nextrec
|| tag
== &tag_s_recl
)
1729 && e
->ts
.kind
!= gfc_default_integer_kind
)
1731 if (!gfc_notify_std (GFC_STD_F2003
, "Fortran 95 requires default "
1732 "INTEGER in %s tag at %L", tag
->name
, &e
->where
))
1736 if (e
->ts
.kind
!= gfc_default_logical_kind
&&
1737 (tag
== &tag_exist
|| tag
== &tag_named
|| tag
== &tag_opened
1738 || tag
== &tag_pending
))
1740 if (!gfc_notify_std (GFC_STD_F2008
, "Non-default LOGICAL kind "
1741 "in %s tag at %L", tag
->name
, &e
->where
))
1745 if (tag
== &tag_newunit
)
1747 if (!gfc_notify_std (GFC_STD_F2008
, "NEWUNIT specifier at %L",
1752 /* NEWUNIT, IOSTAT, SIZE and IOMSG are variable definition contexts. */
1753 if (tag
== &tag_newunit
|| tag
== &tag_iostat
1754 || tag
== &tag_size
|| tag
== &tag_iomsg
)
1758 sprintf (context
, _("%s tag"), tag
->name
);
1759 if (!gfc_check_vardef_context (e
, false, false, false, context
))
1763 if (tag
== &tag_convert
)
1765 if (!gfc_notify_std (GFC_STD_GNU
, "CONVERT tag at %L", &e
->where
))
1773 /* Match a single tag of an OPEN statement. */
1776 match_open_element (gfc_open
*open
)
1780 m
= match_etag (&tag_e_async
, &open
->asynchronous
);
1781 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", open
->asynchronous
))
1785 m
= match_etag (&tag_unit
, &open
->unit
);
1788 m
= match_etag (&tag_iomsg
, &open
->iomsg
);
1789 if (m
== MATCH_YES
&& !check_char_variable (open
->iomsg
))
1793 m
= match_out_tag (&tag_iostat
, &open
->iostat
);
1796 m
= match_etag (&tag_file
, &open
->file
);
1799 m
= match_etag (&tag_status
, &open
->status
);
1802 m
= match_etag (&tag_e_access
, &open
->access
);
1805 m
= match_etag (&tag_e_form
, &open
->form
);
1808 m
= match_etag (&tag_e_recl
, &open
->recl
);
1811 m
= match_etag (&tag_e_blank
, &open
->blank
);
1814 m
= match_etag (&tag_e_position
, &open
->position
);
1817 m
= match_etag (&tag_e_action
, &open
->action
);
1820 m
= match_etag (&tag_e_delim
, &open
->delim
);
1823 m
= match_etag (&tag_e_pad
, &open
->pad
);
1826 m
= match_etag (&tag_e_decimal
, &open
->decimal
);
1829 m
= match_etag (&tag_e_encoding
, &open
->encoding
);
1832 m
= match_etag (&tag_e_round
, &open
->round
);
1835 m
= match_etag (&tag_e_sign
, &open
->sign
);
1838 m
= match_ltag (&tag_err
, &open
->err
);
1841 m
= match_etag (&tag_convert
, &open
->convert
);
1844 m
= match_out_tag (&tag_newunit
, &open
->newunit
);
1848 /* The following are extensions enabled with -fdec. */
1849 m
= match_dec_etag (&tag_e_share
, &open
->share
);
1852 m
= match_dec_etag (&tag_cc
, &open
->cc
);
1855 m
= match_dec_ftag (&tag_readonly
, open
);
1858 m
= match_dec_ftag (&tag_shared
, open
);
1861 m
= match_dec_ftag (&tag_noshared
, open
);
1869 /* Free the gfc_open structure and all the expressions it contains. */
1872 gfc_free_open (gfc_open
*open
)
1877 gfc_free_expr (open
->unit
);
1878 gfc_free_expr (open
->iomsg
);
1879 gfc_free_expr (open
->iostat
);
1880 gfc_free_expr (open
->file
);
1881 gfc_free_expr (open
->status
);
1882 gfc_free_expr (open
->access
);
1883 gfc_free_expr (open
->form
);
1884 gfc_free_expr (open
->recl
);
1885 gfc_free_expr (open
->blank
);
1886 gfc_free_expr (open
->position
);
1887 gfc_free_expr (open
->action
);
1888 gfc_free_expr (open
->delim
);
1889 gfc_free_expr (open
->pad
);
1890 gfc_free_expr (open
->decimal
);
1891 gfc_free_expr (open
->encoding
);
1892 gfc_free_expr (open
->round
);
1893 gfc_free_expr (open
->sign
);
1894 gfc_free_expr (open
->convert
);
1895 gfc_free_expr (open
->asynchronous
);
1896 gfc_free_expr (open
->newunit
);
1897 gfc_free_expr (open
->share
);
1898 gfc_free_expr (open
->cc
);
1903 /* Resolve everything in a gfc_open structure. */
1906 gfc_resolve_open (gfc_open
*open
)
1909 RESOLVE_TAG (&tag_unit
, open
->unit
);
1910 RESOLVE_TAG (&tag_iomsg
, open
->iomsg
);
1911 RESOLVE_TAG (&tag_iostat
, open
->iostat
);
1912 RESOLVE_TAG (&tag_file
, open
->file
);
1913 RESOLVE_TAG (&tag_status
, open
->status
);
1914 RESOLVE_TAG (&tag_e_access
, open
->access
);
1915 RESOLVE_TAG (&tag_e_form
, open
->form
);
1916 RESOLVE_TAG (&tag_e_recl
, open
->recl
);
1917 RESOLVE_TAG (&tag_e_blank
, open
->blank
);
1918 RESOLVE_TAG (&tag_e_position
, open
->position
);
1919 RESOLVE_TAG (&tag_e_action
, open
->action
);
1920 RESOLVE_TAG (&tag_e_delim
, open
->delim
);
1921 RESOLVE_TAG (&tag_e_pad
, open
->pad
);
1922 RESOLVE_TAG (&tag_e_decimal
, open
->decimal
);
1923 RESOLVE_TAG (&tag_e_encoding
, open
->encoding
);
1924 RESOLVE_TAG (&tag_e_async
, open
->asynchronous
);
1925 RESOLVE_TAG (&tag_e_round
, open
->round
);
1926 RESOLVE_TAG (&tag_e_sign
, open
->sign
);
1927 RESOLVE_TAG (&tag_convert
, open
->convert
);
1928 RESOLVE_TAG (&tag_newunit
, open
->newunit
);
1929 RESOLVE_TAG (&tag_e_share
, open
->share
);
1930 RESOLVE_TAG (&tag_cc
, open
->cc
);
1932 if (!gfc_reference_st_label (open
->err
, ST_LABEL_TARGET
))
1939 /* Check if a given value for a SPECIFIER is either in the list of values
1940 allowed in F95 or F2003, issuing an error message and returning a zero
1941 value if it is not allowed. */
1944 compare_to_allowed_values (const char *specifier
, const char *allowed
[],
1945 const char *allowed_f2003
[],
1946 const char *allowed_gnu
[], gfc_char_t
*value
,
1947 const char *statement
, bool warn
)
1952 len
= gfc_wide_strlen (value
);
1955 for (len
--; len
> 0; len
--)
1956 if (value
[len
] != ' ')
1961 for (i
= 0; allowed
[i
]; i
++)
1962 if (len
== strlen (allowed
[i
])
1963 && gfc_wide_strncasecmp (value
, allowed
[i
], strlen (allowed
[i
])) == 0)
1966 for (i
= 0; allowed_f2003
&& allowed_f2003
[i
]; i
++)
1967 if (len
== strlen (allowed_f2003
[i
])
1968 && gfc_wide_strncasecmp (value
, allowed_f2003
[i
],
1969 strlen (allowed_f2003
[i
])) == 0)
1971 notification n
= gfc_notification_std (GFC_STD_F2003
);
1973 if (n
== WARNING
|| (warn
&& n
== ERROR
))
1975 gfc_warning (0, "Fortran 2003: %s specifier in %s statement at %C "
1976 "has value %qs", specifier
, statement
,
1983 gfc_notify_std (GFC_STD_F2003
, "%s specifier in "
1984 "%s statement at %C has value %qs", specifier
,
1985 statement
, allowed_f2003
[i
]);
1993 for (i
= 0; allowed_gnu
&& allowed_gnu
[i
]; i
++)
1994 if (len
== strlen (allowed_gnu
[i
])
1995 && gfc_wide_strncasecmp (value
, allowed_gnu
[i
],
1996 strlen (allowed_gnu
[i
])) == 0)
1998 notification n
= gfc_notification_std (GFC_STD_GNU
);
2000 if (n
== WARNING
|| (warn
&& n
== ERROR
))
2002 gfc_warning (0, "Extension: %s specifier in %s statement at %C "
2003 "has value %qs", specifier
, statement
,
2010 gfc_notify_std (GFC_STD_GNU
, "%s specifier in "
2011 "%s statement at %C has value %qs", specifier
,
2012 statement
, allowed_gnu
[i
]);
2022 char *s
= gfc_widechar_to_char (value
, -1);
2024 "%s specifier in %s statement at %C has invalid value %qs",
2025 specifier
, statement
, s
);
2031 char *s
= gfc_widechar_to_char (value
, -1);
2032 gfc_error ("%s specifier in %s statement at %C has invalid value %qs",
2033 specifier
, statement
, s
);
2040 /* Match an OPEN statement. */
2043 gfc_match_open (void)
2049 m
= gfc_match_char ('(');
2053 open
= XCNEW (gfc_open
);
2055 m
= match_open_element (open
);
2057 if (m
== MATCH_ERROR
)
2061 m
= gfc_match_expr (&open
->unit
);
2062 if (m
== MATCH_ERROR
)
2068 if (gfc_match_char (')') == MATCH_YES
)
2070 if (gfc_match_char (',') != MATCH_YES
)
2073 m
= match_open_element (open
);
2074 if (m
== MATCH_ERROR
)
2080 if (gfc_match_eos () == MATCH_NO
)
2083 if (gfc_pure (NULL
))
2085 gfc_error ("OPEN statement not allowed in PURE procedure at %C");
2089 gfc_unset_implicit_pure (NULL
);
2091 warn
= (open
->err
|| open
->iostat
) ? true : false;
2093 /* Checks on NEWUNIT specifier. */
2098 gfc_error ("UNIT specifier not allowed with NEWUNIT at %C");
2102 if (!open
->file
&& open
->status
)
2104 if (open
->status
->expr_type
== EXPR_CONSTANT
2105 && gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2108 gfc_error ("NEWUNIT specifier must have FILE= "
2109 "or STATUS='scratch' at %C");
2114 else if (!open
->unit
)
2116 gfc_error ("OPEN statement at %C must have UNIT or NEWUNIT specified");
2120 /* Checks on the ACCESS specifier. */
2121 if (open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
)
2123 static const char *access_f95
[] = { "SEQUENTIAL", "DIRECT", NULL
};
2124 static const char *access_f2003
[] = { "STREAM", NULL
};
2125 static const char *access_gnu
[] = { "APPEND", NULL
};
2127 if (!is_char_type ("ACCESS", open
->access
))
2130 if (!compare_to_allowed_values ("ACCESS", access_f95
, access_f2003
,
2132 open
->access
->value
.character
.string
,
2137 /* Checks on the ACTION specifier. */
2138 if (open
->action
&& open
->action
->expr_type
== EXPR_CONSTANT
)
2140 gfc_char_t
*str
= open
->action
->value
.character
.string
;
2141 static const char *action
[] = { "READ", "WRITE", "READWRITE", NULL
};
2143 if (!is_char_type ("ACTION", open
->action
))
2146 if (!compare_to_allowed_values ("ACTION", action
, NULL
, NULL
,
2150 /* With READONLY, only allow ACTION='READ'. */
2151 if (open
->readonly
&& (gfc_wide_strlen (str
) != 4
2152 || gfc_wide_strncasecmp (str
, "READ", 4) != 0))
2154 gfc_error ("ACTION type conflicts with READONLY specifier at %C");
2158 /* If we see READONLY and no ACTION, set ACTION='READ'. */
2159 else if (open
->readonly
&& open
->action
== NULL
)
2161 open
->action
= gfc_get_character_expr (gfc_default_character_kind
,
2162 &gfc_current_locus
, "read", 4);
2165 /* Checks on the ASYNCHRONOUS specifier. */
2166 if (open
->asynchronous
)
2168 if (!gfc_notify_std (GFC_STD_F2003
, "ASYNCHRONOUS= at %C "
2169 "not allowed in Fortran 95"))
2172 if (!is_char_type ("ASYNCHRONOUS", open
->asynchronous
))
2175 if (open
->asynchronous
->expr_type
== EXPR_CONSTANT
)
2177 static const char * asynchronous
[] = { "YES", "NO", NULL
};
2179 if (!compare_to_allowed_values ("ASYNCHRONOUS", asynchronous
,
2180 NULL
, NULL
, open
->asynchronous
->value
.character
.string
,
2186 /* Checks on the BLANK specifier. */
2189 if (!gfc_notify_std (GFC_STD_F2003
, "BLANK= at %C "
2190 "not allowed in Fortran 95"))
2193 if (!is_char_type ("BLANK", open
->blank
))
2196 if (open
->blank
->expr_type
== EXPR_CONSTANT
)
2198 static const char *blank
[] = { "ZERO", "NULL", NULL
};
2200 if (!compare_to_allowed_values ("BLANK", blank
, NULL
, NULL
,
2201 open
->blank
->value
.character
.string
,
2207 /* Checks on the CARRIAGECONTROL specifier. */
2210 if (!is_char_type ("CARRIAGECONTROL", open
->cc
))
2213 if (open
->cc
->expr_type
== EXPR_CONSTANT
)
2215 static const char *cc
[] = { "LIST", "FORTRAN", "NONE", NULL
};
2216 if (!compare_to_allowed_values ("CARRIAGECONTROL", cc
, NULL
, NULL
,
2217 open
->cc
->value
.character
.string
,
2223 /* Checks on the DECIMAL specifier. */
2226 if (!gfc_notify_std (GFC_STD_F2003
, "DECIMAL= at %C "
2227 "not allowed in Fortran 95"))
2230 if (!is_char_type ("DECIMAL", open
->decimal
))
2233 if (open
->decimal
->expr_type
== EXPR_CONSTANT
)
2235 static const char * decimal
[] = { "COMMA", "POINT", NULL
};
2237 if (!compare_to_allowed_values ("DECIMAL", decimal
, NULL
, NULL
,
2238 open
->decimal
->value
.character
.string
,
2244 /* Checks on the DELIM specifier. */
2247 if (open
->delim
->expr_type
== EXPR_CONSTANT
)
2249 static const char *delim
[] = { "APOSTROPHE", "QUOTE", "NONE", NULL
};
2251 if (!is_char_type ("DELIM", open
->delim
))
2254 if (!compare_to_allowed_values ("DELIM", delim
, NULL
, NULL
,
2255 open
->delim
->value
.character
.string
,
2261 /* Checks on the ENCODING specifier. */
2264 if (!gfc_notify_std (GFC_STD_F2003
, "ENCODING= at %C "
2265 "not allowed in Fortran 95"))
2268 if (!is_char_type ("ENCODING", open
->encoding
))
2271 if (open
->encoding
->expr_type
== EXPR_CONSTANT
)
2273 static const char * encoding
[] = { "DEFAULT", "UTF-8", NULL
};
2275 if (!compare_to_allowed_values ("ENCODING", encoding
, NULL
, NULL
,
2276 open
->encoding
->value
.character
.string
,
2282 /* Checks on the FORM specifier. */
2283 if (open
->form
&& open
->form
->expr_type
== EXPR_CONSTANT
)
2285 static const char *form
[] = { "FORMATTED", "UNFORMATTED", NULL
};
2287 if (!is_char_type ("FORM", open
->form
))
2290 if (!compare_to_allowed_values ("FORM", form
, NULL
, NULL
,
2291 open
->form
->value
.character
.string
,
2296 /* Checks on the PAD specifier. */
2297 if (open
->pad
&& open
->pad
->expr_type
== EXPR_CONSTANT
)
2299 static const char *pad
[] = { "YES", "NO", NULL
};
2301 if (!is_char_type ("PAD", open
->pad
))
2304 if (!compare_to_allowed_values ("PAD", pad
, NULL
, NULL
,
2305 open
->pad
->value
.character
.string
,
2310 /* Checks on the POSITION specifier. */
2311 if (open
->position
&& open
->position
->expr_type
== EXPR_CONSTANT
)
2313 static const char *position
[] = { "ASIS", "REWIND", "APPEND", NULL
};
2315 if (!is_char_type ("POSITION", open
->position
))
2318 if (!compare_to_allowed_values ("POSITION", position
, NULL
, NULL
,
2319 open
->position
->value
.character
.string
,
2324 /* Checks on the ROUND specifier. */
2327 if (!gfc_notify_std (GFC_STD_F2003
, "ROUND= at %C "
2328 "not allowed in Fortran 95"))
2331 if (!is_char_type ("ROUND", open
->round
))
2334 if (open
->round
->expr_type
== EXPR_CONSTANT
)
2336 static const char * round
[] = { "UP", "DOWN", "ZERO", "NEAREST",
2337 "COMPATIBLE", "PROCESSOR_DEFINED",
2340 if (!compare_to_allowed_values ("ROUND", round
, NULL
, NULL
,
2341 open
->round
->value
.character
.string
,
2347 /* Checks on the SHARE specifier. */
2350 if (!is_char_type ("SHARE", open
->share
))
2353 if (open
->share
->expr_type
== EXPR_CONSTANT
)
2355 static const char *share
[] = { "DENYNONE", "DENYRW", NULL
};
2356 if (!compare_to_allowed_values ("SHARE", share
, NULL
, NULL
,
2357 open
->share
->value
.character
.string
,
2363 /* Checks on the SIGN specifier. */
2366 if (!gfc_notify_std (GFC_STD_F2003
, "SIGN= at %C "
2367 "not allowed in Fortran 95"))
2370 if (!is_char_type ("SIGN", open
->sign
))
2373 if (open
->sign
->expr_type
== EXPR_CONSTANT
)
2375 static const char * sign
[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
2378 if (!compare_to_allowed_values ("SIGN", sign
, NULL
, NULL
,
2379 open
->sign
->value
.character
.string
,
2385 #define warn_or_error(...) \
2388 gfc_warning (0, __VA_ARGS__); \
2391 gfc_error (__VA_ARGS__); \
2396 /* Checks on the RECL specifier. */
2397 if (open
->recl
&& open
->recl
->expr_type
== EXPR_CONSTANT
2398 && open
->recl
->ts
.type
== BT_INTEGER
2399 && mpz_sgn (open
->recl
->value
.integer
) != 1)
2401 warn_or_error ("RECL in OPEN statement at %C must be positive");
2404 /* Checks on the STATUS specifier. */
2405 if (open
->status
&& open
->status
->expr_type
== EXPR_CONSTANT
)
2407 static const char *status
[] = { "OLD", "NEW", "SCRATCH",
2408 "REPLACE", "UNKNOWN", NULL
};
2410 if (!is_char_type ("STATUS", open
->status
))
2413 if (!compare_to_allowed_values ("STATUS", status
, NULL
, NULL
,
2414 open
->status
->value
.character
.string
,
2418 /* F2003, 9.4.5: If the STATUS= specifier has the value NEW or REPLACE,
2419 the FILE= specifier shall appear. */
2420 if (open
->file
== NULL
2421 && (gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2423 || gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2426 char *s
= gfc_widechar_to_char (open
->status
->value
.character
.string
,
2428 warn_or_error ("The STATUS specified in OPEN statement at %C is "
2429 "%qs and no FILE specifier is present", s
);
2433 /* F2003, 9.4.5: If the STATUS= specifier has the value SCRATCH,
2434 the FILE= specifier shall not appear. */
2435 if (gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2436 "scratch", 7) == 0 && open
->file
)
2438 warn_or_error ("The STATUS specified in OPEN statement at %C "
2439 "cannot have the value SCRATCH if a FILE specifier "
2444 /* Things that are not allowed for unformatted I/O. */
2445 if (open
->form
&& open
->form
->expr_type
== EXPR_CONSTANT
2446 && (open
->delim
|| open
->decimal
|| open
->encoding
|| open
->round
2447 || open
->sign
|| open
->pad
|| open
->blank
)
2448 && gfc_wide_strncasecmp (open
->form
->value
.character
.string
,
2449 "unformatted", 11) == 0)
2451 const char *spec
= (open
->delim
? "DELIM "
2452 : (open
->pad
? "PAD " : open
->blank
2455 warn_or_error ("%s specifier at %C not allowed in OPEN statement for "
2456 "unformatted I/O", spec
);
2459 if (open
->recl
&& open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
2460 && gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2463 warn_or_error ("RECL specifier not allowed in OPEN statement at %C for "
2468 && open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
2469 && !(gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2470 "sequential", 10) == 0
2471 || gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2473 || gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2476 warn_or_error ("POSITION specifier in OPEN statement at %C only allowed "
2477 "for stream or sequential ACCESS");
2480 #undef warn_or_error
2482 new_st
.op
= EXEC_OPEN
;
2483 new_st
.ext
.open
= open
;
2487 gfc_syntax_error (ST_OPEN
);
2490 gfc_free_open (open
);
2495 /* Free a gfc_close structure an all its expressions. */
2498 gfc_free_close (gfc_close
*close
)
2503 gfc_free_expr (close
->unit
);
2504 gfc_free_expr (close
->iomsg
);
2505 gfc_free_expr (close
->iostat
);
2506 gfc_free_expr (close
->status
);
2511 /* Match elements of a CLOSE statement. */
2514 match_close_element (gfc_close
*close
)
2518 m
= match_etag (&tag_unit
, &close
->unit
);
2521 m
= match_etag (&tag_status
, &close
->status
);
2524 m
= match_etag (&tag_iomsg
, &close
->iomsg
);
2525 if (m
== MATCH_YES
&& !check_char_variable (close
->iomsg
))
2529 m
= match_out_tag (&tag_iostat
, &close
->iostat
);
2532 m
= match_ltag (&tag_err
, &close
->err
);
2540 /* Match a CLOSE statement. */
2543 gfc_match_close (void)
2549 m
= gfc_match_char ('(');
2553 close
= XCNEW (gfc_close
);
2555 m
= match_close_element (close
);
2557 if (m
== MATCH_ERROR
)
2561 m
= gfc_match_expr (&close
->unit
);
2564 if (m
== MATCH_ERROR
)
2570 if (gfc_match_char (')') == MATCH_YES
)
2572 if (gfc_match_char (',') != MATCH_YES
)
2575 m
= match_close_element (close
);
2576 if (m
== MATCH_ERROR
)
2582 if (gfc_match_eos () == MATCH_NO
)
2585 if (gfc_pure (NULL
))
2587 gfc_error ("CLOSE statement not allowed in PURE procedure at %C");
2591 gfc_unset_implicit_pure (NULL
);
2593 warn
= (close
->iostat
|| close
->err
) ? true : false;
2595 /* Checks on the STATUS specifier. */
2596 if (close
->status
&& close
->status
->expr_type
== EXPR_CONSTANT
)
2598 static const char *status
[] = { "KEEP", "DELETE", NULL
};
2600 if (!is_char_type ("STATUS", close
->status
))
2603 if (!compare_to_allowed_values ("STATUS", status
, NULL
, NULL
,
2604 close
->status
->value
.character
.string
,
2609 new_st
.op
= EXEC_CLOSE
;
2610 new_st
.ext
.close
= close
;
2614 gfc_syntax_error (ST_CLOSE
);
2617 gfc_free_close (close
);
2622 /* Resolve everything in a gfc_close structure. */
2625 gfc_resolve_close (gfc_close
*close
)
2627 RESOLVE_TAG (&tag_unit
, close
->unit
);
2628 RESOLVE_TAG (&tag_iomsg
, close
->iomsg
);
2629 RESOLVE_TAG (&tag_iostat
, close
->iostat
);
2630 RESOLVE_TAG (&tag_status
, close
->status
);
2632 if (!gfc_reference_st_label (close
->err
, ST_LABEL_TARGET
))
2635 if (close
->unit
== NULL
)
2637 /* Find a locus from one of the arguments to close, when UNIT is
2639 locus loc
= gfc_current_locus
;
2641 loc
= close
->status
->where
;
2642 else if (close
->iostat
)
2643 loc
= close
->iostat
->where
;
2644 else if (close
->iomsg
)
2645 loc
= close
->iomsg
->where
;
2646 else if (close
->err
)
2647 loc
= close
->err
->where
;
2649 gfc_error ("CLOSE statement at %L requires a UNIT number", &loc
);
2653 if (close
->unit
->expr_type
== EXPR_CONSTANT
2654 && close
->unit
->ts
.type
== BT_INTEGER
2655 && mpz_sgn (close
->unit
->value
.integer
) < 0)
2657 gfc_error ("UNIT number in CLOSE statement at %L must be non-negative",
2658 &close
->unit
->where
);
2665 /* Free a gfc_filepos structure. */
2668 gfc_free_filepos (gfc_filepos
*fp
)
2670 gfc_free_expr (fp
->unit
);
2671 gfc_free_expr (fp
->iomsg
);
2672 gfc_free_expr (fp
->iostat
);
2677 /* Match elements of a REWIND, BACKSPACE, ENDFILE, or FLUSH statement. */
2680 match_file_element (gfc_filepos
*fp
)
2684 m
= match_etag (&tag_unit
, &fp
->unit
);
2687 m
= match_etag (&tag_iomsg
, &fp
->iomsg
);
2688 if (m
== MATCH_YES
&& !check_char_variable (fp
->iomsg
))
2692 m
= match_out_tag (&tag_iostat
, &fp
->iostat
);
2695 m
= match_ltag (&tag_err
, &fp
->err
);
2703 /* Match the second half of the file-positioning statements, REWIND,
2704 BACKSPACE, ENDFILE, or the FLUSH statement. */
2707 match_filepos (gfc_statement st
, gfc_exec_op op
)
2712 fp
= XCNEW (gfc_filepos
);
2714 if (gfc_match_char ('(') == MATCH_NO
)
2716 m
= gfc_match_expr (&fp
->unit
);
2717 if (m
== MATCH_ERROR
)
2725 m
= match_file_element (fp
);
2726 if (m
== MATCH_ERROR
)
2730 m
= gfc_match_expr (&fp
->unit
);
2731 if (m
== MATCH_ERROR
|| m
== MATCH_NO
)
2737 if (gfc_match_char (')') == MATCH_YES
)
2739 if (gfc_match_char (',') != MATCH_YES
)
2742 m
= match_file_element (fp
);
2743 if (m
== MATCH_ERROR
)
2750 if (gfc_match_eos () != MATCH_YES
)
2753 if (gfc_pure (NULL
))
2755 gfc_error ("%s statement not allowed in PURE procedure at %C",
2756 gfc_ascii_statement (st
));
2761 gfc_unset_implicit_pure (NULL
);
2764 new_st
.ext
.filepos
= fp
;
2768 gfc_syntax_error (st
);
2771 gfc_free_filepos (fp
);
2777 gfc_resolve_filepos (gfc_filepos
*fp
)
2779 RESOLVE_TAG (&tag_unit
, fp
->unit
);
2780 RESOLVE_TAG (&tag_iostat
, fp
->iostat
);
2781 RESOLVE_TAG (&tag_iomsg
, fp
->iomsg
);
2782 if (!gfc_reference_st_label (fp
->err
, ST_LABEL_TARGET
))
2785 if (!fp
->unit
&& (fp
->iostat
|| fp
->iomsg
))
2788 where
= fp
->iostat
? fp
->iostat
->where
: fp
->iomsg
->where
;
2789 gfc_error ("UNIT number missing in statement at %L", &where
);
2793 if (fp
->unit
->expr_type
== EXPR_CONSTANT
2794 && fp
->unit
->ts
.type
== BT_INTEGER
2795 && mpz_sgn (fp
->unit
->value
.integer
) < 0)
2797 gfc_error ("UNIT number in statement at %L must be non-negative",
2806 /* Match the file positioning statements: ENDFILE, BACKSPACE, REWIND,
2807 and the FLUSH statement. */
2810 gfc_match_endfile (void)
2812 return match_filepos (ST_END_FILE
, EXEC_ENDFILE
);
2816 gfc_match_backspace (void)
2818 return match_filepos (ST_BACKSPACE
, EXEC_BACKSPACE
);
2822 gfc_match_rewind (void)
2824 return match_filepos (ST_REWIND
, EXEC_REWIND
);
2828 gfc_match_flush (void)
2830 if (!gfc_notify_std (GFC_STD_F2003
, "FLUSH statement at %C"))
2833 return match_filepos (ST_FLUSH
, EXEC_FLUSH
);
2836 /******************** Data Transfer Statements *********************/
2838 /* Return a default unit number. */
2841 default_unit (io_kind k
)
2850 return gfc_get_int_expr (gfc_default_integer_kind
, NULL
, unit
);
2854 /* Match a unit specification for a data transfer statement. */
2857 match_dt_unit (io_kind k
, gfc_dt
*dt
)
2862 if (gfc_match_char ('*') == MATCH_YES
)
2864 if (dt
->io_unit
!= NULL
)
2867 dt
->io_unit
= default_unit (k
);
2869 c
= gfc_peek_ascii_char ();
2871 gfc_error_now ("Missing format with default unit at %C");
2876 if (gfc_match_expr (&e
) == MATCH_YES
)
2878 if (dt
->io_unit
!= NULL
)
2891 gfc_error ("Duplicate UNIT specification at %C");
2896 /* Match a format specification. */
2899 match_dt_format (gfc_dt
*dt
)
2903 gfc_st_label
*label
;
2906 where
= gfc_current_locus
;
2908 if (gfc_match_char ('*') == MATCH_YES
)
2910 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2913 dt
->format_label
= &format_asterisk
;
2917 if ((m
= gfc_match_st_label (&label
)) == MATCH_YES
)
2921 /* Need to check if the format label is actually either an operand
2922 to a user-defined operator or is a kind type parameter. That is,
2923 print 2.ip.8 ! .ip. is a user-defined operator return CHARACTER.
2924 print 1_'(I0)', i ! 1_'(I0)' is a default character string. */
2926 gfc_gobble_whitespace ();
2927 c
= gfc_peek_ascii_char ();
2928 if (c
== '.' || c
== '_')
2929 gfc_current_locus
= where
;
2932 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2934 gfc_free_st_label (label
);
2938 if (!gfc_reference_st_label (label
, ST_LABEL_FORMAT
))
2941 dt
->format_label
= label
;
2945 else if (m
== MATCH_ERROR
)
2946 /* The label was zero or too large. Emit the correct diagnosis. */
2949 if (gfc_match_expr (&e
) == MATCH_YES
)
2951 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2956 dt
->format_expr
= e
;
2960 gfc_current_locus
= where
; /* The only case where we have to restore */
2965 gfc_error ("Duplicate format specification at %C");
2969 /* Check for formatted read and write DTIO procedures. */
2972 dtio_procs_present (gfc_symbol
*sym
, io_kind k
)
2974 gfc_symbol
*derived
;
2976 if (sym
&& sym
->ts
.u
.derived
)
2978 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
2979 derived
= CLASS_DATA (sym
)->ts
.u
.derived
;
2980 else if (sym
->ts
.type
== BT_DERIVED
)
2981 derived
= sym
->ts
.u
.derived
;
2984 if ((k
== M_WRITE
|| k
== M_PRINT
) &&
2985 (gfc_find_specific_dtio_proc (derived
, true, true) != NULL
))
2987 if ((k
== M_READ
) &&
2988 (gfc_find_specific_dtio_proc (derived
, false, true) != NULL
))
2994 /* Traverse a namelist that is part of a READ statement to make sure
2995 that none of the variables in the namelist are INTENT(IN). Returns
2996 nonzero if we find such a variable. */
2999 check_namelist (gfc_symbol
*sym
)
3003 for (p
= sym
->namelist
; p
; p
= p
->next
)
3004 if (p
->sym
->attr
.intent
== INTENT_IN
)
3006 gfc_error ("Symbol %qs in namelist %qs is INTENT(IN) at %C",
3007 p
->sym
->name
, sym
->name
);
3015 /* Match a single data transfer element. */
3018 match_dt_element (io_kind k
, gfc_dt
*dt
)
3020 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3024 if (gfc_match (" unit =") == MATCH_YES
)
3026 m
= match_dt_unit (k
, dt
);
3031 if (gfc_match (" fmt =") == MATCH_YES
)
3033 m
= match_dt_format (dt
);
3038 if (gfc_match (" nml = %n", name
) == MATCH_YES
)
3040 if (dt
->namelist
!= NULL
)
3042 gfc_error ("Duplicate NML specification at %C");
3046 if (gfc_find_symbol (name
, NULL
, 1, &sym
))
3049 if (sym
== NULL
|| sym
->attr
.flavor
!= FL_NAMELIST
)
3051 gfc_error ("Symbol %qs at %C must be a NAMELIST group name",
3052 sym
!= NULL
? sym
->name
: name
);
3057 if (k
== M_READ
&& check_namelist (sym
))
3063 m
= match_etag (&tag_e_async
, &dt
->asynchronous
);
3064 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", dt
->asynchronous
))
3068 m
= match_etag (&tag_e_blank
, &dt
->blank
);
3071 m
= match_etag (&tag_e_delim
, &dt
->delim
);
3074 m
= match_etag (&tag_e_pad
, &dt
->pad
);
3077 m
= match_etag (&tag_e_sign
, &dt
->sign
);
3080 m
= match_etag (&tag_e_round
, &dt
->round
);
3083 m
= match_out_tag (&tag_id
, &dt
->id
);
3086 m
= match_etag (&tag_e_decimal
, &dt
->decimal
);
3089 m
= match_etag (&tag_rec
, &dt
->rec
);
3092 m
= match_etag (&tag_spos
, &dt
->pos
);
3095 m
= match_etag (&tag_iomsg
, &dt
->iomsg
);
3096 if (m
== MATCH_YES
&& !check_char_variable (dt
->iomsg
))
3101 m
= match_out_tag (&tag_iostat
, &dt
->iostat
);
3104 m
= match_ltag (&tag_err
, &dt
->err
);
3106 dt
->err_where
= gfc_current_locus
;
3109 m
= match_etag (&tag_advance
, &dt
->advance
);
3112 m
= match_out_tag (&tag_size
, &dt
->size
);
3116 m
= match_ltag (&tag_end
, &dt
->end
);
3121 gfc_error ("END tag at %C not allowed in output statement");
3124 dt
->end_where
= gfc_current_locus
;
3129 m
= match_ltag (&tag_eor
, &dt
->eor
);
3131 dt
->eor_where
= gfc_current_locus
;
3139 /* Free a data transfer structure and everything below it. */
3142 gfc_free_dt (gfc_dt
*dt
)
3147 gfc_free_expr (dt
->io_unit
);
3148 gfc_free_expr (dt
->format_expr
);
3149 gfc_free_expr (dt
->rec
);
3150 gfc_free_expr (dt
->advance
);
3151 gfc_free_expr (dt
->iomsg
);
3152 gfc_free_expr (dt
->iostat
);
3153 gfc_free_expr (dt
->size
);
3154 gfc_free_expr (dt
->pad
);
3155 gfc_free_expr (dt
->delim
);
3156 gfc_free_expr (dt
->sign
);
3157 gfc_free_expr (dt
->round
);
3158 gfc_free_expr (dt
->blank
);
3159 gfc_free_expr (dt
->decimal
);
3160 gfc_free_expr (dt
->pos
);
3161 gfc_free_expr (dt
->dt_io_kind
);
3162 /* dt->extra_comma is a link to dt_io_kind if it is set. */
3167 /* Resolve everything in a gfc_dt structure. */
3170 gfc_resolve_dt (gfc_dt
*dt
, locus
*loc
)
3175 /* This is set in any case. */
3176 gcc_assert (dt
->dt_io_kind
);
3177 k
= dt
->dt_io_kind
->value
.iokind
;
3179 RESOLVE_TAG (&tag_format
, dt
->format_expr
);
3180 RESOLVE_TAG (&tag_rec
, dt
->rec
);
3181 RESOLVE_TAG (&tag_spos
, dt
->pos
);
3182 RESOLVE_TAG (&tag_advance
, dt
->advance
);
3183 RESOLVE_TAG (&tag_id
, dt
->id
);
3184 RESOLVE_TAG (&tag_iomsg
, dt
->iomsg
);
3185 RESOLVE_TAG (&tag_iostat
, dt
->iostat
);
3186 RESOLVE_TAG (&tag_size
, dt
->size
);
3187 RESOLVE_TAG (&tag_e_pad
, dt
->pad
);
3188 RESOLVE_TAG (&tag_e_delim
, dt
->delim
);
3189 RESOLVE_TAG (&tag_e_sign
, dt
->sign
);
3190 RESOLVE_TAG (&tag_e_round
, dt
->round
);
3191 RESOLVE_TAG (&tag_e_blank
, dt
->blank
);
3192 RESOLVE_TAG (&tag_e_decimal
, dt
->decimal
);
3193 RESOLVE_TAG (&tag_e_async
, dt
->asynchronous
);
3198 gfc_error ("UNIT not specified at %L", loc
);
3202 if (gfc_resolve_expr (e
)
3203 && (e
->ts
.type
!= BT_INTEGER
3204 && (e
->ts
.type
!= BT_CHARACTER
|| e
->expr_type
!= EXPR_VARIABLE
)))
3206 /* If there is no extra comma signifying the "format" form of the IO
3207 statement, then this must be an error. */
3208 if (!dt
->extra_comma
)
3210 gfc_error ("UNIT specification at %L must be an INTEGER expression "
3211 "or a CHARACTER variable", &e
->where
);
3216 /* At this point, we have an extra comma. If io_unit has arrived as
3217 type character, we assume its really the "format" form of the I/O
3218 statement. We set the io_unit to the default unit and format to
3219 the character expression. See F95 Standard section 9.4. */
3220 if (e
->ts
.type
== BT_CHARACTER
&& (k
== M_READ
|| k
== M_PRINT
))
3222 dt
->format_expr
= dt
->io_unit
;
3223 dt
->io_unit
= default_unit (k
);
3225 /* Nullify this pointer now so that a warning/error is not
3226 triggered below for the "Extension". */
3227 dt
->extra_comma
= NULL
;
3232 gfc_error ("Invalid form of WRITE statement at %L, UNIT required",
3233 &dt
->extra_comma
->where
);
3239 if (e
->ts
.type
== BT_CHARACTER
)
3241 if (gfc_has_vector_index (e
))
3243 gfc_error ("Internal unit with vector subscript at %L", &e
->where
);
3247 /* If we are writing, make sure the internal unit can be changed. */
3248 gcc_assert (k
!= M_PRINT
);
3250 && !gfc_check_vardef_context (e
, false, false, false,
3251 _("internal unit in WRITE")))
3255 if (e
->rank
&& e
->ts
.type
!= BT_CHARACTER
)
3257 gfc_error ("External IO UNIT cannot be an array at %L", &e
->where
);
3261 if (e
->expr_type
== EXPR_CONSTANT
&& e
->ts
.type
== BT_INTEGER
3262 && mpz_sgn (e
->value
.integer
) < 0)
3264 gfc_error ("UNIT number in statement at %L must be non-negative",
3269 /* If we are reading and have a namelist, check that all namelist symbols
3270 can appear in a variable definition context. */
3274 for (n
= dt
->namelist
->namelist
; n
; n
= n
->next
)
3281 e
= gfc_get_variable_expr (gfc_find_sym_in_symtree (n
->sym
));
3282 t
= gfc_check_vardef_context (e
, false, false, false, NULL
);
3287 gfc_error ("NAMELIST %qs in READ statement at %L contains"
3288 " the symbol %qs which may not appear in a"
3289 " variable definition context",
3290 dt
->namelist
->name
, loc
, n
->sym
->name
);
3295 t
= dtio_procs_present (n
->sym
, k
);
3297 if (n
->sym
->ts
.type
== BT_CLASS
&& !t
)
3299 gfc_error ("NAMELIST object %qs in namelist %qs at %L is "
3300 "polymorphic and requires a defined input/output "
3301 "procedure", n
->sym
->name
, dt
->namelist
->name
, loc
);
3305 if ((n
->sym
->ts
.type
== BT_DERIVED
)
3306 && (n
->sym
->ts
.u
.derived
->attr
.alloc_comp
3307 || n
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
3309 if (!gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs in "
3310 "namelist %qs at %L with ALLOCATABLE "
3311 "or POINTER components", n
->sym
->name
,
3312 dt
->namelist
->name
, loc
))
3317 gfc_error ("NAMELIST object %qs in namelist %qs at %L has "
3318 "ALLOCATABLE or POINTER components and thus requires "
3319 "a defined input/output procedure", n
->sym
->name
,
3320 dt
->namelist
->name
, loc
);
3328 && !gfc_notify_std (GFC_STD_LEGACY
, "Comma before i/o item list at %L",
3329 &dt
->extra_comma
->where
))
3334 if (!gfc_reference_st_label (dt
->err
, ST_LABEL_TARGET
))
3336 if (dt
->err
->defined
== ST_LABEL_UNKNOWN
)
3338 gfc_error ("ERR tag label %d at %L not defined",
3339 dt
->err
->value
, &dt
->err_where
);
3346 if (!gfc_reference_st_label (dt
->end
, ST_LABEL_TARGET
))
3348 if (dt
->end
->defined
== ST_LABEL_UNKNOWN
)
3350 gfc_error ("END tag label %d at %L not defined",
3351 dt
->end
->value
, &dt
->end_where
);
3358 if (!gfc_reference_st_label (dt
->eor
, ST_LABEL_TARGET
))
3360 if (dt
->eor
->defined
== ST_LABEL_UNKNOWN
)
3362 gfc_error ("EOR tag label %d at %L not defined",
3363 dt
->eor
->value
, &dt
->eor_where
);
3368 /* Check the format label actually exists. */
3369 if (dt
->format_label
&& dt
->format_label
!= &format_asterisk
3370 && dt
->format_label
->defined
== ST_LABEL_UNKNOWN
)
3372 gfc_error ("FORMAT label %d at %L not defined", dt
->format_label
->value
,
3381 /* Given an io_kind, return its name. */
3384 io_kind_name (io_kind k
)
3403 gfc_internal_error ("io_kind_name(): bad I/O-kind");
3410 /* Match an IO iteration statement of the form:
3412 ( [<IO element> ,] <IO element>, I = <expr>, <expr> [, <expr> ] )
3414 which is equivalent to a single IO element. This function is
3415 mutually recursive with match_io_element(). */
3417 static match
match_io_element (io_kind
, gfc_code
**);
3420 match_io_iterator (io_kind k
, gfc_code
**result
)
3422 gfc_code
*head
, *tail
, *new_code
;
3430 old_loc
= gfc_current_locus
;
3432 if (gfc_match_char ('(') != MATCH_YES
)
3435 m
= match_io_element (k
, &head
);
3438 if (m
!= MATCH_YES
|| gfc_match_char (',') != MATCH_YES
)
3444 /* Can't be anything but an IO iterator. Build a list. */
3445 iter
= gfc_get_iterator ();
3449 m
= gfc_match_iterator (iter
, 0);
3450 if (m
== MATCH_ERROR
)
3454 gfc_check_do_variable (iter
->var
->symtree
);
3458 m
= match_io_element (k
, &new_code
);
3459 if (m
== MATCH_ERROR
)
3468 tail
= gfc_append_code (tail
, new_code
);
3470 if (gfc_match_char (',') != MATCH_YES
)
3479 if (gfc_match_char (')') != MATCH_YES
)
3482 new_code
= gfc_get_code (EXEC_DO
);
3483 new_code
->ext
.iterator
= iter
;
3485 new_code
->block
= gfc_get_code (EXEC_DO
);
3486 new_code
->block
->next
= head
;
3492 gfc_error ("Syntax error in I/O iterator at %C");
3496 gfc_free_iterator (iter
, 1);
3497 gfc_free_statements (head
);
3498 gfc_current_locus
= old_loc
;
3503 /* Match a single element of an IO list, which is either a single
3504 expression or an IO Iterator. */
3507 match_io_element (io_kind k
, gfc_code
**cpp
)
3515 m
= match_io_iterator (k
, cpp
);
3521 m
= gfc_match_variable (&expr
, 0);
3523 gfc_error ("Expected variable in READ statement at %C");
3527 m
= gfc_match_expr (&expr
);
3529 gfc_error ("Expected expression in %s statement at %C",
3533 if (m
== MATCH_YES
&& k
== M_READ
&& gfc_check_do_variable (expr
->symtree
))
3538 gfc_free_expr (expr
);
3542 cp
= gfc_get_code (EXEC_TRANSFER
);
3545 cp
->ext
.dt
= current_dt
;
3552 /* Match an I/O list, building gfc_code structures as we go. */
3555 match_io_list (io_kind k
, gfc_code
**head_p
)
3557 gfc_code
*head
, *tail
, *new_code
;
3560 *head_p
= head
= tail
= NULL
;
3561 if (gfc_match_eos () == MATCH_YES
)
3566 m
= match_io_element (k
, &new_code
);
3567 if (m
== MATCH_ERROR
)
3572 tail
= gfc_append_code (tail
, new_code
);
3576 if (gfc_match_eos () == MATCH_YES
)
3578 if (gfc_match_char (',') != MATCH_YES
)
3586 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k
));
3589 gfc_free_statements (head
);
3594 /* Attach the data transfer end node. */
3597 terminate_io (gfc_code
*io_code
)
3601 if (io_code
== NULL
)
3602 io_code
= new_st
.block
;
3604 c
= gfc_get_code (EXEC_DT_END
);
3606 /* Point to structure that is already there */
3607 c
->ext
.dt
= new_st
.ext
.dt
;
3608 gfc_append_code (io_code
, c
);
3612 /* Check the constraints for a data transfer statement. The majority of the
3613 constraints appearing in 9.4 of the standard appear here. Some are handled
3614 in resolve_tag and others in gfc_resolve_dt. */
3617 check_io_constraints (io_kind k
, gfc_dt
*dt
, gfc_code
*io_code
,
3620 #define io_constraint(condition,msg,arg)\
3623 gfc_error(msg,arg);\
3629 gfc_symbol
*sym
= NULL
;
3630 bool warn
, unformatted
;
3632 warn
= (dt
->err
|| dt
->iostat
) ? true : false;
3633 unformatted
= dt
->format_expr
== NULL
&& dt
->format_label
== NULL
3634 && dt
->namelist
== NULL
;
3639 if (expr
&& expr
->expr_type
== EXPR_VARIABLE
3640 && expr
->ts
.type
== BT_CHARACTER
)
3642 sym
= expr
->symtree
->n
.sym
;
3644 io_constraint (k
== M_WRITE
&& sym
->attr
.intent
== INTENT_IN
,
3645 "Internal file at %L must not be INTENT(IN)",
3648 io_constraint (gfc_has_vector_index (dt
->io_unit
),
3649 "Internal file incompatible with vector subscript at %L",
3652 io_constraint (dt
->rec
!= NULL
,
3653 "REC tag at %L is incompatible with internal file",
3656 io_constraint (dt
->pos
!= NULL
,
3657 "POS tag at %L is incompatible with internal file",
3660 io_constraint (unformatted
,
3661 "Unformatted I/O not allowed with internal unit at %L",
3662 &dt
->io_unit
->where
);
3664 io_constraint (dt
->asynchronous
!= NULL
,
3665 "ASYNCHRONOUS tag at %L not allowed with internal file",
3666 &dt
->asynchronous
->where
);
3668 if (dt
->namelist
!= NULL
)
3670 if (!gfc_notify_std (GFC_STD_F2003
, "Internal file at %L with "
3671 "namelist", &expr
->where
))
3675 io_constraint (dt
->advance
!= NULL
,
3676 "ADVANCE tag at %L is incompatible with internal file",
3677 &dt
->advance
->where
);
3680 if (expr
&& expr
->ts
.type
!= BT_CHARACTER
)
3683 io_constraint (gfc_pure (NULL
) && (k
== M_READ
|| k
== M_WRITE
),
3684 "IO UNIT in %s statement at %C must be "
3685 "an internal file in a PURE procedure",
3688 if (k
== M_READ
|| k
== M_WRITE
)
3689 gfc_unset_implicit_pure (NULL
);
3694 io_constraint (dt
->end
, "END tag not allowed with output at %L",
3697 io_constraint (dt
->eor
, "EOR tag not allowed with output at %L",
3700 io_constraint (dt
->blank
, "BLANK= specifier not allowed with output at %L",
3703 io_constraint (dt
->pad
, "PAD= specifier not allowed with output at %L",
3706 io_constraint (dt
->size
, "SIZE= specifier not allowed with output at %L",
3711 io_constraint (dt
->size
&& dt
->advance
== NULL
,
3712 "SIZE tag at %L requires an ADVANCE tag",
3715 io_constraint (dt
->eor
&& dt
->advance
== NULL
,
3716 "EOR tag at %L requires an ADVANCE tag",
3720 if (dt
->asynchronous
)
3722 static const char * asynchronous
[] = { "YES", "NO", NULL
};
3724 if (!gfc_reduce_init_expr (dt
->asynchronous
))
3726 gfc_error ("ASYNCHRONOUS= specifier at %L must be an initialization "
3727 "expression", &dt
->asynchronous
->where
);
3731 if (!is_char_type ("ASYNCHRONOUS", dt
->asynchronous
))
3734 if (!compare_to_allowed_values
3735 ("ASYNCHRONOUS", asynchronous
, NULL
, NULL
,
3736 dt
->asynchronous
->value
.character
.string
,
3737 io_kind_name (k
), warn
))
3745 || gfc_wide_strlen (dt
->asynchronous
->value
.character
.string
) != 3
3746 || gfc_wide_strncasecmp (dt
->asynchronous
->value
.character
.string
,
3748 io_constraint (not_yes
,
3749 "ID= specifier at %L must be with ASYNCHRONOUS='yes' "
3750 "specifier", &dt
->id
->where
);
3755 if (!gfc_notify_std (GFC_STD_F2003
, "DECIMAL= at %C "
3756 "not allowed in Fortran 95"))
3759 if (dt
->decimal
->expr_type
== EXPR_CONSTANT
)
3761 static const char * decimal
[] = { "COMMA", "POINT", NULL
};
3763 if (!is_char_type ("DECIMAL", dt
->decimal
))
3766 if (!compare_to_allowed_values ("DECIMAL", decimal
, NULL
, NULL
,
3767 dt
->decimal
->value
.character
.string
,
3768 io_kind_name (k
), warn
))
3771 io_constraint (unformatted
,
3772 "the DECIMAL= specifier at %L must be with an "
3773 "explicit format expression", &dt
->decimal
->where
);
3779 if (!gfc_notify_std (GFC_STD_F2003
, "BLANK= at %C "
3780 "not allowed in Fortran 95"))
3783 if (!is_char_type ("BLANK", dt
->blank
))
3786 if (dt
->blank
->expr_type
== EXPR_CONSTANT
)
3788 static const char * blank
[] = { "NULL", "ZERO", NULL
};
3791 if (!compare_to_allowed_values ("BLANK", blank
, NULL
, NULL
,
3792 dt
->blank
->value
.character
.string
,
3793 io_kind_name (k
), warn
))
3796 io_constraint (unformatted
,
3797 "the BLANK= specifier at %L must be with an "
3798 "explicit format expression", &dt
->blank
->where
);
3804 if (!gfc_notify_std (GFC_STD_F2003
, "PAD= at %C "
3805 "not allowed in Fortran 95"))
3808 if (!is_char_type ("PAD", dt
->pad
))
3811 if (dt
->pad
->expr_type
== EXPR_CONSTANT
)
3813 static const char * pad
[] = { "YES", "NO", NULL
};
3815 if (!compare_to_allowed_values ("PAD", pad
, NULL
, NULL
,
3816 dt
->pad
->value
.character
.string
,
3817 io_kind_name (k
), warn
))
3820 io_constraint (unformatted
,
3821 "the PAD= specifier at %L must be with an "
3822 "explicit format expression", &dt
->pad
->where
);
3828 if (!gfc_notify_std (GFC_STD_F2003
, "ROUND= at %C "
3829 "not allowed in Fortran 95"))
3832 if (!is_char_type ("ROUND", dt
->round
))
3835 if (dt
->round
->expr_type
== EXPR_CONSTANT
)
3837 static const char * round
[] = { "UP", "DOWN", "ZERO", "NEAREST",
3838 "COMPATIBLE", "PROCESSOR_DEFINED",
3841 if (!compare_to_allowed_values ("ROUND", round
, NULL
, NULL
,
3842 dt
->round
->value
.character
.string
,
3843 io_kind_name (k
), warn
))
3850 /* When implemented, change the following to use gfc_notify_std F2003.
3851 if (gfc_notify_std (GFC_STD_F2003, "SIGN= at %C "
3852 "not allowed in Fortran 95") == false)
3853 return MATCH_ERROR; */
3855 if (!is_char_type ("SIGN", dt
->sign
))
3858 if (dt
->sign
->expr_type
== EXPR_CONSTANT
)
3860 static const char * sign
[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
3863 if (!compare_to_allowed_values ("SIGN", sign
, NULL
, NULL
,
3864 dt
->sign
->value
.character
.string
,
3865 io_kind_name (k
), warn
))
3868 io_constraint (unformatted
,
3869 "SIGN= specifier at %L must be with an "
3870 "explicit format expression", &dt
->sign
->where
);
3872 io_constraint (k
== M_READ
,
3873 "SIGN= specifier at %L not allowed in a "
3874 "READ statement", &dt
->sign
->where
);
3880 if (!gfc_notify_std (GFC_STD_F2003
, "DELIM= at %C "
3881 "not allowed in Fortran 95"))
3884 if (!is_char_type ("DELIM", dt
->delim
))
3887 if (dt
->delim
->expr_type
== EXPR_CONSTANT
)
3889 static const char *delim
[] = { "APOSTROPHE", "QUOTE", "NONE", NULL
};
3891 if (!compare_to_allowed_values ("DELIM", delim
, NULL
, NULL
,
3892 dt
->delim
->value
.character
.string
,
3893 io_kind_name (k
), warn
))
3896 io_constraint (k
== M_READ
,
3897 "DELIM= specifier at %L not allowed in a "
3898 "READ statement", &dt
->delim
->where
);
3900 io_constraint (dt
->format_label
!= &format_asterisk
3901 && dt
->namelist
== NULL
,
3902 "DELIM= specifier at %L must have FMT=*",
3905 io_constraint (unformatted
&& dt
->namelist
== NULL
,
3906 "DELIM= specifier at %L must be with FMT=* or "
3907 "NML= specifier", &dt
->delim
->where
);
3913 io_constraint (io_code
&& dt
->namelist
,
3914 "NAMELIST cannot be followed by IO-list at %L",
3917 io_constraint (dt
->format_expr
,
3918 "IO spec-list cannot contain both NAMELIST group name "
3919 "and format specification at %L",
3920 &dt
->format_expr
->where
);
3922 io_constraint (dt
->format_label
,
3923 "IO spec-list cannot contain both NAMELIST group name "
3924 "and format label at %L", spec_end
);
3926 io_constraint (dt
->rec
,
3927 "NAMELIST IO is not allowed with a REC= specifier "
3928 "at %L", &dt
->rec
->where
);
3930 io_constraint (dt
->advance
,
3931 "NAMELIST IO is not allowed with a ADVANCE= specifier "
3932 "at %L", &dt
->advance
->where
);
3937 io_constraint (dt
->end
,
3938 "An END tag is not allowed with a "
3939 "REC= specifier at %L", &dt
->end_where
);
3941 io_constraint (dt
->format_label
== &format_asterisk
,
3942 "FMT=* is not allowed with a REC= specifier "
3945 io_constraint (dt
->pos
,
3946 "POS= is not allowed with REC= specifier "
3947 "at %L", &dt
->pos
->where
);
3952 int not_yes
, not_no
;
3955 io_constraint (dt
->format_label
== &format_asterisk
,
3956 "List directed format(*) is not allowed with a "
3957 "ADVANCE= specifier at %L.", &expr
->where
);
3959 io_constraint (unformatted
,
3960 "the ADVANCE= specifier at %L must appear with an "
3961 "explicit format expression", &expr
->where
);
3963 if (expr
->expr_type
== EXPR_CONSTANT
&& expr
->ts
.type
== BT_CHARACTER
)
3965 const gfc_char_t
*advance
= expr
->value
.character
.string
;
3966 not_no
= gfc_wide_strlen (advance
) != 2
3967 || gfc_wide_strncasecmp (advance
, "no", 2) != 0;
3968 not_yes
= gfc_wide_strlen (advance
) != 3
3969 || gfc_wide_strncasecmp (advance
, "yes", 3) != 0;
3977 io_constraint (not_no
&& not_yes
,
3978 "ADVANCE= specifier at %L must have value = "
3979 "YES or NO.", &expr
->where
);
3981 io_constraint (dt
->size
&& not_no
&& k
== M_READ
,
3982 "SIZE tag at %L requires an ADVANCE = %<NO%>",
3985 io_constraint (dt
->eor
&& not_no
&& k
== M_READ
,
3986 "EOR tag at %L requires an ADVANCE = %<NO%>",
3990 expr
= dt
->format_expr
;
3991 if (!gfc_simplify_expr (expr
, 0)
3992 || !check_format_string (expr
, k
== M_READ
))
3997 #undef io_constraint
4000 /* Match a READ, WRITE or PRINT statement. */
4003 match_io (io_kind k
)
4005 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4010 locus spec_end
, control
;
4014 where
= gfc_current_locus
;
4016 current_dt
= dt
= XCNEW (gfc_dt
);
4017 m
= gfc_match_char ('(');
4020 where
= gfc_current_locus
;
4023 else if (k
== M_PRINT
)
4025 /* Treat the non-standard case of PRINT namelist. */
4026 if ((gfc_current_form
== FORM_FIXED
|| gfc_peek_ascii_char () == ' ')
4027 && gfc_match_name (name
) == MATCH_YES
)
4029 gfc_find_symbol (name
, NULL
, 1, &sym
);
4030 if (sym
&& sym
->attr
.flavor
== FL_NAMELIST
)
4032 if (!gfc_notify_std (GFC_STD_GNU
, "PRINT namelist at "
4033 "%C is an extension"))
4039 dt
->io_unit
= default_unit (k
);
4044 gfc_current_locus
= where
;
4048 if (gfc_current_form
== FORM_FREE
)
4050 char c
= gfc_peek_ascii_char ();
4051 if (c
!= ' ' && c
!= '*' && c
!= '\'' && c
!= '"')
4058 m
= match_dt_format (dt
);
4059 if (m
== MATCH_ERROR
)
4065 dt
->io_unit
= default_unit (k
);
4070 /* Before issuing an error for a malformed 'print (1,*)' type of
4071 error, check for a default-char-expr of the form ('(I0)'). */
4074 control
= gfc_current_locus
;
4077 /* Reset current locus to get the initial '(' in an expression. */
4078 gfc_current_locus
= where
;
4079 dt
->format_expr
= NULL
;
4080 m
= match_dt_format (dt
);
4082 if (m
== MATCH_ERROR
)
4084 if (m
== MATCH_NO
|| dt
->format_expr
== NULL
)
4088 dt
->io_unit
= default_unit (k
);
4093 /* Commit any pending symbols now so that when we undo
4094 symbols later we wont lose them. */
4095 gfc_commit_symbols ();
4096 /* Reset current locus to get the initial '(' in an expression. */
4097 gfc_current_locus
= where
;
4098 dt
->format_expr
= NULL
;
4099 m
= gfc_match_expr (&dt
->format_expr
);
4103 && dt
->format_expr
->ts
.type
== BT_CHARACTER
)
4106 dt
->io_unit
= default_unit (k
);
4111 gfc_free_expr (dt
->format_expr
);
4112 dt
->format_expr
= NULL
;
4113 gfc_current_locus
= control
;
4119 gfc_undo_symbols ();
4120 gfc_free_expr (dt
->format_expr
);
4121 dt
->format_expr
= NULL
;
4122 gfc_current_locus
= control
;
4128 /* Match a control list */
4129 if (match_dt_element (k
, dt
) == MATCH_YES
)
4131 if (match_dt_unit (k
, dt
) != MATCH_YES
)
4134 if (gfc_match_char (')') == MATCH_YES
)
4136 if (gfc_match_char (',') != MATCH_YES
)
4139 m
= match_dt_element (k
, dt
);
4142 if (m
== MATCH_ERROR
)
4145 m
= match_dt_format (dt
);
4148 if (m
== MATCH_ERROR
)
4151 where
= gfc_current_locus
;
4153 m
= gfc_match_name (name
);
4156 gfc_find_symbol (name
, NULL
, 1, &sym
);
4157 if (sym
&& sym
->attr
.flavor
== FL_NAMELIST
)
4160 if (k
== M_READ
&& check_namelist (sym
))
4169 gfc_current_locus
= where
;
4171 goto loop
; /* No matches, try regular elements */
4174 if (gfc_match_char (')') == MATCH_YES
)
4176 if (gfc_match_char (',') != MATCH_YES
)
4182 m
= match_dt_element (k
, dt
);
4185 if (m
== MATCH_ERROR
)
4188 if (gfc_match_char (')') == MATCH_YES
)
4190 if (gfc_match_char (',') != MATCH_YES
)
4196 /* Used in check_io_constraints, where no locus is available. */
4197 spec_end
= gfc_current_locus
;
4199 /* Save the IO kind for later use. */
4200 dt
->dt_io_kind
= gfc_get_iokind_expr (&gfc_current_locus
, k
);
4202 /* Optional leading comma (non-standard). We use a gfc_expr structure here
4203 to save the locus. This is used later when resolving transfer statements
4204 that might have a format expression without unit number. */
4205 if (!comma_flag
&& gfc_match_char (',') == MATCH_YES
)
4206 dt
->extra_comma
= dt
->dt_io_kind
;
4209 if (gfc_match_eos () != MATCH_YES
)
4211 if (comma_flag
&& gfc_match_char (',') != MATCH_YES
)
4213 gfc_error ("Expected comma in I/O list at %C");
4218 m
= match_io_list (k
, &io_code
);
4219 if (m
== MATCH_ERROR
)
4225 /* See if we want to use defaults for missing exponents in real transfers. */
4227 dt
->default_exp
= 1;
4229 /* A full IO statement has been matched. Check the constraints. spec_end is
4230 supplied for cases where no locus is supplied. */
4231 m
= check_io_constraints (k
, dt
, io_code
, &spec_end
);
4233 if (m
== MATCH_ERROR
)
4236 new_st
.op
= (k
== M_READ
) ? EXEC_READ
: EXEC_WRITE
;
4238 new_st
.block
= gfc_get_code (new_st
.op
);
4239 new_st
.block
->next
= io_code
;
4241 terminate_io (io_code
);
4246 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k
));
4256 gfc_match_read (void)
4258 return match_io (M_READ
);
4263 gfc_match_write (void)
4265 return match_io (M_WRITE
);
4270 gfc_match_print (void)
4274 m
= match_io (M_PRINT
);
4278 if (gfc_pure (NULL
))
4280 gfc_error ("PRINT statement at %C not allowed within PURE procedure");
4284 gfc_unset_implicit_pure (NULL
);
4290 /* Free a gfc_inquire structure. */
4293 gfc_free_inquire (gfc_inquire
*inquire
)
4296 if (inquire
== NULL
)
4299 gfc_free_expr (inquire
->unit
);
4300 gfc_free_expr (inquire
->file
);
4301 gfc_free_expr (inquire
->iomsg
);
4302 gfc_free_expr (inquire
->iostat
);
4303 gfc_free_expr (inquire
->exist
);
4304 gfc_free_expr (inquire
->opened
);
4305 gfc_free_expr (inquire
->number
);
4306 gfc_free_expr (inquire
->named
);
4307 gfc_free_expr (inquire
->name
);
4308 gfc_free_expr (inquire
->access
);
4309 gfc_free_expr (inquire
->sequential
);
4310 gfc_free_expr (inquire
->direct
);
4311 gfc_free_expr (inquire
->form
);
4312 gfc_free_expr (inquire
->formatted
);
4313 gfc_free_expr (inquire
->unformatted
);
4314 gfc_free_expr (inquire
->recl
);
4315 gfc_free_expr (inquire
->nextrec
);
4316 gfc_free_expr (inquire
->blank
);
4317 gfc_free_expr (inquire
->position
);
4318 gfc_free_expr (inquire
->action
);
4319 gfc_free_expr (inquire
->read
);
4320 gfc_free_expr (inquire
->write
);
4321 gfc_free_expr (inquire
->readwrite
);
4322 gfc_free_expr (inquire
->delim
);
4323 gfc_free_expr (inquire
->encoding
);
4324 gfc_free_expr (inquire
->pad
);
4325 gfc_free_expr (inquire
->iolength
);
4326 gfc_free_expr (inquire
->convert
);
4327 gfc_free_expr (inquire
->strm_pos
);
4328 gfc_free_expr (inquire
->asynchronous
);
4329 gfc_free_expr (inquire
->decimal
);
4330 gfc_free_expr (inquire
->pending
);
4331 gfc_free_expr (inquire
->id
);
4332 gfc_free_expr (inquire
->sign
);
4333 gfc_free_expr (inquire
->size
);
4334 gfc_free_expr (inquire
->round
);
4335 gfc_free_expr (inquire
->share
);
4336 gfc_free_expr (inquire
->cc
);
4341 /* Match an element of an INQUIRE statement. */
4343 #define RETM if (m != MATCH_NO) return m;
4346 match_inquire_element (gfc_inquire
*inquire
)
4350 m
= match_etag (&tag_unit
, &inquire
->unit
);
4351 RETM m
= match_etag (&tag_file
, &inquire
->file
);
4352 RETM m
= match_ltag (&tag_err
, &inquire
->err
);
4353 RETM m
= match_etag (&tag_iomsg
, &inquire
->iomsg
);
4354 if (m
== MATCH_YES
&& !check_char_variable (inquire
->iomsg
))
4356 RETM m
= match_out_tag (&tag_iostat
, &inquire
->iostat
);
4357 RETM m
= match_vtag (&tag_exist
, &inquire
->exist
);
4358 RETM m
= match_vtag (&tag_opened
, &inquire
->opened
);
4359 RETM m
= match_vtag (&tag_named
, &inquire
->named
);
4360 RETM m
= match_vtag (&tag_name
, &inquire
->name
);
4361 RETM m
= match_out_tag (&tag_number
, &inquire
->number
);
4362 RETM m
= match_vtag (&tag_s_access
, &inquire
->access
);
4363 RETM m
= match_vtag (&tag_sequential
, &inquire
->sequential
);
4364 RETM m
= match_vtag (&tag_direct
, &inquire
->direct
);
4365 RETM m
= match_vtag (&tag_s_form
, &inquire
->form
);
4366 RETM m
= match_vtag (&tag_formatted
, &inquire
->formatted
);
4367 RETM m
= match_vtag (&tag_unformatted
, &inquire
->unformatted
);
4368 RETM m
= match_out_tag (&tag_s_recl
, &inquire
->recl
);
4369 RETM m
= match_out_tag (&tag_nextrec
, &inquire
->nextrec
);
4370 RETM m
= match_vtag (&tag_s_blank
, &inquire
->blank
);
4371 RETM m
= match_vtag (&tag_s_position
, &inquire
->position
);
4372 RETM m
= match_vtag (&tag_s_action
, &inquire
->action
);
4373 RETM m
= match_vtag (&tag_read
, &inquire
->read
);
4374 RETM m
= match_vtag (&tag_write
, &inquire
->write
);
4375 RETM m
= match_vtag (&tag_readwrite
, &inquire
->readwrite
);
4376 RETM m
= match_vtag (&tag_s_async
, &inquire
->asynchronous
);
4377 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", inquire
->asynchronous
))
4379 RETM m
= match_vtag (&tag_s_delim
, &inquire
->delim
);
4380 RETM m
= match_vtag (&tag_s_decimal
, &inquire
->decimal
);
4381 RETM m
= match_out_tag (&tag_size
, &inquire
->size
);
4382 RETM m
= match_vtag (&tag_s_encoding
, &inquire
->encoding
);
4383 RETM m
= match_vtag (&tag_s_round
, &inquire
->round
);
4384 RETM m
= match_vtag (&tag_s_sign
, &inquire
->sign
);
4385 RETM m
= match_vtag (&tag_s_pad
, &inquire
->pad
);
4386 RETM m
= match_out_tag (&tag_iolength
, &inquire
->iolength
);
4387 RETM m
= match_vtag (&tag_convert
, &inquire
->convert
);
4388 RETM m
= match_out_tag (&tag_strm_out
, &inquire
->strm_pos
);
4389 RETM m
= match_vtag (&tag_pending
, &inquire
->pending
);
4390 RETM m
= match_vtag (&tag_id
, &inquire
->id
);
4391 RETM m
= match_vtag (&tag_s_iqstream
, &inquire
->iqstream
);
4392 RETM m
= match_dec_vtag (&tag_v_share
, &inquire
->share
);
4393 RETM m
= match_dec_vtag (&tag_v_cc
, &inquire
->cc
);
4394 RETM
return MATCH_NO
;
4401 gfc_match_inquire (void)
4403 gfc_inquire
*inquire
;
4408 m
= gfc_match_char ('(');
4412 inquire
= XCNEW (gfc_inquire
);
4414 loc
= gfc_current_locus
;
4416 m
= match_inquire_element (inquire
);
4417 if (m
== MATCH_ERROR
)
4421 m
= gfc_match_expr (&inquire
->unit
);
4422 if (m
== MATCH_ERROR
)
4428 /* See if we have the IOLENGTH form of the inquire statement. */
4429 if (inquire
->iolength
!= NULL
)
4431 if (gfc_match_char (')') != MATCH_YES
)
4434 m
= match_io_list (M_INQUIRE
, &code
);
4435 if (m
== MATCH_ERROR
)
4440 new_st
.op
= EXEC_IOLENGTH
;
4441 new_st
.expr1
= inquire
->iolength
;
4442 new_st
.ext
.inquire
= inquire
;
4444 if (gfc_pure (NULL
))
4446 gfc_free_statements (code
);
4447 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
4451 gfc_unset_implicit_pure (NULL
);
4453 new_st
.block
= gfc_get_code (EXEC_IOLENGTH
);
4454 terminate_io (code
);
4455 new_st
.block
->next
= code
;
4459 /* At this point, we have the non-IOLENGTH inquire statement. */
4462 if (gfc_match_char (')') == MATCH_YES
)
4464 if (gfc_match_char (',') != MATCH_YES
)
4467 m
= match_inquire_element (inquire
);
4468 if (m
== MATCH_ERROR
)
4473 if (inquire
->iolength
!= NULL
)
4475 gfc_error ("IOLENGTH tag invalid in INQUIRE statement at %C");
4480 if (gfc_match_eos () != MATCH_YES
)
4483 if (inquire
->unit
!= NULL
&& inquire
->file
!= NULL
)
4485 gfc_error ("INQUIRE statement at %L cannot contain both FILE and "
4486 "UNIT specifiers", &loc
);
4490 if (inquire
->unit
== NULL
&& inquire
->file
== NULL
)
4492 gfc_error ("INQUIRE statement at %L requires either FILE or "
4493 "UNIT specifier", &loc
);
4497 if (inquire
->unit
!= NULL
&& inquire
->unit
->expr_type
== EXPR_CONSTANT
4498 && inquire
->unit
->ts
.type
== BT_INTEGER
4499 && ((mpz_get_si (inquire
->unit
->value
.integer
) == GFC_INTERNAL_UNIT4
)
4500 || (mpz_get_si (inquire
->unit
->value
.integer
) == GFC_INTERNAL_UNIT
)))
4502 gfc_error ("UNIT number in INQUIRE statement at %L can not "
4503 "be %d", &loc
, (int) mpz_get_si (inquire
->unit
->value
.integer
));
4507 if (gfc_pure (NULL
))
4509 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
4513 gfc_unset_implicit_pure (NULL
);
4515 if (inquire
->id
!= NULL
&& inquire
->pending
== NULL
)
4517 gfc_error ("INQUIRE statement at %L requires a PENDING= specifier with "
4518 "the ID= specifier", &loc
);
4522 new_st
.op
= EXEC_INQUIRE
;
4523 new_st
.ext
.inquire
= inquire
;
4527 gfc_syntax_error (ST_INQUIRE
);
4530 gfc_free_inquire (inquire
);
4535 /* Resolve everything in a gfc_inquire structure. */
4538 gfc_resolve_inquire (gfc_inquire
*inquire
)
4540 RESOLVE_TAG (&tag_unit
, inquire
->unit
);
4541 RESOLVE_TAG (&tag_file
, inquire
->file
);
4542 RESOLVE_TAG (&tag_id
, inquire
->id
);
4544 /* For INQUIRE, all tags except FILE, ID and UNIT are variable definition
4545 contexts. Thus, use an extended RESOLVE_TAG macro for that. */
4546 #define INQUIRE_RESOLVE_TAG(tag, expr) \
4547 RESOLVE_TAG (tag, expr); \
4551 sprintf (context, _("%s tag with INQUIRE"), (tag)->name); \
4552 if (gfc_check_vardef_context ((expr), false, false, false, \
4553 context) == false) \
4556 INQUIRE_RESOLVE_TAG (&tag_iomsg
, inquire
->iomsg
);
4557 INQUIRE_RESOLVE_TAG (&tag_iostat
, inquire
->iostat
);
4558 INQUIRE_RESOLVE_TAG (&tag_exist
, inquire
->exist
);
4559 INQUIRE_RESOLVE_TAG (&tag_opened
, inquire
->opened
);
4560 INQUIRE_RESOLVE_TAG (&tag_number
, inquire
->number
);
4561 INQUIRE_RESOLVE_TAG (&tag_named
, inquire
->named
);
4562 INQUIRE_RESOLVE_TAG (&tag_name
, inquire
->name
);
4563 INQUIRE_RESOLVE_TAG (&tag_s_access
, inquire
->access
);
4564 INQUIRE_RESOLVE_TAG (&tag_sequential
, inquire
->sequential
);
4565 INQUIRE_RESOLVE_TAG (&tag_direct
, inquire
->direct
);
4566 INQUIRE_RESOLVE_TAG (&tag_s_form
, inquire
->form
);
4567 INQUIRE_RESOLVE_TAG (&tag_formatted
, inquire
->formatted
);
4568 INQUIRE_RESOLVE_TAG (&tag_unformatted
, inquire
->unformatted
);
4569 INQUIRE_RESOLVE_TAG (&tag_s_recl
, inquire
->recl
);
4570 INQUIRE_RESOLVE_TAG (&tag_nextrec
, inquire
->nextrec
);
4571 INQUIRE_RESOLVE_TAG (&tag_s_blank
, inquire
->blank
);
4572 INQUIRE_RESOLVE_TAG (&tag_s_position
, inquire
->position
);
4573 INQUIRE_RESOLVE_TAG (&tag_s_action
, inquire
->action
);
4574 INQUIRE_RESOLVE_TAG (&tag_read
, inquire
->read
);
4575 INQUIRE_RESOLVE_TAG (&tag_write
, inquire
->write
);
4576 INQUIRE_RESOLVE_TAG (&tag_readwrite
, inquire
->readwrite
);
4577 INQUIRE_RESOLVE_TAG (&tag_s_delim
, inquire
->delim
);
4578 INQUIRE_RESOLVE_TAG (&tag_s_pad
, inquire
->pad
);
4579 INQUIRE_RESOLVE_TAG (&tag_s_encoding
, inquire
->encoding
);
4580 INQUIRE_RESOLVE_TAG (&tag_s_round
, inquire
->round
);
4581 INQUIRE_RESOLVE_TAG (&tag_iolength
, inquire
->iolength
);
4582 INQUIRE_RESOLVE_TAG (&tag_convert
, inquire
->convert
);
4583 INQUIRE_RESOLVE_TAG (&tag_strm_out
, inquire
->strm_pos
);
4584 INQUIRE_RESOLVE_TAG (&tag_s_async
, inquire
->asynchronous
);
4585 INQUIRE_RESOLVE_TAG (&tag_s_sign
, inquire
->sign
);
4586 INQUIRE_RESOLVE_TAG (&tag_s_round
, inquire
->round
);
4587 INQUIRE_RESOLVE_TAG (&tag_pending
, inquire
->pending
);
4588 INQUIRE_RESOLVE_TAG (&tag_size
, inquire
->size
);
4589 INQUIRE_RESOLVE_TAG (&tag_s_decimal
, inquire
->decimal
);
4590 INQUIRE_RESOLVE_TAG (&tag_s_iqstream
, inquire
->iqstream
);
4591 INQUIRE_RESOLVE_TAG (&tag_v_share
, inquire
->share
);
4592 INQUIRE_RESOLVE_TAG (&tag_v_cc
, inquire
->cc
);
4593 #undef INQUIRE_RESOLVE_TAG
4595 if (!gfc_reference_st_label (inquire
->err
, ST_LABEL_TARGET
))
4603 gfc_free_wait (gfc_wait
*wait
)
4608 gfc_free_expr (wait
->unit
);
4609 gfc_free_expr (wait
->iostat
);
4610 gfc_free_expr (wait
->iomsg
);
4611 gfc_free_expr (wait
->id
);
4617 gfc_resolve_wait (gfc_wait
*wait
)
4619 RESOLVE_TAG (&tag_unit
, wait
->unit
);
4620 RESOLVE_TAG (&tag_iomsg
, wait
->iomsg
);
4621 RESOLVE_TAG (&tag_iostat
, wait
->iostat
);
4622 RESOLVE_TAG (&tag_id
, wait
->id
);
4624 if (!gfc_reference_st_label (wait
->err
, ST_LABEL_TARGET
))
4627 if (!gfc_reference_st_label (wait
->end
, ST_LABEL_TARGET
))
4633 /* Match an element of a WAIT statement. */
4635 #define RETM if (m != MATCH_NO) return m;
4638 match_wait_element (gfc_wait
*wait
)
4642 m
= match_etag (&tag_unit
, &wait
->unit
);
4643 RETM m
= match_ltag (&tag_err
, &wait
->err
);
4644 RETM m
= match_ltag (&tag_end
, &wait
->eor
);
4645 RETM m
= match_ltag (&tag_eor
, &wait
->end
);
4646 RETM m
= match_etag (&tag_iomsg
, &wait
->iomsg
);
4647 if (m
== MATCH_YES
&& !check_char_variable (wait
->iomsg
))
4649 RETM m
= match_out_tag (&tag_iostat
, &wait
->iostat
);
4650 RETM m
= match_etag (&tag_id
, &wait
->id
);
4651 RETM
return MATCH_NO
;
4658 gfc_match_wait (void)
4663 m
= gfc_match_char ('(');
4667 wait
= XCNEW (gfc_wait
);
4669 m
= match_wait_element (wait
);
4670 if (m
== MATCH_ERROR
)
4674 m
= gfc_match_expr (&wait
->unit
);
4675 if (m
== MATCH_ERROR
)
4683 if (gfc_match_char (')') == MATCH_YES
)
4685 if (gfc_match_char (',') != MATCH_YES
)
4688 m
= match_wait_element (wait
);
4689 if (m
== MATCH_ERROR
)
4695 if (!gfc_notify_std (GFC_STD_F2003
, "WAIT at %C "
4696 "not allowed in Fortran 95"))
4699 if (gfc_pure (NULL
))
4701 gfc_error ("WAIT statement not allowed in PURE procedure at %C");
4705 gfc_unset_implicit_pure (NULL
);
4707 new_st
.op
= EXEC_WAIT
;
4708 new_st
.ext
.wait
= wait
;
4713 gfc_syntax_error (ST_WAIT
);
4716 gfc_free_wait (wait
);