1 /* Matching subroutines in all sizes, shapes and colors.
2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
31 #include "stringpool.h"
33 int gfc_matching_ptr_assignment
= 0;
34 int gfc_matching_procptr_assignment
= 0;
35 bool gfc_matching_prefix
= false;
37 /* Stack of SELECT TYPE statements. */
38 gfc_select_type_stack
*select_type_stack
= NULL
;
40 /* For debugging and diagnostic purposes. Return the textual representation
41 of the intrinsic operator OP. */
43 gfc_op2string (gfc_intrinsic_op op
)
51 case INTRINSIC_UMINUS
:
57 case INTRINSIC_CONCAT
:
61 case INTRINSIC_DIVIDE
:
100 case INTRINSIC_ASSIGN
:
103 case INTRINSIC_PARENTHESES
:
113 gfc_internal_error ("gfc_op2string(): Bad code");
118 /******************** Generic matching subroutines ************************/
120 /* This function scans the current statement counting the opened and closed
121 parenthesis to make sure they are balanced. */
124 gfc_match_parens (void)
126 locus old_loc
, where
;
128 gfc_instring instring
;
131 old_loc
= gfc_current_locus
;
133 instring
= NONSTRING
;
138 c
= gfc_next_char_literal (instring
);
141 if (quote
== ' ' && ((c
== '\'') || (c
== '"')))
144 instring
= INSTRING_WARN
;
147 if (quote
!= ' ' && c
== quote
)
150 instring
= NONSTRING
;
154 if (c
== '(' && quote
== ' ')
157 where
= gfc_current_locus
;
159 if (c
== ')' && quote
== ' ')
162 where
= gfc_current_locus
;
166 gfc_current_locus
= old_loc
;
170 gfc_error ("Missing %<)%> in statement at or before %L", &where
);
175 gfc_error ("Missing %<(%> in statement at or before %L", &where
);
183 /* See if the next character is a special character that has
184 escaped by a \ via the -fbackslash option. */
187 gfc_match_special_char (gfc_char_t
*res
)
195 switch ((c
= gfc_next_char_literal (INSTRING_WARN
)))
228 /* Hexadecimal form of wide characters. */
229 len
= (c
== 'x' ? 2 : (c
== 'u' ? 4 : 8));
231 for (i
= 0; i
< len
; i
++)
233 char buf
[2] = { '\0', '\0' };
235 c
= gfc_next_char_literal (INSTRING_WARN
);
236 if (!gfc_wide_fits_in_byte (c
)
237 || !gfc_check_digit ((unsigned char) c
, 16))
240 buf
[0] = (unsigned char) c
;
242 n
+= strtol (buf
, NULL
, 16);
248 /* Unknown backslash codes are simply not expanded. */
257 /* In free form, match at least one space. Always matches in fixed
261 gfc_match_space (void)
266 if (gfc_current_form
== FORM_FIXED
)
269 old_loc
= gfc_current_locus
;
271 c
= gfc_next_ascii_char ();
272 if (!gfc_is_whitespace (c
))
274 gfc_current_locus
= old_loc
;
278 gfc_gobble_whitespace ();
284 /* Match an end of statement. End of statement is optional
285 whitespace, followed by a ';' or '\n' or comment '!'. If a
286 semicolon is found, we continue to eat whitespace and semicolons. */
299 old_loc
= gfc_current_locus
;
300 gfc_gobble_whitespace ();
302 c
= gfc_next_ascii_char ();
308 c
= gfc_next_ascii_char ();
325 gfc_current_locus
= old_loc
;
326 return (flag
) ? MATCH_YES
: MATCH_NO
;
330 /* Match a literal integer on the input, setting the value on
331 MATCH_YES. Literal ints occur in kind-parameters as well as
332 old-style character length specifications. If cnt is non-NULL it
333 will be set to the number of digits. */
336 gfc_match_small_literal_int (int *value
, int *cnt
)
342 old_loc
= gfc_current_locus
;
345 gfc_gobble_whitespace ();
346 c
= gfc_next_ascii_char ();
352 gfc_current_locus
= old_loc
;
361 old_loc
= gfc_current_locus
;
362 c
= gfc_next_ascii_char ();
367 i
= 10 * i
+ c
- '0';
372 gfc_error ("Integer too large at %C");
377 gfc_current_locus
= old_loc
;
386 /* Match a small, constant integer expression, like in a kind
387 statement. On MATCH_YES, 'value' is set. */
390 gfc_match_small_int (int *value
)
397 m
= gfc_match_expr (&expr
);
401 p
= gfc_extract_int (expr
, &i
);
402 gfc_free_expr (expr
);
415 /* This function is the same as the gfc_match_small_int, except that
416 we're keeping the pointer to the expr. This function could just be
417 removed and the previously mentioned one modified, though all calls
418 to it would have to be modified then (and there were a number of
419 them). Return MATCH_ERROR if fail to extract the int; otherwise,
420 return the result of gfc_match_expr(). The expr (if any) that was
421 matched is returned in the parameter expr. */
424 gfc_match_small_int_expr (int *value
, gfc_expr
**expr
)
430 m
= gfc_match_expr (expr
);
434 p
= gfc_extract_int (*expr
, &i
);
447 /* Matches a statement label. Uses gfc_match_small_literal_int() to
448 do most of the work. */
451 gfc_match_st_label (gfc_st_label
**label
)
457 old_loc
= gfc_current_locus
;
459 m
= gfc_match_small_literal_int (&i
, &cnt
);
465 gfc_error ("Too many digits in statement label at %C");
471 gfc_error ("Statement label at %C is zero");
475 *label
= gfc_get_st_label (i
);
480 gfc_current_locus
= old_loc
;
485 /* Match and validate a label associated with a named IF, DO or SELECT
486 statement. If the symbol does not have the label attribute, we add
487 it. We also make sure the symbol does not refer to another
488 (active) block. A matched label is pointed to by gfc_new_block. */
491 gfc_match_label (void)
493 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
496 gfc_new_block
= NULL
;
498 m
= gfc_match (" %n :", name
);
502 if (gfc_get_symbol (name
, NULL
, &gfc_new_block
))
504 gfc_error ("Label name %qs at %C is ambiguous", name
);
508 if (gfc_new_block
->attr
.flavor
== FL_LABEL
)
510 gfc_error ("Duplicate construct label %qs at %C", name
);
514 if (!gfc_add_flavor (&gfc_new_block
->attr
, FL_LABEL
,
515 gfc_new_block
->name
, NULL
))
522 /* See if the current input looks like a name of some sort. Modifies
523 the passed buffer which must be GFC_MAX_SYMBOL_LEN+1 bytes long.
524 Note that options.c restricts max_identifier_length to not more
525 than GFC_MAX_SYMBOL_LEN. */
528 gfc_match_name (char *buffer
)
534 old_loc
= gfc_current_locus
;
535 gfc_gobble_whitespace ();
537 c
= gfc_next_ascii_char ();
538 if (!(ISALPHA (c
) || (c
== '_' && flag_allow_leading_underscore
)))
540 /* Special cases for unary minus and plus, which allows for a sensible
541 error message for code of the form 'c = exp(-a*b) )' where an
542 extra ')' appears at the end of statement. */
543 if (!gfc_error_flag_test () && c
!= '(' && c
!= '-' && c
!= '+')
544 gfc_error ("Invalid character in name at %C");
545 gfc_current_locus
= old_loc
;
555 if (i
> gfc_option
.max_identifier_length
)
557 gfc_error ("Name at %C is too long");
561 old_loc
= gfc_current_locus
;
562 c
= gfc_next_ascii_char ();
564 while (ISALNUM (c
) || c
== '_' || (flag_dollar_ok
&& c
== '$'));
566 if (c
== '$' && !flag_dollar_ok
)
568 gfc_fatal_error ("Invalid character %<$%> at %L. Use %<-fdollar-ok%> to "
569 "allow it as an extension", &old_loc
);
574 gfc_current_locus
= old_loc
;
580 /* Match a symbol on the input. Modifies the pointer to the symbol
581 pointer if successful. */
584 gfc_match_sym_tree (gfc_symtree
**matched_symbol
, int host_assoc
)
586 char buffer
[GFC_MAX_SYMBOL_LEN
+ 1];
589 m
= gfc_match_name (buffer
);
594 return (gfc_get_ha_sym_tree (buffer
, matched_symbol
))
595 ? MATCH_ERROR
: MATCH_YES
;
597 if (gfc_get_sym_tree (buffer
, NULL
, matched_symbol
, false))
605 gfc_match_symbol (gfc_symbol
**matched_symbol
, int host_assoc
)
610 m
= gfc_match_sym_tree (&st
, host_assoc
);
615 *matched_symbol
= st
->n
.sym
;
617 *matched_symbol
= NULL
;
620 *matched_symbol
= NULL
;
625 /* Match an intrinsic operator. Returns an INTRINSIC enum. While matching,
626 we always find INTRINSIC_PLUS before INTRINSIC_UPLUS. We work around this
630 gfc_match_intrinsic_op (gfc_intrinsic_op
*result
)
632 locus orig_loc
= gfc_current_locus
;
635 gfc_gobble_whitespace ();
636 ch
= gfc_next_ascii_char ();
641 *result
= INTRINSIC_PLUS
;
646 *result
= INTRINSIC_MINUS
;
650 if (gfc_next_ascii_char () == '=')
653 *result
= INTRINSIC_EQ
;
659 if (gfc_peek_ascii_char () == '=')
662 gfc_next_ascii_char ();
663 *result
= INTRINSIC_LE
;
667 *result
= INTRINSIC_LT
;
671 if (gfc_peek_ascii_char () == '=')
674 gfc_next_ascii_char ();
675 *result
= INTRINSIC_GE
;
679 *result
= INTRINSIC_GT
;
683 if (gfc_peek_ascii_char () == '*')
686 gfc_next_ascii_char ();
687 *result
= INTRINSIC_POWER
;
691 *result
= INTRINSIC_TIMES
;
695 ch
= gfc_peek_ascii_char ();
699 gfc_next_ascii_char ();
700 *result
= INTRINSIC_NE
;
706 gfc_next_ascii_char ();
707 *result
= INTRINSIC_CONCAT
;
711 *result
= INTRINSIC_DIVIDE
;
715 ch
= gfc_next_ascii_char ();
719 if (gfc_next_ascii_char () == 'n'
720 && gfc_next_ascii_char () == 'd'
721 && gfc_next_ascii_char () == '.')
723 /* Matched ".and.". */
724 *result
= INTRINSIC_AND
;
730 if (gfc_next_ascii_char () == 'q')
732 ch
= gfc_next_ascii_char ();
735 /* Matched ".eq.". */
736 *result
= INTRINSIC_EQ_OS
;
741 if (gfc_next_ascii_char () == '.')
743 /* Matched ".eqv.". */
744 *result
= INTRINSIC_EQV
;
752 ch
= gfc_next_ascii_char ();
755 if (gfc_next_ascii_char () == '.')
757 /* Matched ".ge.". */
758 *result
= INTRINSIC_GE_OS
;
764 if (gfc_next_ascii_char () == '.')
766 /* Matched ".gt.". */
767 *result
= INTRINSIC_GT_OS
;
774 ch
= gfc_next_ascii_char ();
777 if (gfc_next_ascii_char () == '.')
779 /* Matched ".le.". */
780 *result
= INTRINSIC_LE_OS
;
786 if (gfc_next_ascii_char () == '.')
788 /* Matched ".lt.". */
789 *result
= INTRINSIC_LT_OS
;
796 ch
= gfc_next_ascii_char ();
799 ch
= gfc_next_ascii_char ();
802 /* Matched ".ne.". */
803 *result
= INTRINSIC_NE_OS
;
808 if (gfc_next_ascii_char () == 'v'
809 && gfc_next_ascii_char () == '.')
811 /* Matched ".neqv.". */
812 *result
= INTRINSIC_NEQV
;
819 if (gfc_next_ascii_char () == 't'
820 && gfc_next_ascii_char () == '.')
822 /* Matched ".not.". */
823 *result
= INTRINSIC_NOT
;
830 if (gfc_next_ascii_char () == 'r'
831 && gfc_next_ascii_char () == '.')
833 /* Matched ".or.". */
834 *result
= INTRINSIC_OR
;
848 gfc_current_locus
= orig_loc
;
853 /* Match a loop control phrase:
855 <LVALUE> = <EXPR>, <EXPR> [, <EXPR> ]
857 If the final integer expression is not present, a constant unity
858 expression is returned. We don't return MATCH_ERROR until after
859 the equals sign is seen. */
862 gfc_match_iterator (gfc_iterator
*iter
, int init_flag
)
864 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
865 gfc_expr
*var
, *e1
, *e2
, *e3
;
871 /* Match the start of an iterator without affecting the symbol table. */
873 start
= gfc_current_locus
;
874 m
= gfc_match (" %n =", name
);
875 gfc_current_locus
= start
;
880 m
= gfc_match_variable (&var
, 0);
884 /* F2008, C617 & C565. */
885 if (var
->symtree
->n
.sym
->attr
.codimension
)
887 gfc_error ("Loop variable at %C cannot be a coarray");
891 if (var
->ref
!= NULL
)
893 gfc_error ("Loop variable at %C cannot be a sub-component");
897 gfc_match_char ('=');
899 var
->symtree
->n
.sym
->attr
.implied_index
= 1;
901 m
= init_flag
? gfc_match_init_expr (&e1
) : gfc_match_expr (&e1
);
904 if (m
== MATCH_ERROR
)
907 if (gfc_match_char (',') != MATCH_YES
)
910 m
= init_flag
? gfc_match_init_expr (&e2
) : gfc_match_expr (&e2
);
913 if (m
== MATCH_ERROR
)
916 if (gfc_match_char (',') != MATCH_YES
)
918 e3
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
922 m
= init_flag
? gfc_match_init_expr (&e3
) : gfc_match_expr (&e3
);
923 if (m
== MATCH_ERROR
)
927 gfc_error ("Expected a step value in iterator at %C");
939 gfc_error ("Syntax error in iterator at %C");
950 /* Tries to match the next non-whitespace character on the input.
951 This subroutine does not return MATCH_ERROR. */
954 gfc_match_char (char c
)
958 where
= gfc_current_locus
;
959 gfc_gobble_whitespace ();
961 if (gfc_next_ascii_char () == c
)
964 gfc_current_locus
= where
;
969 /* General purpose matching subroutine. The target string is a
970 scanf-like format string in which spaces correspond to arbitrary
971 whitespace (including no whitespace), characters correspond to
972 themselves. The %-codes are:
974 %% Literal percent sign
975 %e Expression, pointer to a pointer is set
976 %s Symbol, pointer to the symbol is set
977 %n Name, character buffer is set to name
978 %t Matches end of statement.
979 %o Matches an intrinsic operator, returned as an INTRINSIC enum.
980 %l Matches a statement label
981 %v Matches a variable expression (an lvalue)
982 % Matches a required space (in free form) and optional spaces. */
985 gfc_match (const char *target
, ...)
987 gfc_st_label
**label
;
996 old_loc
= gfc_current_locus
;
997 va_start (argp
, target
);
1007 gfc_gobble_whitespace ();
1018 vp
= va_arg (argp
, void **);
1019 n
= gfc_match_expr ((gfc_expr
**) vp
);
1030 vp
= va_arg (argp
, void **);
1031 n
= gfc_match_variable ((gfc_expr
**) vp
, 0);
1042 vp
= va_arg (argp
, void **);
1043 n
= gfc_match_symbol ((gfc_symbol
**) vp
, 0);
1054 np
= va_arg (argp
, char *);
1055 n
= gfc_match_name (np
);
1066 label
= va_arg (argp
, gfc_st_label
**);
1067 n
= gfc_match_st_label (label
);
1078 ip
= va_arg (argp
, int *);
1079 n
= gfc_match_intrinsic_op ((gfc_intrinsic_op
*) ip
);
1090 if (gfc_match_eos () != MATCH_YES
)
1098 if (gfc_match_space () == MATCH_YES
)
1104 break; /* Fall through to character matcher. */
1107 gfc_internal_error ("gfc_match(): Bad match code %c", c
);
1112 /* gfc_next_ascii_char converts characters to lower-case, so we shouldn't
1113 expect an upper case character here! */
1114 gcc_assert (TOLOWER (c
) == c
);
1116 if (c
== gfc_next_ascii_char ())
1126 /* Clean up after a failed match. */
1127 gfc_current_locus
= old_loc
;
1128 va_start (argp
, target
);
1131 for (; matches
> 0; matches
--)
1133 while (*p
++ != '%');
1141 /* Matches that don't have to be undone */
1146 (void) va_arg (argp
, void **);
1151 vp
= va_arg (argp
, void **);
1152 gfc_free_expr ((struct gfc_expr
*)*vp
);
1165 /*********************** Statement level matching **********************/
1167 /* Matches the start of a program unit, which is the program keyword
1168 followed by an obligatory symbol. */
1171 gfc_match_program (void)
1176 m
= gfc_match ("% %s%t", &sym
);
1180 gfc_error ("Invalid form of PROGRAM statement at %C");
1184 if (m
== MATCH_ERROR
)
1187 if (!gfc_add_flavor (&sym
->attr
, FL_PROGRAM
, sym
->name
, NULL
))
1190 gfc_new_block
= sym
;
1196 /* Match a simple assignment statement. */
1199 gfc_match_assignment (void)
1201 gfc_expr
*lvalue
, *rvalue
;
1205 old_loc
= gfc_current_locus
;
1208 m
= gfc_match (" %v =", &lvalue
);
1211 gfc_current_locus
= old_loc
;
1212 gfc_free_expr (lvalue
);
1217 m
= gfc_match (" %e%t", &rvalue
);
1220 gfc_current_locus
= old_loc
;
1221 gfc_free_expr (lvalue
);
1222 gfc_free_expr (rvalue
);
1226 gfc_set_sym_referenced (lvalue
->symtree
->n
.sym
);
1228 new_st
.op
= EXEC_ASSIGN
;
1229 new_st
.expr1
= lvalue
;
1230 new_st
.expr2
= rvalue
;
1232 gfc_check_do_variable (lvalue
->symtree
);
1238 /* Match a pointer assignment statement. */
1241 gfc_match_pointer_assignment (void)
1243 gfc_expr
*lvalue
, *rvalue
;
1247 old_loc
= gfc_current_locus
;
1249 lvalue
= rvalue
= NULL
;
1250 gfc_matching_ptr_assignment
= 0;
1251 gfc_matching_procptr_assignment
= 0;
1253 m
= gfc_match (" %v =>", &lvalue
);
1260 if (lvalue
->symtree
->n
.sym
->attr
.proc_pointer
1261 || gfc_is_proc_ptr_comp (lvalue
))
1262 gfc_matching_procptr_assignment
= 1;
1264 gfc_matching_ptr_assignment
= 1;
1266 m
= gfc_match (" %e%t", &rvalue
);
1267 gfc_matching_ptr_assignment
= 0;
1268 gfc_matching_procptr_assignment
= 0;
1272 new_st
.op
= EXEC_POINTER_ASSIGN
;
1273 new_st
.expr1
= lvalue
;
1274 new_st
.expr2
= rvalue
;
1279 gfc_current_locus
= old_loc
;
1280 gfc_free_expr (lvalue
);
1281 gfc_free_expr (rvalue
);
1286 /* We try to match an easy arithmetic IF statement. This only happens
1287 when just after having encountered a simple IF statement. This code
1288 is really duplicate with parts of the gfc_match_if code, but this is
1292 match_arithmetic_if (void)
1294 gfc_st_label
*l1
, *l2
, *l3
;
1298 m
= gfc_match (" ( %e ) %l , %l , %l%t", &expr
, &l1
, &l2
, &l3
);
1302 if (!gfc_reference_st_label (l1
, ST_LABEL_TARGET
)
1303 || !gfc_reference_st_label (l2
, ST_LABEL_TARGET
)
1304 || !gfc_reference_st_label (l3
, ST_LABEL_TARGET
))
1306 gfc_free_expr (expr
);
1310 if (!gfc_notify_std (GFC_STD_F95_OBS
, "Arithmetic IF statement at %C"))
1313 new_st
.op
= EXEC_ARITHMETIC_IF
;
1314 new_st
.expr1
= expr
;
1323 /* The IF statement is a bit of a pain. First of all, there are three
1324 forms of it, the simple IF, the IF that starts a block and the
1327 There is a problem with the simple IF and that is the fact that we
1328 only have a single level of undo information on symbols. What this
1329 means is for a simple IF, we must re-match the whole IF statement
1330 multiple times in order to guarantee that the symbol table ends up
1331 in the proper state. */
1333 static match
match_simple_forall (void);
1334 static match
match_simple_where (void);
1337 gfc_match_if (gfc_statement
*if_type
)
1340 gfc_st_label
*l1
, *l2
, *l3
;
1341 locus old_loc
, old_loc2
;
1345 n
= gfc_match_label ();
1346 if (n
== MATCH_ERROR
)
1349 old_loc
= gfc_current_locus
;
1351 m
= gfc_match (" if ( %e", &expr
);
1355 old_loc2
= gfc_current_locus
;
1356 gfc_current_locus
= old_loc
;
1358 if (gfc_match_parens () == MATCH_ERROR
)
1361 gfc_current_locus
= old_loc2
;
1363 if (gfc_match_char (')') != MATCH_YES
)
1365 gfc_error ("Syntax error in IF-expression at %C");
1366 gfc_free_expr (expr
);
1370 m
= gfc_match (" %l , %l , %l%t", &l1
, &l2
, &l3
);
1376 gfc_error ("Block label not appropriate for arithmetic IF "
1378 gfc_free_expr (expr
);
1382 if (!gfc_reference_st_label (l1
, ST_LABEL_TARGET
)
1383 || !gfc_reference_st_label (l2
, ST_LABEL_TARGET
)
1384 || !gfc_reference_st_label (l3
, ST_LABEL_TARGET
))
1386 gfc_free_expr (expr
);
1390 if (!gfc_notify_std (GFC_STD_F95_OBS
, "Arithmetic IF statement at %C"))
1393 new_st
.op
= EXEC_ARITHMETIC_IF
;
1394 new_st
.expr1
= expr
;
1399 *if_type
= ST_ARITHMETIC_IF
;
1403 if (gfc_match (" then%t") == MATCH_YES
)
1405 new_st
.op
= EXEC_IF
;
1406 new_st
.expr1
= expr
;
1407 *if_type
= ST_IF_BLOCK
;
1413 gfc_error ("Block label is not appropriate for IF statement at %C");
1414 gfc_free_expr (expr
);
1418 /* At this point the only thing left is a simple IF statement. At
1419 this point, n has to be MATCH_NO, so we don't have to worry about
1420 re-matching a block label. From what we've got so far, try
1421 matching an assignment. */
1423 *if_type
= ST_SIMPLE_IF
;
1425 m
= gfc_match_assignment ();
1429 gfc_free_expr (expr
);
1430 gfc_undo_symbols ();
1431 gfc_current_locus
= old_loc
;
1433 /* m can be MATCH_NO or MATCH_ERROR, here. For MATCH_ERROR, a mangled
1434 assignment was found. For MATCH_NO, continue to call the various
1436 if (m
== MATCH_ERROR
)
1439 gfc_match (" if ( %e ) ", &expr
); /* Guaranteed to match. */
1441 m
= gfc_match_pointer_assignment ();
1445 gfc_free_expr (expr
);
1446 gfc_undo_symbols ();
1447 gfc_current_locus
= old_loc
;
1449 gfc_match (" if ( %e ) ", &expr
); /* Guaranteed to match. */
1451 /* Look at the next keyword to see which matcher to call. Matching
1452 the keyword doesn't affect the symbol table, so we don't have to
1453 restore between tries. */
1455 #define match(string, subr, statement) \
1456 if (gfc_match (string) == MATCH_YES) { m = subr(); goto got_match; }
1460 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
)
1461 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
)
1462 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
)
1463 match ("call", gfc_match_call
, ST_CALL
)
1464 match ("close", gfc_match_close
, ST_CLOSE
)
1465 match ("continue", gfc_match_continue
, ST_CONTINUE
)
1466 match ("cycle", gfc_match_cycle
, ST_CYCLE
)
1467 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
)
1468 match ("end file", gfc_match_endfile
, ST_END_FILE
)
1469 match ("error stop", gfc_match_error_stop
, ST_ERROR_STOP
)
1470 match ("exit", gfc_match_exit
, ST_EXIT
)
1471 match ("flush", gfc_match_flush
, ST_FLUSH
)
1472 match ("forall", match_simple_forall
, ST_FORALL
)
1473 match ("go to", gfc_match_goto
, ST_GOTO
)
1474 match ("if", match_arithmetic_if
, ST_ARITHMETIC_IF
)
1475 match ("inquire", gfc_match_inquire
, ST_INQUIRE
)
1476 match ("lock", gfc_match_lock
, ST_LOCK
)
1477 match ("nullify", gfc_match_nullify
, ST_NULLIFY
)
1478 match ("open", gfc_match_open
, ST_OPEN
)
1479 match ("pause", gfc_match_pause
, ST_NONE
)
1480 match ("print", gfc_match_print
, ST_WRITE
)
1481 match ("read", gfc_match_read
, ST_READ
)
1482 match ("return", gfc_match_return
, ST_RETURN
)
1483 match ("rewind", gfc_match_rewind
, ST_REWIND
)
1484 match ("stop", gfc_match_stop
, ST_STOP
)
1485 match ("wait", gfc_match_wait
, ST_WAIT
)
1486 match ("sync all", gfc_match_sync_all
, ST_SYNC_CALL
);
1487 match ("sync images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
1488 match ("sync memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
1489 match ("unlock", gfc_match_unlock
, ST_UNLOCK
)
1490 match ("where", match_simple_where
, ST_WHERE
)
1491 match ("write", gfc_match_write
, ST_WRITE
)
1493 /* The gfc_match_assignment() above may have returned a MATCH_NO
1494 where the assignment was to a named constant. Check that
1495 special case here. */
1496 m
= gfc_match_assignment ();
1499 gfc_error ("Cannot assign to a named constant at %C");
1500 gfc_free_expr (expr
);
1501 gfc_undo_symbols ();
1502 gfc_current_locus
= old_loc
;
1506 /* All else has failed, so give up. See if any of the matchers has
1507 stored an error message of some sort. */
1508 if (!gfc_error_check ())
1509 gfc_error ("Unclassifiable statement in IF-clause at %C");
1511 gfc_free_expr (expr
);
1516 gfc_error ("Syntax error in IF-clause at %C");
1519 gfc_free_expr (expr
);
1523 /* At this point, we've matched the single IF and the action clause
1524 is in new_st. Rearrange things so that the IF statement appears
1527 p
= gfc_get_code (EXEC_IF
);
1528 p
->next
= XCNEW (gfc_code
);
1530 p
->next
->loc
= gfc_current_locus
;
1534 gfc_clear_new_st ();
1536 new_st
.op
= EXEC_IF
;
1545 /* Match an ELSE statement. */
1548 gfc_match_else (void)
1550 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
1552 if (gfc_match_eos () == MATCH_YES
)
1555 if (gfc_match_name (name
) != MATCH_YES
1556 || gfc_current_block () == NULL
1557 || gfc_match_eos () != MATCH_YES
)
1559 gfc_error ("Unexpected junk after ELSE statement at %C");
1563 if (strcmp (name
, gfc_current_block ()->name
) != 0)
1565 gfc_error ("Label %qs at %C doesn't match IF label %qs",
1566 name
, gfc_current_block ()->name
);
1574 /* Match an ELSE IF statement. */
1577 gfc_match_elseif (void)
1579 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
1583 m
= gfc_match (" ( %e ) then", &expr
);
1587 if (gfc_match_eos () == MATCH_YES
)
1590 if (gfc_match_name (name
) != MATCH_YES
1591 || gfc_current_block () == NULL
1592 || gfc_match_eos () != MATCH_YES
)
1594 gfc_error ("Unexpected junk after ELSE IF statement at %C");
1598 if (strcmp (name
, gfc_current_block ()->name
) != 0)
1600 gfc_error ("Label %qs at %C doesn't match IF label %qs",
1601 name
, gfc_current_block ()->name
);
1606 new_st
.op
= EXEC_IF
;
1607 new_st
.expr1
= expr
;
1611 gfc_free_expr (expr
);
1616 /* Free a gfc_iterator structure. */
1619 gfc_free_iterator (gfc_iterator
*iter
, int flag
)
1625 gfc_free_expr (iter
->var
);
1626 gfc_free_expr (iter
->start
);
1627 gfc_free_expr (iter
->end
);
1628 gfc_free_expr (iter
->step
);
1635 /* Match a CRITICAL statement. */
1637 gfc_match_critical (void)
1639 gfc_st_label
*label
= NULL
;
1641 if (gfc_match_label () == MATCH_ERROR
)
1644 if (gfc_match (" critical") != MATCH_YES
)
1647 if (gfc_match_st_label (&label
) == MATCH_ERROR
)
1650 if (gfc_match_eos () != MATCH_YES
)
1652 gfc_syntax_error (ST_CRITICAL
);
1656 if (gfc_pure (NULL
))
1658 gfc_error ("Image control statement CRITICAL at %C in PURE procedure");
1662 if (gfc_find_state (COMP_DO_CONCURRENT
))
1664 gfc_error ("Image control statement CRITICAL at %C in DO CONCURRENT "
1669 gfc_unset_implicit_pure (NULL
);
1671 if (!gfc_notify_std (GFC_STD_F2008
, "CRITICAL statement at %C"))
1674 if (flag_coarray
== GFC_FCOARRAY_NONE
)
1676 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to "
1681 if (gfc_find_state (COMP_CRITICAL
))
1683 gfc_error ("Nested CRITICAL block at %C");
1687 new_st
.op
= EXEC_CRITICAL
;
1690 && !gfc_reference_st_label (label
, ST_LABEL_TARGET
))
1697 /* Match a BLOCK statement. */
1700 gfc_match_block (void)
1704 if (gfc_match_label () == MATCH_ERROR
)
1707 if (gfc_match (" block") != MATCH_YES
)
1710 /* For this to be a correct BLOCK statement, the line must end now. */
1711 m
= gfc_match_eos ();
1712 if (m
== MATCH_ERROR
)
1721 /* Match an ASSOCIATE statement. */
1724 gfc_match_associate (void)
1726 if (gfc_match_label () == MATCH_ERROR
)
1729 if (gfc_match (" associate") != MATCH_YES
)
1732 /* Match the association list. */
1733 if (gfc_match_char ('(') != MATCH_YES
)
1735 gfc_error ("Expected association list at %C");
1738 new_st
.ext
.block
.assoc
= NULL
;
1741 gfc_association_list
* newAssoc
= gfc_get_association_list ();
1742 gfc_association_list
* a
;
1744 /* Match the next association. */
1745 if (gfc_match (" %n => %e", newAssoc
->name
, &newAssoc
->target
)
1748 gfc_error ("Expected association at %C");
1749 goto assocListError
;
1751 newAssoc
->where
= gfc_current_locus
;
1753 /* Check that the current name is not yet in the list. */
1754 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
1755 if (!strcmp (a
->name
, newAssoc
->name
))
1757 gfc_error ("Duplicate name %qs in association at %C",
1759 goto assocListError
;
1762 /* The target expression must not be coindexed. */
1763 if (gfc_is_coindexed (newAssoc
->target
))
1765 gfc_error ("Association target at %C must not be coindexed");
1766 goto assocListError
;
1769 /* The `variable' field is left blank for now; because the target is not
1770 yet resolved, we can't use gfc_has_vector_subscript to determine it
1771 for now. This is set during resolution. */
1773 /* Put it into the list. */
1774 newAssoc
->next
= new_st
.ext
.block
.assoc
;
1775 new_st
.ext
.block
.assoc
= newAssoc
;
1777 /* Try next one or end if closing parenthesis is found. */
1778 gfc_gobble_whitespace ();
1779 if (gfc_peek_char () == ')')
1781 if (gfc_match_char (',') != MATCH_YES
)
1783 gfc_error ("Expected %<)%> or %<,%> at %C");
1793 if (gfc_match_char (')') != MATCH_YES
)
1795 /* This should never happen as we peek above. */
1799 if (gfc_match_eos () != MATCH_YES
)
1801 gfc_error ("Junk after ASSOCIATE statement at %C");
1808 gfc_free_association_list (new_st
.ext
.block
.assoc
);
1813 /* Match a Fortran 2003 derived-type-spec (F03:R455), which is just the name of
1814 an accessible derived type. */
1817 match_derived_type_spec (gfc_typespec
*ts
)
1819 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
1821 gfc_symbol
*derived
;
1823 old_locus
= gfc_current_locus
;
1825 if (gfc_match ("%n", name
) != MATCH_YES
)
1827 gfc_current_locus
= old_locus
;
1831 gfc_find_symbol (name
, NULL
, 1, &derived
);
1833 if (derived
&& derived
->attr
.flavor
== FL_PROCEDURE
&& derived
->attr
.generic
)
1834 derived
= gfc_find_dt_in_generic (derived
);
1836 if (derived
&& derived
->attr
.flavor
== FL_DERIVED
)
1838 ts
->type
= BT_DERIVED
;
1839 ts
->u
.derived
= derived
;
1843 gfc_current_locus
= old_locus
;
1848 /* Match a Fortran 2003 type-spec (F03:R401). This is similar to
1849 gfc_match_decl_type_spec() from decl.c, with the following exceptions:
1850 It only includes the intrinsic types from the Fortran 2003 standard
1851 (thus, neither BYTE nor forms like REAL*4 are allowed). Additionally,
1852 the implicit_flag is not needed, so it was removed. Derived types are
1853 identified by their name alone. */
1856 gfc_match_type_spec (gfc_typespec
*ts
)
1862 gfc_gobble_whitespace ();
1863 old_locus
= gfc_current_locus
;
1865 if (match_derived_type_spec (ts
) == MATCH_YES
)
1867 /* Enforce F03:C401. */
1868 if (ts
->u
.derived
->attr
.abstract
)
1870 gfc_error ("Derived type %qs at %L may not be ABSTRACT",
1871 ts
->u
.derived
->name
, &old_locus
);
1877 if (gfc_match ("integer") == MATCH_YES
)
1879 ts
->type
= BT_INTEGER
;
1880 ts
->kind
= gfc_default_integer_kind
;
1884 if (gfc_match ("real") == MATCH_YES
)
1887 ts
->kind
= gfc_default_real_kind
;
1891 if (gfc_match ("double precision") == MATCH_YES
)
1894 ts
->kind
= gfc_default_double_kind
;
1898 if (gfc_match ("complex") == MATCH_YES
)
1900 ts
->type
= BT_COMPLEX
;
1901 ts
->kind
= gfc_default_complex_kind
;
1905 if (gfc_match ("character") == MATCH_YES
)
1907 ts
->type
= BT_CHARACTER
;
1909 m
= gfc_match_char_spec (ts
);
1917 if (gfc_match ("logical") == MATCH_YES
)
1919 ts
->type
= BT_LOGICAL
;
1920 ts
->kind
= gfc_default_logical_kind
;
1924 /* If a type is not matched, simply return MATCH_NO. */
1925 gfc_current_locus
= old_locus
;
1930 gfc_gobble_whitespace ();
1931 if (gfc_peek_ascii_char () == '*')
1933 gfc_error ("Invalid type-spec at %C");
1937 m
= gfc_match_kind_spec (ts
, false);
1940 m
= MATCH_YES
; /* No kind specifier found. */
1946 /******************** FORALL subroutines ********************/
1948 /* Free a list of FORALL iterators. */
1951 gfc_free_forall_iterator (gfc_forall_iterator
*iter
)
1953 gfc_forall_iterator
*next
;
1958 gfc_free_expr (iter
->var
);
1959 gfc_free_expr (iter
->start
);
1960 gfc_free_expr (iter
->end
);
1961 gfc_free_expr (iter
->stride
);
1968 /* Match an iterator as part of a FORALL statement. The format is:
1970 <var> = <start>:<end>[:<stride>]
1972 On MATCH_NO, the caller tests for the possibility that there is a
1973 scalar mask expression. */
1976 match_forall_iterator (gfc_forall_iterator
**result
)
1978 gfc_forall_iterator
*iter
;
1982 where
= gfc_current_locus
;
1983 iter
= XCNEW (gfc_forall_iterator
);
1985 m
= gfc_match_expr (&iter
->var
);
1989 if (gfc_match_char ('=') != MATCH_YES
1990 || iter
->var
->expr_type
!= EXPR_VARIABLE
)
1996 m
= gfc_match_expr (&iter
->start
);
2000 if (gfc_match_char (':') != MATCH_YES
)
2003 m
= gfc_match_expr (&iter
->end
);
2006 if (m
== MATCH_ERROR
)
2009 if (gfc_match_char (':') == MATCH_NO
)
2010 iter
->stride
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
2013 m
= gfc_match_expr (&iter
->stride
);
2016 if (m
== MATCH_ERROR
)
2020 /* Mark the iteration variable's symbol as used as a FORALL index. */
2021 iter
->var
->symtree
->n
.sym
->forall_index
= true;
2027 gfc_error ("Syntax error in FORALL iterator at %C");
2032 gfc_current_locus
= where
;
2033 gfc_free_forall_iterator (iter
);
2038 /* Match the header of a FORALL statement. */
2041 match_forall_header (gfc_forall_iterator
**phead
, gfc_expr
**mask
)
2043 gfc_forall_iterator
*head
, *tail
, *new_iter
;
2047 gfc_gobble_whitespace ();
2052 if (gfc_match_char ('(') != MATCH_YES
)
2055 m
= match_forall_iterator (&new_iter
);
2056 if (m
== MATCH_ERROR
)
2061 head
= tail
= new_iter
;
2065 if (gfc_match_char (',') != MATCH_YES
)
2068 m
= match_forall_iterator (&new_iter
);
2069 if (m
== MATCH_ERROR
)
2074 tail
->next
= new_iter
;
2079 /* Have to have a mask expression. */
2081 m
= gfc_match_expr (&msk
);
2084 if (m
== MATCH_ERROR
)
2090 if (gfc_match_char (')') == MATCH_NO
)
2098 gfc_syntax_error (ST_FORALL
);
2101 gfc_free_expr (msk
);
2102 gfc_free_forall_iterator (head
);
2107 /* Match the rest of a simple FORALL statement that follows an
2111 match_simple_forall (void)
2113 gfc_forall_iterator
*head
;
2122 m
= match_forall_header (&head
, &mask
);
2129 m
= gfc_match_assignment ();
2131 if (m
== MATCH_ERROR
)
2135 m
= gfc_match_pointer_assignment ();
2136 if (m
== MATCH_ERROR
)
2142 c
= XCNEW (gfc_code
);
2144 c
->loc
= gfc_current_locus
;
2146 if (gfc_match_eos () != MATCH_YES
)
2149 gfc_clear_new_st ();
2150 new_st
.op
= EXEC_FORALL
;
2151 new_st
.expr1
= mask
;
2152 new_st
.ext
.forall_iterator
= head
;
2153 new_st
.block
= gfc_get_code (EXEC_FORALL
);
2154 new_st
.block
->next
= c
;
2159 gfc_syntax_error (ST_FORALL
);
2162 gfc_free_forall_iterator (head
);
2163 gfc_free_expr (mask
);
2169 /* Match a FORALL statement. */
2172 gfc_match_forall (gfc_statement
*st
)
2174 gfc_forall_iterator
*head
;
2183 m0
= gfc_match_label ();
2184 if (m0
== MATCH_ERROR
)
2187 m
= gfc_match (" forall");
2191 m
= match_forall_header (&head
, &mask
);
2192 if (m
== MATCH_ERROR
)
2197 if (gfc_match_eos () == MATCH_YES
)
2199 *st
= ST_FORALL_BLOCK
;
2200 new_st
.op
= EXEC_FORALL
;
2201 new_st
.expr1
= mask
;
2202 new_st
.ext
.forall_iterator
= head
;
2206 m
= gfc_match_assignment ();
2207 if (m
== MATCH_ERROR
)
2211 m
= gfc_match_pointer_assignment ();
2212 if (m
== MATCH_ERROR
)
2218 c
= XCNEW (gfc_code
);
2220 c
->loc
= gfc_current_locus
;
2222 gfc_clear_new_st ();
2223 new_st
.op
= EXEC_FORALL
;
2224 new_st
.expr1
= mask
;
2225 new_st
.ext
.forall_iterator
= head
;
2226 new_st
.block
= gfc_get_code (EXEC_FORALL
);
2227 new_st
.block
->next
= c
;
2233 gfc_syntax_error (ST_FORALL
);
2236 gfc_free_forall_iterator (head
);
2237 gfc_free_expr (mask
);
2238 gfc_free_statements (c
);
2243 /* Match a DO statement. */
2248 gfc_iterator iter
, *ip
;
2250 gfc_st_label
*label
;
2253 old_loc
= gfc_current_locus
;
2256 iter
.var
= iter
.start
= iter
.end
= iter
.step
= NULL
;
2258 m
= gfc_match_label ();
2259 if (m
== MATCH_ERROR
)
2262 if (gfc_match (" do") != MATCH_YES
)
2265 m
= gfc_match_st_label (&label
);
2266 if (m
== MATCH_ERROR
)
2269 /* Match an infinite DO, make it like a DO WHILE(.TRUE.). */
2271 if (gfc_match_eos () == MATCH_YES
)
2273 iter
.end
= gfc_get_logical_expr (gfc_default_logical_kind
, NULL
, true);
2274 new_st
.op
= EXEC_DO_WHILE
;
2278 /* Match an optional comma, if no comma is found, a space is obligatory. */
2279 if (gfc_match_char (',') != MATCH_YES
&& gfc_match ("% ") != MATCH_YES
)
2282 /* Check for balanced parens. */
2284 if (gfc_match_parens () == MATCH_ERROR
)
2287 if (gfc_match (" concurrent") == MATCH_YES
)
2289 gfc_forall_iterator
*head
;
2292 if (!gfc_notify_std (GFC_STD_F2008
, "DO CONCURRENT construct at %C"))
2298 m
= match_forall_header (&head
, &mask
);
2302 if (m
== MATCH_ERROR
)
2303 goto concurr_cleanup
;
2305 if (gfc_match_eos () != MATCH_YES
)
2306 goto concurr_cleanup
;
2309 && !gfc_reference_st_label (label
, ST_LABEL_DO_TARGET
))
2310 goto concurr_cleanup
;
2312 new_st
.label1
= label
;
2313 new_st
.op
= EXEC_DO_CONCURRENT
;
2314 new_st
.expr1
= mask
;
2315 new_st
.ext
.forall_iterator
= head
;
2320 gfc_syntax_error (ST_DO
);
2321 gfc_free_expr (mask
);
2322 gfc_free_forall_iterator (head
);
2326 /* See if we have a DO WHILE. */
2327 if (gfc_match (" while ( %e )%t", &iter
.end
) == MATCH_YES
)
2329 new_st
.op
= EXEC_DO_WHILE
;
2333 /* The abortive DO WHILE may have done something to the symbol
2334 table, so we start over. */
2335 gfc_undo_symbols ();
2336 gfc_current_locus
= old_loc
;
2338 gfc_match_label (); /* This won't error. */
2339 gfc_match (" do "); /* This will work. */
2341 gfc_match_st_label (&label
); /* Can't error out. */
2342 gfc_match_char (','); /* Optional comma. */
2344 m
= gfc_match_iterator (&iter
, 0);
2347 if (m
== MATCH_ERROR
)
2350 iter
.var
->symtree
->n
.sym
->attr
.implied_index
= 0;
2351 gfc_check_do_variable (iter
.var
->symtree
);
2353 if (gfc_match_eos () != MATCH_YES
)
2355 gfc_syntax_error (ST_DO
);
2359 new_st
.op
= EXEC_DO
;
2363 && !gfc_reference_st_label (label
, ST_LABEL_DO_TARGET
))
2366 new_st
.label1
= label
;
2368 if (new_st
.op
== EXEC_DO_WHILE
)
2369 new_st
.expr1
= iter
.end
;
2372 new_st
.ext
.iterator
= ip
= gfc_get_iterator ();
2379 gfc_free_iterator (&iter
, 0);
2385 /* Match an EXIT or CYCLE statement. */
2388 match_exit_cycle (gfc_statement st
, gfc_exec_op op
)
2390 gfc_state_data
*p
, *o
;
2395 if (gfc_match_eos () == MATCH_YES
)
2399 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2402 m
= gfc_match ("% %n%t", name
);
2403 if (m
== MATCH_ERROR
)
2407 gfc_syntax_error (st
);
2411 /* Find the corresponding symbol. If there's a BLOCK statement
2412 between here and the label, it is not in gfc_current_ns but a parent
2414 stree
= gfc_find_symtree_in_proc (name
, gfc_current_ns
);
2417 gfc_error ("Name %qs in %s statement at %C is unknown",
2418 name
, gfc_ascii_statement (st
));
2423 if (sym
->attr
.flavor
!= FL_LABEL
)
2425 gfc_error ("Name %qs in %s statement at %C is not a construct name",
2426 name
, gfc_ascii_statement (st
));
2431 /* Find the loop specified by the label (or lack of a label). */
2432 for (o
= NULL
, p
= gfc_state_stack
; p
; p
= p
->previous
)
2433 if (o
== NULL
&& p
->state
== COMP_OMP_STRUCTURED_BLOCK
)
2435 else if (p
->state
== COMP_CRITICAL
)
2437 gfc_error("%s statement at %C leaves CRITICAL construct",
2438 gfc_ascii_statement (st
));
2441 else if (p
->state
== COMP_DO_CONCURRENT
2442 && (op
== EXEC_EXIT
|| (sym
&& sym
!= p
->sym
)))
2444 /* F2008, C821 & C845. */
2445 gfc_error("%s statement at %C leaves DO CONCURRENT construct",
2446 gfc_ascii_statement (st
));
2449 else if ((sym
&& sym
== p
->sym
)
2450 || (!sym
&& (p
->state
== COMP_DO
2451 || p
->state
== COMP_DO_CONCURRENT
)))
2457 gfc_error ("%s statement at %C is not within a construct",
2458 gfc_ascii_statement (st
));
2460 gfc_error ("%s statement at %C is not within construct %qs",
2461 gfc_ascii_statement (st
), sym
->name
);
2466 /* Special checks for EXIT from non-loop constructs. */
2470 case COMP_DO_CONCURRENT
:
2474 /* This is already handled above. */
2477 case COMP_ASSOCIATE
:
2481 case COMP_SELECT_TYPE
:
2483 if (op
== EXEC_CYCLE
)
2485 gfc_error ("CYCLE statement at %C is not applicable to non-loop"
2486 " construct %qs", sym
->name
);
2489 gcc_assert (op
== EXEC_EXIT
);
2490 if (!gfc_notify_std (GFC_STD_F2008
, "EXIT statement with no"
2491 " do-construct-name at %C"))
2496 gfc_error ("%s statement at %C is not applicable to construct %qs",
2497 gfc_ascii_statement (st
), sym
->name
);
2503 gfc_error (is_oacc (p
)
2504 ? "%s statement at %C leaving OpenACC structured block"
2505 : "%s statement at %C leaving OpenMP structured block",
2506 gfc_ascii_statement (st
));
2510 for (o
= p
, cnt
= 0; o
->state
== COMP_DO
&& o
->previous
!= NULL
; cnt
++)
2514 && o
->state
== COMP_OMP_STRUCTURED_BLOCK
2515 && (o
->head
->op
== EXEC_OACC_LOOP
2516 || o
->head
->op
== EXEC_OACC_PARALLEL_LOOP
))
2519 gcc_assert (o
->head
->next
!= NULL
2520 && (o
->head
->next
->op
== EXEC_DO
2521 || o
->head
->next
->op
== EXEC_DO_WHILE
)
2522 && o
->previous
!= NULL
2523 && o
->previous
->tail
->op
== o
->head
->op
);
2524 if (o
->previous
->tail
->ext
.omp_clauses
!= NULL
2525 && o
->previous
->tail
->ext
.omp_clauses
->collapse
> 1)
2526 collapse
= o
->previous
->tail
->ext
.omp_clauses
->collapse
;
2527 if (st
== ST_EXIT
&& cnt
<= collapse
)
2529 gfc_error ("EXIT statement at %C terminating !$ACC LOOP loop");
2532 if (st
== ST_CYCLE
&& cnt
< collapse
)
2534 gfc_error ("CYCLE statement at %C to non-innermost collapsed"
2535 " !$ACC LOOP loop");
2541 && (o
->state
== COMP_OMP_STRUCTURED_BLOCK
)
2542 && (o
->head
->op
== EXEC_OMP_DO
2543 || o
->head
->op
== EXEC_OMP_PARALLEL_DO
2544 || o
->head
->op
== EXEC_OMP_SIMD
2545 || o
->head
->op
== EXEC_OMP_DO_SIMD
2546 || o
->head
->op
== EXEC_OMP_PARALLEL_DO_SIMD
))
2549 gcc_assert (o
->head
->next
!= NULL
2550 && (o
->head
->next
->op
== EXEC_DO
2551 || o
->head
->next
->op
== EXEC_DO_WHILE
)
2552 && o
->previous
!= NULL
2553 && o
->previous
->tail
->op
== o
->head
->op
);
2554 if (o
->previous
->tail
->ext
.omp_clauses
!= NULL
2555 && o
->previous
->tail
->ext
.omp_clauses
->collapse
> 1)
2556 collapse
= o
->previous
->tail
->ext
.omp_clauses
->collapse
;
2557 if (st
== ST_EXIT
&& cnt
<= collapse
)
2559 gfc_error ("EXIT statement at %C terminating !$OMP DO loop");
2562 if (st
== ST_CYCLE
&& cnt
< collapse
)
2564 gfc_error ("CYCLE statement at %C to non-innermost collapsed"
2570 /* Save the first statement in the construct - needed by the backend. */
2571 new_st
.ext
.which_construct
= p
->construct
;
2579 /* Match the EXIT statement. */
2582 gfc_match_exit (void)
2584 return match_exit_cycle (ST_EXIT
, EXEC_EXIT
);
2588 /* Match the CYCLE statement. */
2591 gfc_match_cycle (void)
2593 return match_exit_cycle (ST_CYCLE
, EXEC_CYCLE
);
2597 /* Match a number or character constant after an (ERROR) STOP or PAUSE
2601 gfc_match_stopcode (gfc_statement st
)
2608 if (gfc_match_eos () != MATCH_YES
)
2610 m
= gfc_match_init_expr (&e
);
2611 if (m
== MATCH_ERROR
)
2616 if (gfc_match_eos () != MATCH_YES
)
2620 if (gfc_pure (NULL
))
2622 if (st
== ST_ERROR_STOP
)
2624 if (!gfc_notify_std (GFC_STD_F2015
, "%s statement at %C in PURE "
2625 "procedure", gfc_ascii_statement (st
)))
2630 gfc_error ("%s statement not allowed in PURE procedure at %C",
2631 gfc_ascii_statement (st
));
2636 gfc_unset_implicit_pure (NULL
);
2638 if (st
== ST_STOP
&& gfc_find_state (COMP_CRITICAL
))
2640 gfc_error ("Image control statement STOP at %C in CRITICAL block");
2643 if (st
== ST_STOP
&& gfc_find_state (COMP_DO_CONCURRENT
))
2645 gfc_error ("Image control statement STOP at %C in DO CONCURRENT block");
2651 if (!(e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_INTEGER
))
2653 gfc_error ("STOP code at %L must be either INTEGER or CHARACTER type",
2660 gfc_error ("STOP code at %L must be scalar",
2665 if (e
->ts
.type
== BT_CHARACTER
2666 && e
->ts
.kind
!= gfc_default_character_kind
)
2668 gfc_error ("STOP code at %L must be default character KIND=%d",
2669 &e
->where
, (int) gfc_default_character_kind
);
2673 if (e
->ts
.type
== BT_INTEGER
2674 && e
->ts
.kind
!= gfc_default_integer_kind
)
2676 gfc_error ("STOP code at %L must be default integer KIND=%d",
2677 &e
->where
, (int) gfc_default_integer_kind
);
2685 new_st
.op
= EXEC_STOP
;
2688 new_st
.op
= EXEC_ERROR_STOP
;
2691 new_st
.op
= EXEC_PAUSE
;
2698 new_st
.ext
.stop_code
= -1;
2703 gfc_syntax_error (st
);
2712 /* Match the (deprecated) PAUSE statement. */
2715 gfc_match_pause (void)
2719 m
= gfc_match_stopcode (ST_PAUSE
);
2722 if (!gfc_notify_std (GFC_STD_F95_DEL
, "PAUSE statement at %C"))
2729 /* Match the STOP statement. */
2732 gfc_match_stop (void)
2734 return gfc_match_stopcode (ST_STOP
);
2738 /* Match the ERROR STOP statement. */
2741 gfc_match_error_stop (void)
2743 if (!gfc_notify_std (GFC_STD_F2008
, "ERROR STOP statement at %C"))
2746 return gfc_match_stopcode (ST_ERROR_STOP
);
2750 /* Match LOCK/UNLOCK statement. Syntax:
2751 LOCK ( lock-variable [ , lock-stat-list ] )
2752 UNLOCK ( lock-variable [ , sync-stat-list ] )
2753 where lock-stat is ACQUIRED_LOCK or sync-stat
2754 and sync-stat is STAT= or ERRMSG=. */
2757 lock_unlock_statement (gfc_statement st
)
2760 gfc_expr
*tmp
, *lockvar
, *acq_lock
, *stat
, *errmsg
;
2761 bool saw_acq_lock
, saw_stat
, saw_errmsg
;
2763 tmp
= lockvar
= acq_lock
= stat
= errmsg
= NULL
;
2764 saw_acq_lock
= saw_stat
= saw_errmsg
= false;
2766 if (gfc_pure (NULL
))
2768 gfc_error ("Image control statement %s at %C in PURE procedure",
2769 st
== ST_LOCK
? "LOCK" : "UNLOCK");
2773 gfc_unset_implicit_pure (NULL
);
2775 if (flag_coarray
== GFC_FCOARRAY_NONE
)
2777 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
2781 if (gfc_find_state (COMP_CRITICAL
))
2783 gfc_error ("Image control statement %s at %C in CRITICAL block",
2784 st
== ST_LOCK
? "LOCK" : "UNLOCK");
2788 if (gfc_find_state (COMP_DO_CONCURRENT
))
2790 gfc_error ("Image control statement %s at %C in DO CONCURRENT block",
2791 st
== ST_LOCK
? "LOCK" : "UNLOCK");
2795 if (gfc_match_char ('(') != MATCH_YES
)
2798 if (gfc_match ("%e", &lockvar
) != MATCH_YES
)
2800 m
= gfc_match_char (',');
2801 if (m
== MATCH_ERROR
)
2805 m
= gfc_match_char (')');
2813 m
= gfc_match (" stat = %v", &tmp
);
2814 if (m
== MATCH_ERROR
)
2820 gfc_error ("Redundant STAT tag found at %L ", &tmp
->where
);
2826 m
= gfc_match_char (',');
2834 m
= gfc_match (" errmsg = %v", &tmp
);
2835 if (m
== MATCH_ERROR
)
2841 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp
->where
);
2847 m
= gfc_match_char (',');
2855 m
= gfc_match (" acquired_lock = %v", &tmp
);
2856 if (m
== MATCH_ERROR
|| st
== ST_UNLOCK
)
2862 gfc_error ("Redundant ACQUIRED_LOCK tag found at %L ",
2867 saw_acq_lock
= true;
2869 m
= gfc_match_char (',');
2880 if (m
== MATCH_ERROR
)
2883 if (gfc_match (" )%t") != MATCH_YES
)
2890 new_st
.op
= EXEC_LOCK
;
2893 new_st
.op
= EXEC_UNLOCK
;
2899 new_st
.expr1
= lockvar
;
2900 new_st
.expr2
= stat
;
2901 new_st
.expr3
= errmsg
;
2902 new_st
.expr4
= acq_lock
;
2907 gfc_syntax_error (st
);
2910 if (acq_lock
!= tmp
)
2911 gfc_free_expr (acq_lock
);
2913 gfc_free_expr (errmsg
);
2915 gfc_free_expr (stat
);
2917 gfc_free_expr (tmp
);
2918 gfc_free_expr (lockvar
);
2925 gfc_match_lock (void)
2927 if (!gfc_notify_std (GFC_STD_F2008
, "LOCK statement at %C"))
2930 return lock_unlock_statement (ST_LOCK
);
2935 gfc_match_unlock (void)
2937 if (!gfc_notify_std (GFC_STD_F2008
, "UNLOCK statement at %C"))
2940 return lock_unlock_statement (ST_UNLOCK
);
2944 /* Match SYNC ALL/IMAGES/MEMORY statement. Syntax:
2945 SYNC ALL [(sync-stat-list)]
2946 SYNC MEMORY [(sync-stat-list)]
2947 SYNC IMAGES (image-set [, sync-stat-list] )
2948 with sync-stat is int-expr or *. */
2951 sync_statement (gfc_statement st
)
2954 gfc_expr
*tmp
, *imageset
, *stat
, *errmsg
;
2955 bool saw_stat
, saw_errmsg
;
2957 tmp
= imageset
= stat
= errmsg
= NULL
;
2958 saw_stat
= saw_errmsg
= false;
2960 if (gfc_pure (NULL
))
2962 gfc_error ("Image control statement SYNC at %C in PURE procedure");
2966 gfc_unset_implicit_pure (NULL
);
2968 if (!gfc_notify_std (GFC_STD_F2008
, "SYNC statement at %C"))
2971 if (flag_coarray
== GFC_FCOARRAY_NONE
)
2973 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to "
2978 if (gfc_find_state (COMP_CRITICAL
))
2980 gfc_error ("Image control statement SYNC at %C in CRITICAL block");
2984 if (gfc_find_state (COMP_DO_CONCURRENT
))
2986 gfc_error ("Image control statement SYNC at %C in DO CONCURRENT block");
2990 if (gfc_match_eos () == MATCH_YES
)
2992 if (st
== ST_SYNC_IMAGES
)
2997 if (gfc_match_char ('(') != MATCH_YES
)
3000 if (st
== ST_SYNC_IMAGES
)
3002 /* Denote '*' as imageset == NULL. */
3003 m
= gfc_match_char ('*');
3004 if (m
== MATCH_ERROR
)
3008 if (gfc_match ("%e", &imageset
) != MATCH_YES
)
3011 m
= gfc_match_char (',');
3012 if (m
== MATCH_ERROR
)
3016 m
= gfc_match_char (')');
3025 m
= gfc_match (" stat = %v", &tmp
);
3026 if (m
== MATCH_ERROR
)
3032 gfc_error ("Redundant STAT tag found at %L ", &tmp
->where
);
3038 if (gfc_match_char (',') == MATCH_YES
)
3045 m
= gfc_match (" errmsg = %v", &tmp
);
3046 if (m
== MATCH_ERROR
)
3052 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp
->where
);
3058 if (gfc_match_char (',') == MATCH_YES
)
3068 if (gfc_match (" )%t") != MATCH_YES
)
3075 new_st
.op
= EXEC_SYNC_ALL
;
3077 case ST_SYNC_IMAGES
:
3078 new_st
.op
= EXEC_SYNC_IMAGES
;
3080 case ST_SYNC_MEMORY
:
3081 new_st
.op
= EXEC_SYNC_MEMORY
;
3087 new_st
.expr1
= imageset
;
3088 new_st
.expr2
= stat
;
3089 new_st
.expr3
= errmsg
;
3094 gfc_syntax_error (st
);
3098 gfc_free_expr (stat
);
3100 gfc_free_expr (errmsg
);
3102 gfc_free_expr (tmp
);
3103 gfc_free_expr (imageset
);
3109 /* Match SYNC ALL statement. */
3112 gfc_match_sync_all (void)
3114 return sync_statement (ST_SYNC_ALL
);
3118 /* Match SYNC IMAGES statement. */
3121 gfc_match_sync_images (void)
3123 return sync_statement (ST_SYNC_IMAGES
);
3127 /* Match SYNC MEMORY statement. */
3130 gfc_match_sync_memory (void)
3132 return sync_statement (ST_SYNC_MEMORY
);
3136 /* Match a CONTINUE statement. */
3139 gfc_match_continue (void)
3141 if (gfc_match_eos () != MATCH_YES
)
3143 gfc_syntax_error (ST_CONTINUE
);
3147 new_st
.op
= EXEC_CONTINUE
;
3152 /* Match the (deprecated) ASSIGN statement. */
3155 gfc_match_assign (void)
3158 gfc_st_label
*label
;
3160 if (gfc_match (" %l", &label
) == MATCH_YES
)
3162 if (!gfc_reference_st_label (label
, ST_LABEL_UNKNOWN
))
3164 if (gfc_match (" to %v%t", &expr
) == MATCH_YES
)
3166 if (!gfc_notify_std (GFC_STD_F95_DEL
, "ASSIGN statement at %C"))
3169 expr
->symtree
->n
.sym
->attr
.assign
= 1;
3171 new_st
.op
= EXEC_LABEL_ASSIGN
;
3172 new_st
.label1
= label
;
3173 new_st
.expr1
= expr
;
3181 /* Match the GO TO statement. As a computed GOTO statement is
3182 matched, it is transformed into an equivalent SELECT block. No
3183 tree is necessary, and the resulting jumps-to-jumps are
3184 specifically optimized away by the back end. */
3187 gfc_match_goto (void)
3189 gfc_code
*head
, *tail
;
3192 gfc_st_label
*label
;
3196 if (gfc_match (" %l%t", &label
) == MATCH_YES
)
3198 if (!gfc_reference_st_label (label
, ST_LABEL_TARGET
))
3201 new_st
.op
= EXEC_GOTO
;
3202 new_st
.label1
= label
;
3206 /* The assigned GO TO statement. */
3208 if (gfc_match_variable (&expr
, 0) == MATCH_YES
)
3210 if (!gfc_notify_std (GFC_STD_F95_DEL
, "Assigned GOTO statement at %C"))
3213 new_st
.op
= EXEC_GOTO
;
3214 new_st
.expr1
= expr
;
3216 if (gfc_match_eos () == MATCH_YES
)
3219 /* Match label list. */
3220 gfc_match_char (',');
3221 if (gfc_match_char ('(') != MATCH_YES
)
3223 gfc_syntax_error (ST_GOTO
);
3230 m
= gfc_match_st_label (&label
);
3234 if (!gfc_reference_st_label (label
, ST_LABEL_TARGET
))
3238 head
= tail
= gfc_get_code (EXEC_GOTO
);
3241 tail
->block
= gfc_get_code (EXEC_GOTO
);
3245 tail
->label1
= label
;
3247 while (gfc_match_char (',') == MATCH_YES
);
3249 if (gfc_match (")%t") != MATCH_YES
)
3254 gfc_error ("Statement label list in GOTO at %C cannot be empty");
3257 new_st
.block
= head
;
3262 /* Last chance is a computed GO TO statement. */
3263 if (gfc_match_char ('(') != MATCH_YES
)
3265 gfc_syntax_error (ST_GOTO
);
3274 m
= gfc_match_st_label (&label
);
3278 if (!gfc_reference_st_label (label
, ST_LABEL_TARGET
))
3282 head
= tail
= gfc_get_code (EXEC_SELECT
);
3285 tail
->block
= gfc_get_code (EXEC_SELECT
);
3289 cp
= gfc_get_case ();
3290 cp
->low
= cp
->high
= gfc_get_int_expr (gfc_default_integer_kind
,
3293 tail
->ext
.block
.case_list
= cp
;
3295 tail
->next
= gfc_get_code (EXEC_GOTO
);
3296 tail
->next
->label1
= label
;
3298 while (gfc_match_char (',') == MATCH_YES
);
3300 if (gfc_match_char (')') != MATCH_YES
)
3305 gfc_error ("Statement label list in GOTO at %C cannot be empty");
3309 /* Get the rest of the statement. */
3310 gfc_match_char (',');
3312 if (gfc_match (" %e%t", &expr
) != MATCH_YES
)
3315 if (!gfc_notify_std (GFC_STD_F95_OBS
, "Computed GOTO at %C"))
3318 /* At this point, a computed GOTO has been fully matched and an
3319 equivalent SELECT statement constructed. */
3321 new_st
.op
= EXEC_SELECT
;
3322 new_st
.expr1
= NULL
;
3324 /* Hack: For a "real" SELECT, the expression is in expr. We put
3325 it in expr2 so we can distinguish then and produce the correct
3327 new_st
.expr2
= expr
;
3328 new_st
.block
= head
;
3332 gfc_syntax_error (ST_GOTO
);
3334 gfc_free_statements (head
);
3339 /* Frees a list of gfc_alloc structures. */
3342 gfc_free_alloc_list (gfc_alloc
*p
)
3349 gfc_free_expr (p
->expr
);
3355 /* Match an ALLOCATE statement. */
3358 gfc_match_allocate (void)
3360 gfc_alloc
*head
, *tail
;
3361 gfc_expr
*stat
, *errmsg
, *tmp
, *source
, *mold
;
3365 locus old_locus
, deferred_locus
;
3366 bool saw_stat
, saw_errmsg
, saw_source
, saw_mold
, saw_deferred
, b1
, b2
, b3
;
3367 bool saw_unlimited
= false;
3370 stat
= errmsg
= source
= mold
= tmp
= NULL
;
3371 saw_stat
= saw_errmsg
= saw_source
= saw_mold
= saw_deferred
= false;
3373 if (gfc_match_char ('(') != MATCH_YES
)
3376 /* Match an optional type-spec. */
3377 old_locus
= gfc_current_locus
;
3378 m
= gfc_match_type_spec (&ts
);
3379 if (m
== MATCH_ERROR
)
3381 else if (m
== MATCH_NO
)
3383 char name
[GFC_MAX_SYMBOL_LEN
+ 3];
3385 if (gfc_match ("%n :: ", name
) == MATCH_YES
)
3387 gfc_error ("Error in type-spec at %L", &old_locus
);
3391 ts
.type
= BT_UNKNOWN
;
3395 if (gfc_match (" :: ") == MATCH_YES
)
3397 if (!gfc_notify_std (GFC_STD_F2003
, "typespec in ALLOCATE at %L",
3403 gfc_error ("Type-spec at %L cannot contain a deferred "
3404 "type parameter", &old_locus
);
3408 if (ts
.type
== BT_CHARACTER
)
3409 ts
.u
.cl
->length_from_typespec
= true;
3413 ts
.type
= BT_UNKNOWN
;
3414 gfc_current_locus
= old_locus
;
3421 head
= tail
= gfc_get_alloc ();
3424 tail
->next
= gfc_get_alloc ();
3428 m
= gfc_match_variable (&tail
->expr
, 0);
3431 if (m
== MATCH_ERROR
)
3434 if (gfc_check_do_variable (tail
->expr
->symtree
))
3437 bool impure
= gfc_impure_variable (tail
->expr
->symtree
->n
.sym
);
3438 if (impure
&& gfc_pure (NULL
))
3440 gfc_error ("Bad allocate-object at %C for a PURE procedure");
3445 gfc_unset_implicit_pure (NULL
);
3447 if (tail
->expr
->ts
.deferred
)
3449 saw_deferred
= true;
3450 deferred_locus
= tail
->expr
->where
;
3453 if (gfc_find_state (COMP_DO_CONCURRENT
)
3454 || gfc_find_state (COMP_CRITICAL
))
3457 bool coarray
= tail
->expr
->symtree
->n
.sym
->attr
.codimension
;
3458 for (ref
= tail
->expr
->ref
; ref
; ref
= ref
->next
)
3459 if (ref
->type
== REF_COMPONENT
)
3460 coarray
= ref
->u
.c
.component
->attr
.codimension
;
3462 if (coarray
&& gfc_find_state (COMP_DO_CONCURRENT
))
3464 gfc_error ("ALLOCATE of coarray at %C in DO CONCURRENT block");
3467 if (coarray
&& gfc_find_state (COMP_CRITICAL
))
3469 gfc_error ("ALLOCATE of coarray at %C in CRITICAL block");
3474 /* Check for F08:C628. */
3475 sym
= tail
->expr
->symtree
->n
.sym
;
3476 b1
= !(tail
->expr
->ref
3477 && (tail
->expr
->ref
->type
== REF_COMPONENT
3478 || tail
->expr
->ref
->type
== REF_ARRAY
));
3479 if (sym
&& sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
3480 b2
= !(CLASS_DATA (sym
)->attr
.allocatable
3481 || CLASS_DATA (sym
)->attr
.class_pointer
);
3483 b2
= sym
&& !(sym
->attr
.allocatable
|| sym
->attr
.pointer
3484 || sym
->attr
.proc_pointer
);
3485 b3
= sym
&& sym
->ns
&& sym
->ns
->proc_name
3486 && (sym
->ns
->proc_name
->attr
.allocatable
3487 || sym
->ns
->proc_name
->attr
.pointer
3488 || sym
->ns
->proc_name
->attr
.proc_pointer
);
3489 if (b1
&& b2
&& !b3
)
3491 gfc_error ("Allocate-object at %L is neither a data pointer "
3492 "nor an allocatable variable", &tail
->expr
->where
);
3496 /* The ALLOCATE statement had an optional typespec. Check the
3498 if (ts
.type
!= BT_UNKNOWN
)
3500 /* Enforce F03:C624. */
3501 if (!gfc_type_compatible (&tail
->expr
->ts
, &ts
))
3503 gfc_error ("Type of entity at %L is type incompatible with "
3504 "typespec", &tail
->expr
->where
);
3508 /* Enforce F03:C627. */
3509 if (ts
.kind
!= tail
->expr
->ts
.kind
&& !UNLIMITED_POLY (tail
->expr
))
3511 gfc_error ("Kind type parameter for entity at %L differs from "
3512 "the kind type parameter of the typespec",
3513 &tail
->expr
->where
);
3518 if (tail
->expr
->ts
.type
== BT_DERIVED
)
3519 tail
->expr
->ts
.u
.derived
= gfc_use_derived (tail
->expr
->ts
.u
.derived
);
3521 saw_unlimited
= saw_unlimited
| UNLIMITED_POLY (tail
->expr
);
3523 if (gfc_peek_ascii_char () == '(' && !sym
->attr
.dimension
)
3525 gfc_error ("Shape specification for allocatable scalar at %C");
3529 if (gfc_match_char (',') != MATCH_YES
)
3534 m
= gfc_match (" stat = %v", &tmp
);
3535 if (m
== MATCH_ERROR
)
3542 gfc_error ("Redundant STAT tag found at %L ", &tmp
->where
);
3550 if (gfc_check_do_variable (stat
->symtree
))
3553 if (gfc_match_char (',') == MATCH_YES
)
3554 goto alloc_opt_list
;
3557 m
= gfc_match (" errmsg = %v", &tmp
);
3558 if (m
== MATCH_ERROR
)
3562 if (!gfc_notify_std (GFC_STD_F2003
, "ERRMSG tag at %L", &tmp
->where
))
3568 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp
->where
);
3576 if (gfc_match_char (',') == MATCH_YES
)
3577 goto alloc_opt_list
;
3580 m
= gfc_match (" source = %e", &tmp
);
3581 if (m
== MATCH_ERROR
)
3585 if (!gfc_notify_std (GFC_STD_F2003
, "SOURCE tag at %L", &tmp
->where
))
3591 gfc_error ("Redundant SOURCE tag found at %L ", &tmp
->where
);
3595 /* The next 2 conditionals check C631. */
3596 if (ts
.type
!= BT_UNKNOWN
)
3598 gfc_error ("SOURCE tag at %L conflicts with the typespec at %L",
3599 &tmp
->where
, &old_locus
);
3604 && !gfc_notify_std (GFC_STD_F2008
, "SOURCE tag at %L"
3605 " with more than a single allocate object",
3613 if (gfc_match_char (',') == MATCH_YES
)
3614 goto alloc_opt_list
;
3617 m
= gfc_match (" mold = %e", &tmp
);
3618 if (m
== MATCH_ERROR
)
3622 if (!gfc_notify_std (GFC_STD_F2008
, "MOLD tag at %L", &tmp
->where
))
3625 /* Check F08:C636. */
3628 gfc_error ("Redundant MOLD tag found at %L ", &tmp
->where
);
3632 /* Check F08:C637. */
3633 if (ts
.type
!= BT_UNKNOWN
)
3635 gfc_error ("MOLD tag at %L conflicts with the typespec at %L",
3636 &tmp
->where
, &old_locus
);
3645 if (gfc_match_char (',') == MATCH_YES
)
3646 goto alloc_opt_list
;
3649 gfc_gobble_whitespace ();
3651 if (gfc_peek_char () == ')')
3655 if (gfc_match (" )%t") != MATCH_YES
)
3658 /* Check F08:C637. */
3661 gfc_error ("MOLD tag at %L conflicts with SOURCE tag at %L",
3662 &mold
->where
, &source
->where
);
3666 /* Check F03:C623, */
3667 if (saw_deferred
&& ts
.type
== BT_UNKNOWN
&& !source
&& !mold
)
3669 gfc_error ("Allocate-object at %L with a deferred type parameter "
3670 "requires either a type-spec or SOURCE tag or a MOLD tag",
3675 /* Check F03:C625, */
3676 if (saw_unlimited
&& ts
.type
== BT_UNKNOWN
&& !source
&& !mold
)
3678 for (tail
= head
; tail
; tail
= tail
->next
)
3680 if (UNLIMITED_POLY (tail
->expr
))
3681 gfc_error ("Unlimited polymorphic allocate-object at %L "
3682 "requires either a type-spec or SOURCE tag "
3683 "or a MOLD tag", &tail
->expr
->where
);
3688 new_st
.op
= EXEC_ALLOCATE
;
3689 new_st
.expr1
= stat
;
3690 new_st
.expr2
= errmsg
;
3692 new_st
.expr3
= source
;
3694 new_st
.expr3
= mold
;
3695 new_st
.ext
.alloc
.list
= head
;
3696 new_st
.ext
.alloc
.ts
= ts
;
3701 gfc_syntax_error (ST_ALLOCATE
);
3704 gfc_free_expr (errmsg
);
3705 gfc_free_expr (source
);
3706 gfc_free_expr (stat
);
3707 gfc_free_expr (mold
);
3708 if (tmp
&& tmp
->expr_type
) gfc_free_expr (tmp
);
3709 gfc_free_alloc_list (head
);
3714 /* Match a NULLIFY statement. A NULLIFY statement is transformed into
3715 a set of pointer assignments to intrinsic NULL(). */
3718 gfc_match_nullify (void)
3726 if (gfc_match_char ('(') != MATCH_YES
)
3731 m
= gfc_match_variable (&p
, 0);
3732 if (m
== MATCH_ERROR
)
3737 if (gfc_check_do_variable (p
->symtree
))
3741 if (gfc_is_coindexed (p
))
3743 gfc_error ("Pointer object at %C shall not be coindexed");
3747 /* build ' => NULL() '. */
3748 e
= gfc_get_null_expr (&gfc_current_locus
);
3750 /* Chain to list. */
3754 tail
->op
= EXEC_POINTER_ASSIGN
;
3758 tail
->next
= gfc_get_code (EXEC_POINTER_ASSIGN
);
3765 if (gfc_match (" )%t") == MATCH_YES
)
3767 if (gfc_match_char (',') != MATCH_YES
)
3774 gfc_syntax_error (ST_NULLIFY
);
3777 gfc_free_statements (new_st
.next
);
3779 gfc_free_expr (new_st
.expr1
);
3780 new_st
.expr1
= NULL
;
3781 gfc_free_expr (new_st
.expr2
);
3782 new_st
.expr2
= NULL
;
3787 /* Match a DEALLOCATE statement. */
3790 gfc_match_deallocate (void)
3792 gfc_alloc
*head
, *tail
;
3793 gfc_expr
*stat
, *errmsg
, *tmp
;
3796 bool saw_stat
, saw_errmsg
, b1
, b2
;
3799 stat
= errmsg
= tmp
= NULL
;
3800 saw_stat
= saw_errmsg
= false;
3802 if (gfc_match_char ('(') != MATCH_YES
)
3808 head
= tail
= gfc_get_alloc ();
3811 tail
->next
= gfc_get_alloc ();
3815 m
= gfc_match_variable (&tail
->expr
, 0);
3816 if (m
== MATCH_ERROR
)
3821 if (gfc_check_do_variable (tail
->expr
->symtree
))
3824 sym
= tail
->expr
->symtree
->n
.sym
;
3826 bool impure
= gfc_impure_variable (sym
);
3827 if (impure
&& gfc_pure (NULL
))
3829 gfc_error ("Illegal allocate-object at %C for a PURE procedure");
3834 gfc_unset_implicit_pure (NULL
);
3836 if (gfc_is_coarray (tail
->expr
)
3837 && gfc_find_state (COMP_DO_CONCURRENT
))
3839 gfc_error ("DEALLOCATE of coarray at %C in DO CONCURRENT block");
3843 if (gfc_is_coarray (tail
->expr
)
3844 && gfc_find_state (COMP_CRITICAL
))
3846 gfc_error ("DEALLOCATE of coarray at %C in CRITICAL block");
3850 /* FIXME: disable the checking on derived types. */
3851 b1
= !(tail
->expr
->ref
3852 && (tail
->expr
->ref
->type
== REF_COMPONENT
3853 || tail
->expr
->ref
->type
== REF_ARRAY
));
3854 if (sym
&& sym
->ts
.type
== BT_CLASS
)
3855 b2
= !(CLASS_DATA (sym
)->attr
.allocatable
3856 || CLASS_DATA (sym
)->attr
.class_pointer
);
3858 b2
= sym
&& !(sym
->attr
.allocatable
|| sym
->attr
.pointer
3859 || sym
->attr
.proc_pointer
);
3862 gfc_error ("Allocate-object at %C is not a nonprocedure pointer "
3863 "nor an allocatable variable");
3867 if (gfc_match_char (',') != MATCH_YES
)
3872 m
= gfc_match (" stat = %v", &tmp
);
3873 if (m
== MATCH_ERROR
)
3879 gfc_error ("Redundant STAT tag found at %L ", &tmp
->where
);
3880 gfc_free_expr (tmp
);
3887 if (gfc_check_do_variable (stat
->symtree
))
3890 if (gfc_match_char (',') == MATCH_YES
)
3891 goto dealloc_opt_list
;
3894 m
= gfc_match (" errmsg = %v", &tmp
);
3895 if (m
== MATCH_ERROR
)
3899 if (!gfc_notify_std (GFC_STD_F2003
, "ERRMSG at %L", &tmp
->where
))
3904 gfc_error ("Redundant ERRMSG tag found at %L ", &tmp
->where
);
3905 gfc_free_expr (tmp
);
3912 if (gfc_match_char (',') == MATCH_YES
)
3913 goto dealloc_opt_list
;
3916 gfc_gobble_whitespace ();
3918 if (gfc_peek_char () == ')')
3922 if (gfc_match (" )%t") != MATCH_YES
)
3925 new_st
.op
= EXEC_DEALLOCATE
;
3926 new_st
.expr1
= stat
;
3927 new_st
.expr2
= errmsg
;
3928 new_st
.ext
.alloc
.list
= head
;
3933 gfc_syntax_error (ST_DEALLOCATE
);
3936 gfc_free_expr (errmsg
);
3937 gfc_free_expr (stat
);
3938 gfc_free_alloc_list (head
);
3943 /* Match a RETURN statement. */
3946 gfc_match_return (void)
3950 gfc_compile_state s
;
3954 if (gfc_find_state (COMP_CRITICAL
))
3956 gfc_error ("Image control statement RETURN at %C in CRITICAL block");
3960 if (gfc_find_state (COMP_DO_CONCURRENT
))
3962 gfc_error ("Image control statement RETURN at %C in DO CONCURRENT block");
3966 if (gfc_match_eos () == MATCH_YES
)
3969 if (!gfc_find_state (COMP_SUBROUTINE
))
3971 gfc_error ("Alternate RETURN statement at %C is only allowed within "
3976 if (gfc_current_form
== FORM_FREE
)
3978 /* The following are valid, so we can't require a blank after the
3982 char c
= gfc_peek_ascii_char ();
3983 if (ISALPHA (c
) || ISDIGIT (c
))
3987 m
= gfc_match (" %e%t", &e
);
3990 if (m
== MATCH_ERROR
)
3993 gfc_syntax_error (ST_RETURN
);
4000 gfc_enclosing_unit (&s
);
4001 if (s
== COMP_PROGRAM
4002 && !gfc_notify_std (GFC_STD_GNU
, "RETURN statement in "
4003 "main program at %C"))
4006 new_st
.op
= EXEC_RETURN
;
4013 /* Match the call of a type-bound procedure, if CALL%var has already been
4014 matched and var found to be a derived-type variable. */
4017 match_typebound_call (gfc_symtree
* varst
)
4022 base
= gfc_get_expr ();
4023 base
->expr_type
= EXPR_VARIABLE
;
4024 base
->symtree
= varst
;
4025 base
->where
= gfc_current_locus
;
4026 gfc_set_sym_referenced (varst
->n
.sym
);
4028 m
= gfc_match_varspec (base
, 0, true, true);
4030 gfc_error ("Expected component reference at %C");
4033 gfc_free_expr (base
);
4037 if (gfc_match_eos () != MATCH_YES
)
4039 gfc_error ("Junk after CALL at %C");
4040 gfc_free_expr (base
);
4044 if (base
->expr_type
== EXPR_COMPCALL
)
4045 new_st
.op
= EXEC_COMPCALL
;
4046 else if (base
->expr_type
== EXPR_PPC
)
4047 new_st
.op
= EXEC_CALL_PPC
;
4050 gfc_error ("Expected type-bound procedure or procedure pointer component "
4052 gfc_free_expr (base
);
4055 new_st
.expr1
= base
;
4061 /* Match a CALL statement. The tricky part here are possible
4062 alternate return specifiers. We handle these by having all
4063 "subroutines" actually return an integer via a register that gives
4064 the return number. If the call specifies alternate returns, we
4065 generate code for a SELECT statement whose case clauses contain
4066 GOTOs to the various labels. */
4069 gfc_match_call (void)
4071 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4072 gfc_actual_arglist
*a
, *arglist
;
4082 m
= gfc_match ("% %n", name
);
4088 if (gfc_get_ha_sym_tree (name
, &st
))
4093 /* If this is a variable of derived-type, it probably starts a type-bound
4095 if ((sym
->attr
.flavor
!= FL_PROCEDURE
4096 || gfc_is_function_return_value (sym
, gfc_current_ns
))
4097 && (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
))
4098 return match_typebound_call (st
);
4100 /* If it does not seem to be callable (include functions so that the
4101 right association is made. They are thrown out in resolution.)
4103 if (!sym
->attr
.generic
4104 && !sym
->attr
.subroutine
4105 && !sym
->attr
.function
)
4107 if (!(sym
->attr
.external
&& !sym
->attr
.referenced
))
4109 /* ...create a symbol in this scope... */
4110 if (sym
->ns
!= gfc_current_ns
4111 && gfc_get_sym_tree (name
, NULL
, &st
, false) == 1)
4114 if (sym
!= st
->n
.sym
)
4118 /* ...and then to try to make the symbol into a subroutine. */
4119 if (!gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
))
4123 gfc_set_sym_referenced (sym
);
4125 if (gfc_match_eos () != MATCH_YES
)
4127 m
= gfc_match_actual_arglist (1, &arglist
);
4130 if (m
== MATCH_ERROR
)
4133 if (gfc_match_eos () != MATCH_YES
)
4137 /* If any alternate return labels were found, construct a SELECT
4138 statement that will jump to the right place. */
4141 for (a
= arglist
; a
; a
= a
->next
)
4142 if (a
->expr
== NULL
)
4150 gfc_symtree
*select_st
;
4151 gfc_symbol
*select_sym
;
4152 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4154 new_st
.next
= c
= gfc_get_code (EXEC_SELECT
);
4155 sprintf (name
, "_result_%s", sym
->name
);
4156 gfc_get_ha_sym_tree (name
, &select_st
); /* Can't fail. */
4158 select_sym
= select_st
->n
.sym
;
4159 select_sym
->ts
.type
= BT_INTEGER
;
4160 select_sym
->ts
.kind
= gfc_default_integer_kind
;
4161 gfc_set_sym_referenced (select_sym
);
4162 c
->expr1
= gfc_get_expr ();
4163 c
->expr1
->expr_type
= EXPR_VARIABLE
;
4164 c
->expr1
->symtree
= select_st
;
4165 c
->expr1
->ts
= select_sym
->ts
;
4166 c
->expr1
->where
= gfc_current_locus
;
4169 for (a
= arglist
; a
; a
= a
->next
)
4171 if (a
->expr
!= NULL
)
4174 if (!gfc_reference_st_label (a
->label
, ST_LABEL_TARGET
))
4179 c
->block
= gfc_get_code (EXEC_SELECT
);
4182 new_case
= gfc_get_case ();
4183 new_case
->high
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, i
);
4184 new_case
->low
= new_case
->high
;
4185 c
->ext
.block
.case_list
= new_case
;
4187 c
->next
= gfc_get_code (EXEC_GOTO
);
4188 c
->next
->label1
= a
->label
;
4192 new_st
.op
= EXEC_CALL
;
4193 new_st
.symtree
= st
;
4194 new_st
.ext
.actual
= arglist
;
4199 gfc_syntax_error (ST_CALL
);
4202 gfc_free_actual_arglist (arglist
);
4207 /* Given a name, return a pointer to the common head structure,
4208 creating it if it does not exist. If FROM_MODULE is nonzero, we
4209 mangle the name so that it doesn't interfere with commons defined
4210 in the using namespace.
4211 TODO: Add to global symbol tree. */
4214 gfc_get_common (const char *name
, int from_module
)
4217 static int serial
= 0;
4218 char mangled_name
[GFC_MAX_SYMBOL_LEN
+ 1];
4222 /* A use associated common block is only needed to correctly layout
4223 the variables it contains. */
4224 snprintf (mangled_name
, GFC_MAX_SYMBOL_LEN
, "_%d_%s", serial
++, name
);
4225 st
= gfc_new_symtree (&gfc_current_ns
->common_root
, mangled_name
);
4229 st
= gfc_find_symtree (gfc_current_ns
->common_root
, name
);
4232 st
= gfc_new_symtree (&gfc_current_ns
->common_root
, name
);
4235 if (st
->n
.common
== NULL
)
4237 st
->n
.common
= gfc_get_common_head ();
4238 st
->n
.common
->where
= gfc_current_locus
;
4239 strcpy (st
->n
.common
->name
, name
);
4242 return st
->n
.common
;
4246 /* Match a common block name. */
4248 match
match_common_name (char *name
)
4252 if (gfc_match_char ('/') == MATCH_NO
)
4258 if (gfc_match_char ('/') == MATCH_YES
)
4264 m
= gfc_match_name (name
);
4266 if (m
== MATCH_ERROR
)
4268 if (m
== MATCH_YES
&& gfc_match_char ('/') == MATCH_YES
)
4271 gfc_error ("Syntax error in common block name at %C");
4276 /* Match a COMMON statement. */
4279 gfc_match_common (void)
4281 gfc_symbol
*sym
, **head
, *tail
, *other
, *old_blank_common
;
4282 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4288 old_blank_common
= gfc_current_ns
->blank_common
.head
;
4289 if (old_blank_common
)
4291 while (old_blank_common
->common_next
)
4292 old_blank_common
= old_blank_common
->common_next
;
4299 m
= match_common_name (name
);
4300 if (m
== MATCH_ERROR
)
4303 if (name
[0] == '\0')
4305 t
= &gfc_current_ns
->blank_common
;
4306 if (t
->head
== NULL
)
4307 t
->where
= gfc_current_locus
;
4311 t
= gfc_get_common (name
, 0);
4320 while (tail
->common_next
)
4321 tail
= tail
->common_next
;
4324 /* Grab the list of symbols. */
4327 m
= gfc_match_symbol (&sym
, 0);
4328 if (m
== MATCH_ERROR
)
4333 /* Store a ref to the common block for error checking. */
4334 sym
->common_block
= t
;
4335 sym
->common_block
->refs
++;
4337 /* See if we know the current common block is bind(c), and if
4338 so, then see if we can check if the symbol is (which it'll
4339 need to be). This can happen if the bind(c) attr stmt was
4340 applied to the common block, and the variable(s) already
4341 defined, before declaring the common block. */
4342 if (t
->is_bind_c
== 1)
4344 if (sym
->ts
.type
!= BT_UNKNOWN
&& sym
->ts
.is_c_interop
!= 1)
4346 /* If we find an error, just print it and continue,
4347 cause it's just semantic, and we can see if there
4349 gfc_error_now ("Variable %qs at %L in common block %qs "
4350 "at %C must be declared with a C "
4351 "interoperable kind since common block "
4353 sym
->name
, &(sym
->declared_at
), t
->name
,
4357 if (sym
->attr
.is_bind_c
== 1)
4358 gfc_error_now ("Variable %qs in common block %qs at %C can not "
4359 "be bind(c) since it is not global", sym
->name
,
4363 if (sym
->attr
.in_common
)
4365 gfc_error ("Symbol %qs at %C is already in a COMMON block",
4370 if (((sym
->value
!= NULL
&& sym
->value
->expr_type
!= EXPR_NULL
)
4371 || sym
->attr
.data
) && gfc_current_state () != COMP_BLOCK_DATA
)
4373 if (!gfc_notify_std (GFC_STD_GNU
, "Initialized symbol %qs at "
4374 "%C can only be COMMON in BLOCK DATA",
4379 if (!gfc_add_in_common (&sym
->attr
, sym
->name
, NULL
))
4383 tail
->common_next
= sym
;
4389 /* Deal with an optional array specification after the
4391 m
= gfc_match_array_spec (&as
, true, true);
4392 if (m
== MATCH_ERROR
)
4397 if (as
->type
!= AS_EXPLICIT
)
4399 gfc_error ("Array specification for symbol %qs in COMMON "
4400 "at %C must be explicit", sym
->name
);
4404 if (!gfc_add_dimension (&sym
->attr
, sym
->name
, NULL
))
4407 if (sym
->attr
.pointer
)
4409 gfc_error ("Symbol %qs in COMMON at %C cannot be a "
4410 "POINTER array", sym
->name
);
4419 sym
->common_head
= t
;
4421 /* Check to see if the symbol is already in an equivalence group.
4422 If it is, set the other members as being in common. */
4423 if (sym
->attr
.in_equivalence
)
4425 for (e1
= gfc_current_ns
->equiv
; e1
; e1
= e1
->next
)
4427 for (e2
= e1
; e2
; e2
= e2
->eq
)
4428 if (e2
->expr
->symtree
->n
.sym
== sym
)
4435 for (e2
= e1
; e2
; e2
= e2
->eq
)
4437 other
= e2
->expr
->symtree
->n
.sym
;
4438 if (other
->common_head
4439 && other
->common_head
!= sym
->common_head
)
4441 gfc_error ("Symbol %qs, in COMMON block %qs at "
4442 "%C is being indirectly equivalenced to "
4443 "another COMMON block %qs",
4444 sym
->name
, sym
->common_head
->name
,
4445 other
->common_head
->name
);
4448 other
->attr
.in_common
= 1;
4449 other
->common_head
= t
;
4455 gfc_gobble_whitespace ();
4456 if (gfc_match_eos () == MATCH_YES
)
4458 if (gfc_peek_ascii_char () == '/')
4460 if (gfc_match_char (',') != MATCH_YES
)
4462 gfc_gobble_whitespace ();
4463 if (gfc_peek_ascii_char () == '/')
4472 gfc_syntax_error (ST_COMMON
);
4475 gfc_free_array_spec (as
);
4480 /* Match a BLOCK DATA program unit. */
4483 gfc_match_block_data (void)
4485 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4489 if (gfc_match_eos () == MATCH_YES
)
4491 gfc_new_block
= NULL
;
4495 m
= gfc_match ("% %n%t", name
);
4499 if (gfc_get_symbol (name
, NULL
, &sym
))
4502 if (!gfc_add_flavor (&sym
->attr
, FL_BLOCK_DATA
, sym
->name
, NULL
))
4505 gfc_new_block
= sym
;
4511 /* Free a namelist structure. */
4514 gfc_free_namelist (gfc_namelist
*name
)
4518 for (; name
; name
= n
)
4526 /* Free an OpenMP namelist structure. */
4529 gfc_free_omp_namelist (gfc_omp_namelist
*name
)
4531 gfc_omp_namelist
*n
;
4533 for (; name
; name
= n
)
4535 gfc_free_expr (name
->expr
);
4538 if (name
->udr
->combiner
)
4539 gfc_free_statement (name
->udr
->combiner
);
4540 if (name
->udr
->initializer
)
4541 gfc_free_statement (name
->udr
->initializer
);
4550 /* Match a NAMELIST statement. */
4553 gfc_match_namelist (void)
4555 gfc_symbol
*group_name
, *sym
;
4559 m
= gfc_match (" / %s /", &group_name
);
4562 if (m
== MATCH_ERROR
)
4567 if (group_name
->ts
.type
!= BT_UNKNOWN
)
4569 gfc_error ("Namelist group name %qs at %C already has a basic "
4570 "type of %s", group_name
->name
,
4571 gfc_typename (&group_name
->ts
));
4575 if (group_name
->attr
.flavor
== FL_NAMELIST
4576 && group_name
->attr
.use_assoc
4577 && !gfc_notify_std (GFC_STD_GNU
, "Namelist group name %qs "
4578 "at %C already is USE associated and can"
4579 "not be respecified.", group_name
->name
))
4582 if (group_name
->attr
.flavor
!= FL_NAMELIST
4583 && !gfc_add_flavor (&group_name
->attr
, FL_NAMELIST
,
4584 group_name
->name
, NULL
))
4589 m
= gfc_match_symbol (&sym
, 1);
4592 if (m
== MATCH_ERROR
)
4595 if (sym
->attr
.in_namelist
== 0
4596 && !gfc_add_in_namelist (&sym
->attr
, sym
->name
, NULL
))
4599 /* Use gfc_error_check here, rather than goto error, so that
4600 these are the only errors for the next two lines. */
4601 if (sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
)
4603 gfc_error ("Assumed size array %qs in namelist %qs at "
4604 "%C is not allowed", sym
->name
, group_name
->name
);
4608 nl
= gfc_get_namelist ();
4612 if (group_name
->namelist
== NULL
)
4613 group_name
->namelist
= group_name
->namelist_tail
= nl
;
4616 group_name
->namelist_tail
->next
= nl
;
4617 group_name
->namelist_tail
= nl
;
4620 if (gfc_match_eos () == MATCH_YES
)
4623 m
= gfc_match_char (',');
4625 if (gfc_match_char ('/') == MATCH_YES
)
4627 m2
= gfc_match (" %s /", &group_name
);
4628 if (m2
== MATCH_YES
)
4630 if (m2
== MATCH_ERROR
)
4644 gfc_syntax_error (ST_NAMELIST
);
4651 /* Match a MODULE statement. */
4654 gfc_match_module (void)
4658 m
= gfc_match (" %s%t", &gfc_new_block
);
4662 if (!gfc_add_flavor (&gfc_new_block
->attr
, FL_MODULE
,
4663 gfc_new_block
->name
, NULL
))
4670 /* Free equivalence sets and lists. Recursively is the easiest way to
4674 gfc_free_equiv_until (gfc_equiv
*eq
, gfc_equiv
*stop
)
4679 gfc_free_equiv (eq
->eq
);
4680 gfc_free_equiv_until (eq
->next
, stop
);
4681 gfc_free_expr (eq
->expr
);
4687 gfc_free_equiv (gfc_equiv
*eq
)
4689 gfc_free_equiv_until (eq
, NULL
);
4693 /* Match an EQUIVALENCE statement. */
4696 gfc_match_equivalence (void)
4698 gfc_equiv
*eq
, *set
, *tail
;
4702 gfc_common_head
*common_head
= NULL
;
4710 eq
= gfc_get_equiv ();
4714 eq
->next
= gfc_current_ns
->equiv
;
4715 gfc_current_ns
->equiv
= eq
;
4717 if (gfc_match_char ('(') != MATCH_YES
)
4721 common_flag
= FALSE
;
4726 m
= gfc_match_equiv_variable (&set
->expr
);
4727 if (m
== MATCH_ERROR
)
4732 /* count the number of objects. */
4735 if (gfc_match_char ('%') == MATCH_YES
)
4737 gfc_error ("Derived type component %C is not a "
4738 "permitted EQUIVALENCE member");
4742 for (ref
= set
->expr
->ref
; ref
; ref
= ref
->next
)
4743 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
== AR_SECTION
)
4745 gfc_error ("Array reference in EQUIVALENCE at %C cannot "
4746 "be an array section");
4750 sym
= set
->expr
->symtree
->n
.sym
;
4752 if (!gfc_add_in_equivalence (&sym
->attr
, sym
->name
, NULL
))
4755 if (sym
->attr
.in_common
)
4758 common_head
= sym
->common_head
;
4761 if (gfc_match_char (')') == MATCH_YES
)
4764 if (gfc_match_char (',') != MATCH_YES
)
4767 set
->eq
= gfc_get_equiv ();
4773 gfc_error ("EQUIVALENCE at %C requires two or more objects");
4777 /* If one of the members of an equivalence is in common, then
4778 mark them all as being in common. Before doing this, check
4779 that members of the equivalence group are not in different
4782 for (set
= eq
; set
; set
= set
->eq
)
4784 sym
= set
->expr
->symtree
->n
.sym
;
4785 if (sym
->common_head
&& sym
->common_head
!= common_head
)
4787 gfc_error ("Attempt to indirectly overlap COMMON "
4788 "blocks %s and %s by EQUIVALENCE at %C",
4789 sym
->common_head
->name
, common_head
->name
);
4792 sym
->attr
.in_common
= 1;
4793 sym
->common_head
= common_head
;
4796 if (gfc_match_eos () == MATCH_YES
)
4798 if (gfc_match_char (',') != MATCH_YES
)
4800 gfc_error ("Expecting a comma in EQUIVALENCE at %C");
4808 gfc_syntax_error (ST_EQUIVALENCE
);
4814 gfc_free_equiv (gfc_current_ns
->equiv
);
4815 gfc_current_ns
->equiv
= eq
;
4821 /* Check that a statement function is not recursive. This is done by looking
4822 for the statement function symbol(sym) by looking recursively through its
4823 expression(e). If a reference to sym is found, true is returned.
4824 12.5.4 requires that any variable of function that is implicitly typed
4825 shall have that type confirmed by any subsequent type declaration. The
4826 implicit typing is conveniently done here. */
4828 recursive_stmt_fcn (gfc_expr
*, gfc_symbol
*);
4831 check_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
4837 switch (e
->expr_type
)
4840 if (e
->symtree
== NULL
)
4843 /* Check the name before testing for nested recursion! */
4844 if (sym
->name
== e
->symtree
->n
.sym
->name
)
4847 /* Catch recursion via other statement functions. */
4848 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
4849 && e
->symtree
->n
.sym
->value
4850 && recursive_stmt_fcn (e
->symtree
->n
.sym
->value
, sym
))
4853 if (e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
)
4854 gfc_set_default_type (e
->symtree
->n
.sym
, 0, NULL
);
4859 if (e
->symtree
&& sym
->name
== e
->symtree
->n
.sym
->name
)
4862 if (e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
)
4863 gfc_set_default_type (e
->symtree
->n
.sym
, 0, NULL
);
4875 recursive_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
)
4877 return gfc_traverse_expr (e
, sym
, check_stmt_fcn
, 0);
4881 /* Match a statement function declaration. It is so easy to match
4882 non-statement function statements with a MATCH_ERROR as opposed to
4883 MATCH_NO that we suppress error message in most cases. */
4886 gfc_match_st_function (void)
4888 gfc_error_buffer old_error
;
4894 m
= gfc_match_symbol (&sym
, 0);
4898 gfc_push_error (&old_error
);
4900 if (!gfc_add_procedure (&sym
->attr
, PROC_ST_FUNCTION
, sym
->name
, NULL
))
4903 if (gfc_match_formal_arglist (sym
, 1, 0) != MATCH_YES
)
4906 m
= gfc_match (" = %e%t", &expr
);
4910 gfc_free_error (&old_error
);
4912 if (m
== MATCH_ERROR
)
4915 if (recursive_stmt_fcn (expr
, sym
))
4917 gfc_error ("Statement function at %L is recursive", &expr
->where
);
4923 if (!gfc_notify_std (GFC_STD_F95_OBS
, "Statement function at %C"))
4929 gfc_pop_error (&old_error
);
4934 /***************** SELECT CASE subroutines ******************/
4936 /* Free a single case structure. */
4939 free_case (gfc_case
*p
)
4941 if (p
->low
== p
->high
)
4943 gfc_free_expr (p
->low
);
4944 gfc_free_expr (p
->high
);
4949 /* Free a list of case structures. */
4952 gfc_free_case_list (gfc_case
*p
)
4964 /* Match a single case selector. */
4967 match_case_selector (gfc_case
**cp
)
4972 c
= gfc_get_case ();
4973 c
->where
= gfc_current_locus
;
4975 if (gfc_match_char (':') == MATCH_YES
)
4977 m
= gfc_match_init_expr (&c
->high
);
4980 if (m
== MATCH_ERROR
)
4985 m
= gfc_match_init_expr (&c
->low
);
4986 if (m
== MATCH_ERROR
)
4991 /* If we're not looking at a ':' now, make a range out of a single
4992 target. Else get the upper bound for the case range. */
4993 if (gfc_match_char (':') != MATCH_YES
)
4997 m
= gfc_match_init_expr (&c
->high
);
4998 if (m
== MATCH_ERROR
)
5000 /* MATCH_NO is fine. It's OK if nothing is there! */
5008 gfc_error ("Expected initialization expression in CASE at %C");
5016 /* Match the end of a case statement. */
5019 match_case_eos (void)
5021 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5024 if (gfc_match_eos () == MATCH_YES
)
5027 /* If the case construct doesn't have a case-construct-name, we
5028 should have matched the EOS. */
5029 if (!gfc_current_block ())
5032 gfc_gobble_whitespace ();
5034 m
= gfc_match_name (name
);
5038 if (strcmp (name
, gfc_current_block ()->name
) != 0)
5040 gfc_error ("Expected block name %qs of SELECT construct at %C",
5041 gfc_current_block ()->name
);
5045 return gfc_match_eos ();
5049 /* Match a SELECT statement. */
5052 gfc_match_select (void)
5057 m
= gfc_match_label ();
5058 if (m
== MATCH_ERROR
)
5061 m
= gfc_match (" select case ( %e )%t", &expr
);
5065 new_st
.op
= EXEC_SELECT
;
5066 new_st
.expr1
= expr
;
5072 /* Transfer the selector typespec to the associate name. */
5075 copy_ts_from_selector_to_associate (gfc_expr
*associate
, gfc_expr
*selector
)
5078 gfc_symbol
*assoc_sym
;
5080 assoc_sym
= associate
->symtree
->n
.sym
;
5082 /* At this stage the expression rank and arrayspec dimensions have
5083 not been completely sorted out. We must get the expr2->rank
5084 right here, so that the correct class container is obtained. */
5085 ref
= selector
->ref
;
5086 while (ref
&& ref
->next
)
5089 if (selector
->ts
.type
== BT_CLASS
&& CLASS_DATA (selector
)->as
5090 && ref
&& ref
->type
== REF_ARRAY
)
5092 /* Ensure that the array reference type is set. We cannot use
5093 gfc_resolve_expr at this point, so the usable parts of
5094 resolve.c(resolve_array_ref) are employed to do it. */
5095 if (ref
->u
.ar
.type
== AR_UNKNOWN
)
5097 ref
->u
.ar
.type
= AR_ELEMENT
;
5098 for (int i
= 0; i
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; i
++)
5099 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
5100 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
5101 || (ref
->u
.ar
.dimen_type
[i
] == DIMEN_UNKNOWN
5102 && ref
->u
.ar
.start
[i
] && ref
->u
.ar
.start
[i
]->rank
))
5104 ref
->u
.ar
.type
= AR_SECTION
;
5109 if (ref
->u
.ar
.type
== AR_FULL
)
5110 selector
->rank
= CLASS_DATA (selector
)->as
->rank
;
5111 else if (ref
->u
.ar
.type
== AR_SECTION
)
5112 selector
->rank
= ref
->u
.ar
.dimen
;
5119 assoc_sym
->attr
.dimension
= 1;
5120 assoc_sym
->as
= gfc_get_array_spec ();
5121 assoc_sym
->as
->rank
= selector
->rank
;
5122 assoc_sym
->as
->type
= AS_DEFERRED
;
5125 assoc_sym
->as
= NULL
;
5127 if (selector
->ts
.type
== BT_CLASS
)
5129 /* The correct class container has to be available. */
5130 assoc_sym
->ts
.type
= BT_CLASS
;
5131 assoc_sym
->ts
.u
.derived
= CLASS_DATA (selector
)->ts
.u
.derived
;
5132 assoc_sym
->attr
.pointer
= 1;
5133 gfc_build_class_symbol (&assoc_sym
->ts
, &assoc_sym
->attr
, &assoc_sym
->as
);
5138 /* Push the current selector onto the SELECT TYPE stack. */
5141 select_type_push (gfc_symbol
*sel
)
5143 gfc_select_type_stack
*top
= gfc_get_select_type_stack ();
5144 top
->selector
= sel
;
5146 top
->prev
= select_type_stack
;
5148 select_type_stack
= top
;
5152 /* Set the temporary for the current intrinsic SELECT TYPE selector. */
5154 static gfc_symtree
*
5155 select_intrinsic_set_tmp (gfc_typespec
*ts
)
5157 char name
[GFC_MAX_SYMBOL_LEN
];
5161 if (ts
->type
== BT_CLASS
|| ts
->type
== BT_DERIVED
)
5164 if (select_type_stack
->selector
->ts
.type
== BT_CLASS
5165 && !select_type_stack
->selector
->attr
.class_ok
)
5168 if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& ts
->u
.cl
->length
5169 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
5170 charlen
= mpz_get_si (ts
->u
.cl
->length
->value
.integer
);
5172 if (ts
->type
!= BT_CHARACTER
)
5173 sprintf (name
, "__tmp_%s_%d", gfc_basic_typename (ts
->type
),
5176 sprintf (name
, "__tmp_%s_%d_%d", gfc_basic_typename (ts
->type
),
5179 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp
, false);
5180 gfc_add_type (tmp
->n
.sym
, ts
, NULL
);
5182 /* Copy across the array spec to the selector. */
5183 if (select_type_stack
->selector
->ts
.type
== BT_CLASS
5184 && (CLASS_DATA (select_type_stack
->selector
)->attr
.dimension
5185 || CLASS_DATA (select_type_stack
->selector
)->attr
.codimension
))
5187 tmp
->n
.sym
->attr
.pointer
= 1;
5188 tmp
->n
.sym
->attr
.dimension
5189 = CLASS_DATA (select_type_stack
->selector
)->attr
.dimension
;
5190 tmp
->n
.sym
->attr
.codimension
5191 = CLASS_DATA (select_type_stack
->selector
)->attr
.codimension
;
5193 = gfc_copy_array_spec (CLASS_DATA (select_type_stack
->selector
)->as
);
5196 gfc_set_sym_referenced (tmp
->n
.sym
);
5197 gfc_add_flavor (&tmp
->n
.sym
->attr
, FL_VARIABLE
, name
, NULL
);
5198 tmp
->n
.sym
->attr
.select_type_temporary
= 1;
5204 /* Set up a temporary for the current TYPE IS / CLASS IS branch . */
5207 select_type_set_tmp (gfc_typespec
*ts
)
5209 char name
[GFC_MAX_SYMBOL_LEN
];
5210 gfc_symtree
*tmp
= NULL
;
5214 select_type_stack
->tmp
= NULL
;
5218 tmp
= select_intrinsic_set_tmp (ts
);
5225 if (ts
->type
== BT_CLASS
)
5226 sprintf (name
, "__tmp_class_%s", ts
->u
.derived
->name
);
5228 sprintf (name
, "__tmp_type_%s", ts
->u
.derived
->name
);
5229 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp
, false);
5230 gfc_add_type (tmp
->n
.sym
, ts
, NULL
);
5232 if (select_type_stack
->selector
->ts
.type
== BT_CLASS
5233 && select_type_stack
->selector
->attr
.class_ok
)
5235 tmp
->n
.sym
->attr
.pointer
5236 = CLASS_DATA (select_type_stack
->selector
)->attr
.class_pointer
;
5238 /* Copy across the array spec to the selector. */
5239 if (CLASS_DATA (select_type_stack
->selector
)->attr
.dimension
5240 || CLASS_DATA (select_type_stack
->selector
)->attr
.codimension
)
5242 tmp
->n
.sym
->attr
.dimension
5243 = CLASS_DATA (select_type_stack
->selector
)->attr
.dimension
;
5244 tmp
->n
.sym
->attr
.codimension
5245 = CLASS_DATA (select_type_stack
->selector
)->attr
.codimension
;
5247 = gfc_copy_array_spec (CLASS_DATA (select_type_stack
->selector
)->as
);
5251 gfc_set_sym_referenced (tmp
->n
.sym
);
5252 gfc_add_flavor (&tmp
->n
.sym
->attr
, FL_VARIABLE
, name
, NULL
);
5253 tmp
->n
.sym
->attr
.select_type_temporary
= 1;
5255 if (ts
->type
== BT_CLASS
)
5256 gfc_build_class_symbol (&tmp
->n
.sym
->ts
, &tmp
->n
.sym
->attr
,
5260 /* Add an association for it, so the rest of the parser knows it is
5261 an associate-name. The target will be set during resolution. */
5262 tmp
->n
.sym
->assoc
= gfc_get_association_list ();
5263 tmp
->n
.sym
->assoc
->dangling
= 1;
5264 tmp
->n
.sym
->assoc
->st
= tmp
;
5266 select_type_stack
->tmp
= tmp
;
5270 /* Match a SELECT TYPE statement. */
5273 gfc_match_select_type (void)
5275 gfc_expr
*expr1
, *expr2
= NULL
;
5277 char name
[GFC_MAX_SYMBOL_LEN
];
5281 m
= gfc_match_label ();
5282 if (m
== MATCH_ERROR
)
5285 m
= gfc_match (" select type ( ");
5289 m
= gfc_match (" %n => %e", name
, &expr2
);
5292 expr1
= gfc_get_expr();
5293 expr1
->expr_type
= EXPR_VARIABLE
;
5294 if (gfc_get_sym_tree (name
, NULL
, &expr1
->symtree
, false))
5300 sym
= expr1
->symtree
->n
.sym
;
5301 if (expr2
->ts
.type
== BT_UNKNOWN
)
5302 sym
->attr
.untyped
= 1;
5304 copy_ts_from_selector_to_associate (expr1
, expr2
);
5306 sym
->attr
.flavor
= FL_VARIABLE
;
5307 sym
->attr
.referenced
= 1;
5308 sym
->attr
.class_ok
= 1;
5312 m
= gfc_match (" %e ", &expr1
);
5317 m
= gfc_match (" )%t");
5320 gfc_error ("parse error in SELECT TYPE statement at %C");
5324 /* This ghastly expression seems to be needed to distinguish a CLASS
5325 array, which can have a reference, from other expressions that
5326 have references, such as derived type components, and are not
5327 allowed by the standard.
5328 TODO: see if it is sufficient to exclude component and substring
5330 class_array
= expr1
->expr_type
== EXPR_VARIABLE
5331 && expr1
->ts
.type
== BT_CLASS
5332 && CLASS_DATA (expr1
)
5333 && (strcmp (CLASS_DATA (expr1
)->name
, "_data") == 0)
5334 && (CLASS_DATA (expr1
)->attr
.dimension
5335 || CLASS_DATA (expr1
)->attr
.codimension
)
5337 && expr1
->ref
->type
== REF_ARRAY
5338 && expr1
->ref
->next
== NULL
;
5340 /* Check for F03:C811. */
5341 if (!expr2
&& (expr1
->expr_type
!= EXPR_VARIABLE
5342 || (!class_array
&& expr1
->ref
!= NULL
)))
5344 gfc_error ("Selector in SELECT TYPE at %C is not a named variable; "
5345 "use associate-name=>");
5350 new_st
.op
= EXEC_SELECT_TYPE
;
5351 new_st
.expr1
= expr1
;
5352 new_st
.expr2
= expr2
;
5353 new_st
.ext
.block
.ns
= gfc_current_ns
;
5355 select_type_push (expr1
->symtree
->n
.sym
);
5360 gfc_free_expr (expr1
);
5361 gfc_free_expr (expr2
);
5366 /* Match a CASE statement. */
5369 gfc_match_case (void)
5371 gfc_case
*c
, *head
, *tail
;
5376 if (gfc_current_state () != COMP_SELECT
)
5378 gfc_error ("Unexpected CASE statement at %C");
5382 if (gfc_match ("% default") == MATCH_YES
)
5384 m
= match_case_eos ();
5387 if (m
== MATCH_ERROR
)
5390 new_st
.op
= EXEC_SELECT
;
5391 c
= gfc_get_case ();
5392 c
->where
= gfc_current_locus
;
5393 new_st
.ext
.block
.case_list
= c
;
5397 if (gfc_match_char ('(') != MATCH_YES
)
5402 if (match_case_selector (&c
) == MATCH_ERROR
)
5412 if (gfc_match_char (')') == MATCH_YES
)
5414 if (gfc_match_char (',') != MATCH_YES
)
5418 m
= match_case_eos ();
5421 if (m
== MATCH_ERROR
)
5424 new_st
.op
= EXEC_SELECT
;
5425 new_st
.ext
.block
.case_list
= head
;
5430 gfc_error ("Syntax error in CASE specification at %C");
5433 gfc_free_case_list (head
); /* new_st is cleaned up in parse.c. */
5438 /* Match a TYPE IS statement. */
5441 gfc_match_type_is (void)
5446 if (gfc_current_state () != COMP_SELECT_TYPE
)
5448 gfc_error ("Unexpected TYPE IS statement at %C");
5452 if (gfc_match_char ('(') != MATCH_YES
)
5455 c
= gfc_get_case ();
5456 c
->where
= gfc_current_locus
;
5458 m
= gfc_match_type_spec (&c
->ts
);
5461 if (m
== MATCH_ERROR
)
5464 if (gfc_match_char (')') != MATCH_YES
)
5467 m
= match_case_eos ();
5470 if (m
== MATCH_ERROR
)
5473 new_st
.op
= EXEC_SELECT_TYPE
;
5474 new_st
.ext
.block
.case_list
= c
;
5476 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
5477 && (c
->ts
.u
.derived
->attr
.sequence
5478 || c
->ts
.u
.derived
->attr
.is_bind_c
))
5480 gfc_error ("The type-spec shall not specify a sequence derived "
5481 "type or a type with the BIND attribute in SELECT "
5482 "TYPE at %C [F2003:C815]");
5486 /* Create temporary variable. */
5487 select_type_set_tmp (&c
->ts
);
5492 gfc_error ("Syntax error in TYPE IS specification at %C");
5496 gfc_free_case_list (c
); /* new_st is cleaned up in parse.c. */
5501 /* Match a CLASS IS or CLASS DEFAULT statement. */
5504 gfc_match_class_is (void)
5509 if (gfc_current_state () != COMP_SELECT_TYPE
)
5512 if (gfc_match ("% default") == MATCH_YES
)
5514 m
= match_case_eos ();
5517 if (m
== MATCH_ERROR
)
5520 new_st
.op
= EXEC_SELECT_TYPE
;
5521 c
= gfc_get_case ();
5522 c
->where
= gfc_current_locus
;
5523 c
->ts
.type
= BT_UNKNOWN
;
5524 new_st
.ext
.block
.case_list
= c
;
5525 select_type_set_tmp (NULL
);
5529 m
= gfc_match ("% is");
5532 if (m
== MATCH_ERROR
)
5535 if (gfc_match_char ('(') != MATCH_YES
)
5538 c
= gfc_get_case ();
5539 c
->where
= gfc_current_locus
;
5541 m
= match_derived_type_spec (&c
->ts
);
5544 if (m
== MATCH_ERROR
)
5547 if (c
->ts
.type
== BT_DERIVED
)
5548 c
->ts
.type
= BT_CLASS
;
5550 if (gfc_match_char (')') != MATCH_YES
)
5553 m
= match_case_eos ();
5556 if (m
== MATCH_ERROR
)
5559 new_st
.op
= EXEC_SELECT_TYPE
;
5560 new_st
.ext
.block
.case_list
= c
;
5562 /* Create temporary variable. */
5563 select_type_set_tmp (&c
->ts
);
5568 gfc_error ("Syntax error in CLASS IS specification at %C");
5572 gfc_free_case_list (c
); /* new_st is cleaned up in parse.c. */
5577 /********************* WHERE subroutines ********************/
5579 /* Match the rest of a simple WHERE statement that follows an IF statement.
5583 match_simple_where (void)
5589 m
= gfc_match (" ( %e )", &expr
);
5593 m
= gfc_match_assignment ();
5596 if (m
== MATCH_ERROR
)
5599 if (gfc_match_eos () != MATCH_YES
)
5602 c
= gfc_get_code (EXEC_WHERE
);
5605 c
->next
= XCNEW (gfc_code
);
5607 gfc_clear_new_st ();
5609 new_st
.op
= EXEC_WHERE
;
5615 gfc_syntax_error (ST_WHERE
);
5618 gfc_free_expr (expr
);
5623 /* Match a WHERE statement. */
5626 gfc_match_where (gfc_statement
*st
)
5632 m0
= gfc_match_label ();
5633 if (m0
== MATCH_ERROR
)
5636 m
= gfc_match (" where ( %e )", &expr
);
5640 if (gfc_match_eos () == MATCH_YES
)
5642 *st
= ST_WHERE_BLOCK
;
5643 new_st
.op
= EXEC_WHERE
;
5644 new_st
.expr1
= expr
;
5648 m
= gfc_match_assignment ();
5650 gfc_syntax_error (ST_WHERE
);
5654 gfc_free_expr (expr
);
5658 /* We've got a simple WHERE statement. */
5660 c
= gfc_get_code (EXEC_WHERE
);
5663 c
->next
= XCNEW (gfc_code
);
5665 gfc_clear_new_st ();
5667 new_st
.op
= EXEC_WHERE
;
5674 /* Match an ELSEWHERE statement. We leave behind a WHERE node in
5675 new_st if successful. */
5678 gfc_match_elsewhere (void)
5680 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5684 if (gfc_current_state () != COMP_WHERE
)
5686 gfc_error ("ELSEWHERE statement at %C not enclosed in WHERE block");
5692 if (gfc_match_char ('(') == MATCH_YES
)
5694 m
= gfc_match_expr (&expr
);
5697 if (m
== MATCH_ERROR
)
5700 if (gfc_match_char (')') != MATCH_YES
)
5704 if (gfc_match_eos () != MATCH_YES
)
5706 /* Only makes sense if we have a where-construct-name. */
5707 if (!gfc_current_block ())
5712 /* Better be a name at this point. */
5713 m
= gfc_match_name (name
);
5716 if (m
== MATCH_ERROR
)
5719 if (gfc_match_eos () != MATCH_YES
)
5722 if (strcmp (name
, gfc_current_block ()->name
) != 0)
5724 gfc_error ("Label %qs at %C doesn't match WHERE label %qs",
5725 name
, gfc_current_block ()->name
);
5730 new_st
.op
= EXEC_WHERE
;
5731 new_st
.expr1
= expr
;
5735 gfc_syntax_error (ST_ELSEWHERE
);
5738 gfc_free_expr (expr
);