1 /* Matching subroutines in all sizes, shapes and colors.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
30 /* For debugging and diagnostic purposes. Return the textual representation
31 of the intrinsic operator OP. */
33 gfc_op2string (gfc_intrinsic_op op
)
41 case INTRINSIC_UMINUS
:
47 case INTRINSIC_CONCAT
:
51 case INTRINSIC_DIVIDE
:
90 case INTRINSIC_ASSIGN
:
93 case INTRINSIC_PARENTHESES
:
100 gfc_internal_error ("gfc_op2string(): Bad code");
105 /******************** Generic matching subroutines ************************/
107 /* This function scans the current statement counting the opened and closed
108 parenthesis to make sure they are balanced. */
111 gfc_match_parens (void)
113 locus old_loc
, where
;
117 old_loc
= gfc_current_locus
;
124 c
= gfc_next_char_literal (instring
);
127 if (quote
== ' ' && ((c
== '\'') || (c
== '"')))
133 if (quote
!= ' ' && c
== quote
)
140 if (c
== '(' && quote
== ' ')
143 where
= gfc_current_locus
;
145 if (c
== ')' && quote
== ' ')
148 where
= gfc_current_locus
;
152 gfc_current_locus
= old_loc
;
156 gfc_error ("Missing ')' in statement at or before %L", &where
);
161 gfc_error ("Missing '(' in statement at or before %L", &where
);
169 /* See if the next character is a special character that has
170 escaped by a \ via the -fbackslash option. */
173 gfc_match_special_char (gfc_char_t
*res
)
181 switch ((c
= gfc_next_char_literal (1)))
214 /* Hexadecimal form of wide characters. */
215 len
= (c
== 'x' ? 2 : (c
== 'u' ? 4 : 8));
217 for (i
= 0; i
< len
; i
++)
219 char buf
[2] = { '\0', '\0' };
221 c
= gfc_next_char_literal (1);
222 if (!gfc_wide_fits_in_byte (c
)
223 || !gfc_check_digit ((unsigned char) c
, 16))
226 buf
[0] = (unsigned char) c
;
228 n
+= strtol (buf
, NULL
, 16);
234 /* Unknown backslash codes are simply not expanded. */
243 /* In free form, match at least one space. Always matches in fixed
247 gfc_match_space (void)
252 if (gfc_current_form
== FORM_FIXED
)
255 old_loc
= gfc_current_locus
;
257 c
= gfc_next_ascii_char ();
258 if (!gfc_is_whitespace (c
))
260 gfc_current_locus
= old_loc
;
264 gfc_gobble_whitespace ();
270 /* Match an end of statement. End of statement is optional
271 whitespace, followed by a ';' or '\n' or comment '!'. If a
272 semicolon is found, we continue to eat whitespace and semicolons. */
285 old_loc
= gfc_current_locus
;
286 gfc_gobble_whitespace ();
288 c
= gfc_next_ascii_char ();
294 c
= gfc_next_ascii_char ();
311 gfc_current_locus
= old_loc
;
312 return (flag
) ? MATCH_YES
: MATCH_NO
;
316 /* Match a literal integer on the input, setting the value on
317 MATCH_YES. Literal ints occur in kind-parameters as well as
318 old-style character length specifications. If cnt is non-NULL it
319 will be set to the number of digits. */
322 gfc_match_small_literal_int (int *value
, int *cnt
)
328 old_loc
= gfc_current_locus
;
331 gfc_gobble_whitespace ();
332 c
= gfc_next_ascii_char ();
338 gfc_current_locus
= old_loc
;
347 old_loc
= gfc_current_locus
;
348 c
= gfc_next_ascii_char ();
353 i
= 10 * i
+ c
- '0';
358 gfc_error ("Integer too large at %C");
363 gfc_current_locus
= old_loc
;
372 /* Match a small, constant integer expression, like in a kind
373 statement. On MATCH_YES, 'value' is set. */
376 gfc_match_small_int (int *value
)
383 m
= gfc_match_expr (&expr
);
387 p
= gfc_extract_int (expr
, &i
);
388 gfc_free_expr (expr
);
401 /* This function is the same as the gfc_match_small_int, except that
402 we're keeping the pointer to the expr. This function could just be
403 removed and the previously mentioned one modified, though all calls
404 to it would have to be modified then (and there were a number of
405 them). Return MATCH_ERROR if fail to extract the int; otherwise,
406 return the result of gfc_match_expr(). The expr (if any) that was
407 matched is returned in the parameter expr. */
410 gfc_match_small_int_expr (int *value
, gfc_expr
**expr
)
416 m
= gfc_match_expr (expr
);
420 p
= gfc_extract_int (*expr
, &i
);
433 /* Matches a statement label. Uses gfc_match_small_literal_int() to
434 do most of the work. */
437 gfc_match_st_label (gfc_st_label
**label
)
443 old_loc
= gfc_current_locus
;
445 m
= gfc_match_small_literal_int (&i
, &cnt
);
451 gfc_error ("Too many digits in statement label at %C");
457 gfc_error ("Statement label at %C is zero");
461 *label
= gfc_get_st_label (i
);
466 gfc_current_locus
= old_loc
;
471 /* Match and validate a label associated with a named IF, DO or SELECT
472 statement. If the symbol does not have the label attribute, we add
473 it. We also make sure the symbol does not refer to another
474 (active) block. A matched label is pointed to by gfc_new_block. */
477 gfc_match_label (void)
479 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
482 gfc_new_block
= NULL
;
484 m
= gfc_match (" %n :", name
);
488 if (gfc_get_symbol (name
, NULL
, &gfc_new_block
))
490 gfc_error ("Label name '%s' at %C is ambiguous", name
);
494 if (gfc_new_block
->attr
.flavor
== FL_LABEL
)
496 gfc_error ("Duplicate construct label '%s' at %C", name
);
500 if (gfc_add_flavor (&gfc_new_block
->attr
, FL_LABEL
,
501 gfc_new_block
->name
, NULL
) == FAILURE
)
508 /* See if the current input looks like a name of some sort. Modifies
509 the passed buffer which must be GFC_MAX_SYMBOL_LEN+1 bytes long.
510 Note that options.c restricts max_identifier_length to not more
511 than GFC_MAX_SYMBOL_LEN. */
514 gfc_match_name (char *buffer
)
520 old_loc
= gfc_current_locus
;
521 gfc_gobble_whitespace ();
523 c
= gfc_next_ascii_char ();
524 if (!(ISALPHA (c
) || (c
== '_' && gfc_option
.flag_allow_leading_underscore
)))
526 if (gfc_error_flag_test() == 0 && c
!= '(')
527 gfc_error ("Invalid character in name at %C");
528 gfc_current_locus
= old_loc
;
538 if (i
> gfc_option
.max_identifier_length
)
540 gfc_error ("Name at %C is too long");
544 old_loc
= gfc_current_locus
;
545 c
= gfc_next_ascii_char ();
547 while (ISALNUM (c
) || c
== '_' || (gfc_option
.flag_dollar_ok
&& c
== '$'));
549 if (c
== '$' && !gfc_option
.flag_dollar_ok
)
551 gfc_error ("Invalid character '$' at %C. Use -fdollar-ok to allow it "
557 gfc_current_locus
= old_loc
;
563 /* Match a valid name for C, which is almost the same as for Fortran,
564 except that you can start with an underscore, etc.. It could have
565 been done by modifying the gfc_match_name, but this way other
566 things C allows can be added, such as no limits on the length.
567 Right now, the length is limited to the same thing as Fortran..
568 Also, by rewriting it, we use the gfc_next_char_C() to prevent the
569 input characters from being automatically lower cased, since C is
570 case sensitive. The parameter, buffer, is used to return the name
571 that is matched. Return MATCH_ERROR if the name is too long
572 (though this is a self-imposed limit), MATCH_NO if what we're
573 seeing isn't a name, and MATCH_YES if we successfully match a C
577 gfc_match_name_C (char *buffer
)
583 old_loc
= gfc_current_locus
;
584 gfc_gobble_whitespace ();
586 /* Get the next char (first possible char of name) and see if
587 it's valid for C (either a letter or an underscore). */
588 c
= gfc_next_char_literal (1);
590 /* If the user put nothing expect spaces between the quotes, it is valid
591 and simply means there is no name= specifier and the name is the fortran
592 symbol name, all lowercase. */
593 if (c
== '"' || c
== '\'')
596 gfc_current_locus
= old_loc
;
600 if (!ISALPHA (c
) && c
!= '_')
602 gfc_error ("Invalid C name in NAME= specifier at %C");
606 /* Continue to read valid variable name characters. */
609 gcc_assert (gfc_wide_fits_in_byte (c
));
611 buffer
[i
++] = (unsigned char) c
;
613 /* C does not define a maximum length of variable names, to my
614 knowledge, but the compiler typically places a limit on them.
615 For now, i'll use the same as the fortran limit for simplicity,
616 but this may need to be changed to a dynamic buffer that can
617 be realloc'ed here if necessary, or more likely, a larger
619 if (i
> gfc_option
.max_identifier_length
)
621 gfc_error ("Name at %C is too long");
625 old_loc
= gfc_current_locus
;
627 /* Get next char; param means we're in a string. */
628 c
= gfc_next_char_literal (1);
629 } while (ISALNUM (c
) || c
== '_');
632 gfc_current_locus
= old_loc
;
634 /* See if we stopped because of whitespace. */
637 gfc_gobble_whitespace ();
638 c
= gfc_peek_ascii_char ();
639 if (c
!= '"' && c
!= '\'')
641 gfc_error ("Embedded space in NAME= specifier at %C");
646 /* If we stopped because we had an invalid character for a C name, report
647 that to the user by returning MATCH_NO. */
648 if (c
!= '"' && c
!= '\'')
650 gfc_error ("Invalid C name in NAME= specifier at %C");
658 /* Match a symbol on the input. Modifies the pointer to the symbol
659 pointer if successful. */
662 gfc_match_sym_tree (gfc_symtree
**matched_symbol
, int host_assoc
)
664 char buffer
[GFC_MAX_SYMBOL_LEN
+ 1];
667 m
= gfc_match_name (buffer
);
672 return (gfc_get_ha_sym_tree (buffer
, matched_symbol
))
673 ? MATCH_ERROR
: MATCH_YES
;
675 if (gfc_get_sym_tree (buffer
, NULL
, matched_symbol
))
683 gfc_match_symbol (gfc_symbol
**matched_symbol
, int host_assoc
)
688 m
= gfc_match_sym_tree (&st
, host_assoc
);
693 *matched_symbol
= st
->n
.sym
;
695 *matched_symbol
= NULL
;
698 *matched_symbol
= NULL
;
703 /* Match an intrinsic operator. Returns an INTRINSIC enum. While matching,
704 we always find INTRINSIC_PLUS before INTRINSIC_UPLUS. We work around this
708 gfc_match_intrinsic_op (gfc_intrinsic_op
*result
)
710 locus orig_loc
= gfc_current_locus
;
713 gfc_gobble_whitespace ();
714 ch
= gfc_next_ascii_char ();
719 *result
= INTRINSIC_PLUS
;
724 *result
= INTRINSIC_MINUS
;
728 if (gfc_next_ascii_char () == '=')
731 *result
= INTRINSIC_EQ
;
737 if (gfc_peek_ascii_char () == '=')
740 gfc_next_ascii_char ();
741 *result
= INTRINSIC_LE
;
745 *result
= INTRINSIC_LT
;
749 if (gfc_peek_ascii_char () == '=')
752 gfc_next_ascii_char ();
753 *result
= INTRINSIC_GE
;
757 *result
= INTRINSIC_GT
;
761 if (gfc_peek_ascii_char () == '*')
764 gfc_next_ascii_char ();
765 *result
= INTRINSIC_POWER
;
769 *result
= INTRINSIC_TIMES
;
773 ch
= gfc_peek_ascii_char ();
777 gfc_next_ascii_char ();
778 *result
= INTRINSIC_NE
;
784 gfc_next_ascii_char ();
785 *result
= INTRINSIC_CONCAT
;
789 *result
= INTRINSIC_DIVIDE
;
793 ch
= gfc_next_ascii_char ();
797 if (gfc_next_ascii_char () == 'n'
798 && gfc_next_ascii_char () == 'd'
799 && gfc_next_ascii_char () == '.')
801 /* Matched ".and.". */
802 *result
= INTRINSIC_AND
;
808 if (gfc_next_ascii_char () == 'q')
810 ch
= gfc_next_ascii_char ();
813 /* Matched ".eq.". */
814 *result
= INTRINSIC_EQ_OS
;
819 if (gfc_next_ascii_char () == '.')
821 /* Matched ".eqv.". */
822 *result
= INTRINSIC_EQV
;
830 ch
= gfc_next_ascii_char ();
833 if (gfc_next_ascii_char () == '.')
835 /* Matched ".ge.". */
836 *result
= INTRINSIC_GE_OS
;
842 if (gfc_next_ascii_char () == '.')
844 /* Matched ".gt.". */
845 *result
= INTRINSIC_GT_OS
;
852 ch
= gfc_next_ascii_char ();
855 if (gfc_next_ascii_char () == '.')
857 /* Matched ".le.". */
858 *result
= INTRINSIC_LE_OS
;
864 if (gfc_next_ascii_char () == '.')
866 /* Matched ".lt.". */
867 *result
= INTRINSIC_LT_OS
;
874 ch
= gfc_next_ascii_char ();
877 ch
= gfc_next_ascii_char ();
880 /* Matched ".ne.". */
881 *result
= INTRINSIC_NE_OS
;
886 if (gfc_next_ascii_char () == 'v'
887 && gfc_next_ascii_char () == '.')
889 /* Matched ".neqv.". */
890 *result
= INTRINSIC_NEQV
;
897 if (gfc_next_ascii_char () == 't'
898 && gfc_next_ascii_char () == '.')
900 /* Matched ".not.". */
901 *result
= INTRINSIC_NOT
;
908 if (gfc_next_ascii_char () == 'r'
909 && gfc_next_ascii_char () == '.')
911 /* Matched ".or.". */
912 *result
= INTRINSIC_OR
;
926 gfc_current_locus
= orig_loc
;
931 /* Match a loop control phrase:
933 <LVALUE> = <EXPR>, <EXPR> [, <EXPR> ]
935 If the final integer expression is not present, a constant unity
936 expression is returned. We don't return MATCH_ERROR until after
937 the equals sign is seen. */
940 gfc_match_iterator (gfc_iterator
*iter
, int init_flag
)
942 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
943 gfc_expr
*var
, *e1
, *e2
, *e3
;
947 /* Match the start of an iterator without affecting the symbol table. */
949 start
= gfc_current_locus
;
950 m
= gfc_match (" %n =", name
);
951 gfc_current_locus
= start
;
956 m
= gfc_match_variable (&var
, 0);
960 gfc_match_char ('=');
964 if (var
->ref
!= NULL
)
966 gfc_error ("Loop variable at %C cannot be a sub-component");
970 if (var
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
972 gfc_error ("Loop variable '%s' at %C cannot be INTENT(IN)",
973 var
->symtree
->n
.sym
->name
);
977 var
->symtree
->n
.sym
->attr
.implied_index
= 1;
979 m
= init_flag
? gfc_match_init_expr (&e1
) : gfc_match_expr (&e1
);
982 if (m
== MATCH_ERROR
)
985 if (gfc_match_char (',') != MATCH_YES
)
988 m
= init_flag
? gfc_match_init_expr (&e2
) : gfc_match_expr (&e2
);
991 if (m
== MATCH_ERROR
)
994 if (gfc_match_char (',') != MATCH_YES
)
996 e3
= gfc_int_expr (1);
1000 m
= init_flag
? gfc_match_init_expr (&e3
) : gfc_match_expr (&e3
);
1001 if (m
== MATCH_ERROR
)
1005 gfc_error ("Expected a step value in iterator at %C");
1017 gfc_error ("Syntax error in iterator at %C");
1028 /* Tries to match the next non-whitespace character on the input.
1029 This subroutine does not return MATCH_ERROR. */
1032 gfc_match_char (char c
)
1036 where
= gfc_current_locus
;
1037 gfc_gobble_whitespace ();
1039 if (gfc_next_ascii_char () == c
)
1042 gfc_current_locus
= where
;
1047 /* General purpose matching subroutine. The target string is a
1048 scanf-like format string in which spaces correspond to arbitrary
1049 whitespace (including no whitespace), characters correspond to
1050 themselves. The %-codes are:
1052 %% Literal percent sign
1053 %e Expression, pointer to a pointer is set
1054 %s Symbol, pointer to the symbol is set
1055 %n Name, character buffer is set to name
1056 %t Matches end of statement.
1057 %o Matches an intrinsic operator, returned as an INTRINSIC enum.
1058 %l Matches a statement label
1059 %v Matches a variable expression (an lvalue)
1060 % Matches a required space (in free form) and optional spaces. */
1063 gfc_match (const char *target
, ...)
1065 gfc_st_label
**label
;
1074 old_loc
= gfc_current_locus
;
1075 va_start (argp
, target
);
1085 gfc_gobble_whitespace ();
1096 vp
= va_arg (argp
, void **);
1097 n
= gfc_match_expr ((gfc_expr
**) vp
);
1108 vp
= va_arg (argp
, void **);
1109 n
= gfc_match_variable ((gfc_expr
**) vp
, 0);
1120 vp
= va_arg (argp
, void **);
1121 n
= gfc_match_symbol ((gfc_symbol
**) vp
, 0);
1132 np
= va_arg (argp
, char *);
1133 n
= gfc_match_name (np
);
1144 label
= va_arg (argp
, gfc_st_label
**);
1145 n
= gfc_match_st_label (label
);
1156 ip
= va_arg (argp
, int *);
1157 n
= gfc_match_intrinsic_op ((gfc_intrinsic_op
*) ip
);
1168 if (gfc_match_eos () != MATCH_YES
)
1176 if (gfc_match_space () == MATCH_YES
)
1182 break; /* Fall through to character matcher. */
1185 gfc_internal_error ("gfc_match(): Bad match code %c", c
);
1189 if (c
== gfc_next_ascii_char ())
1199 /* Clean up after a failed match. */
1200 gfc_current_locus
= old_loc
;
1201 va_start (argp
, target
);
1204 for (; matches
> 0; matches
--)
1206 while (*p
++ != '%');
1214 /* Matches that don't have to be undone */
1219 (void) va_arg (argp
, void **);
1224 vp
= va_arg (argp
, void **);
1225 gfc_free_expr (*vp
);
1238 /*********************** Statement level matching **********************/
1240 /* Matches the start of a program unit, which is the program keyword
1241 followed by an obligatory symbol. */
1244 gfc_match_program (void)
1249 m
= gfc_match ("% %s%t", &sym
);
1253 gfc_error ("Invalid form of PROGRAM statement at %C");
1257 if (m
== MATCH_ERROR
)
1260 if (gfc_add_flavor (&sym
->attr
, FL_PROGRAM
, sym
->name
, NULL
) == FAILURE
)
1263 gfc_new_block
= sym
;
1269 /* Match a simple assignment statement. */
1272 gfc_match_assignment (void)
1274 gfc_expr
*lvalue
, *rvalue
;
1278 old_loc
= gfc_current_locus
;
1281 m
= gfc_match (" %v =", &lvalue
);
1284 gfc_current_locus
= old_loc
;
1285 gfc_free_expr (lvalue
);
1289 if (lvalue
->symtree
->n
.sym
->attr
.protected
1290 && lvalue
->symtree
->n
.sym
->attr
.use_assoc
)
1292 gfc_current_locus
= old_loc
;
1293 gfc_free_expr (lvalue
);
1294 gfc_error ("Setting value of PROTECTED variable at %C");
1299 m
= gfc_match (" %e%t", &rvalue
);
1302 gfc_current_locus
= old_loc
;
1303 gfc_free_expr (lvalue
);
1304 gfc_free_expr (rvalue
);
1308 gfc_set_sym_referenced (lvalue
->symtree
->n
.sym
);
1310 new_st
.op
= EXEC_ASSIGN
;
1311 new_st
.expr
= lvalue
;
1312 new_st
.expr2
= rvalue
;
1314 gfc_check_do_variable (lvalue
->symtree
);
1320 /* Match a pointer assignment statement. */
1323 gfc_match_pointer_assignment (void)
1325 gfc_expr
*lvalue
, *rvalue
;
1329 old_loc
= gfc_current_locus
;
1331 lvalue
= rvalue
= NULL
;
1333 m
= gfc_match (" %v =>", &lvalue
);
1340 m
= gfc_match (" %e%t", &rvalue
);
1344 if (lvalue
->symtree
->n
.sym
->attr
.protected
1345 && lvalue
->symtree
->n
.sym
->attr
.use_assoc
)
1347 gfc_error ("Assigning to a PROTECTED pointer at %C");
1352 new_st
.op
= EXEC_POINTER_ASSIGN
;
1353 new_st
.expr
= lvalue
;
1354 new_st
.expr2
= rvalue
;
1359 gfc_current_locus
= old_loc
;
1360 gfc_free_expr (lvalue
);
1361 gfc_free_expr (rvalue
);
1366 /* We try to match an easy arithmetic IF statement. This only happens
1367 when just after having encountered a simple IF statement. This code
1368 is really duplicate with parts of the gfc_match_if code, but this is
1372 match_arithmetic_if (void)
1374 gfc_st_label
*l1
, *l2
, *l3
;
1378 m
= gfc_match (" ( %e ) %l , %l , %l%t", &expr
, &l1
, &l2
, &l3
);
1382 if (gfc_reference_st_label (l1
, ST_LABEL_TARGET
) == FAILURE
1383 || gfc_reference_st_label (l2
, ST_LABEL_TARGET
) == FAILURE
1384 || gfc_reference_st_label (l3
, ST_LABEL_TARGET
) == FAILURE
)
1386 gfc_free_expr (expr
);
1390 if (gfc_notify_std (GFC_STD_F95_OBS
, "Obsolescent: arithmetic IF statement "
1391 "at %C") == FAILURE
)
1394 new_st
.op
= EXEC_ARITHMETIC_IF
;
1404 /* The IF statement is a bit of a pain. First of all, there are three
1405 forms of it, the simple IF, the IF that starts a block and the
1408 There is a problem with the simple IF and that is the fact that we
1409 only have a single level of undo information on symbols. What this
1410 means is for a simple IF, we must re-match the whole IF statement
1411 multiple times in order to guarantee that the symbol table ends up
1412 in the proper state. */
1414 static match
match_simple_forall (void);
1415 static match
match_simple_where (void);
1418 gfc_match_if (gfc_statement
*if_type
)
1421 gfc_st_label
*l1
, *l2
, *l3
;
1422 locus old_loc
, old_loc2
;
1426 n
= gfc_match_label ();
1427 if (n
== MATCH_ERROR
)
1430 old_loc
= gfc_current_locus
;
1432 m
= gfc_match (" if ( %e", &expr
);
1436 old_loc2
= gfc_current_locus
;
1437 gfc_current_locus
= old_loc
;
1439 if (gfc_match_parens () == MATCH_ERROR
)
1442 gfc_current_locus
= old_loc2
;
1444 if (gfc_match_char (')') != MATCH_YES
)
1446 gfc_error ("Syntax error in IF-expression at %C");
1447 gfc_free_expr (expr
);
1451 m
= gfc_match (" %l , %l , %l%t", &l1
, &l2
, &l3
);
1457 gfc_error ("Block label not appropriate for arithmetic IF "
1459 gfc_free_expr (expr
);
1463 if (gfc_reference_st_label (l1
, ST_LABEL_TARGET
) == FAILURE
1464 || gfc_reference_st_label (l2
, ST_LABEL_TARGET
) == FAILURE
1465 || gfc_reference_st_label (l3
, ST_LABEL_TARGET
) == FAILURE
)
1467 gfc_free_expr (expr
);
1471 if (gfc_notify_std (GFC_STD_F95_OBS
, "Obsolescent: arithmetic IF "
1472 "statement at %C") == FAILURE
)
1475 new_st
.op
= EXEC_ARITHMETIC_IF
;
1481 *if_type
= ST_ARITHMETIC_IF
;
1485 if (gfc_match (" then%t") == MATCH_YES
)
1487 new_st
.op
= EXEC_IF
;
1489 *if_type
= ST_IF_BLOCK
;
1495 gfc_error ("Block label is not appropriate for IF statement at %C");
1496 gfc_free_expr (expr
);
1500 /* At this point the only thing left is a simple IF statement. At
1501 this point, n has to be MATCH_NO, so we don't have to worry about
1502 re-matching a block label. From what we've got so far, try
1503 matching an assignment. */
1505 *if_type
= ST_SIMPLE_IF
;
1507 m
= gfc_match_assignment ();
1511 gfc_free_expr (expr
);
1512 gfc_undo_symbols ();
1513 gfc_current_locus
= old_loc
;
1515 /* m can be MATCH_NO or MATCH_ERROR, here. For MATCH_ERROR, a mangled
1516 assignment was found. For MATCH_NO, continue to call the various
1518 if (m
== MATCH_ERROR
)
1521 gfc_match (" if ( %e ) ", &expr
); /* Guaranteed to match. */
1523 m
= gfc_match_pointer_assignment ();
1527 gfc_free_expr (expr
);
1528 gfc_undo_symbols ();
1529 gfc_current_locus
= old_loc
;
1531 gfc_match (" if ( %e ) ", &expr
); /* Guaranteed to match. */
1533 /* Look at the next keyword to see which matcher to call. Matching
1534 the keyword doesn't affect the symbol table, so we don't have to
1535 restore between tries. */
1537 #define match(string, subr, statement) \
1538 if (gfc_match(string) == MATCH_YES) { m = subr(); goto got_match; }
1542 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
)
1543 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
)
1544 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
)
1545 match ("call", gfc_match_call
, ST_CALL
)
1546 match ("close", gfc_match_close
, ST_CLOSE
)
1547 match ("continue", gfc_match_continue
, ST_CONTINUE
)
1548 match ("cycle", gfc_match_cycle
, ST_CYCLE
)
1549 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
)
1550 match ("end file", gfc_match_endfile
, ST_END_FILE
)
1551 match ("exit", gfc_match_exit
, ST_EXIT
)
1552 match ("flush", gfc_match_flush
, ST_FLUSH
)
1553 match ("forall", match_simple_forall
, ST_FORALL
)
1554 match ("go to", gfc_match_goto
, ST_GOTO
)
1555 match ("if", match_arithmetic_if
, ST_ARITHMETIC_IF
)
1556 match ("inquire", gfc_match_inquire
, ST_INQUIRE
)
1557 match ("nullify", gfc_match_nullify
, ST_NULLIFY
)
1558 match ("open", gfc_match_open
, ST_OPEN
)
1559 match ("pause", gfc_match_pause
, ST_NONE
)
1560 match ("print", gfc_match_print
, ST_WRITE
)
1561 match ("read", gfc_match_read
, ST_READ
)
1562 match ("return", gfc_match_return
, ST_RETURN
)
1563 match ("rewind", gfc_match_rewind
, ST_REWIND
)
1564 match ("stop", gfc_match_stop
, ST_STOP
)
1565 match ("wait", gfc_match_wait
, ST_WAIT
)
1566 match ("where", match_simple_where
, ST_WHERE
)
1567 match ("write", gfc_match_write
, ST_WRITE
)
1569 /* The gfc_match_assignment() above may have returned a MATCH_NO
1570 where the assignment was to a named constant. Check that
1571 special case here. */
1572 m
= gfc_match_assignment ();
1575 gfc_error ("Cannot assign to a named constant at %C");
1576 gfc_free_expr (expr
);
1577 gfc_undo_symbols ();
1578 gfc_current_locus
= old_loc
;
1582 /* All else has failed, so give up. See if any of the matchers has
1583 stored an error message of some sort. */
1584 if (gfc_error_check () == 0)
1585 gfc_error ("Unclassifiable statement in IF-clause at %C");
1587 gfc_free_expr (expr
);
1592 gfc_error ("Syntax error in IF-clause at %C");
1595 gfc_free_expr (expr
);
1599 /* At this point, we've matched the single IF and the action clause
1600 is in new_st. Rearrange things so that the IF statement appears
1603 p
= gfc_get_code ();
1604 p
->next
= gfc_get_code ();
1606 p
->next
->loc
= gfc_current_locus
;
1611 gfc_clear_new_st ();
1613 new_st
.op
= EXEC_IF
;
1622 /* Match an ELSE statement. */
1625 gfc_match_else (void)
1627 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
1629 if (gfc_match_eos () == MATCH_YES
)
1632 if (gfc_match_name (name
) != MATCH_YES
1633 || gfc_current_block () == NULL
1634 || gfc_match_eos () != MATCH_YES
)
1636 gfc_error ("Unexpected junk after ELSE statement at %C");
1640 if (strcmp (name
, gfc_current_block ()->name
) != 0)
1642 gfc_error ("Label '%s' at %C doesn't match IF label '%s'",
1643 name
, gfc_current_block ()->name
);
1651 /* Match an ELSE IF statement. */
1654 gfc_match_elseif (void)
1656 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
1660 m
= gfc_match (" ( %e ) then", &expr
);
1664 if (gfc_match_eos () == MATCH_YES
)
1667 if (gfc_match_name (name
) != MATCH_YES
1668 || gfc_current_block () == NULL
1669 || gfc_match_eos () != MATCH_YES
)
1671 gfc_error ("Unexpected junk after ELSE IF statement at %C");
1675 if (strcmp (name
, gfc_current_block ()->name
) != 0)
1677 gfc_error ("Label '%s' at %C doesn't match IF label '%s'",
1678 name
, gfc_current_block ()->name
);
1683 new_st
.op
= EXEC_IF
;
1688 gfc_free_expr (expr
);
1693 /* Free a gfc_iterator structure. */
1696 gfc_free_iterator (gfc_iterator
*iter
, int flag
)
1702 gfc_free_expr (iter
->var
);
1703 gfc_free_expr (iter
->start
);
1704 gfc_free_expr (iter
->end
);
1705 gfc_free_expr (iter
->step
);
1712 /* Match a DO statement. */
1717 gfc_iterator iter
, *ip
;
1719 gfc_st_label
*label
;
1722 old_loc
= gfc_current_locus
;
1725 iter
.var
= iter
.start
= iter
.end
= iter
.step
= NULL
;
1727 m
= gfc_match_label ();
1728 if (m
== MATCH_ERROR
)
1731 if (gfc_match (" do") != MATCH_YES
)
1734 m
= gfc_match_st_label (&label
);
1735 if (m
== MATCH_ERROR
)
1738 /* Match an infinite DO, make it like a DO WHILE(.TRUE.). */
1740 if (gfc_match_eos () == MATCH_YES
)
1742 iter
.end
= gfc_logical_expr (1, NULL
);
1743 new_st
.op
= EXEC_DO_WHILE
;
1747 /* Match an optional comma, if no comma is found, a space is obligatory. */
1748 if (gfc_match_char (',') != MATCH_YES
&& gfc_match ("% ") != MATCH_YES
)
1751 /* Check for balanced parens. */
1753 if (gfc_match_parens () == MATCH_ERROR
)
1756 /* See if we have a DO WHILE. */
1757 if (gfc_match (" while ( %e )%t", &iter
.end
) == MATCH_YES
)
1759 new_st
.op
= EXEC_DO_WHILE
;
1763 /* The abortive DO WHILE may have done something to the symbol
1764 table, so we start over. */
1765 gfc_undo_symbols ();
1766 gfc_current_locus
= old_loc
;
1768 gfc_match_label (); /* This won't error. */
1769 gfc_match (" do "); /* This will work. */
1771 gfc_match_st_label (&label
); /* Can't error out. */
1772 gfc_match_char (','); /* Optional comma. */
1774 m
= gfc_match_iterator (&iter
, 0);
1777 if (m
== MATCH_ERROR
)
1780 iter
.var
->symtree
->n
.sym
->attr
.implied_index
= 0;
1781 gfc_check_do_variable (iter
.var
->symtree
);
1783 if (gfc_match_eos () != MATCH_YES
)
1785 gfc_syntax_error (ST_DO
);
1789 new_st
.op
= EXEC_DO
;
1793 && gfc_reference_st_label (label
, ST_LABEL_TARGET
) == FAILURE
)
1796 new_st
.label
= label
;
1798 if (new_st
.op
== EXEC_DO_WHILE
)
1799 new_st
.expr
= iter
.end
;
1802 new_st
.ext
.iterator
= ip
= gfc_get_iterator ();
1809 gfc_free_iterator (&iter
, 0);
1815 /* Match an EXIT or CYCLE statement. */
1818 match_exit_cycle (gfc_statement st
, gfc_exec_op op
)
1820 gfc_state_data
*p
, *o
;
1824 if (gfc_match_eos () == MATCH_YES
)
1828 m
= gfc_match ("% %s%t", &sym
);
1829 if (m
== MATCH_ERROR
)
1833 gfc_syntax_error (st
);
1837 if (sym
->attr
.flavor
!= FL_LABEL
)
1839 gfc_error ("Name '%s' in %s statement at %C is not a loop name",
1840 sym
->name
, gfc_ascii_statement (st
));
1845 /* Find the loop mentioned specified by the label (or lack of a label). */
1846 for (o
= NULL
, p
= gfc_state_stack
; p
; p
= p
->previous
)
1847 if (p
->state
== COMP_DO
&& (sym
== NULL
|| sym
== p
->sym
))
1849 else if (o
== NULL
&& p
->state
== COMP_OMP_STRUCTURED_BLOCK
)
1855 gfc_error ("%s statement at %C is not within a loop",
1856 gfc_ascii_statement (st
));
1858 gfc_error ("%s statement at %C is not within loop '%s'",
1859 gfc_ascii_statement (st
), sym
->name
);
1866 gfc_error ("%s statement at %C leaving OpenMP structured block",
1867 gfc_ascii_statement (st
));
1870 else if (st
== ST_EXIT
1871 && p
->previous
!= NULL
1872 && p
->previous
->state
== COMP_OMP_STRUCTURED_BLOCK
1873 && (p
->previous
->head
->op
== EXEC_OMP_DO
1874 || p
->previous
->head
->op
== EXEC_OMP_PARALLEL_DO
))
1876 gcc_assert (p
->previous
->head
->next
!= NULL
);
1877 gcc_assert (p
->previous
->head
->next
->op
== EXEC_DO
1878 || p
->previous
->head
->next
->op
== EXEC_DO_WHILE
);
1879 gfc_error ("EXIT statement at %C terminating !$OMP DO loop");
1883 /* Save the first statement in the loop - needed by the backend. */
1884 new_st
.ext
.whichloop
= p
->head
;
1892 /* Match the EXIT statement. */
1895 gfc_match_exit (void)
1897 return match_exit_cycle (ST_EXIT
, EXEC_EXIT
);
1901 /* Match the CYCLE statement. */
1904 gfc_match_cycle (void)
1906 return match_exit_cycle (ST_CYCLE
, EXEC_CYCLE
);
1910 /* Match a number or character constant after a STOP or PAUSE statement. */
1913 gfc_match_stopcode (gfc_statement st
)
1923 if (gfc_match_eos () != MATCH_YES
)
1925 m
= gfc_match_small_literal_int (&stop_code
, &cnt
);
1926 if (m
== MATCH_ERROR
)
1929 if (m
== MATCH_YES
&& cnt
> 5)
1931 gfc_error ("Too many digits in STOP code at %C");
1937 /* Try a character constant. */
1938 m
= gfc_match_expr (&e
);
1939 if (m
== MATCH_ERROR
)
1943 if (e
->ts
.type
!= BT_CHARACTER
|| e
->expr_type
!= EXPR_CONSTANT
)
1947 if (gfc_match_eos () != MATCH_YES
)
1951 if (gfc_pure (NULL
))
1953 gfc_error ("%s statement not allowed in PURE procedure at %C",
1954 gfc_ascii_statement (st
));
1958 new_st
.op
= st
== ST_STOP
? EXEC_STOP
: EXEC_PAUSE
;
1960 new_st
.ext
.stop_code
= stop_code
;
1965 gfc_syntax_error (st
);
1974 /* Match the (deprecated) PAUSE statement. */
1977 gfc_match_pause (void)
1981 m
= gfc_match_stopcode (ST_PAUSE
);
1984 if (gfc_notify_std (GFC_STD_F95_DEL
, "Deleted feature: PAUSE statement"
1993 /* Match the STOP statement. */
1996 gfc_match_stop (void)
1998 return gfc_match_stopcode (ST_STOP
);
2002 /* Match a CONTINUE statement. */
2005 gfc_match_continue (void)
2007 if (gfc_match_eos () != MATCH_YES
)
2009 gfc_syntax_error (ST_CONTINUE
);
2013 new_st
.op
= EXEC_CONTINUE
;
2018 /* Match the (deprecated) ASSIGN statement. */
2021 gfc_match_assign (void)
2024 gfc_st_label
*label
;
2026 if (gfc_match (" %l", &label
) == MATCH_YES
)
2028 if (gfc_reference_st_label (label
, ST_LABEL_UNKNOWN
) == FAILURE
)
2030 if (gfc_match (" to %v%t", &expr
) == MATCH_YES
)
2032 if (gfc_notify_std (GFC_STD_F95_DEL
, "Deleted feature: ASSIGN "
2037 expr
->symtree
->n
.sym
->attr
.assign
= 1;
2039 new_st
.op
= EXEC_LABEL_ASSIGN
;
2040 new_st
.label
= label
;
2049 /* Match the GO TO statement. As a computed GOTO statement is
2050 matched, it is transformed into an equivalent SELECT block. No
2051 tree is necessary, and the resulting jumps-to-jumps are
2052 specifically optimized away by the back end. */
2055 gfc_match_goto (void)
2057 gfc_code
*head
, *tail
;
2060 gfc_st_label
*label
;
2064 if (gfc_match (" %l%t", &label
) == MATCH_YES
)
2066 if (gfc_reference_st_label (label
, ST_LABEL_TARGET
) == FAILURE
)
2069 new_st
.op
= EXEC_GOTO
;
2070 new_st
.label
= label
;
2074 /* The assigned GO TO statement. */
2076 if (gfc_match_variable (&expr
, 0) == MATCH_YES
)
2078 if (gfc_notify_std (GFC_STD_F95_DEL
, "Deleted feature: Assigned GOTO "
2083 new_st
.op
= EXEC_GOTO
;
2086 if (gfc_match_eos () == MATCH_YES
)
2089 /* Match label list. */
2090 gfc_match_char (',');
2091 if (gfc_match_char ('(') != MATCH_YES
)
2093 gfc_syntax_error (ST_GOTO
);
2100 m
= gfc_match_st_label (&label
);
2104 if (gfc_reference_st_label (label
, ST_LABEL_TARGET
) == FAILURE
)
2108 head
= tail
= gfc_get_code ();
2111 tail
->block
= gfc_get_code ();
2115 tail
->label
= label
;
2116 tail
->op
= EXEC_GOTO
;
2118 while (gfc_match_char (',') == MATCH_YES
);
2120 if (gfc_match (")%t") != MATCH_YES
)
2125 gfc_error ("Statement label list in GOTO at %C cannot be empty");
2128 new_st
.block
= head
;
2133 /* Last chance is a computed GO TO statement. */
2134 if (gfc_match_char ('(') != MATCH_YES
)
2136 gfc_syntax_error (ST_GOTO
);
2145 m
= gfc_match_st_label (&label
);
2149 if (gfc_reference_st_label (label
, ST_LABEL_TARGET
) == FAILURE
)
2153 head
= tail
= gfc_get_code ();
2156 tail
->block
= gfc_get_code ();
2160 cp
= gfc_get_case ();
2161 cp
->low
= cp
->high
= gfc_int_expr (i
++);
2163 tail
->op
= EXEC_SELECT
;
2164 tail
->ext
.case_list
= cp
;
2166 tail
->next
= gfc_get_code ();
2167 tail
->next
->op
= EXEC_GOTO
;
2168 tail
->next
->label
= label
;
2170 while (gfc_match_char (',') == MATCH_YES
);
2172 if (gfc_match_char (')') != MATCH_YES
)
2177 gfc_error ("Statement label list in GOTO at %C cannot be empty");
2181 /* Get the rest of the statement. */
2182 gfc_match_char (',');
2184 if (gfc_match (" %e%t", &expr
) != MATCH_YES
)
2187 /* At this point, a computed GOTO has been fully matched and an
2188 equivalent SELECT statement constructed. */
2190 new_st
.op
= EXEC_SELECT
;
2193 /* Hack: For a "real" SELECT, the expression is in expr. We put
2194 it in expr2 so we can distinguish then and produce the correct
2196 new_st
.expr2
= expr
;
2197 new_st
.block
= head
;
2201 gfc_syntax_error (ST_GOTO
);
2203 gfc_free_statements (head
);
2208 /* Frees a list of gfc_alloc structures. */
2211 gfc_free_alloc_list (gfc_alloc
*p
)
2218 gfc_free_expr (p
->expr
);
2224 /* Match an ALLOCATE statement. */
2227 gfc_match_allocate (void)
2229 gfc_alloc
*head
, *tail
;
2236 if (gfc_match_char ('(') != MATCH_YES
)
2242 head
= tail
= gfc_get_alloc ();
2245 tail
->next
= gfc_get_alloc ();
2249 m
= gfc_match_variable (&tail
->expr
, 0);
2252 if (m
== MATCH_ERROR
)
2255 if (gfc_check_do_variable (tail
->expr
->symtree
))
2259 && gfc_impure_variable (tail
->expr
->symtree
->n
.sym
))
2261 gfc_error ("Bad allocate-object in ALLOCATE statement at %C for a "
2266 if (tail
->expr
->ts
.type
== BT_DERIVED
)
2267 tail
->expr
->ts
.derived
= gfc_use_derived (tail
->expr
->ts
.derived
);
2269 if (gfc_match_char (',') != MATCH_YES
)
2272 m
= gfc_match (" stat = %v", &stat
);
2273 if (m
== MATCH_ERROR
)
2280 gfc_check_do_variable(stat
->symtree
);
2282 if (gfc_match (" )%t") != MATCH_YES
)
2285 new_st
.op
= EXEC_ALLOCATE
;
2287 new_st
.ext
.alloc_list
= head
;
2292 gfc_syntax_error (ST_ALLOCATE
);
2295 gfc_free_expr (stat
);
2296 gfc_free_alloc_list (head
);
2301 /* Match a NULLIFY statement. A NULLIFY statement is transformed into
2302 a set of pointer assignments to intrinsic NULL(). */
2305 gfc_match_nullify (void)
2313 if (gfc_match_char ('(') != MATCH_YES
)
2318 m
= gfc_match_variable (&p
, 0);
2319 if (m
== MATCH_ERROR
)
2324 if (gfc_check_do_variable (p
->symtree
))
2327 if (gfc_pure (NULL
) && gfc_impure_variable (p
->symtree
->n
.sym
))
2329 gfc_error ("Illegal variable in NULLIFY at %C for a PURE procedure");
2333 /* build ' => NULL() '. */
2334 e
= gfc_get_expr ();
2335 e
->where
= gfc_current_locus
;
2336 e
->expr_type
= EXPR_NULL
;
2337 e
->ts
.type
= BT_UNKNOWN
;
2339 /* Chain to list. */
2344 tail
->next
= gfc_get_code ();
2348 tail
->op
= EXEC_POINTER_ASSIGN
;
2352 if (gfc_match (" )%t") == MATCH_YES
)
2354 if (gfc_match_char (',') != MATCH_YES
)
2361 gfc_syntax_error (ST_NULLIFY
);
2364 gfc_free_statements (new_st
.next
);
2369 /* Match a DEALLOCATE statement. */
2372 gfc_match_deallocate (void)
2374 gfc_alloc
*head
, *tail
;
2381 if (gfc_match_char ('(') != MATCH_YES
)
2387 head
= tail
= gfc_get_alloc ();
2390 tail
->next
= gfc_get_alloc ();
2394 m
= gfc_match_variable (&tail
->expr
, 0);
2395 if (m
== MATCH_ERROR
)
2400 if (gfc_check_do_variable (tail
->expr
->symtree
))
2404 && gfc_impure_variable (tail
->expr
->symtree
->n
.sym
))
2406 gfc_error ("Illegal deallocate-expression in DEALLOCATE at %C "
2407 "for a PURE procedure");
2411 if (gfc_match_char (',') != MATCH_YES
)
2414 m
= gfc_match (" stat = %v", &stat
);
2415 if (m
== MATCH_ERROR
)
2422 gfc_check_do_variable(stat
->symtree
);
2424 if (gfc_match (" )%t") != MATCH_YES
)
2427 new_st
.op
= EXEC_DEALLOCATE
;
2429 new_st
.ext
.alloc_list
= head
;
2434 gfc_syntax_error (ST_DEALLOCATE
);
2437 gfc_free_expr (stat
);
2438 gfc_free_alloc_list (head
);
2443 /* Match a RETURN statement. */
2446 gfc_match_return (void)
2450 gfc_compile_state s
;
2453 if (gfc_match_eos () == MATCH_YES
)
2456 if (gfc_find_state (COMP_SUBROUTINE
) == FAILURE
)
2458 gfc_error ("Alternate RETURN statement at %C is only allowed within "
2463 if (gfc_current_form
== FORM_FREE
)
2465 /* The following are valid, so we can't require a blank after the
2469 char c
= gfc_peek_ascii_char ();
2470 if (ISALPHA (c
) || ISDIGIT (c
))
2474 m
= gfc_match (" %e%t", &e
);
2477 if (m
== MATCH_ERROR
)
2480 gfc_syntax_error (ST_RETURN
);
2487 gfc_enclosing_unit (&s
);
2488 if (s
== COMP_PROGRAM
2489 && gfc_notify_std (GFC_STD_GNU
, "Extension: RETURN statement in "
2490 "main program at %C") == FAILURE
)
2493 new_st
.op
= EXEC_RETURN
;
2500 /* Match a CALL statement. The tricky part here are possible
2501 alternate return specifiers. We handle these by having all
2502 "subroutines" actually return an integer via a register that gives
2503 the return number. If the call specifies alternate returns, we
2504 generate code for a SELECT statement whose case clauses contain
2505 GOTOs to the various labels. */
2508 gfc_match_call (void)
2510 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2511 gfc_actual_arglist
*a
, *arglist
;
2521 m
= gfc_match ("% %n", name
);
2527 if (gfc_get_ha_sym_tree (name
, &st
))
2532 /* If it does not seem to be callable... */
2533 if (!sym
->attr
.generic
2534 && !sym
->attr
.subroutine
)
2536 if (!(sym
->attr
.external
&& !sym
->attr
.referenced
))
2538 /* ...create a symbol in this scope... */
2539 if (sym
->ns
!= gfc_current_ns
2540 && gfc_get_sym_tree (name
, NULL
, &st
) == 1)
2543 if (sym
!= st
->n
.sym
)
2547 /* ...and then to try to make the symbol into a subroutine. */
2548 if (gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
2552 gfc_set_sym_referenced (sym
);
2554 if (gfc_match_eos () != MATCH_YES
)
2556 m
= gfc_match_actual_arglist (1, &arglist
);
2559 if (m
== MATCH_ERROR
)
2562 if (gfc_match_eos () != MATCH_YES
)
2566 /* If any alternate return labels were found, construct a SELECT
2567 statement that will jump to the right place. */
2570 for (a
= arglist
; a
; a
= a
->next
)
2571 if (a
->expr
== NULL
)
2576 gfc_symtree
*select_st
;
2577 gfc_symbol
*select_sym
;
2578 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2580 new_st
.next
= c
= gfc_get_code ();
2581 c
->op
= EXEC_SELECT
;
2582 sprintf (name
, "_result_%s", sym
->name
);
2583 gfc_get_ha_sym_tree (name
, &select_st
); /* Can't fail. */
2585 select_sym
= select_st
->n
.sym
;
2586 select_sym
->ts
.type
= BT_INTEGER
;
2587 select_sym
->ts
.kind
= gfc_default_integer_kind
;
2588 gfc_set_sym_referenced (select_sym
);
2589 c
->expr
= gfc_get_expr ();
2590 c
->expr
->expr_type
= EXPR_VARIABLE
;
2591 c
->expr
->symtree
= select_st
;
2592 c
->expr
->ts
= select_sym
->ts
;
2593 c
->expr
->where
= gfc_current_locus
;
2596 for (a
= arglist
; a
; a
= a
->next
)
2598 if (a
->expr
!= NULL
)
2601 if (gfc_reference_st_label (a
->label
, ST_LABEL_TARGET
) == FAILURE
)
2606 c
->block
= gfc_get_code ();
2608 c
->op
= EXEC_SELECT
;
2610 new_case
= gfc_get_case ();
2611 new_case
->high
= new_case
->low
= gfc_int_expr (i
);
2612 c
->ext
.case_list
= new_case
;
2614 c
->next
= gfc_get_code ();
2615 c
->next
->op
= EXEC_GOTO
;
2616 c
->next
->label
= a
->label
;
2620 new_st
.op
= EXEC_CALL
;
2621 new_st
.symtree
= st
;
2622 new_st
.ext
.actual
= arglist
;
2627 gfc_syntax_error (ST_CALL
);
2630 gfc_free_actual_arglist (arglist
);
2635 /* Given a name, return a pointer to the common head structure,
2636 creating it if it does not exist. If FROM_MODULE is nonzero, we
2637 mangle the name so that it doesn't interfere with commons defined
2638 in the using namespace.
2639 TODO: Add to global symbol tree. */
2642 gfc_get_common (const char *name
, int from_module
)
2645 static int serial
= 0;
2646 char mangled_name
[GFC_MAX_SYMBOL_LEN
+ 1];
2650 /* A use associated common block is only needed to correctly layout
2651 the variables it contains. */
2652 snprintf (mangled_name
, GFC_MAX_SYMBOL_LEN
, "_%d_%s", serial
++, name
);
2653 st
= gfc_new_symtree (&gfc_current_ns
->common_root
, mangled_name
);
2657 st
= gfc_find_symtree (gfc_current_ns
->common_root
, name
);
2660 st
= gfc_new_symtree (&gfc_current_ns
->common_root
, name
);
2663 if (st
->n
.common
== NULL
)
2665 st
->n
.common
= gfc_get_common_head ();
2666 st
->n
.common
->where
= gfc_current_locus
;
2667 strcpy (st
->n
.common
->name
, name
);
2670 return st
->n
.common
;
2674 /* Match a common block name. */
2676 match
match_common_name (char *name
)
2680 if (gfc_match_char ('/') == MATCH_NO
)
2686 if (gfc_match_char ('/') == MATCH_YES
)
2692 m
= gfc_match_name (name
);
2694 if (m
== MATCH_ERROR
)
2696 if (m
== MATCH_YES
&& gfc_match_char ('/') == MATCH_YES
)
2699 gfc_error ("Syntax error in common block name at %C");
2704 /* Match a COMMON statement. */
2707 gfc_match_common (void)
2709 gfc_symbol
*sym
, **head
, *tail
, *other
, *old_blank_common
;
2710 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2717 old_blank_common
= gfc_current_ns
->blank_common
.head
;
2718 if (old_blank_common
)
2720 while (old_blank_common
->common_next
)
2721 old_blank_common
= old_blank_common
->common_next
;
2728 m
= match_common_name (name
);
2729 if (m
== MATCH_ERROR
)
2732 gsym
= gfc_get_gsymbol (name
);
2733 if (gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= GSYM_COMMON
)
2735 gfc_error ("Symbol '%s' at %C is already an external symbol that "
2736 "is not COMMON", name
);
2740 if (gsym
->type
== GSYM_UNKNOWN
)
2742 gsym
->type
= GSYM_COMMON
;
2743 gsym
->where
= gfc_current_locus
;
2749 if (name
[0] == '\0')
2751 t
= &gfc_current_ns
->blank_common
;
2752 if (t
->head
== NULL
)
2753 t
->where
= gfc_current_locus
;
2757 t
= gfc_get_common (name
, 0);
2766 while (tail
->common_next
)
2767 tail
= tail
->common_next
;
2770 /* Grab the list of symbols. */
2773 m
= gfc_match_symbol (&sym
, 0);
2774 if (m
== MATCH_ERROR
)
2779 /* Store a ref to the common block for error checking. */
2780 sym
->common_block
= t
;
2782 /* See if we know the current common block is bind(c), and if
2783 so, then see if we can check if the symbol is (which it'll
2784 need to be). This can happen if the bind(c) attr stmt was
2785 applied to the common block, and the variable(s) already
2786 defined, before declaring the common block. */
2787 if (t
->is_bind_c
== 1)
2789 if (sym
->ts
.type
!= BT_UNKNOWN
&& sym
->ts
.is_c_interop
!= 1)
2791 /* If we find an error, just print it and continue,
2792 cause it's just semantic, and we can see if there
2794 gfc_error_now ("Variable '%s' at %L in common block '%s' "
2795 "at %C must be declared with a C "
2796 "interoperable kind since common block "
2798 sym
->name
, &(sym
->declared_at
), t
->name
,
2802 if (sym
->attr
.is_bind_c
== 1)
2803 gfc_error_now ("Variable '%s' in common block "
2804 "'%s' at %C can not be bind(c) since "
2805 "it is not global", sym
->name
, t
->name
);
2808 if (sym
->attr
.in_common
)
2810 gfc_error ("Symbol '%s' at %C is already in a COMMON block",
2815 if (((sym
->value
!= NULL
&& sym
->value
->expr_type
!= EXPR_NULL
)
2816 || sym
->attr
.data
) && gfc_current_state () != COMP_BLOCK_DATA
)
2818 if (gfc_notify_std (GFC_STD_GNU
, "Initialized symbol '%s' at %C "
2819 "can only be COMMON in "
2820 "BLOCK DATA", sym
->name
)
2825 if (gfc_add_in_common (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
2829 tail
->common_next
= sym
;
2835 /* Deal with an optional array specification after the
2837 m
= gfc_match_array_spec (&as
);
2838 if (m
== MATCH_ERROR
)
2843 if (as
->type
!= AS_EXPLICIT
)
2845 gfc_error ("Array specification for symbol '%s' in COMMON "
2846 "at %C must be explicit", sym
->name
);
2850 if (gfc_add_dimension (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
2853 if (sym
->attr
.pointer
)
2855 gfc_error ("Symbol '%s' in COMMON at %C cannot be a "
2856 "POINTER array", sym
->name
);
2865 sym
->common_head
= t
;
2867 /* Check to see if the symbol is already in an equivalence group.
2868 If it is, set the other members as being in common. */
2869 if (sym
->attr
.in_equivalence
)
2871 for (e1
= gfc_current_ns
->equiv
; e1
; e1
= e1
->next
)
2873 for (e2
= e1
; e2
; e2
= e2
->eq
)
2874 if (e2
->expr
->symtree
->n
.sym
== sym
)
2881 for (e2
= e1
; e2
; e2
= e2
->eq
)
2883 other
= e2
->expr
->symtree
->n
.sym
;
2884 if (other
->common_head
2885 && other
->common_head
!= sym
->common_head
)
2887 gfc_error ("Symbol '%s', in COMMON block '%s' at "
2888 "%C is being indirectly equivalenced to "
2889 "another COMMON block '%s'",
2890 sym
->name
, sym
->common_head
->name
,
2891 other
->common_head
->name
);
2894 other
->attr
.in_common
= 1;
2895 other
->common_head
= t
;
2901 gfc_gobble_whitespace ();
2902 if (gfc_match_eos () == MATCH_YES
)
2904 if (gfc_peek_ascii_char () == '/')
2906 if (gfc_match_char (',') != MATCH_YES
)
2908 gfc_gobble_whitespace ();
2909 if (gfc_peek_ascii_char () == '/')
2918 gfc_syntax_error (ST_COMMON
);
2921 if (old_blank_common
)
2922 old_blank_common
->common_next
= NULL
;
2924 gfc_current_ns
->blank_common
.head
= NULL
;
2925 gfc_free_array_spec (as
);
2930 /* Match a BLOCK DATA program unit. */
2933 gfc_match_block_data (void)
2935 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2939 if (gfc_match_eos () == MATCH_YES
)
2941 gfc_new_block
= NULL
;
2945 m
= gfc_match ("% %n%t", name
);
2949 if (gfc_get_symbol (name
, NULL
, &sym
))
2952 if (gfc_add_flavor (&sym
->attr
, FL_BLOCK_DATA
, sym
->name
, NULL
) == FAILURE
)
2955 gfc_new_block
= sym
;
2961 /* Free a namelist structure. */
2964 gfc_free_namelist (gfc_namelist
*name
)
2968 for (; name
; name
= n
)
2976 /* Match a NAMELIST statement. */
2979 gfc_match_namelist (void)
2981 gfc_symbol
*group_name
, *sym
;
2985 m
= gfc_match (" / %s /", &group_name
);
2988 if (m
== MATCH_ERROR
)
2993 if (group_name
->ts
.type
!= BT_UNKNOWN
)
2995 gfc_error ("Namelist group name '%s' at %C already has a basic "
2996 "type of %s", group_name
->name
,
2997 gfc_typename (&group_name
->ts
));
3001 if (group_name
->attr
.flavor
== FL_NAMELIST
3002 && group_name
->attr
.use_assoc
3003 && gfc_notify_std (GFC_STD_GNU
, "Namelist group name '%s' "
3004 "at %C already is USE associated and can"
3005 "not be respecified.", group_name
->name
)
3009 if (group_name
->attr
.flavor
!= FL_NAMELIST
3010 && gfc_add_flavor (&group_name
->attr
, FL_NAMELIST
,
3011 group_name
->name
, NULL
) == FAILURE
)
3016 m
= gfc_match_symbol (&sym
, 1);
3019 if (m
== MATCH_ERROR
)
3022 if (sym
->attr
.in_namelist
== 0
3023 && gfc_add_in_namelist (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
3026 /* Use gfc_error_check here, rather than goto error, so that
3027 these are the only errors for the next two lines. */
3028 if (sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
)
3030 gfc_error ("Assumed size array '%s' in namelist '%s' at "
3031 "%C is not allowed", sym
->name
, group_name
->name
);
3035 if (sym
->ts
.type
== BT_CHARACTER
&& sym
->ts
.cl
->length
== NULL
)
3037 gfc_error ("Assumed character length '%s' in namelist '%s' at "
3038 "%C is not allowed", sym
->name
, group_name
->name
);
3042 nl
= gfc_get_namelist ();
3046 if (group_name
->namelist
== NULL
)
3047 group_name
->namelist
= group_name
->namelist_tail
= nl
;
3050 group_name
->namelist_tail
->next
= nl
;
3051 group_name
->namelist_tail
= nl
;
3054 if (gfc_match_eos () == MATCH_YES
)
3057 m
= gfc_match_char (',');
3059 if (gfc_match_char ('/') == MATCH_YES
)
3061 m2
= gfc_match (" %s /", &group_name
);
3062 if (m2
== MATCH_YES
)
3064 if (m2
== MATCH_ERROR
)
3078 gfc_syntax_error (ST_NAMELIST
);
3085 /* Match a MODULE statement. */
3088 gfc_match_module (void)
3092 m
= gfc_match (" %s%t", &gfc_new_block
);
3096 if (gfc_add_flavor (&gfc_new_block
->attr
, FL_MODULE
,
3097 gfc_new_block
->name
, NULL
) == FAILURE
)
3104 /* Free equivalence sets and lists. Recursively is the easiest way to
3108 gfc_free_equiv (gfc_equiv
*eq
)
3113 gfc_free_equiv (eq
->eq
);
3114 gfc_free_equiv (eq
->next
);
3115 gfc_free_expr (eq
->expr
);
3120 /* Match an EQUIVALENCE statement. */
3123 gfc_match_equivalence (void)
3125 gfc_equiv
*eq
, *set
, *tail
;
3129 gfc_common_head
*common_head
= NULL
;
3137 eq
= gfc_get_equiv ();
3141 eq
->next
= gfc_current_ns
->equiv
;
3142 gfc_current_ns
->equiv
= eq
;
3144 if (gfc_match_char ('(') != MATCH_YES
)
3148 common_flag
= FALSE
;
3153 m
= gfc_match_equiv_variable (&set
->expr
);
3154 if (m
== MATCH_ERROR
)
3159 /* count the number of objects. */
3162 if (gfc_match_char ('%') == MATCH_YES
)
3164 gfc_error ("Derived type component %C is not a "
3165 "permitted EQUIVALENCE member");
3169 for (ref
= set
->expr
->ref
; ref
; ref
= ref
->next
)
3170 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
== AR_SECTION
)
3172 gfc_error ("Array reference in EQUIVALENCE at %C cannot "
3173 "be an array section");
3177 sym
= set
->expr
->symtree
->n
.sym
;
3179 if (gfc_add_in_equivalence (&sym
->attr
, sym
->name
, NULL
) == FAILURE
)
3182 if (sym
->attr
.in_common
)
3185 common_head
= sym
->common_head
;
3188 if (gfc_match_char (')') == MATCH_YES
)
3191 if (gfc_match_char (',') != MATCH_YES
)
3194 set
->eq
= gfc_get_equiv ();
3200 gfc_error ("EQUIVALENCE at %C requires two or more objects");
3204 /* If one of the members of an equivalence is in common, then
3205 mark them all as being in common. Before doing this, check
3206 that members of the equivalence group are not in different
3209 for (set
= eq
; set
; set
= set
->eq
)
3211 sym
= set
->expr
->symtree
->n
.sym
;
3212 if (sym
->common_head
&& sym
->common_head
!= common_head
)
3214 gfc_error ("Attempt to indirectly overlap COMMON "
3215 "blocks %s and %s by EQUIVALENCE at %C",
3216 sym
->common_head
->name
, common_head
->name
);
3219 sym
->attr
.in_common
= 1;
3220 sym
->common_head
= common_head
;
3223 if (gfc_match_eos () == MATCH_YES
)
3225 if (gfc_match_char (',') != MATCH_YES
)
3232 gfc_syntax_error (ST_EQUIVALENCE
);
3238 gfc_free_equiv (gfc_current_ns
->equiv
);
3239 gfc_current_ns
->equiv
= eq
;
3245 /* Check that a statement function is not recursive. This is done by looking
3246 for the statement function symbol(sym) by looking recursively through its
3247 expression(e). If a reference to sym is found, true is returned.
3248 12.5.4 requires that any variable of function that is implicitly typed
3249 shall have that type confirmed by any subsequent type declaration. The
3250 implicit typing is conveniently done here. */
3252 recursive_stmt_fcn (gfc_expr
*, gfc_symbol
*);
3255 check_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
3261 switch (e
->expr_type
)
3264 if (e
->symtree
== NULL
)
3267 /* Check the name before testing for nested recursion! */
3268 if (sym
->name
== e
->symtree
->n
.sym
->name
)
3271 /* Catch recursion via other statement functions. */
3272 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
3273 && e
->symtree
->n
.sym
->value
3274 && recursive_stmt_fcn (e
->symtree
->n
.sym
->value
, sym
))
3277 if (e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
)
3278 gfc_set_default_type (e
->symtree
->n
.sym
, 0, NULL
);
3283 if (e
->symtree
&& sym
->name
== e
->symtree
->n
.sym
->name
)
3286 if (e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
)
3287 gfc_set_default_type (e
->symtree
->n
.sym
, 0, NULL
);
3299 recursive_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
)
3301 return gfc_traverse_expr (e
, sym
, check_stmt_fcn
, 0);
3305 /* Match a statement function declaration. It is so easy to match
3306 non-statement function statements with a MATCH_ERROR as opposed to
3307 MATCH_NO that we suppress error message in most cases. */
3310 gfc_match_st_function (void)
3312 gfc_error_buf old_error
;
3317 m
= gfc_match_symbol (&sym
, 0);
3321 gfc_push_error (&old_error
);
3323 if (gfc_add_procedure (&sym
->attr
, PROC_ST_FUNCTION
,
3324 sym
->name
, NULL
) == FAILURE
)
3327 if (gfc_match_formal_arglist (sym
, 1, 0) != MATCH_YES
)
3330 m
= gfc_match (" = %e%t", &expr
);
3334 gfc_free_error (&old_error
);
3335 if (m
== MATCH_ERROR
)
3338 if (recursive_stmt_fcn (expr
, sym
))
3340 gfc_error ("Statement function at %L is recursive", &expr
->where
);
3349 gfc_pop_error (&old_error
);
3354 /***************** SELECT CASE subroutines ******************/
3356 /* Free a single case structure. */
3359 free_case (gfc_case
*p
)
3361 if (p
->low
== p
->high
)
3363 gfc_free_expr (p
->low
);
3364 gfc_free_expr (p
->high
);
3369 /* Free a list of case structures. */
3372 gfc_free_case_list (gfc_case
*p
)
3384 /* Match a single case selector. */
3387 match_case_selector (gfc_case
**cp
)
3392 c
= gfc_get_case ();
3393 c
->where
= gfc_current_locus
;
3395 if (gfc_match_char (':') == MATCH_YES
)
3397 m
= gfc_match_init_expr (&c
->high
);
3400 if (m
== MATCH_ERROR
)
3405 m
= gfc_match_init_expr (&c
->low
);
3406 if (m
== MATCH_ERROR
)
3411 /* If we're not looking at a ':' now, make a range out of a single
3412 target. Else get the upper bound for the case range. */
3413 if (gfc_match_char (':') != MATCH_YES
)
3417 m
= gfc_match_init_expr (&c
->high
);
3418 if (m
== MATCH_ERROR
)
3420 /* MATCH_NO is fine. It's OK if nothing is there! */
3428 gfc_error ("Expected initialization expression in CASE at %C");
3436 /* Match the end of a case statement. */
3439 match_case_eos (void)
3441 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3444 if (gfc_match_eos () == MATCH_YES
)
3447 /* If the case construct doesn't have a case-construct-name, we
3448 should have matched the EOS. */
3449 if (!gfc_current_block ())
3451 gfc_error ("Expected the name of the SELECT CASE construct at %C");
3455 gfc_gobble_whitespace ();
3457 m
= gfc_match_name (name
);
3461 if (strcmp (name
, gfc_current_block ()->name
) != 0)
3463 gfc_error ("Expected case name of '%s' at %C",
3464 gfc_current_block ()->name
);
3468 return gfc_match_eos ();
3472 /* Match a SELECT statement. */
3475 gfc_match_select (void)
3480 m
= gfc_match_label ();
3481 if (m
== MATCH_ERROR
)
3484 m
= gfc_match (" select case ( %e )%t", &expr
);
3488 new_st
.op
= EXEC_SELECT
;
3495 /* Match a CASE statement. */
3498 gfc_match_case (void)
3500 gfc_case
*c
, *head
, *tail
;
3505 if (gfc_current_state () != COMP_SELECT
)
3507 gfc_error ("Unexpected CASE statement at %C");
3511 if (gfc_match ("% default") == MATCH_YES
)
3513 m
= match_case_eos ();
3516 if (m
== MATCH_ERROR
)
3519 new_st
.op
= EXEC_SELECT
;
3520 c
= gfc_get_case ();
3521 c
->where
= gfc_current_locus
;
3522 new_st
.ext
.case_list
= c
;
3526 if (gfc_match_char ('(') != MATCH_YES
)
3531 if (match_case_selector (&c
) == MATCH_ERROR
)
3541 if (gfc_match_char (')') == MATCH_YES
)
3543 if (gfc_match_char (',') != MATCH_YES
)
3547 m
= match_case_eos ();
3550 if (m
== MATCH_ERROR
)
3553 new_st
.op
= EXEC_SELECT
;
3554 new_st
.ext
.case_list
= head
;
3559 gfc_error ("Syntax error in CASE-specification at %C");
3562 gfc_free_case_list (head
); /* new_st is cleaned up in parse.c. */
3566 /********************* WHERE subroutines ********************/
3568 /* Match the rest of a simple WHERE statement that follows an IF statement.
3572 match_simple_where (void)
3578 m
= gfc_match (" ( %e )", &expr
);
3582 m
= gfc_match_assignment ();
3585 if (m
== MATCH_ERROR
)
3588 if (gfc_match_eos () != MATCH_YES
)
3591 c
= gfc_get_code ();
3595 c
->next
= gfc_get_code ();
3598 gfc_clear_new_st ();
3600 new_st
.op
= EXEC_WHERE
;
3606 gfc_syntax_error (ST_WHERE
);
3609 gfc_free_expr (expr
);
3614 /* Match a WHERE statement. */
3617 gfc_match_where (gfc_statement
*st
)
3623 m0
= gfc_match_label ();
3624 if (m0
== MATCH_ERROR
)
3627 m
= gfc_match (" where ( %e )", &expr
);
3631 if (gfc_match_eos () == MATCH_YES
)
3633 *st
= ST_WHERE_BLOCK
;
3634 new_st
.op
= EXEC_WHERE
;
3639 m
= gfc_match_assignment ();
3641 gfc_syntax_error (ST_WHERE
);
3645 gfc_free_expr (expr
);
3649 /* We've got a simple WHERE statement. */
3651 c
= gfc_get_code ();
3655 c
->next
= gfc_get_code ();
3658 gfc_clear_new_st ();
3660 new_st
.op
= EXEC_WHERE
;
3667 /* Match an ELSEWHERE statement. We leave behind a WHERE node in
3668 new_st if successful. */
3671 gfc_match_elsewhere (void)
3673 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3677 if (gfc_current_state () != COMP_WHERE
)
3679 gfc_error ("ELSEWHERE statement at %C not enclosed in WHERE block");
3685 if (gfc_match_char ('(') == MATCH_YES
)
3687 m
= gfc_match_expr (&expr
);
3690 if (m
== MATCH_ERROR
)
3693 if (gfc_match_char (')') != MATCH_YES
)
3697 if (gfc_match_eos () != MATCH_YES
)
3699 /* Only makes sense if we have a where-construct-name. */
3700 if (!gfc_current_block ())
3705 /* Better be a name at this point. */
3706 m
= gfc_match_name (name
);
3709 if (m
== MATCH_ERROR
)
3712 if (gfc_match_eos () != MATCH_YES
)
3715 if (strcmp (name
, gfc_current_block ()->name
) != 0)
3717 gfc_error ("Label '%s' at %C doesn't match WHERE label '%s'",
3718 name
, gfc_current_block ()->name
);
3723 new_st
.op
= EXEC_WHERE
;
3728 gfc_syntax_error (ST_ELSEWHERE
);
3731 gfc_free_expr (expr
);
3736 /******************** FORALL subroutines ********************/
3738 /* Free a list of FORALL iterators. */
3741 gfc_free_forall_iterator (gfc_forall_iterator
*iter
)
3743 gfc_forall_iterator
*next
;
3748 gfc_free_expr (iter
->var
);
3749 gfc_free_expr (iter
->start
);
3750 gfc_free_expr (iter
->end
);
3751 gfc_free_expr (iter
->stride
);
3758 /* Match an iterator as part of a FORALL statement. The format is:
3760 <var> = <start>:<end>[:<stride>]
3762 On MATCH_NO, the caller tests for the possibility that there is a
3763 scalar mask expression. */
3766 match_forall_iterator (gfc_forall_iterator
**result
)
3768 gfc_forall_iterator
*iter
;
3772 where
= gfc_current_locus
;
3773 iter
= gfc_getmem (sizeof (gfc_forall_iterator
));
3775 m
= gfc_match_expr (&iter
->var
);
3779 if (gfc_match_char ('=') != MATCH_YES
3780 || iter
->var
->expr_type
!= EXPR_VARIABLE
)
3786 m
= gfc_match_expr (&iter
->start
);
3790 if (gfc_match_char (':') != MATCH_YES
)
3793 m
= gfc_match_expr (&iter
->end
);
3796 if (m
== MATCH_ERROR
)
3799 if (gfc_match_char (':') == MATCH_NO
)
3800 iter
->stride
= gfc_int_expr (1);
3803 m
= gfc_match_expr (&iter
->stride
);
3806 if (m
== MATCH_ERROR
)
3810 /* Mark the iteration variable's symbol as used as a FORALL index. */
3811 iter
->var
->symtree
->n
.sym
->forall_index
= true;
3817 gfc_error ("Syntax error in FORALL iterator at %C");
3822 gfc_current_locus
= where
;
3823 gfc_free_forall_iterator (iter
);
3828 /* Match the header of a FORALL statement. */
3831 match_forall_header (gfc_forall_iterator
**phead
, gfc_expr
**mask
)
3833 gfc_forall_iterator
*head
, *tail
, *new;
3837 gfc_gobble_whitespace ();
3842 if (gfc_match_char ('(') != MATCH_YES
)
3845 m
= match_forall_iterator (&new);
3846 if (m
== MATCH_ERROR
)
3855 if (gfc_match_char (',') != MATCH_YES
)
3858 m
= match_forall_iterator (&new);
3859 if (m
== MATCH_ERROR
)
3869 /* Have to have a mask expression. */
3871 m
= gfc_match_expr (&msk
);
3874 if (m
== MATCH_ERROR
)
3880 if (gfc_match_char (')') == MATCH_NO
)
3888 gfc_syntax_error (ST_FORALL
);
3891 gfc_free_expr (msk
);
3892 gfc_free_forall_iterator (head
);
3897 /* Match the rest of a simple FORALL statement that follows an
3901 match_simple_forall (void)
3903 gfc_forall_iterator
*head
;
3912 m
= match_forall_header (&head
, &mask
);
3919 m
= gfc_match_assignment ();
3921 if (m
== MATCH_ERROR
)
3925 m
= gfc_match_pointer_assignment ();
3926 if (m
== MATCH_ERROR
)
3932 c
= gfc_get_code ();
3934 c
->loc
= gfc_current_locus
;
3936 if (gfc_match_eos () != MATCH_YES
)
3939 gfc_clear_new_st ();
3940 new_st
.op
= EXEC_FORALL
;
3942 new_st
.ext
.forall_iterator
= head
;
3943 new_st
.block
= gfc_get_code ();
3945 new_st
.block
->op
= EXEC_FORALL
;
3946 new_st
.block
->next
= c
;
3951 gfc_syntax_error (ST_FORALL
);
3954 gfc_free_forall_iterator (head
);
3955 gfc_free_expr (mask
);
3961 /* Match a FORALL statement. */
3964 gfc_match_forall (gfc_statement
*st
)
3966 gfc_forall_iterator
*head
;
3975 m0
= gfc_match_label ();
3976 if (m0
== MATCH_ERROR
)
3979 m
= gfc_match (" forall");
3983 m
= match_forall_header (&head
, &mask
);
3984 if (m
== MATCH_ERROR
)
3989 if (gfc_match_eos () == MATCH_YES
)
3991 *st
= ST_FORALL_BLOCK
;
3992 new_st
.op
= EXEC_FORALL
;
3994 new_st
.ext
.forall_iterator
= head
;
3998 m
= gfc_match_assignment ();
3999 if (m
== MATCH_ERROR
)
4003 m
= gfc_match_pointer_assignment ();
4004 if (m
== MATCH_ERROR
)
4010 c
= gfc_get_code ();
4012 c
->loc
= gfc_current_locus
;
4014 gfc_clear_new_st ();
4015 new_st
.op
= EXEC_FORALL
;
4017 new_st
.ext
.forall_iterator
= head
;
4018 new_st
.block
= gfc_get_code ();
4019 new_st
.block
->op
= EXEC_FORALL
;
4020 new_st
.block
->next
= c
;
4026 gfc_syntax_error (ST_FORALL
);
4029 gfc_free_forall_iterator (head
);
4030 gfc_free_expr (mask
);
4031 gfc_free_statements (c
);