1 /* Matching subroutines in all sizes, shapes and colors.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 2010 Free Software Foundation, Inc.
5 Contributed by Andy Vaught
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
30 int gfc_matching_procptr_assignment = 0;
31 bool gfc_matching_prefix = false;
33 /* Stack of SELECT TYPE statements. */
34 gfc_select_type_stack *select_type_stack = NULL;
36 /* For debugging and diagnostic purposes. Return the textual representation
37 of the intrinsic operator OP. */
39 gfc_op2string (gfc_intrinsic_op op)
47 case INTRINSIC_UMINUS:
53 case INTRINSIC_CONCAT:
57 case INTRINSIC_DIVIDE:
96 case INTRINSIC_ASSIGN:
99 case INTRINSIC_PARENTHESES:
106 gfc_internal_error ("gfc_op2string(): Bad code");
111 /******************** Generic matching subroutines ************************/
113 /* This function scans the current statement counting the opened and closed
114 parenthesis to make sure they are balanced. */
117 gfc_match_parens (void)
119 locus old_loc, where;
123 old_loc = gfc_current_locus;
130 c = gfc_next_char_literal (instring);
133 if (quote == ' ' && ((c == '\'') || (c == '"')))
139 if (quote != ' ' && c == quote)
146 if (c == '(' && quote == ' ')
149 where = gfc_current_locus;
151 if (c == ')' && quote == ' ')
154 where = gfc_current_locus;
158 gfc_current_locus = old_loc;
162 gfc_error ("Missing ')' in statement at or before %L", &where);
167 gfc_error ("Missing '(' in statement at or before %L", &where);
175 /* See if the next character is a special character that has
176 escaped by a \ via the -fbackslash option. */
179 gfc_match_special_char (gfc_char_t *res)
187 switch ((c = gfc_next_char_literal (1)))
220 /* Hexadecimal form of wide characters. */
221 len = (c == 'x' ? 2 : (c == 'u' ? 4 : 8));
223 for (i = 0; i < len; i++)
225 char buf[2] = { '\0', '\0' };
227 c = gfc_next_char_literal (1);
228 if (!gfc_wide_fits_in_byte (c)
229 || !gfc_check_digit ((unsigned char) c, 16))
232 buf[0] = (unsigned char) c;
234 n += strtol (buf, NULL, 16);
240 /* Unknown backslash codes are simply not expanded. */
249 /* In free form, match at least one space. Always matches in fixed
253 gfc_match_space (void)
258 if (gfc_current_form == FORM_FIXED)
261 old_loc = gfc_current_locus;
263 c = gfc_next_ascii_char ();
264 if (!gfc_is_whitespace (c))
266 gfc_current_locus = old_loc;
270 gfc_gobble_whitespace ();
276 /* Match an end of statement. End of statement is optional
277 whitespace, followed by a ';' or '\n' or comment '!'. If a
278 semicolon is found, we continue to eat whitespace and semicolons. */
291 old_loc = gfc_current_locus;
292 gfc_gobble_whitespace ();
294 c = gfc_next_ascii_char ();
300 c = gfc_next_ascii_char ();
317 gfc_current_locus = old_loc;
318 return (flag) ? MATCH_YES : MATCH_NO;
322 /* Match a literal integer on the input, setting the value on
323 MATCH_YES. Literal ints occur in kind-parameters as well as
324 old-style character length specifications. If cnt is non-NULL it
325 will be set to the number of digits. */
328 gfc_match_small_literal_int (int *value, int *cnt)
334 old_loc = gfc_current_locus;
337 gfc_gobble_whitespace ();
338 c = gfc_next_ascii_char ();
344 gfc_current_locus = old_loc;
353 old_loc = gfc_current_locus;
354 c = gfc_next_ascii_char ();
359 i = 10 * i + c - '0';
364 gfc_error ("Integer too large at %C");
369 gfc_current_locus = old_loc;
378 /* Match a small, constant integer expression, like in a kind
379 statement. On MATCH_YES, 'value' is set. */
382 gfc_match_small_int (int *value)
389 m = gfc_match_expr (&expr);
393 p = gfc_extract_int (expr, &i);
394 gfc_free_expr (expr);
407 /* This function is the same as the gfc_match_small_int, except that
408 we're keeping the pointer to the expr. This function could just be
409 removed and the previously mentioned one modified, though all calls
410 to it would have to be modified then (and there were a number of
411 them). Return MATCH_ERROR if fail to extract the int; otherwise,
412 return the result of gfc_match_expr(). The expr (if any) that was
413 matched is returned in the parameter expr. */
416 gfc_match_small_int_expr (int *value, gfc_expr **expr)
422 m = gfc_match_expr (expr);
426 p = gfc_extract_int (*expr, &i);
439 /* Matches a statement label. Uses gfc_match_small_literal_int() to
440 do most of the work. */
443 gfc_match_st_label (gfc_st_label **label)
449 old_loc = gfc_current_locus;
451 m = gfc_match_small_literal_int (&i, &cnt);
457 gfc_error ("Too many digits in statement label at %C");
463 gfc_error ("Statement label at %C is zero");
467 *label = gfc_get_st_label (i);
472 gfc_current_locus = old_loc;
477 /* Match and validate a label associated with a named IF, DO or SELECT
478 statement. If the symbol does not have the label attribute, we add
479 it. We also make sure the symbol does not refer to another
480 (active) block. A matched label is pointed to by gfc_new_block. */
483 gfc_match_label (void)
485 char name[GFC_MAX_SYMBOL_LEN + 1];
488 gfc_new_block = NULL;
490 m = gfc_match (" %n :", name);
494 if (gfc_get_symbol (name, NULL, &gfc_new_block))
496 gfc_error ("Label name '%s' at %C is ambiguous", name);
500 if (gfc_new_block->attr.flavor == FL_LABEL)
502 gfc_error ("Duplicate construct label '%s' at %C", name);
506 if (gfc_add_flavor (&gfc_new_block->attr, FL_LABEL,
507 gfc_new_block->name, NULL) == FAILURE)
514 /* See if the current input looks like a name of some sort. Modifies
515 the passed buffer which must be GFC_MAX_SYMBOL_LEN+1 bytes long.
516 Note that options.c restricts max_identifier_length to not more
517 than GFC_MAX_SYMBOL_LEN. */
520 gfc_match_name (char *buffer)
526 old_loc = gfc_current_locus;
527 gfc_gobble_whitespace ();
529 c = gfc_next_ascii_char ();
530 if (!(ISALPHA (c) || (c == '_' && gfc_option.flag_allow_leading_underscore)))
532 if (gfc_error_flag_test() == 0 && c != '(')
533 gfc_error ("Invalid character in name at %C");
534 gfc_current_locus = old_loc;
544 if (i > gfc_option.max_identifier_length)
546 gfc_error ("Name at %C is too long");
550 old_loc = gfc_current_locus;
551 c = gfc_next_ascii_char ();
553 while (ISALNUM (c) || c == '_' || (gfc_option.flag_dollar_ok && c == '$'));
555 if (c == '$' && !gfc_option.flag_dollar_ok)
557 gfc_error ("Invalid character '$' at %C. Use -fdollar-ok to allow it "
563 gfc_current_locus = old_loc;
569 /* Match a valid name for C, which is almost the same as for Fortran,
570 except that you can start with an underscore, etc.. It could have
571 been done by modifying the gfc_match_name, but this way other
572 things C allows can be added, such as no limits on the length.
573 Right now, the length is limited to the same thing as Fortran..
574 Also, by rewriting it, we use the gfc_next_char_C() to prevent the
575 input characters from being automatically lower cased, since C is
576 case sensitive. The parameter, buffer, is used to return the name
577 that is matched. Return MATCH_ERROR if the name is too long
578 (though this is a self-imposed limit), MATCH_NO if what we're
579 seeing isn't a name, and MATCH_YES if we successfully match a C
583 gfc_match_name_C (char *buffer)
589 old_loc = gfc_current_locus;
590 gfc_gobble_whitespace ();
592 /* Get the next char (first possible char of name) and see if
593 it's valid for C (either a letter or an underscore). */
594 c = gfc_next_char_literal (1);
596 /* If the user put nothing expect spaces between the quotes, it is valid
597 and simply means there is no name= specifier and the name is the fortran
598 symbol name, all lowercase. */
599 if (c == '"' || c == '\'')
602 gfc_current_locus = old_loc;
606 if (!ISALPHA (c) && c != '_')
608 gfc_error ("Invalid C name in NAME= specifier at %C");
612 /* Continue to read valid variable name characters. */
615 gcc_assert (gfc_wide_fits_in_byte (c));
617 buffer[i++] = (unsigned char) c;
619 /* C does not define a maximum length of variable names, to my
620 knowledge, but the compiler typically places a limit on them.
621 For now, i'll use the same as the fortran limit for simplicity,
622 but this may need to be changed to a dynamic buffer that can
623 be realloc'ed here if necessary, or more likely, a larger
625 if (i > gfc_option.max_identifier_length)
627 gfc_error ("Name at %C is too long");
631 old_loc = gfc_current_locus;
633 /* Get next char; param means we're in a string. */
634 c = gfc_next_char_literal (1);
635 } while (ISALNUM (c) || c == '_');
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 if (var->symtree->n.sym->attr.intent == INTENT_IN)
983 gfc_error ("Loop variable '%s' at %C cannot be INTENT(IN)",
984 var->symtree->n.sym->name);
988 gfc_match_char ('=');
990 var->symtree->n.sym->attr.implied_index = 1;
992 m = init_flag ? gfc_match_init_expr (&e1) : gfc_match_expr (&e1);
995 if (m == MATCH_ERROR)
998 if (gfc_match_char (',') != MATCH_YES)
1001 m = init_flag ? gfc_match_init_expr (&e2) : gfc_match_expr (&e2);
1004 if (m == MATCH_ERROR)
1007 if (gfc_match_char (',') != MATCH_YES)
1009 e3 = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
1013 m = init_flag ? gfc_match_init_expr (&e3) : gfc_match_expr (&e3);
1014 if (m == MATCH_ERROR)
1018 gfc_error ("Expected a step value in iterator at %C");
1030 gfc_error ("Syntax error in iterator at %C");
1041 /* Tries to match the next non-whitespace character on the input.
1042 This subroutine does not return MATCH_ERROR. */
1045 gfc_match_char (char c)
1049 where = gfc_current_locus;
1050 gfc_gobble_whitespace ();
1052 if (gfc_next_ascii_char () == c)
1055 gfc_current_locus = where;
1060 /* General purpose matching subroutine. The target string is a
1061 scanf-like format string in which spaces correspond to arbitrary
1062 whitespace (including no whitespace), characters correspond to
1063 themselves. The %-codes are:
1065 %% Literal percent sign
1066 %e Expression, pointer to a pointer is set
1067 %s Symbol, pointer to the symbol is set
1068 %n Name, character buffer is set to name
1069 %t Matches end of statement.
1070 %o Matches an intrinsic operator, returned as an INTRINSIC enum.
1071 %l Matches a statement label
1072 %v Matches a variable expression (an lvalue)
1073 % Matches a required space (in free form) and optional spaces. */
1076 gfc_match (const char *target, ...)
1078 gfc_st_label **label;
1087 old_loc = gfc_current_locus;
1088 va_start (argp, target);
1098 gfc_gobble_whitespace ();
1109 vp = va_arg (argp, void **);
1110 n = gfc_match_expr ((gfc_expr **) vp);
1121 vp = va_arg (argp, void **);
1122 n = gfc_match_variable ((gfc_expr **) vp, 0);
1133 vp = va_arg (argp, void **);
1134 n = gfc_match_symbol ((gfc_symbol **) vp, 0);
1145 np = va_arg (argp, char *);
1146 n = gfc_match_name (np);
1157 label = va_arg (argp, gfc_st_label **);
1158 n = gfc_match_st_label (label);
1169 ip = va_arg (argp, int *);
1170 n = gfc_match_intrinsic_op ((gfc_intrinsic_op *) ip);
1181 if (gfc_match_eos () != MATCH_YES)
1189 if (gfc_match_space () == MATCH_YES)
1195 break; /* Fall through to character matcher. */
1198 gfc_internal_error ("gfc_match(): Bad match code %c", c);
1203 /* gfc_next_ascii_char converts characters to lower-case, so we shouldn't
1204 expect an upper case character here! */
1205 gcc_assert (TOLOWER (c) == c);
1207 if (c == gfc_next_ascii_char ())
1217 /* Clean up after a failed match. */
1218 gfc_current_locus = old_loc;
1219 va_start (argp, target);
1222 for (; matches > 0; matches--)
1224 while (*p++ != '%');
1232 /* Matches that don't have to be undone */
1237 (void) va_arg (argp, void **);
1242 vp = va_arg (argp, void **);
1243 gfc_free_expr ((struct gfc_expr *)*vp);
1256 /*********************** Statement level matching **********************/
1258 /* Matches the start of a program unit, which is the program keyword
1259 followed by an obligatory symbol. */
1262 gfc_match_program (void)
1267 m = gfc_match ("% %s%t", &sym);
1271 gfc_error ("Invalid form of PROGRAM statement at %C");
1275 if (m == MATCH_ERROR)
1278 if (gfc_add_flavor (&sym->attr, FL_PROGRAM, sym->name, NULL) == FAILURE)
1281 gfc_new_block = sym;
1287 /* Match a simple assignment statement. */
1290 gfc_match_assignment (void)
1292 gfc_expr *lvalue, *rvalue;
1296 old_loc = gfc_current_locus;
1299 m = gfc_match (" %v =", &lvalue);
1302 gfc_current_locus = old_loc;
1303 gfc_free_expr (lvalue);
1308 m = gfc_match (" %e%t", &rvalue);
1311 gfc_current_locus = old_loc;
1312 gfc_free_expr (lvalue);
1313 gfc_free_expr (rvalue);
1317 gfc_set_sym_referenced (lvalue->symtree->n.sym);
1319 new_st.op = EXEC_ASSIGN;
1320 new_st.expr1 = lvalue;
1321 new_st.expr2 = rvalue;
1323 gfc_check_do_variable (lvalue->symtree);
1329 /* Match a pointer assignment statement. */
1332 gfc_match_pointer_assignment (void)
1334 gfc_expr *lvalue, *rvalue;
1338 old_loc = gfc_current_locus;
1340 lvalue = rvalue = NULL;
1341 gfc_matching_procptr_assignment = 0;
1343 m = gfc_match (" %v =>", &lvalue);
1350 if (lvalue->symtree->n.sym->attr.proc_pointer
1351 || gfc_is_proc_ptr_comp (lvalue, NULL))
1352 gfc_matching_procptr_assignment = 1;
1354 m = gfc_match (" %e%t", &rvalue);
1355 gfc_matching_procptr_assignment = 0;
1359 new_st.op = EXEC_POINTER_ASSIGN;
1360 new_st.expr1 = lvalue;
1361 new_st.expr2 = rvalue;
1366 gfc_current_locus = old_loc;
1367 gfc_free_expr (lvalue);
1368 gfc_free_expr (rvalue);
1373 /* We try to match an easy arithmetic IF statement. This only happens
1374 when just after having encountered a simple IF statement. This code
1375 is really duplicate with parts of the gfc_match_if code, but this is
1379 match_arithmetic_if (void)
1381 gfc_st_label *l1, *l2, *l3;
1385 m = gfc_match (" ( %e ) %l , %l , %l%t", &expr, &l1, &l2, &l3);
1389 if (gfc_reference_st_label (l1, ST_LABEL_TARGET) == FAILURE
1390 || gfc_reference_st_label (l2, ST_LABEL_TARGET) == FAILURE
1391 || gfc_reference_st_label (l3, ST_LABEL_TARGET) == FAILURE)
1393 gfc_free_expr (expr);
1397 if (gfc_notify_std (GFC_STD_F95_OBS, "Obsolescent feature: Arithmetic IF "
1398 "statement at %C") == FAILURE)
1401 new_st.op = EXEC_ARITHMETIC_IF;
1402 new_st.expr1 = expr;
1411 /* The IF statement is a bit of a pain. First of all, there are three
1412 forms of it, the simple IF, the IF that starts a block and the
1415 There is a problem with the simple IF and that is the fact that we
1416 only have a single level of undo information on symbols. What this
1417 means is for a simple IF, we must re-match the whole IF statement
1418 multiple times in order to guarantee that the symbol table ends up
1419 in the proper state. */
1421 static match match_simple_forall (void);
1422 static match match_simple_where (void);
1425 gfc_match_if (gfc_statement *if_type)
1428 gfc_st_label *l1, *l2, *l3;
1429 locus old_loc, old_loc2;
1433 n = gfc_match_label ();
1434 if (n == MATCH_ERROR)
1437 old_loc = gfc_current_locus;
1439 m = gfc_match (" if ( %e", &expr);
1443 old_loc2 = gfc_current_locus;
1444 gfc_current_locus = old_loc;
1446 if (gfc_match_parens () == MATCH_ERROR)
1449 gfc_current_locus = old_loc2;
1451 if (gfc_match_char (')') != MATCH_YES)
1453 gfc_error ("Syntax error in IF-expression at %C");
1454 gfc_free_expr (expr);
1458 m = gfc_match (" %l , %l , %l%t", &l1, &l2, &l3);
1464 gfc_error ("Block label not appropriate for arithmetic IF "
1466 gfc_free_expr (expr);
1470 if (gfc_reference_st_label (l1, ST_LABEL_TARGET) == FAILURE
1471 || gfc_reference_st_label (l2, ST_LABEL_TARGET) == FAILURE
1472 || gfc_reference_st_label (l3, ST_LABEL_TARGET) == FAILURE)
1474 gfc_free_expr (expr);
1478 if (gfc_notify_std (GFC_STD_F95_OBS, "Obsolescent feature: Arithmetic IF "
1479 "statement at %C") == FAILURE)
1482 new_st.op = EXEC_ARITHMETIC_IF;
1483 new_st.expr1 = expr;
1488 *if_type = ST_ARITHMETIC_IF;
1492 if (gfc_match (" then%t") == MATCH_YES)
1494 new_st.op = EXEC_IF;
1495 new_st.expr1 = expr;
1496 *if_type = ST_IF_BLOCK;
1502 gfc_error ("Block label is not appropriate for IF statement at %C");
1503 gfc_free_expr (expr);
1507 /* At this point the only thing left is a simple IF statement. At
1508 this point, n has to be MATCH_NO, so we don't have to worry about
1509 re-matching a block label. From what we've got so far, try
1510 matching an assignment. */
1512 *if_type = ST_SIMPLE_IF;
1514 m = gfc_match_assignment ();
1518 gfc_free_expr (expr);
1519 gfc_undo_symbols ();
1520 gfc_current_locus = old_loc;
1522 /* m can be MATCH_NO or MATCH_ERROR, here. For MATCH_ERROR, a mangled
1523 assignment was found. For MATCH_NO, continue to call the various
1525 if (m == MATCH_ERROR)
1528 gfc_match (" if ( %e ) ", &expr); /* Guaranteed to match. */
1530 m = gfc_match_pointer_assignment ();
1534 gfc_free_expr (expr);
1535 gfc_undo_symbols ();
1536 gfc_current_locus = old_loc;
1538 gfc_match (" if ( %e ) ", &expr); /* Guaranteed to match. */
1540 /* Look at the next keyword to see which matcher to call. Matching
1541 the keyword doesn't affect the symbol table, so we don't have to
1542 restore between tries. */
1544 #define match(string, subr, statement) \
1545 if (gfc_match(string) == MATCH_YES) { m = subr(); goto got_match; }
1549 match ("allocate", gfc_match_allocate, ST_ALLOCATE)
1550 match ("assign", gfc_match_assign, ST_LABEL_ASSIGNMENT)
1551 match ("backspace", gfc_match_backspace, ST_BACKSPACE)
1552 match ("call", gfc_match_call, ST_CALL)
1553 match ("close", gfc_match_close, ST_CLOSE)
1554 match ("continue", gfc_match_continue, ST_CONTINUE)
1555 match ("cycle", gfc_match_cycle, ST_CYCLE)
1556 match ("deallocate", gfc_match_deallocate, ST_DEALLOCATE)
1557 match ("end file", gfc_match_endfile, ST_END_FILE)
1558 match ("error stop", gfc_match_error_stop, ST_ERROR_STOP)
1559 match ("exit", gfc_match_exit, ST_EXIT)
1560 match ("flush", gfc_match_flush, ST_FLUSH)
1561 match ("forall", match_simple_forall, ST_FORALL)
1562 match ("go to", gfc_match_goto, ST_GOTO)
1563 match ("if", match_arithmetic_if, ST_ARITHMETIC_IF)
1564 match ("inquire", gfc_match_inquire, ST_INQUIRE)
1565 match ("nullify", gfc_match_nullify, ST_NULLIFY)
1566 match ("open", gfc_match_open, ST_OPEN)
1567 match ("pause", gfc_match_pause, ST_NONE)
1568 match ("print", gfc_match_print, ST_WRITE)
1569 match ("read", gfc_match_read, ST_READ)
1570 match ("return", gfc_match_return, ST_RETURN)
1571 match ("rewind", gfc_match_rewind, ST_REWIND)
1572 match ("stop", gfc_match_stop, ST_STOP)
1573 match ("wait", gfc_match_wait, ST_WAIT)
1574 match ("sync all", gfc_match_sync_all, ST_SYNC_CALL);
1575 match ("sync images", gfc_match_sync_images, ST_SYNC_IMAGES);
1576 match ("sync memory", gfc_match_sync_memory, ST_SYNC_MEMORY);
1577 match ("where", match_simple_where, ST_WHERE)
1578 match ("write", gfc_match_write, ST_WRITE)
1580 /* The gfc_match_assignment() above may have returned a MATCH_NO
1581 where the assignment was to a named constant. Check that
1582 special case here. */
1583 m = gfc_match_assignment ();
1586 gfc_error ("Cannot assign to a named constant at %C");
1587 gfc_free_expr (expr);
1588 gfc_undo_symbols ();
1589 gfc_current_locus = old_loc;
1593 /* All else has failed, so give up. See if any of the matchers has
1594 stored an error message of some sort. */
1595 if (gfc_error_check () == 0)
1596 gfc_error ("Unclassifiable statement in IF-clause at %C");
1598 gfc_free_expr (expr);
1603 gfc_error ("Syntax error in IF-clause at %C");
1606 gfc_free_expr (expr);
1610 /* At this point, we've matched the single IF and the action clause
1611 is in new_st. Rearrange things so that the IF statement appears
1614 p = gfc_get_code ();
1615 p->next = gfc_get_code ();
1617 p->next->loc = gfc_current_locus;
1622 gfc_clear_new_st ();
1624 new_st.op = EXEC_IF;
1633 /* Match an ELSE statement. */
1636 gfc_match_else (void)
1638 char name[GFC_MAX_SYMBOL_LEN + 1];
1640 if (gfc_match_eos () == MATCH_YES)
1643 if (gfc_match_name (name) != MATCH_YES
1644 || gfc_current_block () == NULL
1645 || gfc_match_eos () != MATCH_YES)
1647 gfc_error ("Unexpected junk after ELSE statement at %C");
1651 if (strcmp (name, gfc_current_block ()->name) != 0)
1653 gfc_error ("Label '%s' at %C doesn't match IF label '%s'",
1654 name, gfc_current_block ()->name);
1662 /* Match an ELSE IF statement. */
1665 gfc_match_elseif (void)
1667 char name[GFC_MAX_SYMBOL_LEN + 1];
1671 m = gfc_match (" ( %e ) then", &expr);
1675 if (gfc_match_eos () == MATCH_YES)
1678 if (gfc_match_name (name) != MATCH_YES
1679 || gfc_current_block () == NULL
1680 || gfc_match_eos () != MATCH_YES)
1682 gfc_error ("Unexpected junk after ELSE IF statement at %C");
1686 if (strcmp (name, gfc_current_block ()->name) != 0)
1688 gfc_error ("Label '%s' at %C doesn't match IF label '%s'",
1689 name, gfc_current_block ()->name);
1694 new_st.op = EXEC_IF;
1695 new_st.expr1 = expr;
1699 gfc_free_expr (expr);
1704 /* Free a gfc_iterator structure. */
1707 gfc_free_iterator (gfc_iterator *iter, int flag)
1713 gfc_free_expr (iter->var);
1714 gfc_free_expr (iter->start);
1715 gfc_free_expr (iter->end);
1716 gfc_free_expr (iter->step);
1723 /* Match a CRITICAL statement. */
1725 gfc_match_critical (void)
1727 gfc_st_label *label = NULL;
1729 if (gfc_match_label () == MATCH_ERROR)
1732 if (gfc_match (" critical") != MATCH_YES)
1735 if (gfc_match_st_label (&label) == MATCH_ERROR)
1738 if (gfc_match_eos () != MATCH_YES)
1740 gfc_syntax_error (ST_CRITICAL);
1744 if (gfc_pure (NULL))
1746 gfc_error ("Image control statement CRITICAL at %C in PURE procedure");
1750 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: CRITICAL statement at %C")
1754 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
1756 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
1760 if (gfc_find_state (COMP_CRITICAL) == SUCCESS)
1762 gfc_error ("Nested CRITICAL block at %C");
1766 new_st.op = EXEC_CRITICAL;
1769 && gfc_reference_st_label (label, ST_LABEL_TARGET) == FAILURE)
1776 /* Match a BLOCK statement. */
1779 gfc_match_block (void)
1783 if (gfc_match_label () == MATCH_ERROR)
1786 if (gfc_match (" block") != MATCH_YES)
1789 /* For this to be a correct BLOCK statement, the line must end now. */
1790 m = gfc_match_eos ();
1791 if (m == MATCH_ERROR)
1800 /* Match an ASSOCIATE statement. */
1803 gfc_match_associate (void)
1805 if (gfc_match_label () == MATCH_ERROR)
1808 if (gfc_match (" associate") != MATCH_YES)
1811 /* Match the association list. */
1812 if (gfc_match_char ('(') != MATCH_YES)
1814 gfc_error ("Expected association list at %C");
1817 new_st.ext.block.assoc = NULL;
1820 gfc_association_list* newAssoc = gfc_get_association_list ();
1821 gfc_association_list* a;
1823 /* Match the next association. */
1824 if (gfc_match (" %n => %e", newAssoc->name, &newAssoc->target)
1827 gfc_error ("Expected association at %C");
1828 goto assocListError;
1831 /* Check that the current name is not yet in the list. */
1832 for (a = new_st.ext.block.assoc; a; a = a->next)
1833 if (!strcmp (a->name, newAssoc->name))
1835 gfc_error ("Duplicate name '%s' in association at %C",
1837 goto assocListError;
1840 /* The target expression must not be coindexed. */
1841 if (gfc_is_coindexed (newAssoc->target))
1843 gfc_error ("Association target at %C must not be coindexed");
1844 goto assocListError;
1847 /* The target is a variable (and may be used as lvalue) if it's an
1848 EXPR_VARIABLE and does not have vector-subscripts. */
1849 newAssoc->variable = (newAssoc->target->expr_type == EXPR_VARIABLE
1850 && !gfc_has_vector_subscript (newAssoc->target));
1852 /* Put it into the list. */
1853 newAssoc->next = new_st.ext.block.assoc;
1854 new_st.ext.block.assoc = newAssoc;
1856 /* Try next one or end if closing parenthesis is found. */
1857 gfc_gobble_whitespace ();
1858 if (gfc_peek_char () == ')')
1860 if (gfc_match_char (',') != MATCH_YES)
1862 gfc_error ("Expected ')' or ',' at %C");
1869 gfc_free (newAssoc);
1872 if (gfc_match_char (')') != MATCH_YES)
1874 /* This should never happen as we peek above. */
1878 if (gfc_match_eos () != MATCH_YES)
1880 gfc_error ("Junk after ASSOCIATE statement at %C");
1887 gfc_free_association_list (new_st.ext.block.assoc);
1892 /* Match a DO statement. */
1897 gfc_iterator iter, *ip;
1899 gfc_st_label *label;
1902 old_loc = gfc_current_locus;
1905 iter.var = iter.start = iter.end = iter.step = NULL;
1907 m = gfc_match_label ();
1908 if (m == MATCH_ERROR)
1911 if (gfc_match (" do") != MATCH_YES)
1914 m = gfc_match_st_label (&label);
1915 if (m == MATCH_ERROR)
1918 /* Match an infinite DO, make it like a DO WHILE(.TRUE.). */
1920 if (gfc_match_eos () == MATCH_YES)
1922 iter.end = gfc_get_logical_expr (gfc_default_logical_kind, NULL, true);
1923 new_st.op = EXEC_DO_WHILE;
1927 /* Match an optional comma, if no comma is found, a space is obligatory. */
1928 if (gfc_match_char (',') != MATCH_YES && gfc_match ("% ") != MATCH_YES)
1931 /* Check for balanced parens. */
1933 if (gfc_match_parens () == MATCH_ERROR)
1936 /* See if we have a DO WHILE. */
1937 if (gfc_match (" while ( %e )%t", &iter.end) == MATCH_YES)
1939 new_st.op = EXEC_DO_WHILE;
1943 /* The abortive DO WHILE may have done something to the symbol
1944 table, so we start over. */
1945 gfc_undo_symbols ();
1946 gfc_current_locus = old_loc;
1948 gfc_match_label (); /* This won't error. */
1949 gfc_match (" do "); /* This will work. */
1951 gfc_match_st_label (&label); /* Can't error out. */
1952 gfc_match_char (','); /* Optional comma. */
1954 m = gfc_match_iterator (&iter, 0);
1957 if (m == MATCH_ERROR)
1960 iter.var->symtree->n.sym->attr.implied_index = 0;
1961 gfc_check_do_variable (iter.var->symtree);
1963 if (gfc_match_eos () != MATCH_YES)
1965 gfc_syntax_error (ST_DO);
1969 new_st.op = EXEC_DO;
1973 && gfc_reference_st_label (label, ST_LABEL_TARGET) == FAILURE)
1976 new_st.label1 = label;
1978 if (new_st.op == EXEC_DO_WHILE)
1979 new_st.expr1 = iter.end;
1982 new_st.ext.iterator = ip = gfc_get_iterator ();
1989 gfc_free_iterator (&iter, 0);
1995 /* Match an EXIT or CYCLE statement. */
1998 match_exit_cycle (gfc_statement st, gfc_exec_op op)
2000 gfc_state_data *p, *o;
2005 if (gfc_match_eos () == MATCH_YES)
2009 char name[GFC_MAX_SYMBOL_LEN + 1];
2012 m = gfc_match ("% %n%t", name);
2013 if (m == MATCH_ERROR)
2017 gfc_syntax_error (st);
2021 /* Find the corresponding symbol. If there's a BLOCK statement
2022 between here and the label, it is not in gfc_current_ns but a parent
2024 stree = gfc_find_symtree_in_proc (name, gfc_current_ns);
2027 gfc_error ("Name '%s' in %s statement at %C is unknown",
2028 name, gfc_ascii_statement (st));
2033 if (sym->attr.flavor != FL_LABEL)
2035 gfc_error ("Name '%s' in %s statement at %C is not a loop name",
2036 name, gfc_ascii_statement (st));
2041 /* Find the loop specified by the label (or lack of a label). */
2042 for (o = NULL, p = gfc_state_stack; p; p = p->previous)
2043 if (p->state == COMP_DO && (sym == NULL || sym == p->sym))
2045 else if (o == NULL && p->state == COMP_OMP_STRUCTURED_BLOCK)
2047 else if (p->state == COMP_CRITICAL)
2049 gfc_error("%s statement at %C leaves CRITICAL construct",
2050 gfc_ascii_statement (st));
2057 gfc_error ("%s statement at %C is not within a loop",
2058 gfc_ascii_statement (st));
2060 gfc_error ("%s statement at %C is not within loop '%s'",
2061 gfc_ascii_statement (st), sym->name);
2068 gfc_error ("%s statement at %C leaving OpenMP structured block",
2069 gfc_ascii_statement (st));
2073 for (o = p, cnt = 0; o->state == COMP_DO && o->previous != NULL; cnt++)
2077 && o->state == COMP_OMP_STRUCTURED_BLOCK
2078 && (o->head->op == EXEC_OMP_DO
2079 || o->head->op == EXEC_OMP_PARALLEL_DO))
2082 gcc_assert (o->head->next != NULL
2083 && (o->head->next->op == EXEC_DO
2084 || o->head->next->op == EXEC_DO_WHILE)
2085 && o->previous != NULL
2086 && o->previous->tail->op == o->head->op);
2087 if (o->previous->tail->ext.omp_clauses != NULL
2088 && o->previous->tail->ext.omp_clauses->collapse > 1)
2089 collapse = o->previous->tail->ext.omp_clauses->collapse;
2090 if (st == ST_EXIT && cnt <= collapse)
2092 gfc_error ("EXIT statement at %C terminating !$OMP DO loop");
2095 if (st == ST_CYCLE && cnt < collapse)
2097 gfc_error ("CYCLE statement at %C to non-innermost collapsed !$OMP DO loop");
2102 /* Save the first statement in the loop - needed by the backend. */
2103 new_st.ext.whichloop = p->head;
2111 /* Match the EXIT statement. */
2114 gfc_match_exit (void)
2116 return match_exit_cycle (ST_EXIT, EXEC_EXIT);
2120 /* Match the CYCLE statement. */
2123 gfc_match_cycle (void)
2125 return match_exit_cycle (ST_CYCLE, EXEC_CYCLE);
2129 /* Match a number or character constant after an (ALL) STOP or PAUSE statement. */
2132 gfc_match_stopcode (gfc_statement st)
2139 if (gfc_match_eos () != MATCH_YES)
2141 m = gfc_match_init_expr (&e);
2142 if (m == MATCH_ERROR)
2147 if (gfc_match_eos () != MATCH_YES)
2151 if (gfc_pure (NULL))
2153 gfc_error ("%s statement not allowed in PURE procedure at %C",
2154 gfc_ascii_statement (st));
2158 if (st == ST_STOP && gfc_find_state (COMP_CRITICAL) == SUCCESS)
2160 gfc_error ("Image control statement STOP at %C in CRITICAL block");
2166 if (!(e->ts.type == BT_CHARACTER || e->ts.type == BT_INTEGER))
2168 gfc_error ("STOP code at %L must be either INTEGER or CHARACTER type",
2175 gfc_error ("STOP code at %L must be scalar",
2180 if (e->ts.type == BT_CHARACTER
2181 && e->ts.kind != gfc_default_character_kind)
2183 gfc_error ("STOP code at %L must be default character KIND=%d",
2184 &e->where, (int) gfc_default_character_kind);
2188 if (e->ts.type == BT_INTEGER
2189 && e->ts.kind != gfc_default_integer_kind)
2191 gfc_error ("STOP code at %L must be default integer KIND=%d",
2192 &e->where, (int) gfc_default_integer_kind);
2200 new_st.op = EXEC_STOP;
2203 new_st.op = EXEC_ERROR_STOP;
2206 new_st.op = EXEC_PAUSE;
2213 new_st.ext.stop_code = -1;
2218 gfc_syntax_error (st);
2227 /* Match the (deprecated) PAUSE statement. */
2230 gfc_match_pause (void)
2234 m = gfc_match_stopcode (ST_PAUSE);
2237 if (gfc_notify_std (GFC_STD_F95_DEL, "Deleted feature: PAUSE statement"
2246 /* Match the STOP statement. */
2249 gfc_match_stop (void)
2251 return gfc_match_stopcode (ST_STOP);
2255 /* Match the ERROR STOP statement. */
2258 gfc_match_error_stop (void)
2260 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: ERROR STOP statement at %C")
2264 return gfc_match_stopcode (ST_ERROR_STOP);
2268 /* Match SYNC ALL/IMAGES/MEMORY statement. Syntax:
2269 SYNC ALL [(sync-stat-list)]
2270 SYNC MEMORY [(sync-stat-list)]
2271 SYNC IMAGES (image-set [, sync-stat-list] )
2272 with sync-stat is int-expr or *. */
2275 sync_statement (gfc_statement st)
2278 gfc_expr *tmp, *imageset, *stat, *errmsg;
2279 bool saw_stat, saw_errmsg;
2281 tmp = imageset = stat = errmsg = NULL;
2282 saw_stat = saw_errmsg = false;
2284 if (gfc_pure (NULL))
2286 gfc_error ("Image control statement SYNC at %C in PURE procedure");
2290 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: SYNC statement at %C")
2294 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
2296 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
2300 if (gfc_find_state (COMP_CRITICAL) == SUCCESS)
2302 gfc_error ("Image control statement SYNC at %C in CRITICAL block");
2306 if (gfc_match_eos () == MATCH_YES)
2308 if (st == ST_SYNC_IMAGES)
2313 if (gfc_match_char ('(') != MATCH_YES)
2316 if (st == ST_SYNC_IMAGES)
2318 /* Denote '*' as imageset == NULL. */
2319 m = gfc_match_char ('*');
2320 if (m == MATCH_ERROR)
2324 if (gfc_match ("%e", &imageset) != MATCH_YES)
2327 m = gfc_match_char (',');
2328 if (m == MATCH_ERROR)
2332 m = gfc_match_char (')');
2341 m = gfc_match (" stat = %v", &tmp);
2342 if (m == MATCH_ERROR)
2348 gfc_error ("Redundant STAT tag found at %L ", &tmp->where);
2354 if (gfc_match_char (',') == MATCH_YES)
2358 m = gfc_match (" errmsg = %v", &tmp);
2359 if (m == MATCH_ERROR)
2365 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp->where);
2371 if (gfc_match_char (',') == MATCH_YES)
2375 gfc_gobble_whitespace ();
2377 if (gfc_peek_char () == ')')
2383 if (gfc_match (" )%t") != MATCH_YES)
2390 new_st.op = EXEC_SYNC_ALL;
2392 case ST_SYNC_IMAGES:
2393 new_st.op = EXEC_SYNC_IMAGES;
2395 case ST_SYNC_MEMORY:
2396 new_st.op = EXEC_SYNC_MEMORY;
2402 new_st.expr1 = imageset;
2403 new_st.expr2 = stat;
2404 new_st.expr3 = errmsg;
2409 gfc_syntax_error (st);
2412 gfc_free_expr (tmp);
2413 gfc_free_expr (imageset);
2414 gfc_free_expr (stat);
2415 gfc_free_expr (errmsg);
2421 /* Match SYNC ALL statement. */
2424 gfc_match_sync_all (void)
2426 return sync_statement (ST_SYNC_ALL);
2430 /* Match SYNC IMAGES statement. */
2433 gfc_match_sync_images (void)
2435 return sync_statement (ST_SYNC_IMAGES);
2439 /* Match SYNC MEMORY statement. */
2442 gfc_match_sync_memory (void)
2444 return sync_statement (ST_SYNC_MEMORY);
2448 /* Match a CONTINUE statement. */
2451 gfc_match_continue (void)
2453 if (gfc_match_eos () != MATCH_YES)
2455 gfc_syntax_error (ST_CONTINUE);
2459 new_st.op = EXEC_CONTINUE;
2464 /* Match the (deprecated) ASSIGN statement. */
2467 gfc_match_assign (void)
2470 gfc_st_label *label;
2472 if (gfc_match (" %l", &label) == MATCH_YES)
2474 if (gfc_reference_st_label (label, ST_LABEL_UNKNOWN) == FAILURE)
2476 if (gfc_match (" to %v%t", &expr) == MATCH_YES)
2478 if (gfc_notify_std (GFC_STD_F95_DEL, "Deleted feature: ASSIGN "
2483 expr->symtree->n.sym->attr.assign = 1;
2485 new_st.op = EXEC_LABEL_ASSIGN;
2486 new_st.label1 = label;
2487 new_st.expr1 = expr;
2495 /* Match the GO TO statement. As a computed GOTO statement is
2496 matched, it is transformed into an equivalent SELECT block. No
2497 tree is necessary, and the resulting jumps-to-jumps are
2498 specifically optimized away by the back end. */
2501 gfc_match_goto (void)
2503 gfc_code *head, *tail;
2506 gfc_st_label *label;
2510 if (gfc_match (" %l%t", &label) == MATCH_YES)
2512 if (gfc_reference_st_label (label, ST_LABEL_TARGET) == FAILURE)
2515 new_st.op = EXEC_GOTO;
2516 new_st.label1 = label;
2520 /* The assigned GO TO statement. */
2522 if (gfc_match_variable (&expr, 0) == MATCH_YES)
2524 if (gfc_notify_std (GFC_STD_F95_DEL, "Deleted feature: Assigned GOTO "
2529 new_st.op = EXEC_GOTO;
2530 new_st.expr1 = expr;
2532 if (gfc_match_eos () == MATCH_YES)
2535 /* Match label list. */
2536 gfc_match_char (',');
2537 if (gfc_match_char ('(') != MATCH_YES)
2539 gfc_syntax_error (ST_GOTO);
2546 m = gfc_match_st_label (&label);
2550 if (gfc_reference_st_label (label, ST_LABEL_TARGET) == FAILURE)
2554 head = tail = gfc_get_code ();
2557 tail->block = gfc_get_code ();
2561 tail->label1 = label;
2562 tail->op = EXEC_GOTO;
2564 while (gfc_match_char (',') == MATCH_YES);
2566 if (gfc_match (")%t") != MATCH_YES)
2571 gfc_error ("Statement label list in GOTO at %C cannot be empty");
2574 new_st.block = head;
2579 /* Last chance is a computed GO TO statement. */
2580 if (gfc_match_char ('(') != MATCH_YES)
2582 gfc_syntax_error (ST_GOTO);
2591 m = gfc_match_st_label (&label);
2595 if (gfc_reference_st_label (label, ST_LABEL_TARGET) == FAILURE)
2599 head = tail = gfc_get_code ();
2602 tail->block = gfc_get_code ();
2606 cp = gfc_get_case ();
2607 cp->low = cp->high = gfc_get_int_expr (gfc_default_integer_kind,
2610 tail->op = EXEC_SELECT;
2611 tail->ext.case_list = cp;
2613 tail->next = gfc_get_code ();
2614 tail->next->op = EXEC_GOTO;
2615 tail->next->label1 = label;
2617 while (gfc_match_char (',') == MATCH_YES);
2619 if (gfc_match_char (')') != MATCH_YES)
2624 gfc_error ("Statement label list in GOTO at %C cannot be empty");
2628 /* Get the rest of the statement. */
2629 gfc_match_char (',');
2631 if (gfc_match (" %e%t", &expr) != MATCH_YES)
2634 if (gfc_notify_std (GFC_STD_F95_OBS, "Obsolescent feature: Computed GOTO "
2635 "at %C") == FAILURE)
2638 /* At this point, a computed GOTO has been fully matched and an
2639 equivalent SELECT statement constructed. */
2641 new_st.op = EXEC_SELECT;
2642 new_st.expr1 = NULL;
2644 /* Hack: For a "real" SELECT, the expression is in expr. We put
2645 it in expr2 so we can distinguish then and produce the correct
2647 new_st.expr2 = expr;
2648 new_st.block = head;
2652 gfc_syntax_error (ST_GOTO);
2654 gfc_free_statements (head);
2659 /* Frees a list of gfc_alloc structures. */
2662 gfc_free_alloc_list (gfc_alloc *p)
2669 gfc_free_expr (p->expr);
2675 /* Match a Fortran 2003 derived-type-spec (F03:R455), which is just the name of
2676 an accessible derived type. */
2679 match_derived_type_spec (gfc_typespec *ts)
2682 gfc_symbol *derived;
2684 old_locus = gfc_current_locus;
2686 if (gfc_match_symbol (&derived, 1) == MATCH_YES)
2688 if (derived->attr.flavor == FL_DERIVED)
2690 ts->type = BT_DERIVED;
2691 ts->u.derived = derived;
2696 /* Enforce F03:C476. */
2697 gfc_error ("'%s' at %L is not an accessible derived type",
2698 derived->name, &gfc_current_locus);
2703 gfc_current_locus = old_locus;
2708 /* Match a Fortran 2003 type-spec (F03:R401). This is similar to
2709 gfc_match_decl_type_spec() from decl.c, with the following exceptions:
2710 It only includes the intrinsic types from the Fortran 2003 standard
2711 (thus, neither BYTE nor forms like REAL*4 are allowed). Additionally,
2712 the implicit_flag is not needed, so it was removed. Derived types are
2713 identified by their name alone. */
2716 match_type_spec (gfc_typespec *ts)
2722 gfc_gobble_whitespace();
2723 old_locus = gfc_current_locus;
2725 m = match_derived_type_spec (ts);
2728 old_locus = gfc_current_locus;
2729 if (gfc_match (" :: ") != MATCH_YES)
2731 gfc_current_locus = old_locus;
2732 /* Enfore F03:C401. */
2733 if (ts->u.derived->attr.abstract)
2735 gfc_error ("Derived type '%s' at %L may not be ABSTRACT",
2736 ts->u.derived->name, &old_locus);
2741 else if (m == MATCH_ERROR && gfc_match (" :: ") == MATCH_YES)
2744 gfc_current_locus = old_locus;
2746 if (gfc_match ("integer") == MATCH_YES)
2748 ts->type = BT_INTEGER;
2749 ts->kind = gfc_default_integer_kind;
2753 if (gfc_match ("real") == MATCH_YES)
2756 ts->kind = gfc_default_real_kind;
2760 if (gfc_match ("double precision") == MATCH_YES)
2763 ts->kind = gfc_default_double_kind;
2767 if (gfc_match ("complex") == MATCH_YES)
2769 ts->type = BT_COMPLEX;
2770 ts->kind = gfc_default_complex_kind;
2774 if (gfc_match ("character") == MATCH_YES)
2776 ts->type = BT_CHARACTER;
2780 if (gfc_match ("logical") == MATCH_YES)
2782 ts->type = BT_LOGICAL;
2783 ts->kind = gfc_default_logical_kind;
2787 /* If a type is not matched, simply return MATCH_NO. */
2788 gfc_current_locus = old_locus;
2793 gfc_gobble_whitespace ();
2794 if (gfc_peek_ascii_char () == '*')
2796 gfc_error ("Invalid type-spec at %C");
2800 m = gfc_match_kind_spec (ts, false);
2803 m = MATCH_YES; /* No kind specifier found. */
2809 m = gfc_match_char_spec (ts);
2812 m = MATCH_YES; /* No kind specifier found. */
2818 /* Match an ALLOCATE statement. */
2821 gfc_match_allocate (void)
2823 gfc_alloc *head, *tail;
2824 gfc_expr *stat, *errmsg, *tmp, *source, *mold;
2829 bool saw_stat, saw_errmsg, saw_source, saw_mold, b1, b2, b3;
2832 stat = errmsg = source = mold = tmp = NULL;
2833 saw_stat = saw_errmsg = saw_source = saw_mold = false;
2835 if (gfc_match_char ('(') != MATCH_YES)
2838 /* Match an optional type-spec. */
2839 old_locus = gfc_current_locus;
2840 m = match_type_spec (&ts);
2841 if (m == MATCH_ERROR)
2843 else if (m == MATCH_NO)
2844 ts.type = BT_UNKNOWN;
2847 if (gfc_match (" :: ") == MATCH_YES)
2849 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: typespec in "
2850 "ALLOCATE at %L", &old_locus) == FAILURE)
2855 ts.type = BT_UNKNOWN;
2856 gfc_current_locus = old_locus;
2863 head = tail = gfc_get_alloc ();
2866 tail->next = gfc_get_alloc ();
2870 m = gfc_match_variable (&tail->expr, 0);
2873 if (m == MATCH_ERROR)
2876 if (gfc_check_do_variable (tail->expr->symtree))
2879 if (gfc_pure (NULL) && gfc_impure_variable (tail->expr->symtree->n.sym))
2881 gfc_error ("Bad allocate-object at %C for a PURE procedure");
2885 /* The ALLOCATE statement had an optional typespec. Check the
2887 if (ts.type != BT_UNKNOWN)
2889 /* Enforce F03:C624. */
2890 if (!gfc_type_compatible (&tail->expr->ts, &ts))
2892 gfc_error ("Type of entity at %L is type incompatible with "
2893 "typespec", &tail->expr->where);
2897 /* Enforce F03:C627. */
2898 if (ts.kind != tail->expr->ts.kind)
2900 gfc_error ("Kind type parameter for entity at %L differs from "
2901 "the kind type parameter of the typespec",
2902 &tail->expr->where);
2907 if (tail->expr->ts.type == BT_DERIVED)
2908 tail->expr->ts.u.derived = gfc_use_derived (tail->expr->ts.u.derived);
2910 /* FIXME: disable the checking on derived types and arrays. */
2911 sym = tail->expr->symtree->n.sym;
2912 b1 = !(tail->expr->ref
2913 && (tail->expr->ref->type == REF_COMPONENT
2914 || tail->expr->ref->type == REF_ARRAY));
2915 if (sym && sym->ts.type == BT_CLASS)
2916 b2 = !(CLASS_DATA (sym)->attr.allocatable
2917 || CLASS_DATA (sym)->attr.class_pointer);
2919 b2 = sym && !(sym->attr.allocatable || sym->attr.pointer
2920 || sym->attr.proc_pointer);
2921 b3 = sym && sym->ns && sym->ns->proc_name
2922 && (sym->ns->proc_name->attr.allocatable
2923 || sym->ns->proc_name->attr.pointer
2924 || sym->ns->proc_name->attr.proc_pointer);
2925 if (b1 && b2 && !b3)
2927 gfc_error ("Allocate-object at %C is not a nonprocedure pointer "
2928 "or an allocatable variable");
2932 if (gfc_peek_ascii_char () == '(' && !sym->attr.dimension)
2934 gfc_error ("Shape specification for allocatable scalar at %C");
2938 if (gfc_match_char (',') != MATCH_YES)
2943 m = gfc_match (" stat = %v", &tmp);
2944 if (m == MATCH_ERROR)
2951 gfc_error ("Redundant STAT tag found at %L ", &tmp->where);
2958 if (gfc_check_do_variable (stat->symtree))
2961 if (gfc_match_char (',') == MATCH_YES)
2962 goto alloc_opt_list;
2965 m = gfc_match (" errmsg = %v", &tmp);
2966 if (m == MATCH_ERROR)
2970 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ERRMSG tag at %L",
2971 &tmp->where) == FAILURE)
2977 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp->where);
2984 if (gfc_match_char (',') == MATCH_YES)
2985 goto alloc_opt_list;
2988 m = gfc_match (" source = %e", &tmp);
2989 if (m == MATCH_ERROR)
2993 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: SOURCE tag at %L",
2994 &tmp->where) == FAILURE)
3000 gfc_error ("Redundant SOURCE tag found at %L ", &tmp->where);
3004 /* The next 2 conditionals check C631. */
3005 if (ts.type != BT_UNKNOWN)
3007 gfc_error ("SOURCE tag at %L conflicts with the typespec at %L",
3008 &tmp->where, &old_locus);
3014 gfc_error ("SOURCE tag at %L requires only a single entity in "
3015 "the allocation-list", &tmp->where);
3022 if (gfc_match_char (',') == MATCH_YES)
3023 goto alloc_opt_list;
3026 m = gfc_match (" mold = %e", &tmp);
3027 if (m == MATCH_ERROR)
3031 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: MOLD tag at %L",
3032 &tmp->where) == FAILURE)
3035 /* Check F08:C636. */
3038 gfc_error ("Redundant MOLD tag found at %L ", &tmp->where);
3042 /* Check F08:C637. */
3043 if (ts.type != BT_UNKNOWN)
3045 gfc_error ("MOLD tag at %L conflicts with the typespec at %L",
3046 &tmp->where, &old_locus);
3054 if (gfc_match_char (',') == MATCH_YES)
3055 goto alloc_opt_list;
3058 gfc_gobble_whitespace ();
3060 if (gfc_peek_char () == ')')
3065 if (gfc_match (" )%t") != MATCH_YES)
3068 /* Check F08:C637. */
3071 gfc_error ("MOLD tag at %L conflicts with SOURCE tag at %L",
3072 &mold->where, &source->where);
3076 new_st.op = EXEC_ALLOCATE;
3077 new_st.expr1 = stat;
3078 new_st.expr2 = errmsg;
3080 new_st.expr3 = source;
3082 new_st.expr3 = mold;
3083 new_st.ext.alloc.list = head;
3084 new_st.ext.alloc.ts = ts;
3089 gfc_syntax_error (ST_ALLOCATE);
3092 gfc_free_expr (errmsg);
3093 gfc_free_expr (source);
3094 gfc_free_expr (stat);
3095 gfc_free_expr (mold);
3096 if (tmp && tmp->expr_type) gfc_free_expr (tmp);
3097 gfc_free_alloc_list (head);
3102 /* Match a NULLIFY statement. A NULLIFY statement is transformed into
3103 a set of pointer assignments to intrinsic NULL(). */
3106 gfc_match_nullify (void)
3114 if (gfc_match_char ('(') != MATCH_YES)
3119 m = gfc_match_variable (&p, 0);
3120 if (m == MATCH_ERROR)
3125 if (gfc_check_do_variable (p->symtree))
3128 if (gfc_pure (NULL) && gfc_impure_variable (p->symtree->n.sym))
3130 gfc_error ("Illegal variable in NULLIFY at %C for a PURE procedure");
3134 /* build ' => NULL() '. */
3135 e = gfc_get_null_expr (&gfc_current_locus);
3137 /* Chain to list. */
3142 tail->next = gfc_get_code ();
3146 tail->op = EXEC_POINTER_ASSIGN;
3150 if (gfc_match (" )%t") == MATCH_YES)
3152 if (gfc_match_char (',') != MATCH_YES)
3159 gfc_syntax_error (ST_NULLIFY);
3162 gfc_free_statements (new_st.next);
3164 gfc_free_expr (new_st.expr1);
3165 new_st.expr1 = NULL;
3166 gfc_free_expr (new_st.expr2);
3167 new_st.expr2 = NULL;
3172 /* Match a DEALLOCATE statement. */
3175 gfc_match_deallocate (void)
3177 gfc_alloc *head, *tail;
3178 gfc_expr *stat, *errmsg, *tmp;
3181 bool saw_stat, saw_errmsg, b1, b2;
3184 stat = errmsg = tmp = NULL;
3185 saw_stat = saw_errmsg = false;
3187 if (gfc_match_char ('(') != MATCH_YES)
3193 head = tail = gfc_get_alloc ();
3196 tail->next = gfc_get_alloc ();
3200 m = gfc_match_variable (&tail->expr, 0);
3201 if (m == MATCH_ERROR)
3206 if (gfc_check_do_variable (tail->expr->symtree))
3209 sym = tail->expr->symtree->n.sym;
3211 if (gfc_pure (NULL) && gfc_impure_variable (sym))
3213 gfc_error ("Illegal allocate-object at %C for a PURE procedure");
3217 /* FIXME: disable the checking on derived types. */
3218 b1 = !(tail->expr->ref
3219 && (tail->expr->ref->type == REF_COMPONENT
3220 || tail->expr->ref->type == REF_ARRAY));
3221 if (sym && sym->ts.type == BT_CLASS)
3222 b2 = !(CLASS_DATA (sym)->attr.allocatable
3223 || CLASS_DATA (sym)->attr.class_pointer);
3225 b2 = sym && !(sym->attr.allocatable || sym->attr.pointer
3226 || sym->attr.proc_pointer);
3229 gfc_error ("Allocate-object at %C is not a nonprocedure pointer "
3230 "or an allocatable variable");
3234 if (gfc_match_char (',') != MATCH_YES)
3239 m = gfc_match (" stat = %v", &tmp);
3240 if (m == MATCH_ERROR)
3246 gfc_error ("Redundant STAT tag found at %L ", &tmp->where);
3247 gfc_free_expr (tmp);
3254 if (gfc_check_do_variable (stat->symtree))
3257 if (gfc_match_char (',') == MATCH_YES)
3258 goto dealloc_opt_list;
3261 m = gfc_match (" errmsg = %v", &tmp);
3262 if (m == MATCH_ERROR)
3266 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: ERRMSG at %L",
3267 &tmp->where) == FAILURE)
3272 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp->where);
3273 gfc_free_expr (tmp);
3280 if (gfc_match_char (',') == MATCH_YES)
3281 goto dealloc_opt_list;
3284 gfc_gobble_whitespace ();
3286 if (gfc_peek_char () == ')')
3290 if (gfc_match (" )%t") != MATCH_YES)
3293 new_st.op = EXEC_DEALLOCATE;
3294 new_st.expr1 = stat;
3295 new_st.expr2 = errmsg;
3296 new_st.ext.alloc.list = head;
3301 gfc_syntax_error (ST_DEALLOCATE);
3304 gfc_free_expr (errmsg);
3305 gfc_free_expr (stat);
3306 gfc_free_alloc_list (head);
3311 /* Match a RETURN statement. */
3314 gfc_match_return (void)
3318 gfc_compile_state s;
3322 if (gfc_find_state (COMP_CRITICAL) == SUCCESS)
3324 gfc_error ("Image control statement RETURN at %C in CRITICAL block");
3328 if (gfc_match_eos () == MATCH_YES)
3331 if (gfc_find_state (COMP_SUBROUTINE) == FAILURE)
3333 gfc_error ("Alternate RETURN statement at %C is only allowed within "
3338 if (gfc_notify_std (GFC_STD_F95_OBS, "Obsolescent feature: Alternate RETURN "
3339 "at %C") == FAILURE)
3342 if (gfc_current_form == FORM_FREE)
3344 /* The following are valid, so we can't require a blank after the
3348 char c = gfc_peek_ascii_char ();
3349 if (ISALPHA (c) || ISDIGIT (c))
3353 m = gfc_match (" %e%t", &e);
3356 if (m == MATCH_ERROR)
3359 gfc_syntax_error (ST_RETURN);
3366 gfc_enclosing_unit (&s);
3367 if (s == COMP_PROGRAM
3368 && gfc_notify_std (GFC_STD_GNU, "Extension: RETURN statement in "
3369 "main program at %C") == FAILURE)
3372 new_st.op = EXEC_RETURN;
3379 /* Match the call of a type-bound procedure, if CALL%var has already been
3380 matched and var found to be a derived-type variable. */
3383 match_typebound_call (gfc_symtree* varst)
3388 base = gfc_get_expr ();
3389 base->expr_type = EXPR_VARIABLE;
3390 base->symtree = varst;
3391 base->where = gfc_current_locus;
3392 gfc_set_sym_referenced (varst->n.sym);
3394 m = gfc_match_varspec (base, 0, true, true);
3396 gfc_error ("Expected component reference at %C");
3400 if (gfc_match_eos () != MATCH_YES)
3402 gfc_error ("Junk after CALL at %C");
3406 if (base->expr_type == EXPR_COMPCALL)
3407 new_st.op = EXEC_COMPCALL;
3408 else if (base->expr_type == EXPR_PPC)
3409 new_st.op = EXEC_CALL_PPC;
3412 gfc_error ("Expected type-bound procedure or procedure pointer component "
3416 new_st.expr1 = base;
3422 /* Match a CALL statement. The tricky part here are possible
3423 alternate return specifiers. We handle these by having all
3424 "subroutines" actually return an integer via a register that gives
3425 the return number. If the call specifies alternate returns, we
3426 generate code for a SELECT statement whose case clauses contain
3427 GOTOs to the various labels. */
3430 gfc_match_call (void)
3432 char name[GFC_MAX_SYMBOL_LEN + 1];
3433 gfc_actual_arglist *a, *arglist;
3443 m = gfc_match ("% %n", name);
3449 if (gfc_get_ha_sym_tree (name, &st))
3454 /* If this is a variable of derived-type, it probably starts a type-bound
3456 if ((sym->attr.flavor != FL_PROCEDURE
3457 || gfc_is_function_return_value (sym, gfc_current_ns))
3458 && (sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS))
3459 return match_typebound_call (st);
3461 /* If it does not seem to be callable (include functions so that the
3462 right association is made. They are thrown out in resolution.)
3464 if (!sym->attr.generic
3465 && !sym->attr.subroutine
3466 && !sym->attr.function)
3468 if (!(sym->attr.external && !sym->attr.referenced))
3470 /* ...create a symbol in this scope... */
3471 if (sym->ns != gfc_current_ns
3472 && gfc_get_sym_tree (name, NULL, &st, false) == 1)
3475 if (sym != st->n.sym)
3479 /* ...and then to try to make the symbol into a subroutine. */
3480 if (gfc_add_subroutine (&sym->attr, sym->name, NULL) == FAILURE)
3484 gfc_set_sym_referenced (sym);
3486 if (gfc_match_eos () != MATCH_YES)
3488 m = gfc_match_actual_arglist (1, &arglist);
3491 if (m == MATCH_ERROR)
3494 if (gfc_match_eos () != MATCH_YES)
3498 /* If any alternate return labels were found, construct a SELECT
3499 statement that will jump to the right place. */
3502 for (a = arglist; a; a = a->next)
3503 if (a->expr == NULL)
3508 gfc_symtree *select_st;
3509 gfc_symbol *select_sym;
3510 char name[GFC_MAX_SYMBOL_LEN + 1];
3512 new_st.next = c = gfc_get_code ();
3513 c->op = EXEC_SELECT;
3514 sprintf (name, "_result_%s", sym->name);
3515 gfc_get_ha_sym_tree (name, &select_st); /* Can't fail. */
3517 select_sym = select_st->n.sym;
3518 select_sym->ts.type = BT_INTEGER;
3519 select_sym->ts.kind = gfc_default_integer_kind;
3520 gfc_set_sym_referenced (select_sym);
3521 c->expr1 = gfc_get_expr ();
3522 c->expr1->expr_type = EXPR_VARIABLE;
3523 c->expr1->symtree = select_st;
3524 c->expr1->ts = select_sym->ts;
3525 c->expr1->where = gfc_current_locus;
3528 for (a = arglist; a; a = a->next)
3530 if (a->expr != NULL)
3533 if (gfc_reference_st_label (a->label, ST_LABEL_TARGET) == FAILURE)
3538 c->block = gfc_get_code ();
3540 c->op = EXEC_SELECT;
3542 new_case = gfc_get_case ();
3543 new_case->high = gfc_get_int_expr (gfc_default_integer_kind, NULL, i);
3544 new_case->low = new_case->high;
3545 c->ext.case_list = new_case;
3547 c->next = gfc_get_code ();
3548 c->next->op = EXEC_GOTO;
3549 c->next->label1 = a->label;
3553 new_st.op = EXEC_CALL;
3554 new_st.symtree = st;
3555 new_st.ext.actual = arglist;
3560 gfc_syntax_error (ST_CALL);
3563 gfc_free_actual_arglist (arglist);
3568 /* Given a name, return a pointer to the common head structure,
3569 creating it if it does not exist. If FROM_MODULE is nonzero, we
3570 mangle the name so that it doesn't interfere with commons defined
3571 in the using namespace.
3572 TODO: Add to global symbol tree. */
3575 gfc_get_common (const char *name, int from_module)
3578 static int serial = 0;
3579 char mangled_name[GFC_MAX_SYMBOL_LEN + 1];
3583 /* A use associated common block is only needed to correctly layout
3584 the variables it contains. */
3585 snprintf (mangled_name, GFC_MAX_SYMBOL_LEN, "_%d_%s", serial++, name);
3586 st = gfc_new_symtree (&gfc_current_ns->common_root, mangled_name);
3590 st = gfc_find_symtree (gfc_current_ns->common_root, name);
3593 st = gfc_new_symtree (&gfc_current_ns->common_root, name);
3596 if (st->n.common == NULL)
3598 st->n.common = gfc_get_common_head ();
3599 st->n.common->where = gfc_current_locus;
3600 strcpy (st->n.common->name, name);
3603 return st->n.common;
3607 /* Match a common block name. */
3609 match match_common_name (char *name)
3613 if (gfc_match_char ('/') == MATCH_NO)
3619 if (gfc_match_char ('/') == MATCH_YES)
3625 m = gfc_match_name (name);
3627 if (m == MATCH_ERROR)
3629 if (m == MATCH_YES && gfc_match_char ('/') == MATCH_YES)
3632 gfc_error ("Syntax error in common block name at %C");
3637 /* Match a COMMON statement. */
3640 gfc_match_common (void)
3642 gfc_symbol *sym, **head, *tail, *other, *old_blank_common;
3643 char name[GFC_MAX_SYMBOL_LEN + 1];
3650 old_blank_common = gfc_current_ns->blank_common.head;
3651 if (old_blank_common)
3653 while (old_blank_common->common_next)
3654 old_blank_common = old_blank_common->common_next;
3661 m = match_common_name (name);
3662 if (m == MATCH_ERROR)
3665 gsym = gfc_get_gsymbol (name);
3666 if (gsym->type != GSYM_UNKNOWN && gsym->type != GSYM_COMMON)
3668 gfc_error ("Symbol '%s' at %C is already an external symbol that "
3669 "is not COMMON", name);
3673 if (gsym->type == GSYM_UNKNOWN)
3675 gsym->type = GSYM_COMMON;
3676 gsym->where = gfc_current_locus;
3682 if (name[0] == '\0')
3684 t = &gfc_current_ns->blank_common;
3685 if (t->head == NULL)
3686 t->where = gfc_current_locus;
3690 t = gfc_get_common (name, 0);
3699 while (tail->common_next)
3700 tail = tail->common_next;
3703 /* Grab the list of symbols. */
3706 m = gfc_match_symbol (&sym, 0);
3707 if (m == MATCH_ERROR)
3712 /* Store a ref to the common block for error checking. */
3713 sym->common_block = t;
3715 /* See if we know the current common block is bind(c), and if
3716 so, then see if we can check if the symbol is (which it'll
3717 need to be). This can happen if the bind(c) attr stmt was
3718 applied to the common block, and the variable(s) already
3719 defined, before declaring the common block. */
3720 if (t->is_bind_c == 1)
3722 if (sym->ts.type != BT_UNKNOWN && sym->ts.is_c_interop != 1)
3724 /* If we find an error, just print it and continue,
3725 cause it's just semantic, and we can see if there
3727 gfc_error_now ("Variable '%s' at %L in common block '%s' "
3728 "at %C must be declared with a C "
3729 "interoperable kind since common block "
3731 sym->name, &(sym->declared_at), t->name,
3735 if (sym->attr.is_bind_c == 1)
3736 gfc_error_now ("Variable '%s' in common block "
3737 "'%s' at %C can not be bind(c) since "
3738 "it is not global", sym->name, t->name);
3741 if (sym->attr.in_common)
3743 gfc_error ("Symbol '%s' at %C is already in a COMMON block",
3748 if (((sym->value != NULL && sym->value->expr_type != EXPR_NULL)
3749 || sym->attr.data) && gfc_current_state () != COMP_BLOCK_DATA)
3751 if (gfc_notify_std (GFC_STD_GNU, "Initialized symbol '%s' at %C "
3752 "can only be COMMON in "
3753 "BLOCK DATA", sym->name)
3758 if (gfc_add_in_common (&sym->attr, sym->name, NULL) == FAILURE)
3762 tail->common_next = sym;
3768 /* Deal with an optional array specification after the
3770 m = gfc_match_array_spec (&as, true, true);
3771 if (m == MATCH_ERROR)
3776 if (as->type != AS_EXPLICIT)
3778 gfc_error ("Array specification for symbol '%s' in COMMON "
3779 "at %C must be explicit", sym->name);
3783 if (gfc_add_dimension (&sym->attr, sym->name, NULL) == FAILURE)
3786 if (sym->attr.pointer)
3788 gfc_error ("Symbol '%s' in COMMON at %C cannot be a "
3789 "POINTER array", sym->name);
3798 sym->common_head = t;
3800 /* Check to see if the symbol is already in an equivalence group.
3801 If it is, set the other members as being in common. */
3802 if (sym->attr.in_equivalence)
3804 for (e1 = gfc_current_ns->equiv; e1; e1 = e1->next)
3806 for (e2 = e1; e2; e2 = e2->eq)
3807 if (e2->expr->symtree->n.sym == sym)
3814 for (e2 = e1; e2; e2 = e2->eq)
3816 other = e2->expr->symtree->n.sym;
3817 if (other->common_head
3818 && other->common_head != sym->common_head)
3820 gfc_error ("Symbol '%s', in COMMON block '%s' at "
3821 "%C is being indirectly equivalenced to "
3822 "another COMMON block '%s'",
3823 sym->name, sym->common_head->name,
3824 other->common_head->name);
3827 other->attr.in_common = 1;
3828 other->common_head = t;
3834 gfc_gobble_whitespace ();
3835 if (gfc_match_eos () == MATCH_YES)
3837 if (gfc_peek_ascii_char () == '/')
3839 if (gfc_match_char (',') != MATCH_YES)
3841 gfc_gobble_whitespace ();
3842 if (gfc_peek_ascii_char () == '/')
3851 gfc_syntax_error (ST_COMMON);
3854 if (old_blank_common)
3855 old_blank_common->common_next = NULL;
3857 gfc_current_ns->blank_common.head = NULL;
3858 gfc_free_array_spec (as);
3863 /* Match a BLOCK DATA program unit. */
3866 gfc_match_block_data (void)
3868 char name[GFC_MAX_SYMBOL_LEN + 1];
3872 if (gfc_match_eos () == MATCH_YES)
3874 gfc_new_block = NULL;
3878 m = gfc_match ("% %n%t", name);
3882 if (gfc_get_symbol (name, NULL, &sym))
3885 if (gfc_add_flavor (&sym->attr, FL_BLOCK_DATA, sym->name, NULL) == FAILURE)
3888 gfc_new_block = sym;
3894 /* Free a namelist structure. */
3897 gfc_free_namelist (gfc_namelist *name)
3901 for (; name; name = n)
3909 /* Match a NAMELIST statement. */
3912 gfc_match_namelist (void)
3914 gfc_symbol *group_name, *sym;
3918 m = gfc_match (" / %s /", &group_name);
3921 if (m == MATCH_ERROR)
3926 if (group_name->ts.type != BT_UNKNOWN)
3928 gfc_error ("Namelist group name '%s' at %C already has a basic "
3929 "type of %s", group_name->name,
3930 gfc_typename (&group_name->ts));
3934 if (group_name->attr.flavor == FL_NAMELIST
3935 && group_name->attr.use_assoc
3936 && gfc_notify_std (GFC_STD_GNU, "Namelist group name '%s' "
3937 "at %C already is USE associated and can"
3938 "not be respecified.", group_name->name)
3942 if (group_name->attr.flavor != FL_NAMELIST
3943 && gfc_add_flavor (&group_name->attr, FL_NAMELIST,
3944 group_name->name, NULL) == FAILURE)
3949 m = gfc_match_symbol (&sym, 1);
3952 if (m == MATCH_ERROR)
3955 if (sym->attr.in_namelist == 0
3956 && gfc_add_in_namelist (&sym->attr, sym->name, NULL) == FAILURE)
3959 /* Use gfc_error_check here, rather than goto error, so that
3960 these are the only errors for the next two lines. */
3961 if (sym->as && sym->as->type == AS_ASSUMED_SIZE)
3963 gfc_error ("Assumed size array '%s' in namelist '%s' at "
3964 "%C is not allowed", sym->name, group_name->name);
3968 if (sym->ts.type == BT_CHARACTER && sym->ts.u.cl->length == NULL)
3970 gfc_error ("Assumed character length '%s' in namelist '%s' at "
3971 "%C is not allowed", sym->name, group_name->name);
3975 nl = gfc_get_namelist ();
3979 if (group_name->namelist == NULL)
3980 group_name->namelist = group_name->namelist_tail = nl;
3983 group_name->namelist_tail->next = nl;
3984 group_name->namelist_tail = nl;
3987 if (gfc_match_eos () == MATCH_YES)
3990 m = gfc_match_char (',');
3992 if (gfc_match_char ('/') == MATCH_YES)
3994 m2 = gfc_match (" %s /", &group_name);
3995 if (m2 == MATCH_YES)
3997 if (m2 == MATCH_ERROR)
4011 gfc_syntax_error (ST_NAMELIST);
4018 /* Match a MODULE statement. */
4021 gfc_match_module (void)
4025 m = gfc_match (" %s%t", &gfc_new_block);
4029 if (gfc_add_flavor (&gfc_new_block->attr, FL_MODULE,
4030 gfc_new_block->name, NULL) == FAILURE)
4037 /* Free equivalence sets and lists. Recursively is the easiest way to
4041 gfc_free_equiv_until (gfc_equiv *eq, gfc_equiv *stop)
4046 gfc_free_equiv (eq->eq);
4047 gfc_free_equiv_until (eq->next, stop);
4048 gfc_free_expr (eq->expr);
4054 gfc_free_equiv (gfc_equiv *eq)
4056 gfc_free_equiv_until (eq, NULL);
4060 /* Match an EQUIVALENCE statement. */
4063 gfc_match_equivalence (void)
4065 gfc_equiv *eq, *set, *tail;
4069 gfc_common_head *common_head = NULL;
4077 eq = gfc_get_equiv ();
4081 eq->next = gfc_current_ns->equiv;
4082 gfc_current_ns->equiv = eq;
4084 if (gfc_match_char ('(') != MATCH_YES)
4088 common_flag = FALSE;
4093 m = gfc_match_equiv_variable (&set->expr);
4094 if (m == MATCH_ERROR)
4099 /* count the number of objects. */
4102 if (gfc_match_char ('%') == MATCH_YES)
4104 gfc_error ("Derived type component %C is not a "
4105 "permitted EQUIVALENCE member");
4109 for (ref = set->expr->ref; ref; ref = ref->next)
4110 if (ref->type == REF_ARRAY && ref->u.ar.type == AR_SECTION)
4112 gfc_error ("Array reference in EQUIVALENCE at %C cannot "
4113 "be an array section");
4117 sym = set->expr->symtree->n.sym;
4119 if (gfc_add_in_equivalence (&sym->attr, sym->name, NULL) == FAILURE)
4122 if (sym->attr.in_common)
4125 common_head = sym->common_head;
4128 if (gfc_match_char (')') == MATCH_YES)
4131 if (gfc_match_char (',') != MATCH_YES)
4134 set->eq = gfc_get_equiv ();
4140 gfc_error ("EQUIVALENCE at %C requires two or more objects");
4144 /* If one of the members of an equivalence is in common, then
4145 mark them all as being in common. Before doing this, check
4146 that members of the equivalence group are not in different
4149 for (set = eq; set; set = set->eq)
4151 sym = set->expr->symtree->n.sym;
4152 if (sym->common_head && sym->common_head != common_head)
4154 gfc_error ("Attempt to indirectly overlap COMMON "
4155 "blocks %s and %s by EQUIVALENCE at %C",
4156 sym->common_head->name, common_head->name);
4159 sym->attr.in_common = 1;
4160 sym->common_head = common_head;
4163 if (gfc_match_eos () == MATCH_YES)
4165 if (gfc_match_char (',') != MATCH_YES)
4167 gfc_error ("Expecting a comma in EQUIVALENCE at %C");
4175 gfc_syntax_error (ST_EQUIVALENCE);
4181 gfc_free_equiv (gfc_current_ns->equiv);
4182 gfc_current_ns->equiv = eq;
4188 /* Check that a statement function is not recursive. This is done by looking
4189 for the statement function symbol(sym) by looking recursively through its
4190 expression(e). If a reference to sym is found, true is returned.
4191 12.5.4 requires that any variable of function that is implicitly typed
4192 shall have that type confirmed by any subsequent type declaration. The
4193 implicit typing is conveniently done here. */
4195 recursive_stmt_fcn (gfc_expr *, gfc_symbol *);
4198 check_stmt_fcn (gfc_expr *e, gfc_symbol *sym, int *f ATTRIBUTE_UNUSED)
4204 switch (e->expr_type)
4207 if (e->symtree == NULL)
4210 /* Check the name before testing for nested recursion! */
4211 if (sym->name == e->symtree->n.sym->name)
4214 /* Catch recursion via other statement functions. */
4215 if (e->symtree->n.sym->attr.proc == PROC_ST_FUNCTION
4216 && e->symtree->n.sym->value
4217 && recursive_stmt_fcn (e->symtree->n.sym->value, sym))
4220 if (e->symtree->n.sym->ts.type == BT_UNKNOWN)
4221 gfc_set_default_type (e->symtree->n.sym, 0, NULL);
4226 if (e->symtree && sym->name == e->symtree->n.sym->name)
4229 if (e->symtree->n.sym->ts.type == BT_UNKNOWN)
4230 gfc_set_default_type (e->symtree->n.sym, 0, NULL);
4242 recursive_stmt_fcn (gfc_expr *e, gfc_symbol *sym)
4244 return gfc_traverse_expr (e, sym, check_stmt_fcn, 0);
4248 /* Match a statement function declaration. It is so easy to match
4249 non-statement function statements with a MATCH_ERROR as opposed to
4250 MATCH_NO that we suppress error message in most cases. */
4253 gfc_match_st_function (void)
4255 gfc_error_buf old_error;
4260 m = gfc_match_symbol (&sym, 0);
4264 gfc_push_error (&old_error);
4266 if (gfc_add_procedure (&sym->attr, PROC_ST_FUNCTION,
4267 sym->name, NULL) == FAILURE)
4270 if (gfc_match_formal_arglist (sym, 1, 0) != MATCH_YES)
4273 m = gfc_match (" = %e%t", &expr);
4277 gfc_free_error (&old_error);
4278 if (m == MATCH_ERROR)
4281 if (recursive_stmt_fcn (expr, sym))
4283 gfc_error ("Statement function at %L is recursive", &expr->where);
4289 if (gfc_notify_std (GFC_STD_F95_OBS, "Obsolescent feature: "
4290 "Statement function at %C") == FAILURE)
4296 gfc_pop_error (&old_error);
4301 /***************** SELECT CASE subroutines ******************/
4303 /* Free a single case structure. */
4306 free_case (gfc_case *p)
4308 if (p->low == p->high)
4310 gfc_free_expr (p->low);
4311 gfc_free_expr (p->high);
4316 /* Free a list of case structures. */
4319 gfc_free_case_list (gfc_case *p)
4331 /* Match a single case selector. */
4334 match_case_selector (gfc_case **cp)
4339 c = gfc_get_case ();
4340 c->where = gfc_current_locus;
4342 if (gfc_match_char (':') == MATCH_YES)
4344 m = gfc_match_init_expr (&c->high);
4347 if (m == MATCH_ERROR)
4352 m = gfc_match_init_expr (&c->low);
4353 if (m == MATCH_ERROR)
4358 /* If we're not looking at a ':' now, make a range out of a single
4359 target. Else get the upper bound for the case range. */
4360 if (gfc_match_char (':') != MATCH_YES)
4364 m = gfc_match_init_expr (&c->high);
4365 if (m == MATCH_ERROR)
4367 /* MATCH_NO is fine. It's OK if nothing is there! */
4375 gfc_error ("Expected initialization expression in CASE at %C");
4383 /* Match the end of a case statement. */
4386 match_case_eos (void)
4388 char name[GFC_MAX_SYMBOL_LEN + 1];
4391 if (gfc_match_eos () == MATCH_YES)
4394 /* If the case construct doesn't have a case-construct-name, we
4395 should have matched the EOS. */
4396 if (!gfc_current_block ())
4399 gfc_gobble_whitespace ();
4401 m = gfc_match_name (name);
4405 if (strcmp (name, gfc_current_block ()->name) != 0)
4407 gfc_error ("Expected block name '%s' of SELECT construct at %C",
4408 gfc_current_block ()->name);
4412 return gfc_match_eos ();
4416 /* Match a SELECT statement. */
4419 gfc_match_select (void)
4424 m = gfc_match_label ();
4425 if (m == MATCH_ERROR)
4428 m = gfc_match (" select case ( %e )%t", &expr);
4432 new_st.op = EXEC_SELECT;
4433 new_st.expr1 = expr;
4439 /* Push the current selector onto the SELECT TYPE stack. */
4442 select_type_push (gfc_symbol *sel)
4444 gfc_select_type_stack *top = gfc_get_select_type_stack ();
4445 top->selector = sel;
4447 top->prev = select_type_stack;
4449 select_type_stack = top;
4453 /* Set the temporary for the current SELECT TYPE selector. */
4456 select_type_set_tmp (gfc_typespec *ts)
4458 char name[GFC_MAX_SYMBOL_LEN];
4461 if (!gfc_type_is_extensible (ts->u.derived))
4464 if (ts->type == BT_CLASS)
4465 sprintf (name, "tmp$class$%s", ts->u.derived->name);
4467 sprintf (name, "tmp$type$%s", ts->u.derived->name);
4468 gfc_get_sym_tree (name, gfc_current_ns, &tmp, false);
4469 gfc_add_type (tmp->n.sym, ts, NULL);
4470 gfc_set_sym_referenced (tmp->n.sym);
4471 gfc_add_pointer (&tmp->n.sym->attr, NULL);
4472 gfc_add_flavor (&tmp->n.sym->attr, FL_VARIABLE, name, NULL);
4473 if (ts->type == BT_CLASS)
4475 gfc_build_class_symbol (&tmp->n.sym->ts, &tmp->n.sym->attr,
4476 &tmp->n.sym->as, false);
4477 tmp->n.sym->attr.class_ok = 1;
4480 select_type_stack->tmp = tmp;
4484 /* Match a SELECT TYPE statement. */
4487 gfc_match_select_type (void)
4489 gfc_expr *expr1, *expr2 = NULL;
4491 char name[GFC_MAX_SYMBOL_LEN];
4493 m = gfc_match_label ();
4494 if (m == MATCH_ERROR)
4497 m = gfc_match (" select type ( ");
4501 gfc_current_ns = gfc_build_block_ns (gfc_current_ns);
4503 m = gfc_match (" %n => %e", name, &expr2);
4506 expr1 = gfc_get_expr();
4507 expr1->expr_type = EXPR_VARIABLE;
4508 if (gfc_get_sym_tree (name, NULL, &expr1->symtree, false))
4513 if (expr2->ts.type == BT_UNKNOWN)
4514 expr1->symtree->n.sym->attr.untyped = 1;
4516 expr1->symtree->n.sym->ts = expr2->ts;
4517 expr1->symtree->n.sym->attr.referenced = 1;
4518 expr1->symtree->n.sym->attr.class_ok = 1;
4522 m = gfc_match (" %e ", &expr1);
4527 m = gfc_match (" )%t");
4531 /* Check for F03:C811. */
4532 if (!expr2 && (expr1->expr_type != EXPR_VARIABLE || expr1->ref != NULL))
4534 gfc_error ("Selector in SELECT TYPE at %C is not a named variable; "
4535 "use associate-name=>");
4540 new_st.op = EXEC_SELECT_TYPE;
4541 new_st.expr1 = expr1;
4542 new_st.expr2 = expr2;
4543 new_st.ext.block.ns = gfc_current_ns;
4545 select_type_push (expr1->symtree->n.sym);
4550 gfc_current_ns = gfc_current_ns->parent;
4555 /* Match a CASE statement. */
4558 gfc_match_case (void)
4560 gfc_case *c, *head, *tail;
4565 if (gfc_current_state () != COMP_SELECT)
4567 gfc_error ("Unexpected CASE statement at %C");
4571 if (gfc_match ("% default") == MATCH_YES)
4573 m = match_case_eos ();
4576 if (m == MATCH_ERROR)
4579 new_st.op = EXEC_SELECT;
4580 c = gfc_get_case ();
4581 c->where = gfc_current_locus;
4582 new_st.ext.case_list = c;
4586 if (gfc_match_char ('(') != MATCH_YES)
4591 if (match_case_selector (&c) == MATCH_ERROR)
4601 if (gfc_match_char (')') == MATCH_YES)
4603 if (gfc_match_char (',') != MATCH_YES)
4607 m = match_case_eos ();
4610 if (m == MATCH_ERROR)
4613 new_st.op = EXEC_SELECT;
4614 new_st.ext.case_list = head;
4619 gfc_error ("Syntax error in CASE specification at %C");
4622 gfc_free_case_list (head); /* new_st is cleaned up in parse.c. */
4627 /* Match a TYPE IS statement. */
4630 gfc_match_type_is (void)
4635 if (gfc_current_state () != COMP_SELECT_TYPE)
4637 gfc_error ("Unexpected TYPE IS statement at %C");
4641 if (gfc_match_char ('(') != MATCH_YES)
4644 c = gfc_get_case ();
4645 c->where = gfc_current_locus;
4647 /* TODO: Once unlimited polymorphism is implemented, we will need to call
4648 match_type_spec here. */
4649 if (match_derived_type_spec (&c->ts) == MATCH_ERROR)
4652 if (gfc_match_char (')') != MATCH_YES)
4655 m = match_case_eos ();
4658 if (m == MATCH_ERROR)
4661 new_st.op = EXEC_SELECT_TYPE;
4662 new_st.ext.case_list = c;
4664 /* Create temporary variable. */
4665 select_type_set_tmp (&c->ts);
4670 gfc_error ("Syntax error in TYPE IS specification at %C");
4674 gfc_free_case_list (c); /* new_st is cleaned up in parse.c. */
4679 /* Match a CLASS IS or CLASS DEFAULT statement. */
4682 gfc_match_class_is (void)
4687 if (gfc_current_state () != COMP_SELECT_TYPE)
4690 if (gfc_match ("% default") == MATCH_YES)
4692 m = match_case_eos ();
4695 if (m == MATCH_ERROR)
4698 new_st.op = EXEC_SELECT_TYPE;
4699 c = gfc_get_case ();
4700 c->where = gfc_current_locus;
4701 c->ts.type = BT_UNKNOWN;
4702 new_st.ext.case_list = c;
4706 m = gfc_match ("% is");
4709 if (m == MATCH_ERROR)
4712 if (gfc_match_char ('(') != MATCH_YES)
4715 c = gfc_get_case ();
4716 c->where = gfc_current_locus;
4718 if (match_derived_type_spec (&c->ts) == MATCH_ERROR)
4721 if (c->ts.type == BT_DERIVED)
4722 c->ts.type = BT_CLASS;
4724 if (gfc_match_char (')') != MATCH_YES)
4727 m = match_case_eos ();
4730 if (m == MATCH_ERROR)
4733 new_st.op = EXEC_SELECT_TYPE;
4734 new_st.ext.case_list = c;
4736 /* Create temporary variable. */
4737 select_type_set_tmp (&c->ts);
4742 gfc_error ("Syntax error in CLASS IS specification at %C");
4746 gfc_free_case_list (c); /* new_st is cleaned up in parse.c. */
4751 /********************* WHERE subroutines ********************/
4753 /* Match the rest of a simple WHERE statement that follows an IF statement.
4757 match_simple_where (void)
4763 m = gfc_match (" ( %e )", &expr);
4767 m = gfc_match_assignment ();
4770 if (m == MATCH_ERROR)
4773 if (gfc_match_eos () != MATCH_YES)
4776 c = gfc_get_code ();
4780 c->next = gfc_get_code ();
4783 gfc_clear_new_st ();
4785 new_st.op = EXEC_WHERE;
4791 gfc_syntax_error (ST_WHERE);
4794 gfc_free_expr (expr);
4799 /* Match a WHERE statement. */
4802 gfc_match_where (gfc_statement *st)
4808 m0 = gfc_match_label ();
4809 if (m0 == MATCH_ERROR)
4812 m = gfc_match (" where ( %e )", &expr);
4816 if (gfc_match_eos () == MATCH_YES)
4818 *st = ST_WHERE_BLOCK;
4819 new_st.op = EXEC_WHERE;
4820 new_st.expr1 = expr;
4824 m = gfc_match_assignment ();
4826 gfc_syntax_error (ST_WHERE);
4830 gfc_free_expr (expr);
4834 /* We've got a simple WHERE statement. */
4836 c = gfc_get_code ();
4840 c->next = gfc_get_code ();
4843 gfc_clear_new_st ();
4845 new_st.op = EXEC_WHERE;
4852 /* Match an ELSEWHERE statement. We leave behind a WHERE node in
4853 new_st if successful. */
4856 gfc_match_elsewhere (void)
4858 char name[GFC_MAX_SYMBOL_LEN + 1];
4862 if (gfc_current_state () != COMP_WHERE)
4864 gfc_error ("ELSEWHERE statement at %C not enclosed in WHERE block");
4870 if (gfc_match_char ('(') == MATCH_YES)
4872 m = gfc_match_expr (&expr);
4875 if (m == MATCH_ERROR)
4878 if (gfc_match_char (')') != MATCH_YES)
4882 if (gfc_match_eos () != MATCH_YES)
4884 /* Only makes sense if we have a where-construct-name. */
4885 if (!gfc_current_block ())
4890 /* Better be a name at this point. */
4891 m = gfc_match_name (name);
4894 if (m == MATCH_ERROR)
4897 if (gfc_match_eos () != MATCH_YES)
4900 if (strcmp (name, gfc_current_block ()->name) != 0)
4902 gfc_error ("Label '%s' at %C doesn't match WHERE label '%s'",
4903 name, gfc_current_block ()->name);
4908 new_st.op = EXEC_WHERE;
4909 new_st.expr1 = expr;
4913 gfc_syntax_error (ST_ELSEWHERE);
4916 gfc_free_expr (expr);
4921 /******************** FORALL subroutines ********************/
4923 /* Free a list of FORALL iterators. */
4926 gfc_free_forall_iterator (gfc_forall_iterator *iter)
4928 gfc_forall_iterator *next;
4933 gfc_free_expr (iter->var);
4934 gfc_free_expr (iter->start);
4935 gfc_free_expr (iter->end);
4936 gfc_free_expr (iter->stride);
4943 /* Match an iterator as part of a FORALL statement. The format is:
4945 <var> = <start>:<end>[:<stride>]
4947 On MATCH_NO, the caller tests for the possibility that there is a
4948 scalar mask expression. */
4951 match_forall_iterator (gfc_forall_iterator **result)
4953 gfc_forall_iterator *iter;
4957 where = gfc_current_locus;
4958 iter = XCNEW (gfc_forall_iterator);
4960 m = gfc_match_expr (&iter->var);
4964 if (gfc_match_char ('=') != MATCH_YES
4965 || iter->var->expr_type != EXPR_VARIABLE)
4971 m = gfc_match_expr (&iter->start);
4975 if (gfc_match_char (':') != MATCH_YES)
4978 m = gfc_match_expr (&iter->end);
4981 if (m == MATCH_ERROR)
4984 if (gfc_match_char (':') == MATCH_NO)
4985 iter->stride = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
4988 m = gfc_match_expr (&iter->stride);
4991 if (m == MATCH_ERROR)
4995 /* Mark the iteration variable's symbol as used as a FORALL index. */
4996 iter->var->symtree->n.sym->forall_index = true;
5002 gfc_error ("Syntax error in FORALL iterator at %C");
5007 gfc_current_locus = where;
5008 gfc_free_forall_iterator (iter);
5013 /* Match the header of a FORALL statement. */
5016 match_forall_header (gfc_forall_iterator **phead, gfc_expr **mask)
5018 gfc_forall_iterator *head, *tail, *new_iter;
5022 gfc_gobble_whitespace ();
5027 if (gfc_match_char ('(') != MATCH_YES)
5030 m = match_forall_iterator (&new_iter);
5031 if (m == MATCH_ERROR)
5036 head = tail = new_iter;
5040 if (gfc_match_char (',') != MATCH_YES)
5043 m = match_forall_iterator (&new_iter);
5044 if (m == MATCH_ERROR)
5049 tail->next = new_iter;
5054 /* Have to have a mask expression. */
5056 m = gfc_match_expr (&msk);
5059 if (m == MATCH_ERROR)
5065 if (gfc_match_char (')') == MATCH_NO)
5073 gfc_syntax_error (ST_FORALL);
5076 gfc_free_expr (msk);
5077 gfc_free_forall_iterator (head);
5082 /* Match the rest of a simple FORALL statement that follows an
5086 match_simple_forall (void)
5088 gfc_forall_iterator *head;
5097 m = match_forall_header (&head, &mask);
5104 m = gfc_match_assignment ();
5106 if (m == MATCH_ERROR)
5110 m = gfc_match_pointer_assignment ();
5111 if (m == MATCH_ERROR)
5117 c = gfc_get_code ();
5119 c->loc = gfc_current_locus;
5121 if (gfc_match_eos () != MATCH_YES)
5124 gfc_clear_new_st ();
5125 new_st.op = EXEC_FORALL;
5126 new_st.expr1 = mask;
5127 new_st.ext.forall_iterator = head;
5128 new_st.block = gfc_get_code ();
5130 new_st.block->op = EXEC_FORALL;
5131 new_st.block->next = c;
5136 gfc_syntax_error (ST_FORALL);
5139 gfc_free_forall_iterator (head);
5140 gfc_free_expr (mask);
5146 /* Match a FORALL statement. */
5149 gfc_match_forall (gfc_statement *st)
5151 gfc_forall_iterator *head;
5160 m0 = gfc_match_label ();
5161 if (m0 == MATCH_ERROR)
5164 m = gfc_match (" forall");
5168 m = match_forall_header (&head, &mask);
5169 if (m == MATCH_ERROR)
5174 if (gfc_match_eos () == MATCH_YES)
5176 *st = ST_FORALL_BLOCK;
5177 new_st.op = EXEC_FORALL;
5178 new_st.expr1 = mask;
5179 new_st.ext.forall_iterator = head;
5183 m = gfc_match_assignment ();
5184 if (m == MATCH_ERROR)
5188 m = gfc_match_pointer_assignment ();
5189 if (m == MATCH_ERROR)
5195 c = gfc_get_code ();
5197 c->loc = gfc_current_locus;
5199 gfc_clear_new_st ();
5200 new_st.op = EXEC_FORALL;
5201 new_st.expr1 = mask;
5202 new_st.ext.forall_iterator = head;
5203 new_st.block = gfc_get_code ();
5204 new_st.block->op = EXEC_FORALL;
5205 new_st.block->next = c;
5211 gfc_syntax_error (ST_FORALL);
5214 gfc_free_forall_iterator (head);
5215 gfc_free_expr (mask);
5216 gfc_free_statements (c);