1 /* Deal with I/O statements & related stuff.
2 Copyright (C) 2000-2016 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 (bool *error
)
208 error_element
= c
= next_char (NONSTRING
);
211 if (gfc_option
.allow_std
& GFC_STD_GNU
)
212 gfc_warning (0, "Extension: Tab character in format at %C");
215 gfc_error ("Extension: Tab character in format at %C");
221 while (gfc_is_whitespace (c
));
225 static int value
= 0;
227 /* Simple lexical analyzer for getting the next token in a FORMAT
239 if (saved_token
!= FMT_NONE
)
242 saved_token
= FMT_NONE
;
246 c
= next_char_not_space (&error
);
256 c
= next_char_not_space (&error
);
267 c
= next_char_not_space (&error
);
269 value
= 10 * value
+ c
- '0';
278 token
= FMT_SIGNED_INT
;
297 c
= next_char_not_space (&error
);
300 value
= 10 * value
+ c
- '0';
308 token
= zflag
? FMT_ZERO
: FMT_POSINT
;
332 c
= next_char_not_space (&error
);
360 c
= next_char_not_space (&error
);
361 if (c
!= 'P' && c
!= 'S')
368 c
= next_char_not_space (&error
);
369 if (c
== 'N' || c
== 'Z')
387 c
= next_char (INSTRING_WARN
);
396 c
= next_char (NONSTRING
);
430 c
= next_char_not_space (&error
);
460 c
= next_char_not_space (&error
);
463 if (!gfc_notify_std (GFC_STD_F2003
, "DP format "
464 "specifier not allowed at %C"))
470 if (!gfc_notify_std (GFC_STD_F2003
, "DC format "
471 "specifier not allowed at %C"))
477 if (!gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: DT format "
478 "specifier not allowed at %C"))
481 c
= next_char_not_space (&error
);
482 if (c
== '\'' || c
== '"')
489 c
= next_char (INSTRING_WARN
);
498 c
= next_char (NONSTRING
);
521 c
= next_char_not_space (&error
);
570 token_to_string (format_token t
)
589 /* Check a format statement. The format string, either from a FORMAT
590 statement or a constant in an I/O statement has already been parsed
591 by itself, and we are checking it for validity. The dual origin
592 means that the warning message is a little less than great. */
595 check_format (bool is_input
)
597 const char *posint_required
= _("Positive width required");
598 const char *nonneg_required
= _("Nonnegative width required");
599 const char *unexpected_element
= _("Unexpected element %qc in format "
601 const char *unexpected_end
= _("Unexpected end of format string");
602 const char *zero_width
= _("Zero width in format descriptor");
604 const char *error
= NULL
;
611 saved_token
= FMT_NONE
;
615 format_string_pos
= 0;
622 error
= _("Missing leading left parenthesis");
630 goto finished
; /* Empty format is legal */
634 /* In this state, the next thing has to be a format item. */
651 error
= _("Left parenthesis required after %<*%>");
676 /* Signed integer can only precede a P format. */
682 error
= _("Expected P edit descriptor");
689 /* P requires a prior number. */
690 error
= _("P descriptor requires leading scale factor");
694 /* X requires a prior number if we're being pedantic. */
695 if (mode
!= MODE_FORMAT
)
696 format_locus
.nextc
+= format_string_pos
;
697 if (!gfc_notify_std (GFC_STD_GNU
, "X descriptor requires leading "
698 "space count at %L", &format_locus
))
726 error
= posint_required
;
738 error
= _("Right parenthesis expected at %C");
744 error
= unexpected_element
;
763 goto extension_optional_comma
;
774 if (!gfc_notify_std (GFC_STD_GNU
, "$ descriptor at %L", &format_locus
))
776 if (t
!= FMT_RPAREN
|| level
> 0)
778 gfc_warning (0, "$ should be the last specifier in format at %L",
780 goto optional_comma_1
;
801 error
= unexpected_end
;
805 error
= unexpected_element
;
810 /* In this state, t must currently be a data descriptor.
811 Deal with things that can/must follow the descriptor. */
822 /* No comma after P allowed only for F, E, EN, ES, D, or G.
827 if (!(gfc_option
.allow_std
& GFC_STD_F2003
) && t
!= FMT_COMMA
828 && t
!= FMT_F
&& t
!= FMT_E
&& t
!= FMT_EN
&& t
!= FMT_ES
829 && t
!= FMT_D
&& t
!= FMT_G
&& t
!= FMT_RPAREN
&& t
!= FMT_SLASH
)
831 error
= _("Comma required after P descriptor");
842 if (t
!= FMT_F
&& t
!= FMT_E
&& t
!= FMT_EN
&& t
!= FMT_ES
&& t
!= FMT_D
843 && t
!= FMT_G
&& t
!= FMT_RPAREN
&& t
!= FMT_SLASH
)
845 error
= _("Comma required after P descriptor");
859 error
= _("Positive width required with T descriptor");
870 if (mode
!= MODE_FORMAT
)
871 format_locus
.nextc
+= format_string_pos
;
874 switch (gfc_notification_std (GFC_STD_GNU
))
877 gfc_warning (0, "Extension: Zero width after L "
878 "descriptor at %L", &format_locus
);
881 gfc_error ("Extension: Zero width after L "
882 "descriptor at %L", &format_locus
);
893 gfc_notify_std (GFC_STD_GNU
, "Missing positive width after "
894 "L descriptor at %L", &format_locus
);
917 if (t
== FMT_G
&& u
== FMT_ZERO
)
924 if (!gfc_notify_std (GFC_STD_F2008
, "%<G0%> in format at %L",
936 error
= posint_required
;
942 error
= _("E specifier not allowed with g0 descriptor");
951 format_locus
.nextc
+= format_string_pos
;
952 gfc_error ("Positive width required in format "
953 "specifier %s at %L", token_to_string (t
),
964 /* Warn if -std=legacy, otherwise error. */
965 format_locus
.nextc
+= format_string_pos
;
966 if (gfc_option
.warn_std
!= 0)
968 gfc_error ("Period required in format "
969 "specifier %s at %L", token_to_string (t
),
975 gfc_warning (0, "Period required in format "
976 "specifier %s at %L", token_to_string (t
),
978 /* If we go to finished, we need to unwind this
979 before the next round. */
980 format_locus
.nextc
-= format_string_pos
;
988 if (u
!= FMT_ZERO
&& u
!= FMT_POSINT
)
990 error
= nonneg_required
;
997 /* Look for optional exponent. */
1010 if (u
!= FMT_POSINT
)
1012 error
= _("Positive exponent width required");
1023 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1025 error
= nonneg_required
;
1028 else if (is_input
&& t
== FMT_ZERO
)
1030 error
= posint_required
;
1037 if (t
!= FMT_PERIOD
)
1039 /* Warn if -std=legacy, otherwise error. */
1040 if (gfc_option
.warn_std
!= 0)
1042 error
= _("Period required in format specifier");
1045 if (mode
!= MODE_FORMAT
)
1046 format_locus
.nextc
+= format_string_pos
;
1047 gfc_warning (0, "Period required in format specifier at %L",
1056 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1058 error
= nonneg_required
;
1065 if (!(gfc_option
.allow_std
& GFC_STD_GNU
) && !inhibit_warnings
)
1067 if (mode
!= MODE_FORMAT
)
1068 format_locus
.nextc
+= format_string_pos
;
1069 gfc_warning (0, "The H format specifier at %L is"
1070 " a Fortran 95 deleted feature", &format_locus
);
1072 if (mode
== MODE_STRING
)
1074 format_string
+= value
;
1075 format_length
-= value
;
1076 format_string_pos
+= repeat
;
1082 next_char (INSTRING_WARN
);
1092 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1094 error
= nonneg_required
;
1097 else if (is_input
&& t
== FMT_ZERO
)
1099 error
= posint_required
;
1106 if (t
!= FMT_PERIOD
)
1115 if (t
!= FMT_ZERO
&& t
!= FMT_POSINT
)
1117 error
= nonneg_required
;
1125 error
= unexpected_element
;
1130 /* Between a descriptor and what comes next. */
1148 goto optional_comma
;
1151 error
= unexpected_end
;
1155 if (mode
!= MODE_FORMAT
)
1156 format_locus
.nextc
+= format_string_pos
- 1;
1157 if (!gfc_notify_std (GFC_STD_GNU
, "Missing comma at %L", &format_locus
))
1159 /* If we do not actually return a failure, we need to unwind this
1160 before the next round. */
1161 if (mode
!= MODE_FORMAT
)
1162 format_locus
.nextc
-= format_string_pos
;
1167 /* Optional comma is a weird between state where we've just finished
1168 reading a colon, slash, dollar or P descriptor. */
1185 /* Assume that we have another format item. */
1192 extension_optional_comma
:
1193 /* As a GNU extension, permit a missing comma after a string literal. */
1210 goto optional_comma
;
1213 error
= unexpected_end
;
1217 if (mode
!= MODE_FORMAT
)
1218 format_locus
.nextc
+= format_string_pos
;
1219 if (!gfc_notify_std (GFC_STD_GNU
, "Missing comma at %L", &format_locus
))
1221 /* If we do not actually return a failure, we need to unwind this
1222 before the next round. */
1223 if (mode
!= MODE_FORMAT
)
1224 format_locus
.nextc
-= format_string_pos
;
1232 if (mode
!= MODE_FORMAT
)
1233 format_locus
.nextc
+= format_string_pos
;
1234 if (error
== unexpected_element
)
1235 gfc_error (error
, error_element
, &format_locus
);
1237 gfc_error ("%s in format string at %L", error
, &format_locus
);
1246 /* Given an expression node that is a constant string, see if it looks
1247 like a format string. */
1250 check_format_string (gfc_expr
*e
, bool is_input
)
1254 if (!e
|| e
->ts
.type
!= BT_CHARACTER
|| e
->expr_type
!= EXPR_CONSTANT
)
1258 format_string
= e
->value
.character
.string
;
1260 /* More elaborate measures are needed to show where a problem is within a
1261 format string that has been calculated, but that's probably not worth the
1263 format_locus
= e
->where
;
1264 rv
= check_format (is_input
);
1265 /* check for extraneous characters at the end of an otherwise valid format
1266 string, like '(A10,I3)F5'
1267 start at the end and move back to the last character processed,
1269 if (rv
&& e
->value
.character
.length
> format_string_pos
)
1270 for (i
=e
->value
.character
.length
-1;i
>format_string_pos
-1;i
--)
1271 if (e
->value
.character
.string
[i
] != ' ')
1273 format_locus
.nextc
+= format_length
+ 1;
1275 "Extraneous characters in format at %L", &format_locus
);
1282 /************ Fortran I/O statement matchers *************/
1284 /* Match a FORMAT statement. This amounts to actually parsing the
1285 format descriptors in order to correctly locate the end of the
1289 gfc_match_format (void)
1294 if (gfc_current_ns
->proc_name
1295 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
1297 gfc_error ("Format statement in module main block at %C");
1301 /* Before parsing the rest of a FORMAT statement, check F2008:c1206. */
1302 if ((gfc_current_state () == COMP_FUNCTION
1303 || gfc_current_state () == COMP_SUBROUTINE
)
1304 && gfc_state_stack
->previous
->state
== COMP_INTERFACE
)
1306 gfc_error ("FORMAT statement at %C cannot appear within an INTERFACE");
1310 if (gfc_statement_label
== NULL
)
1312 gfc_error ("Missing format label at %C");
1315 gfc_gobble_whitespace ();
1320 start
= gfc_current_locus
;
1322 if (!check_format (false))
1325 if (gfc_match_eos () != MATCH_YES
)
1327 gfc_syntax_error (ST_FORMAT
);
1331 /* The label doesn't get created until after the statement is done
1332 being matched, so we have to leave the string for later. */
1334 gfc_current_locus
= start
; /* Back to the beginning */
1337 new_st
.op
= EXEC_NOP
;
1339 e
= gfc_get_character_expr (gfc_default_character_kind
, &start
,
1340 NULL
, format_length
);
1341 format_string
= e
->value
.character
.string
;
1342 gfc_statement_label
->format
= e
;
1345 check_format (false); /* Guaranteed to succeed */
1346 gfc_match_eos (); /* Guaranteed to succeed */
1352 /* Check for a CHARACTER variable. The check for scalar is done in
1356 check_char_variable (gfc_expr
*e
)
1358 if (e
->expr_type
!= EXPR_VARIABLE
|| e
->ts
.type
!= BT_CHARACTER
)
1360 gfc_error("IOMSG must be a scalar-default-char-variable at %L", &e
->where
);
1368 is_char_type (const char *name
, gfc_expr
*e
)
1370 gfc_resolve_expr (e
);
1372 if (e
->ts
.type
!= BT_CHARACTER
)
1374 gfc_error ("%s requires a scalar-default-char-expr at %L",
1382 /* Match an expression I/O tag of some sort. */
1385 match_etag (const io_tag
*tag
, gfc_expr
**v
)
1390 m
= gfc_match (tag
->spec
);
1394 m
= gfc_match (tag
->value
, &result
);
1397 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1403 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1404 gfc_free_expr (result
);
1413 /* Match a variable I/O tag of some sort. */
1416 match_vtag (const io_tag
*tag
, gfc_expr
**v
)
1421 m
= gfc_match (tag
->spec
);
1425 m
= gfc_match (tag
->value
, &result
);
1428 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1434 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1435 gfc_free_expr (result
);
1439 if (result
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
1441 gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag
->name
);
1442 gfc_free_expr (result
);
1446 bool impure
= gfc_impure_variable (result
->symtree
->n
.sym
);
1447 if (impure
&& gfc_pure (NULL
))
1449 gfc_error ("Variable %s cannot be assigned in PURE procedure at %C",
1451 gfc_free_expr (result
);
1456 gfc_unset_implicit_pure (NULL
);
1463 /* Match I/O tags that cause variables to become redefined. */
1466 match_out_tag (const io_tag
*tag
, gfc_expr
**result
)
1470 m
= match_vtag (tag
, result
);
1472 gfc_check_do_variable ((*result
)->symtree
);
1478 /* Match a label I/O tag. */
1481 match_ltag (const io_tag
*tag
, gfc_st_label
** label
)
1487 m
= gfc_match (tag
->spec
);
1491 m
= gfc_match (tag
->value
, label
);
1494 gfc_error ("Invalid value for %s specification at %C", tag
->name
);
1500 gfc_error ("Duplicate %s label specification at %C", tag
->name
);
1504 if (!gfc_reference_st_label (*label
, ST_LABEL_TARGET
))
1511 /* Match a tag using match_etag, but only if -fdec is enabled. */
1513 match_dec_etag (const io_tag
*tag
, gfc_expr
**e
)
1515 match m
= match_etag (tag
, e
);
1516 if (flag_dec
&& m
!= MATCH_NO
)
1518 else if (m
!= MATCH_NO
)
1520 gfc_error ("%s is a DEC extension at %C, re-compile with "
1521 "-fdec to enable", tag
->name
);
1528 /* Match a tag using match_vtag, but only if -fdec is enabled. */
1530 match_dec_vtag (const io_tag
*tag
, gfc_expr
**e
)
1532 match m
= match_vtag(tag
, e
);
1533 if (flag_dec
&& m
!= MATCH_NO
)
1535 else if (m
!= MATCH_NO
)
1537 gfc_error ("%s is a DEC extension at %C, re-compile with "
1538 "-fdec to enable", tag
->name
);
1545 /* Match a DEC I/O flag tag - a tag with no expression such as READONLY. */
1548 match_dec_ftag (const io_tag
*tag
, gfc_open
*o
)
1552 m
= gfc_match (tag
->spec
);
1558 gfc_error ("%s is a DEC extension at %C, re-compile with "
1559 "-fdec to enable", tag
->name
);
1563 /* Just set the READONLY flag, which we use at runtime to avoid delete on
1565 if (tag
== &tag_readonly
)
1571 /* Interpret SHARED as SHARE='DENYNONE' (read lock). */
1572 else if (tag
== &tag_shared
)
1574 if (o
->share
!= NULL
)
1576 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1579 o
->share
= gfc_get_character_expr (gfc_default_character_kind
,
1580 &gfc_current_locus
, "denynone", 8);
1584 /* Interpret NOSHARED as SHARE='DENYRW' (exclusive lock). */
1585 else if (tag
== &tag_noshared
)
1587 if (o
->share
!= NULL
)
1589 gfc_error ("Duplicate %s specification at %C", tag
->name
);
1592 o
->share
= gfc_get_character_expr (gfc_default_character_kind
,
1593 &gfc_current_locus
, "denyrw", 6);
1597 /* We handle all DEC tags above. */
1602 /* Resolution of the FORMAT tag, to be called from resolve_tag. */
1605 resolve_tag_format (const gfc_expr
*e
)
1607 if (e
->expr_type
== EXPR_CONSTANT
1608 && (e
->ts
.type
!= BT_CHARACTER
1609 || e
->ts
.kind
!= gfc_default_character_kind
))
1611 gfc_error ("Constant expression in FORMAT tag at %L must be "
1612 "of type default CHARACTER", &e
->where
);
1616 /* If e's rank is zero and e is not an element of an array, it should be
1617 of integer or character type. The integer variable should be
1620 && (e
->expr_type
!= EXPR_VARIABLE
1621 || e
->symtree
== NULL
1622 || e
->symtree
->n
.sym
->as
== NULL
1623 || e
->symtree
->n
.sym
->as
->rank
== 0))
1625 if ((e
->ts
.type
!= BT_CHARACTER
1626 || e
->ts
.kind
!= gfc_default_character_kind
)
1627 && e
->ts
.type
!= BT_INTEGER
)
1629 gfc_error ("FORMAT tag at %L must be of type default-kind CHARACTER "
1630 "or of INTEGER", &e
->where
);
1633 else if (e
->ts
.type
== BT_INTEGER
&& e
->expr_type
== EXPR_VARIABLE
)
1635 if (!gfc_notify_std (GFC_STD_F95_DEL
, "ASSIGNED variable in "
1636 "FORMAT tag at %L", &e
->where
))
1638 if (e
->symtree
->n
.sym
->attr
.assign
!= 1)
1640 gfc_error ("Variable %qs at %L has not been assigned a "
1641 "format label", e
->symtree
->n
.sym
->name
, &e
->where
);
1645 else if (e
->ts
.type
== BT_INTEGER
)
1647 gfc_error ("Scalar %qs in FORMAT tag at %L is not an ASSIGNED "
1648 "variable", gfc_basic_typename (e
->ts
.type
), &e
->where
);
1655 /* If rank is nonzero and type is not character, we allow it under GFC_STD_LEGACY.
1656 It may be assigned an Hollerith constant. */
1657 if (e
->ts
.type
!= BT_CHARACTER
)
1659 if (!gfc_notify_std (GFC_STD_LEGACY
, "Non-character in FORMAT tag "
1660 "at %L", &e
->where
))
1663 if (e
->rank
== 0 && e
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SHAPE
)
1665 gfc_error ("Non-character assumed shape array element in FORMAT"
1666 " tag at %L", &e
->where
);
1670 if (e
->rank
== 0 && e
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
)
1672 gfc_error ("Non-character assumed size array element in FORMAT"
1673 " tag at %L", &e
->where
);
1677 if (e
->rank
== 0 && e
->symtree
->n
.sym
->attr
.pointer
)
1679 gfc_error ("Non-character pointer array element in FORMAT tag at %L",
1689 /* Do expression resolution and type-checking on an expression tag. */
1692 resolve_tag (const io_tag
*tag
, gfc_expr
*e
)
1697 if (!gfc_resolve_expr (e
))
1700 if (tag
== &tag_format
)
1701 return resolve_tag_format (e
);
1703 if (e
->ts
.type
!= tag
->type
)
1705 gfc_error ("%s tag at %L must be of type %s", tag
->name
,
1706 &e
->where
, gfc_basic_typename (tag
->type
));
1710 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= gfc_default_character_kind
)
1712 gfc_error ("%s tag at %L must be a character string of default kind",
1713 tag
->name
, &e
->where
);
1719 gfc_error ("%s tag at %L must be scalar", tag
->name
, &e
->where
);
1723 if (tag
== &tag_iomsg
)
1725 if (!gfc_notify_std (GFC_STD_F2003
, "IOMSG tag at %L", &e
->where
))
1729 if ((tag
== &tag_iostat
|| tag
== &tag_size
|| tag
== &tag_iolength
1730 || tag
== &tag_number
|| tag
== &tag_nextrec
|| tag
== &tag_s_recl
)
1731 && e
->ts
.kind
!= gfc_default_integer_kind
)
1733 if (!gfc_notify_std (GFC_STD_F2003
, "Fortran 95 requires default "
1734 "INTEGER in %s tag at %L", tag
->name
, &e
->where
))
1738 if (e
->ts
.kind
!= gfc_default_logical_kind
&&
1739 (tag
== &tag_exist
|| tag
== &tag_named
|| tag
== &tag_opened
1740 || tag
== &tag_pending
))
1742 if (!gfc_notify_std (GFC_STD_F2008
, "Non-default LOGICAL kind "
1743 "in %s tag at %L", tag
->name
, &e
->where
))
1747 if (tag
== &tag_newunit
)
1749 if (!gfc_notify_std (GFC_STD_F2008
, "NEWUNIT specifier at %L",
1754 /* NEWUNIT, IOSTAT, SIZE and IOMSG are variable definition contexts. */
1755 if (tag
== &tag_newunit
|| tag
== &tag_iostat
1756 || tag
== &tag_size
|| tag
== &tag_iomsg
)
1760 sprintf (context
, _("%s tag"), tag
->name
);
1761 if (!gfc_check_vardef_context (e
, false, false, false, context
))
1765 if (tag
== &tag_convert
)
1767 if (!gfc_notify_std (GFC_STD_GNU
, "CONVERT tag at %L", &e
->where
))
1775 /* Match a single tag of an OPEN statement. */
1778 match_open_element (gfc_open
*open
)
1782 m
= match_etag (&tag_e_async
, &open
->asynchronous
);
1783 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", open
->asynchronous
))
1787 m
= match_etag (&tag_unit
, &open
->unit
);
1790 m
= match_etag (&tag_iomsg
, &open
->iomsg
);
1791 if (m
== MATCH_YES
&& !check_char_variable (open
->iomsg
))
1795 m
= match_out_tag (&tag_iostat
, &open
->iostat
);
1798 m
= match_etag (&tag_file
, &open
->file
);
1801 m
= match_etag (&tag_status
, &open
->status
);
1804 m
= match_etag (&tag_e_access
, &open
->access
);
1807 m
= match_etag (&tag_e_form
, &open
->form
);
1810 m
= match_etag (&tag_e_recl
, &open
->recl
);
1813 m
= match_etag (&tag_e_blank
, &open
->blank
);
1816 m
= match_etag (&tag_e_position
, &open
->position
);
1819 m
= match_etag (&tag_e_action
, &open
->action
);
1822 m
= match_etag (&tag_e_delim
, &open
->delim
);
1825 m
= match_etag (&tag_e_pad
, &open
->pad
);
1828 m
= match_etag (&tag_e_decimal
, &open
->decimal
);
1831 m
= match_etag (&tag_e_encoding
, &open
->encoding
);
1834 m
= match_etag (&tag_e_round
, &open
->round
);
1837 m
= match_etag (&tag_e_sign
, &open
->sign
);
1840 m
= match_ltag (&tag_err
, &open
->err
);
1843 m
= match_etag (&tag_convert
, &open
->convert
);
1846 m
= match_out_tag (&tag_newunit
, &open
->newunit
);
1850 /* The following are extensions enabled with -fdec. */
1851 m
= match_dec_etag (&tag_e_share
, &open
->share
);
1854 m
= match_dec_etag (&tag_cc
, &open
->cc
);
1857 m
= match_dec_ftag (&tag_readonly
, open
);
1860 m
= match_dec_ftag (&tag_shared
, open
);
1863 m
= match_dec_ftag (&tag_noshared
, open
);
1871 /* Free the gfc_open structure and all the expressions it contains. */
1874 gfc_free_open (gfc_open
*open
)
1879 gfc_free_expr (open
->unit
);
1880 gfc_free_expr (open
->iomsg
);
1881 gfc_free_expr (open
->iostat
);
1882 gfc_free_expr (open
->file
);
1883 gfc_free_expr (open
->status
);
1884 gfc_free_expr (open
->access
);
1885 gfc_free_expr (open
->form
);
1886 gfc_free_expr (open
->recl
);
1887 gfc_free_expr (open
->blank
);
1888 gfc_free_expr (open
->position
);
1889 gfc_free_expr (open
->action
);
1890 gfc_free_expr (open
->delim
);
1891 gfc_free_expr (open
->pad
);
1892 gfc_free_expr (open
->decimal
);
1893 gfc_free_expr (open
->encoding
);
1894 gfc_free_expr (open
->round
);
1895 gfc_free_expr (open
->sign
);
1896 gfc_free_expr (open
->convert
);
1897 gfc_free_expr (open
->asynchronous
);
1898 gfc_free_expr (open
->newunit
);
1899 gfc_free_expr (open
->share
);
1900 gfc_free_expr (open
->cc
);
1905 /* Resolve everything in a gfc_open structure. */
1908 gfc_resolve_open (gfc_open
*open
)
1911 RESOLVE_TAG (&tag_unit
, open
->unit
);
1912 RESOLVE_TAG (&tag_iomsg
, open
->iomsg
);
1913 RESOLVE_TAG (&tag_iostat
, open
->iostat
);
1914 RESOLVE_TAG (&tag_file
, open
->file
);
1915 RESOLVE_TAG (&tag_status
, open
->status
);
1916 RESOLVE_TAG (&tag_e_access
, open
->access
);
1917 RESOLVE_TAG (&tag_e_form
, open
->form
);
1918 RESOLVE_TAG (&tag_e_recl
, open
->recl
);
1919 RESOLVE_TAG (&tag_e_blank
, open
->blank
);
1920 RESOLVE_TAG (&tag_e_position
, open
->position
);
1921 RESOLVE_TAG (&tag_e_action
, open
->action
);
1922 RESOLVE_TAG (&tag_e_delim
, open
->delim
);
1923 RESOLVE_TAG (&tag_e_pad
, open
->pad
);
1924 RESOLVE_TAG (&tag_e_decimal
, open
->decimal
);
1925 RESOLVE_TAG (&tag_e_encoding
, open
->encoding
);
1926 RESOLVE_TAG (&tag_e_async
, open
->asynchronous
);
1927 RESOLVE_TAG (&tag_e_round
, open
->round
);
1928 RESOLVE_TAG (&tag_e_sign
, open
->sign
);
1929 RESOLVE_TAG (&tag_convert
, open
->convert
);
1930 RESOLVE_TAG (&tag_newunit
, open
->newunit
);
1931 RESOLVE_TAG (&tag_e_share
, open
->share
);
1932 RESOLVE_TAG (&tag_cc
, open
->cc
);
1934 if (!gfc_reference_st_label (open
->err
, ST_LABEL_TARGET
))
1941 /* Check if a given value for a SPECIFIER is either in the list of values
1942 allowed in F95 or F2003, issuing an error message and returning a zero
1943 value if it is not allowed. */
1946 compare_to_allowed_values (const char *specifier
, const char *allowed
[],
1947 const char *allowed_f2003
[],
1948 const char *allowed_gnu
[], gfc_char_t
*value
,
1949 const char *statement
, bool warn
)
1954 len
= gfc_wide_strlen (value
);
1957 for (len
--; len
> 0; len
--)
1958 if (value
[len
] != ' ')
1963 for (i
= 0; allowed
[i
]; i
++)
1964 if (len
== strlen (allowed
[i
])
1965 && gfc_wide_strncasecmp (value
, allowed
[i
], strlen (allowed
[i
])) == 0)
1968 for (i
= 0; allowed_f2003
&& allowed_f2003
[i
]; i
++)
1969 if (len
== strlen (allowed_f2003
[i
])
1970 && gfc_wide_strncasecmp (value
, allowed_f2003
[i
],
1971 strlen (allowed_f2003
[i
])) == 0)
1973 notification n
= gfc_notification_std (GFC_STD_F2003
);
1975 if (n
== WARNING
|| (warn
&& n
== ERROR
))
1977 gfc_warning (0, "Fortran 2003: %s specifier in %s statement at %C "
1978 "has value %qs", specifier
, statement
,
1985 gfc_notify_std (GFC_STD_F2003
, "%s specifier in "
1986 "%s statement at %C has value %qs", specifier
,
1987 statement
, allowed_f2003
[i
]);
1995 for (i
= 0; allowed_gnu
&& allowed_gnu
[i
]; i
++)
1996 if (len
== strlen (allowed_gnu
[i
])
1997 && gfc_wide_strncasecmp (value
, allowed_gnu
[i
],
1998 strlen (allowed_gnu
[i
])) == 0)
2000 notification n
= gfc_notification_std (GFC_STD_GNU
);
2002 if (n
== WARNING
|| (warn
&& n
== ERROR
))
2004 gfc_warning (0, "Extension: %s specifier in %s statement at %C "
2005 "has value %qs", specifier
, statement
,
2012 gfc_notify_std (GFC_STD_GNU
, "%s specifier in "
2013 "%s statement at %C has value %qs", specifier
,
2014 statement
, allowed_gnu
[i
]);
2024 char *s
= gfc_widechar_to_char (value
, -1);
2026 "%s specifier in %s statement at %C has invalid value %qs",
2027 specifier
, statement
, s
);
2033 char *s
= gfc_widechar_to_char (value
, -1);
2034 gfc_error ("%s specifier in %s statement at %C has invalid value %qs",
2035 specifier
, statement
, s
);
2042 /* Match an OPEN statement. */
2045 gfc_match_open (void)
2051 m
= gfc_match_char ('(');
2055 open
= XCNEW (gfc_open
);
2057 m
= match_open_element (open
);
2059 if (m
== MATCH_ERROR
)
2063 m
= gfc_match_expr (&open
->unit
);
2064 if (m
== MATCH_ERROR
)
2070 if (gfc_match_char (')') == MATCH_YES
)
2072 if (gfc_match_char (',') != MATCH_YES
)
2075 m
= match_open_element (open
);
2076 if (m
== MATCH_ERROR
)
2082 if (gfc_match_eos () == MATCH_NO
)
2085 if (gfc_pure (NULL
))
2087 gfc_error ("OPEN statement not allowed in PURE procedure at %C");
2091 gfc_unset_implicit_pure (NULL
);
2093 warn
= (open
->err
|| open
->iostat
) ? true : false;
2095 /* Checks on NEWUNIT specifier. */
2100 gfc_error ("UNIT specifier not allowed with NEWUNIT at %C");
2104 if (!open
->file
&& open
->status
)
2106 if (open
->status
->expr_type
== EXPR_CONSTANT
2107 && gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2110 gfc_error ("NEWUNIT specifier must have FILE= "
2111 "or STATUS='scratch' at %C");
2116 else if (!open
->unit
)
2118 gfc_error ("OPEN statement at %C must have UNIT or NEWUNIT specified");
2122 /* Checks on the ACCESS specifier. */
2123 if (open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
)
2125 static const char *access_f95
[] = { "SEQUENTIAL", "DIRECT", NULL
};
2126 static const char *access_f2003
[] = { "STREAM", NULL
};
2127 static const char *access_gnu
[] = { "APPEND", NULL
};
2129 if (!is_char_type ("ACCESS", open
->access
))
2132 if (!compare_to_allowed_values ("ACCESS", access_f95
, access_f2003
,
2134 open
->access
->value
.character
.string
,
2139 /* Checks on the ACTION specifier. */
2140 if (open
->action
&& open
->action
->expr_type
== EXPR_CONSTANT
)
2142 gfc_char_t
*str
= open
->action
->value
.character
.string
;
2143 static const char *action
[] = { "READ", "WRITE", "READWRITE", NULL
};
2145 if (!is_char_type ("ACTION", open
->action
))
2148 if (!compare_to_allowed_values ("ACTION", action
, NULL
, NULL
,
2152 /* With READONLY, only allow ACTION='READ'. */
2153 if (open
->readonly
&& (gfc_wide_strlen (str
) != 4
2154 || gfc_wide_strncasecmp (str
, "READ", 4) != 0))
2156 gfc_error ("ACTION type conflicts with READONLY specifier at %C");
2160 /* If we see READONLY and no ACTION, set ACTION='READ'. */
2161 else if (open
->readonly
&& open
->action
== NULL
)
2163 open
->action
= gfc_get_character_expr (gfc_default_character_kind
,
2164 &gfc_current_locus
, "read", 4);
2167 /* Checks on the ASYNCHRONOUS specifier. */
2168 if (open
->asynchronous
)
2170 if (!gfc_notify_std (GFC_STD_F2003
, "ASYNCHRONOUS= at %C "
2171 "not allowed in Fortran 95"))
2174 if (!is_char_type ("ASYNCHRONOUS", open
->asynchronous
))
2177 if (open
->asynchronous
->expr_type
== EXPR_CONSTANT
)
2179 static const char * asynchronous
[] = { "YES", "NO", NULL
};
2181 if (!compare_to_allowed_values ("ASYNCHRONOUS", asynchronous
,
2182 NULL
, NULL
, open
->asynchronous
->value
.character
.string
,
2188 /* Checks on the BLANK specifier. */
2191 if (!gfc_notify_std (GFC_STD_F2003
, "BLANK= at %C "
2192 "not allowed in Fortran 95"))
2195 if (!is_char_type ("BLANK", open
->blank
))
2198 if (open
->blank
->expr_type
== EXPR_CONSTANT
)
2200 static const char *blank
[] = { "ZERO", "NULL", NULL
};
2202 if (!compare_to_allowed_values ("BLANK", blank
, NULL
, NULL
,
2203 open
->blank
->value
.character
.string
,
2209 /* Checks on the CARRIAGECONTROL specifier. */
2212 if (!is_char_type ("CARRIAGECONTROL", open
->cc
))
2215 if (open
->cc
->expr_type
== EXPR_CONSTANT
)
2217 static const char *cc
[] = { "LIST", "FORTRAN", "NONE", NULL
};
2218 if (!compare_to_allowed_values ("CARRIAGECONTROL", cc
, NULL
, NULL
,
2219 open
->cc
->value
.character
.string
,
2225 /* Checks on the DECIMAL specifier. */
2228 if (!gfc_notify_std (GFC_STD_F2003
, "DECIMAL= at %C "
2229 "not allowed in Fortran 95"))
2232 if (!is_char_type ("DECIMAL", open
->decimal
))
2235 if (open
->decimal
->expr_type
== EXPR_CONSTANT
)
2237 static const char * decimal
[] = { "COMMA", "POINT", NULL
};
2239 if (!compare_to_allowed_values ("DECIMAL", decimal
, NULL
, NULL
,
2240 open
->decimal
->value
.character
.string
,
2246 /* Checks on the DELIM specifier. */
2249 if (open
->delim
->expr_type
== EXPR_CONSTANT
)
2251 static const char *delim
[] = { "APOSTROPHE", "QUOTE", "NONE", NULL
};
2253 if (!is_char_type ("DELIM", open
->delim
))
2256 if (!compare_to_allowed_values ("DELIM", delim
, NULL
, NULL
,
2257 open
->delim
->value
.character
.string
,
2263 /* Checks on the ENCODING specifier. */
2266 if (!gfc_notify_std (GFC_STD_F2003
, "ENCODING= at %C "
2267 "not allowed in Fortran 95"))
2270 if (!is_char_type ("ENCODING", open
->encoding
))
2273 if (open
->encoding
->expr_type
== EXPR_CONSTANT
)
2275 static const char * encoding
[] = { "DEFAULT", "UTF-8", NULL
};
2277 if (!compare_to_allowed_values ("ENCODING", encoding
, NULL
, NULL
,
2278 open
->encoding
->value
.character
.string
,
2284 /* Checks on the FORM specifier. */
2285 if (open
->form
&& open
->form
->expr_type
== EXPR_CONSTANT
)
2287 static const char *form
[] = { "FORMATTED", "UNFORMATTED", NULL
};
2289 if (!is_char_type ("FORM", open
->form
))
2292 if (!compare_to_allowed_values ("FORM", form
, NULL
, NULL
,
2293 open
->form
->value
.character
.string
,
2298 /* Checks on the PAD specifier. */
2299 if (open
->pad
&& open
->pad
->expr_type
== EXPR_CONSTANT
)
2301 static const char *pad
[] = { "YES", "NO", NULL
};
2303 if (!is_char_type ("PAD", open
->pad
))
2306 if (!compare_to_allowed_values ("PAD", pad
, NULL
, NULL
,
2307 open
->pad
->value
.character
.string
,
2312 /* Checks on the POSITION specifier. */
2313 if (open
->position
&& open
->position
->expr_type
== EXPR_CONSTANT
)
2315 static const char *position
[] = { "ASIS", "REWIND", "APPEND", NULL
};
2317 if (!is_char_type ("POSITION", open
->position
))
2320 if (!compare_to_allowed_values ("POSITION", position
, NULL
, NULL
,
2321 open
->position
->value
.character
.string
,
2326 /* Checks on the ROUND specifier. */
2329 if (!gfc_notify_std (GFC_STD_F2003
, "ROUND= at %C "
2330 "not allowed in Fortran 95"))
2333 if (!is_char_type ("ROUND", open
->round
))
2336 if (open
->round
->expr_type
== EXPR_CONSTANT
)
2338 static const char * round
[] = { "UP", "DOWN", "ZERO", "NEAREST",
2339 "COMPATIBLE", "PROCESSOR_DEFINED",
2342 if (!compare_to_allowed_values ("ROUND", round
, NULL
, NULL
,
2343 open
->round
->value
.character
.string
,
2349 /* Checks on the SHARE specifier. */
2352 if (!is_char_type ("SHARE", open
->share
))
2355 if (open
->share
->expr_type
== EXPR_CONSTANT
)
2357 static const char *share
[] = { "DENYNONE", "DENYRW", NULL
};
2358 if (!compare_to_allowed_values ("SHARE", share
, NULL
, NULL
,
2359 open
->share
->value
.character
.string
,
2365 /* Checks on the SIGN specifier. */
2368 if (!gfc_notify_std (GFC_STD_F2003
, "SIGN= at %C "
2369 "not allowed in Fortran 95"))
2372 if (!is_char_type ("SIGN", open
->sign
))
2375 if (open
->sign
->expr_type
== EXPR_CONSTANT
)
2377 static const char * sign
[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
2380 if (!compare_to_allowed_values ("SIGN", sign
, NULL
, NULL
,
2381 open
->sign
->value
.character
.string
,
2387 #define warn_or_error(...) \
2390 gfc_warning (0, __VA_ARGS__); \
2393 gfc_error (__VA_ARGS__); \
2398 /* Checks on the RECL specifier. */
2399 if (open
->recl
&& open
->recl
->expr_type
== EXPR_CONSTANT
2400 && open
->recl
->ts
.type
== BT_INTEGER
2401 && mpz_sgn (open
->recl
->value
.integer
) != 1)
2403 warn_or_error ("RECL in OPEN statement at %C must be positive");
2406 /* Checks on the STATUS specifier. */
2407 if (open
->status
&& open
->status
->expr_type
== EXPR_CONSTANT
)
2409 static const char *status
[] = { "OLD", "NEW", "SCRATCH",
2410 "REPLACE", "UNKNOWN", NULL
};
2412 if (!is_char_type ("STATUS", open
->status
))
2415 if (!compare_to_allowed_values ("STATUS", status
, NULL
, NULL
,
2416 open
->status
->value
.character
.string
,
2420 /* F2003, 9.4.5: If the STATUS= specifier has the value NEW or REPLACE,
2421 the FILE= specifier shall appear. */
2422 if (open
->file
== NULL
2423 && (gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2425 || gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2428 char *s
= gfc_widechar_to_char (open
->status
->value
.character
.string
,
2430 warn_or_error ("The STATUS specified in OPEN statement at %C is "
2431 "%qs and no FILE specifier is present", s
);
2435 /* F2003, 9.4.5: If the STATUS= specifier has the value SCRATCH,
2436 the FILE= specifier shall not appear. */
2437 if (gfc_wide_strncasecmp (open
->status
->value
.character
.string
,
2438 "scratch", 7) == 0 && open
->file
)
2440 warn_or_error ("The STATUS specified in OPEN statement at %C "
2441 "cannot have the value SCRATCH if a FILE specifier "
2446 /* Things that are not allowed for unformatted I/O. */
2447 if (open
->form
&& open
->form
->expr_type
== EXPR_CONSTANT
2448 && (open
->delim
|| open
->decimal
|| open
->encoding
|| open
->round
2449 || open
->sign
|| open
->pad
|| open
->blank
)
2450 && gfc_wide_strncasecmp (open
->form
->value
.character
.string
,
2451 "unformatted", 11) == 0)
2453 const char *spec
= (open
->delim
? "DELIM "
2454 : (open
->pad
? "PAD " : open
->blank
2457 warn_or_error ("%s specifier at %C not allowed in OPEN statement for "
2458 "unformatted I/O", spec
);
2461 if (open
->recl
&& open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
2462 && gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2465 warn_or_error ("RECL specifier not allowed in OPEN statement at %C for "
2470 && open
->access
&& open
->access
->expr_type
== EXPR_CONSTANT
2471 && !(gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2472 "sequential", 10) == 0
2473 || gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2475 || gfc_wide_strncasecmp (open
->access
->value
.character
.string
,
2478 warn_or_error ("POSITION specifier in OPEN statement at %C only allowed "
2479 "for stream or sequential ACCESS");
2482 #undef warn_or_error
2484 new_st
.op
= EXEC_OPEN
;
2485 new_st
.ext
.open
= open
;
2489 gfc_syntax_error (ST_OPEN
);
2492 gfc_free_open (open
);
2497 /* Free a gfc_close structure an all its expressions. */
2500 gfc_free_close (gfc_close
*close
)
2505 gfc_free_expr (close
->unit
);
2506 gfc_free_expr (close
->iomsg
);
2507 gfc_free_expr (close
->iostat
);
2508 gfc_free_expr (close
->status
);
2513 /* Match elements of a CLOSE statement. */
2516 match_close_element (gfc_close
*close
)
2520 m
= match_etag (&tag_unit
, &close
->unit
);
2523 m
= match_etag (&tag_status
, &close
->status
);
2526 m
= match_etag (&tag_iomsg
, &close
->iomsg
);
2527 if (m
== MATCH_YES
&& !check_char_variable (close
->iomsg
))
2531 m
= match_out_tag (&tag_iostat
, &close
->iostat
);
2534 m
= match_ltag (&tag_err
, &close
->err
);
2542 /* Match a CLOSE statement. */
2545 gfc_match_close (void)
2551 m
= gfc_match_char ('(');
2555 close
= XCNEW (gfc_close
);
2557 m
= match_close_element (close
);
2559 if (m
== MATCH_ERROR
)
2563 m
= gfc_match_expr (&close
->unit
);
2566 if (m
== MATCH_ERROR
)
2572 if (gfc_match_char (')') == MATCH_YES
)
2574 if (gfc_match_char (',') != MATCH_YES
)
2577 m
= match_close_element (close
);
2578 if (m
== MATCH_ERROR
)
2584 if (gfc_match_eos () == MATCH_NO
)
2587 if (gfc_pure (NULL
))
2589 gfc_error ("CLOSE statement not allowed in PURE procedure at %C");
2593 gfc_unset_implicit_pure (NULL
);
2595 warn
= (close
->iostat
|| close
->err
) ? true : false;
2597 /* Checks on the STATUS specifier. */
2598 if (close
->status
&& close
->status
->expr_type
== EXPR_CONSTANT
)
2600 static const char *status
[] = { "KEEP", "DELETE", NULL
};
2602 if (!is_char_type ("STATUS", close
->status
))
2605 if (!compare_to_allowed_values ("STATUS", status
, NULL
, NULL
,
2606 close
->status
->value
.character
.string
,
2611 new_st
.op
= EXEC_CLOSE
;
2612 new_st
.ext
.close
= close
;
2616 gfc_syntax_error (ST_CLOSE
);
2619 gfc_free_close (close
);
2624 /* Resolve everything in a gfc_close structure. */
2627 gfc_resolve_close (gfc_close
*close
)
2629 RESOLVE_TAG (&tag_unit
, close
->unit
);
2630 RESOLVE_TAG (&tag_iomsg
, close
->iomsg
);
2631 RESOLVE_TAG (&tag_iostat
, close
->iostat
);
2632 RESOLVE_TAG (&tag_status
, close
->status
);
2634 if (!gfc_reference_st_label (close
->err
, ST_LABEL_TARGET
))
2637 if (close
->unit
== NULL
)
2639 /* Find a locus from one of the arguments to close, when UNIT is
2641 locus loc
= gfc_current_locus
;
2643 loc
= close
->status
->where
;
2644 else if (close
->iostat
)
2645 loc
= close
->iostat
->where
;
2646 else if (close
->iomsg
)
2647 loc
= close
->iomsg
->where
;
2648 else if (close
->err
)
2649 loc
= close
->err
->where
;
2651 gfc_error ("CLOSE statement at %L requires a UNIT number", &loc
);
2655 if (close
->unit
->expr_type
== EXPR_CONSTANT
2656 && close
->unit
->ts
.type
== BT_INTEGER
2657 && mpz_sgn (close
->unit
->value
.integer
) < 0)
2659 gfc_error ("UNIT number in CLOSE statement at %L must be non-negative",
2660 &close
->unit
->where
);
2667 /* Free a gfc_filepos structure. */
2670 gfc_free_filepos (gfc_filepos
*fp
)
2672 gfc_free_expr (fp
->unit
);
2673 gfc_free_expr (fp
->iomsg
);
2674 gfc_free_expr (fp
->iostat
);
2679 /* Match elements of a REWIND, BACKSPACE, ENDFILE, or FLUSH statement. */
2682 match_file_element (gfc_filepos
*fp
)
2686 m
= match_etag (&tag_unit
, &fp
->unit
);
2689 m
= match_etag (&tag_iomsg
, &fp
->iomsg
);
2690 if (m
== MATCH_YES
&& !check_char_variable (fp
->iomsg
))
2694 m
= match_out_tag (&tag_iostat
, &fp
->iostat
);
2697 m
= match_ltag (&tag_err
, &fp
->err
);
2705 /* Match the second half of the file-positioning statements, REWIND,
2706 BACKSPACE, ENDFILE, or the FLUSH statement. */
2709 match_filepos (gfc_statement st
, gfc_exec_op op
)
2714 fp
= XCNEW (gfc_filepos
);
2716 if (gfc_match_char ('(') == MATCH_NO
)
2718 m
= gfc_match_expr (&fp
->unit
);
2719 if (m
== MATCH_ERROR
)
2727 m
= match_file_element (fp
);
2728 if (m
== MATCH_ERROR
)
2732 m
= gfc_match_expr (&fp
->unit
);
2733 if (m
== MATCH_ERROR
|| m
== MATCH_NO
)
2739 if (gfc_match_char (')') == MATCH_YES
)
2741 if (gfc_match_char (',') != MATCH_YES
)
2744 m
= match_file_element (fp
);
2745 if (m
== MATCH_ERROR
)
2752 if (gfc_match_eos () != MATCH_YES
)
2755 if (gfc_pure (NULL
))
2757 gfc_error ("%s statement not allowed in PURE procedure at %C",
2758 gfc_ascii_statement (st
));
2763 gfc_unset_implicit_pure (NULL
);
2766 new_st
.ext
.filepos
= fp
;
2770 gfc_syntax_error (st
);
2773 gfc_free_filepos (fp
);
2779 gfc_resolve_filepos (gfc_filepos
*fp
)
2781 RESOLVE_TAG (&tag_unit
, fp
->unit
);
2782 RESOLVE_TAG (&tag_iostat
, fp
->iostat
);
2783 RESOLVE_TAG (&tag_iomsg
, fp
->iomsg
);
2784 if (!gfc_reference_st_label (fp
->err
, ST_LABEL_TARGET
))
2787 if (!fp
->unit
&& (fp
->iostat
|| fp
->iomsg
))
2790 where
= fp
->iostat
? fp
->iostat
->where
: fp
->iomsg
->where
;
2791 gfc_error ("UNIT number missing in statement at %L", &where
);
2795 if (fp
->unit
->expr_type
== EXPR_CONSTANT
2796 && fp
->unit
->ts
.type
== BT_INTEGER
2797 && mpz_sgn (fp
->unit
->value
.integer
) < 0)
2799 gfc_error ("UNIT number in statement at %L must be non-negative",
2808 /* Match the file positioning statements: ENDFILE, BACKSPACE, REWIND,
2809 and the FLUSH statement. */
2812 gfc_match_endfile (void)
2814 return match_filepos (ST_END_FILE
, EXEC_ENDFILE
);
2818 gfc_match_backspace (void)
2820 return match_filepos (ST_BACKSPACE
, EXEC_BACKSPACE
);
2824 gfc_match_rewind (void)
2826 return match_filepos (ST_REWIND
, EXEC_REWIND
);
2830 gfc_match_flush (void)
2832 if (!gfc_notify_std (GFC_STD_F2003
, "FLUSH statement at %C"))
2835 return match_filepos (ST_FLUSH
, EXEC_FLUSH
);
2838 /******************** Data Transfer Statements *********************/
2840 /* Return a default unit number. */
2843 default_unit (io_kind k
)
2852 return gfc_get_int_expr (gfc_default_integer_kind
, NULL
, unit
);
2856 /* Match a unit specification for a data transfer statement. */
2859 match_dt_unit (io_kind k
, gfc_dt
*dt
)
2864 if (gfc_match_char ('*') == MATCH_YES
)
2866 if (dt
->io_unit
!= NULL
)
2869 dt
->io_unit
= default_unit (k
);
2871 c
= gfc_peek_ascii_char ();
2873 gfc_error_now ("Missing format with default unit at %C");
2878 if (gfc_match_expr (&e
) == MATCH_YES
)
2880 if (dt
->io_unit
!= NULL
)
2893 gfc_error ("Duplicate UNIT specification at %C");
2898 /* Match a format specification. */
2901 match_dt_format (gfc_dt
*dt
)
2905 gfc_st_label
*label
;
2908 where
= gfc_current_locus
;
2910 if (gfc_match_char ('*') == MATCH_YES
)
2912 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2915 dt
->format_label
= &format_asterisk
;
2919 if ((m
= gfc_match_st_label (&label
)) == MATCH_YES
)
2923 /* Need to check if the format label is actually either an operand
2924 to a user-defined operator or is a kind type parameter. That is,
2925 print 2.ip.8 ! .ip. is a user-defined operator return CHARACTER.
2926 print 1_'(I0)', i ! 1_'(I0)' is a default character string. */
2928 gfc_gobble_whitespace ();
2929 c
= gfc_peek_ascii_char ();
2930 if (c
== '.' || c
== '_')
2931 gfc_current_locus
= where
;
2934 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2936 gfc_free_st_label (label
);
2940 if (!gfc_reference_st_label (label
, ST_LABEL_FORMAT
))
2943 dt
->format_label
= label
;
2947 else if (m
== MATCH_ERROR
)
2948 /* The label was zero or too large. Emit the correct diagnosis. */
2951 if (gfc_match_expr (&e
) == MATCH_YES
)
2953 if (dt
->format_expr
!= NULL
|| dt
->format_label
!= NULL
)
2958 dt
->format_expr
= e
;
2962 gfc_current_locus
= where
; /* The only case where we have to restore */
2967 gfc_error ("Duplicate format specification at %C");
2972 /* Traverse a namelist that is part of a READ statement to make sure
2973 that none of the variables in the namelist are INTENT(IN). Returns
2974 nonzero if we find such a variable. */
2977 check_namelist (gfc_symbol
*sym
)
2981 for (p
= sym
->namelist
; p
; p
= p
->next
)
2982 if (p
->sym
->attr
.intent
== INTENT_IN
)
2984 gfc_error ("Symbol %qs in namelist %qs is INTENT(IN) at %C",
2985 p
->sym
->name
, sym
->name
);
2993 /* Match a single data transfer element. */
2996 match_dt_element (io_kind k
, gfc_dt
*dt
)
2998 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3002 if (gfc_match (" unit =") == MATCH_YES
)
3004 m
= match_dt_unit (k
, dt
);
3009 if (gfc_match (" fmt =") == MATCH_YES
)
3011 m
= match_dt_format (dt
);
3016 if (gfc_match (" nml = %n", name
) == MATCH_YES
)
3018 if (dt
->namelist
!= NULL
)
3020 gfc_error ("Duplicate NML specification at %C");
3024 if (gfc_find_symbol (name
, NULL
, 1, &sym
))
3027 if (sym
== NULL
|| sym
->attr
.flavor
!= FL_NAMELIST
)
3029 gfc_error ("Symbol %qs at %C must be a NAMELIST group name",
3030 sym
!= NULL
? sym
->name
: name
);
3035 if (k
== M_READ
&& check_namelist (sym
))
3041 m
= match_etag (&tag_e_async
, &dt
->asynchronous
);
3042 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", dt
->asynchronous
))
3046 m
= match_etag (&tag_e_blank
, &dt
->blank
);
3049 m
= match_etag (&tag_e_delim
, &dt
->delim
);
3052 m
= match_etag (&tag_e_pad
, &dt
->pad
);
3055 m
= match_etag (&tag_e_sign
, &dt
->sign
);
3058 m
= match_etag (&tag_e_round
, &dt
->round
);
3061 m
= match_out_tag (&tag_id
, &dt
->id
);
3064 m
= match_etag (&tag_e_decimal
, &dt
->decimal
);
3067 m
= match_etag (&tag_rec
, &dt
->rec
);
3070 m
= match_etag (&tag_spos
, &dt
->pos
);
3073 m
= match_etag (&tag_iomsg
, &dt
->iomsg
);
3074 if (m
== MATCH_YES
&& !check_char_variable (dt
->iomsg
))
3079 m
= match_out_tag (&tag_iostat
, &dt
->iostat
);
3082 m
= match_ltag (&tag_err
, &dt
->err
);
3084 dt
->err_where
= gfc_current_locus
;
3087 m
= match_etag (&tag_advance
, &dt
->advance
);
3090 m
= match_out_tag (&tag_size
, &dt
->size
);
3094 m
= match_ltag (&tag_end
, &dt
->end
);
3099 gfc_error ("END tag at %C not allowed in output statement");
3102 dt
->end_where
= gfc_current_locus
;
3107 m
= match_ltag (&tag_eor
, &dt
->eor
);
3109 dt
->eor_where
= gfc_current_locus
;
3117 /* Free a data transfer structure and everything below it. */
3120 gfc_free_dt (gfc_dt
*dt
)
3125 gfc_free_expr (dt
->io_unit
);
3126 gfc_free_expr (dt
->format_expr
);
3127 gfc_free_expr (dt
->rec
);
3128 gfc_free_expr (dt
->advance
);
3129 gfc_free_expr (dt
->iomsg
);
3130 gfc_free_expr (dt
->iostat
);
3131 gfc_free_expr (dt
->size
);
3132 gfc_free_expr (dt
->pad
);
3133 gfc_free_expr (dt
->delim
);
3134 gfc_free_expr (dt
->sign
);
3135 gfc_free_expr (dt
->round
);
3136 gfc_free_expr (dt
->blank
);
3137 gfc_free_expr (dt
->decimal
);
3138 gfc_free_expr (dt
->pos
);
3139 gfc_free_expr (dt
->dt_io_kind
);
3140 /* dt->extra_comma is a link to dt_io_kind if it is set. */
3145 /* Resolve everything in a gfc_dt structure. */
3148 gfc_resolve_dt (gfc_dt
*dt
, locus
*loc
)
3153 /* This is set in any case. */
3154 gcc_assert (dt
->dt_io_kind
);
3155 k
= dt
->dt_io_kind
->value
.iokind
;
3157 RESOLVE_TAG (&tag_format
, dt
->format_expr
);
3158 RESOLVE_TAG (&tag_rec
, dt
->rec
);
3159 RESOLVE_TAG (&tag_spos
, dt
->pos
);
3160 RESOLVE_TAG (&tag_advance
, dt
->advance
);
3161 RESOLVE_TAG (&tag_id
, dt
->id
);
3162 RESOLVE_TAG (&tag_iomsg
, dt
->iomsg
);
3163 RESOLVE_TAG (&tag_iostat
, dt
->iostat
);
3164 RESOLVE_TAG (&tag_size
, dt
->size
);
3165 RESOLVE_TAG (&tag_e_pad
, dt
->pad
);
3166 RESOLVE_TAG (&tag_e_delim
, dt
->delim
);
3167 RESOLVE_TAG (&tag_e_sign
, dt
->sign
);
3168 RESOLVE_TAG (&tag_e_round
, dt
->round
);
3169 RESOLVE_TAG (&tag_e_blank
, dt
->blank
);
3170 RESOLVE_TAG (&tag_e_decimal
, dt
->decimal
);
3171 RESOLVE_TAG (&tag_e_async
, dt
->asynchronous
);
3176 gfc_error ("UNIT not specified at %L", loc
);
3180 if (gfc_resolve_expr (e
)
3181 && (e
->ts
.type
!= BT_INTEGER
3182 && (e
->ts
.type
!= BT_CHARACTER
|| e
->expr_type
!= EXPR_VARIABLE
)))
3184 /* If there is no extra comma signifying the "format" form of the IO
3185 statement, then this must be an error. */
3186 if (!dt
->extra_comma
)
3188 gfc_error ("UNIT specification at %L must be an INTEGER expression "
3189 "or a CHARACTER variable", &e
->where
);
3194 /* At this point, we have an extra comma. If io_unit has arrived as
3195 type character, we assume its really the "format" form of the I/O
3196 statement. We set the io_unit to the default unit and format to
3197 the character expression. See F95 Standard section 9.4. */
3198 if (e
->ts
.type
== BT_CHARACTER
&& (k
== M_READ
|| k
== M_PRINT
))
3200 dt
->format_expr
= dt
->io_unit
;
3201 dt
->io_unit
= default_unit (k
);
3203 /* Nullify this pointer now so that a warning/error is not
3204 triggered below for the "Extension". */
3205 dt
->extra_comma
= NULL
;
3210 gfc_error ("Invalid form of WRITE statement at %L, UNIT required",
3211 &dt
->extra_comma
->where
);
3217 if (e
->ts
.type
== BT_CHARACTER
)
3219 if (gfc_has_vector_index (e
))
3221 gfc_error ("Internal unit with vector subscript at %L", &e
->where
);
3225 /* If we are writing, make sure the internal unit can be changed. */
3226 gcc_assert (k
!= M_PRINT
);
3228 && !gfc_check_vardef_context (e
, false, false, false,
3229 _("internal unit in WRITE")))
3233 if (e
->rank
&& e
->ts
.type
!= BT_CHARACTER
)
3235 gfc_error ("External IO UNIT cannot be an array at %L", &e
->where
);
3239 if (e
->expr_type
== EXPR_CONSTANT
&& e
->ts
.type
== BT_INTEGER
3240 && mpz_sgn (e
->value
.integer
) < 0)
3242 gfc_error ("UNIT number in statement at %L must be non-negative",
3247 /* If we are reading and have a namelist, check that all namelist symbols
3248 can appear in a variable definition context. */
3249 if (k
== M_READ
&& dt
->namelist
)
3252 for (n
= dt
->namelist
->namelist
; n
; n
= n
->next
)
3257 e
= gfc_get_variable_expr (gfc_find_sym_in_symtree (n
->sym
));
3258 t
= gfc_check_vardef_context (e
, false, false, false, NULL
);
3263 gfc_error ("NAMELIST %qs in READ statement at %L contains"
3264 " the symbol %qs which may not appear in a"
3265 " variable definition context",
3266 dt
->namelist
->name
, loc
, n
->sym
->name
);
3273 && !gfc_notify_std (GFC_STD_LEGACY
, "Comma before i/o item list at %L",
3274 &dt
->extra_comma
->where
))
3279 if (!gfc_reference_st_label (dt
->err
, ST_LABEL_TARGET
))
3281 if (dt
->err
->defined
== ST_LABEL_UNKNOWN
)
3283 gfc_error ("ERR tag label %d at %L not defined",
3284 dt
->err
->value
, &dt
->err_where
);
3291 if (!gfc_reference_st_label (dt
->end
, ST_LABEL_TARGET
))
3293 if (dt
->end
->defined
== ST_LABEL_UNKNOWN
)
3295 gfc_error ("END tag label %d at %L not defined",
3296 dt
->end
->value
, &dt
->end_where
);
3303 if (!gfc_reference_st_label (dt
->eor
, ST_LABEL_TARGET
))
3305 if (dt
->eor
->defined
== ST_LABEL_UNKNOWN
)
3307 gfc_error ("EOR tag label %d at %L not defined",
3308 dt
->eor
->value
, &dt
->eor_where
);
3313 /* Check the format label actually exists. */
3314 if (dt
->format_label
&& dt
->format_label
!= &format_asterisk
3315 && dt
->format_label
->defined
== ST_LABEL_UNKNOWN
)
3317 gfc_error ("FORMAT label %d at %L not defined", dt
->format_label
->value
,
3326 /* Given an io_kind, return its name. */
3329 io_kind_name (io_kind k
)
3348 gfc_internal_error ("io_kind_name(): bad I/O-kind");
3355 /* Match an IO iteration statement of the form:
3357 ( [<IO element> ,] <IO element>, I = <expr>, <expr> [, <expr> ] )
3359 which is equivalent to a single IO element. This function is
3360 mutually recursive with match_io_element(). */
3362 static match
match_io_element (io_kind
, gfc_code
**);
3365 match_io_iterator (io_kind k
, gfc_code
**result
)
3367 gfc_code
*head
, *tail
, *new_code
;
3375 old_loc
= gfc_current_locus
;
3377 if (gfc_match_char ('(') != MATCH_YES
)
3380 m
= match_io_element (k
, &head
);
3383 if (m
!= MATCH_YES
|| gfc_match_char (',') != MATCH_YES
)
3389 /* Can't be anything but an IO iterator. Build a list. */
3390 iter
= gfc_get_iterator ();
3394 m
= gfc_match_iterator (iter
, 0);
3395 if (m
== MATCH_ERROR
)
3399 gfc_check_do_variable (iter
->var
->symtree
);
3403 m
= match_io_element (k
, &new_code
);
3404 if (m
== MATCH_ERROR
)
3413 tail
= gfc_append_code (tail
, new_code
);
3415 if (gfc_match_char (',') != MATCH_YES
)
3424 if (gfc_match_char (')') != MATCH_YES
)
3427 new_code
= gfc_get_code (EXEC_DO
);
3428 new_code
->ext
.iterator
= iter
;
3430 new_code
->block
= gfc_get_code (EXEC_DO
);
3431 new_code
->block
->next
= head
;
3437 gfc_error ("Syntax error in I/O iterator at %C");
3441 gfc_free_iterator (iter
, 1);
3442 gfc_free_statements (head
);
3443 gfc_current_locus
= old_loc
;
3448 /* Match a single element of an IO list, which is either a single
3449 expression or an IO Iterator. */
3452 match_io_element (io_kind k
, gfc_code
**cpp
)
3460 m
= match_io_iterator (k
, cpp
);
3466 m
= gfc_match_variable (&expr
, 0);
3468 gfc_error ("Expected variable in READ statement at %C");
3472 m
= gfc_match_expr (&expr
);
3474 gfc_error ("Expected expression in %s statement at %C",
3478 if (m
== MATCH_YES
&& k
== M_READ
&& gfc_check_do_variable (expr
->symtree
))
3483 gfc_free_expr (expr
);
3487 cp
= gfc_get_code (EXEC_TRANSFER
);
3490 cp
->ext
.dt
= current_dt
;
3497 /* Match an I/O list, building gfc_code structures as we go. */
3500 match_io_list (io_kind k
, gfc_code
**head_p
)
3502 gfc_code
*head
, *tail
, *new_code
;
3505 *head_p
= head
= tail
= NULL
;
3506 if (gfc_match_eos () == MATCH_YES
)
3511 m
= match_io_element (k
, &new_code
);
3512 if (m
== MATCH_ERROR
)
3517 tail
= gfc_append_code (tail
, new_code
);
3521 if (gfc_match_eos () == MATCH_YES
)
3523 if (gfc_match_char (',') != MATCH_YES
)
3531 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k
));
3534 gfc_free_statements (head
);
3539 /* Attach the data transfer end node. */
3542 terminate_io (gfc_code
*io_code
)
3546 if (io_code
== NULL
)
3547 io_code
= new_st
.block
;
3549 c
= gfc_get_code (EXEC_DT_END
);
3551 /* Point to structure that is already there */
3552 c
->ext
.dt
= new_st
.ext
.dt
;
3553 gfc_append_code (io_code
, c
);
3557 /* Check the constraints for a data transfer statement. The majority of the
3558 constraints appearing in 9.4 of the standard appear here. Some are handled
3559 in resolve_tag and others in gfc_resolve_dt. */
3562 check_io_constraints (io_kind k
, gfc_dt
*dt
, gfc_code
*io_code
,
3565 #define io_constraint(condition,msg,arg)\
3568 gfc_error(msg,arg);\
3574 gfc_symbol
*sym
= NULL
;
3575 bool warn
, unformatted
;
3577 warn
= (dt
->err
|| dt
->iostat
) ? true : false;
3578 unformatted
= dt
->format_expr
== NULL
&& dt
->format_label
== NULL
3579 && dt
->namelist
== NULL
;
3584 if (expr
&& expr
->expr_type
== EXPR_VARIABLE
3585 && expr
->ts
.type
== BT_CHARACTER
)
3587 sym
= expr
->symtree
->n
.sym
;
3589 io_constraint (k
== M_WRITE
&& sym
->attr
.intent
== INTENT_IN
,
3590 "Internal file at %L must not be INTENT(IN)",
3593 io_constraint (gfc_has_vector_index (dt
->io_unit
),
3594 "Internal file incompatible with vector subscript at %L",
3597 io_constraint (dt
->rec
!= NULL
,
3598 "REC tag at %L is incompatible with internal file",
3601 io_constraint (dt
->pos
!= NULL
,
3602 "POS tag at %L is incompatible with internal file",
3605 io_constraint (unformatted
,
3606 "Unformatted I/O not allowed with internal unit at %L",
3607 &dt
->io_unit
->where
);
3609 io_constraint (dt
->asynchronous
!= NULL
,
3610 "ASYNCHRONOUS tag at %L not allowed with internal file",
3611 &dt
->asynchronous
->where
);
3613 if (dt
->namelist
!= NULL
)
3615 if (!gfc_notify_std (GFC_STD_F2003
, "Internal file at %L with "
3616 "namelist", &expr
->where
))
3620 io_constraint (dt
->advance
!= NULL
,
3621 "ADVANCE tag at %L is incompatible with internal file",
3622 &dt
->advance
->where
);
3625 if (expr
&& expr
->ts
.type
!= BT_CHARACTER
)
3628 io_constraint (gfc_pure (NULL
) && (k
== M_READ
|| k
== M_WRITE
),
3629 "IO UNIT in %s statement at %C must be "
3630 "an internal file in a PURE procedure",
3633 if (k
== M_READ
|| k
== M_WRITE
)
3634 gfc_unset_implicit_pure (NULL
);
3639 io_constraint (dt
->end
, "END tag not allowed with output at %L",
3642 io_constraint (dt
->eor
, "EOR tag not allowed with output at %L",
3645 io_constraint (dt
->blank
, "BLANK= specifier not allowed with output at %L",
3648 io_constraint (dt
->pad
, "PAD= specifier not allowed with output at %L",
3651 io_constraint (dt
->size
, "SIZE= specifier not allowed with output at %L",
3656 io_constraint (dt
->size
&& dt
->advance
== NULL
,
3657 "SIZE tag at %L requires an ADVANCE tag",
3660 io_constraint (dt
->eor
&& dt
->advance
== NULL
,
3661 "EOR tag at %L requires an ADVANCE tag",
3665 if (dt
->asynchronous
)
3667 static const char * asynchronous
[] = { "YES", "NO", NULL
};
3669 if (!gfc_reduce_init_expr (dt
->asynchronous
))
3671 gfc_error ("ASYNCHRONOUS= specifier at %L must be an initialization "
3672 "expression", &dt
->asynchronous
->where
);
3676 if (!is_char_type ("ASYNCHRONOUS", dt
->asynchronous
))
3679 if (!compare_to_allowed_values
3680 ("ASYNCHRONOUS", asynchronous
, NULL
, NULL
,
3681 dt
->asynchronous
->value
.character
.string
,
3682 io_kind_name (k
), warn
))
3690 || gfc_wide_strlen (dt
->asynchronous
->value
.character
.string
) != 3
3691 || gfc_wide_strncasecmp (dt
->asynchronous
->value
.character
.string
,
3693 io_constraint (not_yes
,
3694 "ID= specifier at %L must be with ASYNCHRONOUS='yes' "
3695 "specifier", &dt
->id
->where
);
3700 if (!gfc_notify_std (GFC_STD_F2003
, "DECIMAL= at %C "
3701 "not allowed in Fortran 95"))
3704 if (dt
->decimal
->expr_type
== EXPR_CONSTANT
)
3706 static const char * decimal
[] = { "COMMA", "POINT", NULL
};
3708 if (!is_char_type ("DECIMAL", dt
->decimal
))
3711 if (!compare_to_allowed_values ("DECIMAL", decimal
, NULL
, NULL
,
3712 dt
->decimal
->value
.character
.string
,
3713 io_kind_name (k
), warn
))
3716 io_constraint (unformatted
,
3717 "the DECIMAL= specifier at %L must be with an "
3718 "explicit format expression", &dt
->decimal
->where
);
3724 if (!gfc_notify_std (GFC_STD_F2003
, "BLANK= at %C "
3725 "not allowed in Fortran 95"))
3728 if (!is_char_type ("BLANK", dt
->blank
))
3731 if (dt
->blank
->expr_type
== EXPR_CONSTANT
)
3733 static const char * blank
[] = { "NULL", "ZERO", NULL
};
3736 if (!compare_to_allowed_values ("BLANK", blank
, NULL
, NULL
,
3737 dt
->blank
->value
.character
.string
,
3738 io_kind_name (k
), warn
))
3741 io_constraint (unformatted
,
3742 "the BLANK= specifier at %L must be with an "
3743 "explicit format expression", &dt
->blank
->where
);
3749 if (!gfc_notify_std (GFC_STD_F2003
, "PAD= at %C "
3750 "not allowed in Fortran 95"))
3753 if (!is_char_type ("PAD", dt
->pad
))
3756 if (dt
->pad
->expr_type
== EXPR_CONSTANT
)
3758 static const char * pad
[] = { "YES", "NO", NULL
};
3760 if (!compare_to_allowed_values ("PAD", pad
, NULL
, NULL
,
3761 dt
->pad
->value
.character
.string
,
3762 io_kind_name (k
), warn
))
3765 io_constraint (unformatted
,
3766 "the PAD= specifier at %L must be with an "
3767 "explicit format expression", &dt
->pad
->where
);
3773 if (!gfc_notify_std (GFC_STD_F2003
, "ROUND= at %C "
3774 "not allowed in Fortran 95"))
3777 if (!is_char_type ("ROUND", dt
->round
))
3780 if (dt
->round
->expr_type
== EXPR_CONSTANT
)
3782 static const char * round
[] = { "UP", "DOWN", "ZERO", "NEAREST",
3783 "COMPATIBLE", "PROCESSOR_DEFINED",
3786 if (!compare_to_allowed_values ("ROUND", round
, NULL
, NULL
,
3787 dt
->round
->value
.character
.string
,
3788 io_kind_name (k
), warn
))
3795 /* When implemented, change the following to use gfc_notify_std F2003.
3796 if (gfc_notify_std (GFC_STD_F2003, "SIGN= at %C "
3797 "not allowed in Fortran 95") == false)
3798 return MATCH_ERROR; */
3800 if (!is_char_type ("SIGN", dt
->sign
))
3803 if (dt
->sign
->expr_type
== EXPR_CONSTANT
)
3805 static const char * sign
[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
3808 if (!compare_to_allowed_values ("SIGN", sign
, NULL
, NULL
,
3809 dt
->sign
->value
.character
.string
,
3810 io_kind_name (k
), warn
))
3813 io_constraint (unformatted
,
3814 "SIGN= specifier at %L must be with an "
3815 "explicit format expression", &dt
->sign
->where
);
3817 io_constraint (k
== M_READ
,
3818 "SIGN= specifier at %L not allowed in a "
3819 "READ statement", &dt
->sign
->where
);
3825 if (!gfc_notify_std (GFC_STD_F2003
, "DELIM= at %C "
3826 "not allowed in Fortran 95"))
3829 if (!is_char_type ("DELIM", dt
->delim
))
3832 if (dt
->delim
->expr_type
== EXPR_CONSTANT
)
3834 static const char *delim
[] = { "APOSTROPHE", "QUOTE", "NONE", NULL
};
3836 if (!compare_to_allowed_values ("DELIM", delim
, NULL
, NULL
,
3837 dt
->delim
->value
.character
.string
,
3838 io_kind_name (k
), warn
))
3841 io_constraint (k
== M_READ
,
3842 "DELIM= specifier at %L not allowed in a "
3843 "READ statement", &dt
->delim
->where
);
3845 io_constraint (dt
->format_label
!= &format_asterisk
3846 && dt
->namelist
== NULL
,
3847 "DELIM= specifier at %L must have FMT=*",
3850 io_constraint (unformatted
&& dt
->namelist
== NULL
,
3851 "DELIM= specifier at %L must be with FMT=* or "
3852 "NML= specifier ", &dt
->delim
->where
);
3858 io_constraint (io_code
&& dt
->namelist
,
3859 "NAMELIST cannot be followed by IO-list at %L",
3862 io_constraint (dt
->format_expr
,
3863 "IO spec-list cannot contain both NAMELIST group name "
3864 "and format specification at %L",
3865 &dt
->format_expr
->where
);
3867 io_constraint (dt
->format_label
,
3868 "IO spec-list cannot contain both NAMELIST group name "
3869 "and format label at %L", spec_end
);
3871 io_constraint (dt
->rec
,
3872 "NAMELIST IO is not allowed with a REC= specifier "
3873 "at %L", &dt
->rec
->where
);
3875 io_constraint (dt
->advance
,
3876 "NAMELIST IO is not allowed with a ADVANCE= specifier "
3877 "at %L", &dt
->advance
->where
);
3882 io_constraint (dt
->end
,
3883 "An END tag is not allowed with a "
3884 "REC= specifier at %L", &dt
->end_where
);
3886 io_constraint (dt
->format_label
== &format_asterisk
,
3887 "FMT=* is not allowed with a REC= specifier "
3890 io_constraint (dt
->pos
,
3891 "POS= is not allowed with REC= specifier "
3892 "at %L", &dt
->pos
->where
);
3897 int not_yes
, not_no
;
3900 io_constraint (dt
->format_label
== &format_asterisk
,
3901 "List directed format(*) is not allowed with a "
3902 "ADVANCE= specifier at %L.", &expr
->where
);
3904 io_constraint (unformatted
,
3905 "the ADVANCE= specifier at %L must appear with an "
3906 "explicit format expression", &expr
->where
);
3908 if (expr
->expr_type
== EXPR_CONSTANT
&& expr
->ts
.type
== BT_CHARACTER
)
3910 const gfc_char_t
*advance
= expr
->value
.character
.string
;
3911 not_no
= gfc_wide_strlen (advance
) != 2
3912 || gfc_wide_strncasecmp (advance
, "no", 2) != 0;
3913 not_yes
= gfc_wide_strlen (advance
) != 3
3914 || gfc_wide_strncasecmp (advance
, "yes", 3) != 0;
3922 io_constraint (not_no
&& not_yes
,
3923 "ADVANCE= specifier at %L must have value = "
3924 "YES or NO.", &expr
->where
);
3926 io_constraint (dt
->size
&& not_no
&& k
== M_READ
,
3927 "SIZE tag at %L requires an ADVANCE = %<NO%>",
3930 io_constraint (dt
->eor
&& not_no
&& k
== M_READ
,
3931 "EOR tag at %L requires an ADVANCE = %<NO%>",
3935 expr
= dt
->format_expr
;
3936 if (!gfc_simplify_expr (expr
, 0)
3937 || !check_format_string (expr
, k
== M_READ
))
3942 #undef io_constraint
3945 /* Match a READ, WRITE or PRINT statement. */
3948 match_io (io_kind k
)
3950 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3955 locus spec_end
, control
;
3959 where
= gfc_current_locus
;
3961 current_dt
= dt
= XCNEW (gfc_dt
);
3962 m
= gfc_match_char ('(');
3965 where
= gfc_current_locus
;
3968 else if (k
== M_PRINT
)
3970 /* Treat the non-standard case of PRINT namelist. */
3971 if ((gfc_current_form
== FORM_FIXED
|| gfc_peek_ascii_char () == ' ')
3972 && gfc_match_name (name
) == MATCH_YES
)
3974 gfc_find_symbol (name
, NULL
, 1, &sym
);
3975 if (sym
&& sym
->attr
.flavor
== FL_NAMELIST
)
3977 if (!gfc_notify_std (GFC_STD_GNU
, "PRINT namelist at "
3978 "%C is an extension"))
3984 dt
->io_unit
= default_unit (k
);
3989 gfc_current_locus
= where
;
3993 if (gfc_current_form
== FORM_FREE
)
3995 char c
= gfc_peek_ascii_char ();
3996 if (c
!= ' ' && c
!= '*' && c
!= '\'' && c
!= '"')
4003 m
= match_dt_format (dt
);
4004 if (m
== MATCH_ERROR
)
4010 dt
->io_unit
= default_unit (k
);
4015 /* Before issuing an error for a malformed 'print (1,*)' type of
4016 error, check for a default-char-expr of the form ('(I0)'). */
4019 control
= gfc_current_locus
;
4022 /* Reset current locus to get the initial '(' in an expression. */
4023 gfc_current_locus
= where
;
4024 dt
->format_expr
= NULL
;
4025 m
= match_dt_format (dt
);
4027 if (m
== MATCH_ERROR
)
4029 if (m
== MATCH_NO
|| dt
->format_expr
== NULL
)
4033 dt
->io_unit
= default_unit (k
);
4038 /* Commit any pending symbols now so that when we undo
4039 symbols later we wont lose them. */
4040 gfc_commit_symbols ();
4041 /* Reset current locus to get the initial '(' in an expression. */
4042 gfc_current_locus
= where
;
4043 dt
->format_expr
= NULL
;
4044 m
= gfc_match_expr (&dt
->format_expr
);
4048 && dt
->format_expr
->ts
.type
== BT_CHARACTER
)
4051 dt
->io_unit
= default_unit (k
);
4056 gfc_free_expr (dt
->format_expr
);
4057 dt
->format_expr
= NULL
;
4058 gfc_current_locus
= control
;
4064 gfc_undo_symbols ();
4065 gfc_free_expr (dt
->format_expr
);
4066 dt
->format_expr
= NULL
;
4067 gfc_current_locus
= control
;
4073 /* Match a control list */
4074 if (match_dt_element (k
, dt
) == MATCH_YES
)
4076 if (match_dt_unit (k
, dt
) != MATCH_YES
)
4079 if (gfc_match_char (')') == MATCH_YES
)
4081 if (gfc_match_char (',') != MATCH_YES
)
4084 m
= match_dt_element (k
, dt
);
4087 if (m
== MATCH_ERROR
)
4090 m
= match_dt_format (dt
);
4093 if (m
== MATCH_ERROR
)
4096 where
= gfc_current_locus
;
4098 m
= gfc_match_name (name
);
4101 gfc_find_symbol (name
, NULL
, 1, &sym
);
4102 if (sym
&& sym
->attr
.flavor
== FL_NAMELIST
)
4105 if (k
== M_READ
&& check_namelist (sym
))
4114 gfc_current_locus
= where
;
4116 goto loop
; /* No matches, try regular elements */
4119 if (gfc_match_char (')') == MATCH_YES
)
4121 if (gfc_match_char (',') != MATCH_YES
)
4127 m
= match_dt_element (k
, dt
);
4130 if (m
== MATCH_ERROR
)
4133 if (gfc_match_char (')') == MATCH_YES
)
4135 if (gfc_match_char (',') != MATCH_YES
)
4141 /* Used in check_io_constraints, where no locus is available. */
4142 spec_end
= gfc_current_locus
;
4144 /* Save the IO kind for later use. */
4145 dt
->dt_io_kind
= gfc_get_iokind_expr (&gfc_current_locus
, k
);
4147 /* Optional leading comma (non-standard). We use a gfc_expr structure here
4148 to save the locus. This is used later when resolving transfer statements
4149 that might have a format expression without unit number. */
4150 if (!comma_flag
&& gfc_match_char (',') == MATCH_YES
)
4151 dt
->extra_comma
= dt
->dt_io_kind
;
4154 if (gfc_match_eos () != MATCH_YES
)
4156 if (comma_flag
&& gfc_match_char (',') != MATCH_YES
)
4158 gfc_error ("Expected comma in I/O list at %C");
4163 m
= match_io_list (k
, &io_code
);
4164 if (m
== MATCH_ERROR
)
4170 /* A full IO statement has been matched. Check the constraints. spec_end is
4171 supplied for cases where no locus is supplied. */
4172 m
= check_io_constraints (k
, dt
, io_code
, &spec_end
);
4174 if (m
== MATCH_ERROR
)
4177 new_st
.op
= (k
== M_READ
) ? EXEC_READ
: EXEC_WRITE
;
4179 new_st
.block
= gfc_get_code (new_st
.op
);
4180 new_st
.block
->next
= io_code
;
4182 terminate_io (io_code
);
4187 gfc_error ("Syntax error in %s statement at %C", io_kind_name (k
));
4197 gfc_match_read (void)
4199 return match_io (M_READ
);
4204 gfc_match_write (void)
4206 return match_io (M_WRITE
);
4211 gfc_match_print (void)
4215 m
= match_io (M_PRINT
);
4219 if (gfc_pure (NULL
))
4221 gfc_error ("PRINT statement at %C not allowed within PURE procedure");
4225 gfc_unset_implicit_pure (NULL
);
4231 /* Free a gfc_inquire structure. */
4234 gfc_free_inquire (gfc_inquire
*inquire
)
4237 if (inquire
== NULL
)
4240 gfc_free_expr (inquire
->unit
);
4241 gfc_free_expr (inquire
->file
);
4242 gfc_free_expr (inquire
->iomsg
);
4243 gfc_free_expr (inquire
->iostat
);
4244 gfc_free_expr (inquire
->exist
);
4245 gfc_free_expr (inquire
->opened
);
4246 gfc_free_expr (inquire
->number
);
4247 gfc_free_expr (inquire
->named
);
4248 gfc_free_expr (inquire
->name
);
4249 gfc_free_expr (inquire
->access
);
4250 gfc_free_expr (inquire
->sequential
);
4251 gfc_free_expr (inquire
->direct
);
4252 gfc_free_expr (inquire
->form
);
4253 gfc_free_expr (inquire
->formatted
);
4254 gfc_free_expr (inquire
->unformatted
);
4255 gfc_free_expr (inquire
->recl
);
4256 gfc_free_expr (inquire
->nextrec
);
4257 gfc_free_expr (inquire
->blank
);
4258 gfc_free_expr (inquire
->position
);
4259 gfc_free_expr (inquire
->action
);
4260 gfc_free_expr (inquire
->read
);
4261 gfc_free_expr (inquire
->write
);
4262 gfc_free_expr (inquire
->readwrite
);
4263 gfc_free_expr (inquire
->delim
);
4264 gfc_free_expr (inquire
->encoding
);
4265 gfc_free_expr (inquire
->pad
);
4266 gfc_free_expr (inquire
->iolength
);
4267 gfc_free_expr (inquire
->convert
);
4268 gfc_free_expr (inquire
->strm_pos
);
4269 gfc_free_expr (inquire
->asynchronous
);
4270 gfc_free_expr (inquire
->decimal
);
4271 gfc_free_expr (inquire
->pending
);
4272 gfc_free_expr (inquire
->id
);
4273 gfc_free_expr (inquire
->sign
);
4274 gfc_free_expr (inquire
->size
);
4275 gfc_free_expr (inquire
->round
);
4276 gfc_free_expr (inquire
->share
);
4277 gfc_free_expr (inquire
->cc
);
4282 /* Match an element of an INQUIRE statement. */
4284 #define RETM if (m != MATCH_NO) return m;
4287 match_inquire_element (gfc_inquire
*inquire
)
4291 m
= match_etag (&tag_unit
, &inquire
->unit
);
4292 RETM m
= match_etag (&tag_file
, &inquire
->file
);
4293 RETM m
= match_ltag (&tag_err
, &inquire
->err
);
4294 RETM m
= match_etag (&tag_iomsg
, &inquire
->iomsg
);
4295 if (m
== MATCH_YES
&& !check_char_variable (inquire
->iomsg
))
4297 RETM m
= match_out_tag (&tag_iostat
, &inquire
->iostat
);
4298 RETM m
= match_vtag (&tag_exist
, &inquire
->exist
);
4299 RETM m
= match_vtag (&tag_opened
, &inquire
->opened
);
4300 RETM m
= match_vtag (&tag_named
, &inquire
->named
);
4301 RETM m
= match_vtag (&tag_name
, &inquire
->name
);
4302 RETM m
= match_out_tag (&tag_number
, &inquire
->number
);
4303 RETM m
= match_vtag (&tag_s_access
, &inquire
->access
);
4304 RETM m
= match_vtag (&tag_sequential
, &inquire
->sequential
);
4305 RETM m
= match_vtag (&tag_direct
, &inquire
->direct
);
4306 RETM m
= match_vtag (&tag_s_form
, &inquire
->form
);
4307 RETM m
= match_vtag (&tag_formatted
, &inquire
->formatted
);
4308 RETM m
= match_vtag (&tag_unformatted
, &inquire
->unformatted
);
4309 RETM m
= match_out_tag (&tag_s_recl
, &inquire
->recl
);
4310 RETM m
= match_out_tag (&tag_nextrec
, &inquire
->nextrec
);
4311 RETM m
= match_vtag (&tag_s_blank
, &inquire
->blank
);
4312 RETM m
= match_vtag (&tag_s_position
, &inquire
->position
);
4313 RETM m
= match_vtag (&tag_s_action
, &inquire
->action
);
4314 RETM m
= match_vtag (&tag_read
, &inquire
->read
);
4315 RETM m
= match_vtag (&tag_write
, &inquire
->write
);
4316 RETM m
= match_vtag (&tag_readwrite
, &inquire
->readwrite
);
4317 RETM m
= match_vtag (&tag_s_async
, &inquire
->asynchronous
);
4318 if (m
== MATCH_YES
&& !is_char_type ("ASYNCHRONOUS", inquire
->asynchronous
))
4320 RETM m
= match_vtag (&tag_s_delim
, &inquire
->delim
);
4321 RETM m
= match_vtag (&tag_s_decimal
, &inquire
->decimal
);
4322 RETM m
= match_out_tag (&tag_size
, &inquire
->size
);
4323 RETM m
= match_vtag (&tag_s_encoding
, &inquire
->encoding
);
4324 RETM m
= match_vtag (&tag_s_round
, &inquire
->round
);
4325 RETM m
= match_vtag (&tag_s_sign
, &inquire
->sign
);
4326 RETM m
= match_vtag (&tag_s_pad
, &inquire
->pad
);
4327 RETM m
= match_out_tag (&tag_iolength
, &inquire
->iolength
);
4328 RETM m
= match_vtag (&tag_convert
, &inquire
->convert
);
4329 RETM m
= match_out_tag (&tag_strm_out
, &inquire
->strm_pos
);
4330 RETM m
= match_vtag (&tag_pending
, &inquire
->pending
);
4331 RETM m
= match_vtag (&tag_id
, &inquire
->id
);
4332 RETM m
= match_vtag (&tag_s_iqstream
, &inquire
->iqstream
);
4333 RETM m
= match_dec_vtag (&tag_v_share
, &inquire
->share
);
4334 RETM m
= match_dec_vtag (&tag_v_cc
, &inquire
->cc
);
4335 RETM
return MATCH_NO
;
4342 gfc_match_inquire (void)
4344 gfc_inquire
*inquire
;
4349 m
= gfc_match_char ('(');
4353 inquire
= XCNEW (gfc_inquire
);
4355 loc
= gfc_current_locus
;
4357 m
= match_inquire_element (inquire
);
4358 if (m
== MATCH_ERROR
)
4362 m
= gfc_match_expr (&inquire
->unit
);
4363 if (m
== MATCH_ERROR
)
4369 /* See if we have the IOLENGTH form of the inquire statement. */
4370 if (inquire
->iolength
!= NULL
)
4372 if (gfc_match_char (')') != MATCH_YES
)
4375 m
= match_io_list (M_INQUIRE
, &code
);
4376 if (m
== MATCH_ERROR
)
4381 new_st
.op
= EXEC_IOLENGTH
;
4382 new_st
.expr1
= inquire
->iolength
;
4383 new_st
.ext
.inquire
= inquire
;
4385 if (gfc_pure (NULL
))
4387 gfc_free_statements (code
);
4388 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
4392 gfc_unset_implicit_pure (NULL
);
4394 new_st
.block
= gfc_get_code (EXEC_IOLENGTH
);
4395 terminate_io (code
);
4396 new_st
.block
->next
= code
;
4400 /* At this point, we have the non-IOLENGTH inquire statement. */
4403 if (gfc_match_char (')') == MATCH_YES
)
4405 if (gfc_match_char (',') != MATCH_YES
)
4408 m
= match_inquire_element (inquire
);
4409 if (m
== MATCH_ERROR
)
4414 if (inquire
->iolength
!= NULL
)
4416 gfc_error ("IOLENGTH tag invalid in INQUIRE statement at %C");
4421 if (gfc_match_eos () != MATCH_YES
)
4424 if (inquire
->unit
!= NULL
&& inquire
->file
!= NULL
)
4426 gfc_error ("INQUIRE statement at %L cannot contain both FILE and "
4427 "UNIT specifiers", &loc
);
4431 if (inquire
->unit
== NULL
&& inquire
->file
== NULL
)
4433 gfc_error ("INQUIRE statement at %L requires either FILE or "
4434 "UNIT specifier", &loc
);
4438 if (inquire
->unit
!= NULL
&& inquire
->unit
->expr_type
== EXPR_CONSTANT
4439 && inquire
->unit
->ts
.type
== BT_INTEGER
4440 && ((mpz_get_si (inquire
->unit
->value
.integer
) == GFC_INTERNAL_UNIT4
)
4441 || (mpz_get_si (inquire
->unit
->value
.integer
) == GFC_INTERNAL_UNIT
)))
4443 gfc_error ("UNIT number in INQUIRE statement at %L can not "
4444 "be %d", &loc
, (int) mpz_get_si (inquire
->unit
->value
.integer
));
4448 if (gfc_pure (NULL
))
4450 gfc_error ("INQUIRE statement not allowed in PURE procedure at %C");
4454 gfc_unset_implicit_pure (NULL
);
4456 if (inquire
->id
!= NULL
&& inquire
->pending
== NULL
)
4458 gfc_error ("INQUIRE statement at %L requires a PENDING= specifier with "
4459 "the ID= specifier", &loc
);
4463 new_st
.op
= EXEC_INQUIRE
;
4464 new_st
.ext
.inquire
= inquire
;
4468 gfc_syntax_error (ST_INQUIRE
);
4471 gfc_free_inquire (inquire
);
4476 /* Resolve everything in a gfc_inquire structure. */
4479 gfc_resolve_inquire (gfc_inquire
*inquire
)
4481 RESOLVE_TAG (&tag_unit
, inquire
->unit
);
4482 RESOLVE_TAG (&tag_file
, inquire
->file
);
4483 RESOLVE_TAG (&tag_id
, inquire
->id
);
4485 /* For INQUIRE, all tags except FILE, ID and UNIT are variable definition
4486 contexts. Thus, use an extended RESOLVE_TAG macro for that. */
4487 #define INQUIRE_RESOLVE_TAG(tag, expr) \
4488 RESOLVE_TAG (tag, expr); \
4492 sprintf (context, _("%s tag with INQUIRE"), (tag)->name); \
4493 if (gfc_check_vardef_context ((expr), false, false, false, \
4494 context) == false) \
4497 INQUIRE_RESOLVE_TAG (&tag_iomsg
, inquire
->iomsg
);
4498 INQUIRE_RESOLVE_TAG (&tag_iostat
, inquire
->iostat
);
4499 INQUIRE_RESOLVE_TAG (&tag_exist
, inquire
->exist
);
4500 INQUIRE_RESOLVE_TAG (&tag_opened
, inquire
->opened
);
4501 INQUIRE_RESOLVE_TAG (&tag_number
, inquire
->number
);
4502 INQUIRE_RESOLVE_TAG (&tag_named
, inquire
->named
);
4503 INQUIRE_RESOLVE_TAG (&tag_name
, inquire
->name
);
4504 INQUIRE_RESOLVE_TAG (&tag_s_access
, inquire
->access
);
4505 INQUIRE_RESOLVE_TAG (&tag_sequential
, inquire
->sequential
);
4506 INQUIRE_RESOLVE_TAG (&tag_direct
, inquire
->direct
);
4507 INQUIRE_RESOLVE_TAG (&tag_s_form
, inquire
->form
);
4508 INQUIRE_RESOLVE_TAG (&tag_formatted
, inquire
->formatted
);
4509 INQUIRE_RESOLVE_TAG (&tag_unformatted
, inquire
->unformatted
);
4510 INQUIRE_RESOLVE_TAG (&tag_s_recl
, inquire
->recl
);
4511 INQUIRE_RESOLVE_TAG (&tag_nextrec
, inquire
->nextrec
);
4512 INQUIRE_RESOLVE_TAG (&tag_s_blank
, inquire
->blank
);
4513 INQUIRE_RESOLVE_TAG (&tag_s_position
, inquire
->position
);
4514 INQUIRE_RESOLVE_TAG (&tag_s_action
, inquire
->action
);
4515 INQUIRE_RESOLVE_TAG (&tag_read
, inquire
->read
);
4516 INQUIRE_RESOLVE_TAG (&tag_write
, inquire
->write
);
4517 INQUIRE_RESOLVE_TAG (&tag_readwrite
, inquire
->readwrite
);
4518 INQUIRE_RESOLVE_TAG (&tag_s_delim
, inquire
->delim
);
4519 INQUIRE_RESOLVE_TAG (&tag_s_pad
, inquire
->pad
);
4520 INQUIRE_RESOLVE_TAG (&tag_s_encoding
, inquire
->encoding
);
4521 INQUIRE_RESOLVE_TAG (&tag_s_round
, inquire
->round
);
4522 INQUIRE_RESOLVE_TAG (&tag_iolength
, inquire
->iolength
);
4523 INQUIRE_RESOLVE_TAG (&tag_convert
, inquire
->convert
);
4524 INQUIRE_RESOLVE_TAG (&tag_strm_out
, inquire
->strm_pos
);
4525 INQUIRE_RESOLVE_TAG (&tag_s_async
, inquire
->asynchronous
);
4526 INQUIRE_RESOLVE_TAG (&tag_s_sign
, inquire
->sign
);
4527 INQUIRE_RESOLVE_TAG (&tag_s_round
, inquire
->round
);
4528 INQUIRE_RESOLVE_TAG (&tag_pending
, inquire
->pending
);
4529 INQUIRE_RESOLVE_TAG (&tag_size
, inquire
->size
);
4530 INQUIRE_RESOLVE_TAG (&tag_s_decimal
, inquire
->decimal
);
4531 INQUIRE_RESOLVE_TAG (&tag_s_iqstream
, inquire
->iqstream
);
4532 INQUIRE_RESOLVE_TAG (&tag_v_share
, inquire
->share
);
4533 INQUIRE_RESOLVE_TAG (&tag_v_cc
, inquire
->cc
);
4534 #undef INQUIRE_RESOLVE_TAG
4536 if (!gfc_reference_st_label (inquire
->err
, ST_LABEL_TARGET
))
4544 gfc_free_wait (gfc_wait
*wait
)
4549 gfc_free_expr (wait
->unit
);
4550 gfc_free_expr (wait
->iostat
);
4551 gfc_free_expr (wait
->iomsg
);
4552 gfc_free_expr (wait
->id
);
4558 gfc_resolve_wait (gfc_wait
*wait
)
4560 RESOLVE_TAG (&tag_unit
, wait
->unit
);
4561 RESOLVE_TAG (&tag_iomsg
, wait
->iomsg
);
4562 RESOLVE_TAG (&tag_iostat
, wait
->iostat
);
4563 RESOLVE_TAG (&tag_id
, wait
->id
);
4565 if (!gfc_reference_st_label (wait
->err
, ST_LABEL_TARGET
))
4568 if (!gfc_reference_st_label (wait
->end
, ST_LABEL_TARGET
))
4574 /* Match an element of a WAIT statement. */
4576 #define RETM if (m != MATCH_NO) return m;
4579 match_wait_element (gfc_wait
*wait
)
4583 m
= match_etag (&tag_unit
, &wait
->unit
);
4584 RETM m
= match_ltag (&tag_err
, &wait
->err
);
4585 RETM m
= match_ltag (&tag_end
, &wait
->eor
);
4586 RETM m
= match_ltag (&tag_eor
, &wait
->end
);
4587 RETM m
= match_etag (&tag_iomsg
, &wait
->iomsg
);
4588 if (m
== MATCH_YES
&& !check_char_variable (wait
->iomsg
))
4590 RETM m
= match_out_tag (&tag_iostat
, &wait
->iostat
);
4591 RETM m
= match_etag (&tag_id
, &wait
->id
);
4592 RETM
return MATCH_NO
;
4599 gfc_match_wait (void)
4604 m
= gfc_match_char ('(');
4608 wait
= XCNEW (gfc_wait
);
4610 m
= match_wait_element (wait
);
4611 if (m
== MATCH_ERROR
)
4615 m
= gfc_match_expr (&wait
->unit
);
4616 if (m
== MATCH_ERROR
)
4624 if (gfc_match_char (')') == MATCH_YES
)
4626 if (gfc_match_char (',') != MATCH_YES
)
4629 m
= match_wait_element (wait
);
4630 if (m
== MATCH_ERROR
)
4636 if (!gfc_notify_std (GFC_STD_F2003
, "WAIT at %C "
4637 "not allowed in Fortran 95"))
4640 if (gfc_pure (NULL
))
4642 gfc_error ("WAIT statement not allowed in PURE procedure at %C");
4646 gfc_unset_implicit_pure (NULL
);
4648 new_st
.op
= EXEC_WAIT
;
4649 new_st
.ext
.wait
= wait
;
4654 gfc_syntax_error (ST_WAIT
);
4657 gfc_free_wait (wait
);