1 /* Matching subroutines in all sizes, shapes and colors.
2 Copyright (C) 2000-2013 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 int gfc_matching_ptr_assignment
= 0;
31 int gfc_matching_procptr_assignment
= 0;
32 bool gfc_matching_prefix
= false;
34 /* Stack of SELECT TYPE statements. */
35 gfc_select_type_stack
*select_type_stack
= NULL
;
37 /* For debugging and diagnostic purposes. Return the textual representation
38 of the intrinsic operator OP. */
40 gfc_op2string (gfc_intrinsic_op op
)
48 case INTRINSIC_UMINUS
:
54 case INTRINSIC_CONCAT
:
58 case INTRINSIC_DIVIDE
:
97 case INTRINSIC_ASSIGN
:
100 case INTRINSIC_PARENTHESES
:
107 gfc_internal_error ("gfc_op2string(): Bad code");
112 /******************** Generic matching subroutines ************************/
114 /* This function scans the current statement counting the opened and closed
115 parenthesis to make sure they are balanced. */
118 gfc_match_parens (void)
120 locus old_loc
, where
;
122 gfc_instring instring
;
125 old_loc
= gfc_current_locus
;
127 instring
= NONSTRING
;
132 c
= gfc_next_char_literal (instring
);
135 if (quote
== ' ' && ((c
== '\'') || (c
== '"')))
138 instring
= INSTRING_WARN
;
141 if (quote
!= ' ' && c
== quote
)
144 instring
= NONSTRING
;
148 if (c
== '(' && quote
== ' ')
151 where
= gfc_current_locus
;
153 if (c
== ')' && quote
== ' ')
156 where
= gfc_current_locus
;
160 gfc_current_locus
= old_loc
;
164 gfc_error ("Missing ')' in statement at or before %L", &where
);
169 gfc_error ("Missing '(' in statement at or before %L", &where
);
177 /* See if the next character is a special character that has
178 escaped by a \ via the -fbackslash option. */
181 gfc_match_special_char (gfc_char_t
*res
)
189 switch ((c
= gfc_next_char_literal (INSTRING_WARN
)))
222 /* Hexadecimal form of wide characters. */
223 len
= (c
== 'x' ? 2 : (c
== 'u' ? 4 : 8));
225 for (i
= 0; i
< len
; i
++)
227 char buf
[2] = { '\0', '\0' };
229 c
= gfc_next_char_literal (INSTRING_WARN
);
230 if (!gfc_wide_fits_in_byte (c
)
231 || !gfc_check_digit ((unsigned char) c
, 16))
234 buf
[0] = (unsigned char) c
;
236 n
+= strtol (buf
, NULL
, 16);
242 /* Unknown backslash codes are simply not expanded. */
251 /* In free form, match at least one space. Always matches in fixed
255 gfc_match_space (void)
260 if (gfc_current_form
== FORM_FIXED
)
263 old_loc
= gfc_current_locus
;
265 c
= gfc_next_ascii_char ();
266 if (!gfc_is_whitespace (c
))
268 gfc_current_locus
= old_loc
;
272 gfc_gobble_whitespace ();
278 /* Match an end of statement. End of statement is optional
279 whitespace, followed by a ';' or '\n' or comment '!'. If a
280 semicolon is found, we continue to eat whitespace and semicolons. */
293 old_loc
= gfc_current_locus
;
294 gfc_gobble_whitespace ();
296 c
= gfc_next_ascii_char ();
302 c
= gfc_next_ascii_char ();
319 gfc_current_locus
= old_loc
;
320 return (flag
) ? MATCH_YES
: MATCH_NO
;
324 /* Match a literal integer on the input, setting the value on
325 MATCH_YES. Literal ints occur in kind-parameters as well as
326 old-style character length specifications. If cnt is non-NULL it
327 will be set to the number of digits. */
330 gfc_match_small_literal_int (int *value
, int *cnt
)
336 old_loc
= gfc_current_locus
;
339 gfc_gobble_whitespace ();
340 c
= gfc_next_ascii_char ();
346 gfc_current_locus
= old_loc
;
355 old_loc
= gfc_current_locus
;
356 c
= gfc_next_ascii_char ();
361 i
= 10 * i
+ c
- '0';
366 gfc_error ("Integer too large at %C");
371 gfc_current_locus
= old_loc
;
380 /* Match a small, constant integer expression, like in a kind
381 statement. On MATCH_YES, 'value' is set. */
384 gfc_match_small_int (int *value
)
391 m
= gfc_match_expr (&expr
);
395 p
= gfc_extract_int (expr
, &i
);
396 gfc_free_expr (expr
);
409 /* This function is the same as the gfc_match_small_int, except that
410 we're keeping the pointer to the expr. This function could just be
411 removed and the previously mentioned one modified, though all calls
412 to it would have to be modified then (and there were a number of
413 them). Return MATCH_ERROR if fail to extract the int; otherwise,
414 return the result of gfc_match_expr(). The expr (if any) that was
415 matched is returned in the parameter expr. */
418 gfc_match_small_int_expr (int *value
, gfc_expr
**expr
)
424 m
= gfc_match_expr (expr
);
428 p
= gfc_extract_int (*expr
, &i
);
441 /* Matches a statement label. Uses gfc_match_small_literal_int() to
442 do most of the work. */
445 gfc_match_st_label (gfc_st_label
**label
)
451 old_loc
= gfc_current_locus
;
453 m
= gfc_match_small_literal_int (&i
, &cnt
);
459 gfc_error ("Too many digits in statement label at %C");
465 gfc_error ("Statement label at %C is zero");
469 *label
= gfc_get_st_label (i
);
474 gfc_current_locus
= old_loc
;
479 /* Match and validate a label associated with a named IF, DO or SELECT
480 statement. If the symbol does not have the label attribute, we add
481 it. We also make sure the symbol does not refer to another
482 (active) block. A matched label is pointed to by gfc_new_block. */
485 gfc_match_label (void)
487 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
490 gfc_new_block
= NULL
;
492 m
= gfc_match (" %n :", name
);
496 if (gfc_get_symbol (name
, NULL
, &gfc_new_block
))
498 gfc_error ("Label name '%s' at %C is ambiguous", name
);
502 if (gfc_new_block
->attr
.flavor
== FL_LABEL
)
504 gfc_error ("Duplicate construct label '%s' at %C", name
);
508 if (gfc_add_flavor (&gfc_new_block
->attr
, FL_LABEL
,
509 gfc_new_block
->name
, NULL
) == FAILURE
)
516 /* See if the current input looks like a name of some sort. Modifies
517 the passed buffer which must be GFC_MAX_SYMBOL_LEN+1 bytes long.
518 Note that options.c restricts max_identifier_length to not more
519 than GFC_MAX_SYMBOL_LEN. */
522 gfc_match_name (char *buffer
)
528 old_loc
= gfc_current_locus
;
529 gfc_gobble_whitespace ();
531 c
= gfc_next_ascii_char ();
532 if (!(ISALPHA (c
) || (c
== '_' && gfc_option
.flag_allow_leading_underscore
)))
534 if (gfc_error_flag_test() == 0 && c
!= '(')
535 gfc_error ("Invalid character in name at %C");
536 gfc_current_locus
= old_loc
;
546 if (i
> gfc_option
.max_identifier_length
)
548 gfc_error ("Name at %C is too long");
552 old_loc
= gfc_current_locus
;
553 c
= gfc_next_ascii_char ();
555 while (ISALNUM (c
) || c
== '_' || (gfc_option
.flag_dollar_ok
&& c
== '$'));
557 if (c
== '$' && !gfc_option
.flag_dollar_ok
)
559 gfc_error ("Invalid character '$' at %C. Use -fdollar-ok to allow it "
565 gfc_current_locus
= old_loc
;
571 /* Match a valid name for C, which is almost the same as for Fortran,
572 except that you can start with an underscore, etc.. It could have
573 been done by modifying the gfc_match_name, but this way other
574 things C allows can be done, such as no limits on the length.
575 Also, by rewriting it, we use the gfc_next_char_C() to prevent the
576 input characters from being automatically lower cased, since C is
577 case sensitive. The parameter, buffer, is used to return the name
578 that is matched. Return MATCH_ERROR if the name is not a valid C
579 name, MATCH_NO if what we're seeing isn't a name, and MATCH_YES if
580 we successfully match a C name. */
583 gfc_match_name_C (const char **buffer
)
591 old_loc
= gfc_current_locus
;
592 gfc_gobble_whitespace ();
594 /* Get the next char (first possible char of name) and see if
595 it's valid for C (either a letter or an underscore). */
596 c
= gfc_next_char_literal (INSTRING_WARN
);
598 /* If the user put nothing expect spaces between the quotes, it is valid
599 and simply means there is no name= specifier and the name is the Fortran
600 symbol name, all lowercase. */
601 if (c
== '"' || c
== '\'')
603 gfc_current_locus
= old_loc
;
607 if (!ISALPHA (c
) && c
!= '_')
609 gfc_error ("Invalid C name in NAME= specifier at %C");
613 buf
= XNEWVEC (char, cursz
);
614 /* Continue to read valid variable name characters. */
617 gcc_assert (gfc_wide_fits_in_byte (c
));
619 buf
[i
++] = (unsigned char) c
;
624 buf
= XRESIZEVEC (char, buf
, cursz
);
627 old_loc
= gfc_current_locus
;
629 /* Get next char; param means we're in a string. */
630 c
= gfc_next_char_literal (INSTRING_WARN
);
631 } while (ISALNUM (c
) || c
== '_');
633 /* The binding label will be needed later anyway, so just insert it
634 into the symbol table. */
636 *buffer
= IDENTIFIER_POINTER (get_identifier (buf
));
638 gfc_current_locus
= old_loc
;
640 /* See if we stopped because of whitespace. */
643 gfc_gobble_whitespace ();
644 c
= gfc_peek_ascii_char ();
645 if (c
!= '"' && c
!= '\'')
647 gfc_error ("Embedded space in NAME= specifier at %C");
652 /* If we stopped because we had an invalid character for a C name, report
653 that to the user by returning MATCH_NO. */
654 if (c
!= '"' && c
!= '\'')
656 gfc_error ("Invalid C name in NAME= specifier at %C");
664 /* Match a symbol on the input. Modifies the pointer to the symbol
665 pointer if successful. */
668 gfc_match_sym_tree (gfc_symtree
**matched_symbol
, int host_assoc
)
670 char buffer
[GFC_MAX_SYMBOL_LEN
+ 1];
673 m
= gfc_match_name (buffer
);
678 return (gfc_get_ha_sym_tree (buffer
, matched_symbol
))
679 ? MATCH_ERROR
: MATCH_YES
;
681 if (gfc_get_sym_tree (buffer
, NULL
, matched_symbol
, false))
689 gfc_match_symbol (gfc_symbol
**matched_symbol
, int host_assoc
)
694 m
= gfc_match_sym_tree (&st
, host_assoc
);
699 *matched_symbol
= st
->n
.sym
;
701 *matched_symbol
= NULL
;
704 *matched_symbol
= NULL
;
709 /* Match an intrinsic operator. Returns an INTRINSIC enum. While matching,
710 we always find INTRINSIC_PLUS before INTRINSIC_UPLUS. We work around this
714 gfc_match_intrinsic_op (gfc_intrinsic_op
*result
)
716 locus orig_loc
= gfc_current_locus
;
719 gfc_gobble_whitespace ();
720 ch
= gfc_next_ascii_char ();
725 *result
= INTRINSIC_PLUS
;
730 *result
= INTRINSIC_MINUS
;
734 if (gfc_next_ascii_char () == '=')
737 *result
= INTRINSIC_EQ
;
743 if (gfc_peek_ascii_char () == '=')
746 gfc_next_ascii_char ();
747 *result
= INTRINSIC_LE
;
751 *result
= INTRINSIC_LT
;
755 if (gfc_peek_ascii_char () == '=')
758 gfc_next_ascii_char ();
759 *result
= INTRINSIC_GE
;
763 *result
= INTRINSIC_GT
;
767 if (gfc_peek_ascii_char () == '*')
770 gfc_next_ascii_char ();
771 *result
= INTRINSIC_POWER
;
775 *result
= INTRINSIC_TIMES
;
779 ch
= gfc_peek_ascii_char ();
783 gfc_next_ascii_char ();
784 *result
= INTRINSIC_NE
;
790 gfc_next_ascii_char ();
791 *result
= INTRINSIC_CONCAT
;
795 *result
= INTRINSIC_DIVIDE
;
799 ch
= gfc_next_ascii_char ();
803 if (gfc_next_ascii_char () == 'n'
804 && gfc_next_ascii_char () == 'd'
805 && gfc_next_ascii_char () == '.')
807 /* Matched ".and.". */
808 *result
= INTRINSIC_AND
;
814 if (gfc_next_ascii_char () == 'q')
816 ch
= gfc_next_ascii_char ();
819 /* Matched ".eq.". */
820 *result
= INTRINSIC_EQ_OS
;
825 if (gfc_next_ascii_char () == '.')
827 /* Matched ".eqv.". */
828 *result
= INTRINSIC_EQV
;
836 ch
= gfc_next_ascii_char ();
839 if (gfc_next_ascii_char () == '.')
841 /* Matched ".ge.". */
842 *result
= INTRINSIC_GE_OS
;
848 if (gfc_next_ascii_char () == '.')
850 /* Matched ".gt.". */
851 *result
= INTRINSIC_GT_OS
;
858 ch
= gfc_next_ascii_char ();
861 if (gfc_next_ascii_char () == '.')
863 /* Matched ".le.". */
864 *result
= INTRINSIC_LE_OS
;
870 if (gfc_next_ascii_char () == '.')
872 /* Matched ".lt.". */
873 *result
= INTRINSIC_LT_OS
;
880 ch
= gfc_next_ascii_char ();
883 ch
= gfc_next_ascii_char ();
886 /* Matched ".ne.". */
887 *result
= INTRINSIC_NE_OS
;
892 if (gfc_next_ascii_char () == 'v'
893 && gfc_next_ascii_char () == '.')
895 /* Matched ".neqv.". */
896 *result
= INTRINSIC_NEQV
;
903 if (gfc_next_ascii_char () == 't'
904 && gfc_next_ascii_char () == '.')
906 /* Matched ".not.". */
907 *result
= INTRINSIC_NOT
;
914 if (gfc_next_ascii_char () == 'r'
915 && gfc_next_ascii_char () == '.')
917 /* Matched ".or.". */
918 *result
= INTRINSIC_OR
;
932 gfc_current_locus
= orig_loc
;
937 /* Match a loop control phrase:
939 <LVALUE> = <EXPR>, <EXPR> [, <EXPR> ]
941 If the final integer expression is not present, a constant unity
942 expression is returned. We don't return MATCH_ERROR until after
943 the equals sign is seen. */
946 gfc_match_iterator (gfc_iterator
*iter
, int init_flag
)
948 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
949 gfc_expr
*var
, *e1
, *e2
, *e3
;
955 /* Match the start of an iterator without affecting the symbol table. */
957 start
= gfc_current_locus
;
958 m
= gfc_match (" %n =", name
);
959 gfc_current_locus
= start
;
964 m
= gfc_match_variable (&var
, 0);
968 /* F2008, C617 & C565. */
969 if (var
->symtree
->n
.sym
->attr
.codimension
)
971 gfc_error ("Loop variable at %C cannot be a coarray");
975 if (var
->ref
!= NULL
)
977 gfc_error ("Loop variable at %C cannot be a sub-component");
981 gfc_match_char ('=');
983 var
->symtree
->n
.sym
->attr
.implied_index
= 1;
985 m
= init_flag
? gfc_match_init_expr (&e1
) : gfc_match_expr (&e1
);
988 if (m
== MATCH_ERROR
)
991 if (gfc_match_char (',') != MATCH_YES
)
994 m
= init_flag
? gfc_match_init_expr (&e2
) : gfc_match_expr (&e2
);
997 if (m
== MATCH_ERROR
)
1000 if (gfc_match_char (',') != MATCH_YES
)
1002 e3
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
1006 m
= init_flag
? gfc_match_init_expr (&e3
) : gfc_match_expr (&e3
);
1007 if (m
== MATCH_ERROR
)
1011 gfc_error ("Expected a step value in iterator at %C");
1023 gfc_error ("Syntax error in iterator at %C");
1034 /* Tries to match the next non-whitespace character on the input.
1035 This subroutine does not return MATCH_ERROR. */
1038 gfc_match_char (char c
)
1042 where
= gfc_current_locus
;
1043 gfc_gobble_whitespace ();
1045 if (gfc_next_ascii_char () == c
)
1048 gfc_current_locus
= where
;
1053 /* General purpose matching subroutine. The target string is a
1054 scanf-like format string in which spaces correspond to arbitrary
1055 whitespace (including no whitespace), characters correspond to
1056 themselves. The %-codes are:
1058 %% Literal percent sign
1059 %e Expression, pointer to a pointer is set
1060 %s Symbol, pointer to the symbol is set
1061 %n Name, character buffer is set to name
1062 %t Matches end of statement.
1063 %o Matches an intrinsic operator, returned as an INTRINSIC enum.
1064 %l Matches a statement label
1065 %v Matches a variable expression (an lvalue)
1066 % Matches a required space (in free form) and optional spaces. */
1069 gfc_match (const char *target
, ...)
1071 gfc_st_label
**label
;
1080 old_loc
= gfc_current_locus
;
1081 va_start (argp
, target
);
1091 gfc_gobble_whitespace ();
1102 vp
= va_arg (argp
, void **);
1103 n
= gfc_match_expr ((gfc_expr
**) vp
);
1114 vp
= va_arg (argp
, void **);
1115 n
= gfc_match_variable ((gfc_expr
**) vp
, 0);
1126 vp
= va_arg (argp
, void **);
1127 n
= gfc_match_symbol ((gfc_symbol
**) vp
, 0);
1138 np
= va_arg (argp
, char *);
1139 n
= gfc_match_name (np
);
1150 label
= va_arg (argp
, gfc_st_label
**);
1151 n
= gfc_match_st_label (label
);
1162 ip
= va_arg (argp
, int *);
1163 n
= gfc_match_intrinsic_op ((gfc_intrinsic_op
*) ip
);
1174 if (gfc_match_eos () != MATCH_YES
)
1182 if (gfc_match_space () == MATCH_YES
)
1188 break; /* Fall through to character matcher. */
1191 gfc_internal_error ("gfc_match(): Bad match code %c", c
);
1196 /* gfc_next_ascii_char converts characters to lower-case, so we shouldn't
1197 expect an upper case character here! */
1198 gcc_assert (TOLOWER (c
) == c
);
1200 if (c
== gfc_next_ascii_char ())
1210 /* Clean up after a failed match. */
1211 gfc_current_locus
= old_loc
;
1212 va_start (argp
, target
);
1215 for (; matches
> 0; matches
--)
1217 while (*p
++ != '%');
1225 /* Matches that don't have to be undone */
1230 (void) va_arg (argp
, void **);
1235 vp
= va_arg (argp
, void **);
1236 gfc_free_expr ((struct gfc_expr
*)*vp
);
1249 /*********************** Statement level matching **********************/
1251 /* Matches the start of a program unit, which is the program keyword
1252 followed by an obligatory symbol. */
1255 gfc_match_program (void)
1260 m
= gfc_match ("% %s%t", &sym
);
1264 gfc_error ("Invalid form of PROGRAM statement at %C");
1268 if (m
== MATCH_ERROR
)
1271 if (gfc_add_flavor (&sym
->attr
, FL_PROGRAM
, sym
->name
, NULL
) == FAILURE
)
1274 gfc_new_block
= sym
;
1280 /* Match a simple assignment statement. */
1283 gfc_match_assignment (void)
1285 gfc_expr
*lvalue
, *rvalue
;
1289 old_loc
= gfc_current_locus
;
1292 m
= gfc_match (" %v =", &lvalue
);
1295 gfc_current_locus
= old_loc
;
1296 gfc_free_expr (lvalue
);
1301 m
= gfc_match (" %e%t", &rvalue
);
1304 gfc_current_locus
= old_loc
;
1305 gfc_free_expr (lvalue
);
1306 gfc_free_expr (rvalue
);
1310 gfc_set_sym_referenced (lvalue
->symtree
->n
.sym
);
1312 new_st
.op
= EXEC_ASSIGN
;
1313 new_st
.expr1
= lvalue
;
1314 new_st
.expr2
= rvalue
;
1316 gfc_check_do_variable (lvalue
->symtree
);
1322 /* Match a pointer assignment statement. */
1325 gfc_match_pointer_assignment (void)
1327 gfc_expr
*lvalue
, *rvalue
;
1331 old_loc
= gfc_current_locus
;
1333 lvalue
= rvalue
= NULL
;
1334 gfc_matching_ptr_assignment
= 0;
1335 gfc_matching_procptr_assignment
= 0;
1337 m
= gfc_match (" %v =>", &lvalue
);
1344 if (lvalue
->symtree
->n
.sym
->attr
.proc_pointer
1345 || gfc_is_proc_ptr_comp (lvalue
))
1346 gfc_matching_procptr_assignment
= 1;
1348 gfc_matching_ptr_assignment
= 1;
1350 m
= gfc_match (" %e%t", &rvalue
);
1351 gfc_matching_ptr_assignment
= 0;
1352 gfc_matching_procptr_assignment
= 0;
1356 new_st
.op
= EXEC_POINTER_ASSIGN
;
1357 new_st
.expr1
= lvalue
;
1358 new_st
.expr2
= rvalue
;
1363 gfc_current_locus
= old_loc
;
1364 gfc_free_expr (lvalue
);
1365 gfc_free_expr (rvalue
);
1370 /* We try to match an easy arithmetic IF statement. This only happens
1371 when just after having encountered a simple IF statement. This code
1372 is really duplicate with parts of the gfc_match_if code, but this is
1376 match_arithmetic_if (void)
1378 gfc_st_label
*l1
, *l2
, *l3
;
1382 m
= gfc_match (" ( %e ) %l , %l , %l%t", &expr
, &l1
, &l2
, &l3
);
1386 if (gfc_reference_st_label (l1
, ST_LABEL_TARGET
) == FAILURE
1387 || gfc_reference_st_label (l2
, ST_LABEL_TARGET
) == FAILURE
1388 || gfc_reference_st_label (l3
, ST_LABEL_TARGET
) == FAILURE
)
1390 gfc_free_expr (expr
);
1394 if (gfc_notify_std (GFC_STD_F95_OBS
, "Arithmetic IF "
1395 "statement at %C") == FAILURE
)
1398 new_st
.op
= EXEC_ARITHMETIC_IF
;
1399 new_st
.expr1
= expr
;
1408 /* The IF statement is a bit of a pain. First of all, there are three
1409 forms of it, the simple IF, the IF that starts a block and the
1412 There is a problem with the simple IF and that is the fact that we
1413 only have a single level of undo information on symbols. What this
1414 means is for a simple IF, we must re-match the whole IF statement
1415 multiple times in order to guarantee that the symbol table ends up
1416 in the proper state. */
1418 static match
match_simple_forall (void);
1419 static match
match_simple_where (void);
1422 gfc_match_if (gfc_statement
*if_type
)
1425 gfc_st_label
*l1
, *l2
, *l3
;
1426 locus old_loc
, old_loc2
;
1430 n
= gfc_match_label ();
1431 if (n
== MATCH_ERROR
)
1434 old_loc
= gfc_current_locus
;
1436 m
= gfc_match (" if ( %e", &expr
);
1440 old_loc2
= gfc_current_locus
;
1441 gfc_current_locus
= old_loc
;
1443 if (gfc_match_parens () == MATCH_ERROR
)
1446 gfc_current_locus
= old_loc2
;
1448 if (gfc_match_char (')') != MATCH_YES
)
1450 gfc_error ("Syntax error in IF-expression at %C");
1451 gfc_free_expr (expr
);
1455 m
= gfc_match (" %l , %l , %l%t", &l1
, &l2
, &l3
);
1461 gfc_error ("Block label not appropriate for arithmetic IF "
1463 gfc_free_expr (expr
);
1467 if (gfc_reference_st_label (l1
, ST_LABEL_TARGET
) == FAILURE
1468 || gfc_reference_st_label (l2
, ST_LABEL_TARGET
) == FAILURE
1469 || gfc_reference_st_label (l3
, ST_LABEL_TARGET
) == FAILURE
)
1471 gfc_free_expr (expr
);
1475 if (gfc_notify_std (GFC_STD_F95_OBS
, "Arithmetic IF "
1476 "statement at %C") == FAILURE
)
1479 new_st
.op
= EXEC_ARITHMETIC_IF
;
1480 new_st
.expr1
= expr
;
1485 *if_type
= ST_ARITHMETIC_IF
;
1489 if (gfc_match (" then%t") == MATCH_YES
)
1491 new_st
.op
= EXEC_IF
;
1492 new_st
.expr1
= expr
;
1493 *if_type
= ST_IF_BLOCK
;
1499 gfc_error ("Block label is not appropriate for IF statement at %C");
1500 gfc_free_expr (expr
);
1504 /* At this point the only thing left is a simple IF statement. At
1505 this point, n has to be MATCH_NO, so we don't have to worry about
1506 re-matching a block label. From what we've got so far, try
1507 matching an assignment. */
1509 *if_type
= ST_SIMPLE_IF
;
1511 m
= gfc_match_assignment ();
1515 gfc_free_expr (expr
);
1516 gfc_undo_symbols ();
1517 gfc_current_locus
= old_loc
;
1519 /* m can be MATCH_NO or MATCH_ERROR, here. For MATCH_ERROR, a mangled
1520 assignment was found. For MATCH_NO, continue to call the various
1522 if (m
== MATCH_ERROR
)
1525 gfc_match (" if ( %e ) ", &expr
); /* Guaranteed to match. */
1527 m
= gfc_match_pointer_assignment ();
1531 gfc_free_expr (expr
);
1532 gfc_undo_symbols ();
1533 gfc_current_locus
= old_loc
;
1535 gfc_match (" if ( %e ) ", &expr
); /* Guaranteed to match. */
1537 /* Look at the next keyword to see which matcher to call. Matching
1538 the keyword doesn't affect the symbol table, so we don't have to
1539 restore between tries. */
1541 #define match(string, subr, statement) \
1542 if (gfc_match(string) == MATCH_YES) { m = subr(); goto got_match; }
1546 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
)
1547 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
)
1548 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
)
1549 match ("call", gfc_match_call
, ST_CALL
)
1550 match ("close", gfc_match_close
, ST_CLOSE
)
1551 match ("continue", gfc_match_continue
, ST_CONTINUE
)
1552 match ("cycle", gfc_match_cycle
, ST_CYCLE
)
1553 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
)
1554 match ("end file", gfc_match_endfile
, ST_END_FILE
)
1555 match ("error stop", gfc_match_error_stop
, ST_ERROR_STOP
)
1556 match ("exit", gfc_match_exit
, ST_EXIT
)
1557 match ("flush", gfc_match_flush
, ST_FLUSH
)
1558 match ("forall", match_simple_forall
, ST_FORALL
)
1559 match ("go to", gfc_match_goto
, ST_GOTO
)
1560 match ("if", match_arithmetic_if
, ST_ARITHMETIC_IF
)
1561 match ("inquire", gfc_match_inquire
, ST_INQUIRE
)
1562 match ("lock", gfc_match_lock
, ST_LOCK
)
1563 match ("nullify", gfc_match_nullify
, ST_NULLIFY
)
1564 match ("open", gfc_match_open
, ST_OPEN
)
1565 match ("pause", gfc_match_pause
, ST_NONE
)
1566 match ("print", gfc_match_print
, ST_WRITE
)
1567 match ("read", gfc_match_read
, ST_READ
)
1568 match ("return", gfc_match_return
, ST_RETURN
)
1569 match ("rewind", gfc_match_rewind
, ST_REWIND
)
1570 match ("stop", gfc_match_stop
, ST_STOP
)
1571 match ("wait", gfc_match_wait
, ST_WAIT
)
1572 match ("sync all", gfc_match_sync_all
, ST_SYNC_CALL
);
1573 match ("sync images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
1574 match ("sync memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
1575 match ("unlock", gfc_match_unlock
, ST_UNLOCK
)
1576 match ("where", match_simple_where
, ST_WHERE
)
1577 match ("write", gfc_match_write
, ST_WRITE
)
1579 /* The gfc_match_assignment() above may have returned a MATCH_NO
1580 where the assignment was to a named constant. Check that
1581 special case here. */
1582 m
= gfc_match_assignment ();
1585 gfc_error ("Cannot assign to a named constant at %C");
1586 gfc_free_expr (expr
);
1587 gfc_undo_symbols ();
1588 gfc_current_locus
= old_loc
;
1592 /* All else has failed, so give up. See if any of the matchers has
1593 stored an error message of some sort. */
1594 if (gfc_error_check () == 0)
1595 gfc_error ("Unclassifiable statement in IF-clause at %C");
1597 gfc_free_expr (expr
);
1602 gfc_error ("Syntax error in IF-clause at %C");
1605 gfc_free_expr (expr
);
1609 /* At this point, we've matched the single IF and the action clause
1610 is in new_st. Rearrange things so that the IF statement appears
1613 p
= gfc_get_code ();
1614 p
->next
= gfc_get_code ();
1616 p
->next
->loc
= gfc_current_locus
;
1621 gfc_clear_new_st ();
1623 new_st
.op
= EXEC_IF
;
1632 /* Match an ELSE statement. */
1635 gfc_match_else (void)
1637 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
1639 if (gfc_match_eos () == MATCH_YES
)
1642 if (gfc_match_name (name
) != MATCH_YES
1643 || gfc_current_block () == NULL
1644 || gfc_match_eos () != MATCH_YES
)
1646 gfc_error ("Unexpected junk after ELSE statement at %C");
1650 if (strcmp (name
, gfc_current_block ()->name
) != 0)
1652 gfc_error ("Label '%s' at %C doesn't match IF label '%s'",
1653 name
, gfc_current_block ()->name
);
1661 /* Match an ELSE IF statement. */
1664 gfc_match_elseif (void)
1666 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
1670 m
= gfc_match (" ( %e ) then", &expr
);
1674 if (gfc_match_eos () == MATCH_YES
)
1677 if (gfc_match_name (name
) != MATCH_YES
1678 || gfc_current_block () == NULL
1679 || gfc_match_eos () != MATCH_YES
)
1681 gfc_error ("Unexpected junk after ELSE IF statement at %C");
1685 if (strcmp (name
, gfc_current_block ()->name
) != 0)
1687 gfc_error ("Label '%s' at %C doesn't match IF label '%s'",
1688 name
, gfc_current_block ()->name
);
1693 new_st
.op
= EXEC_IF
;
1694 new_st
.expr1
= expr
;
1698 gfc_free_expr (expr
);
1703 /* Free a gfc_iterator structure. */
1706 gfc_free_iterator (gfc_iterator
*iter
, int flag
)
1712 gfc_free_expr (iter
->var
);
1713 gfc_free_expr (iter
->start
);
1714 gfc_free_expr (iter
->end
);
1715 gfc_free_expr (iter
->step
);
1722 /* Match a CRITICAL statement. */
1724 gfc_match_critical (void)
1726 gfc_st_label
*label
= NULL
;
1728 if (gfc_match_label () == MATCH_ERROR
)
1731 if (gfc_match (" critical") != MATCH_YES
)
1734 if (gfc_match_st_label (&label
) == MATCH_ERROR
)
1737 if (gfc_match_eos () != MATCH_YES
)
1739 gfc_syntax_error (ST_CRITICAL
);
1743 if (gfc_pure (NULL
))
1745 gfc_error ("Image control statement CRITICAL at %C in PURE procedure");
1749 if (gfc_find_state (COMP_DO_CONCURRENT
) == SUCCESS
)
1751 gfc_error ("Image control statement CRITICAL at %C in DO CONCURRENT "
1756 if (gfc_implicit_pure (NULL
))
1757 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
1759 if (gfc_notify_std (GFC_STD_F2008
, "CRITICAL statement at %C")
1763 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
1765 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
1769 if (gfc_find_state (COMP_CRITICAL
) == SUCCESS
)
1771 gfc_error ("Nested CRITICAL block at %C");
1775 new_st
.op
= EXEC_CRITICAL
;
1778 && gfc_reference_st_label (label
, ST_LABEL_TARGET
) == FAILURE
)
1785 /* Match a BLOCK statement. */
1788 gfc_match_block (void)
1792 if (gfc_match_label () == MATCH_ERROR
)
1795 if (gfc_match (" block") != MATCH_YES
)
1798 /* For this to be a correct BLOCK statement, the line must end now. */
1799 m
= gfc_match_eos ();
1800 if (m
== MATCH_ERROR
)
1809 /* Match an ASSOCIATE statement. */
1812 gfc_match_associate (void)
1814 if (gfc_match_label () == MATCH_ERROR
)
1817 if (gfc_match (" associate") != MATCH_YES
)
1820 /* Match the association list. */
1821 if (gfc_match_char ('(') != MATCH_YES
)
1823 gfc_error ("Expected association list at %C");
1826 new_st
.ext
.block
.assoc
= NULL
;
1829 gfc_association_list
* newAssoc
= gfc_get_association_list ();
1830 gfc_association_list
* a
;
1832 /* Match the next association. */
1833 if (gfc_match (" %n => %e", newAssoc
->name
, &newAssoc
->target
)
1836 gfc_error ("Expected association at %C");
1837 goto assocListError
;
1839 newAssoc
->where
= gfc_current_locus
;
1841 /* Check that the current name is not yet in the list. */
1842 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
1843 if (!strcmp (a
->name
, newAssoc
->name
))
1845 gfc_error ("Duplicate name '%s' in association at %C",
1847 goto assocListError
;
1850 /* The target expression must not be coindexed. */
1851 if (gfc_is_coindexed (newAssoc
->target
))
1853 gfc_error ("Association target at %C must not be coindexed");
1854 goto assocListError
;
1857 /* The `variable' field is left blank for now; because the target is not
1858 yet resolved, we can't use gfc_has_vector_subscript to determine it
1859 for now. This is set during resolution. */
1861 /* Put it into the list. */
1862 newAssoc
->next
= new_st
.ext
.block
.assoc
;
1863 new_st
.ext
.block
.assoc
= newAssoc
;
1865 /* Try next one or end if closing parenthesis is found. */
1866 gfc_gobble_whitespace ();
1867 if (gfc_peek_char () == ')')
1869 if (gfc_match_char (',') != MATCH_YES
)
1871 gfc_error ("Expected ')' or ',' at %C");
1881 if (gfc_match_char (')') != MATCH_YES
)
1883 /* This should never happen as we peek above. */
1887 if (gfc_match_eos () != MATCH_YES
)
1889 gfc_error ("Junk after ASSOCIATE statement at %C");
1896 gfc_free_association_list (new_st
.ext
.block
.assoc
);
1901 /* Match a Fortran 2003 derived-type-spec (F03:R455), which is just the name of
1902 an accessible derived type. */
1905 match_derived_type_spec (gfc_typespec
*ts
)
1907 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
1909 gfc_symbol
*derived
;
1911 old_locus
= gfc_current_locus
;
1913 if (gfc_match ("%n", name
) != MATCH_YES
)
1915 gfc_current_locus
= old_locus
;
1919 gfc_find_symbol (name
, NULL
, 1, &derived
);
1921 if (derived
&& derived
->attr
.flavor
== FL_PROCEDURE
&& derived
->attr
.generic
)
1922 derived
= gfc_find_dt_in_generic (derived
);
1924 if (derived
&& derived
->attr
.flavor
== FL_DERIVED
)
1926 ts
->type
= BT_DERIVED
;
1927 ts
->u
.derived
= derived
;
1931 gfc_current_locus
= old_locus
;
1936 /* Match a Fortran 2003 type-spec (F03:R401). This is similar to
1937 gfc_match_decl_type_spec() from decl.c, with the following exceptions:
1938 It only includes the intrinsic types from the Fortran 2003 standard
1939 (thus, neither BYTE nor forms like REAL*4 are allowed). Additionally,
1940 the implicit_flag is not needed, so it was removed. Derived types are
1941 identified by their name alone. */
1944 match_type_spec (gfc_typespec
*ts
)
1950 gfc_gobble_whitespace ();
1951 old_locus
= gfc_current_locus
;
1953 if (match_derived_type_spec (ts
) == MATCH_YES
)
1955 /* Enforce F03:C401. */
1956 if (ts
->u
.derived
->attr
.abstract
)
1958 gfc_error ("Derived type '%s' at %L may not be ABSTRACT",
1959 ts
->u
.derived
->name
, &old_locus
);
1965 if (gfc_match ("integer") == MATCH_YES
)
1967 ts
->type
= BT_INTEGER
;
1968 ts
->kind
= gfc_default_integer_kind
;
1972 if (gfc_match ("real") == MATCH_YES
)
1975 ts
->kind
= gfc_default_real_kind
;
1979 if (gfc_match ("double precision") == MATCH_YES
)
1982 ts
->kind
= gfc_default_double_kind
;
1986 if (gfc_match ("complex") == MATCH_YES
)
1988 ts
->type
= BT_COMPLEX
;
1989 ts
->kind
= gfc_default_complex_kind
;
1993 if (gfc_match ("character") == MATCH_YES
)
1995 ts
->type
= BT_CHARACTER
;
1997 m
= gfc_match_char_spec (ts
);
2005 if (gfc_match ("logical") == MATCH_YES
)
2007 ts
->type
= BT_LOGICAL
;
2008 ts
->kind
= gfc_default_logical_kind
;
2012 /* If a type is not matched, simply return MATCH_NO. */
2013 gfc_current_locus
= old_locus
;
2018 gfc_gobble_whitespace ();
2019 if (gfc_peek_ascii_char () == '*')
2021 gfc_error ("Invalid type-spec at %C");
2025 m
= gfc_match_kind_spec (ts
, false);
2028 m
= MATCH_YES
; /* No kind specifier found. */
2034 /******************** FORALL subroutines ********************/
2036 /* Free a list of FORALL iterators. */
2039 gfc_free_forall_iterator (gfc_forall_iterator
*iter
)
2041 gfc_forall_iterator
*next
;
2046 gfc_free_expr (iter
->var
);
2047 gfc_free_expr (iter
->start
);
2048 gfc_free_expr (iter
->end
);
2049 gfc_free_expr (iter
->stride
);
2056 /* Match an iterator as part of a FORALL statement. The format is:
2058 <var> = <start>:<end>[:<stride>]
2060 On MATCH_NO, the caller tests for the possibility that there is a
2061 scalar mask expression. */
2064 match_forall_iterator (gfc_forall_iterator
**result
)
2066 gfc_forall_iterator
*iter
;
2070 where
= gfc_current_locus
;
2071 iter
= XCNEW (gfc_forall_iterator
);
2073 m
= gfc_match_expr (&iter
->var
);
2077 if (gfc_match_char ('=') != MATCH_YES
2078 || iter
->var
->expr_type
!= EXPR_VARIABLE
)
2084 m
= gfc_match_expr (&iter
->start
);
2088 if (gfc_match_char (':') != MATCH_YES
)
2091 m
= gfc_match_expr (&iter
->end
);
2094 if (m
== MATCH_ERROR
)
2097 if (gfc_match_char (':') == MATCH_NO
)
2098 iter
->stride
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
2101 m
= gfc_match_expr (&iter
->stride
);
2104 if (m
== MATCH_ERROR
)
2108 /* Mark the iteration variable's symbol as used as a FORALL index. */
2109 iter
->var
->symtree
->n
.sym
->forall_index
= true;
2115 gfc_error ("Syntax error in FORALL iterator at %C");
2120 gfc_current_locus
= where
;
2121 gfc_free_forall_iterator (iter
);
2126 /* Match the header of a FORALL statement. */
2129 match_forall_header (gfc_forall_iterator
**phead
, gfc_expr
**mask
)
2131 gfc_forall_iterator
*head
, *tail
, *new_iter
;
2135 gfc_gobble_whitespace ();
2140 if (gfc_match_char ('(') != MATCH_YES
)
2143 m
= match_forall_iterator (&new_iter
);
2144 if (m
== MATCH_ERROR
)
2149 head
= tail
= new_iter
;
2153 if (gfc_match_char (',') != MATCH_YES
)
2156 m
= match_forall_iterator (&new_iter
);
2157 if (m
== MATCH_ERROR
)
2162 tail
->next
= new_iter
;
2167 /* Have to have a mask expression. */
2169 m
= gfc_match_expr (&msk
);
2172 if (m
== MATCH_ERROR
)
2178 if (gfc_match_char (')') == MATCH_NO
)
2186 gfc_syntax_error (ST_FORALL
);
2189 gfc_free_expr (msk
);
2190 gfc_free_forall_iterator (head
);
2195 /* Match the rest of a simple FORALL statement that follows an
2199 match_simple_forall (void)
2201 gfc_forall_iterator
*head
;
2210 m
= match_forall_header (&head
, &mask
);
2217 m
= gfc_match_assignment ();
2219 if (m
== MATCH_ERROR
)
2223 m
= gfc_match_pointer_assignment ();
2224 if (m
== MATCH_ERROR
)
2230 c
= gfc_get_code ();
2232 c
->loc
= gfc_current_locus
;
2234 if (gfc_match_eos () != MATCH_YES
)
2237 gfc_clear_new_st ();
2238 new_st
.op
= EXEC_FORALL
;
2239 new_st
.expr1
= mask
;
2240 new_st
.ext
.forall_iterator
= head
;
2241 new_st
.block
= gfc_get_code ();
2243 new_st
.block
->op
= EXEC_FORALL
;
2244 new_st
.block
->next
= c
;
2249 gfc_syntax_error (ST_FORALL
);
2252 gfc_free_forall_iterator (head
);
2253 gfc_free_expr (mask
);
2259 /* Match a FORALL statement. */
2262 gfc_match_forall (gfc_statement
*st
)
2264 gfc_forall_iterator
*head
;
2273 m0
= gfc_match_label ();
2274 if (m0
== MATCH_ERROR
)
2277 m
= gfc_match (" forall");
2281 m
= match_forall_header (&head
, &mask
);
2282 if (m
== MATCH_ERROR
)
2287 if (gfc_match_eos () == MATCH_YES
)
2289 *st
= ST_FORALL_BLOCK
;
2290 new_st
.op
= EXEC_FORALL
;
2291 new_st
.expr1
= mask
;
2292 new_st
.ext
.forall_iterator
= head
;
2296 m
= gfc_match_assignment ();
2297 if (m
== MATCH_ERROR
)
2301 m
= gfc_match_pointer_assignment ();
2302 if (m
== MATCH_ERROR
)
2308 c
= gfc_get_code ();
2310 c
->loc
= gfc_current_locus
;
2312 gfc_clear_new_st ();
2313 new_st
.op
= EXEC_FORALL
;
2314 new_st
.expr1
= mask
;
2315 new_st
.ext
.forall_iterator
= head
;
2316 new_st
.block
= gfc_get_code ();
2317 new_st
.block
->op
= EXEC_FORALL
;
2318 new_st
.block
->next
= c
;
2324 gfc_syntax_error (ST_FORALL
);
2327 gfc_free_forall_iterator (head
);
2328 gfc_free_expr (mask
);
2329 gfc_free_statements (c
);
2334 /* Match a DO statement. */
2339 gfc_iterator iter
, *ip
;
2341 gfc_st_label
*label
;
2344 old_loc
= gfc_current_locus
;
2347 iter
.var
= iter
.start
= iter
.end
= iter
.step
= NULL
;
2349 m
= gfc_match_label ();
2350 if (m
== MATCH_ERROR
)
2353 if (gfc_match (" do") != MATCH_YES
)
2356 m
= gfc_match_st_label (&label
);
2357 if (m
== MATCH_ERROR
)
2360 /* Match an infinite DO, make it like a DO WHILE(.TRUE.). */
2362 if (gfc_match_eos () == MATCH_YES
)
2364 iter
.end
= gfc_get_logical_expr (gfc_default_logical_kind
, NULL
, true);
2365 new_st
.op
= EXEC_DO_WHILE
;
2369 /* Match an optional comma, if no comma is found, a space is obligatory. */
2370 if (gfc_match_char (',') != MATCH_YES
&& gfc_match ("% ") != MATCH_YES
)
2373 /* Check for balanced parens. */
2375 if (gfc_match_parens () == MATCH_ERROR
)
2378 if (gfc_match (" concurrent") == MATCH_YES
)
2380 gfc_forall_iterator
*head
;
2383 if (gfc_notify_std (GFC_STD_F2008
, "DO CONCURRENT "
2384 "construct at %C") == FAILURE
)
2390 m
= match_forall_header (&head
, &mask
);
2394 if (m
== MATCH_ERROR
)
2395 goto concurr_cleanup
;
2397 if (gfc_match_eos () != MATCH_YES
)
2398 goto concurr_cleanup
;
2401 && gfc_reference_st_label (label
, ST_LABEL_DO_TARGET
) == FAILURE
)
2402 goto concurr_cleanup
;
2404 new_st
.label1
= label
;
2405 new_st
.op
= EXEC_DO_CONCURRENT
;
2406 new_st
.expr1
= mask
;
2407 new_st
.ext
.forall_iterator
= head
;
2412 gfc_syntax_error (ST_DO
);
2413 gfc_free_expr (mask
);
2414 gfc_free_forall_iterator (head
);
2418 /* See if we have a DO WHILE. */
2419 if (gfc_match (" while ( %e )%t", &iter
.end
) == MATCH_YES
)
2421 new_st
.op
= EXEC_DO_WHILE
;
2425 /* The abortive DO WHILE may have done something to the symbol
2426 table, so we start over. */
2427 gfc_undo_symbols ();
2428 gfc_current_locus
= old_loc
;
2430 gfc_match_label (); /* This won't error. */
2431 gfc_match (" do "); /* This will work. */
2433 gfc_match_st_label (&label
); /* Can't error out. */
2434 gfc_match_char (','); /* Optional comma. */
2436 m
= gfc_match_iterator (&iter
, 0);
2439 if (m
== MATCH_ERROR
)
2442 iter
.var
->symtree
->n
.sym
->attr
.implied_index
= 0;
2443 gfc_check_do_variable (iter
.var
->symtree
);
2445 if (gfc_match_eos () != MATCH_YES
)
2447 gfc_syntax_error (ST_DO
);
2451 new_st
.op
= EXEC_DO
;
2455 && gfc_reference_st_label (label
, ST_LABEL_DO_TARGET
) == FAILURE
)
2458 new_st
.label1
= label
;
2460 if (new_st
.op
== EXEC_DO_WHILE
)
2461 new_st
.expr1
= iter
.end
;
2464 new_st
.ext
.iterator
= ip
= gfc_get_iterator ();
2471 gfc_free_iterator (&iter
, 0);
2477 /* Match an EXIT or CYCLE statement. */
2480 match_exit_cycle (gfc_statement st
, gfc_exec_op op
)
2482 gfc_state_data
*p
, *o
;
2487 if (gfc_match_eos () == MATCH_YES
)
2491 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2494 m
= gfc_match ("% %n%t", name
);
2495 if (m
== MATCH_ERROR
)
2499 gfc_syntax_error (st
);
2503 /* Find the corresponding symbol. If there's a BLOCK statement
2504 between here and the label, it is not in gfc_current_ns but a parent
2506 stree
= gfc_find_symtree_in_proc (name
, gfc_current_ns
);
2509 gfc_error ("Name '%s' in %s statement at %C is unknown",
2510 name
, gfc_ascii_statement (st
));
2515 if (sym
->attr
.flavor
!= FL_LABEL
)
2517 gfc_error ("Name '%s' in %s statement at %C is not a construct name",
2518 name
, gfc_ascii_statement (st
));
2523 /* Find the loop specified by the label (or lack of a label). */
2524 for (o
= NULL
, p
= gfc_state_stack
; p
; p
= p
->previous
)
2525 if (o
== NULL
&& p
->state
== COMP_OMP_STRUCTURED_BLOCK
)
2527 else if (p
->state
== COMP_CRITICAL
)
2529 gfc_error("%s statement at %C leaves CRITICAL construct",
2530 gfc_ascii_statement (st
));
2533 else if (p
->state
== COMP_DO_CONCURRENT
2534 && (op
== EXEC_EXIT
|| (sym
&& sym
!= p
->sym
)))
2536 /* F2008, C821 & C845. */
2537 gfc_error("%s statement at %C leaves DO CONCURRENT construct",
2538 gfc_ascii_statement (st
));
2541 else if ((sym
&& sym
== p
->sym
)
2542 || (!sym
&& (p
->state
== COMP_DO
2543 || p
->state
== COMP_DO_CONCURRENT
)))
2549 gfc_error ("%s statement at %C is not within a construct",
2550 gfc_ascii_statement (st
));
2552 gfc_error ("%s statement at %C is not within construct '%s'",
2553 gfc_ascii_statement (st
), sym
->name
);
2558 /* Special checks for EXIT from non-loop constructs. */
2562 case COMP_DO_CONCURRENT
:
2566 /* This is already handled above. */
2569 case COMP_ASSOCIATE
:
2573 case COMP_SELECT_TYPE
:
2575 if (op
== EXEC_CYCLE
)
2577 gfc_error ("CYCLE statement at %C is not applicable to non-loop"
2578 " construct '%s'", sym
->name
);
2581 gcc_assert (op
== EXEC_EXIT
);
2582 if (gfc_notify_std (GFC_STD_F2008
, "EXIT statement with no"
2583 " do-construct-name at %C") == FAILURE
)
2588 gfc_error ("%s statement at %C is not applicable to construct '%s'",
2589 gfc_ascii_statement (st
), sym
->name
);
2595 gfc_error ("%s statement at %C leaving OpenMP structured block",
2596 gfc_ascii_statement (st
));
2600 for (o
= p
, cnt
= 0; o
->state
== COMP_DO
&& o
->previous
!= NULL
; cnt
++)
2604 && o
->state
== COMP_OMP_STRUCTURED_BLOCK
2605 && (o
->head
->op
== EXEC_OMP_DO
2606 || o
->head
->op
== EXEC_OMP_PARALLEL_DO
))
2609 gcc_assert (o
->head
->next
!= NULL
2610 && (o
->head
->next
->op
== EXEC_DO
2611 || o
->head
->next
->op
== EXEC_DO_WHILE
)
2612 && o
->previous
!= NULL
2613 && o
->previous
->tail
->op
== o
->head
->op
);
2614 if (o
->previous
->tail
->ext
.omp_clauses
!= NULL
2615 && o
->previous
->tail
->ext
.omp_clauses
->collapse
> 1)
2616 collapse
= o
->previous
->tail
->ext
.omp_clauses
->collapse
;
2617 if (st
== ST_EXIT
&& cnt
<= collapse
)
2619 gfc_error ("EXIT statement at %C terminating !$OMP DO loop");
2622 if (st
== ST_CYCLE
&& cnt
< collapse
)
2624 gfc_error ("CYCLE statement at %C to non-innermost collapsed"
2630 /* Save the first statement in the construct - needed by the backend. */
2631 new_st
.ext
.which_construct
= p
->construct
;
2639 /* Match the EXIT statement. */
2642 gfc_match_exit (void)
2644 return match_exit_cycle (ST_EXIT
, EXEC_EXIT
);
2648 /* Match the CYCLE statement. */
2651 gfc_match_cycle (void)
2653 return match_exit_cycle (ST_CYCLE
, EXEC_CYCLE
);
2657 /* Match a number or character constant after an (ALL) STOP or PAUSE statement. */
2660 gfc_match_stopcode (gfc_statement st
)
2667 if (gfc_match_eos () != MATCH_YES
)
2669 m
= gfc_match_init_expr (&e
);
2670 if (m
== MATCH_ERROR
)
2675 if (gfc_match_eos () != MATCH_YES
)
2679 if (gfc_pure (NULL
))
2681 gfc_error ("%s statement not allowed in PURE procedure at %C",
2682 gfc_ascii_statement (st
));
2686 if (gfc_implicit_pure (NULL
))
2687 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
2689 if (st
== ST_STOP
&& gfc_find_state (COMP_CRITICAL
) == SUCCESS
)
2691 gfc_error ("Image control statement STOP at %C in CRITICAL block");
2694 if (st
== ST_STOP
&& gfc_find_state (COMP_DO_CONCURRENT
) == SUCCESS
)
2696 gfc_error ("Image control statement STOP at %C in DO CONCURRENT block");
2702 if (!(e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_INTEGER
))
2704 gfc_error ("STOP code at %L must be either INTEGER or CHARACTER type",
2711 gfc_error ("STOP code at %L must be scalar",
2716 if (e
->ts
.type
== BT_CHARACTER
2717 && e
->ts
.kind
!= gfc_default_character_kind
)
2719 gfc_error ("STOP code at %L must be default character KIND=%d",
2720 &e
->where
, (int) gfc_default_character_kind
);
2724 if (e
->ts
.type
== BT_INTEGER
2725 && e
->ts
.kind
!= gfc_default_integer_kind
)
2727 gfc_error ("STOP code at %L must be default integer KIND=%d",
2728 &e
->where
, (int) gfc_default_integer_kind
);
2736 new_st
.op
= EXEC_STOP
;
2739 new_st
.op
= EXEC_ERROR_STOP
;
2742 new_st
.op
= EXEC_PAUSE
;
2749 new_st
.ext
.stop_code
= -1;
2754 gfc_syntax_error (st
);
2763 /* Match the (deprecated) PAUSE statement. */
2766 gfc_match_pause (void)
2770 m
= gfc_match_stopcode (ST_PAUSE
);
2773 if (gfc_notify_std (GFC_STD_F95_DEL
, "PAUSE statement"
2782 /* Match the STOP statement. */
2785 gfc_match_stop (void)
2787 return gfc_match_stopcode (ST_STOP
);
2791 /* Match the ERROR STOP statement. */
2794 gfc_match_error_stop (void)
2796 if (gfc_notify_std (GFC_STD_F2008
, "ERROR STOP statement at %C")
2800 return gfc_match_stopcode (ST_ERROR_STOP
);
2804 /* Match LOCK/UNLOCK statement. Syntax:
2805 LOCK ( lock-variable [ , lock-stat-list ] )
2806 UNLOCK ( lock-variable [ , sync-stat-list ] )
2807 where lock-stat is ACQUIRED_LOCK or sync-stat
2808 and sync-stat is STAT= or ERRMSG=. */
2811 lock_unlock_statement (gfc_statement st
)
2814 gfc_expr
*tmp
, *lockvar
, *acq_lock
, *stat
, *errmsg
;
2815 bool saw_acq_lock
, saw_stat
, saw_errmsg
;
2817 tmp
= lockvar
= acq_lock
= stat
= errmsg
= NULL
;
2818 saw_acq_lock
= saw_stat
= saw_errmsg
= false;
2820 if (gfc_pure (NULL
))
2822 gfc_error ("Image control statement %s at %C in PURE procedure",
2823 st
== ST_LOCK
? "LOCK" : "UNLOCK");
2827 if (gfc_implicit_pure (NULL
))
2828 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
2830 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
2832 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
2836 if (gfc_find_state (COMP_CRITICAL
) == SUCCESS
)
2838 gfc_error ("Image control statement %s at %C in CRITICAL block",
2839 st
== ST_LOCK
? "LOCK" : "UNLOCK");
2843 if (gfc_find_state (COMP_DO_CONCURRENT
) == SUCCESS
)
2845 gfc_error ("Image control statement %s at %C in DO CONCURRENT block",
2846 st
== ST_LOCK
? "LOCK" : "UNLOCK");
2850 if (gfc_match_char ('(') != MATCH_YES
)
2853 if (gfc_match ("%e", &lockvar
) != MATCH_YES
)
2855 m
= gfc_match_char (',');
2856 if (m
== MATCH_ERROR
)
2860 m
= gfc_match_char (')');
2868 m
= gfc_match (" stat = %v", &tmp
);
2869 if (m
== MATCH_ERROR
)
2875 gfc_error ("Redundant STAT tag found at %L ", &tmp
->where
);
2881 m
= gfc_match_char (',');
2889 m
= gfc_match (" errmsg = %v", &tmp
);
2890 if (m
== MATCH_ERROR
)
2896 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp
->where
);
2902 m
= gfc_match_char (',');
2910 m
= gfc_match (" acquired_lock = %v", &tmp
);
2911 if (m
== MATCH_ERROR
|| st
== ST_UNLOCK
)
2917 gfc_error ("Redundant ACQUIRED_LOCK tag found at %L ",
2922 saw_acq_lock
= true;
2924 m
= gfc_match_char (',');
2935 if (m
== MATCH_ERROR
)
2938 if (gfc_match (" )%t") != MATCH_YES
)
2945 new_st
.op
= EXEC_LOCK
;
2948 new_st
.op
= EXEC_UNLOCK
;
2954 new_st
.expr1
= lockvar
;
2955 new_st
.expr2
= stat
;
2956 new_st
.expr3
= errmsg
;
2957 new_st
.expr4
= acq_lock
;
2962 gfc_syntax_error (st
);
2965 if (acq_lock
!= tmp
)
2966 gfc_free_expr (acq_lock
);
2968 gfc_free_expr (errmsg
);
2970 gfc_free_expr (stat
);
2972 gfc_free_expr (tmp
);
2973 gfc_free_expr (lockvar
);
2980 gfc_match_lock (void)
2982 if (gfc_notify_std (GFC_STD_F2008
, "LOCK statement at %C")
2986 return lock_unlock_statement (ST_LOCK
);
2991 gfc_match_unlock (void)
2993 if (gfc_notify_std (GFC_STD_F2008
, "UNLOCK statement at %C")
2997 return lock_unlock_statement (ST_UNLOCK
);
3001 /* Match SYNC ALL/IMAGES/MEMORY statement. Syntax:
3002 SYNC ALL [(sync-stat-list)]
3003 SYNC MEMORY [(sync-stat-list)]
3004 SYNC IMAGES (image-set [, sync-stat-list] )
3005 with sync-stat is int-expr or *. */
3008 sync_statement (gfc_statement st
)
3011 gfc_expr
*tmp
, *imageset
, *stat
, *errmsg
;
3012 bool saw_stat
, saw_errmsg
;
3014 tmp
= imageset
= stat
= errmsg
= NULL
;
3015 saw_stat
= saw_errmsg
= false;
3017 if (gfc_pure (NULL
))
3019 gfc_error ("Image control statement SYNC at %C in PURE procedure");
3023 if (gfc_implicit_pure (NULL
))
3024 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
3026 if (gfc_notify_std (GFC_STD_F2008
, "SYNC statement at %C")
3030 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3032 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3036 if (gfc_find_state (COMP_CRITICAL
) == SUCCESS
)
3038 gfc_error ("Image control statement SYNC at %C in CRITICAL block");
3042 if (gfc_find_state (COMP_DO_CONCURRENT
) == SUCCESS
)
3044 gfc_error ("Image control statement SYNC at %C in DO CONCURRENT block");
3048 if (gfc_match_eos () == MATCH_YES
)
3050 if (st
== ST_SYNC_IMAGES
)
3055 if (gfc_match_char ('(') != MATCH_YES
)
3058 if (st
== ST_SYNC_IMAGES
)
3060 /* Denote '*' as imageset == NULL. */
3061 m
= gfc_match_char ('*');
3062 if (m
== MATCH_ERROR
)
3066 if (gfc_match ("%e", &imageset
) != MATCH_YES
)
3069 m
= gfc_match_char (',');
3070 if (m
== MATCH_ERROR
)
3074 m
= gfc_match_char (')');
3083 m
= gfc_match (" stat = %v", &tmp
);
3084 if (m
== MATCH_ERROR
)
3090 gfc_error ("Redundant STAT tag found at %L ", &tmp
->where
);
3096 if (gfc_match_char (',') == MATCH_YES
)
3103 m
= gfc_match (" errmsg = %v", &tmp
);
3104 if (m
== MATCH_ERROR
)
3110 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp
->where
);
3116 if (gfc_match_char (',') == MATCH_YES
)
3126 if (gfc_match (" )%t") != MATCH_YES
)
3133 new_st
.op
= EXEC_SYNC_ALL
;
3135 case ST_SYNC_IMAGES
:
3136 new_st
.op
= EXEC_SYNC_IMAGES
;
3138 case ST_SYNC_MEMORY
:
3139 new_st
.op
= EXEC_SYNC_MEMORY
;
3145 new_st
.expr1
= imageset
;
3146 new_st
.expr2
= stat
;
3147 new_st
.expr3
= errmsg
;
3152 gfc_syntax_error (st
);
3156 gfc_free_expr (stat
);
3158 gfc_free_expr (errmsg
);
3160 gfc_free_expr (tmp
);
3161 gfc_free_expr (imageset
);
3167 /* Match SYNC ALL statement. */
3170 gfc_match_sync_all (void)
3172 return sync_statement (ST_SYNC_ALL
);
3176 /* Match SYNC IMAGES statement. */
3179 gfc_match_sync_images (void)
3181 return sync_statement (ST_SYNC_IMAGES
);
3185 /* Match SYNC MEMORY statement. */
3188 gfc_match_sync_memory (void)
3190 return sync_statement (ST_SYNC_MEMORY
);
3194 /* Match a CONTINUE statement. */
3197 gfc_match_continue (void)
3199 if (gfc_match_eos () != MATCH_YES
)
3201 gfc_syntax_error (ST_CONTINUE
);
3205 new_st
.op
= EXEC_CONTINUE
;
3210 /* Match the (deprecated) ASSIGN statement. */
3213 gfc_match_assign (void)
3216 gfc_st_label
*label
;
3218 if (gfc_match (" %l", &label
) == MATCH_YES
)
3220 if (gfc_reference_st_label (label
, ST_LABEL_UNKNOWN
) == FAILURE
)
3222 if (gfc_match (" to %v%t", &expr
) == MATCH_YES
)
3224 if (gfc_notify_std (GFC_STD_F95_DEL
, "ASSIGN "
3229 expr
->symtree
->n
.sym
->attr
.assign
= 1;
3231 new_st
.op
= EXEC_LABEL_ASSIGN
;
3232 new_st
.label1
= label
;
3233 new_st
.expr1
= expr
;
3241 /* Match the GO TO statement. As a computed GOTO statement is
3242 matched, it is transformed into an equivalent SELECT block. No
3243 tree is necessary, and the resulting jumps-to-jumps are
3244 specifically optimized away by the back end. */
3247 gfc_match_goto (void)
3249 gfc_code
*head
, *tail
;
3252 gfc_st_label
*label
;
3256 if (gfc_match (" %l%t", &label
) == MATCH_YES
)
3258 if (gfc_reference_st_label (label
, ST_LABEL_TARGET
) == FAILURE
)
3261 new_st
.op
= EXEC_GOTO
;
3262 new_st
.label1
= label
;
3266 /* The assigned GO TO statement. */
3268 if (gfc_match_variable (&expr
, 0) == MATCH_YES
)
3270 if (gfc_notify_std (GFC_STD_F95_DEL
, "Assigned GOTO "
3275 new_st
.op
= EXEC_GOTO
;
3276 new_st
.expr1
= expr
;
3278 if (gfc_match_eos () == MATCH_YES
)
3281 /* Match label list. */
3282 gfc_match_char (',');
3283 if (gfc_match_char ('(') != MATCH_YES
)
3285 gfc_syntax_error (ST_GOTO
);
3292 m
= gfc_match_st_label (&label
);
3296 if (gfc_reference_st_label (label
, ST_LABEL_TARGET
) == FAILURE
)
3300 head
= tail
= gfc_get_code ();
3303 tail
->block
= gfc_get_code ();
3307 tail
->label1
= label
;
3308 tail
->op
= EXEC_GOTO
;
3310 while (gfc_match_char (',') == MATCH_YES
);
3312 if (gfc_match (")%t") != MATCH_YES
)
3317 gfc_error ("Statement label list in GOTO at %C cannot be empty");
3320 new_st
.block
= head
;
3325 /* Last chance is a computed GO TO statement. */
3326 if (gfc_match_char ('(') != MATCH_YES
)
3328 gfc_syntax_error (ST_GOTO
);
3337 m
= gfc_match_st_label (&label
);
3341 if (gfc_reference_st_label (label
, ST_LABEL_TARGET
) == FAILURE
)
3345 head
= tail
= gfc_get_code ();
3348 tail
->block
= gfc_get_code ();
3352 cp
= gfc_get_case ();
3353 cp
->low
= cp
->high
= gfc_get_int_expr (gfc_default_integer_kind
,
3356 tail
->op
= EXEC_SELECT
;
3357 tail
->ext
.block
.case_list
= cp
;
3359 tail
->next
= gfc_get_code ();
3360 tail
->next
->op
= EXEC_GOTO
;
3361 tail
->next
->label1
= label
;
3363 while (gfc_match_char (',') == MATCH_YES
);
3365 if (gfc_match_char (')') != MATCH_YES
)
3370 gfc_error ("Statement label list in GOTO at %C cannot be empty");
3374 /* Get the rest of the statement. */
3375 gfc_match_char (',');
3377 if (gfc_match (" %e%t", &expr
) != MATCH_YES
)
3380 if (gfc_notify_std (GFC_STD_F95_OBS
, "Computed GOTO "
3381 "at %C") == FAILURE
)
3384 /* At this point, a computed GOTO has been fully matched and an
3385 equivalent SELECT statement constructed. */
3387 new_st
.op
= EXEC_SELECT
;
3388 new_st
.expr1
= NULL
;
3390 /* Hack: For a "real" SELECT, the expression is in expr. We put
3391 it in expr2 so we can distinguish then and produce the correct
3393 new_st
.expr2
= expr
;
3394 new_st
.block
= head
;
3398 gfc_syntax_error (ST_GOTO
);
3400 gfc_free_statements (head
);
3405 /* Frees a list of gfc_alloc structures. */
3408 gfc_free_alloc_list (gfc_alloc
*p
)
3415 gfc_free_expr (p
->expr
);
3421 /* Match an ALLOCATE statement. */
3424 gfc_match_allocate (void)
3426 gfc_alloc
*head
, *tail
;
3427 gfc_expr
*stat
, *errmsg
, *tmp
, *source
, *mold
;
3431 locus old_locus
, deferred_locus
;
3432 bool saw_stat
, saw_errmsg
, saw_source
, saw_mold
, saw_deferred
, b1
, b2
, b3
;
3433 bool saw_unlimited
= false;
3436 stat
= errmsg
= source
= mold
= tmp
= NULL
;
3437 saw_stat
= saw_errmsg
= saw_source
= saw_mold
= saw_deferred
= false;
3439 if (gfc_match_char ('(') != MATCH_YES
)
3442 /* Match an optional type-spec. */
3443 old_locus
= gfc_current_locus
;
3444 m
= match_type_spec (&ts
);
3445 if (m
== MATCH_ERROR
)
3447 else if (m
== MATCH_NO
)
3449 char name
[GFC_MAX_SYMBOL_LEN
+ 3];
3451 if (gfc_match ("%n :: ", name
) == MATCH_YES
)
3453 gfc_error ("Error in type-spec at %L", &old_locus
);
3457 ts
.type
= BT_UNKNOWN
;
3461 if (gfc_match (" :: ") == MATCH_YES
)
3463 if (gfc_notify_std (GFC_STD_F2003
, "typespec in "
3464 "ALLOCATE at %L", &old_locus
) == FAILURE
)
3469 gfc_error ("Type-spec at %L cannot contain a deferred "
3470 "type parameter", &old_locus
);
3474 if (ts
.type
== BT_CHARACTER
)
3475 ts
.u
.cl
->length_from_typespec
= true;
3479 ts
.type
= BT_UNKNOWN
;
3480 gfc_current_locus
= old_locus
;
3487 head
= tail
= gfc_get_alloc ();
3490 tail
->next
= gfc_get_alloc ();
3494 m
= gfc_match_variable (&tail
->expr
, 0);
3497 if (m
== MATCH_ERROR
)
3500 if (gfc_check_do_variable (tail
->expr
->symtree
))
3503 if (gfc_pure (NULL
) && gfc_impure_variable (tail
->expr
->symtree
->n
.sym
))
3505 gfc_error ("Bad allocate-object at %C for a PURE procedure");
3509 if (gfc_implicit_pure (NULL
)
3510 && gfc_impure_variable (tail
->expr
->symtree
->n
.sym
))
3511 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
3513 if (tail
->expr
->ts
.deferred
)
3515 saw_deferred
= true;
3516 deferred_locus
= tail
->expr
->where
;
3519 if (gfc_find_state (COMP_DO_CONCURRENT
) == SUCCESS
3520 || gfc_find_state (COMP_CRITICAL
) == SUCCESS
)
3523 bool coarray
= tail
->expr
->symtree
->n
.sym
->attr
.codimension
;
3524 for (ref
= tail
->expr
->ref
; ref
; ref
= ref
->next
)
3525 if (ref
->type
== REF_COMPONENT
)
3526 coarray
= ref
->u
.c
.component
->attr
.codimension
;
3528 if (coarray
&& gfc_find_state (COMP_DO_CONCURRENT
) == SUCCESS
)
3530 gfc_error ("ALLOCATE of coarray at %C in DO CONCURRENT block");
3533 if (coarray
&& gfc_find_state (COMP_CRITICAL
) == SUCCESS
)
3535 gfc_error ("ALLOCATE of coarray at %C in CRITICAL block");
3540 /* Check for F08:C628. */
3541 sym
= tail
->expr
->symtree
->n
.sym
;
3542 b1
= !(tail
->expr
->ref
3543 && (tail
->expr
->ref
->type
== REF_COMPONENT
3544 || tail
->expr
->ref
->type
== REF_ARRAY
));
3545 if (sym
&& sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
3546 b2
= !(CLASS_DATA (sym
)->attr
.allocatable
3547 || CLASS_DATA (sym
)->attr
.class_pointer
);
3549 b2
= sym
&& !(sym
->attr
.allocatable
|| sym
->attr
.pointer
3550 || sym
->attr
.proc_pointer
);
3551 b3
= sym
&& sym
->ns
&& sym
->ns
->proc_name
3552 && (sym
->ns
->proc_name
->attr
.allocatable
3553 || sym
->ns
->proc_name
->attr
.pointer
3554 || sym
->ns
->proc_name
->attr
.proc_pointer
);
3555 if (b1
&& b2
&& !b3
)
3557 gfc_error ("Allocate-object at %L is neither a data pointer "
3558 "nor an allocatable variable", &tail
->expr
->where
);
3562 /* The ALLOCATE statement had an optional typespec. Check the
3564 if (ts
.type
!= BT_UNKNOWN
)
3566 /* Enforce F03:C624. */
3567 if (!gfc_type_compatible (&tail
->expr
->ts
, &ts
))
3569 gfc_error ("Type of entity at %L is type incompatible with "
3570 "typespec", &tail
->expr
->where
);
3574 /* Enforce F03:C627. */
3575 if (ts
.kind
!= tail
->expr
->ts
.kind
&& !UNLIMITED_POLY (tail
->expr
))
3577 gfc_error ("Kind type parameter for entity at %L differs from "
3578 "the kind type parameter of the typespec",
3579 &tail
->expr
->where
);
3584 if (tail
->expr
->ts
.type
== BT_DERIVED
)
3585 tail
->expr
->ts
.u
.derived
= gfc_use_derived (tail
->expr
->ts
.u
.derived
);
3587 saw_unlimited
= saw_unlimited
| UNLIMITED_POLY (tail
->expr
);
3589 if (gfc_peek_ascii_char () == '(' && !sym
->attr
.dimension
)
3591 gfc_error ("Shape specification for allocatable scalar at %C");
3595 if (gfc_match_char (',') != MATCH_YES
)
3600 m
= gfc_match (" stat = %v", &tmp
);
3601 if (m
== MATCH_ERROR
)
3608 gfc_error ("Redundant STAT tag found at %L ", &tmp
->where
);
3616 if (gfc_check_do_variable (stat
->symtree
))
3619 if (gfc_match_char (',') == MATCH_YES
)
3620 goto alloc_opt_list
;
3623 m
= gfc_match (" errmsg = %v", &tmp
);
3624 if (m
== MATCH_ERROR
)
3628 if (gfc_notify_std (GFC_STD_F2003
, "ERRMSG tag at %L",
3629 &tmp
->where
) == FAILURE
)
3635 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp
->where
);
3643 if (gfc_match_char (',') == MATCH_YES
)
3644 goto alloc_opt_list
;
3647 m
= gfc_match (" source = %e", &tmp
);
3648 if (m
== MATCH_ERROR
)
3652 if (gfc_notify_std (GFC_STD_F2003
, "SOURCE tag at %L",
3653 &tmp
->where
) == FAILURE
)
3659 gfc_error ("Redundant SOURCE tag found at %L ", &tmp
->where
);
3663 /* The next 2 conditionals check C631. */
3664 if (ts
.type
!= BT_UNKNOWN
)
3666 gfc_error ("SOURCE tag at %L conflicts with the typespec at %L",
3667 &tmp
->where
, &old_locus
);
3672 && gfc_notify_std (GFC_STD_F2008
, "SOURCE tag at %L"
3673 " with more than a single allocate object",
3674 &tmp
->where
) == FAILURE
)
3681 if (gfc_match_char (',') == MATCH_YES
)
3682 goto alloc_opt_list
;
3685 m
= gfc_match (" mold = %e", &tmp
);
3686 if (m
== MATCH_ERROR
)
3690 if (gfc_notify_std (GFC_STD_F2008
, "MOLD tag at %L",
3691 &tmp
->where
) == FAILURE
)
3694 /* Check F08:C636. */
3697 gfc_error ("Redundant MOLD tag found at %L ", &tmp
->where
);
3701 /* Check F08:C637. */
3702 if (ts
.type
!= BT_UNKNOWN
)
3704 gfc_error ("MOLD tag at %L conflicts with the typespec at %L",
3705 &tmp
->where
, &old_locus
);
3714 if (gfc_match_char (',') == MATCH_YES
)
3715 goto alloc_opt_list
;
3718 gfc_gobble_whitespace ();
3720 if (gfc_peek_char () == ')')
3724 if (gfc_match (" )%t") != MATCH_YES
)
3727 /* Check F08:C637. */
3730 gfc_error ("MOLD tag at %L conflicts with SOURCE tag at %L",
3731 &mold
->where
, &source
->where
);
3735 /* Check F03:C623, */
3736 if (saw_deferred
&& ts
.type
== BT_UNKNOWN
&& !source
&& !mold
)
3738 gfc_error ("Allocate-object at %L with a deferred type parameter "
3739 "requires either a type-spec or SOURCE tag or a MOLD tag",
3744 /* Check F03:C625, */
3745 if (saw_unlimited
&& ts
.type
== BT_UNKNOWN
&& !source
&& !mold
)
3747 for (tail
= head
; tail
; tail
= tail
->next
)
3749 if (UNLIMITED_POLY (tail
->expr
))
3750 gfc_error ("Unlimited polymorphic allocate-object at %L "
3751 "requires either a type-spec or SOURCE tag "
3752 "or a MOLD tag", &tail
->expr
->where
);
3757 new_st
.op
= EXEC_ALLOCATE
;
3758 new_st
.expr1
= stat
;
3759 new_st
.expr2
= errmsg
;
3761 new_st
.expr3
= source
;
3763 new_st
.expr3
= mold
;
3764 new_st
.ext
.alloc
.list
= head
;
3765 new_st
.ext
.alloc
.ts
= ts
;
3770 gfc_syntax_error (ST_ALLOCATE
);
3773 gfc_free_expr (errmsg
);
3774 gfc_free_expr (source
);
3775 gfc_free_expr (stat
);
3776 gfc_free_expr (mold
);
3777 if (tmp
&& tmp
->expr_type
) gfc_free_expr (tmp
);
3778 gfc_free_alloc_list (head
);
3783 /* Match a NULLIFY statement. A NULLIFY statement is transformed into
3784 a set of pointer assignments to intrinsic NULL(). */
3787 gfc_match_nullify (void)
3795 if (gfc_match_char ('(') != MATCH_YES
)
3800 m
= gfc_match_variable (&p
, 0);
3801 if (m
== MATCH_ERROR
)
3806 if (gfc_check_do_variable (p
->symtree
))
3810 if (gfc_is_coindexed (p
))
3812 gfc_error ("Pointer object at %C shall not be coindexed");
3816 /* build ' => NULL() '. */
3817 e
= gfc_get_null_expr (&gfc_current_locus
);
3819 /* Chain to list. */
3824 tail
->next
= gfc_get_code ();
3828 tail
->op
= EXEC_POINTER_ASSIGN
;
3832 if (gfc_match (" )%t") == MATCH_YES
)
3834 if (gfc_match_char (',') != MATCH_YES
)
3841 gfc_syntax_error (ST_NULLIFY
);
3844 gfc_free_statements (new_st
.next
);
3846 gfc_free_expr (new_st
.expr1
);
3847 new_st
.expr1
= NULL
;
3848 gfc_free_expr (new_st
.expr2
);
3849 new_st
.expr2
= NULL
;
3854 /* Match a DEALLOCATE statement. */
3857 gfc_match_deallocate (void)
3859 gfc_alloc
*head
, *tail
;
3860 gfc_expr
*stat
, *errmsg
, *tmp
;
3863 bool saw_stat
, saw_errmsg
, b1
, b2
;
3866 stat
= errmsg
= tmp
= NULL
;
3867 saw_stat
= saw_errmsg
= false;
3869 if (gfc_match_char ('(') != MATCH_YES
)
3875 head
= tail
= gfc_get_alloc ();
3878 tail
->next
= gfc_get_alloc ();
3882 m
= gfc_match_variable (&tail
->expr
, 0);
3883 if (m
== MATCH_ERROR
)
3888 if (gfc_check_do_variable (tail
->expr
->symtree
))
3891 sym
= tail
->expr
->symtree
->n
.sym
;
3893 if (gfc_pure (NULL
) && gfc_impure_variable (sym
))
3895 gfc_error ("Illegal allocate-object at %C for a PURE procedure");
3899 if (gfc_implicit_pure (NULL
) && gfc_impure_variable (sym
))
3900 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
3902 if (gfc_is_coarray (tail
->expr
)
3903 && gfc_find_state (COMP_DO_CONCURRENT
) == SUCCESS
)
3905 gfc_error ("DEALLOCATE of coarray at %C in DO CONCURRENT block");
3909 if (gfc_is_coarray (tail
->expr
)
3910 && gfc_find_state (COMP_CRITICAL
) == SUCCESS
)
3912 gfc_error ("DEALLOCATE of coarray at %C in CRITICAL block");
3916 /* FIXME: disable the checking on derived types. */
3917 b1
= !(tail
->expr
->ref
3918 && (tail
->expr
->ref
->type
== REF_COMPONENT
3919 || tail
->expr
->ref
->type
== REF_ARRAY
));
3920 if (sym
&& sym
->ts
.type
== BT_CLASS
)
3921 b2
= !(CLASS_DATA (sym
)->attr
.allocatable
3922 || CLASS_DATA (sym
)->attr
.class_pointer
);
3924 b2
= sym
&& !(sym
->attr
.allocatable
|| sym
->attr
.pointer
3925 || sym
->attr
.proc_pointer
);
3928 gfc_error ("Allocate-object at %C is not a nonprocedure pointer "
3929 "nor an allocatable variable");
3933 if (gfc_match_char (',') != MATCH_YES
)
3938 m
= gfc_match (" stat = %v", &tmp
);
3939 if (m
== MATCH_ERROR
)
3945 gfc_error ("Redundant STAT tag found at %L ", &tmp
->where
);
3946 gfc_free_expr (tmp
);
3953 if (gfc_check_do_variable (stat
->symtree
))
3956 if (gfc_match_char (',') == MATCH_YES
)
3957 goto dealloc_opt_list
;
3960 m
= gfc_match (" errmsg = %v", &tmp
);
3961 if (m
== MATCH_ERROR
)
3965 if (gfc_notify_std (GFC_STD_F2003
, "ERRMSG at %L",
3966 &tmp
->where
) == FAILURE
)
3971 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp
->where
);
3972 gfc_free_expr (tmp
);
3979 if (gfc_match_char (',') == MATCH_YES
)
3980 goto dealloc_opt_list
;
3983 gfc_gobble_whitespace ();
3985 if (gfc_peek_char () == ')')
3989 if (gfc_match (" )%t") != MATCH_YES
)
3992 new_st
.op
= EXEC_DEALLOCATE
;
3993 new_st
.expr1
= stat
;
3994 new_st
.expr2
= errmsg
;
3995 new_st
.ext
.alloc
.list
= head
;
4000 gfc_syntax_error (ST_DEALLOCATE
);
4003 gfc_free_expr (errmsg
);
4004 gfc_free_expr (stat
);
4005 gfc_free_alloc_list (head
);
4010 /* Match a RETURN statement. */
4013 gfc_match_return (void)
4017 gfc_compile_state s
;
4021 if (gfc_find_state (COMP_CRITICAL
) == SUCCESS
)
4023 gfc_error ("Image control statement RETURN at %C in CRITICAL block");
4027 if (gfc_find_state (COMP_DO_CONCURRENT
) == SUCCESS
)
4029 gfc_error ("Image control statement RETURN at %C in DO CONCURRENT block");
4033 if (gfc_match_eos () == MATCH_YES
)
4036 if (gfc_find_state (COMP_SUBROUTINE
) == FAILURE
)
4038 gfc_error ("Alternate RETURN statement at %C is only allowed within "
4043 if (gfc_notify_std (GFC_STD_F95_OBS
, "Alternate RETURN "
4044 "at %C") == FAILURE
)
4047 if (gfc_current_form
== FORM_FREE
)
4049 /* The following are valid, so we can't require a blank after the
4053 char c
= gfc_peek_ascii_char ();
4054 if (ISALPHA (c
) || ISDIGIT (c
))
4058 m
= gfc_match (" %e%t", &e
);
4061 if (m
== MATCH_ERROR
)
4064 gfc_syntax_error (ST_RETURN
);
4071 gfc_enclosing_unit (&s
);
4072 if (s
== COMP_PROGRAM
4073 && gfc_notify_std (GFC_STD_GNU
, "RETURN statement in "
4074 "main program at %C") == FAILURE
)
4077 new_st
.op
= EXEC_RETURN
;
4084 /* Match the call of a type-bound procedure, if CALL%var has already been
4085 matched and var found to be a derived-type variable. */
4088 match_typebound_call (gfc_symtree
* varst
)
4093 base
= gfc_get_expr ();
4094 base
->expr_type
= EXPR_VARIABLE
;
4095 base
->symtree
= varst
;
4096 base
->where
= gfc_current_locus
;
4097 gfc_set_sym_referenced (varst
->n
.sym
);
4099 m
= gfc_match_varspec (base
, 0, true, true);
4101 gfc_error ("Expected component reference at %C");
4105 if (gfc_match_eos () != MATCH_YES
)
4107 gfc_error ("Junk after CALL at %C");
4111 if (base
->expr_type
== EXPR_COMPCALL
)
4112 new_st
.op
= EXEC_COMPCALL
;
4113 else if (base
->expr_type
== EXPR_PPC
)
4114 new_st
.op
= EXEC_CALL_PPC
;
4117 gfc_error ("Expected type-bound procedure or procedure pointer component "
4121 new_st
.expr1
= base
;
4127 /* Match a CALL statement. The tricky part here are possible
4128 alternate return specifiers. We handle these by having all
4129 "subroutines" actually return an integer via a register that gives
4130 the return number. If the call specifies alternate returns, we
4131 generate code for a SELECT statement whose case clauses contain
4132 GOTOs to the various labels. */
4135 gfc_match_call (void)
4137 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4138 gfc_actual_arglist
*a
, *arglist
;
4148 m
= gfc_match ("% %n", name
);
4154 if (gfc_get_ha_sym_tree (name
, &st
))
4159 /* If this is a variable of derived-type, it probably starts a type-bound
4161 if ((sym
->attr
.flavor
!= FL_PROCEDURE
4162 || gfc_is_function_return_value (sym
, gfc_current_ns
))
4163 && (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
))
4164 return match_typebound_call (st
);
4166 /* If it does not seem to be callable (include functions so that the
4167 right association is made. They are thrown out in resolution.)
4169 if (!sym
->attr
.generic
4170 && !sym
->attr
.subroutine
4171 && !sym
->attr
.function
)
4173 if (!(sym
->attr
.external
&& !sym
->attr
.referenced
))
4175 /* ...create a symbol in this scope... */
4176 if (sym
->ns
!= gfc_current_ns
4177 && gfc_get_sym_tree (name
, NULL
, &st
, false) == 1)
4180 if (sym
!= st
->n
.sym
)
4184 /* ...and then to try to make the symbol into a subroutine. */
4185 if (gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
4189 gfc_set_sym_referenced (sym
);
4191 if (gfc_match_eos () != MATCH_YES
)
4193 m
= gfc_match_actual_arglist (1, &arglist
);
4196 if (m
== MATCH_ERROR
)
4199 if (gfc_match_eos () != MATCH_YES
)
4203 /* If any alternate return labels were found, construct a SELECT
4204 statement that will jump to the right place. */
4207 for (a
= arglist
; a
; a
= a
->next
)
4208 if (a
->expr
== NULL
)
4213 gfc_symtree
*select_st
;
4214 gfc_symbol
*select_sym
;
4215 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4217 new_st
.next
= c
= gfc_get_code ();
4218 c
->op
= EXEC_SELECT
;
4219 sprintf (name
, "_result_%s", sym
->name
);
4220 gfc_get_ha_sym_tree (name
, &select_st
); /* Can't fail. */
4222 select_sym
= select_st
->n
.sym
;
4223 select_sym
->ts
.type
= BT_INTEGER
;
4224 select_sym
->ts
.kind
= gfc_default_integer_kind
;
4225 gfc_set_sym_referenced (select_sym
);
4226 c
->expr1
= gfc_get_expr ();
4227 c
->expr1
->expr_type
= EXPR_VARIABLE
;
4228 c
->expr1
->symtree
= select_st
;
4229 c
->expr1
->ts
= select_sym
->ts
;
4230 c
->expr1
->where
= gfc_current_locus
;
4233 for (a
= arglist
; a
; a
= a
->next
)
4235 if (a
->expr
!= NULL
)
4238 if (gfc_reference_st_label (a
->label
, ST_LABEL_TARGET
) == FAILURE
)
4243 c
->block
= gfc_get_code ();
4245 c
->op
= EXEC_SELECT
;
4247 new_case
= gfc_get_case ();
4248 new_case
->high
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, i
);
4249 new_case
->low
= new_case
->high
;
4250 c
->ext
.block
.case_list
= new_case
;
4252 c
->next
= gfc_get_code ();
4253 c
->next
->op
= EXEC_GOTO
;
4254 c
->next
->label1
= a
->label
;
4258 new_st
.op
= EXEC_CALL
;
4259 new_st
.symtree
= st
;
4260 new_st
.ext
.actual
= arglist
;
4265 gfc_syntax_error (ST_CALL
);
4268 gfc_free_actual_arglist (arglist
);
4273 /* Given a name, return a pointer to the common head structure,
4274 creating it if it does not exist. If FROM_MODULE is nonzero, we
4275 mangle the name so that it doesn't interfere with commons defined
4276 in the using namespace.
4277 TODO: Add to global symbol tree. */
4280 gfc_get_common (const char *name
, int from_module
)
4283 static int serial
= 0;
4284 char mangled_name
[GFC_MAX_SYMBOL_LEN
+ 1];
4288 /* A use associated common block is only needed to correctly layout
4289 the variables it contains. */
4290 snprintf (mangled_name
, GFC_MAX_SYMBOL_LEN
, "_%d_%s", serial
++, name
);
4291 st
= gfc_new_symtree (&gfc_current_ns
->common_root
, mangled_name
);
4295 st
= gfc_find_symtree (gfc_current_ns
->common_root
, name
);
4298 st
= gfc_new_symtree (&gfc_current_ns
->common_root
, name
);
4301 if (st
->n
.common
== NULL
)
4303 st
->n
.common
= gfc_get_common_head ();
4304 st
->n
.common
->where
= gfc_current_locus
;
4305 strcpy (st
->n
.common
->name
, name
);
4308 return st
->n
.common
;
4312 /* Match a common block name. */
4314 match
match_common_name (char *name
)
4318 if (gfc_match_char ('/') == MATCH_NO
)
4324 if (gfc_match_char ('/') == MATCH_YES
)
4330 m
= gfc_match_name (name
);
4332 if (m
== MATCH_ERROR
)
4334 if (m
== MATCH_YES
&& gfc_match_char ('/') == MATCH_YES
)
4337 gfc_error ("Syntax error in common block name at %C");
4342 /* Match a COMMON statement. */
4345 gfc_match_common (void)
4347 gfc_symbol
*sym
, **head
, *tail
, *other
, *old_blank_common
;
4348 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4355 old_blank_common
= gfc_current_ns
->blank_common
.head
;
4356 if (old_blank_common
)
4358 while (old_blank_common
->common_next
)
4359 old_blank_common
= old_blank_common
->common_next
;
4366 m
= match_common_name (name
);
4367 if (m
== MATCH_ERROR
)
4370 gsym
= gfc_get_gsymbol (name
);
4371 if (gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= GSYM_COMMON
)
4373 gfc_error ("Symbol '%s' at %C is already an external symbol that "
4374 "is not COMMON", name
);
4378 if (gsym
->type
== GSYM_UNKNOWN
)
4380 gsym
->type
= GSYM_COMMON
;
4381 gsym
->where
= gfc_current_locus
;
4387 if (name
[0] == '\0')
4389 t
= &gfc_current_ns
->blank_common
;
4390 if (t
->head
== NULL
)
4391 t
->where
= gfc_current_locus
;
4395 t
= gfc_get_common (name
, 0);
4404 while (tail
->common_next
)
4405 tail
= tail
->common_next
;
4408 /* Grab the list of symbols. */
4411 m
= gfc_match_symbol (&sym
, 0);
4412 if (m
== MATCH_ERROR
)
4417 /* Store a ref to the common block for error checking. */
4418 sym
->common_block
= t
;
4419 sym
->common_block
->refs
++;
4421 /* See if we know the current common block is bind(c), and if
4422 so, then see if we can check if the symbol is (which it'll
4423 need to be). This can happen if the bind(c) attr stmt was
4424 applied to the common block, and the variable(s) already
4425 defined, before declaring the common block. */
4426 if (t
->is_bind_c
== 1)
4428 if (sym
->ts
.type
!= BT_UNKNOWN
&& sym
->ts
.is_c_interop
!= 1)
4430 /* If we find an error, just print it and continue,
4431 cause it's just semantic, and we can see if there
4433 gfc_error_now ("Variable '%s' at %L in common block '%s' "
4434 "at %C must be declared with a C "
4435 "interoperable kind since common block "
4437 sym
->name
, &(sym
->declared_at
), t
->name
,
4441 if (sym
->attr
.is_bind_c
== 1)
4442 gfc_error_now ("Variable '%s' in common block "
4443 "'%s' at %C can not be bind(c) since "
4444 "it is not global", sym
->name
, t
->name
);
4447 if (sym
->attr
.in_common
)
4449 gfc_error ("Symbol '%s' at %C is already in a COMMON block",
4454 if (((sym
->value
!= NULL
&& sym
->value
->expr_type
!= EXPR_NULL
)
4455 || sym
->attr
.data
) && gfc_current_state () != COMP_BLOCK_DATA
)
4457 if (gfc_notify_std (GFC_STD_GNU
, "Initialized symbol '%s' at %C "
4458 "can only be COMMON in "
4459 "BLOCK DATA", sym
->name
)
4464 if (gfc_add_in_common (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
4468 tail
->common_next
= sym
;
4474 /* Deal with an optional array specification after the
4476 m
= gfc_match_array_spec (&as
, true, true);
4477 if (m
== MATCH_ERROR
)
4482 if (as
->type
!= AS_EXPLICIT
)
4484 gfc_error ("Array specification for symbol '%s' in COMMON "
4485 "at %C must be explicit", sym
->name
);
4489 if (gfc_add_dimension (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
4492 if (sym
->attr
.pointer
)
4494 gfc_error ("Symbol '%s' in COMMON at %C cannot be a "
4495 "POINTER array", sym
->name
);
4504 sym
->common_head
= t
;
4506 /* Check to see if the symbol is already in an equivalence group.
4507 If it is, set the other members as being in common. */
4508 if (sym
->attr
.in_equivalence
)
4510 for (e1
= gfc_current_ns
->equiv
; e1
; e1
= e1
->next
)
4512 for (e2
= e1
; e2
; e2
= e2
->eq
)
4513 if (e2
->expr
->symtree
->n
.sym
== sym
)
4520 for (e2
= e1
; e2
; e2
= e2
->eq
)
4522 other
= e2
->expr
->symtree
->n
.sym
;
4523 if (other
->common_head
4524 && other
->common_head
!= sym
->common_head
)
4526 gfc_error ("Symbol '%s', in COMMON block '%s' at "
4527 "%C is being indirectly equivalenced to "
4528 "another COMMON block '%s'",
4529 sym
->name
, sym
->common_head
->name
,
4530 other
->common_head
->name
);
4533 other
->attr
.in_common
= 1;
4534 other
->common_head
= t
;
4540 gfc_gobble_whitespace ();
4541 if (gfc_match_eos () == MATCH_YES
)
4543 if (gfc_peek_ascii_char () == '/')
4545 if (gfc_match_char (',') != MATCH_YES
)
4547 gfc_gobble_whitespace ();
4548 if (gfc_peek_ascii_char () == '/')
4557 gfc_syntax_error (ST_COMMON
);
4560 if (old_blank_common
)
4561 old_blank_common
->common_next
= NULL
;
4563 gfc_current_ns
->blank_common
.head
= NULL
;
4564 gfc_free_array_spec (as
);
4569 /* Match a BLOCK DATA program unit. */
4572 gfc_match_block_data (void)
4574 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4578 if (gfc_match_eos () == MATCH_YES
)
4580 gfc_new_block
= NULL
;
4584 m
= gfc_match ("% %n%t", name
);
4588 if (gfc_get_symbol (name
, NULL
, &sym
))
4591 if (gfc_add_flavor (&sym
->attr
, FL_BLOCK_DATA
, sym
->name
, NULL
) == FAILURE
)
4594 gfc_new_block
= sym
;
4600 /* Free a namelist structure. */
4603 gfc_free_namelist (gfc_namelist
*name
)
4607 for (; name
; name
= n
)
4615 /* Match a NAMELIST statement. */
4618 gfc_match_namelist (void)
4620 gfc_symbol
*group_name
, *sym
;
4624 m
= gfc_match (" / %s /", &group_name
);
4627 if (m
== MATCH_ERROR
)
4632 if (group_name
->ts
.type
!= BT_UNKNOWN
)
4634 gfc_error ("Namelist group name '%s' at %C already has a basic "
4635 "type of %s", group_name
->name
,
4636 gfc_typename (&group_name
->ts
));
4640 if (group_name
->attr
.flavor
== FL_NAMELIST
4641 && group_name
->attr
.use_assoc
4642 && gfc_notify_std (GFC_STD_GNU
, "Namelist group name '%s' "
4643 "at %C already is USE associated and can"
4644 "not be respecified.", group_name
->name
)
4648 if (group_name
->attr
.flavor
!= FL_NAMELIST
4649 && gfc_add_flavor (&group_name
->attr
, FL_NAMELIST
,
4650 group_name
->name
, NULL
) == FAILURE
)
4655 m
= gfc_match_symbol (&sym
, 1);
4658 if (m
== MATCH_ERROR
)
4661 if (sym
->attr
.in_namelist
== 0
4662 && gfc_add_in_namelist (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
4665 /* Use gfc_error_check here, rather than goto error, so that
4666 these are the only errors for the next two lines. */
4667 if (sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
)
4669 gfc_error ("Assumed size array '%s' in namelist '%s' at "
4670 "%C is not allowed", sym
->name
, group_name
->name
);
4674 nl
= gfc_get_namelist ();
4678 if (group_name
->namelist
== NULL
)
4679 group_name
->namelist
= group_name
->namelist_tail
= nl
;
4682 group_name
->namelist_tail
->next
= nl
;
4683 group_name
->namelist_tail
= nl
;
4686 if (gfc_match_eos () == MATCH_YES
)
4689 m
= gfc_match_char (',');
4691 if (gfc_match_char ('/') == MATCH_YES
)
4693 m2
= gfc_match (" %s /", &group_name
);
4694 if (m2
== MATCH_YES
)
4696 if (m2
== MATCH_ERROR
)
4710 gfc_syntax_error (ST_NAMELIST
);
4717 /* Match a MODULE statement. */
4720 gfc_match_module (void)
4724 m
= gfc_match (" %s%t", &gfc_new_block
);
4728 if (gfc_add_flavor (&gfc_new_block
->attr
, FL_MODULE
,
4729 gfc_new_block
->name
, NULL
) == FAILURE
)
4736 /* Free equivalence sets and lists. Recursively is the easiest way to
4740 gfc_free_equiv_until (gfc_equiv
*eq
, gfc_equiv
*stop
)
4745 gfc_free_equiv (eq
->eq
);
4746 gfc_free_equiv_until (eq
->next
, stop
);
4747 gfc_free_expr (eq
->expr
);
4753 gfc_free_equiv (gfc_equiv
*eq
)
4755 gfc_free_equiv_until (eq
, NULL
);
4759 /* Match an EQUIVALENCE statement. */
4762 gfc_match_equivalence (void)
4764 gfc_equiv
*eq
, *set
, *tail
;
4768 gfc_common_head
*common_head
= NULL
;
4776 eq
= gfc_get_equiv ();
4780 eq
->next
= gfc_current_ns
->equiv
;
4781 gfc_current_ns
->equiv
= eq
;
4783 if (gfc_match_char ('(') != MATCH_YES
)
4787 common_flag
= FALSE
;
4792 m
= gfc_match_equiv_variable (&set
->expr
);
4793 if (m
== MATCH_ERROR
)
4798 /* count the number of objects. */
4801 if (gfc_match_char ('%') == MATCH_YES
)
4803 gfc_error ("Derived type component %C is not a "
4804 "permitted EQUIVALENCE member");
4808 for (ref
= set
->expr
->ref
; ref
; ref
= ref
->next
)
4809 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
== AR_SECTION
)
4811 gfc_error ("Array reference in EQUIVALENCE at %C cannot "
4812 "be an array section");
4816 sym
= set
->expr
->symtree
->n
.sym
;
4818 if (gfc_add_in_equivalence (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
4821 if (sym
->attr
.in_common
)
4824 common_head
= sym
->common_head
;
4827 if (gfc_match_char (')') == MATCH_YES
)
4830 if (gfc_match_char (',') != MATCH_YES
)
4833 set
->eq
= gfc_get_equiv ();
4839 gfc_error ("EQUIVALENCE at %C requires two or more objects");
4843 /* If one of the members of an equivalence is in common, then
4844 mark them all as being in common. Before doing this, check
4845 that members of the equivalence group are not in different
4848 for (set
= eq
; set
; set
= set
->eq
)
4850 sym
= set
->expr
->symtree
->n
.sym
;
4851 if (sym
->common_head
&& sym
->common_head
!= common_head
)
4853 gfc_error ("Attempt to indirectly overlap COMMON "
4854 "blocks %s and %s by EQUIVALENCE at %C",
4855 sym
->common_head
->name
, common_head
->name
);
4858 sym
->attr
.in_common
= 1;
4859 sym
->common_head
= common_head
;
4862 if (gfc_match_eos () == MATCH_YES
)
4864 if (gfc_match_char (',') != MATCH_YES
)
4866 gfc_error ("Expecting a comma in EQUIVALENCE at %C");
4874 gfc_syntax_error (ST_EQUIVALENCE
);
4880 gfc_free_equiv (gfc_current_ns
->equiv
);
4881 gfc_current_ns
->equiv
= eq
;
4887 /* Check that a statement function is not recursive. This is done by looking
4888 for the statement function symbol(sym) by looking recursively through its
4889 expression(e). If a reference to sym is found, true is returned.
4890 12.5.4 requires that any variable of function that is implicitly typed
4891 shall have that type confirmed by any subsequent type declaration. The
4892 implicit typing is conveniently done here. */
4894 recursive_stmt_fcn (gfc_expr
*, gfc_symbol
*);
4897 check_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
4903 switch (e
->expr_type
)
4906 if (e
->symtree
== NULL
)
4909 /* Check the name before testing for nested recursion! */
4910 if (sym
->name
== e
->symtree
->n
.sym
->name
)
4913 /* Catch recursion via other statement functions. */
4914 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
4915 && e
->symtree
->n
.sym
->value
4916 && recursive_stmt_fcn (e
->symtree
->n
.sym
->value
, sym
))
4919 if (e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
)
4920 gfc_set_default_type (e
->symtree
->n
.sym
, 0, NULL
);
4925 if (e
->symtree
&& sym
->name
== e
->symtree
->n
.sym
->name
)
4928 if (e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
)
4929 gfc_set_default_type (e
->symtree
->n
.sym
, 0, NULL
);
4941 recursive_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
)
4943 return gfc_traverse_expr (e
, sym
, check_stmt_fcn
, 0);
4947 /* Match a statement function declaration. It is so easy to match
4948 non-statement function statements with a MATCH_ERROR as opposed to
4949 MATCH_NO that we suppress error message in most cases. */
4952 gfc_match_st_function (void)
4954 gfc_error_buf old_error
;
4959 m
= gfc_match_symbol (&sym
, 0);
4963 gfc_push_error (&old_error
);
4965 if (gfc_add_procedure (&sym
->attr
, PROC_ST_FUNCTION
,
4966 sym
->name
, NULL
) == FAILURE
)
4969 if (gfc_match_formal_arglist (sym
, 1, 0) != MATCH_YES
)
4972 m
= gfc_match (" = %e%t", &expr
);
4976 gfc_free_error (&old_error
);
4977 if (m
== MATCH_ERROR
)
4980 if (recursive_stmt_fcn (expr
, sym
))
4982 gfc_error ("Statement function at %L is recursive", &expr
->where
);
4988 if (gfc_notify_std (GFC_STD_F95_OBS
,
4989 "Statement function at %C") == FAILURE
)
4995 gfc_pop_error (&old_error
);
5000 /***************** SELECT CASE subroutines ******************/
5002 /* Free a single case structure. */
5005 free_case (gfc_case
*p
)
5007 if (p
->low
== p
->high
)
5009 gfc_free_expr (p
->low
);
5010 gfc_free_expr (p
->high
);
5015 /* Free a list of case structures. */
5018 gfc_free_case_list (gfc_case
*p
)
5030 /* Match a single case selector. */
5033 match_case_selector (gfc_case
**cp
)
5038 c
= gfc_get_case ();
5039 c
->where
= gfc_current_locus
;
5041 if (gfc_match_char (':') == MATCH_YES
)
5043 m
= gfc_match_init_expr (&c
->high
);
5046 if (m
== MATCH_ERROR
)
5051 m
= gfc_match_init_expr (&c
->low
);
5052 if (m
== MATCH_ERROR
)
5057 /* If we're not looking at a ':' now, make a range out of a single
5058 target. Else get the upper bound for the case range. */
5059 if (gfc_match_char (':') != MATCH_YES
)
5063 m
= gfc_match_init_expr (&c
->high
);
5064 if (m
== MATCH_ERROR
)
5066 /* MATCH_NO is fine. It's OK if nothing is there! */
5074 gfc_error ("Expected initialization expression in CASE at %C");
5082 /* Match the end of a case statement. */
5085 match_case_eos (void)
5087 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5090 if (gfc_match_eos () == MATCH_YES
)
5093 /* If the case construct doesn't have a case-construct-name, we
5094 should have matched the EOS. */
5095 if (!gfc_current_block ())
5098 gfc_gobble_whitespace ();
5100 m
= gfc_match_name (name
);
5104 if (strcmp (name
, gfc_current_block ()->name
) != 0)
5106 gfc_error ("Expected block name '%s' of SELECT construct at %C",
5107 gfc_current_block ()->name
);
5111 return gfc_match_eos ();
5115 /* Match a SELECT statement. */
5118 gfc_match_select (void)
5123 m
= gfc_match_label ();
5124 if (m
== MATCH_ERROR
)
5127 m
= gfc_match (" select case ( %e )%t", &expr
);
5131 new_st
.op
= EXEC_SELECT
;
5132 new_st
.expr1
= expr
;
5138 /* Transfer the selector typespec to the associate name. */
5141 copy_ts_from_selector_to_associate (gfc_expr
*associate
, gfc_expr
*selector
)
5144 gfc_symbol
*assoc_sym
;
5147 assoc_sym
= associate
->symtree
->n
.sym
;
5149 /* At this stage the expression rank and arrayspec dimensions have
5150 not been completely sorted out. We must get the expr2->rank
5151 right here, so that the correct class container is obtained. */
5152 ref
= selector
->ref
;
5153 while (ref
&& ref
->next
)
5156 if (selector
->ts
.type
== BT_CLASS
5157 && CLASS_DATA (selector
)->as
5158 && ref
&& ref
->type
== REF_ARRAY
)
5160 /* Ensure that the array reference type is set. We cannot use
5161 gfc_resolve_expr at this point, so the usable parts of
5162 resolve.c(resolve_array_ref) are employed to do it. */
5163 if (ref
->u
.ar
.type
== AR_UNKNOWN
)
5165 ref
->u
.ar
.type
= AR_ELEMENT
;
5166 for (i
= 0; i
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; i
++)
5167 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
5168 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
5169 || (ref
->u
.ar
.dimen_type
[i
] == DIMEN_UNKNOWN
5170 && ref
->u
.ar
.start
[i
] && ref
->u
.ar
.start
[i
]->rank
))
5172 ref
->u
.ar
.type
= AR_SECTION
;
5177 if (ref
->u
.ar
.type
== AR_FULL
)
5178 selector
->rank
= CLASS_DATA (selector
)->as
->rank
;
5179 else if (ref
->u
.ar
.type
== AR_SECTION
)
5180 selector
->rank
= ref
->u
.ar
.dimen
;
5185 if (selector
->ts
.type
!= BT_CLASS
)
5187 /* The correct class container has to be available. */
5190 assoc_sym
->attr
.dimension
= 1;
5191 assoc_sym
->as
= gfc_get_array_spec ();
5192 assoc_sym
->as
->rank
= selector
->rank
;
5193 assoc_sym
->as
->type
= AS_DEFERRED
;
5196 assoc_sym
->as
= NULL
;
5198 assoc_sym
->ts
.type
= BT_CLASS
;
5199 assoc_sym
->ts
.u
.derived
= selector
->ts
.u
.derived
;
5200 assoc_sym
->attr
.pointer
= 1;
5201 gfc_build_class_symbol (&assoc_sym
->ts
, &assoc_sym
->attr
,
5202 &assoc_sym
->as
, false);
5206 /* The correct class container has to be available. */
5209 assoc_sym
->attr
.dimension
= 1;
5210 assoc_sym
->as
= gfc_get_array_spec ();
5211 assoc_sym
->as
->rank
= selector
->rank
;
5212 assoc_sym
->as
->type
= AS_DEFERRED
;
5215 assoc_sym
->as
= NULL
;
5216 assoc_sym
->ts
.type
= BT_CLASS
;
5217 assoc_sym
->ts
.u
.derived
= CLASS_DATA (selector
)->ts
.u
.derived
;
5218 assoc_sym
->attr
.pointer
= 1;
5219 gfc_build_class_symbol (&assoc_sym
->ts
, &assoc_sym
->attr
,
5220 &assoc_sym
->as
, false);
5225 /* Push the current selector onto the SELECT TYPE stack. */
5228 select_type_push (gfc_symbol
*sel
)
5230 gfc_select_type_stack
*top
= gfc_get_select_type_stack ();
5231 top
->selector
= sel
;
5233 top
->prev
= select_type_stack
;
5235 select_type_stack
= top
;
5239 /* Set the temporary for the current intrinsic SELECT TYPE selector. */
5241 static gfc_symtree
*
5242 select_intrinsic_set_tmp (gfc_typespec
*ts
)
5244 char name
[GFC_MAX_SYMBOL_LEN
];
5248 if (ts
->type
== BT_CLASS
|| ts
->type
== BT_DERIVED
)
5251 if (select_type_stack
->selector
->ts
.type
== BT_CLASS
5252 && !select_type_stack
->selector
->attr
.class_ok
)
5255 if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& ts
->u
.cl
->length
5256 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
5257 charlen
= mpz_get_si (ts
->u
.cl
->length
->value
.integer
);
5259 if (ts
->type
!= BT_CHARACTER
)
5260 sprintf (name
, "__tmp_%s_%d", gfc_basic_typename (ts
->type
),
5263 sprintf (name
, "__tmp_%s_%d_%d", gfc_basic_typename (ts
->type
),
5266 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp
, false);
5267 gfc_add_type (tmp
->n
.sym
, ts
, NULL
);
5269 /* Copy across the array spec to the selector. */
5270 if (select_type_stack
->selector
->ts
.type
== BT_CLASS
5271 && (CLASS_DATA (select_type_stack
->selector
)->attr
.dimension
5272 || CLASS_DATA (select_type_stack
->selector
)->attr
.codimension
))
5274 tmp
->n
.sym
->attr
.pointer
= 1;
5275 tmp
->n
.sym
->attr
.dimension
5276 = CLASS_DATA (select_type_stack
->selector
)->attr
.dimension
;
5277 tmp
->n
.sym
->attr
.codimension
5278 = CLASS_DATA (select_type_stack
->selector
)->attr
.codimension
;
5280 = gfc_copy_array_spec (CLASS_DATA (select_type_stack
->selector
)->as
);
5283 gfc_set_sym_referenced (tmp
->n
.sym
);
5284 gfc_add_flavor (&tmp
->n
.sym
->attr
, FL_VARIABLE
, name
, NULL
);
5285 tmp
->n
.sym
->attr
.select_type_temporary
= 1;
5291 /* Set up a temporary for the current TYPE IS / CLASS IS branch . */
5294 select_type_set_tmp (gfc_typespec
*ts
)
5296 char name
[GFC_MAX_SYMBOL_LEN
];
5297 gfc_symtree
*tmp
= NULL
;
5301 select_type_stack
->tmp
= NULL
;
5305 tmp
= select_intrinsic_set_tmp (ts
);
5312 if (ts
->type
== BT_CLASS
)
5313 sprintf (name
, "__tmp_class_%s", ts
->u
.derived
->name
);
5315 sprintf (name
, "__tmp_type_%s", ts
->u
.derived
->name
);
5316 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp
, false);
5317 gfc_add_type (tmp
->n
.sym
, ts
, NULL
);
5319 if (select_type_stack
->selector
->ts
.type
== BT_CLASS
5320 && select_type_stack
->selector
->attr
.class_ok
)
5322 tmp
->n
.sym
->attr
.pointer
5323 = CLASS_DATA (select_type_stack
->selector
)->attr
.class_pointer
;
5325 /* Copy across the array spec to the selector. */
5326 if (CLASS_DATA (select_type_stack
->selector
)->attr
.dimension
5327 || CLASS_DATA (select_type_stack
->selector
)->attr
.codimension
)
5329 tmp
->n
.sym
->attr
.dimension
5330 = CLASS_DATA (select_type_stack
->selector
)->attr
.dimension
;
5331 tmp
->n
.sym
->attr
.codimension
5332 = CLASS_DATA (select_type_stack
->selector
)->attr
.codimension
;
5334 = gfc_copy_array_spec (CLASS_DATA (select_type_stack
->selector
)->as
);
5338 gfc_set_sym_referenced (tmp
->n
.sym
);
5339 gfc_add_flavor (&tmp
->n
.sym
->attr
, FL_VARIABLE
, name
, NULL
);
5340 tmp
->n
.sym
->attr
.select_type_temporary
= 1;
5342 if (ts
->type
== BT_CLASS
)
5343 gfc_build_class_symbol (&tmp
->n
.sym
->ts
, &tmp
->n
.sym
->attr
,
5344 &tmp
->n
.sym
->as
, false);
5347 /* Add an association for it, so the rest of the parser knows it is
5348 an associate-name. The target will be set during resolution. */
5349 tmp
->n
.sym
->assoc
= gfc_get_association_list ();
5350 tmp
->n
.sym
->assoc
->dangling
= 1;
5351 tmp
->n
.sym
->assoc
->st
= tmp
;
5353 select_type_stack
->tmp
= tmp
;
5357 /* Match a SELECT TYPE statement. */
5360 gfc_match_select_type (void)
5362 gfc_expr
*expr1
, *expr2
= NULL
;
5364 char name
[GFC_MAX_SYMBOL_LEN
];
5367 gfc_namespace
*parent_ns
;
5369 m
= gfc_match_label ();
5370 if (m
== MATCH_ERROR
)
5373 m
= gfc_match (" select type ( ");
5377 gfc_current_ns
= gfc_build_block_ns (gfc_current_ns
);
5379 m
= gfc_match (" %n => %e", name
, &expr2
);
5382 expr1
= gfc_get_expr();
5383 expr1
->expr_type
= EXPR_VARIABLE
;
5384 if (gfc_get_sym_tree (name
, NULL
, &expr1
->symtree
, false))
5390 sym
= expr1
->symtree
->n
.sym
;
5391 if (expr2
->ts
.type
== BT_UNKNOWN
)
5392 sym
->attr
.untyped
= 1;
5394 copy_ts_from_selector_to_associate (expr1
, expr2
);
5396 sym
->attr
.flavor
= FL_VARIABLE
;
5397 sym
->attr
.referenced
= 1;
5398 sym
->attr
.class_ok
= 1;
5402 m
= gfc_match (" %e ", &expr1
);
5407 m
= gfc_match (" )%t");
5411 /* This ghastly expression seems to be needed to distinguish a CLASS
5412 array, which can have a reference, from other expressions that
5413 have references, such as derived type components, and are not
5414 allowed by the standard.
5415 TODO: see if it is sufficient to exclude component and substring
5417 class_array
= expr1
->expr_type
== EXPR_VARIABLE
5418 && expr1
->ts
.type
== BT_CLASS
5419 && CLASS_DATA (expr1
)
5420 && (strcmp (CLASS_DATA (expr1
)->name
, "_data") == 0)
5421 && (CLASS_DATA (expr1
)->attr
.dimension
5422 || CLASS_DATA (expr1
)->attr
.codimension
)
5424 && expr1
->ref
->type
== REF_ARRAY
5425 && expr1
->ref
->next
== NULL
;
5427 /* Check for F03:C811. */
5428 if (!expr2
&& (expr1
->expr_type
!= EXPR_VARIABLE
5429 || (!class_array
&& expr1
->ref
!= NULL
)))
5431 gfc_error ("Selector in SELECT TYPE at %C is not a named variable; "
5432 "use associate-name=>");
5437 new_st
.op
= EXEC_SELECT_TYPE
;
5438 new_st
.expr1
= expr1
;
5439 new_st
.expr2
= expr2
;
5440 new_st
.ext
.block
.ns
= gfc_current_ns
;
5442 select_type_push (expr1
->symtree
->n
.sym
);
5447 parent_ns
= gfc_current_ns
->parent
;
5448 gfc_free_namespace (gfc_current_ns
);
5449 gfc_current_ns
= parent_ns
;
5454 /* Match a CASE statement. */
5457 gfc_match_case (void)
5459 gfc_case
*c
, *head
, *tail
;
5464 if (gfc_current_state () != COMP_SELECT
)
5466 gfc_error ("Unexpected CASE statement at %C");
5470 if (gfc_match ("% default") == MATCH_YES
)
5472 m
= match_case_eos ();
5475 if (m
== MATCH_ERROR
)
5478 new_st
.op
= EXEC_SELECT
;
5479 c
= gfc_get_case ();
5480 c
->where
= gfc_current_locus
;
5481 new_st
.ext
.block
.case_list
= c
;
5485 if (gfc_match_char ('(') != MATCH_YES
)
5490 if (match_case_selector (&c
) == MATCH_ERROR
)
5500 if (gfc_match_char (')') == MATCH_YES
)
5502 if (gfc_match_char (',') != MATCH_YES
)
5506 m
= match_case_eos ();
5509 if (m
== MATCH_ERROR
)
5512 new_st
.op
= EXEC_SELECT
;
5513 new_st
.ext
.block
.case_list
= head
;
5518 gfc_error ("Syntax error in CASE specification at %C");
5521 gfc_free_case_list (head
); /* new_st is cleaned up in parse.c. */
5526 /* Match a TYPE IS statement. */
5529 gfc_match_type_is (void)
5534 if (gfc_current_state () != COMP_SELECT_TYPE
)
5536 gfc_error ("Unexpected TYPE IS statement at %C");
5540 if (gfc_match_char ('(') != MATCH_YES
)
5543 c
= gfc_get_case ();
5544 c
->where
= gfc_current_locus
;
5546 if (match_type_spec (&c
->ts
) == MATCH_ERROR
)
5549 if (gfc_match_char (')') != MATCH_YES
)
5552 m
= match_case_eos ();
5555 if (m
== MATCH_ERROR
)
5558 new_st
.op
= EXEC_SELECT_TYPE
;
5559 new_st
.ext
.block
.case_list
= c
;
5561 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
5562 && (c
->ts
.u
.derived
->attr
.sequence
5563 || c
->ts
.u
.derived
->attr
.is_bind_c
))
5565 gfc_error ("The type-spec shall not specify a sequence derived "
5566 "type or a type with the BIND attribute in SELECT "
5567 "TYPE at %C [F2003:C815]");
5571 /* Create temporary variable. */
5572 select_type_set_tmp (&c
->ts
);
5577 gfc_error ("Syntax error in TYPE IS specification at %C");
5581 gfc_free_case_list (c
); /* new_st is cleaned up in parse.c. */
5586 /* Match a CLASS IS or CLASS DEFAULT statement. */
5589 gfc_match_class_is (void)
5594 if (gfc_current_state () != COMP_SELECT_TYPE
)
5597 if (gfc_match ("% default") == MATCH_YES
)
5599 m
= match_case_eos ();
5602 if (m
== MATCH_ERROR
)
5605 new_st
.op
= EXEC_SELECT_TYPE
;
5606 c
= gfc_get_case ();
5607 c
->where
= gfc_current_locus
;
5608 c
->ts
.type
= BT_UNKNOWN
;
5609 new_st
.ext
.block
.case_list
= c
;
5610 select_type_set_tmp (NULL
);
5614 m
= gfc_match ("% is");
5617 if (m
== MATCH_ERROR
)
5620 if (gfc_match_char ('(') != MATCH_YES
)
5623 c
= gfc_get_case ();
5624 c
->where
= gfc_current_locus
;
5626 if (match_derived_type_spec (&c
->ts
) == MATCH_ERROR
)
5629 if (c
->ts
.type
== BT_DERIVED
)
5630 c
->ts
.type
= BT_CLASS
;
5632 if (gfc_match_char (')') != MATCH_YES
)
5635 m
= match_case_eos ();
5638 if (m
== MATCH_ERROR
)
5641 new_st
.op
= EXEC_SELECT_TYPE
;
5642 new_st
.ext
.block
.case_list
= c
;
5644 /* Create temporary variable. */
5645 select_type_set_tmp (&c
->ts
);
5650 gfc_error ("Syntax error in CLASS IS specification at %C");
5654 gfc_free_case_list (c
); /* new_st is cleaned up in parse.c. */
5659 /********************* WHERE subroutines ********************/
5661 /* Match the rest of a simple WHERE statement that follows an IF statement.
5665 match_simple_where (void)
5671 m
= gfc_match (" ( %e )", &expr
);
5675 m
= gfc_match_assignment ();
5678 if (m
== MATCH_ERROR
)
5681 if (gfc_match_eos () != MATCH_YES
)
5684 c
= gfc_get_code ();
5688 c
->next
= gfc_get_code ();
5691 gfc_clear_new_st ();
5693 new_st
.op
= EXEC_WHERE
;
5699 gfc_syntax_error (ST_WHERE
);
5702 gfc_free_expr (expr
);
5707 /* Match a WHERE statement. */
5710 gfc_match_where (gfc_statement
*st
)
5716 m0
= gfc_match_label ();
5717 if (m0
== MATCH_ERROR
)
5720 m
= gfc_match (" where ( %e )", &expr
);
5724 if (gfc_match_eos () == MATCH_YES
)
5726 *st
= ST_WHERE_BLOCK
;
5727 new_st
.op
= EXEC_WHERE
;
5728 new_st
.expr1
= expr
;
5732 m
= gfc_match_assignment ();
5734 gfc_syntax_error (ST_WHERE
);
5738 gfc_free_expr (expr
);
5742 /* We've got a simple WHERE statement. */
5744 c
= gfc_get_code ();
5748 c
->next
= gfc_get_code ();
5751 gfc_clear_new_st ();
5753 new_st
.op
= EXEC_WHERE
;
5760 /* Match an ELSEWHERE statement. We leave behind a WHERE node in
5761 new_st if successful. */
5764 gfc_match_elsewhere (void)
5766 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5770 if (gfc_current_state () != COMP_WHERE
)
5772 gfc_error ("ELSEWHERE statement at %C not enclosed in WHERE block");
5778 if (gfc_match_char ('(') == MATCH_YES
)
5780 m
= gfc_match_expr (&expr
);
5783 if (m
== MATCH_ERROR
)
5786 if (gfc_match_char (')') != MATCH_YES
)
5790 if (gfc_match_eos () != MATCH_YES
)
5792 /* Only makes sense if we have a where-construct-name. */
5793 if (!gfc_current_block ())
5798 /* Better be a name at this point. */
5799 m
= gfc_match_name (name
);
5802 if (m
== MATCH_ERROR
)
5805 if (gfc_match_eos () != MATCH_YES
)
5808 if (strcmp (name
, gfc_current_block ()->name
) != 0)
5810 gfc_error ("Label '%s' at %C doesn't match WHERE label '%s'",
5811 name
, gfc_current_block ()->name
);
5816 new_st
.op
= EXEC_WHERE
;
5817 new_st
.expr1
= expr
;
5821 gfc_syntax_error (ST_ELSEWHERE
);
5824 gfc_free_expr (expr
);